Skip to content

Commit cf0b642

Browse files
committed
[Dependency Scanning] Synchronize on updating Swift dependency lookup results in-parallel
Resolves rdar://142978967
1 parent 2e92644 commit cf0b642

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,13 @@ ModuleDependencyScanner::resolveAllClangModuleDependencies(
742742
// results back to the shared set for future lookups.
743743
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> seenClangModules =
744744
cache.getAlreadySeenClangModules();
745-
std::mutex cacheAccessLock;
745+
std::mutex lookupResultLock;
746746
auto scanForClangModuleDependency =
747747
[this, &cache, &moduleLookupResult,
748-
&cacheAccessLock, &seenClangModules](Identifier moduleIdentifier) {
748+
&lookupResultLock, &seenClangModules](Identifier moduleIdentifier) {
749749
auto moduleName = moduleIdentifier.str();
750750
{
751-
std::lock_guard<std::mutex> guard(cacheAccessLock);
751+
std::lock_guard<std::mutex> guard(lookupResultLock);
752752
if (cache.hasDependency(moduleName, ModuleDependencyKind::Clang))
753753
return;
754754
}
@@ -766,7 +766,7 @@ ModuleDependencyScanner::resolveAllClangModuleDependencies(
766766
// if looking for a module that was discovered as a transitive dependency
767767
// in this scan.
768768
{
769-
std::lock_guard<std::mutex> guard(cacheAccessLock);
769+
std::lock_guard<std::mutex> guard(lookupResultLock);
770770
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
771771
if (!moduleDependencies.empty())
772772
cache.recordDependencies(moduleDependencies);
@@ -926,16 +926,19 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
926926
for (const auto &dependsOn : moduleDependencyInfo.getModuleImports())
927927
moduleLookupResult.insert(
928928
std::make_pair(dependsOn.importIdentifier, std::nullopt));
929+
std::mutex lookupResultLock;
929930

930931
// A scanning task to query a module by-name. If the module already exists
931932
// in the cache, do nothing and return.
932933
auto scanForSwiftModuleDependency =
933-
[this, &cache, &moduleLookupResult](Identifier moduleIdentifier,
934-
bool isTestable) {
934+
[this, &cache, &lookupResultLock, &moduleLookupResult](Identifier moduleIdentifier,
935+
bool isTestable) {
935936
auto moduleName = moduleIdentifier.str().str();
936-
// If this is already in the cache, no work to do here
937-
if (cache.hasSwiftDependency(moduleName))
938-
return;
937+
{
938+
std::lock_guard<std::mutex> guard(lookupResultLock);
939+
if (cache.hasSwiftDependency(moduleName))
940+
return;
941+
}
939942

940943
auto moduleDependencies = withDependencyScanningWorker(
941944
[&cache, moduleIdentifier,
@@ -944,7 +947,11 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
944947
moduleIdentifier, cache.getModuleOutputPath(),
945948
cache.getScanService().getPrefixMapper(), isTestable);
946949
});
947-
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
950+
951+
{
952+
std::lock_guard<std::mutex> guard(lookupResultLock);
953+
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
954+
}
948955
};
949956

950957
// Enque asynchronous lookup tasks

0 commit comments

Comments
 (0)