Skip to content

Commit 81aa7b1

Browse files
[DependencyScanning] Fix clang submodule canImport check after swiftlang#70974
When clang submodule is used in `canImport` check, it should return the top level module as dependency, not the submodule. This fixes a regression after swiftlang#70974 that causes dependency scanning to fail due to failed submodule lookup during dependency scanning.
1 parent be35394 commit 81aa7b1

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,10 +2382,12 @@ bool ASTContext::canImportModule(ImportPath::Module ModuleName,
23822382
if (!canImportModuleImpl(ModuleName, version, underlyingVersion, true))
23832383
return false;
23842384

2385-
// If inserted successfully, add that to success list as dependency.
2386-
SmallString<64> FullModuleName;
2387-
ModuleName.getString(FullModuleName);
2388-
SucceededModuleImportNames.insert(FullModuleName.str());
2385+
// If checked successfully, add the top level name to success list as
2386+
// dependency to handle clang submodule correctly. Swift does not have
2387+
// submodule so the name should be the same.
2388+
SmallString<64> TopModuleName;
2389+
ModuleName.getTopLevelPath().getString(TopModuleName);
2390+
SucceededModuleImportNames.insert(TopModuleName.str());
23892391
return true;
23902392
}
23912393

test/CAS/can-import.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@
6969

7070
//--- main.swift
7171
#if canImport(A.Sub)
72-
import A.Sub
72+
func a() {}
7373
#endif
7474

7575
#if canImport(A.Missing)
7676
import A.Missing
7777
#endif
7878

79-
#if canImport(B) // never actually import B
79+
#if canImport(B)
8080
func b() {}
8181
#endif
8282

@@ -99,7 +99,7 @@ module B {
9999
}
100100

101101
//--- include/sub.h
102-
void a(void);
102+
void notused(void);
103103

104104
//--- include/B.h
105-
void notused(void);
105+
void notused2(void);

test/ScanDependencies/module_deps_can_import.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -module-name Test -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -swift-version 4
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %t/main.swift -module-name Test -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -I %t/include -swift-version 4
34

45
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps.json Test directDependencies | %FileCheck %s
56

67
// CHECK-DAG: "clang": "C"
8+
// CHECK-DAG: "clang": "ClangTest"
79
// CHECK-DAG: "swift": "A"
810
// CHECK-DAG: "swift": "F"
911
// CHECK-NOT: "swift": "G"
1012
// CHECK-NOT: "swift": "B"
1113
// CHECK-NOT: "Missing"
1214

15+
//--- main.swift
16+
1317
#if canImport(Missing)
1418
import G
1519
#endif
@@ -32,3 +36,18 @@ import Missing
3236
// B is short circuited
3337
#if canImport(C) || canImport(B)
3438
#endif
39+
40+
// Check clang submodule, this should import ClangTest, not ClangTest.Sub
41+
#if canImport(ClangTest.Sub)
42+
#endif
43+
44+
//--- include/module.modulemap
45+
module ClangTest {
46+
module Sub {
47+
header "sub.h"
48+
export *
49+
}
50+
}
51+
52+
//--- include/sub.h
53+
void notused(void);

0 commit comments

Comments
 (0)