[Dependency Scanning] Restrict Swift overlay lookup to "visible" Clang modules only

Previously Swift overlay lookup was performed for every directly and transitively-imported Clang module.

https://github.com/llvm/llvm-project/pull/147969 introduced the concept of "visible" Clang modules from a given named Clang dependency scanner query which closely maps to the set of modules for which Swift will attempt to load a Swift overlay. This change switches overlay querying to apply only to the set of such visible modules.

Resolves rdar://144797648
This commit is contained in:
Artem Chikin
2025-07-11 16:59:34 -07:00
parent 23678690b2
commit 242585dcba
6 changed files with 197 additions and 82 deletions

View File

@@ -212,6 +212,11 @@ public:
/// The macro dependencies.
std::map<std::string, MacroPluginDependency> macroDependencies;
/// A list of Clang modules that are visible to this Swift module. This
/// includes both direct Clang modules as well as transitive Clang
/// module dependencies when they are exported
llvm::StringSet<> visibleClangModules;
/// ModuleDependencyInfo is finalized (with all transitive dependencies
/// and inputs).
bool finalized;
@@ -816,7 +821,17 @@ public:
cast<ClangModuleDependencyStorage>(storage.get())->CASFileSystemRootID =
rootID;
else
llvm_unreachable("Unexpected type");
llvm_unreachable("Unexpected module dependency kind");
}
llvm::StringSet<> &getVisibleClangModules() const {
return storage->visibleClangModules;
}
void
addVisibleClangModules(const std::vector<std::string> &moduleNames) const {
storage->visibleClangModules.insert(moduleNames.begin(),
moduleNames.end());
}
/// Whether explicit input paths of all the module dependencies
@@ -1057,6 +1072,9 @@ public:
/// Query all cross-import overlay dependencies
llvm::ArrayRef<ModuleDependencyID>
getCrossImportOverlayDependencies(const ModuleDependencyID &moduleID) const;
/// Query all visible Clang modules for a given Swift dependency
llvm::StringSet<>&
getVisibleClangModules(ModuleDependencyID moduleID) const;
/// Look for module dependencies for a module with the given ID
///
@@ -1123,6 +1141,11 @@ public:
setCrossImportOverlayDependencies(ModuleDependencyID moduleID,
const ArrayRef<ModuleDependencyID> dependencyIDs);
/// Add to this module's set of visible Clang modules
void
addVisibleClangModules(ModuleDependencyID moduleID,
const std::vector<std::string> &moduleNames);
StringRef getMainModuleName() const { return mainScanModuleName; }
private: