Skip to content

Commit 08d1c33

Browse files
Merge pull request #37278 from apple/QuietMisdreavus/default-relation
[SymbolGraph] add "memberOf" relations for remote protocol implementations
2 parents a7f9e25 + 633ffec commit 08d1c33

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ void SymbolGraph::recordDefaultImplementationRelationships(Symbol S) {
430430
recordEdge(Symbol(this, VD, nullptr),
431431
Symbol(this, MemberVD, nullptr),
432432
RelationshipKind::DefaultImplementationOf());
433+
434+
// If P is from a different module, and it's being added to a type
435+
// from the current module, add a `memberOf` relation to the extended
436+
// protocol.
437+
if (MemberVD->getModuleContext()->getNameStr() != M.getNameStr() && VD->getDeclContext()) {
438+
if (auto *ExP = VD->getDeclContext()->getSelfNominalTypeDecl()) {
439+
recordEdge(Symbol(this, VD, nullptr),
440+
Symbol(this, ExP, nullptr),
441+
RelationshipKind::MemberOf());
442+
}
443+
}
433444
}
434445
}
435446
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public protocol RemoteP {
2+
func someFunc()
3+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %S/Inputs/RemoteP.swift -module-name RemoteP -emit-module -emit-module-path %t/
3+
// RUN: %target-build-swift %s -module-name Remote -emit-module -emit-module-path %t/ -I %t
4+
// RUN: %target-swift-symbolgraph-extract -module-name Remote -I %t -pretty-print -output-dir %t
5+
// RUN: %FileCheck %s --input-file %t/Remote.symbols.json
6+
// RUN: %FileCheck %s --input-file %t/Remote.symbols.json --check-prefix MEMBER
7+
8+
import RemoteP
9+
10+
public protocol LocalP: RemoteP {}
11+
12+
public extension LocalP {
13+
func someFunc() {}
14+
}
15+
16+
// default implementations that are for protocols in a different module should have a `memberOf`
17+
// relation linking them to a local symbol, if one exists
18+
19+
// CHECK: "kind": "defaultImplementationOf"
20+
// CHECK-NEXT: "source": "s:6Remote6LocalPPAAE8someFuncyyF"
21+
// CHECK-NEXT: "target": "s:7RemotePAAP8someFuncyyF"
22+
// CHECK-NEXT: "targetFallback": "RemoteP.RemoteP.someFunc()"
23+
24+
// MEMBER: "kind": "memberOf"
25+
// MEMBER-NEXT: "source": "s:6Remote6LocalPPAAE8someFuncyyF"
26+
// MEMBER-NEXT: "target": "s:6Remote6LocalPP"

0 commit comments

Comments
 (0)