Skip to content

Commit bafe819

Browse files
don't drop underscored protocol implementation symbols (#75848)
rdar://133086270
1 parent a721ef6 commit bafe819

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,17 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
725725
// Special cases below.
726726

727727
// If we've been asked to skip protocol implementations, filter them out here.
728-
if (Walker.Options.SkipProtocolImplementations && getProtocolRequirement(VD)) {
729-
// Allow them to stay if they have their own doc comment
730-
const auto *DocCommentProvidingDecl = VD->getDocCommentProvidingDecl();
731-
if (DocCommentProvidingDecl != VD)
732-
return true;
728+
if (Walker.Options.SkipProtocolImplementations) {
729+
if (const auto *ProtocolRequirement = getProtocolRequirement(VD)) {
730+
if (const auto *Protocol = ProtocolRequirement->getDeclContext()->getSelfProtocolDecl()) {
731+
if (!Protocol->hasUnderscoredNaming()) {
732+
// Allow them to stay if they have their own doc comment
733+
const auto *DocCommentProvidingDecl = VD->getDocCommentProvidingDecl();
734+
if (DocCommentProvidingDecl != VD)
735+
return true;
736+
}
737+
}
738+
}
733739
}
734740

735741
// Symbols from exported-imported modules should only be included if they

test/SymbolGraph/Symbols/SkipProtocolImplementations.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@
2525
// Same for ExtraStruct.Inner
2626
// CHECK-DAG: s:27SkipProtocolImplementations11ExtraStructV5InnerV
2727

28+
// HiddenStruct.T should be present because its source protocol is underscored
29+
// CHECK-DAG: "precise": "s:27SkipProtocolImplementations12HiddenStructV1TV",
30+
2831
// CHECK-LABEL: "relationships": [
2932

3033
// we want to make sure that the conformance relationship itself stays
3134
// CHECK-DAG: conformsTo
3235

33-
// SomeStruct.otherFunc() and ExtraStruct.Inner should be the only ones with sourceOrigin information
36+
// There should only be three symbols with sourceOrigin information:
37+
// - SomeStruct.otherFunc()
38+
// - ExtraStruct.Inner
39+
// - HiddenStruct.T
3440
// (ExtraStruct.Inner will have two sourceOrigins because it has two relationships: a memberOf and a
3541
// conformsTo)
36-
// COUNT-COUNT-3: sourceOrigin
42+
// COUNT-COUNT-4: sourceOrigin
3743
// COUNT-NOT: sourceOrigin
3844

3945
public protocol SomeProtocol {
@@ -73,3 +79,11 @@ public struct ExtraStruct: OtherProtocol {
7379
}
7480

7581
extension ExtraStruct.Inner: Sendable {}
82+
83+
public protocol _HiddenProtocol {
84+
associatedtype T
85+
}
86+
87+
public struct HiddenStruct: _HiddenProtocol {
88+
public struct T {}
89+
}

0 commit comments

Comments
 (0)