19
19
#include " clang/AST/DeclObjC.h"
20
20
#include " swift/AST/ASTContext.h"
21
21
#include " swift/AST/GenericSignature.h"
22
- #include " swift/AST/GenericSignatureBuilder.h"
23
22
#include " swift/AST/ImportCache.h"
24
23
#include " swift/AST/Initializer.h"
25
24
#include " swift/AST/LazyResolver.h"
@@ -413,7 +412,7 @@ static void doDynamicLookup(VisibleDeclConsumer &Consumer,
413
412
}
414
413
415
414
namespace {
416
- typedef llvm::SmallPtrSet<TypeDecl *, 8 > VisitedSet;
415
+ typedef llvm::SmallPtrSet<const TypeDecl *, 8 > VisitedSet;
417
416
} // end anonymous namespace
418
417
419
418
static DeclVisibilityKind getReasonForSuper (DeclVisibilityKind Reason) {
@@ -528,15 +527,15 @@ static void
528
527
lookupVisibleMemberDeclsImpl (Type BaseTy, VisibleDeclConsumer &Consumer,
529
528
const DeclContext *CurrDC, LookupState LS,
530
529
DeclVisibilityKind Reason,
531
- GenericSignatureBuilder *GSB ,
530
+ GenericSignature Sig ,
532
531
VisitedSet &Visited);
533
532
534
533
static void
535
- lookupVisibleProtocolMemberDecls (Type BaseTy, ProtocolDecl *PD,
534
+ lookupVisibleProtocolMemberDecls (Type BaseTy, const ProtocolDecl *PD,
536
535
VisibleDeclConsumer &Consumer,
537
536
const DeclContext *CurrDC, LookupState LS,
538
537
DeclVisibilityKind Reason,
539
- GenericSignatureBuilder *GSB ,
538
+ GenericSignature Sig ,
540
539
VisitedSet &Visited) {
541
540
if (!Visited.insert (PD).second )
542
541
return ;
@@ -545,7 +544,7 @@ static void
545
544
lookupVisibleProtocolMemberDecls (BaseTy, Proto,
546
545
Consumer, CurrDC, LS,
547
546
getReasonForSuper (Reason),
548
- GSB , Visited);
547
+ Sig , Visited);
549
548
lookupTypeMembers (BaseTy, PD->getDeclaredInterfaceType (),
550
549
Consumer, CurrDC, LS, Reason);
551
550
}
@@ -597,7 +596,7 @@ static void synthesizeMemberDeclsForLookup(NominalTypeDecl *NTD,
597
596
598
597
static void lookupVisibleMemberDeclsImpl (
599
598
Type BaseTy, VisibleDeclConsumer &Consumer, const DeclContext *CurrDC,
600
- LookupState LS, DeclVisibilityKind Reason, GenericSignatureBuilder *GSB ,
599
+ LookupState LS, DeclVisibilityKind Reason, GenericSignature Sig ,
601
600
VisitedSet &Visited) {
602
601
// Just look through l-valueness. It doesn't affect name lookup.
603
602
assert (BaseTy && " lookup into null type" );
@@ -628,7 +627,7 @@ static void lookupVisibleMemberDeclsImpl(
628
627
// functions, and can even look up non-static functions as well (thus
629
628
// getting the address of the member).
630
629
lookupVisibleMemberDeclsImpl (Ty, Consumer, CurrDC, subLS, Reason,
631
- GSB , Visited);
630
+ Sig , Visited);
632
631
return ;
633
632
}
634
633
@@ -652,15 +651,15 @@ static void lookupVisibleMemberDeclsImpl(
652
651
if (ProtocolType *PT = BaseTy->getAs <ProtocolType>()) {
653
652
lookupVisibleProtocolMemberDecls (BaseTy, PT->getDecl (),
654
653
Consumer, CurrDC, LS, Reason,
655
- GSB , Visited);
654
+ Sig , Visited);
656
655
return ;
657
656
}
658
657
659
658
// If the base is a protocol composition, enumerate members of the protocols.
660
659
if (auto PC = BaseTy->getAs <ProtocolCompositionType>()) {
661
660
for (auto Member : PC->getMembers ())
662
661
lookupVisibleMemberDeclsImpl (Member, Consumer, CurrDC, LS, Reason,
663
- GSB , Visited);
662
+ Sig , Visited);
664
663
return ;
665
664
}
666
665
@@ -669,38 +668,35 @@ static void lookupVisibleMemberDeclsImpl(
669
668
for (auto Proto : Archetype->getConformsTo ())
670
669
lookupVisibleProtocolMemberDecls (
671
670
BaseTy, Proto, Consumer, CurrDC, LS,
672
- Reason, GSB , Visited);
671
+ Reason, Sig , Visited);
673
672
674
673
if (auto superclass = Archetype->getSuperclass ())
675
674
lookupVisibleMemberDeclsImpl (superclass, Consumer, CurrDC, LS,
676
- Reason, GSB , Visited);
675
+ Reason, Sig , Visited);
677
676
return ;
678
677
}
679
678
680
- // If we're looking into a type parameter and we have a generic signature
681
- // builder, use the GSB to resolve where we should look.
682
- if (BaseTy->isTypeParameter () && GSB) {
683
- auto EquivClass =
684
- GSB->resolveEquivalenceClass (BaseTy,
685
- ArchetypeResolutionKind::CompleteWellFormed);
686
- if (!EquivClass) return ;
687
-
688
- if (EquivClass->concreteType ) {
689
- BaseTy = EquivClass->concreteType ;
679
+ // If we're looking into a type parameter and we have a GenericSignature,
680
+ // query the signature to resolve where we should look.
681
+ if (BaseTy->isTypeParameter () && Sig) {
682
+ // The type might be fully concrete via a same-type requirement.
683
+ if (auto ConcreteTy = Sig->getConcreteType (BaseTy)) {
684
+ BaseTy = ConcreteTy;
690
685
} else {
691
- // Conformances
692
- for (const auto &Conforms : EquivClass-> conformsTo ) {
686
+ // Look into protocols of conformance requirements
687
+ for (const auto *Proto : Sig-> getRequiredProtocols (BaseTy) ) {
693
688
lookupVisibleProtocolMemberDecls (
694
- BaseTy, Conforms. first , Consumer, CurrDC,
695
- LS, getReasonForSuper (Reason), GSB , Visited);
689
+ BaseTy, Proto , Consumer, CurrDC,
690
+ LS, getReasonForSuper (Reason), Sig , Visited);
696
691
}
697
692
698
- // Superclass .
699
- if (EquivClass-> superclass ) {
700
- lookupVisibleMemberDeclsImpl (EquivClass-> superclass , Consumer, CurrDC,
693
+ // Look into the superclass requirement type, if there is one .
694
+ if (auto SuperclassTy = Sig-> getSuperclassBound (BaseTy) ) {
695
+ lookupVisibleMemberDeclsImpl (SuperclassTy , Consumer, CurrDC,
701
696
LS, getReasonForSuper (Reason),
702
- GSB , Visited);
697
+ Sig , Visited);
703
698
}
699
+
704
700
return ;
705
701
}
706
702
}
@@ -1073,7 +1069,7 @@ struct KeyPathDynamicMemberConsumer : public VisibleDeclConsumer {
1073
1069
static void lookupVisibleDynamicMemberLookupDecls (
1074
1070
Type baseType, KeyPathDynamicMemberConsumer &consumer,
1075
1071
const DeclContext *dc, LookupState LS, DeclVisibilityKind reason,
1076
- GenericSignatureBuilder *GSB , VisitedSet &visited,
1072
+ GenericSignature Sig , VisitedSet &visited,
1077
1073
llvm::DenseSet<TypeBase *> &seenDynamicLookup);
1078
1074
1079
1075
// / Enumerates all members of \c baseType, including both directly visible and
@@ -1084,11 +1080,11 @@ static void lookupVisibleDynamicMemberLookupDecls(
1084
1080
static void lookupVisibleMemberAndDynamicMemberDecls (
1085
1081
Type baseType, VisibleDeclConsumer &consumer,
1086
1082
KeyPathDynamicMemberConsumer &dynamicMemberConsumer, const DeclContext *DC,
1087
- LookupState LS, DeclVisibilityKind reason, GenericSignatureBuilder *GSB ,
1083
+ LookupState LS, DeclVisibilityKind reason, GenericSignature Sig ,
1088
1084
VisitedSet &visited, llvm::DenseSet<TypeBase *> &seenDynamicLookup) {
1089
- lookupVisibleMemberDeclsImpl (baseType, consumer, DC, LS, reason, GSB , visited);
1085
+ lookupVisibleMemberDeclsImpl (baseType, consumer, DC, LS, reason, Sig , visited);
1090
1086
lookupVisibleDynamicMemberLookupDecls (baseType, dynamicMemberConsumer, DC, LS,
1091
- reason, GSB , visited, seenDynamicLookup);
1087
+ reason, Sig , visited, seenDynamicLookup);
1092
1088
}
1093
1089
1094
1090
// / Enumerates all keypath dynamic members of \c baseType, as seen from the
@@ -1100,7 +1096,7 @@ static void lookupVisibleMemberAndDynamicMemberDecls(
1100
1096
static void lookupVisibleDynamicMemberLookupDecls (
1101
1097
Type baseType, KeyPathDynamicMemberConsumer &consumer,
1102
1098
const DeclContext *dc, LookupState LS, DeclVisibilityKind reason,
1103
- GenericSignatureBuilder *GSB , VisitedSet &visited,
1099
+ GenericSignature Sig , VisitedSet &visited,
1104
1100
llvm::DenseSet<TypeBase *> &seenDynamicLookup) {
1105
1101
if (!seenDynamicLookup.insert (baseType.getPointer ()).second )
1106
1102
return ;
@@ -1138,7 +1134,7 @@ static void lookupVisibleDynamicMemberLookupDecls(
1138
1134
baseType);
1139
1135
1140
1136
lookupVisibleMemberAndDynamicMemberDecls (memberType, consumer, consumer, dc,
1141
- LS, reason, GSB , visited,
1137
+ LS, reason, Sig , visited,
1142
1138
seenDynamicLookup);
1143
1139
}
1144
1140
}
@@ -1151,7 +1147,7 @@ static void lookupVisibleDynamicMemberLookupDecls(
1151
1147
// / binding.
1152
1148
static void lookupVisibleMemberDecls (
1153
1149
Type BaseTy, VisibleDeclConsumer &Consumer, const DeclContext *CurrDC,
1154
- LookupState LS, DeclVisibilityKind Reason, GenericSignatureBuilder *GSB ) {
1150
+ LookupState LS, DeclVisibilityKind Reason, GenericSignature Sig ) {
1155
1151
OverrideFilteringConsumer overrideConsumer (BaseTy, CurrDC);
1156
1152
KeyPathDynamicMemberConsumer dynamicConsumer (
1157
1153
Consumer,
@@ -1161,7 +1157,7 @@ static void lookupVisibleMemberDecls(
1161
1157
llvm::DenseSet<TypeBase *> seenDynamicLookup;
1162
1158
lookupVisibleMemberAndDynamicMemberDecls (
1163
1159
BaseTy, overrideConsumer, dynamicConsumer, CurrDC, LS, Reason,
1164
- GSB , Visited, seenDynamicLookup);
1160
+ Sig , Visited, seenDynamicLookup);
1165
1161
1166
1162
// Report the declarations we found to the real consumer.
1167
1163
overrideConsumer.filterDecls (Consumer);
@@ -1332,7 +1328,7 @@ void swift::lookupVisibleMemberDecls(VisibleDeclConsumer &Consumer, Type BaseTy,
1332
1328
bool includeInstanceMembers,
1333
1329
bool includeDerivedRequirements,
1334
1330
bool includeProtocolExtensionMembers,
1335
- GenericSignatureBuilder *GSB ) {
1331
+ GenericSignature Sig ) {
1336
1332
assert (CurrDC);
1337
1333
LookupState ls = LookupState::makeQualified ();
1338
1334
if (includeInstanceMembers) {
@@ -1347,5 +1343,5 @@ void swift::lookupVisibleMemberDecls(VisibleDeclConsumer &Consumer, Type BaseTy,
1347
1343
1348
1344
::lookupVisibleMemberDecls (BaseTy, Consumer, CurrDC, ls,
1349
1345
DeclVisibilityKind::MemberOfCurrentNominal,
1350
- GSB );
1346
+ Sig );
1351
1347
}
0 commit comments