Skip to content

argprefix: fix evaluation order and missing cleanup bug [bugzilla 14903]#5151

Merged
MartinNowak merged 2 commits intodlang:masterfrom
kinke:argprefixD
Jan 31, 2016
Merged

argprefix: fix evaluation order and missing cleanup bug [bugzilla 14903]#5151
MartinNowak merged 2 commits intodlang:masterfrom
kinke:argprefixD

Conversation

@kinke
Copy link
Contributor

@kinke kinke commented Oct 1, 2015

DDMD port of #4885.

Previously, if the last potentially throwing argument expression's
`type->baseElemOf()` yielded a struct type, the arg would incorrectly
NOT be added to `eprefix`.
This led to the destructor gate being set to true (disabling all dtors)
right BEFORE evluating the last potentially throwing argument. So in
case it threw, no dtors would be triggered.
If argprefix is required, make sure it covers the very first argument up
to and including the last potentially throwing argument. Only evaluate
subsequent arguments directly.
This also includes ref and out params, but not lazy ones.

Note that previously, `appendToPrefix` would be set by the first arg with
dtor (if a subsequent arg may throw), and only reset when processing the
last throwing arg (i == lastthrow).
So all non-ref/out/lazy args inbetween would be added to `eprefix`,
leading to this staggering evaluation order:

  [firstDtor..lastThrow (except for ref/out/lazy)]
  [0..firstDtor]
  [firstDtor..lastThrow (only ref/out/lazy)]
  [lastThrow..$]

Also prepare for potential right-to-left arguments evaluation order
(array ops).
@kinke
Copy link
Contributor Author

kinke commented Nov 1, 2015

Am I really the only one deeming this important enough to be included in 2.069?

@dnadlinger
Copy link
Contributor

I agree, this should have really gone into 2.069. It might be too late now, though, since it's not really a regression fix. (ping @MartinNowak)

@MartinNowak
Copy link
Member

Sorry, we won't merge something risky into stable, and just looking at the diff is pretty hard.
I'm all for fixing this, but don't have enough resources to review this atm. At best you keep track of your work on our trello board (makes it easier for us to plan time for reviews). Just send me a mail so I can add you.

@kinke
Copy link
Contributor Author

kinke commented Jan 25, 2016

So another release will pass by... just let me express that waiting for a pull fixing 2 rather horrible issues (missing dtor calls + totally unintuitive argument evaluation order with potentially nasty side fx) to be merged is pretty annoying. The first pull was for C++ dmd back in August, i.e., 5 months ago; it's been green since then, so it cannot be that wrong - and by no means more wrong than the current implementation ;). If I wasn't part of the community already (to some limited extent), I'd be off for good; if it had been like this with LDC too, I would have never gotten involved. No offense to anyone (especially @MartinNowak), but we should try not to scare off new people with a mindset similar to mine, by finding a better prioritization system.

@andralex
Copy link
Member

@WalterBright @MartinNowak @yebblies now with 2.070 out the door what do you guys think about discussing this?

@MartinNowak
Copy link
Member

You're absolutely right @kinke, will try to review this within the next few days.
argprefix: fix evaluation order and missing cleanup bug [bugzilla 14903] on Active | Trello

by finding a better prioritization system

We can't currently keep up with github, but if you want to bring up something important, please participate in our spring planings or simply write a mail.

Are you aware of Issue 14708 – destructor for temporary not called during stack unwinding and #5110 (comment).
We don't currently have a proper way to handle exceptions on expression level, only for statements.
The dtors of expressions are added as IR ops (appendDtor or so), lacking any attribute inference.

@kinke
Copy link
Contributor Author

kinke commented Jan 28, 2016

Thanks for the follow-up. 👍

I'm at work now so I can't dig into the 2 mentioned issues. But they may very likely be fixed by this. As I said, one thing is the args evaluation order. The other one is a bug wrt. to premature disabling of the temporaries' dtors in case the right-most potentially throwing arg does throw. Disabling is only okay if the callee gets actually called, as it will destruct the args. The previous code disabled all dtors right before evaluating the last potentially throwing arg though (edit: if it yielded a struct, see 1st commit msg), so no dtors were called if it did throw. That's a short summary to give you the required context. ;)

We don't currently have a proper way to handle exceptions on expression level, only for statements.

We had to extend LDC for this to work; it keeps a stack of live temporaries to be destructed for the current statement, and takes care of destructing them on a throw. This is the other part of issue 14903, and isn't tackled by this PR. The TODO parts in the tests file are related to this aspect...

@MartinNowak
Copy link
Member

We had to extend LDC for this to work; it keeps a stack of live temporaries to be destructed for the current statement, and takes care of destructing them on a throw.

That would be a good solution, and one that could mostly be implemented in the frontend.

@MartinNowak
Copy link
Member

Auto-merge toggled on

@kinke
Copy link
Contributor Author

kinke commented Jan 31, 2016

Thank you very much!

MartinNowak added a commit that referenced this pull request Jan 31, 2016
argprefix: fix evaluation order and missing cleanup bug [bugzilla 14903]
@MartinNowak MartinNowak merged commit 944756b into dlang:master Jan 31, 2016
@kinke kinke deleted the argprefixD branch January 31, 2016 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants