Skip to content

[Dependency Scanning] Revert Swift overlay lookup using "visible" Clang modules only #83551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions lib/DependencyScan/ModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,25 @@ ModuleDependencyScanner::ModuleDependencyScanner(
DependencyTracker, CAS, ActionCache, PrefixMapper.get(), Diagnostics));
}

/// Find all of the imported Clang modules starting with the given module name.
static void findAllImportedClangModules(StringRef moduleName,
const ModuleDependenciesCache &cache,
std::vector<std::string> &allModules,
llvm::StringSet<> &knownModules) {
if (!knownModules.insert(moduleName).second)
return;
allModules.push_back(moduleName.str());
auto moduleID =
ModuleDependencyID{moduleName.str(), ModuleDependencyKind::Clang};
auto optionalDependencies = cache.findDependency(moduleID);
if (!optionalDependencies.has_value())
return;

for (const auto &dep : cache.getClangDependencies(moduleID))
findAllImportedClangModules(dep.ModuleName, cache, allModules,
knownModules);
}

static std::set<ModuleDependencyID>
collectBinarySwiftDeps(const ModuleDependenciesCache &cache) {
std::set<ModuleDependencyID> binarySwiftModuleDepIDs;
Expand Down Expand Up @@ -1462,7 +1481,14 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
ModuleDependencyIDSetVector &swiftOverlayDependencies) {
PrettyStackTraceStringAction trace(
"Resolving Swift Overlay dependencies of module", moduleID.ModuleName);
auto visibleClangDependencies = cache.getVisibleClangModules(moduleID);
std::vector<std::string> allClangDependencies;
llvm::StringSet<> knownModules;

// Find all of the discovered Clang modules that this module depends on.
for (const auto &dep : cache.getClangDependencies(moduleID))
findAllImportedClangModules(dep.ModuleName, cache, allClangDependencies,
knownModules);

llvm::StringMap<SwiftModuleScannerQueryResult> swiftOverlayLookupResult;
std::mutex lookupResultLock;

Expand Down Expand Up @@ -1492,9 +1518,9 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
};

// Enque asynchronous lookup tasks
for (const auto &clangDep : visibleClangDependencies)
for (const auto &clangDep : allClangDependencies)
ScanningThreadPool.async(scanForSwiftDependency,
getModuleImportIdentifier(clangDep.getKey()));
getModuleImportIdentifier(clangDep));
ScanningThreadPool.wait();

// Aggregate both previously-cached and freshly-scanned module results
Expand All @@ -1521,8 +1547,8 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
lookupResult.incompatibleCandidates, cache, std::nullopt);
}
};
for (const auto &clangDep : visibleClangDependencies)
recordResult(clangDep.getKey().str());
for (const auto &clangDep : allClangDependencies)
recordResult(clangDep);

// C++ Interop requires additional handling
bool lookupCxxStdLibOverlay = ScanCompilerInvocation.getLangOptions().EnableCXXInterop;
Expand All @@ -1543,8 +1569,8 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
}

if (lookupCxxStdLibOverlay) {
for (const auto &clangDepNameEntry : visibleClangDependencies) {
auto clangDepName = clangDepNameEntry.getKey().str();
for (const auto &clangDepNameEntry : allClangDependencies) {
auto clangDepName = clangDepNameEntry;
// If this Clang module is a part of the C++ stdlib, and we haven't
// loaded the overlay for it so far, it is a split libc++ module (e.g.
// std_vector). Load the CxxStdlib overlay explicitly.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// REQUIRES: rdar157603647
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/clang-module-cache)
// RUN: %empty-directory(%t/swiftDeps)
Expand Down