Bug 24084 – Add -nothrow Switch to Compiler

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-13T21:20:48Z
Last change time
2023-08-18T00:29:03Z
Keywords
pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2023-08-13T21:20:48Z
dmd itself (and presumably others) do not throw Exceptions, preferring other methods for dealing with errors. There is a cost, however, in supporting Exceptions even when they are never thrown. The cost is in adding stack unwinders for things like RAII objects, and preventing numerous optimizations across try-catch boundaries. Adding `nothrow` to all the code in a project turns out to be an inordinate amount of work if the program is large. Putting `nothrow:` at the top of the module doesn't influence the status for member functions in a class or struct, the `nothrow:` will have to be repeated for each class/struct. Taking a cue from gdc, it seems much more practical to add a -nothrow switch to the compiler which doesn't add the stack unwinders and enables the optimizations. This capability is already there for -betterC code, this would just enable it for regular D code.
Comment #1 by dlang-bot — 2023-08-13T21:49:35Z
@WalterBright created dlang/dmd pull request #15536 "fix Issue 24084 - Add -nothrow Switch to Compiler" fixing this issue: - fix Issue 24084 - Add -nothrow Switch to Compiler https://github.com/dlang/dmd/pull/15536
Comment #2 by maxhaton — 2023-08-14T01:09:25Z
What is are "stack unwinders" (i.e. plural)? Some kind of stack unwinding implementation is still required regardless of whether exceptions are used so you can give a proper error message when something goes wrong.
Comment #3 by bugzilla — 2023-08-17T00:07:53Z
A stack unwinder goes up the stack executing finally blocks until it finds a matching catch.
Comment #4 by dlang-bot — 2023-08-18T00:29:03Z
dlang/dmd pull request #15536 "fix Issue 24084 - Add -nothrow Switch to Compiler" was merged into master: - e49b74dbcff9534b4ca262a2a62f525c222d8a5e by Walter Bright: fix Issue 24084 - Add -nothrow Switch to Compiler https://github.com/dlang/dmd/pull/15536