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