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

Steven Schveighoffer schveiguy at gmail.com
Mon Nov 11 16:45:16 UTC 2019


On 11/11/19 5:27 AM, Mike Parker wrote:
> This is the feedback thread for the first round of Community Review for 
> DIP 1025, "Dynamic Arrays Only Shrink, Never Grow":
> 
> https://github.com/dlang/DIPs/blob/1b525ec4c914c06bc286c1a6dc93bf1533ee56e4/DIPs/DIP1025.md 
> 
> 
> All review-related feedback on and discussion of the DIP should occur in 
> this thread. The review period will end at 11:59 PM ET on November 25, 
> or when I make a post declaring it complete.
> 
> At the end of Round 1, if further review is deemed necessary, the DIP 
> will be scheduled for another round of Community Review. Otherwise, it 
> will be queued for the Final Review and Formal Assessment.
> 
> Anyone intending to post feedback in this thread is expected to be 
> familiar with the reviewer guidelines:
> 
> https://github.com/dlang/DIPs/blob/master/docs/guidelines-reviewers.md
> 
> *Please stay on topic!*
> 
> Thanks in advance to all who participate.

This is a question of terminology. The dynamic array type in D is 
specified to be a slice. This has extreme benefits that I think we all 
will lament if this goes away.

As I've said before, treating the slice type as the array type is super 
confusing and not technically true. A dynamic array owns its own data, 
the slice does not. In D, the dynamic array is created and maintained 
*typeless* in the GC. It's owned by the GC. A slice can point at a 
dynamic array, stack-allocated data, global/thread-local data, a 
malloc-allocated array, or any other piece of memory that you can 
possibly point at. As soon as you append to it, it NOW points at a 
GC-allocated array. This should be neither surprising, nor a problem, IF 
you adopt the right terminology.

A fix here could be to actually DEFINE the dynamic array type, and allow 
the user to fetch it, and understand how it works. You can continue to 
allow the slice to be an interface to it, or you can use it directly. 
Please email me if you want more details.

I 100% agree with Adam, just put @nogc if you don't want to use the GC. 
This is a huge breaking change, and the much better solution is to make 
the desired behavior opt-in. A middle ground could be a newly defined 
"slice" type that can be used to opt-in.

I'd say no to this change, unless we are talking D3. And if that's the 
case, let's start talking about all the other things we want to fix ;)

-Steve


More information about the Digitalmars-d mailing list