Skip to content

Commit 3ded9c0

Browse files
[SymbolGraphGen] move "protocol implementations" check into isImplicitlyPrivate (#64867) (#64940)
rdar://107432084
1 parent 822fd8a commit 3ded9c0

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ SymbolGraph::isRequirementOrDefaultImplementation(const ValueDecl *VD) const {
191191
// MARK: - Symbols (Nodes)
192192

193193
void SymbolGraph::recordNode(Symbol S) {
194-
if (Walker.Options.SkipProtocolImplementations && S.getInheritedDecl()) {
195-
const auto *DocCommentProvidingDecl =
196-
getDocCommentProvidingDecl(S.getLocalSymbolDecl(), /*AllowSerialized=*/true);
197-
198-
// allow implementation symbols to remain if they have their own comment
199-
if (DocCommentProvidingDecl != S.getLocalSymbolDecl())
200-
return;
201-
}
202-
203194
Nodes.insert(S);
204195

205196
// Record all of the possible relationships (edges) originating
@@ -637,6 +628,19 @@ SymbolGraph::serializeDeclarationFragments(StringRef Key, Type T,
637628
T->print(Printer, Options);
638629
}
639630

631+
namespace {
632+
633+
const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
634+
auto reqs = VD->getSatisfiedProtocolRequirements();
635+
636+
if (!reqs.empty())
637+
return reqs.front();
638+
else
639+
return nullptr;
640+
}
641+
642+
}
643+
640644
bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
641645
bool IgnoreContext) const {
642646
// Don't record unconditionally private declarations
@@ -698,6 +702,15 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
698702

699703
// Special cases below.
700704

705+
// If we've been asked to skip protocol implementations, filter them out here.
706+
if (Walker.Options.SkipProtocolImplementations && getProtocolRequirement(VD)) {
707+
// Allow them to stay if they have their own doc comment
708+
const auto *DocCommentProvidingDecl =
709+
getDocCommentProvidingDecl(VD, /*AllowSerialized=*/true);
710+
if (DocCommentProvidingDecl != VD)
711+
return true;
712+
}
713+
701714
// Symbols from exported-imported modules should only be included if they
702715
// were originally public.
703716
if (Walker.isFromExportedImportedModule(D) &&

test/SymbolGraph/Symbols/SkipProtocolImplementations.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@
1414
// CHECK-NOT: s:27SkipProtocolImplementations04SomeB0PAAE9bonusFuncyyF::SYNTHESIZED::s:27SkipProtocolImplementations10SomeStructV
1515
// CHECK-NOT: s:27SkipProtocolImplementations10SomeStructV8someFuncyyF
1616

17+
// ...as well as the inner type from `OtherProtocol` on `OtherStruct`
18+
// CHECK-NOT: "s:27SkipProtocolImplementations11OtherStructV5InnerV"
19+
1720
// CHECK-LABEL: "symbols": [
1821

1922
// SomeStruct.otherFunc() should be present because it has its own doc comment
20-
// CHECK: s:27SkipProtocolImplementations10SomeStructV9otherFuncyyF
23+
// CHECK-DAG: s:27SkipProtocolImplementations10SomeStructV9otherFuncyyF
24+
25+
// Same for ExtraStruct.Inner
26+
// CHECK-DAG: s:27SkipProtocolImplementations11ExtraStructV5InnerV
2127

2228
// CHECK-LABEL: "relationships": [
2329

2430
// we want to make sure that the conformance relationship itself stays
2531
// CHECK-DAG: conformsTo
2632

27-
// SomeStruct.otherFunc() should be the only one with sourceOrigin information
28-
// COUNT-COUNT-1: sourceOrigin
33+
// SomeStruct.otherFunc() and ExtraStruct.Inner should be the only ones with sourceOrigin information
34+
// (ExtraStruct.Inner will have two sourceOrigins because it has two relationships: a memberOf and a
35+
// conformsTo)
36+
// COUNT-COUNT-3: sourceOrigin
37+
// COUNT-NOT: sourceOrigin
2938

3039
public protocol SomeProtocol {
3140
/// Base docs
@@ -45,3 +54,22 @@ public struct SomeStruct: SomeProtocol {
4554
/// Local docs
4655
public func otherFunc() {}
4756
}
57+
58+
// Make sure that protocol conformances added in extensions don't create bogus symbol relationships (rdar://107432084)
59+
60+
public protocol OtherProtocol {
61+
associatedtype Inner
62+
}
63+
64+
public struct OtherStruct: OtherProtocol {
65+
public struct Inner {}
66+
}
67+
68+
extension OtherStruct.Inner: Sendable {}
69+
70+
public struct ExtraStruct: OtherProtocol {
71+
/// This time with a doc comment!
72+
public struct Inner {}
73+
}
74+
75+
extension ExtraStruct.Inner: Sendable {}

0 commit comments

Comments
 (0)