Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -1485,12 +1485,19 @@ struct ASTBase

const FileName srcfile;
const(char)* arg;
bool rootModule;

extern (D) this(const(char)* filename, Identifier ident, int doDocComment, int doHdrGen)
extern (D) this(const(char)* filename, Identifier ident, int doDocComment, int doHdrGen, bool rootModule = false)
{
super(ident);
this.arg = filename;
srcfile = FileName(FileName.defaultExt(filename.toDString, global.mars_ext));
this.rootModule = rootModule;
}

bool isRoot()
{
return rootModule;
}

override void accept(Visitor v)
Expand Down
43 changes: 0 additions & 43 deletions src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -6141,41 +6141,6 @@ extern (C++) class TemplateInstance : ScopeDsymbol
return false;
}

if (global.params.useUnitTests)
{
// Prefer instantiations from root modules, to maximize link-ability.
if (minst.isRoot())
return true;

TemplateInstance tnext = this.tnext;
TemplateInstance tinst = this.tinst;
this.tnext = null;
this.tinst = null;

if (tinst && tinst.needsCodegen())
{
minst = tinst.minst; // cache result
assert(minst);
assert(minst.isRoot() || minst.rootImports());
return true;
}
if (tnext && tnext.needsCodegen())
{
minst = tnext.minst; // cache result
assert(minst);
assert(minst.isRoot() || minst.rootImports());
return true;
}

// https://issues.dlang.org/show_bug.cgi?id=2500 case
if (minst.rootImports())
return true;

// Elide codegen because this is not included in root instances.
return false;
}
else
{
// Prefer instantiations from non-root module, to minimize object code size.

/* If a TemplateInstance is ever instantiated by non-root modules,
Expand Down Expand Up @@ -6205,7 +6170,6 @@ extern (C++) class TemplateInstance : ScopeDsymbol

// Do codegen because this is not included in non-root instances.
return true;
}
}

/**********************************************
Expand Down Expand Up @@ -7139,13 +7103,6 @@ extern (C++) class TemplateInstance : ScopeDsymbol
{
Module mi = minst; // instantiated . inserted module

if (global.params.useUnitTests || global.params.debuglevel)
{
// Turn all non-root instances to speculative
if (mi && !mi.isRoot())
mi = null;
}

//printf("%s.appendToModuleMember() enclosing = %s mi = %s\n",
// toPrettyChars(),
// enclosing ? enclosing.toPrettyChars() : null,
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ final class Parser(AST) : Lexer
goto Lerror;

case TOK.unittest_:
if (global.params.useUnitTests || global.params.doDocComments || global.params.doHdrGeneration)
if (global.params.useUnitTests && mod.isRoot()
|| global.params.doDocComments || global.params.doHdrGeneration)
{
s = parseUnitTest(pAttrs);
if (*pLastDecl)
Expand Down