diff --git a/src/dmd/astbase.d b/src/dmd/astbase.d index df42d3e35314..460ce857b24e 100644 --- a/src/dmd/astbase.d +++ b/src/dmd/astbase.d @@ -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) diff --git a/src/dmd/dtemplate.d b/src/dmd/dtemplate.d index 49cb9f6d1d8e..b905db489baf 100644 --- a/src/dmd/dtemplate.d +++ b/src/dmd/dtemplate.d @@ -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, @@ -6205,7 +6170,6 @@ extern (C++) class TemplateInstance : ScopeDsymbol // Do codegen because this is not included in non-root instances. return true; - } } /********************************************** @@ -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, diff --git a/src/dmd/parse.d b/src/dmd/parse.d index 4a95a1087fac..0be553014b83 100644 --- a/src/dmd/parse.d +++ b/src/dmd/parse.d @@ -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)