@@ -756,16 +756,55 @@ void CompilerInstance::setUpDiagnosticOptions() {
756
756
// in the presence of overlays and mixed-source frameworks, we want to prefer
757
757
// the overlay or framework module over the underlying Clang module.
758
758
bool 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
+
759
800
if (hasSourceImport ()) {
760
801
bool enableLibraryEvolution =
761
802
Invocation.getFrontendOptions ().EnableLibraryEvolution ;
762
803
Context->addModuleLoader (SourceLoader::create (*Context,
763
804
enableLibraryEvolution,
764
805
getDependencyTracker ()));
765
806
}
766
- auto MLM = Invocation.getSearchPathOptions ().ModuleLoadMode ;
767
- auto IgnoreSourceInfoFile =
768
- Invocation.getFrontendOptions ().IgnoreSwiftSourceInfo ;
807
+
769
808
if (Invocation.getLangOptions ().EnableMemoryBufferImporter ) {
770
809
auto MemoryBufferLoader = MemoryBufferSerializedModuleLoader::create (
771
810
*Context, getDependencyTracker (), MLM, IgnoreSourceInfoFile);
@@ -808,13 +847,10 @@ bool CompilerInstance::setUpModuleLoaders() {
808
847
}
809
848
810
849
// Configure ModuleInterfaceChecker for the ASTContext.
811
- auto CacheFromInvocation = getInvocation ().getClangModuleCachePath ();
812
850
auto const &Clang = clangImporter->getClangInstance ();
813
- std::string ModuleCachePath = CacheFromInvocation .empty ()
851
+ std::string ModuleCachePath = ModuleCachePathFromInvocation .empty ()
814
852
? getModuleCachePathFromClang (Clang)
815
- : CacheFromInvocation.str ();
816
- auto &FEOpts = Invocation.getFrontendOptions ();
817
- ModuleInterfaceLoaderOptions LoaderOpts (FEOpts);
853
+ : ModuleCachePathFromInvocation.str ();
818
854
Context->addModuleInterfaceChecker (
819
855
std::make_unique<ModuleInterfaceCheckerImpl>(
820
856
*Context, ModuleCachePath, FEOpts.PrebuiltModuleCachePath ,
0 commit comments