Re: Leak-detection of references to scoped class instances

2019-11-29 Thread IGotD- via Digitalmars-d-learn
On Thursday, 28 November 2019 at 21:49:09 UTC, Per Also, what happens if `C` doesn't fit on the stack? This is OS specific I think. For example on Linux at the end of the stack there is a guard page and when you hit it the process will segfault.

Re: Leak-detection of references to scoped class instances

2019-11-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 25 November 2019 at 13:09:44 UTC, mipri wrote: class C { int x; this(int n) { x = n; } } int heap() { auto x = new C(2); // vgc: `new` causes a GC allocation return x.x; } /+ int example.heap(): sub rsp, 8 mov edi, OFFSET FLAT:example.C.__Class

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 25 November 2019 at 13:09:44 UTC, mipri wrote: gdc assembly. ldc eliminates the object entirely. DIP-1000 kicks comes to the rescue here aswell: class C { @safe pure nothrow @nogc: this(int x) { this.x = x; } int x; } C leakClass() @safe pure nothrow {

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 25 November 2019 at 13:09:44 UTC, mipri wrote: gdc assembly. ldc eliminates the object entirely. Thanks.

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread mipri via Digitalmars-d-learn
On Monday, 25 November 2019 at 12:08:54 UTC, Per Nordlöw wrote: On Monday, 25 November 2019 at 08:22:02 UTC, Jacob Carlborg wrote: On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote: I guess we need a builtin language qualifier for scoped classes for that to work, right? We have t

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 25 November 2019 at 08:22:02 UTC, Jacob Carlborg wrote: On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote: I guess we need a builtin language qualifier for scoped classes for that to work, right? We have that: scope a = new Object; — /Jacob Carlborg Ahh, nice. Does

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote: I guess we need a builtin language qualifier for scoped classes for that to work, right? We have that: scope a = new Object; — /Jacob Carlborg

Re: Leak-detection of references to scoped class instances

2019-11-24 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 24 November 2019 at 14:21:48 UTC, Adam D. Ruppe wrote: On Sunday, 24 November 2019 at 14:19:23 UTC, Per Nordlöw wrote: Why doesn't DIP-1000 include such escape analysis? did you enable it with the command line switch? furthermore i *think* it onyl works o @safe stuff, not @trusted

Re: Leak-detection of references to scoped class instances

2019-11-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 November 2019 at 14:19:23 UTC, Per Nordlöw wrote: Why doesn't DIP-1000 include such escape analysis? did you enable it with the command line switch? furthermore i *think* it onyl works o @safe stuff, not @trusted stuff.

Re: Leak-detection of references to scoped class instances

2019-11-24 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 24 November 2019 at 12:51:53 UTC, rikki cattermole wrote: "Allocates a class object right inside the current scope, therefore avoiding the overhead of new. This facility is unsafe; it is the responsibility of the user to not escape a reference to the object outside the scope." http

Re: Leak-detection of references to scoped class instances

2019-11-24 Thread rikki cattermole via Digitalmars-d-learn
"Allocates a class object right inside the current scope, therefore avoiding the overhead of new. This facility is unsafe; it is the responsibility of the user to not escape a reference to the object outside the scope." https://dlang.org/phobos/std_typecons.html#.scoped

Leak-detection of references to scoped class instances

2019-11-24 Thread Per Nordlöw via Digitalmars-d-learn
Why doesn't DMD detect invalid out-of-scope references to scoped class instances? Example: @safe: class C { @safe pure: this() { } int x; } @trusted unittest { C f() { import std.typecons : scoped; auto x = scoped!C(); return x; } auto c