commit email: explicit arrays and limit checks

Stephen Weeks MLton@sourcelight.com
Mon, 18 Feb 2002 18:12:10 -0800


> Can you explain the origin of array0Const and array0?  How
> often are these primitives likely to be generated?  It just
> seems unintuitive that zero length arrays are very common,
> unless their a representation for something else.

array0Const is there so that we can share the heap space required for
zero length vectors among all vectors (of a given type).  It lets the
constant propagation pass move all array0Const to the globals.  This
optimization is important, e.g., in a self-compile, where we use
vectors for lots of syntax tree elements, and many of those vectors
are empty.

array0 is there because the code for implementing zero length arrays
is slightly different than that for other arrays, because zero length
arrays need an extra four bytes that otherwise wouldn't be there so
there is space for the forwarding pointer.  Previously, this was
hidden in the semantics of Array_array and each codegen implemented an
if-zero-test.  Now, the semantics is that Array_array knows it will
get a length greater than zero, and the if-zero-test is done in the
basis library.