DIP 1008 Preliminary Review Round 1

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri May 19 19:25:45 PDT 2017


On 5/19/2017 6:23 PM, Meta wrote:
> Like others, I do not like the special-casing of `throw new`. However, several
> designs have already been explored and found lacking. This proposal also has the
> advantage that it (hopefully) doesn't break existing code and all existing code
> gets the benefit for free. I think this benefit has been hugely underestimated;
> we must consider that large swathes of code that were previously non- at nogc due
> to exception allocation can now be *inferred automatically* to be @nogc. That's
> a huge advantage and may be worth the special case.

We'll be doing more invisible special casing in the future. For example,

   void foo(scope string s);
   ...
   string s;
   ...
   foo(s ~ "abc");

This array concatenation does not need to be done with the GC. It's not 
fundamentally different from what the compiler does now with:

   s = "abc" ~ "def";

not doing a GC allocation, either. The compiler also detects when it can 
allocate a closure on the stack rather than on the GC. We expect the compiler to 
do such transformations.

In general, if the compiler can determine the lifetime of an allocation, and can 
control "leakage" of any references to that allocation, then it is fair game to 
not use the GC for it.

The recent 'scope' improvements have uncovered a lot more opportunities for 
this, and DIP 1008 is the first fruit of it.


More information about the Digitalmars-d mailing list