@@ -756,16 +756,55 @@ void CompilerInstance::setUpDiagnosticOptions() {
756756// in the presence of overlays and mixed-source frameworks, we want to prefer
757757// the overlay or framework module over the underlying Clang module.
758758bool CompilerInstance::setUpModuleLoaders () {
759+ auto ModuleCachePathFromInvocation = getInvocation ().getClangModuleCachePath ();
760+ auto &FEOpts = Invocation.getFrontendOptions ();
761+ auto MLM = Invocation.getSearchPathOptions ().ModuleLoadMode ;
762+ auto IgnoreSourceInfoFile = Invocation.getFrontendOptions ().IgnoreSwiftSourceInfo ;
763+ ModuleInterfaceLoaderOptions LoaderOpts (FEOpts);
764+
765+ // Dependency scanning sub-invocations only require the loaders necessary
766+ // for locating textual and binary Swift modules.
767+ if (Invocation.getFrontendOptions ().DependencyScanningSubInvocation ) {
768+ Context->addModuleInterfaceChecker (
769+ std::make_unique<ModuleInterfaceCheckerImpl>(
770+ *Context, ModuleCachePathFromInvocation, FEOpts.PrebuiltModuleCachePath ,
771+ FEOpts.BackupModuleInterfaceDir , LoaderOpts,
772+ RequireOSSAModules_t (Invocation.getSILOptions ())));
773+
774+ if (MLM != ModuleLoadingMode::OnlySerialized) {
775+ // We only need ModuleInterfaceLoader for implicit modules.
776+ auto PIML = ModuleInterfaceLoader::create (
777+ *Context, *static_cast <ModuleInterfaceCheckerImpl*>(Context
778+ ->getModuleInterfaceChecker ()), getDependencyTracker (), MLM,
779+ FEOpts.PreferInterfaceForModules , IgnoreSourceInfoFile);
780+ Context->addModuleLoader (std::move (PIML), false , false , true );
781+ }
782+ std::unique_ptr<ImplicitSerializedModuleLoader> ISML =
783+ ImplicitSerializedModuleLoader::create (*Context, getDependencyTracker (), MLM,
784+ IgnoreSourceInfoFile);
785+ this ->DefaultSerializedLoader = ISML.get ();
786+ Context->addModuleLoader (std::move (ISML));
787+
788+ // When caching is enabled, we rely on ClangImporter for
789+ // 'addClangInvovcationDependencies'
790+ if (Invocation.getCASOptions ().EnableCaching ) {
791+ std::unique_ptr<ClangImporter> clangImporter =
792+ ClangImporter::create (*Context, Invocation.getPCHHash (),
793+ getDependencyTracker ());
794+ Context->addModuleLoader (std::move (clangImporter), /* isClang*/ true );
795+ }
796+
797+ return false ;
798+ }
799+
759800 if (hasSourceImport ()) {
760801 bool enableLibraryEvolution =
761802 Invocation.getFrontendOptions ().EnableLibraryEvolution ;
762803 Context->addModuleLoader (SourceLoader::create (*Context,
763804 enableLibraryEvolution,
764805 getDependencyTracker ()));
765806 }
766- auto MLM = Invocation.getSearchPathOptions ().ModuleLoadMode ;
767- auto IgnoreSourceInfoFile =
768- Invocation.getFrontendOptions ().IgnoreSwiftSourceInfo ;
807+
769808 if (Invocation.getLangOptions ().EnableMemoryBufferImporter ) {
770809 auto MemoryBufferLoader = MemoryBufferSerializedModuleLoader::create (
771810 *Context, getDependencyTracker (), MLM, IgnoreSourceInfoFile);
@@ -808,13 +847,10 @@ bool CompilerInstance::setUpModuleLoaders() {
808847 }
809848
810849 // Configure ModuleInterfaceChecker for the ASTContext.
811- auto CacheFromInvocation = getInvocation ().getClangModuleCachePath ();
812850 auto const &Clang = clangImporter->getClangInstance ();
813- std::string ModuleCachePath = CacheFromInvocation .empty ()
851+ std::string ModuleCachePath = ModuleCachePathFromInvocation .empty ()
814852 ? getModuleCachePathFromClang (Clang)
815- : CacheFromInvocation.str ();
816- auto &FEOpts = Invocation.getFrontendOptions ();
817- ModuleInterfaceLoaderOptions LoaderOpts (FEOpts);
853+ : ModuleCachePathFromInvocation.str ();
818854 Context->addModuleInterfaceChecker (
819855 std::make_unique<ModuleInterfaceCheckerImpl>(
820856 *Context, ModuleCachePath, FEOpts.PrebuiltModuleCachePath ,
0 commit comments