consider requirements of an underscored protocol to also be underscored (#59480)

rdar://94336558
This commit is contained in:
QuietMisdreavus
2022-06-16 14:20:14 -06:00
committed by GitHub
parent 45820d370a
commit a8ecfc94ec
2 changed files with 63 additions and 3 deletions

View File

@@ -574,6 +574,56 @@ SymbolGraph::serializeDeclarationFragments(StringRef Key, Type T,
T->print(Printer, Options);
}
namespace {
/// Returns the first satisfied protocol requirement for the given decl.
const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
auto reqs = VD->getSatisfiedProtocolRequirements();
if (!reqs.empty())
return reqs.front();
else
return nullptr;
}
/// Returns the protocol that the given decl is a requirement or conformance of, if any.
const ProtocolDecl *getSourceProtocol(const Decl *D) {
const auto *DC = D->getDeclContext();
// First check to see whether it's declared directly in the protocol decl
if (const auto *P = dyn_cast<ProtocolDecl>(DC))
return P;
// Next look at whether it's an extension on a protocol
if (const auto *Extension = dyn_cast<ExtensionDecl>(DC)) {
if (const auto *ExtendedProtocol = Extension->getExtendedProtocolDecl()) {
return ExtendedProtocol;
}
}
// Then check to see whether it's an implementation of a protocol requirement
if (const auto *VD = dyn_cast<ValueDecl>(D)) {
if (const auto *Requirement = getProtocolRequirement(VD)) {
if (const auto *P = dyn_cast<ProtocolDecl>(Requirement->getDeclContext())) {
return P;
}
}
}
// If all those didn't work, there's no protocol to fetch
return nullptr;
}
/// Returns whether the given decl is from a protocol, and that protocol has an underscored name.
bool isFromUnderscoredProtocol(const Decl *D) {
if (const auto *P = getSourceProtocol(D))
return P->hasUnderscoredNaming();
return false;
}
}
bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
bool IgnoreContext) const {
// Don't record unconditionally private declarations
@@ -582,7 +632,7 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
}
// Don't record effectively internal declarations if specified
if (D->hasUnderscoredNaming()) {
if (D->hasUnderscoredNaming() || isFromUnderscoredProtocol(D)) {
// Some implicit decls from Clang with underscored names sneak in, so throw those out
if (const auto *clangD = D->getClangDecl()) {
if (clangD->isImplicit())