[Dlang-study] [lifetime] Few root decisions to take on RC classes

Timon Gehr timon.gehr at gmx.ch
Mon Nov 2 13:54:05 PST 2015


On 11/02/2015 10:14 PM, Andrei Alexandrescu wrote:
> On 11/02/2015 03:24 PM, Timon Gehr wrote:
>> @noescape in the presented form is not modular, which will be painful
>> outside toy examples.
>
> I thought it can be made modular (save the attribute with the function
> signature, allow @noescape arguments to go to @noescape etc). What am I
> missing? Thx! -- Andrei

It is modular in the sense that it can be conservatively checked 
locally, but there will be cases where inlining a function or aggregate 
makes code compile that wouldn't otherwise, so it hinders composition, 
which would also be needed for modularity. Escape information only flows 
down the call tree but never up, nor does it flow across aggregate 
boundaries.


Simple examples:

C id(@noescape C x){ return x; }

C foo(@noescape C x){
     auto l=rc!C;
     auto bar(@noescape C y){
         return tuple(x,y);
     }
     auto r=bar(l);
     return r[0];
}


One other obvious example is something like:

void bar(){
     RC!(int[]) x;
     // ... (initialize x)
     foreach(a;x.map!foo){
         writeln(a);
     }
}


More information about the Dlang-study mailing list