What's the current state of the art for module compilation?

monkyyy crazymonkyyy at gmail.com
Sat Nov 28 03:19:07 UTC 2026


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


More information about the Digitalmars-d mailing list