Now let's see how the previous example correlates with compilation taking longer when using -unittest.
Besides the if(compiledWithUnittest) block from the needsCodegen()
which prefers instantiations from root modules,
there's another if(compiledWithUnittest) which enforces the treatment of non-root modules (imports) as root modules.
for reference: https://github.com/dlang/dmd/blob/f5f0b68b8537270fd70cb7fb27c703abd216377d/src/dmd/dtemplate.d#L7139-L7144
This means that if you have the following program:
module test;
import std.uni;
import std.stdio;
import std.regex;
and we compile it using dmd -unittest test.d
, then every imported module (regardless if it is used or not) will be
semantic analysed and there'll be codegen for every template instantiation that is done inside the module that is imported. This is why the compilation takes longer.
What I've done is this PR (dlang/dmd#10641) was to disable the treatment of non-root modules (imports) as root modules