@@ -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 ()
@@ -369,14 +369,8 @@ extern (C++) final class Module : Package
369369 Dsymbol searchCacheSymbol; // cached value of search
370370 int searchCacheFlags; // cached flags
371371
372- /**
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- */
379372 Module importedFrom;
373+ bool isCompiledImport;
380374
381375 Dsymbols* decldefs; // top level declarations for this Module
382376
@@ -515,41 +509,6 @@ extern (C++) final class Module : Package
515509 message(" import %s" , buf.peekString());
516510 }
517511 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-
553512 Target.loadModule(m);
554513 return m;
555514 }
@@ -1288,9 +1247,28 @@ extern (C++) final class Module : Package
12881247 return false ;
12891248 }
12901249
1291- bool isRoot ()
1250+ /**
1251+ A root module is one that will be compiled all the way to object code.
1252+ */
1253+ final bool isRoot () const
1254+ {
1255+ return this .importedFrom == this || isCompiledImport;
1256+ }
1257+
1258+ /**
1259+ Called by the parser after the module declaration has been determined.
1260+ */
1261+ final void afterModuleDeclaration ()
12921262 {
1293- return this .importedFrom == this ;
1263+ // Call onImport here because if the module is going to be compiled then we
1264+ // need to determine it early because it affects whether unittests will be parsed
1265+ // and semantic analysis. This is being done right after parsing the module delclaration
1266+ // so the full module name can be taken from whatever was declared in the file.
1267+ if (! isRoot() && Module.onImport && Module.onImport(this ))
1268+ {
1269+ isCompiledImport = true ;
1270+ assert (isRoot());
1271+ }
12941272 }
12951273
12961274 // true if the module source file is directly
0 commit comments