Skip to content

Commit bcbc72d

Browse files
committed
---
yaml --- r: 278445 b: refs/heads/swift-5.1-old-llvm-branch c: 80a234a h: refs/heads/master i: 278443: f59f800
1 parent 7594fe1 commit bcbc72d

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-01-24-a: b6f62823aa5010b2ae53f15f72a57
12411241
refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e0
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
1244-
refs/heads/swift-5.1-old-llvm-branch: e9277469fbac794b031a5e5adad977ff144939df
1244+
refs/heads/swift-5.1-old-llvm-branch: 80a234a2ef2d41c7ba5dfbe1a508f20058e5c2fa
12451245
refs/heads/swift-5.1-branch: 8060872acb4105d9655e020fe047e1ebcd77d0fb
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e

branches/swift-5.1-old-llvm-branch/lib/AST/NameLookup.cpp

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,8 @@ namespace {
13311331
using PlacesToSearch = UnqualifiedLookup::PlacesToSearch;
13321332
using PerScopeLookupState = UnqualifiedLookup::PerScopeLookupState;
13331333

1334+
enum class LookupFinished { Yes, No };
1335+
13341336
private:
13351337
// Inputs
13361338
const DeclName Name;
@@ -1376,8 +1378,13 @@ namespace {
13761378

13771379
#pragma mark ASTScope-based-lookup declarations
13781380

1379-
/// Return nullptr if done with whole enchilada and isCascadingUse
1380-
std::pair<DeclContext *, bool>
1381+
// TODO: better name than DC
1382+
struct DCAndIsCascadingUse {
1383+
DeclContext *const DC;
1384+
const bool isCascadingUse;
1385+
};
1386+
1387+
Optional<DCAndIsCascadingUse>
13811388
astScopeBasedLookup(DeclContext *dc, Optional<bool> isCascadingUse);
13821389

13831390
std::pair<const ASTScope *, bool>
@@ -1414,15 +1421,15 @@ namespace {
14141421

14151422
#pragma mark normal (non-ASTScope-based) lookup declarations
14161423

1417-
/// Return nullptr if lookup done.
1418-
std::pair<DeclContext *, bool>
1419-
operatorLookup(DeclContext *dc, Optional<bool> isCascadingUse);
1424+
/// Return None if lookup done.
1425+
Optional<DCAndIsCascadingUse> operatorLookup(DeclContext *dc,
1426+
Optional<bool> isCascadingUse);
14201427

1421-
/// Return nullptr if done looking up.
1422-
std::pair<DeclContext *, bool>
1428+
/// Return None if lookup done.
1429+
Optional<DCAndIsCascadingUse>
14231430
nonASTScopeBasedLookup(DeclContext *const dc,
14241431
const Optional<bool> isCascadingUseArg);
1425-
1432+
14261433
struct LookupInOneDeclContextResult {
14271434
bool isDone;
14281435
DeclContext* dc;
@@ -1597,36 +1604,38 @@ UnqualifiedLookupFactory::UnqualifiedLookupFactory(
15971604
// clang-format on
15981605

15991606
void UnqualifiedLookupFactory::fillInLookup() {
1600-
const Optional<bool> isCascadingUse =
1607+
const Optional<bool> isCascadingUseInitial =
16011608
options.contains(Flags::KnownPrivate) ? Optional<bool>(false) : None;
16021609
// Never perform local lookup for operators.
1603-
std::pair<DeclContext *, bool> dcAndIsCascadingUse =
1610+
auto dcAndIsCascadingUse =
16041611
shouldUseASTScopeLookup()
1605-
? astScopeBasedLookup(DC, isCascadingUse)
1606-
: Name.isOperator() ? operatorLookup(DC, isCascadingUse)
1607-
: nonASTScopeBasedLookup(DC, isCascadingUse);
1612+
? astScopeBasedLookup(DC, isCascadingUseInitial)
1613+
: Name.isOperator()
1614+
? operatorLookup(DC, isCascadingUseInitial)
1615+
: nonASTScopeBasedLookup(DC, isCascadingUseInitial);
16081616

1609-
if (!dcAndIsCascadingUse.first)
1617+
if (!dcAndIsCascadingUse.hasValue())
16101618
return;
16111619

1620+
DeclContext *const DC = dcAndIsCascadingUse.getValue().DC;
1621+
const bool isCascadingUse = dcAndIsCascadingUse.getValue().isCascadingUse;
1622+
16121623
// TODO: Does the debugger client care about compound names?
16131624
if (Name.isSimpleName() && DebugClient &&
1614-
DebugClient->lookupOverrides(Name.getBaseName(),
1615-
dcAndIsCascadingUse.first, Loc,
1625+
DebugClient->lookupOverrides(Name.getBaseName(), DC, Loc,
16161626
isOriginallyTypeLookup, Results))
16171627
return;
16181628

1619-
recordDependencyOnTopLevelName(dcAndIsCascadingUse.first, Name,
1620-
dcAndIsCascadingUse.second);
1621-
addPrivateImports(dcAndIsCascadingUse.first);
1622-
if (addNamesKnownToDebugClient(dcAndIsCascadingUse.first))
1629+
recordDependencyOnTopLevelName(DC, Name, isCascadingUse);
1630+
addPrivateImports(DC);
1631+
if (addNamesKnownToDebugClient(DC))
16231632
return;
16241633
// If we still haven't found anything, but we do have some
16251634
// declarations that are "unavailable in the current Swift", drop
16261635
// those in.
16271636
if (addUnavailableInnerResults())
16281637
return;
1629-
if (lookForAModuleWithTheGivenName(dcAndIsCascadingUse.first))
1638+
if (lookForAModuleWithTheGivenName(DC))
16301639
return;
16311640
// Make sure we've recorded the inner-result-boundary.
16321641
(void)isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
@@ -1640,7 +1649,9 @@ bool UnqualifiedLookupFactory::shouldUseASTScopeLookup() const {
16401649
}
16411650

16421651
#pragma mark ASTScope-based-lookup definitions
1643-
std::pair<DeclContext *, bool>
1652+
1653+
/// Return None if lookup done
1654+
Optional<UnqualifiedLookupFactory::DCAndIsCascadingUse>
16441655
UnqualifiedLookupFactory::astScopeBasedLookup(DeclContext *const startDC,
16451656
Optional<bool> isCascadingUse) {
16461657
const std::pair<const ASTScope *, Optional<bool>>
@@ -1657,13 +1668,13 @@ UnqualifiedLookupFactory::astScopeBasedLookup(DeclContext *const startDC,
16571668
auto r = lookInScopeForASTScopeLookup(currentScope, selfDC, dc,
16581669
currentIsCascadingUse);
16591670
if (!r.hasValue())
1660-
return std::make_pair(nullptr, false);
1671+
return None;
16611672
const bool isDone = r.getValue().isDone;
16621673
selfDC = r.getValue().selfDC;
16631674
dc = r.getValue().dc;
16641675
currentIsCascadingUse = r.getValue().isCascadingUse;
16651676
if (isDone)
1666-
return std::make_pair(dc, currentIsCascadingUse.getValue());
1677+
return DCAndIsCascadingUse{dc, currentIsCascadingUse.getValue()};
16671678
}
16681679
llvm_unreachable("impossible");
16691680
}
@@ -1854,18 +1865,18 @@ UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
18541865

18551866
#pragma mark normal (non-ASTScope-based) lookup declarations
18561867

1857-
std::pair<DeclContext *, bool>
1868+
Optional<UnqualifiedLookupFactory::DCAndIsCascadingUse>
18581869
UnqualifiedLookupFactory::operatorLookup(DeclContext *dc,
18591870
Optional<bool> isCascadingUse) {
18601871
auto *msc = dc->getModuleScopeContext();
1861-
return std::make_pair(
1872+
return DCAndIsCascadingUse{
18621873
addLocalVariableResults(msc) ? nullptr : msc,
18631874
resolveIsCascadingUse(dc, isCascadingUse,
1864-
/*onlyCareAboutFunctionBody*/ true));
1875+
/*onlyCareAboutFunctionBody*/ true)};
18651876
}
18661877

1867-
// TODO: fix this convention w/ struct: Return nullptr if done looking up.
1868-
std::pair<DeclContext *, bool> UnqualifiedLookupFactory::nonASTScopeBasedLookup(
1878+
Optional<UnqualifiedLookupFactory::DCAndIsCascadingUse>
1879+
UnqualifiedLookupFactory::nonASTScopeBasedLookup(
18691880
DeclContext *const dc, const Optional<bool> isCascadingUseArg) {
18701881
// If we are inside of a method, check to see if there are any ivars in
18711882
// scope, and if so, whether this is a reference to one of them.
@@ -1877,7 +1888,7 @@ std::pair<DeclContext *, bool> UnqualifiedLookupFactory::nonASTScopeBasedLookup(
18771888
auto r =
18781889
lookupInOneDeclContext(nextDC, isCascadingUse);
18791890
if (!r.hasValue())
1880-
return std::make_pair(nullptr, false);
1891+
return None;
18811892
const bool isDone = r.getValue().isDone;
18821893
nextDC = r.getValue().dc;
18831894
isCascadingUse = r.getValue().isCascadingUse;
@@ -1886,9 +1897,10 @@ std::pair<DeclContext *, bool> UnqualifiedLookupFactory::nonASTScopeBasedLookup(
18861897
assert(nextDC != priorDC && "non-termination");
18871898
priorDC = nextDC;
18881899
}
1889-
return std::make_pair(addLocalVariableResults(nextDC) ? nullptr : nextDC,
1890-
isCascadingUse.hasValue() ? isCascadingUse.getValue()
1891-
: true);
1900+
if (addLocalVariableResults(nextDC))
1901+
return None;
1902+
return DCAndIsCascadingUse{
1903+
nextDC, isCascadingUse.hasValue() ? isCascadingUse.getValue() : true};
18921904
}
18931905

18941906
// clang-format off

0 commit comments

Comments
 (0)