[Dependency Scanning] Synchronize on updating Swift dependency lookup results in-parallel

Resolves rdar://142978967
This commit is contained in:
Artem Chikin
2025-01-23 09:55:56 -08:00
parent 2e92644b68
commit ae98eae9d5

View File

@@ -926,16 +926,19 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
for (const auto &dependsOn : moduleDependencyInfo.getModuleImports())
moduleLookupResult.insert(
std::make_pair(dependsOn.importIdentifier, std::nullopt));
std::mutex lookupResultLock;
// A scanning task to query a module by-name. If the module already exists
// in the cache, do nothing and return.
auto scanForSwiftModuleDependency =
[this, &cache, &moduleLookupResult](Identifier moduleIdentifier,
bool isTestable) {
[this, &cache, &lookupResultLock, &moduleLookupResult](Identifier moduleIdentifier,
bool isTestable) {
auto moduleName = moduleIdentifier.str().str();
// If this is already in the cache, no work to do here
if (cache.hasSwiftDependency(moduleName))
return;
{
std::lock_guard<std::mutex> guard(lookupResultLock);
if (cache.hasSwiftDependency(moduleName))
return;
}
auto moduleDependencies = withDependencyScanningWorker(
[&cache, moduleIdentifier,
@@ -944,7 +947,11 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
moduleIdentifier, cache.getModuleOutputPath(),
cache.getScanService().getPrefixMapper(), isTestable);
});
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
{
std::lock_guard<std::mutex> guard(lookupResultLock);
moduleLookupResult.insert_or_assign(moduleName, moduleDependencies);
}
};
// Enque asynchronous lookup tasks