@@ -165,20 +165,26 @@ static void findAllImportedClangModules(ASTContext &ctx, StringRef moduleName,
165165 return ;
166166
167167 auto dependencies = optionalDependencies.value ();
168- for (const auto &dep : dependencies->getModuleDependencies ()) {
168+ for (const auto &dep : dependencies->getDirectModuleDependencies ())
169+ findAllImportedClangModules (ctx, dep.first , cache, allModules, knownModules);
170+ for (const auto &dep : dependencies->getSwiftOverlayDependencies ())
169171 findAllImportedClangModules (ctx, dep.first , cache, allModules, knownModules);
170- }
171172}
172173
173174// Get all dependencies's IDs of this module from its cached
174175// ModuleDependencyInfo
175- static ArrayRef <ModuleDependencyID>
176- getDependencies (const ModuleDependencyID &moduleID,
177- const ModuleDependenciesCache &cache) {
176+ static std::vector <ModuleDependencyID>
177+ getAllDependencies (const ModuleDependencyID &moduleID,
178+ const ModuleDependenciesCache &cache) {
178179 const auto &optionalModuleInfo =
179180 cache.findDependency (moduleID.first , moduleID.second );
180181 assert (optionalModuleInfo.has_value ());
181- return optionalModuleInfo.value ()->getModuleDependencies ();
182+ auto directDependenciesRef = optionalModuleInfo.value ()->getDirectModuleDependencies ();
183+ auto overlayDependenciesRef = optionalModuleInfo.value ()->getSwiftOverlayDependencies ();
184+ std::vector<ModuleDependencyID> result;
185+ result.insert (std::end (result), directDependenciesRef.begin (), directDependenciesRef.end ());
186+ result.insert (std::end (result), overlayDependenciesRef.begin (), overlayDependenciesRef.end ());
187+ return result;
182188}
183189
184190// / Implements a topological sort via recursion and reverse postorder DFS.
@@ -200,7 +206,7 @@ computeTopologicalSortOfExplicitDependencies(
200206 return ;
201207
202208 // Otherwise, visit each adjacent node.
203- for (const auto &succID : getDependencies (moduleID, cache)) {
209+ for (const auto &succID : getAllDependencies (moduleID, cache)) {
204210 // We don't worry if successor is already in this current stack,
205211 // since that would mean we have found a cycle, which should not
206212 // be possible because we checked for cycles earlier.
@@ -249,7 +255,7 @@ computeTransitiveClosureOfExplicitDependencies(
249255 it != end; ++it) {
250256 const auto &modID = *it;
251257 auto &modReachableSet = result[modID];
252- for (const auto &succID : getDependencies (modID, cache)) {
258+ for (const auto &succID : getAllDependencies (modID, cache)) {
253259 const auto &succReachableSet = result[succID];
254260 llvm::set_union (modReachableSet, succReachableSet);
255261 }
@@ -517,10 +523,10 @@ static llvm::Error resolveExplicitModuleInputs(
517523
518524// / Resolve the direct dependencies of the given module.
519525static std::vector<ModuleDependencyID>
520- resolveDirectDependencies (CompilerInstance &instance, ModuleDependencyID moduleID,
521- ModuleDependenciesCache &cache,
522- InterfaceSubContextDelegate &ASTDelegate) {
523- PrettyStackTraceStringAction trace (" Resolving direct dependencies of: " , moduleID.first );
526+ resolveDependencies (CompilerInstance &instance, ModuleDependencyID moduleID,
527+ ModuleDependenciesCache &cache,
528+ InterfaceSubContextDelegate &ASTDelegate) {
529+ PrettyStackTraceStringAction trace (" Resolving dependencies of: " , moduleID.first );
524530 auto &ctx = instance.getASTContext ();
525531 auto optionalKnownDependencies = cache.findDependency (moduleID.first , moduleID.second );
526532 assert (optionalKnownDependencies.has_value ());
@@ -529,7 +535,7 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID moduleI
529535 // If this dependency has already been resolved, return the result.
530536 if (knownDependencies->isResolved () &&
531537 knownDependencies->getKind () != ModuleDependencyKind::SwiftSource)
532- return knownDependencies-> getModuleDependencies ( );
538+ return getAllDependencies (moduleID, cache );
533539
534540 auto isSwiftInterfaceOrSource = knownDependencies->isSwiftInterfaceModule () ||
535541 knownDependencies->isSwiftSourceModule ();
@@ -621,10 +627,6 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID moduleI
621627 ctx.getSwiftModuleDependencies (clangDep, cache, ASTDelegate)) {
622628 if (clangDep != moduleID.first ) {
623629 swiftOverlayDependencies.insert ({clangDep, found.value ()->getKind ()});
624- // FIXME: Once all clients know to fetch these dependencies from
625- // `swiftOverlayDependencies`, the goal is to no longer have them in
626- // `directDependencies` so the following will need to go away.
627- directDependencies.insert ({clangDep, found.value ()->getKind ()});
628630 }
629631 }
630632 }
@@ -716,7 +718,7 @@ static void discoverCrossImportOverlayDependencies(
716718 ++currentModuleIdx) {
717719 auto module = allModules[currentModuleIdx];
718720 auto moduleDependnencyIDs =
719- resolveDirectDependencies (instance, module , cache, ASTDelegate);
721+ resolveDependencies (instance, module , cache, ASTDelegate);
720722 allModules.insert (moduleDependnencyIDs.begin (), moduleDependnencyIDs.end ());
721723 }
722724
@@ -1350,7 +1352,7 @@ generateFullDependencyGraph(CompilerInstance &instance,
13501352 auto optionalDepInfo = cache.findDependency (module .first , module .second );
13511353 assert (optionalDepInfo.has_value () && " Missing dependency info during graph generation diagnosis." );
13521354 auto depInfo = optionalDepInfo.value ();
1353- auto directDependencies = depInfo->getModuleDependencies ();
1355+ auto directDependencies = depInfo->getDirectModuleDependencies ();
13541356
13551357 // Generate a swiftscan_clang_details_t object based on the dependency kind
13561358 auto getModuleDetails = [&]() -> swiftscan_module_details_t {
@@ -1490,7 +1492,7 @@ static bool diagnoseCycle(CompilerInstance &instance,
14901492 assert (optionalDepInfo.has_value () && " Missing dependency info during cycle diagnosis." );
14911493 auto depInfo = optionalDepInfo.value ();
14921494
1493- for (const auto &dep : depInfo-> getModuleDependencies ( )) {
1495+ for (const auto &dep : getAllDependencies (lastOpen, cache )) {
14941496 if (closeSet.count (dep))
14951497 continue ;
14961498 if (openSet.insert (dep)) {
@@ -2009,7 +2011,14 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
20092011 ++currentModuleIdx) {
20102012 auto module = allModules[currentModuleIdx];
20112013 auto discoveredModules =
2012- resolveDirectDependencies (instance, module , cache, ASTDelegate);
2014+ resolveDependencies (instance, module , cache, ASTDelegate);
2015+
2016+ // Do not need to resolve clang modules, those come pre-resolved
2017+ // from the Clang dependency scanner.
2018+ for (const auto &moduleID : discoveredModules)
2019+ if (moduleID.second != ModuleDependencyKind::Clang)
2020+ allModules.insert (moduleID);
2021+
20132022 allModules.insert (discoveredModules.begin (), discoveredModules.end ());
20142023 }
20152024
@@ -2161,7 +2170,7 @@ swift::dependencies::performBatchModuleScan(
21612170 currentModuleIdx < allModules.size (); ++currentModuleIdx) {
21622171 auto module = allModules[currentModuleIdx];
21632172 auto discoveredModules =
2164- resolveDirectDependencies (instance, module , cache, ASTDelegate);
2173+ resolveDependencies (instance, module , cache, ASTDelegate);
21652174 allModules.insert (discoveredModules.begin (), discoveredModules.end ());
21662175 }
21672176
0 commit comments