First Draft: Static Single Assignment

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Dec 4 01:42:43 UTC 2025


On Wednesday, December 3, 2025 3:53:04 AM Mountain Standard Time Dom Disc via dip.development wrote:
> This doesn't seem to be very useful. If you want a dynamic array
> that can't change length, why don't you use a static array?!?

Well, the benefit would be basically the same as with a const dynamic array
which is a slice of a mutable dynamic array except that you can mutate the
elements. The length is dynamically determined (whereas the length of a
static array is known at compile time), and the elements don't need to be
copied. Of course, if you're talking about an array whose length is known at
compile time, you're creating it in that function, and it's not going to
escape that function, then you probably should use a static array to avoid
allocating memory, but in many cases, the dynamic array could be coming from
elsewhere (e.g. via a function parameter), and you simply don't want to
mutate its ptr or length.

Now, I personally don't think that it's worth adding a storage class to
prevent mutating the ptr or length fields of a dynamic array, but using a
static array instead would have very different semantics to simply not
mutating the ptr or length of a dynamic array within a function.

Personally, if I wanted to use a dynamic array without mutating its ptr or
length (which I'm sure that I've done plenty of times before), then I just
wouldn't mutate the ptr or length.

- Jonathan M Davis






More information about the dip.development mailing list