@@ -233,18 +233,6 @@ void SymbolGraph::recordEdge(Symbol Source,
233
233
234
234
void SymbolGraph::recordMemberRelationship (Symbol S) {
235
235
const auto *DC = S.getLocalSymbolDecl ()->getDeclContext ();
236
- const ValueDecl *ParentDecl = DC->getSelfNominalTypeDecl ();
237
- if (!ParentDecl) {
238
- // If we couldn't look up the type the member is declared on (e.g.
239
- // because the member is declared in an extension whose extended type
240
- // doesn't exist), don't record a memberOf relationship.
241
- return ;
242
- }
243
- if (const auto *PublicDecl = Walker.PublicPrivateTypeAliases [ParentDecl]) {
244
- // If our member target is a private type that has a public type alias,
245
- // point the membership to that type alias instead.
246
- ParentDecl = PublicDecl;
247
- }
248
236
switch (DC->getContextKind ()) {
249
237
case DeclContextKind::GenericTypeDecl:
250
238
case DeclContextKind::ExtensionDecl:
@@ -263,6 +251,13 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {
263
251
return ;
264
252
}
265
253
254
+ if (DC->getSelfNominalTypeDecl () == nullptr ) {
255
+ // If we couldn't look up the type the member is declared on (e.g.
256
+ // because the member is declared in an extension whose extended type
257
+ // doesn't exist), don't record a memberOf relationship.
258
+ return ;
259
+ }
260
+
266
261
// If this is an extension to an external type, we use the extension
267
262
// symbol itself as the target.
268
263
if (auto const *Extension =
@@ -274,7 +269,8 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {
274
269
}
275
270
}
276
271
277
- return recordEdge (S, Symbol (this , ParentDecl, nullptr ),
272
+ return recordEdge (S,
273
+ Symbol (this , DC->getSelfNominalTypeDecl (), nullptr ),
278
274
RelationshipKind::MemberOf ());
279
275
case swift::DeclContextKind::AbstractClosureExpr:
280
276
case swift::DeclContextKind::SerializedAbstractClosure:
@@ -327,16 +323,7 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
327
323
bool dropSynthesizedMembers = !Walker.Options .EmitSynthesizedMembers ||
328
324
Walker.Options .SkipProtocolImplementations ;
329
325
330
- const auto *D = S.getLocalSymbolDecl ();
331
-
332
- // If this symbol is a public type alias to a private symbol, collect
333
- // synthesized members for the underlying type.
334
- if (const auto *TD = dyn_cast<TypeAliasDecl>(D)) {
335
- const auto *NTD = TD->getUnderlyingType ()->getAnyNominal ();
336
- if (NTD && Walker.PublicPrivateTypeAliases [NTD] == D)
337
- D = NTD;
338
- }
339
-
326
+ const auto D = S.getLocalSymbolDecl ();
340
327
const NominalTypeDecl *OwningNominal = nullptr ;
341
328
if (const auto *ThisNominal = dyn_cast<NominalTypeDecl>(D)) {
342
329
OwningNominal = ThisNominal;
@@ -389,11 +376,9 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
389
376
// that protocol would otherwise be hidden.
390
377
if (auto *Nominal = Info.Ext ->getExtendedNominal ()) {
391
378
if (dropSynthesizedMembers &&
392
- !isImplicitlyPrivate (Nominal, /* IgnoreContext =*/
393
- [&](const Decl *P) {
394
- return Nominal->getModuleContext () ==
395
- StdlibModule;
396
- }))
379
+ !isImplicitlyPrivate (
380
+ Nominal, /* IgnoreContext =*/ Nominal->getModuleContext () ==
381
+ StdlibModule))
397
382
continue ;
398
383
} else if (dropSynthesizedMembers) {
399
384
continue ;
@@ -408,12 +393,10 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
408
393
// There can be synthesized members on effectively private
409
394
// protocols or things that conform to them. We don't want to
410
395
// include those.
411
- if (isImplicitlyPrivate (
412
- SynthMember,
413
- /* IgnoreContext =*/
414
- [&](const Decl *P) {
415
- return SynthMember->getModuleContext () == StdlibModule;
416
- })) {
396
+ if (isImplicitlyPrivate (SynthMember,
397
+ /* IgnoreContext =*/
398
+ SynthMember->getModuleContext () ==
399
+ StdlibModule)) {
417
400
continue ;
418
401
}
419
402
@@ -422,29 +405,22 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
422
405
continue ;
423
406
}
424
407
425
- const ValueDecl *BaseDecl = OwningNominal;
426
- if (Walker.PublicPrivateTypeAliases .contains (BaseDecl))
427
- BaseDecl = Walker.PublicPrivateTypeAliases [BaseDecl];
428
-
429
- Symbol Source (this , SynthMember, BaseDecl);
408
+ Symbol Source (this , SynthMember, OwningNominal);
430
409
431
410
if (auto *InheritedDecl = Source.getInheritedDecl ()) {
432
411
if (auto *ParentDecl =
433
412
InheritedDecl->getDeclContext ()->getAsDecl ()) {
434
413
if (dropSynthesizedMembers &&
435
414
!isImplicitlyPrivate (
436
415
ParentDecl,
437
- /* IgnoreContext =*/
438
- [&](const Decl *P) {
439
- return ParentDecl->getModuleContext () ==
440
- StdlibModule;
441
- })) {
416
+ /* IgnoreContext =*/ ParentDecl->getModuleContext () ==
417
+ StdlibModule)) {
442
418
continue ;
443
419
}
444
420
}
445
421
}
446
422
447
- auto ExtendedSG = Walker.getModuleSymbolGraph (BaseDecl );
423
+ auto ExtendedSG = Walker.getModuleSymbolGraph (OwningNominal );
448
424
449
425
ExtendedSG->Nodes .insert (Source);
450
426
@@ -457,15 +433,7 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
457
433
458
434
void
459
435
SymbolGraph::recordInheritanceRelationships (Symbol S) {
460
- const auto *D = S.getLocalSymbolDecl ();
461
-
462
- // If this is a public type alias for a private symbol, gather inheritance
463
- // for the underlying type instead.
464
- if (const auto *TD = dyn_cast<TypeAliasDecl>(D)) {
465
- const auto *NTD = TD->getUnderlyingType ()->getAnyNominal ();
466
- if (NTD && Walker.PublicPrivateTypeAliases [NTD] == D)
467
- D = NTD;
468
- }
436
+ const auto D = S.getLocalSymbolDecl ();
469
437
470
438
ClassDecl *Super = nullptr ;
471
439
if (auto *CD = dyn_cast<ClassDecl>(D))
@@ -474,7 +442,8 @@ SymbolGraph::recordInheritanceRelationships(Symbol S) {
474
442
Super = PD->getSuperclassDecl ();
475
443
476
444
if (Super) {
477
- recordEdge (S, Symbol (this , Super, nullptr ),
445
+ recordEdge (Symbol (this , cast<ValueDecl>(D), nullptr ),
446
+ Symbol (this , Super, nullptr ),
478
447
RelationshipKind::InheritsFrom ());
479
448
}
480
449
}
@@ -553,16 +522,7 @@ void SymbolGraph::recordOptionalRequirementRelationships(Symbol S) {
553
522
}
554
523
555
524
void SymbolGraph::recordConformanceRelationships (Symbol S) {
556
- const auto *D = S.getLocalSymbolDecl ();
557
-
558
- // If this is a public type alias for a private symbol, gather conformances
559
- // for the underlying type instead.
560
- if (const auto *TD = dyn_cast<TypeAliasDecl>(D)) {
561
- const auto *NTD = TD->getUnderlyingType ()->getAnyNominal ();
562
- if (NTD && Walker.PublicPrivateTypeAliases [NTD] == D)
563
- D = NTD;
564
- }
565
-
525
+ const auto D = S.getLocalSymbolDecl ();
566
526
if (const auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
567
527
if (auto *PD = dyn_cast<ProtocolDecl>(NTD)) {
568
528
for (auto *inherited : PD->getAllInheritedProtocols ()) {
@@ -740,8 +700,8 @@ const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
740
700
741
701
}
742
702
743
- bool SymbolGraph::isImplicitlyPrivate (
744
- const Decl *D, llvm::function_ref< bool ( const Decl *)> IgnoreContext) const {
703
+ bool SymbolGraph::isImplicitlyPrivate (const Decl *D,
704
+ bool IgnoreContext) const {
745
705
// Don't record unconditionally private declarations
746
706
if (D->isPrivateSystemDecl (/* treatNonBuiltinProtocolsAsPublic=*/ false )) {
747
707
return true ;
@@ -849,15 +809,16 @@ bool SymbolGraph::isImplicitlyPrivate(
849
809
if (IsGlobalSIMDType) {
850
810
return true ;
851
811
}
812
+
813
+ if (IgnoreContext) {
814
+ return false ;
815
+ }
852
816
}
853
817
854
818
// Check up the parent chain. Anything inside a privately named
855
819
// thing is also private. We could be looking at the `B` of `_A.B`.
856
820
if (const auto *DC = D->getDeclContext ()) {
857
821
if (const auto *Parent = DC->getAsDecl ()) {
858
- if (IgnoreContext && IgnoreContext (Parent))
859
- return false ;
860
-
861
822
// Exception: Children of underscored protocols should be considered
862
823
// public, even though the protocols themselves aren't. This way,
863
824
// synthesized copies of those symbols are correctly added to the public
@@ -890,11 +851,7 @@ bool SymbolGraph::isUnconditionallyUnavailableOnAllPlatforms(const Decl *D) cons
890
851
}
891
852
892
853
// / Returns `true` if the symbol should be included as a node in the graph.
893
- bool SymbolGraph::canIncludeDeclAsNode (const Decl *D,
894
- const Decl *PublicAncestorDecl) const {
895
- if (PublicAncestorDecl && D == PublicAncestorDecl)
896
- return true ;
897
-
854
+ bool SymbolGraph::canIncludeDeclAsNode (const Decl *D) const {
898
855
// If this decl isn't in this module or module that this module imported with `@_exported`, don't record it,
899
856
// as it will appear elsewhere in its module's symbol graph.
900
857
@@ -916,8 +873,6 @@ bool SymbolGraph::canIncludeDeclAsNode(const Decl *D,
916
873
} else {
917
874
return false ;
918
875
}
919
- return !isImplicitlyPrivate (
920
- cast<ValueDecl>(D), /* IgnoreContext=*/
921
- [&](const Decl *P) { return P == PublicAncestorDecl; }) &&
922
- !isUnconditionallyUnavailableOnAllPlatforms (cast<ValueDecl>(D));
876
+ return !isImplicitlyPrivate (cast<ValueDecl>(D))
877
+ && !isUnconditionallyUnavailableOnAllPlatforms (cast<ValueDecl>(D));
923
878
}
0 commit comments