What's the current state of the art for module compilation?
Mengu
mengukagan at gmail.com
Sat Nov 28 14:18:55 UTC 2026
On Saturday, 28 November 2026 at 03:19:07 UTC, monkyyy wrote:
> On Saturday, 28 November 2026 at 01:37:35 UTC, Mengu wrote:
>> The following is not AI slop.
>
>> #### 3. Stripped `const` initializers and function bodies
>> diverge under `__traits(compiles, ...)`
>>
>
>> **Root cause.** `visitVarDecl` in
>> `compiler/src/dmd/hdrgen.d:2152-2202` sets `isextern = true`
>> and drops `v._init` for all module-level variables except
>> `STC.manifest`, including `const` and `immutable` compile-time
>> constants. Also, `genhdrfile` runs before semantic analysis in
>> `compiler/src/dmd/main.d:591-615`, and `bodyToBuffer` in
>> `compiler/src/dmd/hdrgen.d:1446` strips normal function bodies
>> without knowing whether a `static if` or `enum` evaluates them
>> at compile time.
>>
>> **Fix.** For `const` and `immutable` module variables with an
>> initializer, preserve the initializer in `visitVarDecl`
>> instead of rewriting them to `extern const T x;`. For
>> CTFE-dependent `static if` and `__traits(compiles, ...)`
>> expressions, resolve module-level conditional compilation
>> before header emission so `lib.di` matches the AST compiled
>> into `lib.o`.
>
> this is still slop even if you used a more mathy method, this
> is a bad conclusion; I was able to point at `__traits(compiles`
> as a source of bugs with no computation with far less words,
> directly above you.
>
> As written youll only whack-a-mole bugs; believing you can fix
> `_traits(compiles` completely is a fools errand; it should be
> debated what sort of fix is most human understandable and has
> the best behavior.
>
> If you generated failing code with this method fine, but you
> should still do the think`n
The run I did was specifically targeted at _"generated .di files
with certain constructs (templates, auto return, something
annotation-based which I forget) doesn't work and produces .di
files which will in turn cause miscompilation and runtime
crashes"_ so it generated tests specifically targeting these
cases and I asked it to not to ignore the d spec meaning some
things it would consider as a bug would actually be a known
limitation or a deliberate design decision.
With your experience, I believe you can leverage the tool a
thousand times better than I can. Give it a go.
More information about the Digitalmars-d
mailing list