[Dlang-internal] DIP1000 discussion and testing: borrowing a range

Dicebot via Dlang-internal dlang-internal at puremagic.com
Sun Oct 16 13:00:41 PDT 2016


On 10/16/2016 10:30 PM, Walter Bright wrote:
> On 10/16/2016 7:02 AM, Dicebot wrote:
>>     Owner instance;
>>     // must work, lifetime of 'instance' exceeds one of x :
>>     scope x = instance.borrow();
>>     // must not work, infinite lifetime
>>     auto y  = instance.borrow();
>> }

> It works because 'scope' is inferred as a storage class when an
> expression that needs scope is used to initialize a local. y gets a
> subset of the life of instance. Doing such inference makes using
> -transition=safe far more palatable.

Great, thanks for explanation, this will need to be mentioned clearly
with example in DIP document (I'll make a PR once other uncertainties
are cleared too).

However, it also keeps compiling if I change it to use explicit
non-scope type:

// move Range definition outside and mark `borrow` @trusted
Range y = instance.borrow(); // compiles, but must require `scope Range y`

> BTW, reducing the examples to their minimums helps a lot.

This helps in debugging but doesn't help in defining good acceptance
tests. I am looking for the latter and that means "minimal snippet that
looks like useful code", not "minimal reduced test case" - and this is
exactly what is needed as part of scope PR test cases to evaluate it.

Now, I would be glad to provide minimal test cases for ease of debugging
too, but that is not possible until I can reason which behavior is bug
and which one is intentional. Getting your comments about why certain
things don't work helps to understand.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/dlang-internal/attachments/20161016/52cb806a/attachment-0001.sig>


More information about the Dlang-internal mailing list