@@ -680,8 +680,10 @@ static bool scanModuleDependencies(CompilerInstance &instance,
680680
681681 llvm::SetVector<ModuleDependencyID, std::vector<ModuleDependencyID>,
682682 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." );
685687 InterfaceSubContextDelegateImpl ASTDelegate (ctx.SourceMgr , ctx.Diags ,
686688 ctx.SearchPathOpts , ctx.LangOpts ,
687689 ctx.ClangImporterOpts ,
@@ -697,11 +699,11 @@ static bool scanModuleDependencies(CompilerInstance &instance,
697699 if (isClang) {
698700 // Loading the clang module using Clang importer.
699701 // 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,
701703 ASTDelegate);
702704 } else {
703705 // Loading the swift module's dependencies.
704- rootDeps = ctx.getSwiftModuleDependencies (moduleName, cache, ASTDelegate);
706+ rootDeps = ctx.getSwiftModuleDependencies (moduleName, * cache, ASTDelegate);
705707 }
706708 if (!rootDeps.hasValue ()) {
707709 // We cannot find the clang module, abort.
@@ -723,11 +725,11 @@ static bool scanModuleDependencies(CompilerInstance &instance,
723725 ++currentModuleIdx) {
724726 auto module = allModules[currentModuleIdx];
725727 auto discoveredModules =
726- resolveDirectDependencies (instance, module , cache, ASTDelegate);
728+ resolveDirectDependencies (instance, module , * cache, ASTDelegate);
727729 allModules.insert (discoveredModules.begin (), discoveredModules.end ());
728730 }
729731 // Write out the JSON description.
730- writeJSON (out, instance, cache, ASTDelegate, allModules.getArrayRef ());
732+ writeJSON (out, instance, * cache, ASTDelegate, allModules.getArrayRef ());
731733 return false ;
732734}
733735
@@ -889,9 +891,11 @@ bool swift::scanDependencies(CompilerInstance &instance) {
889891
890892 allModules.insert ({mainModuleName.str (), mainDependencies.getKind ()});
891893
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));
895899
896900 auto &ctx = instance.getASTContext ();
897901 auto ModuleCachePath = getModuleCachePathFromClang (ctx
@@ -914,28 +918,28 @@ bool swift::scanDependencies(CompilerInstance &instance) {
914918 ++currentModuleIdx) {
915919 auto module = allModules[currentModuleIdx];
916920 auto discoveredModules =
917- resolveDirectDependencies (instance, module , cache, ASTDelegate);
921+ resolveDirectDependencies (instance, module , * cache, ASTDelegate);
918922 allModules.insert (discoveredModules.begin (), discoveredModules.end ());
919923 }
920924
921925 // We have all explicit imports now, resolve cross import overlays.
922926 discoverCrosssImportOverlayDependencies (instance, mainModuleName,
923- /* All transitive dependencies*/ allModules.getArrayRef ().slice (1 ), cache,
927+ /* All transitive dependencies*/ allModules.getArrayRef ().slice (1 ), * cache,
924928 ASTDelegate, [&](ModuleDependencyID id) {
925929 allModules.insert (id);
926930 });
927931
928932 // Dignose cycle in dependency graph.
929- if (diagnoseCycle (instance, cache, /* MainModule*/ allModules.front (), ASTDelegate))
933+ if (diagnoseCycle (instance, * cache, /* MainModule*/ allModules.front (), ASTDelegate))
930934 return true ;
931935
932936 // Write out the JSON description.
933- writeJSON (out, instance, cache, ASTDelegate, allModules.getArrayRef ());
937+ writeJSON (out, instance, * cache, ASTDelegate, allModules.getArrayRef ());
934938
935939 // Update the dependency tracker.
936940 if (auto depTracker = instance.getDependencyTracker ()) {
937941 for (auto module : allModules) {
938- auto deps = cache. findDependencies (module .first , module .second );
942+ auto deps = cache-> findDependencies (module .first , module .second );
939943 if (!deps)
940944 continue ;
941945
0 commit comments