Skip to content

Commit 7277baa

Browse files
Merge pull request #37777 from apple/QuietMisdreavus/sourceOrigin-with-feeling
[SymbolGraph] add sourceOrigin info for all protocol implementations
2 parents 7ca2301 + 703ebb6 commit 7277baa

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

lib/SymbolGraphGen/Edge.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const ValueDecl *getForeignProtocolRequirement(const ValueDecl *VD, const Module
3636
requirements.pop();
3737
}
3838
}
39+
40+
const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
41+
auto reqs = VD->getSatisfiedProtocolRequirements();
42+
43+
if (!reqs.empty())
44+
return reqs.front();
45+
else
46+
return nullptr;
47+
}
3948
} // end anonymous namespace
4049

4150
void Edge::serialize(llvm::json::OStream &OS) const {
@@ -79,10 +88,8 @@ void Edge::serialize(llvm::json::OStream &OS) const {
7988
}
8089

8190
const ValueDecl *InheritingDecl = nullptr;
82-
if (const auto *ID = Source.getDeclInheritingDocs()) {
83-
if (Target.getSymbolDecl() == ID || Source.getSynthesizedBaseTypeDecl())
84-
InheritingDecl = ID;
85-
}
91+
if (const auto *ID = Source.getDeclInheritingDocs())
92+
InheritingDecl = ID;
8693

8794
if (!InheritingDecl && Source.getSynthesizedBaseTypeDecl())
8895
InheritingDecl = Source.getSymbolDecl();
@@ -91,7 +98,12 @@ void Edge::serialize(llvm::json::OStream &OS) const {
9198
if (const auto *ID = getForeignProtocolRequirement(Source.getSymbolDecl(), &Graph->M))
9299
InheritingDecl = ID;
93100
}
94-
101+
102+
if (!InheritingDecl) {
103+
if (const auto *ID = getProtocolRequirement(Source.getSymbolDecl()))
104+
InheritingDecl = ID;
105+
}
106+
95107
// If our source symbol is a inheriting decl, write in information about
96108
// where it's inheriting docs from.
97109
if (InheritingDecl) {

test/SymbolGraph/Relationships/Synthesized/InheritedDocs.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS
88
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-DOCS
99
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes EXTRA
10+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes LOCAL
11+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SUPER
1012

1113
// RUN: %target-swift-symbolgraph-extract -module-name InheritedDocs -I %t -pretty-print -output-dir %t -skip-inherited-docs
1214
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes CHECK,SKIP
1315
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes IMPL
1416
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS
1517
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-SKIP
1618
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes EXTRA
19+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes LOCAL
20+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SUPER
1721

1822
// RUN: %empty-directory(%t)
1923
// RUN: %target-build-swift %s -module-name InheritedDocs -emit-module -emit-module-path %t/InheritedDocs.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -skip-inherited-docs
@@ -56,10 +60,31 @@
5660
// EXTRA-NEXT: "identifier": "s:13InheritedDocs1PPAAE9extraFuncyyF"
5761
// EXTRA-NEXT: "displayName": "P.extraFunc()"
5862

63+
// local implementations of a local protocol still need to a relation to that protocol
64+
65+
// LOCAL: "source": "s:13InheritedDocs1SV9localFuncyyF"
66+
// LOCAL-NEXT: "target": "s:13InheritedDocs1SV"
67+
// LOCAL-NEXT: "sourceOrigin"
68+
// LOCAL-NEXT: "identifier": "s:13InheritedDocs1PP9localFuncyyF"
69+
// LOCAL-NEXT: "displayName": "P.localFunc()"
70+
71+
// ...both with and without docs
72+
73+
// SUPER: "source": "s:13InheritedDocs1SV9superFuncyyF"
74+
// SUPER-NEXT: "target": "s:13InheritedDocs1SV"
75+
// SUPER-NEXT: "sourceOrigin"
76+
// SUPER-NEXT: "identifier": "s:13InheritedDocs1PP9superFuncyyF"
77+
// SUPER-NEXT: "displayName": "P.superFunc()"
78+
5979
/// Protocol P
6080
public protocol P {
6181
/// Some Function
6282
func someFunc()
83+
84+
/// It's a local function!
85+
func localFunc()
86+
87+
func superFunc()
6388
}
6489

6590
public extension P {
@@ -72,4 +97,7 @@ public extension P {
7297
}
7398

7499
public struct S: P {
100+
public func localFunc() {}
101+
102+
public func superFunc() {}
75103
}

0 commit comments

Comments
 (0)