[SymbolGraphGen] synthesize child symbols for type aliases of private decls (#78959)

This commit is contained in:
QuietMisdreavus
2025-01-29 12:39:26 -07:00
committed by GitHub
parent 7eada7dd86
commit b1871fb333
8 changed files with 226 additions and 62 deletions

View File

@@ -119,6 +119,9 @@ static bool isUnavailableOrObsoletedOnPlatform(const Decl *D) {
}
bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
if (SynthesizedChildrenBaseDecl && D == SynthesizedChildrenBaseDecl)
return true;
if (isUnavailableOrObsoletedOnPlatform(D)) {
return false;
}
@@ -239,7 +242,7 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
auto *VD = cast<ValueDecl>(D);
if (!SG->canIncludeDeclAsNode(VD)) {
if (!BaseDecl && !SG->canIncludeDeclAsNode(VD)) {
return false;
}
@@ -270,8 +273,21 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
}
}
if (const auto *TD = dyn_cast_or_null<TypeAliasDecl>(VD)) {
const auto InnerType = TD->getUnderlyingType();
if (NominalTypeDecl *NTD = InnerType->getAnyNominal()) {
// Only fold typedefs together if the inner type is from our module and it
// otherwise isn't being shown
if (isOurModule(NTD->getModuleContext()) &&
!SG->canIncludeDeclAsNode(NTD)) {
PublicPrivateTypeAliases[NTD] = TD;
synthesizeChildSymbols(NTD, TD);
}
}
}
// Otherwise, record this in the main module `M`'s symbol graph.
SG->recordNode(Symbol(SG, VD, nullptr));
SG->recordNode(Symbol(SG, VD, BaseDecl));
return true;
}
@@ -340,3 +356,15 @@ bool SymbolGraphASTWalker::shouldBeRecordedAsExtension(
!isExportedImportedModule(
ED->getExtendedNominal()->getModuleContext());
}
bool SymbolGraphASTWalker::synthesizeChildSymbols(Decl *D,
const ValueDecl *BD) {
BaseDecl = BD;
SynthesizedChildrenBaseDecl = D;
SWIFT_DEFER {
BaseDecl = nullptr;
SynthesizedChildrenBaseDecl = nullptr;
};
return walk(D);
}