On Wed, Mar 11, 2009 at 11:46 AM, Swaroop Sridhar <[email protected]> wrote: > Geoffrey Irving wrote: >> Most imperative operations in numerical code (my own, at least) >> involve incremental construction of vectors, sometimes in random >> access order. In many cases these arrays aren't modified once they >> are created. Currently each location in BitC memory is either >> permanently mutable or permanently immutable, which means that an >> array constructed using imperative operations must be copied in order >> to become immutable. How difficult would it be to relax this >> restriction enough to allow the following pattern: >> >> f : vector int -> () >> freeze : mutable 'a -> 'a # with escape restrictions >> let a = make-vector 100 0 >> for i in range(100): >> a[i] = i >> f (freeze a) > > BitC has a primitive called make-vector > (http://bitc-lang.org/docs/bitc/spec.html#7.5.2) which can be used to > initialize immutable vectors incrementally. > > The above initialization can be written using make-vector as: > > (define (init n:word) n) > (define vec (make-vector 100 init)) > > All elements can be incrementally initialized using different cases in > the init function, but there is no reason to actually make the vector > mutable. Since the elements of the array (once initialized) will not be > modified even during initialization, my thought is that this support > should be sufficient?
No, this isn't sufficient because the elements are sometimes constructed out of order or modified multiple times. Common examples include 1. Gather operations such as matrix multiply 2. Arbitrary random access, such as inverting a permutation represented by an int vector 3. Constructing more than one array at the same time (any large SIMD operation with multiple outputs) Also, if make-vector is a primitive inlining it produces invalid BitC code, which breaks the BitC -> BitC optimization property. Geoffrey _______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
