Skip to content

Commit 543c826

Browse files
author
David Ungar
committed
Rename ResultFinderForSelfsConformances
1 parent 85d6012 commit 543c826

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,25 @@ class UnqualifiedLookupFactory {
138138
/// But in addition, self could conform to any number of protocols.
139139
/// For example, when there's a protocol extension, e.g. extension P where
140140
/// self: P2, self also conforms to P2 so P2 must be searched.
141-
class ResultFinderForSelfsConformances {
141+
class ResultFinderForTypeContext {
142142
/// Nontypes are formally members of the base type, i.e. the dynamic type
143143
/// of the activation record.
144144
DeclContext *const dynamicContext;
145145
/// Types are formally members of the metatype, i.e. the static type of the
146146
/// activation record.
147147
DeclContext *const staticContext;
148-
using NominalTypesThatSelfMustConformTo = SmallVector<NominalTypeDecl *, 2>;
149-
NominalTypesThatSelfMustConformTo nominalTypesThatSelfMustConformTo;
148+
using SelfBounds = SmallVector<NominalTypeDecl *, 2>;
149+
SelfBounds selfBounds;
150150

151151
public:
152152
/// \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);
155155

156156
void dump() const;
157157

158158
private:
159-
NominalTypesThatSelfMustConformTo
160-
findNominalTypesThatSelfMustConformTo(DeclContext *dc);
159+
SelfBounds findSelfBounds(DeclContext *dc);
161160

162161
// Classify this declaration.
163162
// Types are formally members of the metatype.
@@ -287,11 +286,11 @@ class UnqualifiedLookupFactory {
287286

288287
void lookupNamesIntroducedBy(const ContextAndUnresolvedIsCascadingUse);
289288

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);
295294

296295
void lookupInModuleScopeContext(DeclContext *, Optional<bool> isCascadingUse);
297296

@@ -379,10 +378,10 @@ class UnqualifiedLookupFactory {
379378
onlyCareAboutFunctionBody);
380379
}
381380

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);
386385

387386
void dumpBreadcrumbs() const;
388387

@@ -615,7 +614,7 @@ void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
615614
// Dig out the type we're looking into.
616615
// Perform lookup into the type
617616
findResultsAndSaveUnavailables(
618-
ResultFinderForSelfsConformances(
617+
ResultFinderForTypeContext(
619618
defaultNextState.selfDC ? defaultNextState.selfDC : scopeDC, scopeDC),
620619
isCascadingUseResult, baseNLOptions, scopeDC);
621620
// Forget the 'self' declaration.
@@ -664,8 +663,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedBy(
664663
void UnqualifiedLookupFactory::finishLookingInContext(
665664
const AddGenericParameters addGenericParameters,
666665
DeclContext *const lookupContextForThisContext,
667-
Optional<ResultFinderForSelfsConformances>
668-
&&resultFinderForSelfsConformances,
666+
Optional<ResultFinderForTypeContext> &&resultFinderForTypeContext,
669667
const Optional<bool> isCascadingUse) {
670668

671669
// When a generic has the same name as a member, Swift prioritizes the generic
@@ -677,10 +675,10 @@ void UnqualifiedLookupFactory::finishLookingInContext(
677675

678676
ifNotDoneYet(
679677
[&] {
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);
684682
},
685683
// Recurse into the next context.
686684
[&] {
@@ -690,11 +688,12 @@ void UnqualifiedLookupFactory::finishLookingInContext(
690688
}
691689

692690
void UnqualifiedLookupFactory::findResultsAndSaveUnavailables(
693-
ResultFinderForSelfsConformances &&PTS, bool isCascadingUse,
694-
NLOptions baseNLOptions, DeclContext *lookupContextForThisContext) {
691+
ResultFinderForTypeContext &&resultFinderForTypeContext,
692+
bool isCascadingUse, NLOptions baseNLOptions,
693+
DeclContext *lookupContextForThisContext) {
695694
auto firstPossiblyUnavailableResult = Results.size();
696-
PTS.findResults(Name, isCascadingUse, baseNLOptions,
697-
lookupContextForThisContext, Results);
695+
resultFinderForTypeContext.findResults(Name, isCascadingUse, baseNLOptions,
696+
lookupContextForThisContext, Results);
698697
setAsideUnavailableResults(firstPossiblyUnavailableResult);
699698
}
700699

@@ -735,7 +734,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByPatternBindingInitializer(
735734
finishLookingInContext(
736735
AddGenericParameters::Yes,
737736
patternContainer,
738-
ResultFinderForSelfsConformances(PBI, patternContainer),
737+
ResultFinderForTypeContext(PBI, patternContainer),
739738
resolveIsCascadingUse(PBI, isCascadingUse,
740739
/*onlyCareAboutFunctionBody=*/false));
741740
// clang-format on
@@ -752,7 +751,7 @@ void UnqualifiedLookupFactory::
752751
finishLookingInContext(
753752
AddGenericParameters::Yes,
754753
storedPropertyContainer,
755-
ResultFinderForSelfsConformances(storedPropertyContainer, storedPropertyContainer),
754+
ResultFinderForTypeContext(storedPropertyContainer, storedPropertyContainer),
756755
resolveIsCascadingUse(storedPropertyContainer, None,
757756
/*onlyCareAboutFunctionBody=*/false));
758757
// clang-format on
@@ -816,7 +815,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByMemberFunction(
816815
finishLookingInContext(
817816
AddGenericParameters::Yes,
818817
AFD->getParent(),
819-
ResultFinderForSelfsConformances(BaseDC, fnDeclContext),
818+
ResultFinderForTypeContext(BaseDC, fnDeclContext),
820819
isCascadingUse);
821820
// clang-format on
822821
});
@@ -860,7 +859,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByNominalTypeOrExtension(
860859
AddGenericParameters::Yes,
861860
D,
862861
shouldLookupMembers(D, Loc)
863-
? Optional<ResultFinderForSelfsConformances>(ResultFinderForSelfsConformances(D, D))
862+
? Optional<ResultFinderForTypeContext>(ResultFinderForTypeContext(D, D))
864863
: None,
865864
resolveIsCascadingUse(D, isCascadingUse,
866865
/*onlyCareAboutFunctionBody=*/false));
@@ -986,20 +985,19 @@ void UnqualifiedLookupFactory::addGenericParametersForFunction(
986985
}
987986
}
988987

989-
void UnqualifiedLookupFactory::ResultFinderForSelfsConformances::findResults(
988+
void UnqualifiedLookupFactory::ResultFinderForTypeContext::findResults(
990989
const DeclName &Name, bool isCascadingUse, NLOptions baseNLOptions,
991990
DeclContext *contextForLookup,
992991
SmallVectorImpl<LookupResultEntry> &results) const {
993992
// An optimization:
994-
if (nominalTypesThatSelfMustConformTo.empty())
993+
if (selfBounds.empty())
995994
return;
996995
const NLOptions options =
997996
baseNLOptions | (isCascadingUse ? NL_KnownCascadingDependency
998997
: NL_KnownNonCascadingDependency);
999998

1000999
SmallVector<ValueDecl *, 4> Lookup;
1001-
contextForLookup->lookupQualified(nominalTypesThatSelfMustConformTo, Name,
1002-
options, Lookup);
1000+
contextForLookup->lookupQualified(selfBounds, Name, options, Lookup);
10031001
for (auto Result : Lookup)
10041002
results.push_back(LookupResultEntry(whereValueIsMember(Result), Result));
10051003
}
@@ -1703,33 +1701,31 @@ TypeDecl *LegacyUnqualifiedLookup::getSingleTypeResult() const {
17031701
return dyn_cast<TypeDecl>(Results.back().getValueDecl());
17041702
}
17051703

1706-
UnqualifiedLookupFactory::ResultFinderForSelfsConformances::
1707-
ResultFinderForSelfsConformances(DeclContext *dynamicContext,
1708-
DeclContext *staticContext)
1704+
UnqualifiedLookupFactory::ResultFinderForTypeContext::
1705+
ResultFinderForTypeContext(DeclContext *dynamicContext,
1706+
DeclContext *staticContext)
17091707
: dynamicContext(dynamicContext), staticContext(staticContext),
1710-
nominalTypesThatSelfMustConformTo(
1711-
findNominalTypesThatSelfMustConformTo(staticContext)) {}
1708+
selfBounds(findSelfBounds(staticContext)) {}
17121709

1713-
UnqualifiedLookupFactory::ResultFinderForSelfsConformances::
1714-
NominalTypesThatSelfMustConformTo
1715-
UnqualifiedLookupFactory::ResultFinderForSelfsConformances::
1716-
findNominalTypesThatSelfMustConformTo(DeclContext *dc) {
1710+
UnqualifiedLookupFactory::ResultFinderForTypeContext::SelfBounds
1711+
UnqualifiedLookupFactory::ResultFinderForTypeContext::findSelfBounds(
1712+
DeclContext *dc) {
17171713
auto nominal = dc->getSelfNominalTypeDecl();
17181714
if (!nominal)
17191715
return {};
17201716

1721-
NominalTypesThatSelfMustConformTo lookupDecls;
1722-
lookupDecls.push_back(nominal);
1717+
SelfBounds selfBounds;
1718+
selfBounds.push_back(nominal);
17231719

17241720
// For a protocol extension, check whether there are additional "Self"
17251721
// constraints that can affect name lookup.
17261722
if (dc->getExtendedProtocolDecl()) {
17271723
auto ext = cast<ExtensionDecl>(dc);
17281724
auto bounds = getSelfBoundsFromWhereClause(ext);
17291725
for (auto bound : bounds.decls)
1730-
lookupDecls.push_back(bound);
1726+
selfBounds.push_back(bound);
17311727
}
1732-
return lookupDecls;
1728+
return selfBounds;
17331729
}
17341730

17351731
void LegacyUnqualifiedLookup::populateLookupDeclsFromContext(
@@ -1750,13 +1746,13 @@ void LegacyUnqualifiedLookup::populateLookupDeclsFromContext(
17501746
}
17511747
}
17521748

1753-
void UnqualifiedLookupFactory::ResultFinderForSelfsConformances::dump() const {
1749+
void UnqualifiedLookupFactory::ResultFinderForTypeContext::dump() const {
17541750
llvm::errs() << "dynamicContext: ";
17551751
dynamicContext->dumpContext();
17561752
llvm::errs() << "staticContext: ";
17571753
staticContext->dumpContext();
1758-
llvm::errs() << "nominalTypesThatSelfMustConformTo: ";
1759-
for (const auto *D : nominalTypesThatSelfMustConformTo)
1754+
llvm::errs() << "selfBounds: ";
1755+
for (const auto *D : selfBounds)
17601756
D->dump(llvm::errs(), 1);
17611757
llvm::errs() << "\n";
17621758
}

0 commit comments

Comments
 (0)