[Issue 14078] Call DTor for stack allocated objects

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jan 29 14:44:31 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14078

--- Comment #5 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
(In reply to rswhite4 from comment #4)
> I'm not talking about emplace. That is completely irrelevant. My thought was
> that the compiler should recognize that a2 is stack allocated and therefore
> call the dtor. Therefore the label "enhancement".
and i'm asking you how compiler has to do that. what kind of magic it should
use to gain that knowledge? remember that it must be done in compile-time, so
compiler can generate correct call to dtor. or you are proposing to check *all*
class variables when they going out of scope to determine somehow if they
points to the stack space which was allocated in the current scope, therefore
building very fragile detection (remember that compiler is free to reuse some
stack space if it sees that stack variable is already dead; DMD doesn't do data
flow analysis yet, but ldc and gdc is able to… sometimes), and making *all*
class usage slow for the sake of changing rarely used thing?

i simply can't see how this can be done, so i'm asking you for sample code.
maybe i'm missing some obvious things here.

> > > But your example with malloc could be true, but I'm sure that the DTor of a2
> > > should be called at least at the end of the programm. The compiler should be
> > > able to do that, even without any AI. ;)
> > class dtors are not guaranteed to be called at all. if someone will change
> > GC so it will stop calling dtors, it will break nothing by the specs. and
> > this is not an oversight.
> That is new to me. Ok, then it is probably impossible.
> I thought at least it would be helpful to call all remaining dtors at the
> end of the program.
> If that is not desired I will close this issue.
that just can't be done with good predictability and without throwing in
massive code analysing for almost nothing. this will significantly slow down
the compiler, made it much more complex and will not give any significant win.

> > > > if you want stack-allocated classes with automatic dtors, why don't use
> > > > `std.typecons.scoped`?
> > > It is IMO not well implemented.
> > please, can you show the cases where it's not working, so we can fill
> > bugreports and somebody will fix it?
> Look at the code. One thing is that the buffer is overproportional. But that
> is not the topic.
it's still interesting, so maybe you can start an NG discussion about it?

--


More information about the Digitalmars-d-bugs mailing list