@@ -290,9 +290,12 @@ class UnqualifiedLookupFactory {
290
290
291
291
void lookupOperatorInDeclContexts (DCAndUnresolvedIsCascadingUse);
292
292
293
- void lookupNameInDeclContexts (const DCAndUnresolvedIsCascadingUse);
293
+ void lookupStartingWith (const DCAndUnresolvedIsCascadingUse);
294
294
295
- void finishLookingInContext (const PerContextInfo &&);
295
+ void finishLookingInContext (AddGenericParameters addGenericParameters,
296
+ DeclContext *lookupContextForThisContext,
297
+ Optional<PlacesToSearch> &&placesToSearch,
298
+ Optional<bool > isCascadingUse);
296
299
297
300
void lookupLocalsInAppropriateContext (DCAndUnresolvedIsCascadingUse);
298
301
@@ -332,7 +335,7 @@ class UnqualifiedLookupFactory {
332
335
bool addLocalVariableResults (DeclContext *dc);
333
336
334
337
// / Return true if finished with lookup
335
- bool handleUnavailableInnerResults (const size_t startIndexOfInnerResults);
338
+ bool setAsideUnavailableResults (const size_t startIndexOfInnerResults);
336
339
337
340
void recordDependencyOnTopLevelName (DeclContext *topLevelContext,
338
341
DeclName name, bool isCascadingUse);
@@ -405,7 +408,7 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
405
408
else if (Name.isOperator ())
406
409
lookupOperatorInDeclContexts (dcAndIsCascadingUse);
407
410
else
408
- lookupNameInDeclContexts (dcAndIsCascadingUse);
411
+ lookupStartingWith (dcAndIsCascadingUse);
409
412
}
410
413
411
414
void UnqualifiedLookupFactory::lookInModuleScopeContext (
@@ -655,7 +658,7 @@ void UnqualifiedLookupFactory::lookupOperatorInDeclContexts(
655
658
}
656
659
657
660
// TODO: Unify with LookupVisibleDecls.cpp::lookupVisibleDeclsImpl
658
- void UnqualifiedLookupFactory::lookupNameInDeclContexts (
661
+ void UnqualifiedLookupFactory::lookupStartingWith (
659
662
const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) {
660
663
// TODO: reloc comment
661
664
// If we are inside of a method, check to see if there are any ivars in
@@ -671,28 +674,31 @@ void UnqualifiedLookupFactory::lookupNameInDeclContexts(
671
674
}
672
675
673
676
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 &&
681
687
addGenericParametersHereAndInEnclosingScopes (lookupContextForThisContext))
682
688
return ;
689
+
683
690
if (placesToSearch.hasValue () && !placesToSearch.getValue ().empty ()) {
684
691
auto startIndexOfInnerResults = Results.size ();
685
692
placesToSearch.getValue ().addToResults (
686
693
Name, isCascadingUse.getValue (), baseNLOptions,
687
694
lookupContextForThisContext, Results);
688
- if (handleUnavailableInnerResults (startIndexOfInnerResults))
695
+ if (setAsideUnavailableResults (startIndexOfInnerResults))
689
696
return ;
690
697
}
691
- auto *const whereToLookNext =
692
- lookupContextForThisContext->getParentForLookup ();
693
698
694
- lookupNameInDeclContexts (
695
- DCAndUnresolvedIsCascadingUse{whereToLookNext, isCascadingUse});
699
+ // Recurse into the next context.
700
+ lookupStartingWith (DCAndUnresolvedIsCascadingUse{
701
+ lookupContextForThisContext->getParentForLookup (), isCascadingUse});
696
702
}
697
703
698
704
void UnqualifiedLookupFactory::lookupLocalsInAppropriateContext (
@@ -728,12 +734,12 @@ void UnqualifiedLookupFactory::lookupLocalsInPatternBindingInitializer(
728
734
return ;
729
735
DeclContext *const parent = PBI->getParent ();
730
736
// clang-format off
731
- finishLookingInContext ( PerContextInfo{
737
+ finishLookingInContext (
732
738
AddGenericParameters::Yes,
733
739
parent,
734
740
PlacesToSearch (PBI, parent, parent),
735
741
resolveIsCascadingUse (PBI, isCascadingUse,
736
- /* onlyCareAboutFunctionBody=*/ false )} );
742
+ /* onlyCareAboutFunctionBody=*/ false ));
737
743
return ;
738
744
// clang-format no
739
745
}
@@ -742,27 +748,26 @@ void UnqualifiedLookupFactory::lookupLocalsInPatternBindingInitializer(
742
748
if (PBD->getDeclContext ()->isTypeContext ()) {
743
749
DeclContext *const surroundingContext = PBI->getParent ();
744
750
// clang-format off
745
- finishLookingInContext ( PerContextInfo{
751
+ finishLookingInContext (
746
752
AddGenericParameters::Yes,
747
753
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 ));
753
758
return ;
754
759
// clang-format on
755
760
}
756
761
// Otherwise, we have an initializer for a global or local property.
757
762
// There's not much to find here, we'll keep going up to a parent
758
763
// context.
759
764
// clang-format off
760
- finishLookingInContext ( PerContextInfo{
765
+ finishLookingInContext (
761
766
AddGenericParameters::Yes,
762
767
PBI,
763
768
None,
764
769
resolveIsCascadingUse (PBI, isCascadingUse,
765
- /* onlyCareAboutFunctionBody=*/ false )} );
770
+ /* onlyCareAboutFunctionBody=*/ false ));
766
771
// clang-format on
767
772
}
768
773
@@ -804,11 +809,11 @@ void UnqualifiedLookupFactory::lookupLocalsInFunctionDecl(
804
809
805
810
if (!AFD->getDeclContext ()->isTypeContext ()) {
806
811
// clang-format off
807
- finishLookingInContext ( PerContextInfo{
812
+ finishLookingInContext (
808
813
AddGenericParameters::Yes,
809
814
AFD,
810
815
None,
811
- returnValueForIsCascadingUse} );
816
+ returnValueForIsCascadingUse);
812
817
return ;
813
818
}
814
819
// clang-format on
@@ -820,13 +825,11 @@ void UnqualifiedLookupFactory::lookupLocalsInFunctionDecl(
820
825
// is the nominal type, not 'self'.
821
826
DeclContext *const BaseDC = isOutsideBodyOfFunction (AFD) ? fnDeclContext : AFD;
822
827
// clang-format off
823
- finishLookingInContext ( PerContextInfo{
828
+ finishLookingInContext (
824
829
AddGenericParameters::Yes,
825
- AFD->getParent (),
826
- PlacesToSearch (BaseDC,
827
- fnDeclContext,
828
- fnDeclContext),
829
- returnValueForIsCascadingUse});
830
+ AFD->getParent (),
831
+ PlacesToSearch (BaseDC, fnDeclContext, fnDeclContext),
832
+ returnValueForIsCascadingUse);
830
833
// clang-format on
831
834
}
832
835
@@ -850,27 +853,27 @@ void UnqualifiedLookupFactory::lookupLocalsInClosure(
850
853
}
851
854
}
852
855
// 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 ));
859
862
// clang-format on
860
863
}
861
864
862
865
template <typename NominalTypeDeclOrExtensionDecl>
863
866
void UnqualifiedLookupFactory::lookupLocalsInNominalTypeOrExtension (
864
867
NominalTypeDeclOrExtensionDecl *D, Optional<bool > isCascadingUse) {
865
868
// 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 ));
874
877
875
878
// clang-format on
876
879
}
@@ -879,8 +882,7 @@ void UnqualifiedLookupFactory::lookupLocalsInDefaultArgumentInitializer(
879
882
DefaultArgumentInitializer *I, Optional<bool > isCascadingUse) {
880
883
// In a default argument, skip immediately out of both the
881
884
// initializer and the function.
882
- finishLookingInContext (
883
- PerContextInfo{AddGenericParameters::No, I->getParent (), None, false });
885
+ finishLookingInContext (AddGenericParameters::No, I->getParent (), None, false );
884
886
}
885
887
886
888
void UnqualifiedLookupFactory::lookupLocalsInMiscContext (
@@ -890,12 +892,12 @@ void UnqualifiedLookupFactory::lookupLocalsInMiscContext(
890
892
isa<Initializer>(dc) ||
891
893
isa<TypeAliasDecl>(dc) ||
892
894
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 ));
899
901
// clang-format on
900
902
}
901
903
@@ -975,7 +977,7 @@ void UnqualifiedLookupFactory::PlacesToSearch::addToResults(
975
977
results.push_back (LookupResultEntry (whereValueIsMember (Result), Result));
976
978
}
977
979
978
- bool UnqualifiedLookupFactory::handleUnavailableInnerResults (
980
+ bool UnqualifiedLookupFactory::setAsideUnavailableResults (
979
981
const size_t startIndexOfInnerResults) {
980
982
// An optimization:
981
983
assert (Results.size () >= startIndexOfInnerResults);
0 commit comments