BetterC: make try-finally work without exceptions#7305
BetterC: make try-finally work without exceptions#7305dlang-bot merged 1 commit intodlang:masterfrom
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. |
|
This seems to be a bit of an anti feature. Shouldn't you instead just detect if an eh region needs to be generated? Also, libgcc supports handling of dwarf EH as a "pass-through" between C and interfacing languages. |
It needs to be generated if there is RAII, and then the D personality routine is needed, which is in druntime.
I know. And this should still work with that, it's just the destructors won't get called when unwinding is done. |
|
As this is a backend-only change I'm not too concerned about this, but I'd rather like to see an implementation which:
This then also optimizes code like this: void foo()
{
scope(exit) checkErrors();
//nothrow code goes here....
} |
|
Hmm, seems like #7304 proposes such statement level nothrow tracking. So wouldn't it make sense to use |
|
@jpf91 those sorts of optimizations will add a lot of value, and I intend to add them in the future. But they aren't trivial to implement, so one step at a time. Currently, not having RAII for BetterC is a major blocker, and this PR solves that issue. |
7ac13fa to
2dc02e4
Compare
| config.exe = EX_LINUX; | ||
| config.ehmethod = EH_DWARF; | ||
| config.ehmethod = betterC ? EH_NONE : EH_DWARF; | ||
| if (!exe) |
There was a problem hiding this comment.
Yellow in codecov? That's new. What does it mean?
| #if SCPP | ||
| if (config.exe == EX_WIN32) | ||
| { usednteh |= NTEH_try; | ||
| #endif |
There was a problem hiding this comment.
Oy this use of the preprocessor is quite nasty... far as I understand exactly one of MARS or SCPP must be defined. Then this is quite a bit easier on the eyes:
#if MARS
if (config.ehmethod == EH_NONE)
{
}
else
if (config.ehmethod == EH_WIN32)
#else
if (config.exe == EX_WIN32)
#endifThere was a problem hiding this comment.
I avoid that style now because MARS isn't on-off. The back end supports multiple separate builds - SCPP, SPP, HTOD, and MARS.
There was a problem hiding this comment.
All I'm saying is the code doesn't work unless exactly one of MARS and SCPP is defined, and that's difficult to infer from the code.
There was a problem hiding this comment.
I know, but in the rest of the code I removed the #else because of bugs and confusion about what code was for which build.
There was a problem hiding this comment.
This particular piece of code is ugly, and I'm going to straighten it out in a follow-on, as it will require some refactoring. In the meantime, it gets the RAII working.
Instead of relying on the exception unwinding mechanism, this just calls the finally block. Since destructors and scope statements are rewritten to use try-finally, they'll work with this.