[Dlang-internal] DIP1000 discussion and testing
Mathias Lang via Dlang-internal
dlang-internal at puremagic.com
Sat Oct 22 08:52:17 PDT 2016
On Saturday, 22 October 2016 at 07:19:11 UTC, Walter Bright wrote:
> On 10/21/2016 1:30 AM, pineapple wrote:
>> There's this big language enhancement in the pipeline
>
> But it's not big.
>
> It's the same as 'return ref', which is already there, except
> it's 'return scope'. The examples on how it works all boil down
> to a couple lines of code.
Most people seem to disagree with that opinion.
I was looking at the DIP, and checked out the P.R. branch to test
it, and I cannot see how it could work if `scope` is not
transitive.
It is just pushing the problem one level down.
For example:
```
alias FunDG = void delegate () @safe;
struct Escaper
{
FunDG DG;
}
FunDG escapeDg1 (scope FunDG d) @safe
{
Escaper e;
e.DG = d;
return e.DG;
}
```
This compiles, and escapes a `scope delegate`.
Used `./src/dmd -transition=safe -dip25 -run test.d` to compile,
on commit:
`48b7815 - (HEAD, walter/return-scope) add lifetime checks (9
days ago) <Walter Bright>`. Did I miss something ?
Also, as others already mentioned, the DIP is quite confusing.
I read the whole thread and AFAICS people got confused because of
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md#escaping-via-return which mentions that "taking the address of a local [...] is restrictive." and continue with "The `scope` storage class was introduced which annotates the pointer.", which doesn't quite relate to the previous sentence if scope is not meant to remove this restriction.
The examples also use a mix of `@safe` and non-annotated
function, which doesn't help understanding since it's explicitly
stated that those checks are only done in @safe code (why?).
Finally, I agree with Dicebot that having scope infered when the
type is specified is extremely confusing, and makes writing test
cases, and code in general, much more complicated.
More information about the Dlang-internal
mailing list