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

Nicholas Wilson iamthewilsonator at hotmail.com
Mon Nov 11 11:26:49 UTC 2019

On Monday, 11 November 2019 at 10:27:26 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community 
> Review for DIP 1025, "Dynamic Arrays Only Shrink, Never Grow":

The rationale is severely lacking:

Any issue related to the GC is completely orthogonal to any 
issues with memory safety.
The first example is buggy, but is @system because it uses free, 
and thus the onus is on the user.
The second example is well defined because ~= copies if the 
capacity is exceeded[1].

The prior work section lists no references and does not present 
any logical connection to the ideas presented in the rationale.

The breaking changes are massive and not well argued for.
The suggested workaround of

1) a = a ~ b;

in place of

2) a ~= b;

is functional identical, thus any issues present in 2 are also 
present in 1. The suggestion that doing so in a loop would create 
more garbage is false as it is functionally identical.

The author should revisit the core assumptions made and rewrite 
the DIP accordingly with references for prior art. If the issue 
in example one is considered bad enough to warrant doing 
something about then that issue should be tacked specifically, 
starting perhaps with a druntime / GC option to later 
statistics/log when an unmanaged slice is appended to.


void main()
     import std.stdio;
     enum { dead, alive }
     foreach (i;0 .. 10000)
         int[] cat = new int[i+1];
         cat[i] = alive;
         int[] b = cat;
         b ~= 1;
         b[i] = dead;
         if (i % 1000)
             import core.memory;

More information about the Digitalmars-d mailing list