Skip to content

Commit 06c55d0

Browse files
committed
[Dependency Scanning] Revert Swift overlay lookup using "visible" Clang modules only
We have identified scenarios where this is insufficient and compilation still relies on the presence of certain overlay modules this excludes. Reverting to prior lookup logic while we investigate. Resolves rdar://157519278
1 parent 573607f commit 06c55d0

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,25 @@ ModuleDependencyScanner::ModuleDependencyScanner(
609609
DependencyTracker, CAS, ActionCache, PrefixMapper.get(), Diagnostics));
610610
}
611611

612+
/// Find all of the imported Clang modules starting with the given module name.
613+
static void findAllImportedClangModules(StringRef moduleName,
614+
const ModuleDependenciesCache &cache,
615+
std::vector<std::string> &allModules,
616+
llvm::StringSet<> &knownModules) {
617+
if (!knownModules.insert(moduleName).second)
618+
return;
619+
allModules.push_back(moduleName.str());
620+
auto moduleID =
621+
ModuleDependencyID{moduleName.str(), ModuleDependencyKind::Clang};
622+
auto optionalDependencies = cache.findDependency(moduleID);
623+
if (!optionalDependencies.has_value())
624+
return;
625+
626+
for (const auto &dep : cache.getClangDependencies(moduleID))
627+
findAllImportedClangModules(dep.ModuleName, cache, allModules,
628+
knownModules);
629+
}
630+
612631
static std::set<ModuleDependencyID>
613632
collectBinarySwiftDeps(const ModuleDependenciesCache &cache) {
614633
std::set<ModuleDependencyID> binarySwiftModuleDepIDs;
@@ -1462,7 +1481,14 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
14621481
ModuleDependencyIDSetVector &swiftOverlayDependencies) {
14631482
PrettyStackTraceStringAction trace(
14641483
"Resolving Swift Overlay dependencies of module", moduleID.ModuleName);
1465-
auto visibleClangDependencies = cache.getVisibleClangModules(moduleID);
1484+
std::vector<std::string> allClangDependencies;
1485+
llvm::StringSet<> knownModules;
1486+
1487+
// Find all of the discovered Clang modules that this module depends on.
1488+
for (const auto &dep : cache.getClangDependencies(moduleID))
1489+
findAllImportedClangModules(dep.ModuleName, cache, allClangDependencies,
1490+
knownModules);
1491+
14661492
llvm::StringMap<SwiftModuleScannerQueryResult> swiftOverlayLookupResult;
14671493
std::mutex lookupResultLock;
14681494

@@ -1492,9 +1518,9 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
14921518
};
14931519

14941520
// Enque asynchronous lookup tasks
1495-
for (const auto &clangDep : visibleClangDependencies)
1521+
for (const auto &clangDep : allClangDependencies)
14961522
ScanningThreadPool.async(scanForSwiftDependency,
1497-
getModuleImportIdentifier(clangDep.getKey()));
1523+
getModuleImportIdentifier(clangDep));
14981524
ScanningThreadPool.wait();
14991525

15001526
// Aggregate both previously-cached and freshly-scanned module results
@@ -1521,8 +1547,8 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
15211547
lookupResult.incompatibleCandidates, cache, std::nullopt);
15221548
}
15231549
};
1524-
for (const auto &clangDep : visibleClangDependencies)
1525-
recordResult(clangDep.getKey().str());
1550+
for (const auto &clangDep : allClangDependencies)
1551+
recordResult(clangDep);
15261552

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

15451571
if (lookupCxxStdLibOverlay) {
1546-
for (const auto &clangDepNameEntry : visibleClangDependencies) {
1547-
auto clangDepName = clangDepNameEntry.getKey().str();
1572+
for (const auto &clangDepNameEntry : allClangDependencies) {
1573+
auto clangDepName = clangDepNameEntry;
15481574
// If this Clang module is a part of the C++ stdlib, and we haven't
15491575
// loaded the overlay for it so far, it is a split libc++ module (e.g.
15501576
// std_vector). Load the CxxStdlib overlay explicitly.

test/ScanDependencies/module_deps_swift_overlay_only_visible.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// REQUIRES: rdar157603647
12
// RUN: %empty-directory(%t)
23
// RUN: %empty-directory(%t/clang-module-cache)
34
// RUN: %empty-directory(%t/swiftDeps)

0 commit comments

Comments
 (0)