Skip to content

Commit ac246f8

Browse files
committed
---
yaml --- r: 274287 b: refs/heads/master-next c: 977b0db h: refs/heads/master i: 274285: c9f095c 274283: ef46a0e 274279: 38fbdfa 274271: 9228d9d
1 parent f3496b6 commit ac246f8

File tree

3 files changed

+66
-64
lines changed

3 files changed

+66
-64
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: cbef630f19f869ab5279731179bd731f12b3b9d5
3-
refs/heads/master-next: 3c295f8228d90eeeaa16f68c07eb93a4ea53d0b4
3+
refs/heads/master-next: 977b0db93df8cdda1b9a1743acae671c94d5f659
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/AST/NameLookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
228228
enum class ScopeLookupResult { next, stop, finished };
229229
struct PerScopeLookupState {
230230
ScopeLookupResult result;
231-
DeclContext *nextDC; // TODO: rename to child of nextDC
231+
DeclContext *childOfNextDC;
232232
Optional<PlacesToSearch> placesToSearch;
233233
Optional<bool> isCascadingUse;
234234

branches/master-next/lib/AST/NameLookup.cpp

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,9 +1392,9 @@ namespace {
13921392
}
13931393
// Never perform local lookup for operators.
13941394
else if (Name.isOperator()) {
1395-
if (operatorLookup())
1395+
if (!(DC = operatorLookup(DC)))
13961396
return;
1397-
} else if (nonASTScopeBasedLookup())
1397+
} else if (!(DC = nonASTScopeBasedLookup(DC)))
13981398
return;
13991399

14001400
// TODO: Does the debugger client care about compound names?
@@ -1636,77 +1636,78 @@ namespace {
16361636
}
16371637
}
16381638

