@@ -680,8 +680,10 @@ static bool scanModuleDependencies(CompilerInstance &instance,
680
680
681
681
llvm::SetVector<ModuleDependencyID, std::vector<ModuleDependencyID>,
682
682
std::set<ModuleDependencyID>> allModules;
683
- // Create the module dependency cache.
684
- ModuleDependenciesCache cache;
683
+ // Retrieve the instance's module dependency cache.
684
+ ModuleDependenciesCache *cache = instance.getModuleDependencyCache ();
685
+ assert (cache &&
686
+ " Dependency Scanner expected a ModuleDependenciesCache on a compiler instance." );
685
687
InterfaceSubContextDelegateImpl ASTDelegate (ctx.SourceMgr , ctx.Diags ,
686
688
ctx.SearchPathOpts , ctx.LangOpts ,
687
689
ctx.ClangImporterOpts ,
@@ -697,11 +699,11 @@ static bool scanModuleDependencies(CompilerInstance &instance,
697
699
if (isClang) {
698
700
// Loading the clang module using Clang importer.
699
701
// This action will populate the cache with the main module's dependencies.
700
- rootDeps = ctx.getModuleDependencies (moduleName, /* IsClang*/ true , cache,
702
+ rootDeps = ctx.getModuleDependencies (moduleName, /* IsClang*/ true , * cache,
701
703
ASTDelegate);
702
704
} else {
703
705
// Loading the swift module's dependencies.
704
- rootDeps = ctx.getSwiftModuleDependencies (moduleName, cache, ASTDelegate);
706
+ rootDeps = ctx.getSwiftModuleDependencies (moduleName, * cache, ASTDelegate);
705
707
}
706
708
if (!rootDeps.hasValue ()) {
707
709
// We cannot find the clang module, abort.
@@ -723,11 +725,11 @@ static bool scanModuleDependencies(CompilerInstance &instance,
723
725
++currentModuleIdx) {
724
726
auto module = allModules[currentModuleIdx];
725
727
auto discoveredModules =
726
- resolveDirectDependencies (instance, module , cache, ASTDelegate);
728
+ resolveDirectDependencies (instance, module , * cache, ASTDelegate);
727
729
allModules.insert (discoveredModules.begin (), discoveredModules.end ());
728
730
}
729
731
// Write out the JSON description.
730
- writeJSON (out, instance, cache, ASTDelegate, allModules.getArrayRef ());
732
+ writeJSON (out, instance, * cache, ASTDelegate, allModules.getArrayRef ());
731
733
return false ;
732
734
}
733
735
@@ -889,9 +891,11 @@ bool swift::scanDependencies(CompilerInstance &instance) {
889
891
890
892
allModules.insert ({mainModuleName.str (), mainDependencies.getKind ()});
891
893
892
- // Create the module dependency cache.
893
- ModuleDependenciesCache cache;
894
- cache.recordDependencies (mainModuleName, std::move (mainDependencies));
894
+ // Retrieve the instance's module dependency cache.
895
+ ModuleDependenciesCache *cache = instance.getModuleDependencyCache ();
896
+ assert (cache &&
897
+ " Dependency Scanner expected a ModuleDependenciesCache on a compiler instance." );
898
+ cache->recordDependencies (mainModuleName, std::move (mainDependencies));
895
899
896
900
auto &ctx = instance.getASTContext ();
897
901
auto ModuleCachePath = getModuleCachePathFromClang (ctx
@@ -914,28 +918,28 @@ bool swift::scanDependencies(CompilerInstance &instance) {
914
918
++currentModuleIdx) {
915
919
auto module = allModules[currentModuleIdx];
916
920
auto discoveredModules =
917
- resolveDirectDependencies (instance, module , cache, ASTDelegate);
921
+ resolveDirectDependencies (instance, module , * cache, ASTDelegate);
918
922
allModules.insert (discoveredModules.begin (), discoveredModules.end ());
919
923
}
920
924
921
925
// We have all explicit imports now, resolve cross import overlays.
922
926
discoverCrosssImportOverlayDependencies (instance, mainModuleName,
923
- /* All transitive dependencies*/ allModules.getArrayRef ().slice (1 ), cache,
927
+ /* All transitive dependencies*/ allModules.getArrayRef ().slice (1 ), * cache,
924
928
ASTDelegate, [&](ModuleDependencyID id) {
925
929
allModules.insert (id);
926
930
});
927
931
928
932
// Dignose cycle in dependency graph.
929
- if (diagnoseCycle (instance, cache, /* MainModule*/ allModules.front (), ASTDelegate))
933
+ if (diagnoseCycle (instance, * cache, /* MainModule*/ allModules.front (), ASTDelegate))
930
934
return true ;
931
935
932
936
// Write out the JSON description.
933
- writeJSON (out, instance, cache, ASTDelegate, allModules.getArrayRef ());
937
+ writeJSON (out, instance, * cache, ASTDelegate, allModules.getArrayRef ());
934
938
935
939
// Update the dependency tracker.
936
940
if (auto depTracker = instance.getDependencyTracker ()) {
937
941
for (auto module : allModules) {
938
- auto deps = cache. findDependencies (module .first , module .second );
942
+ auto deps = cache-> findDependencies (module .first , module .second );
939
943
if (!deps)
940
944
continue ;
941
945
0 commit comments