@@ -273,15 +273,15 @@ class UnqualifiedLookupFactory {
273
273
// / the result.
274
274
void recordCompletionOfAScope ();
275
275
276
- template <typename Fn> void runIfNotDoneYet (Fn fn) {
276
+ template <typename Fn> void ifNotDoneYet (Fn fn) {
277
277
recordCompletionOfAScope ();
278
278
if (!isFirstResultEnough ())
279
279
fn ();
280
280
}
281
281
282
- template <typename Fn1, typename Fn2> void runIfNotDoneYet (Fn1 fn1, Fn2 fn2) {
283
- runIfNotDoneYet (fn1);
284
- runIfNotDoneYet (fn2);
282
+ template <typename Fn1, typename Fn2> void ifNotDoneYet (Fn1 fn1, Fn2 fn2) {
283
+ ifNotDoneYet (fn1);
284
+ ifNotDoneYet (fn2);
285
285
}
286
286
287
287
#pragma mark normal (non-ASTScope-based) lookup declarations
@@ -520,23 +520,22 @@ void UnqualifiedLookupFactory::lookInScopeForASTScopeLookup(
520
520
for (auto local : localBindings) {
521
521
Consumer.foundDecl (local, getLocalDeclVisibilityKind (state.scope ));
522
522
}
523
- const bool inBody =
524
- state.scope ->getKind () == ASTScopeKind::AbstractFunctionBody &&
525
- state.scope ->getAbstractFunctionDecl ()->getDeclContext ()->isTypeContext ();
526
-
527
- // When we are in the body of a method, get the 'self' declaration.
528
- runIfNotDoneYet ([&] {
523
+ ifNotDoneYet ([&] {
524
+ // When we are in the body of a method, get the 'self' declaration.
525
+ const bool inBody =
526
+ state.scope ->getKind () == ASTScopeKind::AbstractFunctionBody &&
527
+ state.scope ->getAbstractFunctionDecl ()
528
+ ->getDeclContext ()
529
+ ->isTypeContext ();
529
530
if (inBody)
530
531
lookInScopeForASTScopeLookup (
531
532
state.withSelfDC (state.scope ->getAbstractFunctionDecl ())
532
533
.withParentScope ());
534
+ // If there is a declaration context associated with this scope, we might
535
+ // want to look in it.
536
+ else
537
+ lookIntoDeclarationContextForASTScopeLookup (state);
533
538
});
534
- if (inBody)
535
- return ;
536
-
537
- // If there is a declaration context associated with this scope, we might
538
- // want to look in it.
539
- runIfNotDoneYet ([&] { lookIntoDeclarationContextForASTScopeLookup (state); });
540
539
}
541
540
542
541
void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup (
@@ -620,7 +619,7 @@ void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
620
619
defaultNextState.selfDC ? defaultNextState.selfDC : scopeDC, scopeDC),
621
620
isCascadingUseResult, baseNLOptions, scopeDC);
622
621
// Forget the 'self' declaration.
623
- runIfNotDoneYet ([&] {
622
+ ifNotDoneYet ([&] {
624
623
lookInScopeForASTScopeLookup (defaultNextState.withSelfDC (nullptr ));
625
624
});
626
625
}
@@ -675,7 +674,7 @@ void UnqualifiedLookupFactory::finishLookingInContext(
675
674
if (addGenericParameters == AddGenericParameters::Yes)
676
675
addGenericParametersHereAndInEnclosingScopes (lookupContextForThisContext);
677
676
678
- runIfNotDoneYet (
677
+ ifNotDoneYet (
679
678
[&] {
680
679
if (resultFinderForSelfsConformances)
681
680
findResultsAndSaveUnavailables (
@@ -702,8 +701,9 @@ void UnqualifiedLookupFactory::lookupInModuleScopeContext(
702
701
DeclContext *dc, Optional<bool > isCascadingUse) {
703
702
if (auto SF = dyn_cast<SourceFile>(dc))
704
703
lookForLocalVariablesIn (SF);
705
- runIfNotDoneYet ([&] {
706
- // TODO: why isn't the following line unconditional?
704
+ ifNotDoneYet ([&] {
705
+ // TODO: figure out why this line is here, not unconditional, or after
706
+ // lookupNonLocals.
707
707
recordDependencyOnTopLevelName (dc, Name, isCascadingUse.getValueOr (true ));
708
708
lookupNonlocalsInModuleScopeContext (dc);
709
709
});
@@ -728,7 +728,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByPatternBindingInitializer(
728
728
PatternBindingInitializer *PBI, ParamDecl *selfParam,
729
729
Optional<bool > isCascadingUse) {
730
730
Consumer.foundDecl (selfParam, DeclVisibilityKind::FunctionParameter);
731
- runIfNotDoneYet ([&] {
731
+ ifNotDoneYet ([&] {
732
732
DeclContext *const patternContainer = PBI->getParent ();
733
733
// clang-format off
734
734
finishLookingInContext (
@@ -791,7 +791,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByFunctionDecl(
791
791
void UnqualifiedLookupFactory::lookupNamesIntroducedByMemberFunction (
792
792
AbstractFunctionDecl *AFD, bool isCascadingUse) {
793
793
lookForLocalVariablesIn (AFD, isCascadingUse);
794
- runIfNotDoneYet (
794
+ ifNotDoneYet (
795
795
[&] {
796
796
// If we're inside a function context, we're about to move to
797
797
// the parent DC, so we have to check the function's generic
@@ -824,7 +824,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByMemberFunction(
824
824
void UnqualifiedLookupFactory::lookupNamesIntroducedByPureFunction (
825
825
AbstractFunctionDecl *AFD, bool isCascadingUse) {
826
826
lookForLocalVariablesIn (AFD, isCascadingUse);
827
- runIfNotDoneYet ([&] {
827
+ ifNotDoneYet ([&] {
828
828
// clang-format off
829
829
finishLookingInContext (
830
830
AddGenericParameters::Yes,
@@ -839,7 +839,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByClosure(
839
839
AbstractClosureExpr *ACE, Optional<bool > isCascadingUse) {
840
840
if (auto *CE = dyn_cast<ClosureExpr>(ACE))
841
841
lookForLocalVariablesIn (CE);
842
- runIfNotDoneYet ([&] {
842
+ ifNotDoneYet ([&] {
843
843
// clang-format off
844
844
finishLookingInContext (
845
845
AddGenericParameters::Yes,
@@ -905,7 +905,7 @@ void UnqualifiedLookupFactory::lookForLocalVariablesIn(
905
905
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
906
906
localVal.visit (AFD->getBody ());
907
907
908
- runIfNotDoneYet ([&] {
908
+ ifNotDoneYet ([&] {
909
909
if (auto *P = AFD->getImplicitSelfDecl ())
910
910
localVal.checkValueDecl (P, DeclVisibilityKind::FunctionParameter);
911
911
localVal.checkParameterList (AFD->getParameters ());
@@ -920,7 +920,7 @@ void UnqualifiedLookupFactory::lookForLocalVariablesIn(ClosureExpr *CE) {
920
920
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
921
921
if (auto body = CE->getBody ())
922
922
localVal.visit (body);
923
- runIfNotDoneYet ([&] {
923
+ ifNotDoneYet ([&] {
924
924
if (auto params = CE->getParameters ())
925
925
localVal.checkParameterList (params);
926
926
});
@@ -970,7 +970,7 @@ void UnqualifiedLookupFactory::addGenericParametersHereAndInEnclosingScopes(
970
970
return ;
971
971
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
972
972
localVal.checkGenericParams (dcGenericParams);
973
- runIfNotDoneYet ([&] {
973
+ ifNotDoneYet ([&] {
974
974
addGenericParametersHereAndInEnclosingScopes (
975
975
dcGenericParams->getOuterParameters ());
976
976
});
0 commit comments