Skip to content

Commit 3641e35

Browse files
committed
Pass individual arguments.
1 parent 0a817a9 commit 3641e35

File tree

1 file changed

+60
-58
lines changed

1 file changed

+60
-58
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,12 @@ class UnqualifiedLookupFactory {
290290

291291
void lookupOperatorInDeclContexts(DCAndUnresolvedIsCascadingUse);
292292

293-
void lookupNameInDeclContexts(const DCAndUnresolvedIsCascadingUse);
293+
void lookupStartingWith(const DCAndUnresolvedIsCascadingUse);
294294

295-
void finishLookingInContext(const PerContextInfo &&);
295+
void finishLookingInContext(AddGenericParameters addGenericParameters,
296+
DeclContext *lookupContextForThisContext,
297+
Optional<PlacesToSearch> &&placesToSearch,
298+
Optional<bool> isCascadingUse);
296299

297300
void lookupLocalsInAppropriateContext(DCAndUnresolvedIsCascadingUse);
298301

@@ -332,7 +335,7 @@ class UnqualifiedLookupFactory {
332335
bool addLocalVariableResults(DeclContext *dc);
333336

334337
/// Return true if finished with lookup
335-
bool handleUnavailableInnerResults(const size_t startIndexOfInnerResults);
338+
bool setAsideUnavailableResults(const size_t startIndexOfInnerResults);
336339

337340
void recordDependencyOnTopLevelName(DeclContext *topLevelContext,
338341
DeclName name, bool isCascadingUse);
@@ -405,7 +408,7 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
405408
else if (Name.isOperator())
406409
lookupOperatorInDeclContexts(dcAndIsCascadingUse);
407410
else
408-
lookupNameInDeclContexts(dcAndIsCascadingUse);
411+
lookupStartingWith(dcAndIsCascadingUse);
409412
}
410413

411414
void UnqualifiedLookupFactory::lookInModuleScopeContext(
@@ -655,7 +658,7 @@ void UnqualifiedLookupFactory::lookupOperatorInDeclContexts(
655658
}
656659

657660
// TODO: Unify with LookupVisibleDecls.cpp::lookupVisibleDeclsImpl
658-
void UnqualifiedLookupFactory::lookupNameInDeclContexts(
661+
void UnqualifiedLookupFactory::lookupStartingWith(
659662
const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) {
660663
// TODO: reloc comment
661664
// If we are inside of a method, check to see if there are any ivars in
@@ -671,28 +674,31 @@ void UnqualifiedLookupFactory::lookupNameInDeclContexts(
671674
}
672675

673676
void UnqualifiedLookupFactory::finishLookingInContext(
674-
const PerContextInfo &&info) {
675-
breadcrumbs.push_back(info);
676-
auto lookupContextForThisContext = info.lookupContextForThisContext;
677-
auto placesToSearch = std::move(info.placesToSearch);
678-
auto isCascadingUse = info.isCascadingUse;
679-
680-
if (info.addGenericParameters == AddGenericParameters::Yes &&
677+
const AddGenericParameters addGenericParameters,
678+
DeclContext *const lookupContextForThisContext,
679+
Optional<PlacesToSearch> &&placesToSearch,
680+
const Optional<bool> isCascadingUse) {
681+
#ifndef NDEBUG
682+
breadcrumbs.push_back(PerContextInfo{addGenericParameters,
683+
lookupContextForThisContext,
684+
placesToSearch, isCascadingUse});
685+
#endif
686+
if (addGenericParameters == AddGenericParameters::Yes &&
681687
addGenericParametersHereAndInEnclosingScopes(lookupContextForThisContext))
682688
return;
689+
683690
if (placesToSearch.hasValue() && !placesToSearch.getValue().empty()) {
684691
auto startIndexOfInnerResults = Results.size();
685692
placesToSearch.getValue().addToResults(
686693
Name, isCascadingUse.getValue(), baseNLOptions,
687694
lookupContextForThisContext, Results);
688-
if (handleUnavailableInnerResults(startIndexOfInnerResults))
695+
if (setAsideUnavailableResults(startIndexOfInnerResults))
689696
return;
690697
}
691-
auto *const whereToLookNext =
692-
lookupContextForThisContext->getParentForLookup();
693698

694-
lookupNameInDeclContexts(
695-
DCAndUnresolvedIsCascadingUse{whereToLookNext, isCascadingUse});
699+
// Recurse into the next context.
700+
lookupStartingWith(DCAndUnresolvedIsCascadingUse{
701+
lookupContextForThisContext->getParentForLookup(), isCascadingUse});
696702
}
697703

698704
void UnqualifiedLookupFactory::lookupLocalsInAppropriateContext(
@@ -728,12 +734,12 @@ void UnqualifiedLookupFactory::lookupLocalsInPatternBindingInitializer(
728734
return;
729735
DeclContext *const parent = PBI->getParent();
730736
// clang-format off
731-
finishLookingInContext( PerContextInfo{
737+
finishLookingInContext(
732738
AddGenericParameters::Yes,
733739
parent,
734740
PlacesToSearch(PBI, parent, parent),
735741
resolveIsCascadingUse(PBI, isCascadingUse,
736-
/*onlyCareAboutFunctionBody=*/false)});
742+
/*onlyCareAboutFunctionBody=*/false));
737743
return;
738744
// clang-format no
739745
}
@@ -742,27 +748,26 @@ void UnqualifiedLookupFactory::lookupLocalsInPatternBindingInitializer(
742748
if (PBD->getDeclContext()->isTypeContext()) {
743749
DeclContext *const surroundingContext = PBI->getParent();
744750
// clang-format off
745-
finishLookingInContext( PerContextInfo{
751+
finishLookingInContext(
746752
AddGenericParameters::Yes,
747753
surroundingContext,
748-
PlacesToSearch(surroundingContext,
749-
surroundingContext, surroundingContext),
750-
resolveIsCascadingUse(surroundingContext,
751-
None,
752-
/*onlyCareAboutFunctionBody=*/false)});
754+
PlacesToSearch(surroundingContext, surroundingContext,
755+
surroundingContext),
756+
resolveIsCascadingUse(surroundingContext, None,
757+
/*onlyCareAboutFunctionBody=*/false));
753758
return;
754759
// clang-format on
755760
}
756761
// Otherwise, we have an initializer for a global or local property.
757762
// There's not much to find here, we'll keep going up to a parent
758763
// context.
759764
// clang-format off
760-
finishLookingInContext( PerContextInfo{
765+
finishLookingInContext(
761766
AddGenericParameters::Yes,
762767
PBI,
763768
None,
764769
resolveIsCascadingUse(PBI, isCascadingUse,
765-
/*onlyCareAboutFunctionBody=*/false)});
770+
/*onlyCareAboutFunctionBody=*/false));
766771
// clang-format on
767772
}
768773

@@ -804,11 +809,11 @@ void UnqualifiedLookupFactory::lookupLocalsInFunctionDecl(
804809

805810
if (!AFD->getDeclContext()->isTypeContext()) {
806811
// clang-format off
807-
finishLookingInContext( PerContextInfo{
812+
finishLookingInContext(
808813
AddGenericParameters::Yes,
809814
AFD,
810815
None,
811-
returnValueForIsCascadingUse});
816+
returnValueForIsCascadingUse);
812817
return;
813818
}
814819
// clang-format on
@@ -820,13 +825,11 @@ void UnqualifiedLookupFactory::lookupLocalsInFunctionDecl(
820825
// is the nominal type, not 'self'.
821826
DeclContext *const BaseDC = isOutsideBodyOfFunction(AFD) ? fnDeclContext : AFD;
822827
// clang-format off
823-
finishLookingInContext( PerContextInfo{
828+
finishLookingInContext(
824829
AddGenericParameters::Yes,
825-
AFD->getParent(),
826-
PlacesToSearch(BaseDC,
827-
fnDeclContext,
828-
fnDeclContext),
829-
returnValueForIsCascadingUse});
830+
AFD->getParent(),
831+
PlacesToSearch(BaseDC, fnDeclContext, fnDeclContext),
832+
returnValueForIsCascadingUse);
830833
// clang-format on
831834
}
832835

@@ -850,27 +853,27 @@ void UnqualifiedLookupFactory::lookupLocalsInClosure(
850853
}
851854
}
852855
// clang-format off
853-
finishLookingInContext( PerContextInfo{
854-
AddGenericParameters::Yes,
855-
ACE,
856-
None,
857-
resolveIsCascadingUse(ACE, isCascadingUse,
858-
/*onlyCareAboutFunctionBody=*/false)});
856+
finishLookingInContext(
857+
AddGenericParameters::Yes,
858+
ACE,
859+
None,
860+
resolveIsCascadingUse(ACE, isCascadingUse,
861+
/*onlyCareAboutFunctionBody=*/false));
859862
// clang-format on
860863
}
861864

862865
template <typename NominalTypeDeclOrExtensionDecl>
863866
void UnqualifiedLookupFactory::lookupLocalsInNominalTypeOrExtension(
864867
NominalTypeDeclOrExtensionDecl *D, Optional<bool> isCascadingUse) {
865868
// clang-format off
866-
finishLookingInContext( PerContextInfo{
867-
AddGenericParameters::Yes,
868-
D,
869-
shouldLookupMembers(D, Loc)
870-
? Optional<PlacesToSearch>(PlacesToSearch(D, D, D))
871-
: None,
872-
resolveIsCascadingUse(D, isCascadingUse,
873-
/*onlyCareAboutFunctionBody=*/false)});
869+
finishLookingInContext(
870+
AddGenericParameters::Yes,
871+
D,
872+
shouldLookupMembers(D, Loc)
873+
? Optional<PlacesToSearch>(PlacesToSearch(D, D, D))
874+
: None,
875+
resolveIsCascadingUse(D, isCascadingUse,
876+
/*onlyCareAboutFunctionBody=*/false));
874877

875878
// clang-format on
876879
}
@@ -879,8 +882,7 @@ void UnqualifiedLookupFactory::lookupLocalsInDefaultArgumentInitializer(
879882
DefaultArgumentInitializer *I, Optional<bool> isCascadingUse) {
880883
// In a default argument, skip immediately out of both the
881884
// initializer and the function.
882-
finishLookingInContext(
883-
PerContextInfo{AddGenericParameters::No, I->getParent(), None, false});
885+
finishLookingInContext(AddGenericParameters::No, I->getParent(), None, false);
884886
}
885887

886888
void UnqualifiedLookupFactory::lookupLocalsInMiscContext(
@@ -890,12 +892,12 @@ void UnqualifiedLookupFactory::lookupLocalsInMiscContext(
890892
isa<Initializer>(dc) ||
891893
isa<TypeAliasDecl>(dc) ||
892894
isa<SubscriptDecl>(dc));
893-
finishLookingInContext( PerContextInfo{
894-
AddGenericParameters::Yes,
895-
dc,
896-
None,
897-
resolveIsCascadingUse(DC, isCascadingUse,
898-
/*onlyCareAboutFunctionBody=*/false)});
895+
finishLookingInContext(
896+
AddGenericParameters::Yes,
897+
dc,
898+
None,
899+
resolveIsCascadingUse(DC, isCascadingUse,
900+
/*onlyCareAboutFunctionBody=*/false));
899901
// clang-format on
900902
}
901903

@@ -975,7 +977,7 @@ void UnqualifiedLookupFactory::PlacesToSearch::addToResults(
975977
results.push_back(LookupResultEntry(whereValueIsMember(Result), Result));
976978
}
977979

978-
bool UnqualifiedLookupFactory::handleUnavailableInnerResults(
980+
bool UnqualifiedLookupFactory::setAsideUnavailableResults(
979981
const size_t startIndexOfInnerResults) {
980982
// An optimization:
981983
assert(Results.size() >= startIndexOfInnerResults);

0 commit comments

Comments
 (0)