What's the current state of the art for module compilation?
David Given
dg at cowlark.com
Sun Nov 22 23:05:44 UTC 2026
On Thursday, 19 November 2026 at 02:17:43 UTC, Walter Bright
wrote:
[...]
>> - .di files are not to be trusted, as even though the compiler
>> will generate them, it will silently break things like
>> templates and functions which return auto.
>
> Is there an issue filed for that?
[...]
> That's the point of .di files. Regarding auto functions,
> there's no way the compiler can deduce what auto means without
> the source code for the auto function.
Yes, this is the issue. I was previously told that if I try to
use autogenerated .di files with unsupported features like auto
or templates, then I'd get an incorrect .di file and runtime
crashes due to type mismatches. Is this true?
>> (Also the compiler interface is a bit unfriendly as many of
>> the paths for input and output artifacts are determine
>> automatically by the compiler, meaning the build system isn't
>> necessarily aware of them, but that can be worked around.)
>
> Can you be more specific?
This one's a minor issue, but hermetic build systems like to
control all the compiler's inputs and outputs. If the compiler is
going to look up arbitrary files and then _write_ arbitrary
files, the build system can't do this. Writing is particularly
difficult as it means that the build system can't determine the
dependency graph until the compiler runs.
Java has the same problem, and what hermetic build systems like
bazel do is to use a custom compiler driver which limits access
to which files the compiler has access to --- typically, the
compiler can only read library files from the set of jars
specified by the build system, and then will only write exactly
one output jar which correspond to the explicit source files.
This also prevents drive-by compilations where it'll create a
class file for a library source file which isn't listed on the
command line, if it happens to see that file. (I don't know if D
does this. I don't think so?)
> Once a program gets large enough, .di files are needed
> (analogously to the need for .h files in C).
Yes, exactly; hence my question.
More information about the Digitalmars-d
mailing list