[Dlang-internal] DIP1000 discussion and testing
Dicebot via Dlang-internal
dlang-internal at puremagic.com
Mon Oct 31 01:08:06 PDT 2016
On Monday, 31 October 2016 at 06:43:48 UTC, Walter Bright wrote:
> If the returned pointer is or is not derived from the value of
> the scope parameter is immaterial, the caller will act as if
> it is - meaning that the scope of the returned value will be
> restricted to being the same scope of the argument.
Is it how you want to change the implementation or how you intend
it to work now? Because currently it acts differently and no
lifetime restriction ever happens in absence of explicit `return
scope` annotation:
int* foo ( scope int* );
int* global;
void main () {
scope int* ptr;
global = foo(ptr); // compiles
}
-----------------------------
Let's get back to the old snippet as you haven't answered my
question:
struct Tree
{
Node* head;
TreeRange range ( ) scope;
}
Per my understanding, it is roughly equivalent to this:
struct Tree { Node* head; }
TreeRange range ( scope ref Tree this );
With current rules `scope` here is completely ignored because
`this` is already a reference and thus is not allowed to escape.
And `TreeRange` lifetime has no relation with `this` lifetime,
because such relation is only defined by `return scope`/`return
ref`.
Now in http://forum.dlang.org/post/nusi80$4h0$1@digitalmars.com
you propose to make so that such `scope` annotation does indeed
transfer lifetime: ".. the design ignores 'scope' if it is
applied to a variable with no indirections. But we can make it
apply". But that does not seem applicable to discussed example as
struct Tree does contain indirections.
Another issue is that would be completely out of line from
existing difference between `scope` and `return scope`.
More information about the Dlang-internal
mailing list