Notes
2026/11/28
Instead of growing lists on the stack, here's a better idea:
Pushing or setting an element when the list doesn't have enough capacity (because the element would need to be allocated and stored as part of the list) simply fails. It is then up to the user to decide what to do: Either grow the list manually (which would then move the entire stack above the list) or do something else (e.g. abort the allocation or store the element somewhere else).
This fits the idea of a purely functional language with explicit mutable references (of which only one can exist at any point in time, thus guaranteeing referential transparency), because reads can never fail because of borrowing/mutation, but writes can: Either because there's no capacity or because an immutable reference still exists at the time of the attempted write. Both are fundamentally lifetime issues and can then be handled explicitly by the user instead of implicitly by the language runtime.
In addition to the following operations...
get(), last(), length(), which work with either immutable or mutable referencesset(), pop(), push(), which require a mutable reference and can fail...a list also supports the following operations for dealing with capacity:
capacity() (either immutable/mutable ref), returns the unused slotsgrow() (requires a mutable ref), expands the capacitySince the capacity can only change through an exclusively owned mutable reference, reading capacity() doesn't need a mutable reference.
Regions/arenas cannot be handled the same way because regions support adopting elements without requiring a mutable reference. A region can thus grow while other immutable references exist, which is fine because readers cannot observe other readers of a region, but this also implies that exposing the capacity through immutable references would break referential transparency. This is why regions support the following operations:
adopt(), which works with either immutable or mutable referencescapacity(), grow(), both requiring mutable referencesSo what happens when adopt() is called on a region that is out of capacity? Failing (like lists do) is not an option because adopt() does not require exclusive ownership. Failing would thus depend on how other readers have used the region and break referential transparency.
Instead, adopt() simply turns into a no-op when a region is full, thus keeping the element that was meant to be allocated on the top of the stack. That doesn't affect correctness and is simply slightly less performant because the element might be compacted and moved more than if it had been kept in the region.
This feels more magical and potentially hard to predict than growing the region and moving the stack above it but is probably a better choice because it guarantees that the stack is never moved because something grows without an explicit grow(), neither for lists nor for regions. Having a single clear principle here feels important. That said, it would still be possible to simply double the size of the region and move the stack above it, if the implicit no-ops ever turn out to be a problem.