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

Andrei Alexandrescu andrei at erdani.com
Sun Nov 1 16:20:40 PST 2015


On 11/1/15 4:14 PM, Martin Nowak wrote:
> - If the compiler knows a reference has a limited lifetime
>    it could check for @noescape making most of RC implementable
>    in a library.
>
>    struct RC
>    {
>      Object get() return; // lifetime of Object is bound to RC, compiler
> could check any function called on Object for @noescape
>    }

Yah, I think it's worth exploring a variant in which we annotate 
@noescape methods and then only allow those methods to be called from 
RC!T.get.

Note, however, that we may end up with a more conservative scheme. Consider:

class Widget
   static Widget g;
   void fun()
   {
     g = this;
   }
}

If we make the entire Widget reference-counted, the compiler knows how 
to make the code work. If we go the @noescape route, this code and 
others like it will be statically disallowed. So we end up with 
something more restrictive (or more complicated if we decide to allow 
certain escape patterns).


Andrei


More information about the Dlang-study mailing list