Skip to content

Commit d477efb

Browse files
Merge pull request #38039 from apple/QuietMisdreavus/overlay-symbol-extensions
[SymbolGraph] rename symbol graph files for cross-import overlays
2 parents f44d1f7 + 183db81 commit d477efb

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

lib/SymbolGraphGen/SymbolGraphASTWalker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(const Decl *D) {
4545

4646
if (this->M.getNameStr().equals(M->getNameStr())) {
4747
return &MainGraph;
48+
} else if (MainGraph.DeclaringModule.hasValue() &&
49+
MainGraph.DeclaringModule.getValue()->getNameStr().equals(M->getNameStr())) {
50+
// Cross-import overlay modules already appear as "extensions" of their declaring module; we
51+
// should put actual extensions of that module into the main graph
52+
return &MainGraph;
4853
}
4954
auto Found = ExtendedModuleGraphs.find(M->getNameStr());
5055
if (Found != ExtendedModuleGraphs.end()) {

lib/SymbolGraphGen/SymbolGraphGen.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,14 @@ namespace {
2525
int serializeSymbolGraph(SymbolGraph &SG,
2626
const SymbolGraphOptions &Options) {
2727
SmallString<256> FileName;
28-
if (SG.DeclaringModule.hasValue()) {
29-
// Save a cross-import overlay symbol graph as `MainModule@BystandingModule[@BystandingModule...]@OverlayModule.symbols.json`
30-
//
31-
// The overlay module's name is added as a disambiguator in case an overlay
32-
// declares multiple modules for the same set of imports.
33-
FileName.append(SG.DeclaringModule.getValue()->getNameStr());
34-
for (auto BystanderModule : SG.BystanderModules) {
35-
FileName.push_back('@');
36-
FileName.append(BystanderModule.str());
37-
}
38-
28+
FileName.append(SG.M.getNameStr());
29+
if (SG.ExtendedModule.hasValue()) {
3930
FileName.push_back('@');
40-
FileName.append(SG.M.getNameStr());
41-
} else {
42-
FileName.append(SG.M.getNameStr());
43-
44-
if (SG.ExtendedModule.hasValue()) {
45-
FileName.push_back('@');
46-
FileName.append(SG.ExtendedModule.getValue()->getNameStr());
47-
}
31+
FileName.append(SG.ExtendedModule.getValue()->getNameStr());
32+
} else if (SG.DeclaringModule.hasValue()) {
33+
// Treat cross-import overlay modules as "extensions" of their declaring module
34+
FileName.push_back('@');
35+
FileName.append(SG.DeclaringModule.getValue()->getNameStr());
4836
}
4937
FileName.append(".symbols.json");
5038

test/SymbolGraph/Module/CrossImport.swift

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// RUN: %target-build-swift %s -module-name _A_B -I %t -emit-module -emit-module-path %t/
55
// RUN: cp -r %S/Inputs/CrossImport/A.swiftcrossimport %t/
66
// RUN: %target-swift-symbolgraph-extract -module-name A -I %t -pretty-print -output-dir %t
7-
// RUN: %FileCheck %s --input-file %t/A@B@_A_B.symbols.json
7+
// RUN: %FileCheck %s --input-file %t/[email protected] --check-prefix CHECK-MOD
8+
// RUN: %FileCheck %s --input-file %t/[email protected] --check-prefix CHECK-A
9+
// RUN: %FileCheck %s --input-file %t/[email protected] --check-prefix CHECK-MOD
10+
// RUN: %FileCheck %s --input-file %t/[email protected] --check-prefix CHECK-B
811

912
@_exported import A
1013
import B
@@ -15,7 +18,26 @@ extension A {
1518
}
1619
}
1720

18-
// CHECK: module
19-
// CHECK-NEXT: "name": "A"
20-
// CHECK-NEXT: bystanders
21-
// CHECK-NEXT: B
21+
public struct LocalStruct {}
22+
23+
extension LocalStruct {
24+
public func someFunc() {}
25+
}
26+
27+
extension B {
28+
public func untransmogrify() -> A {
29+
return A(x: self.y)
30+
}
31+
}
32+
33+
// CHECK-MOD: module
34+
// CHECK-MOD-NEXT: "name": "A"
35+
// CHECK-MOD-NEXT: bystanders
36+
// CHECK-MOD-NEXT: B
37+
38+
// CHECK-A-NOT: s:1BAAV4_A_BE14untransmogrify1AAEVyF
39+
// CHECK-A-DAG: s:1AAAV4_A_BE12transmogrify1BAEVyF
40+
// CHECK-A-DAG: s:4_A_B11LocalStructV
41+
// CHECK-A-DAG: s:4_A_B11LocalStructV8someFuncyyF
42+
43+
// CHECK-B: s:1BAAV4_A_BE14untransmogrify1AAEVyF
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
public struct A {
22
public var x: Int
3+
4+
public init(x: Int) {
5+
self.x = x
6+
}
37
}

0 commit comments

Comments
 (0)