radical ideas about GC and ARC : need to be time driven?

via Digitalmars-d digitalmars-d at puremagic.com
Mon May 12 01:44:51 PDT 2014


On Monday, 12 May 2014 at 04:22:21 UTC, Marco Leise wrote:
> On the positive side the talk about Rust, in particular how
> reference counted pointers decay to borrowed pointers made me
> think the same could be done for our "scope" args. A reference
> counted slice with 3 machine words could decay to a 2 machine
> word "scoped" slice. Most of my code at least just works on the
> slices and doesn't keep a reference to them. A counter example
> is when you have something like an XML parser - a use case
> that D traditionally (see Tango) excelled in. The GC
> environment and slices make it possible to replace string
> copies with cheap slices into the original XML string.

Rust also has a solution for this: They have lifetime 
annotations. D's scope could be extended to support something 
similar:

     scope(input) string getSlice(scope string input);

or with methods:

     struct Xml {
         scope(this) string getSlice();
     }

scope(symbol) means, "this value references/aliases (parts of) 
the value referred to by <symbol>". The compiler can then make 
sure it is never assigned to variables with longer lifetimes than 
<symbol>.


More information about the Digitalmars-d mailing list