Skip to content

Commit 26125f5

Browse files
authored
Merge pull request swiftlang#32083 from artemcm/RecycleYourSwiftModules
[Fast Dependency Scanner] Ensure Swift modules don't depend on self.
2 parents 68ba9cf + 99a0919 commit 26125f5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ static std::vector<ModuleDependencyID> resolveDirectDependencies(
130130
for (const auto &clangDep : allClangModules) {
131131
if (auto found = ctx.getModuleDependencies(
132132
clangDep, /*onlyClangModule=*/false, cache, ASTDelegate)) {
133-
if (found->getKind() == ModuleDependenciesKind::Swift)
133+
// ASTContext::getModuleDependencies returns dependencies for a module with a given name.
134+
// This Clang module may have the same name as the Swift module we are resolving, so we
135+
// need to make sure we don't add a dependency from a Swift module to itself.
136+
if (found->getKind() == ModuleDependenciesKind::Swift && clangDep != module.first)
134137
result.push_back({clangDep, found->getKind()});
135138
}
136139
}

test/ScanDependencies/module_deps.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ import G
126126
// CHECK: "directDependencies"
127127
// CHECK-NEXT: {
128128
// CHECK-NEXT: "clang": "G"
129-
// CHECK-NEXT: },
130-
// CHECK-NEXT: {
131-
// CHECK-NEXT: "swift": "G"
132129
// CHECK-NEXT: }
130+
// CHECK-NEXT: ],
131+
// CHECK-NEXT: "details": {
133132

134133
// CHECK: "contextHash": "{{.*}}",
135134
// CHECK: "commandLine": [

0 commit comments

Comments
 (0)