1639-
bool operatorLookup() {
1640-
updateIsCascadingForOperator(DC);
1641-
DC = DC->getModuleScopeContext();
1642-
return addLocalVariableResults();
1639+
// return nullptr if lookup done
1640+
DeclContext * operatorLookup(DeclContext *dc) {
1641+
updateIsCascadingForOperator(dc);
1642+
auto *msc = dc->getModuleScopeContext();
1643+
return addLocalVariableResults(msc) ? nullptr : msc;
16431644
}
16441645

1645-
/// Return true if done looking up.
1646-
bool nonASTScopeBasedLookup() {
1646+
/// Return nullptr if done looking up.
1647+
DeclContext *nonASTScopeBasedLookup(DeclContext *const dc) {
16471648
// If we are inside of a method, check to see if there are any ivars in
16481649
// scope, and if so, whether this is a reference to one of them.
16491650
// FIXME: We should persist this information between lookups.
1650-
while (!DC->isModuleScopeContext()) {
1651-
auto resultAndDC = lookupInOneDeclContext(DC);
1652-
DeclContext *oldDC = DC; // CLEAN UP
1653-
DC = resultAndDC.second;
1654-
switch (resultAndDC.first) {
1655-
case ScopeLookupResult::next:
1656-
assert(DC != oldDC && "non-termination");
1657-
continue;
1658-
case ScopeLookupResult::stop:
1651+
DeclContext *nextDC = dc;
1652+
while (!nextDC->isModuleScopeContext()) {
1653+
auto resultAndDC = lookupInOneDeclContext(nextDC);
1654+
DeclContext *oldDC = nextDC; // CLEAN UP
1655+
nextDC = resultAndDC.second;
1656+
switch (resultAndDC.first) {
1657+
case ScopeLookupResult::next:
1658+
assert(nextDC != oldDC && "non-termination");
1659+
continue;
1660+
case ScopeLookupResult::stop:
1661+
break;
1662+
case ScopeLookupResult::finished:
1663+
return nullptr;
1664+
}
16591665
break;
1660-
case ScopeLookupResult::finished:
1661-
return true;
16621666
}
1663-
break;
1667+
1668+
if (!isCascadingUse.hasValue())
1669+
isCascadingUse = true;
1670+
1671+
return addLocalVariableResults(nextDC) ? nullptr : nextDC;
16641672
}
16651673

1666-
if (!isCascadingUse.hasValue())
1667-
isCascadingUse = true;
1668-
1669-
return addLocalVariableResults();
1670-
}
1671-
16721674
/// Return the next context to search.
16731675
std::pair<ScopeLookupResult, DeclContext *>
1674-
lookupInOneDeclContext(DeclContext *DC) {
1676+
lookupInOneDeclContext(DeclContext *dc) {
16751677
PerScopeLookupState results =
1676-
lookupInAppropriateContext(DC, isCascadingUse);
1678+
lookupInAppropriateContext(dc, isCascadingUse);
16771679
breadcrumbs.push_back(results);
16781680

1679-
DC = results.nextDC;
16801681
isCascadingUse = results.isCascadingUse;
16811682
switch (results.result) {
16821683
case ScopeLookupResult::next:
16831684
break;
16841685
case ScopeLookupResult::stop:
1685-
return std::make_pair(ScopeLookupResult::next, results.nextDC);
1686+
return std::make_pair(ScopeLookupResult::next, results.childOfNextDC);
16861687
case ScopeLookupResult::finished:
1687-
return std::make_pair(ScopeLookupResult::finished, results.nextDC);
1688+
return std::make_pair(ScopeLookupResult::finished, results.childOfNextDC);
16881689
}
1689-
if (addGenericParametersHereAndInEnclosingScopes(DC))
1690-
return std::make_pair(ScopeLookupResult::finished, DC);
1690+
if (addGenericParametersHereAndInEnclosingScopes(results.childOfNextDC))
1691+
return std::make_pair(ScopeLookupResult::finished, results.childOfNextDC);
16911692

16921693
if (results.placesToSearch.hasValue() &&
16931694
!results.placesToSearch.getValue().empty()) {
16941695
auto startIndexOfInnerResults = Results.size();
16951696
searchPlacesToSearch(std::move(results.placesToSearch.getValue()), Name,
1696-
isCascadingUse.getValue(), baseNLOptions, DC);
1697+
isCascadingUse.getValue(), baseNLOptions, results.childOfNextDC);
16971698
if (handleUnavailableInnerResults(startIndexOfInnerResults))
1698-
return std::make_pair(ScopeLookupResult::finished, DC);
1699+
return std::make_pair(ScopeLookupResult::finished, results.childOfNextDC);
16991700
}
17001701
// TODO: What if !BaseDC && lookupDecls non-empty?
1701-
DC = DC->getParentForLookup();
1702-
return std::make_pair(ScopeLookupResult::next, DC);
1702+
DeclContext *nextDC = results.childOfNextDC->getParentForLookup();
1703+
return std::make_pair(ScopeLookupResult::next, nextDC);
17031704
}
17041705

17051706
/// Check the generic parameters of our context.
17061707
/// Return true if done with lookup
17071708
/// TODO: Factor with addGenericParmeters below
1708-
bool addGenericParametersHereAndInEnclosingScopes(DeclContext *DC) {
1709-
for (GenericParamList *dcGenericParams = getGenericParams(DC);
1709+
bool addGenericParametersHereAndInEnclosingScopes(DeclContext *dc) {
1710+
for (GenericParamList *dcGenericParams = getGenericParams(dc);
17101711
dcGenericParams;
17111712
dcGenericParams = dcGenericParams->getOuterParameters()) {
17121713
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
@@ -1730,32 +1731,32 @@ namespace {
17301731
}
17311732
}
17321733

1733-
static GenericParamList *getGenericParams(const DeclContext *const DC) {
1734-
if (auto nominal = dyn_cast<NominalTypeDecl>(DC))
1734+
static GenericParamList *getGenericParams(const DeclContext *const dc) {
1735+
if (auto nominal = dyn_cast<NominalTypeDecl>(dc))
17351736
return nominal->getGenericParams();
1736-
if (auto ext = dyn_cast<ExtensionDecl>(DC))
1737+
if (auto ext = dyn_cast<ExtensionDecl>(dc))
17371738
return ext->getGenericParams();
1738-
if (auto subscript = dyn_cast<SubscriptDecl>(DC))
1739+
if (auto subscript = dyn_cast<SubscriptDecl>(dc))
17391740
return subscript->getGenericParams();
17401741
return nullptr;
17411742
}
17421743

17431744
PerScopeLookupState
1744-
lookupInAppropriateContext(DeclContext *DC, Optional<bool> isCascadingUse) {
1745-
if (auto *PBI = dyn_cast<PatternBindingInitializer>(DC))
1745+
lookupInAppropriateContext(DeclContext *dc, Optional<bool> isCascadingUse) {
1746+
if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
17461747
return lookupInPatternBindingInitializer(PBI, isCascadingUse);
1747-
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC))
1748+
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(dc))
17481749
return lookupInFunctionDecl(AFD, isCascadingUse);
1749-
if (auto *ACE = dyn_cast<AbstractClosureExpr>(DC))
1750+
if (auto *ACE = dyn_cast<AbstractClosureExpr>(dc))
17501751
return lookupInClosure(ACE, isCascadingUse);
1751-
if (auto *ED = dyn_cast<ExtensionDecl>(DC))
1752+
if (auto *ED = dyn_cast<ExtensionDecl>(dc))
17521753
return lookupInExtension(ED, isCascadingUse);
1753-
if (auto *ND = dyn_cast<NominalTypeDecl>(DC))
1754+
if (auto *ND = dyn_cast<NominalTypeDecl>(dc))
17541755
return lookupInNominalType(ND, isCascadingUse);
1755-
if (auto I = dyn_cast<DefaultArgumentInitializer>(DC))
1756+
if (auto I = dyn_cast<DefaultArgumentInitializer>(dc))
17561757
return lookupInDefaultArgumentInitializer(I, isCascadingUse);
17571758

1758-
return lookupInMiscContext(DC, isCascadingUse);
1759+
return lookupInMiscContext(dc, isCascadingUse);
17591760
}
17601761

17611762
PerScopeLookupState
@@ -1782,7 +1783,7 @@ namespace {
17821783
PlacesToSearch(parent, PBI, parent, parent),
17831784
isCascadingUse.hasValue()
17841785
? isCascadingUse.getValue()
1785-
: DC->isCascadingContextForLookup(false)};
1786+
: PBI->isCascadingContextForLookup(false)};
17861787
}
17871788
// Initializers for stored properties of types perform static
17881789
// lookup into the surrounding context.
@@ -1889,7 +1890,7 @@ namespace {
18891890
}
18901891
}
18911892
}
1892-
return PerScopeLookupState{ScopeLookupResult::next, DC, None,
1893+
return PerScopeLookupState{ScopeLookupResult::next, ACE, None,
18931894
isCascadingUse.hasValue()
18941895
? isCascadingUse.getValue()
18951896
: ACE->isCascadingContextForLookup(false)};
@@ -1932,18 +1933,19 @@ namespace {
19321933
!SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc);
19331934
}
19341935

1935-
PerScopeLookupState lookupInMiscContext(DeclContext *DC,
1936+
PerScopeLookupState lookupInMiscContext(DeclContext *dc,
19361937
Optional<bool> isCascadingUse) {
1937-
assert(isa<TopLevelCodeDecl>(DC) || isa<Initializer>(DC) ||
1938-
isa<TypeAliasDecl>(DC) || isa<SubscriptDecl>(DC));
1939-
return PerScopeLookupState{ScopeLookupResult::next, DC, None,
1938+
assert(isa<TopLevelCodeDecl>(dc) || isa<Initializer>(dc) ||
1939+
isa<TypeAliasDecl>(dc) || isa<SubscriptDecl>(dc));
1940+
return PerScopeLookupState{ScopeLookupResult::next, dc, None,
19401941
isCascadingUse.hasValue()
19411942
? isCascadingUse.getValue()
1942-
: DC->isCascadingContextForLookup(false)};
1943+
: dc->isCascadingContextForLookup(false)};
19431944
}
19441945

1945-
bool addLocalVariableResults() {
1946-
if (auto SF = dyn_cast<SourceFile>(DC)) {
1946+
/// return true if lookup is done
1947+
bool addLocalVariableResults(DeclContext *dc) {
1948+
if (auto SF = dyn_cast<SourceFile>(dc)) {
19471949
if (Loc.isValid()) {
19481950
// Look for local variables in top-level code; normally, the parser
19491951
// resolves these for us, but it can't do the right thing for
@@ -1968,7 +1970,7 @@ namespace {
19681970
: NL_KnownNonCascadingDependency);
19691971

19701972
SmallVector<ValueDecl *, 4> Lookup;
1971-
DC->lookupQualified(placesToSearch.places, Name, options, Lookup);
1973+
contextForLookup->lookupQualified(placesToSearch.places, Name, options, Lookup);
19721974
for (auto Result : Lookup)
19731975
Results.push_back(LookupResultEntry(
19741976
placesToSearch.whereValueIsMember(Result), Result));
@@ -2138,7 +2140,7 @@ void ExpUnqualifiedLookup::PerScopeLookupState::dump() const {
21382140
break;
21392141
}
21402142
e << " dc: ";
2141-
nextDC->dumpContext();
2143+
childOfNextDC->dumpContext();
21422144
if (placesToSearch.hasValue())
21432145
placesToSearch.getValue().dump();
21442146
}

0 commit comments

Comments
 (0)