Skip to content

Commit bba7a23

Browse files
authored
Merge pull request #78868 from artemcm/61_FixRaceOnSwiftDepLookup
[6.1 🍒][Dependency Scanning] Synchronize on updating Swift dependency lookup results in-parallel
2 parents 8fce176 + 6033500 commit bba7a23

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -928,16 +928,19 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
928928
for (const auto &dependsOn : moduleDependencyInfo.getModuleImports())
929929
moduleLookupResult.insert(
930930
std::make_pair(dependsOn.importIdentifier, std::nullopt));
931+
std::mutex lookupResultLock;
931932

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

942945
auto moduleDependencies = withDependencyScanningWorker(
943946
[&cache, moduleIdentifier,
@@ -946,7 +949,11 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
946949
moduleIdentifier, cache.getModuleOutputPath(),
947950
cache.getScanService().getPrefixMapper(), isTestable);
948951
});
949-
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
952+
953+
{
954+
std::lock_guard<std::mutex> guard(lookupResultLock);
955+
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
956+
}
950957
};
951958

952959
// Enque asynchronous lookup tasks

0 commit comments

Comments
 (0)