Skip to content

Commit a83a17c

Browse files
Revert "consider requirements of an underscored protocol to also be underscored (take two) (#59531)" (#60096)
This reverts commit ababa79.
1 parent 7e0c2a9 commit a83a17c

File tree

3 files changed

+22
-63
lines changed

3 files changed

+22
-63
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -574,56 +574,6 @@ SymbolGraph::serializeDeclarationFragments(StringRef Key, Type T,
574574
T->print(Printer, Options);
575575
}
576576

577-
namespace {
578-
579-
/// Returns the first satisfied protocol requirement for the given decl.
580-
const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
581-
auto reqs = VD->getSatisfiedProtocolRequirements();
582-
583-
if (!reqs.empty())
584-
return reqs.front();
585-
else
586-
return nullptr;
587-
}
588-
589-
/// Returns the protocol that the given decl is a requirement or conformance of, if any.
590-
const ProtocolDecl *getSourceProtocol(const Decl *D) {
591-
const auto *DC = D->getDeclContext();
592-
593-
// First check to see whether it's declared directly in the protocol decl
594-
if (const auto *P = dyn_cast<ProtocolDecl>(DC))
595-
return P;
596-
597-
// Next look at whether it's an extension on a protocol
598-
if (const auto *Extension = dyn_cast<ExtensionDecl>(DC)) {
599-
if (const auto *ExtendedProtocol = Extension->getExtendedProtocolDecl()) {
600-
return ExtendedProtocol;
601-
}
602-
}
603-
604-
// Then check to see whether it's an implementation of a protocol requirement
605-
if (const auto *VD = dyn_cast<ValueDecl>(D)) {
606-
if (const auto *Requirement = getProtocolRequirement(VD)) {
607-
if (const auto *P = dyn_cast<ProtocolDecl>(Requirement->getDeclContext())) {
608-
return P;
609-
}
610-
}
611-
}
612-
613-
// If all those didn't work, there's no protocol to fetch
614-
return nullptr;
615-
}
616-
617-
/// Returns whether the given decl is from a protocol, and that protocol has an underscored name.
618-
bool isFromUnderscoredProtocol(const Decl *D) {
619-
if (const auto *P = getSourceProtocol(D))
620-
return P->hasUnderscoredNaming();
621-
622-
return false;
623-
}
624-
625-
}
626-
627577
bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
628578
bool IgnoreContext) const {
629579
// Don't record unconditionally private declarations
@@ -632,7 +582,7 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
632582
}
633583

634584
// Don't record effectively internal declarations if specified
635-
if (D->hasUnderscoredNaming() || isFromUnderscoredProtocol(D)) {
585+
if (D->hasUnderscoredNaming()) {
636586
// Some implicit decls from Clang with underscored names sneak in, so throw those out
637587
if (const auto *clangD = D->getClangDecl()) {
638588
if (clangD->isImplicit())

test/SymbolGraph/Symbols/SkipsPublicUnderscore.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ public class SomeClass {
2222

2323
// PUBLIC-NOT: precise:{{.*}}_ProtocolShouldntAppear
2424
// PUBLIC-NOT: precise:{{.*}}PublicProtocol
25-
// PUBLIC-NOT: precise:{{.*}}someHiddenVar
2625
@_show_in_interface
27-
public protocol _ProtocolShouldntAppear {
28-
static var someHiddenVar: String { get }
29-
}
26+
public protocol _ProtocolShouldntAppear {}
3027

3128
// PUBLIC-NOT: _ShouldntAppear
3229
// INTERNAL-DAG: _ShouldntAppear
@@ -49,18 +46,11 @@ public struct _ShouldntAppear: PublicProtocol, _ProtocolShouldntAppear {
4946
// INTERNAL-DAG: InnerInnerShouldntAppear
5047
public struct InnerInnerShouldntAppear {}
5148
}
52-
53-
// INTERNAL-DAG: someHiddenVar
54-
public static var someHiddenVar: String { "someHiddenVar" }
5549
}
5650

5751
// A public type's relationship to an "internal" protocol
5852
// shouldn't cause it to be included.
59-
public struct ShouldAppear {}
60-
61-
extension ShouldAppear: _ProtocolShouldntAppear {
62-
public static var someHiddenVar: String { "someHiddenVar" }
63-
}
53+
public struct ShouldAppear: _ProtocolShouldntAppear {}
6454

6555
public struct PublicOuter {
6656
// Nor should an "internal" type's relationship to a "public" protocol.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name UnderscoredProtocols -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name UnderscoredProtocols -I %t -pretty-print -output-dir %t
4+
5+
// Make sure that underscored protocols do not appear in public symbol graphs, but their
6+
// requirements do appear on types which conform to them.
7+
8+
// CHECK-NOT: "precise": "s:20UnderscoredProtocols15_HiddenProtocolP",
9+
// CHECK: "precise": "s:20UnderscoredProtocols10SomeStructV8someFuncyyF",
10+
11+
public protocol _HiddenProtocol {
12+
func someFunc()
13+
}
14+
15+
public struct SomeStruct {}
16+
17+
extension SomeStruct: _HiddenProtocol {
18+
public func someFunc() {}
19+
}

0 commit comments

Comments
 (0)