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
emit better code for try-finally when function does not throw #7333
Conversation
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
b6a8322
to
a995bb9
Compare
awesome possum! |
@WalterBright check the autotester |
Yeah, I know. It's not ready yet. Turned off automerge. |
bace0ee
to
8181759
Compare
This has an odd failure on Win32. I get two failures:
and:
In test16031.d it says:
and in cppeh2.d it says:
How can the tests fail on Win32 when they are disabled on Win32? |
8181759
to
7ab71d4
Compare
The tests are still run even if disabled, but the result is ignored (and shows |
Thanks for the tip. I retrieved and tried running d_do_test:
I.e. it works normally. Not sure where to go with this now. |
cad9c11
to
c02fa7b
Compare
I wound up disabling the optimization for Win32 and filing a bug report for it: |
@CyberShadow I can't tell if the DAutoTest failure is the fault of this PR or not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise looks good.
Would be great if we could generally improve the non-exception code-path, currently dmd uses a call to jump to the finally handler, which trashes the return prediction.
@@ -523,6 +524,8 @@ class FuncDeclaration : public Declaration | |||
CompiledCtfeFunction *ctfeCode; // Compiled code for interpreter | |||
int inlineNest; // !=0 if nested inline | |||
bool isArrayOp; // true if array operation | |||
bool eh_none; /// true if no exception unwinding is needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmh, that doesn't belong in the frontend, any other place you could store or retrieve this flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flag is per-function, and is detected by the font end. It is later transferred to the backend's symbol for that same function.
It's a temporarily code.dlang.org issue, the dub version used doesn't yet know about https://code-mirror.dlang.io/. Unfortunately DAutoTest still has no retry button, so simply push a new commit to retest. |
From the build log, it looks like an intermittent network failure:
As clearly ddox is a known package: http://code.dlang.org/packages/ddox. The error message is trying to say that dub has tried to contact the registry in order to find The error message is quite obscure, but has since been improved (along with the addition of registry mirrors to remedy the network failures) in later versions of Dub, but dlang.org's build uses DMD 2.072.2, and hence why the the dub version used is probably quite old. To fix this, you need to restart the build and at the moment the only way is to rebase the branch of your pull request and force push it. |
I know, but this is just one more incremental step to get there. I spent 3 days trying to get just this to work, and it still fails on Win32 for mysterious reasons. Debugging eh code is stupidly hard. Having I lost at least one day because asserts are disabled in the front end. I need to fix that, too. The asserts had found the problem, but being disabled, things just went merrily onwards and died randomly somewhere else. |
c02fa7b
to
9327d15
Compare
Ok, changed a comment to get the DAutoTest to run again. |
|
Let's give it a try then #7344. |
That's an idiom that we use everywhere else, a bit more tricky due to the unclear mingw/cygwin environment. |
BTW, getting all these EH optimizations in should substantially reduce the cost of "zero cost" RAII exceptions (haha). I had forgotten how much better code my pre-exceptions C++ compiler generated for RAII. |
See #7345 |
Even if a function is marked
nothrow
, the exception unwind tables must still be there because a try-catch could still be there that absorbs the exception. This PR marks a function internally if it does not throw and does not have a try-catch. This knowledge is then used to omit building exception unwind tables, and the code gen does not have to assume that an external unwinder is calling thefinally
blocks. The code emitted (at least for Windows) is substantially less.