DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1

Meta jared771 at gmail.com
Mon Nov 11 20:50:07 UTC 2019

I've never been comfortable with the fact that T[] can refer to 
any type of memory, GC-allocated or not (or T*, for that matter), 
but I think this DIP is not the right approach. It severely 
pessimizes one of the most common use cases of slices in order to 
prevent memory corruption when the slice does not refer to a GC'd 
array. While this could be a big gain, it is also definitely a 
huge loss in terms of how much code would be broken.

I completely agree, though, that the fact that ~ may change 
slices referring to non-GC'd memory to GC'd memory is not a good 
thing - I just think this DIP would break too much code.

I can't see a clear way forward, either, because at a fundamental 
level in the type system, D treats GC'd and non-GC'd pointers the 
same. Therefore, it would not be enough to introduce a new type 
that exclusively refers to GC-allocated memory (i.e., new T* / 
T[new], or whatever), because slicing would still have to be 
disabled for non-GC'd pointers, and appending would still have to 
be disabled for non-GC'd slices.

Would it be enough to put an assert in GC.realloc/extend/free 
that asserts the memory is GC-owned, maybe tied to a compiler 

More information about the Digitalmars-d mailing list