mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
rename symbol graph files for cross-import overlays
rdar://79474927
This commit is contained in:
@@ -45,6 +45,11 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(const Decl *D) {
|
||||
|
||||
if (this->M.getNameStr().equals(M->getNameStr())) {
|
||||
return &MainGraph;
|
||||
} else if (MainGraph.DeclaringModule.hasValue() &&
|
||||
MainGraph.DeclaringModule.getValue()->getNameStr().equals(M->getNameStr())) {
|
||||
// Cross-import overlay modules already appear as "extensions" of their declaring module; we
|
||||
// should put actual extensions of that module into the main graph
|
||||
return &MainGraph;
|
||||
}
|
||||
auto Found = ExtendedModuleGraphs.find(M->getNameStr());
|
||||
if (Found != ExtendedModuleGraphs.end()) {
|
||||
|
||||
@@ -25,26 +25,14 @@ namespace {
|
||||
int serializeSymbolGraph(SymbolGraph &SG,
|
||||
const SymbolGraphOptions &Options) {
|
||||
SmallString<256> FileName;
|
||||
if (SG.DeclaringModule.hasValue()) {
|
||||
// Save a cross-import overlay symbol graph as `MainModule@BystandingModule[@BystandingModule...]@OverlayModule.symbols.json`
|
||||
//
|
||||
// The overlay module's name is added as a disambiguator in case an overlay
|
||||
// declares multiple modules for the same set of imports.
|
||||
FileName.append(SG.DeclaringModule.getValue()->getNameStr());
|
||||
for (auto BystanderModule : SG.BystanderModules) {
|
||||
FileName.push_back('@');
|
||||
FileName.append(BystanderModule.str());
|
||||
}
|
||||
|
||||
FileName.push_back('@');
|
||||
FileName.append(SG.M.getNameStr());
|
||||
} else {
|
||||
FileName.append(SG.M.getNameStr());
|
||||
|
||||
if (SG.ExtendedModule.hasValue()) {
|
||||
FileName.push_back('@');
|
||||
FileName.append(SG.ExtendedModule.getValue()->getNameStr());
|
||||
}
|
||||
} else if (SG.DeclaringModule.hasValue()) {
|
||||
// Treat cross-import overlay modules as "extensions" of their declaring module
|
||||
FileName.push_back('@');
|
||||
FileName.append(SG.DeclaringModule.getValue()->getNameStr());
|
||||
}
|
||||
FileName.append(".symbols.json");
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
// RUN: %target-build-swift %s -module-name _A_B -I %t -emit-module -emit-module-path %t/
|
||||
// RUN: cp -r %S/Inputs/CrossImport/A.swiftcrossimport %t/
|
||||
// RUN: %target-swift-symbolgraph-extract -module-name A -I %t -pretty-print -output-dir %t
|
||||
// RUN: %FileCheck %s --input-file %t/A@B@_A_B.symbols.json
|
||||
// RUN: %FileCheck %s --input-file %t/_A_B@A.symbols.json --check-prefix CHECK-MOD
|
||||
// RUN: %FileCheck %s --input-file %t/_A_B@A.symbols.json --check-prefix CHECK-A
|
||||
// RUN: %FileCheck %s --input-file %t/_A_B@B.symbols.json --check-prefix CHECK-MOD
|
||||
// RUN: %FileCheck %s --input-file %t/_A_B@B.symbols.json --check-prefix CHECK-B
|
||||
|
||||
@_exported import A
|
||||
import B
|
||||
@@ -15,7 +18,26 @@ extension A {
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: module
|
||||
// CHECK-NEXT: "name": "A"
|
||||
// CHECK-NEXT: bystanders
|
||||
// CHECK-NEXT: B
|
||||
public struct LocalStruct {}
|
||||
|
||||
extension LocalStruct {
|
||||
public func someFunc() {}
|
||||
}
|
||||
|
||||
extension B {
|
||||
public func untransmogrify() -> A {
|
||||
return A(x: self.y)
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-MOD: module
|
||||
// CHECK-MOD-NEXT: "name": "A"
|
||||
// CHECK-MOD-NEXT: bystanders
|
||||
// CHECK-MOD-NEXT: B
|
||||
|
||||
// CHECK-A-NOT: s:1BAAV4_A_BE14untransmogrify1AAEVyF
|
||||
// CHECK-A-DAG: s:1AAAV4_A_BE12transmogrify1BAEVyF
|
||||
// CHECK-A-DAG: s:4_A_B11LocalStructV
|
||||
// CHECK-A-DAG: s:4_A_B11LocalStructV8someFuncyyF
|
||||
|
||||
// CHECK-B: s:1BAAV4_A_BE14untransmogrify1AAEVyF
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
public struct A {
|
||||
public var x: Int
|
||||
|
||||
public init(x: Int) {
|
||||
self.x = x
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user