Don't generate exception handling code if Throwable is not declared#7786
Don't generate exception handling code if Throwable is not declared#7786dlang-bot merged 1 commit intodlang:masterfrom JinShil:optional_throwable
Throwable is not declared#7786Conversation
|
Thanks for your pull request, @JinShil! 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. |
wilzbach
left a comment
There was a problem hiding this comment.
How about adding the second example to the testsuite too?
src/dmd/dclass.d
Outdated
| extern (C++) class ClassDeclaration : AggregateDeclaration | ||
| { | ||
| extern (C++) __gshared | ||
| extern (C++) static __gshared |
There was a problem hiding this comment.
It's already __gshared. DMD should emit a warning when both are used as this doesn't make any sense.
There was a problem hiding this comment.
There's a few concerns I have about that:
But I'll add it if it's desired, and I can figure out how to compile and link separately in the test suite. |
src/dmd/backend/mscoffobj.c
Outdated
| SegData[seg]->SDbuf->write(name, strlen(name)); | ||
| SegData[seg]->SDbuf->writeByte('"'); | ||
| return true; | ||
| if (name && strlen(name) > 0) |
There was a problem hiding this comment.
This isn't checked in cgobj.c, why here? What does it have to do with Throwable?
There was a problem hiding this comment.
It's because the tests are compiled with defaultlib=, and the mircosoft linker rejects empty arguments to /DEFAULTLIB:. It's just necessary to get the tests to pass on Windows.
There was a problem hiding this comment.
BTW, in glue.d where this function is called:
if (global.params.mscrtlib && global.params.mscrtlib[0])
objmod.includelib(global.params.mscrtlib);
so now the check is being done twice. Also, the strlen can be safely replaced with [0].
src/dmd/link.d
Outdated
| cmdbuf.writeByte(' '); | ||
| cmdbuf.writestring("/DEFAULTLIB:"); | ||
| writeFilename(&cmdbuf, f); | ||
| } |
There was a problem hiding this comment.
This looks like it belongs in a separate PR?
There was a problem hiding this comment.
I could do that, but I don't have a test to verify it. This PR has the logic necessary to create a test that actually benefits from defaultlib= (i.e. no defaultlib). So, I think they need to go together.
There was a problem hiding this comment.
Should clearly set up the code so that no default lib has defaultlib set to null, not a 0 length string.
src/dmd/statementsem.d
Outdated
|
|
||
| if (!global.params.useExceptions) // if not worrying about exceptions | ||
| // if not worrying about exceptions | ||
| if (!global.params.useExceptions || !ClassDeclaration.throwable) |
There was a problem hiding this comment.
Elsewhere is written useExceptions && throwable, so I suggest rewriting this to be consistent:
if (!(global.params.useExceptions && ClassDeclaration.throwable))
src/dmd/link.d
Outdated
| writeFilename(&cmdbuf, global.params.libfiles[i]); | ||
| // The `/DEFAULTLIB:` argument cannot be empty | ||
| const f = global.params.libfiles[i]; | ||
| if (f && strlen(f) > 0) |
There was a problem hiding this comment.
replace strlen(f) > 0 with f[0]
There was a problem hiding this comment.
also, perhaps this check should be done where libfiles[] is filled, rather than where it is used.
|
Good idea! |
|
The tests in this PR require Per @WalterBright's suggestion in prior comments in this PR, @WalterBright, this is ready for another look. Thanks. |
This PR is a follow up to #7395 and #7768. It is to
Throwablewhat #7395 and #7768 were toModuleInfo.In D, anything that can be
thrown must inherit fromobject.Throwable. Therefore, ifobject.Throwabledoes not exist, no exception handling code should be generated, and any attempt tothrowshould emit compilation error.With #7395, #7768, and this PR, we can now generate a minimal executable with almost no boilerplate and produce very small resulting binaries.
Example 1
object.d
main.d
Compile
Result
Example 2
object.d
main.d
Compile and link
Result
Again, this will be of interest to users wishing to incrementally or partially port D to new platforms, users hoping to target resource constrained platforms, and users wishing to use D as a library from other languages without druntime.