@@ -424,14 +424,17 @@ void CompilerInstance::setUpDiagnosticOptions() {
424424// Ideally, we'd get rid of it.
425425// 2. MemoryBufferSerializedModuleLoader: This is used by LLDB, because it might
426426// already have the module available in memory.
427- // 3. ModuleInterfaceLoader: Tries to find an up-to-date swiftmodule. If it
427+ // 3. ExplicitSwiftModuleLoader: Loads a serialized module if it can, provided
428+ // this modules was specified as an explicit input to the compiler.
429+ // 4. ModuleInterfaceLoader: Tries to find an up-to-date swiftmodule. If it
428430// succeeds, it issues a particular "error" (see
429- // [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader ]), which
431+ // [Note: ModuleInterfaceLoader-defer-to-ImplicitSerializedModuleLoader ]), which
430432// is interpreted by the overarching loader as a command to use the
431- // SerializedModuleLoader . If we failed to find a .swiftmodule, this falls
433+ // ImplicitSerializedModuleLoader . If we failed to find a .swiftmodule, this falls
432434// back to using an interface. Actual errors lead to diagnostics.
433- // 4. SerializedModuleLoader: Loads a serialized module if it can.
434- // 5. ClangImporter: This must come after all the Swift module loaders because
435+ // 5. ImplicitSerializedModuleLoader: Loads a serialized module if it can.
436+ // Used for implicit loading of modules from the compiler's search paths.
437+ // 6. ClangImporter: This must come after all the Swift module loaders because
435438// in the presence of overlays and mixed-source frameworks, we want to prefer
436439// the overlay or framework module over the underlying Clang module.
437440bool CompilerInstance::setUpModuleLoaders () {
@@ -484,15 +487,18 @@ bool CompilerInstance::setUpModuleLoaders() {
484487
485488 // If implicit modules are disabled, we need to install an explicit module
486489 // loader.
487- if (Invocation.getFrontendOptions ().DisableImplicitModules ) {
490+ bool ExplicitModuleBuild = Invocation.getFrontendOptions ().DisableImplicitModules ;
491+ if (ExplicitModuleBuild) {
488492 auto ESML = ExplicitSwiftModuleLoader::create (
489493 *Context,
490494 getDependencyTracker (), MLM,
491495 Invocation.getSearchPathOptions ().ExplicitSwiftModules ,
492496 Invocation.getSearchPathOptions ().ExplicitSwiftModuleMap ,
493497 IgnoreSourceInfoFile);
498+ this ->DefaultSerializedLoader = ESML.get ();
494499 Context->addModuleLoader (std::move (ESML));
495500 }
501+
496502 if (MLM != ModuleLoadingMode::OnlySerialized) {
497503 auto const &Clang = clangImporter->getClangInstance ();
498504 std::string ModuleCachePath = getModuleCachePathFromClang (Clang);
@@ -507,12 +513,14 @@ bool CompilerInstance::setUpModuleLoaders() {
507513 Context->addModuleLoader (std::move (PIML), false , false , true );
508514 }
509515
510- std::unique_ptr<SerializedModuleLoader> SML =
511- SerializedModuleLoader::create (*Context, getDependencyTracker (), MLM,
516+ if (!ExplicitModuleBuild) {
517+ std::unique_ptr<ImplicitSerializedModuleLoader> ISML =
518+ ImplicitSerializedModuleLoader::create (*Context, getDependencyTracker (), MLM,
512519 IgnoreSourceInfoFile);
513- this ->SML = SML.get ();
514- Context->addModuleLoader (std::move (SML));
515-
520+ this ->DefaultSerializedLoader = ISML.get ();
521+ Context->addModuleLoader (std::move (ISML));
522+ }
523+
516524 Context->addModuleLoader (std::move (clangImporter), /* isClang*/ true );
517525
518526 return false ;
@@ -868,6 +876,7 @@ bool CompilerInstance::loadStdlibIfNeeded() {
868876
869877bool CompilerInstance::loadPartialModulesAndImplicitImports (
870878 ModuleDecl *mod, SmallVectorImpl<FileUnit *> &partialModules) const {
879+ assert (DefaultSerializedLoader && " Expected module loader in Compiler Instance" );
871880 FrontendStatsTracer tracer (getStatsReporter (),
872881 " load-partial-modules-and-implicit-imports" );
873882 // Force loading implicit imports. This is currently needed to allow
@@ -881,7 +890,7 @@ bool CompilerInstance::loadPartialModulesAndImplicitImports(
881890 for (auto &PM : PartialModules) {
882891 assert (PM.ModuleBuffer );
883892 auto *file =
884- SML ->loadAST (*mod, /* diagLoc*/ SourceLoc (), /* moduleInterfacePath*/ " " ,
893+ DefaultSerializedLoader ->loadAST (*mod, /* diagLoc*/ SourceLoc (), /* moduleInterfacePath*/ " " ,
885894 std::move (PM.ModuleBuffer ), std::move (PM.ModuleDocBuffer ),
886895 std::move (PM.ModuleSourceInfoBuffer ),
887896 /* isFramework*/ false );
@@ -974,7 +983,7 @@ void CompilerInstance::freeASTContext() {
974983 TheSILTypes.reset ();
975984 Context.reset ();
976985 MainModule = nullptr ;
977- SML = nullptr ;
986+ DefaultSerializedLoader = nullptr ;
978987 MemoryBufferLoader = nullptr ;
979988 PrimaryBufferIDs.clear ();
980989}
0 commit comments