Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 13586 - Destructors not run when argument list evaluation throws #4078

Merged
merged 1 commit into from Oct 26, 2014

Conversation

WalterBright
Copy link
Member

@WalterBright WalterBright force-pushed the fix13586 branch 6 times, most recently from e255f68 to 48dac1f Compare October 21, 2014 20:41
@WalterBright
Copy link
Member Author

This is necessary for reference counting to work reliably.

@@ -774,7 +774,7 @@ STATIC void defstarkill()

#if 1
/* The following program fails for this:
import core.stdc.stdio;
import std.c.stdio;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A merge error I'd overlooked. Fixed.

@yebblies
Copy link
Member

Why can't this be done entirely in the glue layer? Have you tested that the modifications to the ast don't break ctfe?

Why is the new volatile stc necessary? Would it be necessary if this was all done in the glue layer instead of half in the frontend?

@WalterBright
Copy link
Member Author

Why can't this be done entirely in the glue layer?

Note the changes to how struct value arguments are handled in functionParameters(). Doing it in the glue layer would require awkward detection and undoing of those changes. The new code does it all in the front end. I thought about this for several days before deciding this was the most practical approach.

Also, note that the glue layer still handles the actual insertion of destructor code.

Also, the logic in the glue layer should be minimal. There's already too much in there. The idea with lowering in the front end is to reduce code and bugs by exploiting commonality through rewrite rules.

Have you tested that the modifications to the ast don't break ctfe?

I don't know why it would. Why should it? Note that what this logic does is equivalent to:

   (S(), foo(), T())

which had better work in CTFE.

Why is the new volatile stc necessary?

In order to prevent data flow optimizations to it, since the destructor code can be called out of line. This follows the optimizer logic that basically disables optimizations in finally blocks.

Would it be necessary if this was all done in the glue layer instead of half in the frontend?

Yes.

@yebblies
Copy link
Member

I don't know why it would. Why should it? Note that what this logic does is equivalent to:

   (S(), foo(), T())

which had better work in CTFE.

I can see for CallExp that argprefix is getting Expression::combined, but for NewExp it's getting stored in the ast... How is the interpreter going to know about these ast nodes and call them correctly?

@WalterBright
Copy link
Member Author

Ah, good point. Will check it out. Note that this is yet another reason for lowering rather than putting the logic in the glue layer!

@yebblies
Copy link
Member

Yeah, or at least an argument for putting the entire thing in one layer. Sometimes a higher-level construct is easier to interpret than a lower one.

@WalterBright
Copy link
Member Author

Added CTFE support.

@9rnsr
Copy link
Contributor

9rnsr commented Oct 23, 2014

Also, note that the glue layer still handles the actual insertion of destructor code.

All destructor calls must be handled in AST for correct CTFE interpretation and temporary struct objects.
For example: Issue 13095 - Someteims struct destructor is called if constructor throws

@WalterBright
Copy link
Member Author

@9rnsr those are separate issues and should not be handled by this PR. If every destructor issue was handled by one PR, then it would not be very reviewable.

@WalterBright
Copy link
Member Author

Sigh, another heisenbug in std.concurrency

@@ -3351,6 +3351,90 @@ void test13303()

/**********************************/

void test13586()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use hard tab.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@9rnsr
Copy link
Contributor

9rnsr commented Oct 26, 2014

I'm not sure how the backend change is related with the front-end fix. I'd suggest to separate backend changes in its own commit with explanation commit log.

@9rnsr
Copy link
Contributor

9rnsr commented Oct 26, 2014

Note that, the co-working of front-end and glue-layer will be harmful for CTFE. Actually, this PR does not fix issue 13586 during CTFE. @WalterBright, is that intended?

@WalterBright
Copy link
Member Author

This PR produces actual expressions in the dtor trees, and so also needed a bit of upgrading the back end to handle it. The front and back end changes need each other. Also, I don't know how to test for those other back end changes, as this PR caused a slightly different path to be taken through it which exposed a couple problems. They're simple enough fixes.

@WalterBright
Copy link
Member Author

Note that, the co-working of front-end and glue-layer will be harmful for CTFE.

Do you mean the insertion of dtors by e2ir.c?

Actually, this PR does not fix issue 13586 during CTFE. @WalterBright, is that intended?

As far as I can tell, CTFE has never handled destructors in expressions. This PR does not fix that, that is true, but it is a separate bug and should be handled separately.

@9rnsr
Copy link
Contributor

9rnsr commented Oct 26, 2014

Current CTFE engine does not specially handle destructor calls those are inserted in glue layer.
But OK, at least fixing runtime behavior would be better than nothing.

@9rnsr
Copy link
Contributor

9rnsr commented Oct 26, 2014

Auto-merge toggled on

9rnsr added a commit that referenced this pull request Oct 26, 2014
fix Issue 13586 - Destructors not run when argument list evaluation throws
@9rnsr 9rnsr merged commit 11276b8 into dlang:master Oct 26, 2014
@WalterBright WalterBright deleted the fix13586 branch October 26, 2014 19:00
@sinkuu
Copy link

sinkuu commented Nov 3, 2014

This PR introduced a regression(ICE).
https://issues.dlang.org/show_bug.cgi?id=13673

@MartinNowak
Copy link
Member

This seems to have introduced another regression.
Issue 14443 – [Reg 2.067.0] Incorrect double freeing of reference counted struct

@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=13720

@9rnsr
Copy link
Contributor

9rnsr commented Feb 9, 2016

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=15661

9rnsr added a commit to 9rnsr/dmd that referenced this pull request Feb 9, 2016
By the PR dlang#4078, some preparation code has been inserted before a constructor
call expression. Then, AssignExp has failed to recognize the ctor call form.
9rnsr added a commit to 9rnsr/dmd that referenced this pull request Feb 9, 2016
By the PR dlang#4078, some preparation code has been inserted before a constructor
call expression. Then, `AssignExp` had failed to recognize the ctor call form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants