DIP69 - Implement scope for escape proof references

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Sun Dec 14 19:41:29 PST 2014


On Monday, 15 December 2014 at 02:45:04 UTC, Walter Bright wrote:
> 1. All inout actually does is reduce code copy/pasta, it is not 
> critical.

Being forced to duplicate every single function in two flavors to 
actually make scope system usable? This is as much critical as it 
can be.

> 2. This is what scope inference is all about.

Which only works with templates and lack of scope on arguments 
does not affect function body -> templates are not necessary, 
same as inout.

>> 2) at least optional transitivity to be able to express to 
>> protect with scope
>> data referenced by slice or owned linked list referenced from 
>> root node.
>
> 1. that won't work unless scope is a type constructor

I know and this is why I am leaning toward it being qualifier 
despite all related issues.

> 2. it can be achieved by using wrappers that only allow 
> by-scope references to their data (RC is an example of such a 
> wrapper)

It is viral approach and backwards incompatible one - we can't 
change signatures of Phobos functions to return Wrapped!(char[]) 
instead of char[] for example. While theoretically possible I 
can't call this approach practical - not until see some 
convincing application example.

>> In your tree example I would have never wanted scope 
>> protection of one specific
>> node of such tree - but a transitive scope protection of whole 
>> tree view
>> available through on of node pointers/references. It doesn't 
>> matter who and how
>> owns the data for borrowship implementation - only thing that 
>> matters that _it
>> is not me_.
>
> As I explained to Manu, transitive scope makes things like 
> doing a symbol table lookup, then putting a pointer to the 
> found symbol in an AST, not workable.

This sounds totally against my understanding of scope. I want 
scope exactly to prohibit such actions. However it is possible in 
slightly modified way - where you don't directly insert pointer 
to AST but use public method of AST control structure that checks 
if supplied scope pointer belongs to list of nodes it owns  and 
casts away scope after that.


More information about the Digitalmars-d mailing list