@@ -377,7 +377,7 @@ bool ModuleDependencyScanningWorker::scanHeaderDependenciesOfSwiftModule(
377
377
auto bridgedDeps = ClangImporter::bridgeClangModuleDependencies (
378
378
ctx, clangScanningTool, dependencies->ModuleGraph , lookupModuleOutput,
379
379
[this ](StringRef path) { return remapPath (PrefixMapper, path); });
380
- cache.recordDependencies (bridgedDeps, ctx.Diags );
380
+ cache.recordClangDependencies (bridgedDeps, ctx.Diags );
381
381
visibleClangModules = dependencies->VisibleModules ;
382
382
383
383
llvm::copy (dependencies->FileDeps , std::back_inserter (headerFileInputs));
@@ -1057,7 +1057,7 @@ void ModuleDependencyScanner::resolveAllClangModuleDependencies(
1057
1057
continue ;
1058
1058
} else {
1059
1059
// We need to query the Clang dependency scanner for this module's
1060
- // unresolved imports
1060
+ // non-Swift imports
1061
1061
llvm::StringSet<> resolvedImportIdentifiers;
1062
1062
for (const auto &resolvedDep :
1063
1063
moduleDependencyInfo.getImportedSwiftDependencies ())
@@ -1095,46 +1095,23 @@ void ModuleDependencyScanner::resolveAllClangModuleDependencies(
1095
1095
}
1096
1096
}
1097
1097
1098
- // Prepare the module lookup result collection
1099
- llvm::StringMap<std::optional<ClangModuleScannerQueryResult>>
1100
- moduleLookupResult;
1101
- for (const auto &unresolvedIdentifier : unresolvedImportIdentifiers)
1102
- moduleLookupResult.insert (
1103
- std::make_pair (unresolvedIdentifier.getKey (), std::nullopt ));
1104
-
1105
- // We need a copy of the shared already-seen module set, which will be shared
1106
- // amongst all the workers. In `recordDependencies`, each worker will
1107
- // contribute its results back to the shared set for future lookups.
1098
+ // Module lookup result collection
1099
+ llvm::StringMap<ClangModuleScannerQueryResult> moduleLookupResult;
1108
1100
const llvm::DenseSet<clang::tooling::dependencies::ModuleID>
1109
- seenClangModules = cache.getAlreadySeenClangModules ();
1110
- std::mutex cacheAccessLock ;
1111
- auto scanForClangModuleDependency = [this , &cache, & moduleLookupResult,
1112
- &cacheAccessLock , &seenClangModules](
1101
+ seenClangModules = cache.getAlreadySeenClangModules ();
1102
+ std::mutex resultAccessLock ;
1103
+ auto scanForClangModuleDependency = [this , &moduleLookupResult,
1104
+ &resultAccessLock , &seenClangModules](
1113
1105
Identifier moduleIdentifier) {
1114
- auto moduleName = moduleIdentifier.str ();
1115
- {
1116
- std::lock_guard<std::mutex> guard (cacheAccessLock);
1117
- if (cache.hasDependency (moduleName, ModuleDependencyKind::Clang))
1118
- return ;
1119
- }
1120
-
1121
1106
auto scanResult = withDependencyScanningWorker (
1122
1107
[&seenClangModules,
1123
1108
moduleIdentifier](ModuleDependencyScanningWorker *ScanningWorker) {
1124
1109
return ScanningWorker->scanFilesystemForClangModuleDependency (
1125
1110
moduleIdentifier, seenClangModules);
1126
1111
});
1127
-
1128
- // Update the `moduleLookupResult` and cache all discovered dependencies
1129
- // so that subsequent queries do not have to call into the scanner
1130
- // if looking for a module that was discovered as a transitive
1131
- // dependency in this scan.
1132
1112
{
1133
- std::lock_guard<std::mutex> guard (cacheAccessLock);
1134
- moduleLookupResult.insert_or_assign (moduleName, scanResult);
1135
- if (!scanResult.foundDependencyModuleGraph .empty ())
1136
- cache.recordDependencies (scanResult.foundDependencyModuleGraph ,
1137
- IssueReporter.Diagnostics );
1113
+ std::lock_guard<std::mutex> guard (resultAccessLock);
1114
+ moduleLookupResult.insert_or_assign (moduleIdentifier.str (), scanResult);
1138
1115
}
1139
1116
};
1140
1117
@@ -1154,35 +1131,37 @@ void ModuleDependencyScanner::resolveAllClangModuleDependencies(
1154
1131
std::vector<ScannerImportStatementInfo> failedToResolveImports;
1155
1132
ModuleDependencyIDSetVector importedClangDependencies;
1156
1133
auto recordResolvedClangModuleImport =
1157
- [&moduleLookupResult, &importedClangDependencies, &cache,
1134
+ [this , &moduleLookupResult, &importedClangDependencies, &cache,
1158
1135
&allDiscoveredClangModules, moduleID, &failedToResolveImports](
1159
1136
const ScannerImportStatementInfo &moduleImport,
1160
1137
bool optionalImport) {
1161
- auto lookupResult = moduleLookupResult[moduleImport.importIdentifier ];
1162
- // The imported module was found in the cache
1163
- if (lookupResult == std::nullopt ) {
1164
- importedClangDependencies.insert (
1165
- {moduleImport.importIdentifier , ModuleDependencyKind::Clang});
1166
- } else {
1167
- // Cache discovered module dependencies.
1168
- if (!lookupResult.value ().foundDependencyModuleGraph .empty ()) {
1169
- importedClangDependencies.insert (
1170
- {moduleImport.importIdentifier , ModuleDependencyKind::Clang});
1138
+ ASSERT (moduleLookupResult.contains (moduleImport.importIdentifier ));
1139
+ const auto &lookupResult =
1140
+ moduleLookupResult.at (moduleImport.importIdentifier );
1141
+ // Cache discovered module dependencies.
1142
+ if (!lookupResult.foundDependencyModuleGraph .empty () ||
1143
+ !lookupResult.visibleModuleIdentifiers .empty ()) {
1144
+ if (!lookupResult.foundDependencyModuleGraph .empty ()) {
1145
+ cache.recordClangDependencies (lookupResult.foundDependencyModuleGraph ,
1146
+ IssueReporter.Diagnostics );
1171
1147
// Add the full transitive dependency set
1172
- for (const auto &dep :
1173
- lookupResult.value ().foundDependencyModuleGraph )
1148
+ for (const auto &dep : lookupResult.foundDependencyModuleGraph )
1174
1149
allDiscoveredClangModules.insert (dep.first );
1175
- // Add visible Clang modules for this query to the depending
1176
- // Swift module
1177
- cache.addVisibleClangModules (
1178
- moduleID, lookupResult->visibleModuleIdentifiers );
1179
- } else if (!optionalImport) {
1180
- // Otherwise, we failed to resolve this dependency. We will try
1181
- // again using the cache after all other imports have been
1182
- // resolved. If that fails too, a scanning failure will be
1183
- // diagnosed.
1184
- failedToResolveImports.push_back (moduleImport);
1185
1150
}
1151
+
1152
+ importedClangDependencies.insert (
1153
+ {moduleImport.importIdentifier , ModuleDependencyKind::Clang});
1154
+
1155
+ // Add visible Clang modules for this query to the depending
1156
+ // Swift module
1157
+ cache.addVisibleClangModules (moduleID,
1158
+ lookupResult.visibleModuleIdentifiers );
1159
+ } else if (!optionalImport) {
1160
+ // Otherwise, we failed to resolve this dependency. We will try
1161
+ // again using the cache after all other imports have been
1162
+ // resolved. If that fails too, a scanning failure will be
1163
+ // diagnosed.
1164
+ failedToResolveImports.push_back (moduleImport);
1186
1165
}
1187
1166
};
1188
1167
0 commit comments