DIP1000: Scoped Pointers (Discussion)

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 12 16:49:14 PDT 2016


On 8/12/2016 2:03 PM, Timon Gehr wrote:
> On 12.08.2016 22:22, Walter Bright wrote:
>> I believe it does track across function boundaries, because function
>> parameters can be annotated.
> Yes, to some extent, but what the type system knows and makes use of at the call
> site is more informative than what can be tracked around function boundaries.
> The effect is that there are pieces of code that cannot be abstracted into their
> own functions, which creates friction.

I don't understand your comment.


>> Aggregate boundaries, no, because annotating fields with 'scope' is not
>> allowed, like 'ref' fields are not allowed.
> This rules out structs that wrap data and adapt it in some interesting way, a
> very common idiom in (generic) D code.

Consider:

     struct S { int* a, b; }

     int x;
     S s;
     s.a = &x;

should be semantically equivalent, as far as scope rules go, to:

     int x;
     int* a;
     a = &x;

(Note that 'scope' is inferred here.)

What would not work is:

     int x;
     S* ps = new S;
     ps.a = &x;


More information about the Digitalmars-d mailing list