@@ -138,26 +138,25 @@ class UnqualifiedLookupFactory {
138
138
// / But in addition, self could conform to any number of protocols.
139
139
// / For example, when there's a protocol extension, e.g. extension P where
140
140
// / self: P2, self also conforms to P2 so P2 must be searched.
141
- class ResultFinderForSelfsConformances {
141
+ class ResultFinderForTypeContext {
142
142
// / Nontypes are formally members of the base type, i.e. the dynamic type
143
143
// / of the activation record.
144
144
DeclContext *const dynamicContext;
145
145
// / Types are formally members of the metatype, i.e. the static type of the
146
146
// / activation record.
147
147
DeclContext *const staticContext;
148
- using NominalTypesThatSelfMustConformTo = SmallVector<NominalTypeDecl *, 2 >;
149
- NominalTypesThatSelfMustConformTo nominalTypesThatSelfMustConformTo ;
148
+ using SelfBounds = SmallVector<NominalTypeDecl *, 2 >;
149
+ SelfBounds selfBounds ;
150
150
151
151
public:
152
152
// / \p staticContext is also the context from which to derive the self types
153
- ResultFinderForSelfsConformances (DeclContext *dynamicContext,
154
- DeclContext *staticContext);
153
+ ResultFinderForTypeContext (DeclContext *dynamicContext,
154
+ DeclContext *staticContext);
155
155
156
156
void dump () const ;
157
157
158
158
private:
159
- NominalTypesThatSelfMustConformTo
160
- findNominalTypesThatSelfMustConformTo (DeclContext *dc);
159
+ SelfBounds findSelfBounds (DeclContext *dc);
161
160
162
161
// Classify this declaration.
163
162
// Types are formally members of the metatype.
@@ -287,11 +286,11 @@ class UnqualifiedLookupFactory {
287
286
288
287
void lookupNamesIntroducedBy (const ContextAndUnresolvedIsCascadingUse);
289
288
290
- void finishLookingInContext (AddGenericParameters addGenericParameters,
291
- DeclContext *lookupContextForThisContext ,
292
- Optional<ResultFinderForSelfsConformances>
293
- &&resultFinderForSelfsConformances ,
294
- Optional<bool > isCascadingUse);
289
+ void finishLookingInContext (
290
+ AddGenericParameters addGenericParameters ,
291
+ DeclContext *lookupContextForThisContext,
292
+ Optional<ResultFinderForTypeContext> &&resultFinderForTypeContext ,
293
+ Optional<bool > isCascadingUse);
295
294
296
295
void lookupInModuleScopeContext (DeclContext *, Optional<bool > isCascadingUse);
297
296
@@ -379,10 +378,10 @@ class UnqualifiedLookupFactory {
379
378
onlyCareAboutFunctionBody);
380
379
}
381
380
382
- void findResultsAndSaveUnavailables (ResultFinderForSelfsConformances &&PTS,
383
- bool isCascadingUse ,
384
- NLOptions baseNLOptions,
385
- DeclContext *lookupContextForThisContext);
381
+ void findResultsAndSaveUnavailables (
382
+ ResultFinderForTypeContext &&resultFinderForTypeContext ,
383
+ bool isCascadingUse, NLOptions baseNLOptions,
384
+ DeclContext *lookupContextForThisContext);
386
385
387
386
void dumpBreadcrumbs () const ;
388
387
@@ -615,7 +614,7 @@ void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
615
614
// Dig out the type we're looking into.
616
615
// Perform lookup into the type
617
616
findResultsAndSaveUnavailables (
618
- ResultFinderForSelfsConformances (
617
+ ResultFinderForTypeContext (
619
618
defaultNextState.selfDC ? defaultNextState.selfDC : scopeDC, scopeDC),
620
619
isCascadingUseResult, baseNLOptions, scopeDC);
621
620
// Forget the 'self' declaration.
@@ -664,8 +663,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedBy(
664
663
void UnqualifiedLookupFactory::finishLookingInContext (
665
664
const AddGenericParameters addGenericParameters,
666
665
DeclContext *const lookupContextForThisContext,
667
- Optional<ResultFinderForSelfsConformances>
668
- &&resultFinderForSelfsConformances,
666
+ Optional<ResultFinderForTypeContext> &&resultFinderForTypeContext,
669
667
const Optional<bool > isCascadingUse) {
670
668
671
669
// When a generic has the same name as a member, Swift prioritizes the generic
@@ -677,10 +675,10 @@ void UnqualifiedLookupFactory::finishLookingInContext(
677
675
678
676
ifNotDoneYet (
679
677
[&] {
680
- if (resultFinderForSelfsConformances )
681
- findResultsAndSaveUnavailables (
682
- std::move (*resultFinderForSelfsConformances), *isCascadingUse,
683
- baseNLOptions, lookupContextForThisContext);
678
+ if (resultFinderForTypeContext )
679
+ findResultsAndSaveUnavailables (std::move (*resultFinderForTypeContext),
680
+ *isCascadingUse, baseNLOptions ,
681
+ lookupContextForThisContext);
684
682
},
685
683
// Recurse into the next context.
686
684
[&] {
@@ -690,11 +688,12 @@ void UnqualifiedLookupFactory::finishLookingInContext(
690
688
}
691
689
692
690
void UnqualifiedLookupFactory::findResultsAndSaveUnavailables (
693
- ResultFinderForSelfsConformances &&PTS, bool isCascadingUse,
694
- NLOptions baseNLOptions, DeclContext *lookupContextForThisContext) {
691
+ ResultFinderForTypeContext &&resultFinderForTypeContext,
692
+ bool isCascadingUse, NLOptions baseNLOptions,
693
+ DeclContext *lookupContextForThisContext) {
695
694
auto firstPossiblyUnavailableResult = Results.size ();
696
- PTS .findResults (Name, isCascadingUse, baseNLOptions,
697
- lookupContextForThisContext, Results);
695
+ resultFinderForTypeContext .findResults (Name, isCascadingUse, baseNLOptions,
696
+ lookupContextForThisContext, Results);
698
697
setAsideUnavailableResults (firstPossiblyUnavailableResult);
699
698
}
700
699
@@ -735,7 +734,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByPatternBindingInitializer(
735
734
finishLookingInContext (
736
735
AddGenericParameters::Yes,
737
736
patternContainer,
738
- ResultFinderForSelfsConformances (PBI, patternContainer),
737
+ ResultFinderForTypeContext (PBI, patternContainer),
739
738
resolveIsCascadingUse (PBI, isCascadingUse,
740
739
/* onlyCareAboutFunctionBody=*/ false ));
741
740
// clang-format on
@@ -752,7 +751,7 @@ void UnqualifiedLookupFactory::
752
751
finishLookingInContext (
753
752
AddGenericParameters::Yes,
754
753
storedPropertyContainer,
755
- ResultFinderForSelfsConformances (storedPropertyContainer, storedPropertyContainer),
754
+ ResultFinderForTypeContext (storedPropertyContainer, storedPropertyContainer),
756
755
resolveIsCascadingUse (storedPropertyContainer, None,
757
756
/* onlyCareAboutFunctionBody=*/ false ));
758
757
// clang-format on
@@ -816,7 +815,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByMemberFunction(
816
815
finishLookingInContext (
817
816
AddGenericParameters::Yes,
818
817
AFD->getParent (),
819
- ResultFinderForSelfsConformances (BaseDC, fnDeclContext),
818
+ ResultFinderForTypeContext (BaseDC, fnDeclContext),
820
819
isCascadingUse);
821
820
// clang-format on
822
821
});
@@ -860,7 +859,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByNominalTypeOrExtension(
860
859
AddGenericParameters::Yes,
861
860
D,
862
861
shouldLookupMembers (D, Loc)
863
- ? Optional<ResultFinderForSelfsConformances>( ResultFinderForSelfsConformances (D, D))
862
+ ? Optional<ResultFinderForTypeContext>( ResultFinderForTypeContext (D, D))
864
863
: None,
865
864
resolveIsCascadingUse (D, isCascadingUse,
866
865
/* onlyCareAboutFunctionBody=*/ false ));
@@ -986,20 +985,19 @@ void UnqualifiedLookupFactory::addGenericParametersForFunction(
986
985
}
987
986
}
988
987
989
- void UnqualifiedLookupFactory::ResultFinderForSelfsConformances ::findResults (
988
+ void UnqualifiedLookupFactory::ResultFinderForTypeContext ::findResults (
990
989
const DeclName &Name, bool isCascadingUse, NLOptions baseNLOptions,
991
990
DeclContext *contextForLookup,
992
991
SmallVectorImpl<LookupResultEntry> &results) const {
993
992
// An optimization:
994
- if (nominalTypesThatSelfMustConformTo .empty ())
993
+ if (selfBounds .empty ())
995
994
return ;
996
995
const NLOptions options =
997
996
baseNLOptions | (isCascadingUse ? NL_KnownCascadingDependency
998
997
: NL_KnownNonCascadingDependency);
999
998
1000
999
SmallVector<ValueDecl *, 4 > Lookup;
1001
- contextForLookup->lookupQualified (nominalTypesThatSelfMustConformTo, Name,
1002
- options, Lookup);
1000
+ contextForLookup->lookupQualified (selfBounds, Name, options, Lookup);
1003
1001
for (auto Result : Lookup)
1004
1002
results.push_back (LookupResultEntry (whereValueIsMember (Result), Result));
1005
1003
}
@@ -1703,33 +1701,31 @@ TypeDecl *LegacyUnqualifiedLookup::getSingleTypeResult() const {
1703
1701
return dyn_cast<TypeDecl>(Results.back ().getValueDecl ());
1704
1702
}
1705
1703
1706
- UnqualifiedLookupFactory::ResultFinderForSelfsConformances ::
1707
- ResultFinderForSelfsConformances (DeclContext *dynamicContext,
1708
- DeclContext *staticContext)
1704
+ UnqualifiedLookupFactory::ResultFinderForTypeContext ::
1705
+ ResultFinderForTypeContext (DeclContext *dynamicContext,
1706
+ DeclContext *staticContext)
1709
1707
: dynamicContext(dynamicContext), staticContext(staticContext),
1710
- nominalTypesThatSelfMustConformTo(
1711
- findNominalTypesThatSelfMustConformTo (staticContext)) {}
1708
+ selfBounds(findSelfBounds(staticContext)) {}
1712
1709
1713
- UnqualifiedLookupFactory::ResultFinderForSelfsConformances::
1714
- NominalTypesThatSelfMustConformTo
1715
- UnqualifiedLookupFactory::ResultFinderForSelfsConformances::
1716
- findNominalTypesThatSelfMustConformTo (DeclContext *dc) {
1710
+ UnqualifiedLookupFactory::ResultFinderForTypeContext::SelfBounds
1711
+ UnqualifiedLookupFactory::ResultFinderForTypeContext::findSelfBounds (
1712
+ DeclContext *dc) {
1717
1713
auto nominal = dc->getSelfNominalTypeDecl ();
1718
1714
if (!nominal)
1719
1715
return {};
1720
1716
1721
- NominalTypesThatSelfMustConformTo lookupDecls ;
1722
- lookupDecls .push_back (nominal);
1717
+ SelfBounds selfBounds ;
1718
+ selfBounds .push_back (nominal);
1723
1719
1724
1720
// For a protocol extension, check whether there are additional "Self"
1725
1721
// constraints that can affect name lookup.
1726
1722
if (dc->getExtendedProtocolDecl ()) {
1727
1723
auto ext = cast<ExtensionDecl>(dc);
1728
1724
auto bounds = getSelfBoundsFromWhereClause (ext);
1729
1725
for (auto bound : bounds.decls )
1730
- lookupDecls .push_back (bound);
1726
+ selfBounds .push_back (bound);
1731
1727
}
1732
- return lookupDecls ;
1728
+ return selfBounds ;
1733
1729
}
1734
1730
1735
1731
void LegacyUnqualifiedLookup::populateLookupDeclsFromContext (
@@ -1750,13 +1746,13 @@ void LegacyUnqualifiedLookup::populateLookupDeclsFromContext(
1750
1746
}
1751
1747
}
1752
1748
1753
- void UnqualifiedLookupFactory::ResultFinderForSelfsConformances ::dump () const {
1749
+ void UnqualifiedLookupFactory::ResultFinderForTypeContext ::dump () const {
1754
1750
llvm::errs () << " dynamicContext: " ;
1755
1751
dynamicContext->dumpContext ();
1756
1752
llvm::errs () << " staticContext: " ;
1757
1753
staticContext->dumpContext ();
1758
- llvm::errs () << " nominalTypesThatSelfMustConformTo : " ;
1759
- for (const auto *D : nominalTypesThatSelfMustConformTo )
1754
+ llvm::errs () << " selfBounds : " ;
1755
+ for (const auto *D : selfBounds )
1760
1756
D->dump (llvm::errs (), 1 );
1761
1757
llvm::errs () << " \n " ;
1762
1758
}
0 commit comments