[Dependency Scanning] Reduce number of module loaders instantiated for textual interface scanning sub-instance

This commit is contained in:
Artem Chikin
2025-05-07 11:23:25 -07:00
parent 8cd193fc08
commit 80c71fd3a9
3 changed files with 47 additions and 15 deletions

View File

@@ -756,6 +756,47 @@ void CompilerInstance::setUpDiagnosticOptions() {
// in the presence of overlays and mixed-source frameworks, we want to prefer
// the overlay or framework module over the underlying Clang module.
bool CompilerInstance::setUpModuleLoaders() {
auto ModuleCachePathFromInvocation = getInvocation().getClangModuleCachePath();
auto &FEOpts = Invocation.getFrontendOptions();
auto MLM = Invocation.getSearchPathOptions().ModuleLoadMode;
auto IgnoreSourceInfoFile = Invocation.getFrontendOptions().IgnoreSwiftSourceInfo;
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
// Dependency scanning sub-invocations only require the loaders necessary
// for locating textual and binary Swift modules.
if (Invocation.getFrontendOptions().DependencyScanningSubInvocation) {
Context->addModuleInterfaceChecker(
std::make_unique<ModuleInterfaceCheckerImpl>(
*Context, ModuleCachePathFromInvocation, FEOpts.PrebuiltModuleCachePath,
FEOpts.BackupModuleInterfaceDir, LoaderOpts,
RequireOSSAModules_t(Invocation.getSILOptions())));
if (MLM != ModuleLoadingMode::OnlySerialized) {
// We only need ModuleInterfaceLoader for implicit modules.
auto PIML = ModuleInterfaceLoader::create(
*Context, *static_cast<ModuleInterfaceCheckerImpl*>(Context
->getModuleInterfaceChecker()), getDependencyTracker(), MLM,
FEOpts.PreferInterfaceForModules, IgnoreSourceInfoFile);
Context->addModuleLoader(std::move(PIML), false, false, true);
}
std::unique_ptr<ImplicitSerializedModuleLoader> ISML =
ImplicitSerializedModuleLoader::create(*Context, getDependencyTracker(), MLM,
IgnoreSourceInfoFile);
this->DefaultSerializedLoader = ISML.get();
Context->addModuleLoader(std::move(ISML));
// When caching is enabled, we rely on ClangImporter for
// 'addClangInvovcationDependencies'
if (Invocation.getCASOptions().EnableCaching) {
std::unique_ptr<ClangImporter> clangImporter =
ClangImporter::create(*Context, Invocation.getPCHHash(),
getDependencyTracker());
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
}
return false;
}
if (hasSourceImport()) {
bool enableLibraryEvolution =
Invocation.getFrontendOptions().EnableLibraryEvolution;
@@ -763,9 +804,7 @@ bool CompilerInstance::setUpModuleLoaders() {
enableLibraryEvolution,
getDependencyTracker()));
}
auto MLM = Invocation.getSearchPathOptions().ModuleLoadMode;
auto IgnoreSourceInfoFile =
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo;
if (Invocation.getLangOptions().EnableMemoryBufferImporter) {
auto MemoryBufferLoader = MemoryBufferSerializedModuleLoader::create(
*Context, getDependencyTracker(), MLM, IgnoreSourceInfoFile);
@@ -808,13 +847,10 @@ bool CompilerInstance::setUpModuleLoaders() {
}
// Configure ModuleInterfaceChecker for the ASTContext.
auto CacheFromInvocation = getInvocation().getClangModuleCachePath();
auto const &Clang = clangImporter->getClangInstance();
std::string ModuleCachePath = CacheFromInvocation.empty()
std::string ModuleCachePath = ModuleCachePathFromInvocation.empty()
? getModuleCachePathFromClang(Clang)
: CacheFromInvocation.str();
auto &FEOpts = Invocation.getFrontendOptions();
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
: ModuleCachePathFromInvocation.str();
Context->addModuleInterfaceChecker(
std::make_unique<ModuleInterfaceCheckerImpl>(
*Context, ModuleCachePath, FEOpts.PrebuiltModuleCachePath,