@@ -232,6 +232,18 @@ void SymbolGraph::recordEdge(Symbol Source,
232
232
233
233
void SymbolGraph::recordMemberRelationship (Symbol S) {
234
234
const auto *DC = S.getLocalSymbolDecl ()->getDeclContext ();
235
+ const ValueDecl *ParentDecl = DC->getSelfNominalTypeDecl ();
236
+ if (!ParentDecl) {
237
+ // If we couldn't look up the type the member is declared on (e.g.
238
+ // because the member is declared in an extension whose extended type
239
+ // doesn't exist), don't record a memberOf relationship.
240
+ return ;
241
+ }
242
+ if (const auto *PublicDecl = Walker.PublicPrivateTypeAliases [ParentDecl]) {
243
+ // If our member target is a private type that has a public type alias,
244
+ // point the membership to that type alias instead.
245
+ ParentDecl = PublicDecl;
246
+ }
235
247
switch (DC->getContextKind ()) {
236
248
case DeclContextKind::GenericTypeDecl:
237
249
case DeclContextKind::ExtensionDecl:
@@ -250,13 +262,6 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {
250
262
return ;
251
263
}
252
264
253
- if (DC->getSelfNominalTypeDecl () == nullptr ) {
254
- // If we couldn't look up the type the member is declared on (e.g.
255
- // because the member is declared in an extension whose extended type
256
- // doesn't exist), don't record a memberOf relationship.
257
- return ;
258
- }
259
-
260
265
// If this is an extension to an external type, we use the extension
261
266
// symbol itself as the target.
262
267
if (auto const *Extension =
@@ -268,22 +273,8 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {
268
273
}
269
274
}
270
275
271
- if (Walker.PublicPrivateTypeAliases .contains (
272
- DC->getSelfNominalTypeDecl ())) {
273
- // If our member target is a private type that has a public type alias,
274
- // point the membership to that type alias instead.
275
- return recordEdge (
276
- S,
277
- Symbol (
278
- this ,
279
- Walker.PublicPrivateTypeAliases [DC->getSelfNominalTypeDecl ()],
280
- nullptr ),
281
- RelationshipKind::MemberOf ());
282
- } else {
283
- return recordEdge (S,
284
- Symbol (this , DC->getSelfNominalTypeDecl (), nullptr ),
285
- RelationshipKind::MemberOf ());
286
- }
276
+ return recordEdge (S, Symbol (this , ParentDecl, nullptr ),
277
+ RelationshipKind::MemberOf ());
287
278
case swift::DeclContextKind::AbstractClosureExpr:
288
279
case swift::DeclContextKind::SerializedAbstractClosure:
289
280
case swift::DeclContextKind::Initializer:
@@ -335,7 +326,16 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
335
326
bool dropSynthesizedMembers = !Walker.Options .EmitSynthesizedMembers ||
336
327
Walker.Options .SkipProtocolImplementations ;
337
328
338
- const auto D = S.getLocalSymbolDecl ();
329
+ const auto *D = S.getLocalSymbolDecl ();
330
+
331
+ // If this symbol is a public type alias to a private symbol, collect
332
+ // synthesized members for the underlying type.
333
+ if (const auto *TD = dyn_cast<TypeAliasDecl>(D)) {
334
+ const auto *NTD = TD->getUnderlyingType ()->getAnyNominal ();
335
+ if (NTD && Walker.PublicPrivateTypeAliases [NTD] == D)
336
+ D = NTD;
337
+ }
338
+
339
339
const NominalTypeDecl *OwningNominal = nullptr ;
340
340
if (const auto *ThisNominal = dyn_cast<NominalTypeDecl>(D)) {
341
341
OwningNominal = ThisNominal;
@@ -421,7 +421,11 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
421
421
continue ;
422
422
}
423
423
424
- Symbol Source (this , SynthMember, OwningNominal);
424
+ const ValueDecl *BaseDecl = OwningNominal;
425
+ if (Walker.PublicPrivateTypeAliases .contains (BaseDecl))
426
+ BaseDecl = Walker.PublicPrivateTypeAliases [BaseDecl];
427
+
428
+ Symbol Source (this , SynthMember, BaseDecl);
425
429
426
430
if (auto *InheritedDecl = Source.getInheritedDecl ()) {
427
431
if (auto *ParentDecl =
@@ -439,7 +443,7 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
439
443
}
440
444
}
441
445
442
- auto ExtendedSG = Walker.getModuleSymbolGraph (OwningNominal );
446
+ auto ExtendedSG = Walker.getModuleSymbolGraph (BaseDecl );
443
447
444
448
ExtendedSG->Nodes .insert (Source);
445
449
@@ -452,7 +456,15 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
452
456
453
457
void
454
458
SymbolGraph::recordInheritanceRelationships (Symbol S) {
455
- const auto D = S.getLocalSymbolDecl ();
459
+ const auto *D = S.getLocalSymbolDecl ();
460
+
461
+ // If this is a public type alias for a private symbol, gather inheritance
462
+ // for the underlying type instead.
463
+ if (const auto *TD = dyn_cast<TypeAliasDecl>(D)) {
464
+ const auto *NTD = TD->getUnderlyingType ()->getAnyNominal ();
465
+ if (NTD && Walker.PublicPrivateTypeAliases [NTD] == D)
466
+ D = NTD;
467
+ }
456
468
457
469
ClassDecl *Super = nullptr ;
458
470
if (auto *CD = dyn_cast<ClassDecl>(D))
@@ -461,8 +473,7 @@ SymbolGraph::recordInheritanceRelationships(Symbol S) {
461
473
Super = PD->getSuperclassDecl ();
462
474
463
475
if (Super) {
464
- recordEdge (Symbol (this , cast<ValueDecl>(D), nullptr ),
465
- Symbol (this , Super, nullptr ),
476
+ recordEdge (S, Symbol (this , Super, nullptr ),
466
477
RelationshipKind::InheritsFrom ());
467
478
}
468
479
}
@@ -541,7 +552,16 @@ void SymbolGraph::recordOptionalRequirementRelationships(Symbol S) {
541
552
}
542
553
543
554
void SymbolGraph::recordConformanceRelationships (Symbol S) {
544
- const auto D = S.getLocalSymbolDecl ();
555
+ const auto *D = S.getLocalSymbolDecl ();
556
+
557
+ // If this is a public type alias for a private symbol, gather conformances
558
+ // for the underlying type instead.
559
+ if (const auto *TD = dyn_cast<TypeAliasDecl>(D)) {
560
+ const auto *NTD = TD->getUnderlyingType ()->getAnyNominal ();
561
+ if (NTD && Walker.PublicPrivateTypeAliases [NTD] == D)
562
+ D = NTD;
563
+ }
564
+
545
565
if (const auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
546
566
if (auto *PD = dyn_cast<ProtocolDecl>(NTD)) {
547
567
for (auto *inherited : PD->getAllInheritedProtocols ()) {
0 commit comments