@@ -165,20 +165,26 @@ static void findAllImportedClangModules(ASTContext &ctx, StringRef moduleName,
165
165
return ;
166
166
167
167
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 ())
169
171
findAllImportedClangModules (ctx, dep.first , cache, allModules, knownModules);
170
- }
171
172
}
172
173
173
174
// Get all dependencies's IDs of this module from its cached
174
175
// 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) {
178
179
const auto &optionalModuleInfo =
179
180
cache.findDependency (moduleID.first , moduleID.second );
180
181
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;
182
188
}
183
189
184
190
// / Implements a topological sort via recursion and reverse postorder DFS.
@@ -200,7 +206,7 @@ computeTopologicalSortOfExplicitDependencies(
200
206
return ;
201
207
202
208
// Otherwise, visit each adjacent node.
203
- for (const auto &succID : getDependencies (moduleID, cache)) {
209
+ for (const auto &succID : getAllDependencies (moduleID, cache)) {
204
210
// We don't worry if successor is already in this current stack,
205
211
// since that would mean we have found a cycle, which should not
206
212
// be possible because we checked for cycles earlier.
@@ -249,7 +255,7 @@ computeTransitiveClosureOfExplicitDependencies(
249
255
it != end; ++it) {
250
256
const auto &modID = *it;
251
257
auto &modReachableSet = result[modID];
252
- for (const auto &succID : getDependencies (modID, cache)) {
258
+ for (const auto &succID : getAllDependencies (modID, cache)) {
253
259
const auto &succReachableSet = result[succID];
254
260
llvm::set_union (modReachableSet, succReachableSet);
255
261
}
@@ -517,10 +523,10 @@ static llvm::Error resolveExplicitModuleInputs(
517
523
518
524
// / Resolve the direct dependencies of the given module.
519
525
static 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 );
524
530
auto &ctx = instance.getASTContext ();
525
531
auto optionalKnownDependencies = cache.findDependency (moduleID.first , moduleID.second );
526
532
assert (optionalKnownDependencies.has_value ());
@@ -529,7 +535,7 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID moduleI
529
535
// If this dependency has already been resolved, return the result.
530
536
if (knownDependencies->isResolved () &&
531
537
knownDependencies->getKind () != ModuleDependencyKind::SwiftSource)
532
- return knownDependencies-> getModuleDependencies ( );
538
+ return getAllDependencies (moduleID, cache );
533
539
534
540
auto isSwiftInterfaceOrSource = knownDependencies->isSwiftInterfaceModule () ||
535
541
knownDependencies->isSwiftSourceModule ();
@@ -621,10 +627,6 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID moduleI
621
627
ctx.getSwiftModuleDependencies (clangDep, cache, ASTDelegate)) {
622
628
if (clangDep != moduleID.first ) {
623
629
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 ()});
628
630
}
629
631
}
630
632
}
@@ -716,7 +718,7 @@ static void discoverCrossImportOverlayDependencies(
716
718
++currentModuleIdx) {
717
719
auto module = allModules[currentModuleIdx];
718
720
auto moduleDependnencyIDs =
719
- resolveDirectDependencies (instance, module , cache, ASTDelegate);
721
+ resolveDependencies (instance, module , cache, ASTDelegate);
720
722
allModules.insert (moduleDependnencyIDs.begin (), moduleDependnencyIDs.end ());
721
723
}
722
724
@@ -1350,7 +1352,7 @@ generateFullDependencyGraph(CompilerInstance &instance,
1350
1352
auto optionalDepInfo = cache.findDependency (module .first , module .second );
1351
1353
assert (optionalDepInfo.has_value () && " Missing dependency info during graph generation diagnosis." );
1352
1354
auto depInfo = optionalDepInfo.value ();
1353
- auto directDependencies = depInfo->getModuleDependencies ();
1355
+ auto directDependencies = depInfo->getDirectModuleDependencies ();
1354
1356
1355
1357
// Generate a swiftscan_clang_details_t object based on the dependency kind
1356
1358
auto getModuleDetails = [&]() -> swiftscan_module_details_t {
@@ -1490,7 +1492,7 @@ static bool diagnoseCycle(CompilerInstance &instance,
1490
1492
assert (optionalDepInfo.has_value () && " Missing dependency info during cycle diagnosis." );
1491
1493
auto depInfo = optionalDepInfo.value ();
1492
1494
1493
- for (const auto &dep : depInfo-> getModuleDependencies ( )) {
1495
+ for (const auto &dep : getAllDependencies (lastOpen, cache )) {
1494
1496
if (closeSet.count (dep))
1495
1497
continue ;
1496
1498
if (openSet.insert (dep)) {
@@ -2009,7 +2011,14 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
2009
2011
++currentModuleIdx) {
2010
2012
auto module = allModules[currentModuleIdx];
2011
2013
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
+
2013
2022
allModules.insert (discoveredModules.begin (), discoveredModules.end ());
2014
2023
}
2015
2024
@@ -2161,7 +2170,7 @@ swift::dependencies::performBatchModuleScan(
2161
2170
currentModuleIdx < allModules.size (); ++currentModuleIdx) {
2162
2171
auto module = allModules[currentModuleIdx];
2163
2172
auto discoveredModules =
2164
- resolveDirectDependencies (instance, module , cache, ASTDelegate);
2173
+ resolveDependencies (instance, module , cache, ASTDelegate);
2165
2174
allModules.insert (discoveredModules.begin (), discoveredModules.end ());
2166
2175
}
2167
2176
0 commit comments