Skip to content

Instantly share code, notes, and snippets.

@alexandrumc
Last active December 11, 2019 14:57
Show Gist options
  • Save alexandrumc/efb998f458f70bb59ad671d978a86ff7 to your computer and use it in GitHub Desktop.
Save alexandrumc/efb998f458f70bb59ad671d978a86ff7 to your computer and use it in GitHub Desktop.
Solving unittest issue

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment