[Dlang-internal] DIP1000 discussion and testing
Walter Bright via Dlang-internal
dlang-internal at puremagic.com
Sun Oct 30 23:43:48 PDT 2016
On 10/29/2016 10:33 PM, Dicebot wrote:
> On Sunday, 30 October 2016 at 02:17:36 UTC, Walter Bright wrote:
>> This is covered by my proposed modification:
>>
>> struct Tree
>> {
>> TreeRange range ( ) scope;
>> }
>
> Maybe I misunderstand what you propose in that case? You have said "if it is
> applied to a variable with no indirections", but `struct Tree` in my example
> does contain indirection in form of `head` pointer (as struct is composition of
> fields).
Since the caller cannot see inside the function, it must rely on the interface.
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.
It's just tracking the scope of expressions:
return x;
return x + 3;
return i ? x : y;
so they work through function calls:
return foo(x);
return foo(x + 3);
return foo(x, y);
The 'return scope' and 'return ref' make that work so that the compiler only has
to examine the function's interface, not its implementation.
More information about the Dlang-internal
mailing list