Andrei Alexandrescu wrote:
Following work on typechecking synchronized methods, Walter and I were discussing about managing escaping references to objects that wouldn't actually agree to escaping. The problem is that today a value has no idea that its address is being taken, so it has no saying in that.

To compensate for that, my idea was to allow @disable on opUnary!"&". Walter suggested allowing "scope" as a property of a struct:

scope struct Transitory
{
    ...
}

A scope struct cannot have its address taken. You can take addresses of its members (access permitting), but you can't take the address of any other struct that has at least one scope struct as a direct member. For example:

struct A
{
    int x;
    Transitory tr;
}

A will also be scope. So scope has this funny way of propagating outwards, as opposed to qualifiers, which propagate inwards.

This is as much as we have in terms of a design right now, so definitely it stands some more fleshing out. If gotten right, scope should allow defining a number of useful idioms, such as pass-down values, unique/lent objects, and the such.

Working against escapes has long been a problem, and with scope we're hoping to strike a balance between useful and simple.

Please share any thoughts you might have.

Why is this useful?

Reply via email to