@@ -292,10 +292,10 @@ extern (C++) final class Module : Package
292292 extern (C++ ) static __gshared Dsymbols deferred3; // deferred Dsymbol's needing semantic3() run on them
293293 extern (C++ ) static __gshared uint dprogress; // progress resolving the deferred list
294294 /**
295- * A callback function that is called once an imported module is
296- * parsed. If the callback returns true, then it tells the
297- * frontend that the driver intends on compiling the import.
298- */
295+ A callback function that is called when a module is loaded as soon as its
296+ module declaration has been parsed. If the callback returns true, then it tells the
297+ frontend that the driver intends on compiling the import.
298+ */
299299 extern (C++ ) static __gshared bool function (Module mod) onImport;
300300
301301 static void _init ()
@@ -370,12 +370,10 @@ extern (C++) final class Module : Package
370370 int searchCacheFlags; // cached flags
371371
372372 /**
373- * A root module is one that will be compiled all the way to
374- * object code. This field holds the root module that caused
375- * this module to be loaded. If this module is a root module,
376- * then it will be set to `this`. This is used to determine
377- * ownership of template instantiation.
378- */
373+ This field holds the root module that caused this module
374+ to be loaded. If this module is a root module, then it will
375+ be set to `this`.
376+ */
379377 Module importedFrom;
380378
381379 Dsymbols* decldefs; // top level declarations for this Module
@@ -515,41 +513,6 @@ extern (C++) final class Module : Package
515513 message(" import %s" , buf.peekString());
516514 }
517515 m = m.parse();
518-
519- // Call onImport here because if the module is going to be compiled then we
520- // need to determine it early because it affects semantic analysis. This is
521- // being done after parsing the module so the full module name can be taken
522- // from whatever was declared in the file.
523-
524- // !!!!!!!!!!!!!!!!!!!!!!!
525- // Workaround for bug in dmd version 2.068.2 platform Darwin_64_32.
526- // This is the compiler version that the autotester uses, and this code
527- // has been carefully crafted using trial and error to prevent a seg fault
528- // bug that occurs with that version of the compiler. Note, this segfault
529- // does not occur on the next version of dmd, namely, version 2.069.0. If
530- // the autotester upgrades to that version, then this workaround can be removed.
531- // !!!!!!!!!!!!!!!!!!!!!!!
532- version (OSX )
533- {
534- if (! m.isRoot() && onImport)
535- {
536- auto onImportResult = onImport(m);
537- if (onImportResult)
538- {
539- m.importedFrom = m;
540- assert (m.isRoot());
541- }
542- }
543- }
544- else
545- {
546- if (! m.isRoot() && onImport && onImport(m))
547- {
548- m.importedFrom = m;
549- assert (m.isRoot());
550- }
551- }
552-
553516 Target.loadModule(m);
554517 return m;
555518 }
@@ -853,7 +816,6 @@ extern (C++) final class Module : Package
853816 scope p = new Parser! ASTCodegen(this , buf[0 .. buflen], docfile ! is null );
854817 p.nextToken();
855818 members = p.parseModule();
856- md = p.md;
857819 numlines = p.scanloc.linnum;
858820 if (p.errors)
859821 ++ global.errors;
@@ -1288,11 +1250,35 @@ extern (C++) final class Module : Package
12881250 return false ;
12891251 }
12901252
1291- bool isRoot ()
1253+ /**
1254+ A root module is one that will be compiled to object code. This is used to
1255+ determine ownership of template instantiation and when to compile unittests.
1256+ Returns:
1257+ true if this is a root module
1258+ */
1259+ final bool isRoot () const
12921260 {
12931261 return this .importedFrom == this ;
12941262 }
12951263
1264+ /**
1265+ Called by the parser after the module declaration has been determined.
1266+ */
1267+ final void afterModuleDeclaration (ModuleDeclaration* md)
1268+ {
1269+ this .md = md;
1270+
1271+ // Call onImport here because if the module is going to be compiled then we
1272+ // need to determine it early because it affects whether unittests will be parsed
1273+ // and semantic analysis. This is being done right after parsing the module delclaration
1274+ // so the full module name can be taken from whatever was declared in the file.
1275+ if (! isRoot() && onImport && onImport(this ))
1276+ {
1277+ importedFrom = this ;
1278+ assert (isRoot());
1279+ }
1280+ }
1281+
12961282 // true if the module source file is directly
12971283 // listed in command line.
12981284 bool isCoreModule (Identifier ident)
0 commit comments