Skip to content

Commit 99a0919

Browse files
committed
[Fast Dependency Scanner] Ensure Swift modules don't depend on self.
When resolving direct dependencies for a given Swift module, we go over all Clang module dependencies and add, as additional dependencies, their Swift overlays. We find overlays by querying `ASTContext::getModuleDependencies` with the Clang module's name. If the Clang module in question is a dependency of a Swift module with the same name, we will end up adding the Swift module as its own dependence. e.g. - Swift A depends on Clang A - Add Clang A to dependencies of Swift A - We look for overlays of Clang A, by name, and find Swift A - Add Swift A to dependencies of Swift A From what I can tell, the logic upstream is sound, and `getModuleDependencies` is doing the right thing, so this change is simply restricting what gets added when we are looking for overlays. Resolves rdar://problem/63731428
1 parent a676a37 commit 99a0919

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)