@@ -223,45 +223,26 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
223
223
workerCompilerInvocation->getSearchPathOptions ().ModuleLoadMode );
224
224
}
225
225
226
- ModuleDependencyVector
227
- ModuleDependencyScanningWorker::scanFilesystemForModuleDependency (
228
- Identifier moduleName, const ModuleDependenciesCache &cache,
229
- bool isTestableImport) {
230
- // First query a Swift module, otherwise lookup a Clang module
231
- ModuleDependencyVector moduleDependencies =
232
- swiftScannerModuleLoader->getModuleDependencies (
233
- moduleName, cache.getModuleOutputPath (),
234
- cache.getAlreadySeenClangModules (), clangScanningTool,
235
- *scanningASTDelegate, cache.getScanService ().getPrefixMapper (),
236
- isTestableImport);
237
-
238
- if (moduleDependencies.empty ())
239
- moduleDependencies = clangScannerModuleLoader->getModuleDependencies (
240
- moduleName, cache.getModuleOutputPath (),
241
- cache.getAlreadySeenClangModules (), clangScanningTool,
242
- *scanningASTDelegate, cache.getScanService ().getPrefixMapper (),
243
- isTestableImport);
244
-
245
- return moduleDependencies;
246
- }
247
-
248
226
ModuleDependencyVector
249
227
ModuleDependencyScanningWorker::scanFilesystemForSwiftModuleDependency (
250
- Identifier moduleName, const ModuleDependenciesCache &cache ,
251
- bool isTestableImport) {
228
+ Identifier moduleName, StringRef moduleOutputPath ,
229
+ llvm::PrefixMapper *prefixMapper, bool isTestableImport) {
252
230
return swiftScannerModuleLoader->getModuleDependencies (
253
- moduleName, cache. getModuleOutputPath () ,
254
- cache. getAlreadySeenClangModules () , clangScanningTool,
255
- *scanningASTDelegate, cache. getScanService (). getPrefixMapper () , isTestableImport);
231
+ moduleName, moduleOutputPath ,
232
+ {} , clangScanningTool, *scanningASTDelegate ,
233
+ prefixMapper , isTestableImport);
256
234
}
257
235
258
236
ModuleDependencyVector
259
237
ModuleDependencyScanningWorker::scanFilesystemForClangModuleDependency (
260
- Identifier moduleName, const ModuleDependenciesCache &cache) {
238
+ Identifier moduleName,
239
+ StringRef moduleOutputPath,
240
+ const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenModules,
241
+ llvm::PrefixMapper *prefixMapper) {
261
242
return clangScannerModuleLoader->getModuleDependencies (
262
- moduleName, cache. getModuleOutputPath () ,
263
- cache. getAlreadySeenClangModules () , clangScanningTool,
264
- *scanningASTDelegate, cache. getScanService (). getPrefixMapper () , false );
243
+ moduleName, moduleOutputPath ,
244
+ alreadySeenModules , clangScanningTool,
245
+ *scanningASTDelegate, prefixMapper , false );
265
246
}
266
247
267
248
template <typename Function, typename ... Args>
@@ -503,7 +484,9 @@ ModuleDependencyScanner::getNamedClangModuleDependencyInfo(
503
484
auto moduleDependencies = withDependencyScanningWorker (
504
485
[&cache, moduleIdentifier](ModuleDependencyScanningWorker *ScanningWorker) {
505
486
return ScanningWorker->scanFilesystemForClangModuleDependency (
506
- moduleIdentifier, cache);
487
+ moduleIdentifier, cache.getModuleOutputPath (),
488
+ cache.getAlreadySeenClangModules (),
489
+ cache.getScanService ().getPrefixMapper ());
507
490
});
508
491
if (moduleDependencies.empty ())
509
492
return std::nullopt;
@@ -539,7 +522,8 @@ ModuleDependencyScanner::getNamedSwiftModuleDependencyInfo(
539
522
auto moduleDependencies = withDependencyScanningWorker (
540
523
[&cache, moduleIdentifier](ModuleDependencyScanningWorker *ScanningWorker) {
541
524
return ScanningWorker->scanFilesystemForSwiftModuleDependency (
542
- moduleIdentifier, cache);
525
+ moduleIdentifier, cache.getModuleOutputPath (),
526
+ cache.getScanService ().getPrefixMapper ());
543
527
});
544
528
if (moduleDependencies.empty ())
545
529
return std::nullopt;
@@ -755,29 +739,36 @@ ModuleDependencyScanner::resolveAllClangModuleDependencies(
755
739
moduleLookupResult.insert (
756
740
std::make_pair (unresolvedIdentifier.getKey (), std::nullopt));
757
741
758
- std::mutex CacheAccessLock;
742
+ // We need a copy of the shared already-seen module set, which will be shared amongst
743
+ // all the workers. In `recordDependencies`, each worker will contribute its
744
+ // results back to the shared set for future lookups.
745
+ const llvm::DenseSet<clang::tooling::dependencies::ModuleID> seenClangModules =
746
+ cache.getAlreadySeenClangModules ();
747
+ std::mutex cacheAccessLock;
759
748
auto scanForClangModuleDependency =
760
- [this , &cache, &moduleLookupResult, &CacheAccessLock](Identifier moduleIdentifier) {
749
+ [this , &cache, &moduleLookupResult,
750
+ &cacheAccessLock, &seenClangModules](Identifier moduleIdentifier) {
761
751
auto moduleName = moduleIdentifier.str ();
762
752
{
763
- std::lock_guard<std::mutex> guard (CacheAccessLock );
753
+ std::lock_guard<std::mutex> guard (cacheAccessLock );
764
754
if (cache.hasDependency (moduleName, ModuleDependencyKind::Clang))
765
755
return ;
766
756
}
767
757
768
758
auto moduleDependencies = withDependencyScanningWorker (
769
- [&cache,
759
+ [&cache, &seenClangModules,
770
760
moduleIdentifier](ModuleDependencyScanningWorker *ScanningWorker) {
771
761
return ScanningWorker->scanFilesystemForClangModuleDependency (
772
- moduleIdentifier, cache);
762
+ moduleIdentifier, cache.getModuleOutputPath (),
763
+ seenClangModules, cache.getScanService ().getPrefixMapper ());
773
764
});
774
765
775
766
// Update the `moduleLookupResult` and cache all discovered dependencies
776
767
// so that subsequent queries do not have to call into the scanner
777
768
// if looking for a module that was discovered as a transitive dependency
778
769
// in this scan.
779
770
{
780
- std::lock_guard<std::mutex> guard (CacheAccessLock );
771
+ std::lock_guard<std::mutex> guard (cacheAccessLock );
781
772
moduleLookupResult.insert_or_assign (moduleName, moduleDependencies);
782
773
if (!moduleDependencies.empty ())
783
774
cache.recordDependencies (moduleDependencies);
@@ -952,7 +943,8 @@ void ModuleDependencyScanner::resolveSwiftImportsForModule(
952
943
[&cache, moduleIdentifier,
953
944
isTestable](ModuleDependencyScanningWorker *ScanningWorker) {
954
945
return ScanningWorker->scanFilesystemForSwiftModuleDependency (
955
- moduleIdentifier, cache, isTestable);
946
+ moduleIdentifier, cache.getModuleOutputPath (),
947
+ cache.getScanService ().getPrefixMapper (), isTestable);
956
948
});
957
949
moduleLookupResult.insert_or_assign (moduleName, moduleDependencies);
958
950
};
@@ -1094,7 +1086,8 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
1094
1086
[&cache,
1095
1087
moduleIdentifier](ModuleDependencyScanningWorker *ScanningWorker) {
1096
1088
return ScanningWorker->scanFilesystemForSwiftModuleDependency (
1097
- moduleIdentifier, cache);
1089
+ moduleIdentifier, cache.getModuleOutputPath (),
1090
+ cache.getScanService ().getPrefixMapper ());
1098
1091
});
1099
1092
swiftOverlayLookupResult.insert_or_assign (moduleName, moduleDependencies);
1100
1093
};
0 commit comments