Skip to content

Commit e9298a1

Browse files
committed
Renamed shouldReturnBasedOnResults to isFinishedWithLookupNowThatIsAboutToLookForOuterResults
1 parent 04ef0da commit e9298a1

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

include/swift/AST/NameLookup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
157157
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
158158
/// will be Results from the innermost scope that had results, and the
159159
/// remaining elements of Results will be from parent scopes of this one.
160+
///
161+
/// Allows unqualified name lookup to return results from outer scopes.
162+
/// This is necessary for disambiguating calls to functions like `min` and
163+
/// `max`.
160164
size_t IndexOfFirstOuterResult;
161165

162166
/// Return true if anything was found by the name lookup.

lib/AST/NameLookup.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ namespace {
13191319
LazyResolver *const TypeResolver;
13201320
SourceLoc Loc;
13211321
const SourceManager &SM;
1322+
/// Used to find the file-local names.
13221323
DebuggerClient *const DebugClient;
13231324
const Options options;
13241325
const bool isOriginallyTypeLookup;
@@ -1412,8 +1413,10 @@ namespace {
14121413
baseNLOptions |= NL_IgnoreAccessControl;
14131414
return baseNLOptions;
14141415
}
1415-
1416-
bool shouldReturnBasedOnResults(bool noMoreOuterResults = false) {
1416+
1417+
/// Return true if done with lookup.
1418+
bool isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1419+
bool noMoreOuterResults = false) {
14171420
if (Results.empty())
14181421
return false;
14191422

@@ -1467,7 +1470,7 @@ namespace {
14671470
}
14681471

14691472
// If we found anything, we're done.
1470-
if (shouldReturnBasedOnResults())
1473+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
14711474
return std::make_pair(ScopeLookupResult::finished, selfDC);
14721475

14731476
// When we are in the body of a method, get the 'self' declaration.
@@ -1583,8 +1586,8 @@ namespace {
15831586
} else {
15841587
if (DebugClient)
15851588
filterForDiscriminator(Results, DebugClient);
1586-
1587-
if (shouldReturnBasedOnResults())
1589+
1590+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
15881591
return std::make_pair(ScopeLookupResult::finished, selfDC);
15891592
}
15901593
}
@@ -1628,7 +1631,7 @@ namespace {
16281631
if (auto *selfParam = PBI->getImplicitSelfDecl()) {
16291632
Consumer.foundDecl(selfParam,
16301633
DeclVisibilityKind::FunctionParameter);
1631-
if (shouldReturnBasedOnResults())
1634+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
16321635
return true;
16331636

16341637
DC = DC->getParent();
@@ -1667,13 +1670,13 @@ namespace {
16671670

16681671
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
16691672
localVal.visit(AFD->getBody());
1670-
if (shouldReturnBasedOnResults())
1673+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
16711674
return true;
16721675

16731676
if (auto *P = AFD->getImplicitSelfDecl())
16741677
localVal.checkValueDecl(P, DeclVisibilityKind::FunctionParameter);
16751678
localVal.checkParameterList(AFD->getParameters());
1676-
if (shouldReturnBasedOnResults())
1679+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
16771680
return true;
16781681
}
16791682
if (!isCascadingUse.hasValue() || isCascadingUse.getValue())
@@ -1708,11 +1711,11 @@ namespace {
17081711
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
17091712
if (auto body = CE->getBody())
17101713
localVal.visit(body);
1711-
if (shouldReturnBasedOnResults())
1714+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
17121715
return true;
17131716
if (auto params = CE->getParameters())
17141717
localVal.checkParameterList(params);
1715-
if (shouldReturnBasedOnResults())
1718+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
17161719
return true;
17171720
}
17181721
}
@@ -1752,8 +1755,8 @@ namespace {
17521755
if (GenericParams) {
17531756
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
17541757
localVal.checkGenericParams(GenericParams);
1755-
1756-
if (shouldReturnBasedOnResults())
1758+
1759+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
17571760
return true;
17581761
}
17591762

@@ -1769,8 +1772,8 @@ namespace {
17691772
while (dcGenericParams) {
17701773
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
17711774
localVal.checkGenericParams(dcGenericParams);
1772-
1773-
if (shouldReturnBasedOnResults())
1775+
1776+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
17741777
return true;
17751778

17761779
dcGenericParams = dcGenericParams->getOuterParameters();
@@ -1818,8 +1821,8 @@ namespace {
18181821
} else {
18191822
if (DebugClient)
18201823
filterForDiscriminator(Results, DebugClient);
1821-
1822-
if (shouldReturnBasedOnResults())
1824+
1825+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
18231826
return true;
18241827
}
18251828
}
@@ -1842,7 +1845,7 @@ namespace {
18421845
// local types.
18431846
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
18441847
localVal.checkSourceFile(*SF);
1845-
if (shouldReturnBasedOnResults())
1848+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults())
18461849
return true;
18471850
}
18481851
}
@@ -1882,14 +1885,16 @@ namespace {
18821885
isOriginallyTypeLookup, Results);
18831886

18841887
// If we've found something, we're done.
1885-
if (shouldReturnBasedOnResults(/*noMoreOuterResults=*/true))
1888+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1889+
/*noMoreOuterResults=*/true))
18861890
return;
18871891

18881892
// If we still haven't found anything, but we do have some
18891893
// declarations that are "unavailable in the current Swift", drop
18901894
// those in.
18911895
Results = std::move(UnavailableInnerResults);
1892-
if (shouldReturnBasedOnResults(/*noMoreOuterResults=*/true))
1896+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1897+
/*noMoreOuterResults=*/true))
18931898
return;
18941899

18951900
if (!Name.isSimpleName())
@@ -1898,7 +1903,8 @@ namespace {
18981903
// Look for a module with the given name.
18991904
if (Name.isSimpleName(M.getName())) {
19001905
Results.push_back(LookupResultEntry(&M));
1901-
if (shouldReturnBasedOnResults(/*noMoreOuterResults=*/true))
1906+
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1907+
/*noMoreOuterResults=*/true))
19021908
return;
19031909
}
19041910

@@ -1915,7 +1921,8 @@ namespace {
19151921
});
19161922
}
19171923
// Make sure we've recorded the inner-result-boundary.
1918-
(void)shouldReturnBasedOnResults(/*noMoreOuterResults=*/true);
1924+
(void)isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1925+
/*noMoreOuterResults=*/true);
19191926
}
19201927
};
19211928
} // end anon namespace

0 commit comments

Comments
 (0)