DMD 2.100, bring ont he attribute soup
Timon Gehr
timon.gehr at gmx.ch
Sun May 29 00:55:58 UTC 2022
On 28.05.22 12:55, Nick Treleaven wrote:
> On Friday, 27 May 2022 at 21:09:49 UTC, deadalnix wrote:
>>> void f(scope T);
>>>
>>> T v = new T; // can be stack allocated
>>> f(v);
>>
>> I don't think this is a valid optimization, because DIP1000 cannot
>> track indirections. Therefore, I could have an objects within the
>> subgraph reachable from `v` which escape and which itself can reaches
>> back to `v`.
>
> Can you give an example? The following currently compiles:
>
> ```d
> @safe @nogc:
>
> class C {
> C g() => this;
> }
>
> //C f(C c); // error
> C f(scope C c); // OK
> //C f(scope C c) { return c.g; } // error
>
> void main()
> {
> scope c = new C(); // allocated on the stack, scope currently required
> f(c);
> }
> ```
>
> If I switch in the third version of `f`, I get an error with -dip1000:
> scopeclass.d(7): Error: scope variable `c` assigned to non-scope
> parameter `this` calling scopeclass.C.g
```d
class D{
C c;
}
class C {
D d;
int x=3;
this(D d)@safe @nogc{
d.c=this;
this.d=d;
}
}
C foo(D d)@nogc @safe{
scope c = new C(d); // remove `scope` and program does not crash
return c.d.c; // escape c
}
void main(){
import std.stdio;
writeln(foo(new D)); // segfault
}
```
Not sure if this was already in bugzilla, added it:
https://issues.dlang.org/show_bug.cgi?id=23145
More information about the Digitalmars-d
mailing list