Repository navigation
Conversation
| @@ -0,0 +1 @@ | |||
| import core.memory; | |||
There was a problem hiding this comment.
A test case should be minimal and self-contained. Importing druntime creates a very large deps file which is fragile, as any change could alter that output and require updating the this test.
| `-deps` no longer causes spurious `-betterC` errors in unreferenced modules | ||
|
|
||
| Using `-deps` together with `-betterC` previously caused spurious errors | ||
| in transitively imported druntime modules the user never referenced — | ||
| `throw` statements in `core.exception` and GC array literals in | ||
| `core.time` being the most common. | ||
|
|
||
| This happened because `-deps` triggered `semantic3OnDependencies`, which | ||
| forced full function-body analysis on every transitively imported module. | ||
| Under `-betterC`, that analysis flags constructs that are perfectly legal | ||
| in druntime but illegal in user code. | ||
|
|
||
| The `-deps` output is populated during normal semantic passes and does not | ||
| require this additional analysis step, so the call has been removed. | ||
|
|
||
| To get recursive dependencies (the original motivation for this behavior), | ||
| combine `-deps` with `-i`. |
There was a problem hiding this comment.
This looks like an AI-written description that is very literal. It describes the issue from a very technical lens through the specific issue that this PR closes, which is only a manifestation of the more general problem that -deps conflates -i.
|
Removed the druntime |
Fixes #20392
Problem
Using
-depswith-betterCcauses spurious errors in transitively imported druntime modules the user never references. A bare unused import is enough to trigger it:dmd repro.d -betterC -deps=deps.txt // fails with throw/GC errors in core.exception, core.time
dmd repro.d -betterC -c // compiles clean
Root cause
When
-depsis active,tryMaincallssemantic3OnDependencies(), which recursively forces full function-body analysis (semantic3) on every transitively imported module. Under-betterC, that flags constructs in unreferenced druntime functions that are legal in druntime but illegal in user code. The-depsoutput is populated during normal semantic passes and does not require this extra step.Confirmed via GDB stack trace:
#40 dmd.dsymbolsem.semantic3OnDependencies(Module m) at src/dmd/dsymbolsem.d:718
#41 dmd.dsymbolsem.semantic3OnDependencies(Module m) at src/dmd/dsymbolsem.d:721
#42 dmd.main.tryMain(...) at src/dmd/main.d:732
Fix
Remove
semantic3OnDependenciesand its call site inmain.d. This revives the approach from #9122, which stalled in 2019 due to a since-resolved objection. For recursive dependencies, use-depscombined with-i.@dkorpel