Skip to content

Commit 64ff790

Browse files
committed
Factor isFinishedWithLookupNowThatIsAboutToLookForOuterResults
1 parent 3a744d1 commit 64ff790

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@ class UnqualifiedLookupFactory {
264264
Optional<bool> isCascadingUse);
265265

266266
/// Return true if done with lookup.
267-
bool isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
268-
bool noMoreOuterResults = false);
267+
bool isFinishedWithLookupNowThatIsAboutToLookForOuterResults();
268+
269+
void setIndexOfFirstOuterResultIfNotSetAlready();
269270

270271
#pragma mark normal (non-ASTScope-based) lookup declarations
271272

@@ -425,8 +426,7 @@ void UnqualifiedLookupFactory::fillInLookup() {
425426
if (lookForAModuleWithTheGivenName(DC))
426427
return;
427428
// Make sure we've recorded the inner-result-boundary.
428-
(void)isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
429-
/*noMoreOuterResults=*/true);
429+
setIndexOfFirstOuterResultIfNotSetAlready();
430430
}
431431

432432
bool UnqualifiedLookupFactory::shouldUseASTScopeLookup() const {
@@ -1062,16 +1062,15 @@ bool UnqualifiedLookupFactory::addNamesKnownToDebugClient(DeclContext *dc) {
10621062
if (Name.isSimpleName() && DebugClient)
10631063
DebugClient->lookupAdditions(Name.getBaseName(), dc, Loc,
10641064
isOriginallyTypeLookup, Results);
1065-
1065+
setIndexOfFirstOuterResultIfNotSetAlready();
10661066
// If we've found something, we're done.
1067-
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1068-
/*noMoreOuterResults=*/true);
1067+
return !Results.empty();
10691068
}
10701069

10711070
bool UnqualifiedLookupFactory::addUnavailableInnerResults() {
10721071
Results = std::move(UnavailableInnerResults);
1073-
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1074-
/*noMoreOuterResults=*/true);
1072+
setIndexOfFirstOuterResultIfNotSetAlready();
1073+
return !Results.empty();
10751074
}
10761075

10771076
bool UnqualifiedLookupFactory::lookForAModuleWithTheGivenName(
@@ -1083,8 +1082,8 @@ bool UnqualifiedLookupFactory::lookForAModuleWithTheGivenName(
10831082
// Look for a module with the given name.
10841083
if (Name.isSimpleName(M.getName())) {
10851084
Results.push_back(LookupResultEntry(&M));
1086-
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1087-
/*noMoreOuterResults=*/true);
1085+
setIndexOfFirstOuterResultIfNotSetAlready();
1086+
return true;
10881087
}
10891088
ModuleDecl *desiredModule = Ctx.getLoadedModule(Name.getBaseIdentifier());
10901089
if (!desiredModule && Name == Ctx.TheBuiltinModule->getName())
@@ -1115,18 +1114,18 @@ NLOptions UnqualifiedLookupFactory::computeBaseNLOptions(
11151114
baseNLOptions |= NL_IgnoreAccessControl;
11161115
return baseNLOptions;
11171116
}
1118-
// TODO: elim flag?
1119-
// TODO: fold this into return None?
1117+
11201118
bool UnqualifiedLookupFactory::
1121-
isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1122-
bool noMoreOuterResults) {
1123-
if (Results.empty())
1124-
return false;
1119+
isFinishedWithLookupNowThatIsAboutToLookForOuterResults() {
1120+
setIndexOfFirstOuterResultIfNotSetAlready();
1121+
1122+
return !Results.empty() && !options.contains(Flags::IncludeOuterResults);
1123+
}
11251124

1125+
void UnqualifiedLookupFactory::setIndexOfFirstOuterResultIfNotSetAlready() {
1126+
// OK to call (NOOP) if there are more inner results and Results is empty
11261127
if (IndexOfFirstOuterResult == 0)
11271128
IndexOfFirstOuterResult = Results.size();
1128-
1129-
return !options.contains(Flags::IncludeOuterResults) || noMoreOuterResults;
11301129
}
11311130

11321131
bool UnqualifiedLookupFactory::resolveIsCascadingUse(

0 commit comments

Comments
 (0)