@@ -1331,6 +1331,8 @@ namespace {
1331
1331
using PlacesToSearch = UnqualifiedLookup::PlacesToSearch;
1332
1332
using PerScopeLookupState = UnqualifiedLookup::PerScopeLookupState;
1333
1333
1334
+ enum class LookupFinished { Yes, No };
1335
+
1334
1336
private:
1335
1337
// Inputs
1336
1338
const DeclName Name;
@@ -1376,8 +1378,13 @@ namespace {
1376
1378
1377
1379
#pragma mark ASTScope-based-lookup declarations
1378
1380
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>
1381
1388
astScopeBasedLookup (DeclContext *dc, Optional<bool > isCascadingUse);
1382
1389
1383
1390
std::pair<const ASTScope *, bool >
@@ -1414,15 +1421,15 @@ namespace {
1414
1421
1415
1422
#pragma mark normal (non-ASTScope-based) lookup declarations
1416
1423
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);
1420
1427
1421
- // / Return nullptr if done looking up .
1422
- std::pair<DeclContext *, bool >
1428
+ // / Return None if lookup done .
1429
+ Optional<DCAndIsCascadingUse >
1423
1430
nonASTScopeBasedLookup (DeclContext *const dc,
1424
1431
const Optional<bool > isCascadingUseArg);
1425
-
1432
+
1426
1433
struct LookupInOneDeclContextResult {
1427
1434
bool isDone;
1428
1435
DeclContext* dc;
@@ -1597,36 +1604,38 @@ UnqualifiedLookupFactory::UnqualifiedLookupFactory(
1597
1604
// clang-format on
1598
1605
1599
1606
void UnqualifiedLookupFactory::fillInLookup () {
1600
- const Optional<bool > isCascadingUse =
1607
+ const Optional<bool > isCascadingUseInitial =
1601
1608
options.contains (Flags::KnownPrivate) ? Optional<bool >(false ) : None;
1602
1609
// Never perform local lookup for operators.
1603
- std::pair<DeclContext *, bool > dcAndIsCascadingUse =
1610
+ auto dcAndIsCascadingUse =
1604
1611
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);
1608
1616
1609
- if (!dcAndIsCascadingUse.first )
1617
+ if (!dcAndIsCascadingUse.hasValue () )
1610
1618
return ;
1611
1619
1620
+ DeclContext *const DC = dcAndIsCascadingUse.getValue ().DC ;
1621
+ const bool isCascadingUse = dcAndIsCascadingUse.getValue ().isCascadingUse ;
1622
+
1612
1623
// TODO: Does the debugger client care about compound names?
1613
1624
if (Name.isSimpleName () && DebugClient &&
1614
- DebugClient->lookupOverrides (Name.getBaseName (),
1615
- dcAndIsCascadingUse.first , Loc,
1625
+ DebugClient->lookupOverrides (Name.getBaseName (), DC, Loc,
1616
1626
isOriginallyTypeLookup, Results))
1617
1627
return ;
1618
1628
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))
1623
1632
return ;
1624
1633
// If we still haven't found anything, but we do have some
1625
1634
// declarations that are "unavailable in the current Swift", drop
1626
1635
// those in.
1627
1636
if (addUnavailableInnerResults ())
1628
1637
return ;
1629
- if (lookForAModuleWithTheGivenName (dcAndIsCascadingUse. first ))
1638
+ if (lookForAModuleWithTheGivenName (DC ))
1630
1639
return ;
1631
1640
// Make sure we've recorded the inner-result-boundary.
1632
1641
(void )isFinishedWithLookupNowThatIsAboutToLookForOuterResults (
@@ -1640,7 +1649,9 @@ bool UnqualifiedLookupFactory::shouldUseASTScopeLookup() const {
1640
1649
}
1641
1650
1642
1651
#pragma mark ASTScope-based-lookup definitions
1643
- std::pair<DeclContext *, bool >
1652
+
1653
+ // / Return None if lookup done
1654
+ Optional<UnqualifiedLookupFactory::DCAndIsCascadingUse>
1644
1655
UnqualifiedLookupFactory::astScopeBasedLookup (DeclContext *const startDC,
1645
1656
Optional<bool > isCascadingUse) {
1646
1657
const std::pair<const ASTScope *, Optional<bool >>
@@ -1657,13 +1668,13 @@ UnqualifiedLookupFactory::astScopeBasedLookup(DeclContext *const startDC,
1657
1668
auto r = lookInScopeForASTScopeLookup (currentScope, selfDC, dc,
1658
1669
currentIsCascadingUse);
1659
1670
if (!r.hasValue ())
1660
- return std::make_pair ( nullptr , false ) ;
1671
+ return None ;
1661
1672
const bool isDone = r.getValue ().isDone ;
1662
1673
selfDC = r.getValue ().selfDC ;
1663
1674
dc = r.getValue ().dc ;
1664
1675
currentIsCascadingUse = r.getValue ().isCascadingUse ;
1665
1676
if (isDone)
1666
- return std::make_pair ( dc, currentIsCascadingUse.getValue ()) ;
1677
+ return DCAndIsCascadingUse{ dc, currentIsCascadingUse.getValue ()} ;
1667
1678
}
1668
1679
llvm_unreachable (" impossible" );
1669
1680
}
@@ -1854,18 +1865,18 @@ UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
1854
1865
1855
1866
#pragma mark normal (non-ASTScope-based) lookup declarations
1856
1867
1857
- std::pair<DeclContext *, bool >
1868
+ Optional<UnqualifiedLookupFactory::DCAndIsCascadingUse >
1858
1869
UnqualifiedLookupFactory::operatorLookup (DeclContext *dc,
1859
1870
Optional<bool > isCascadingUse) {
1860
1871
auto *msc = dc->getModuleScopeContext ();
1861
- return std::make_pair (
1872
+ return DCAndIsCascadingUse{
1862
1873
addLocalVariableResults (msc) ? nullptr : msc,
1863
1874
resolveIsCascadingUse (dc, isCascadingUse,
1864
- /* onlyCareAboutFunctionBody*/ true )) ;
1875
+ /* onlyCareAboutFunctionBody*/ true )} ;
1865
1876
}
1866
1877
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 (
1869
1880
DeclContext *const dc, const Optional<bool > isCascadingUseArg) {
1870
1881
// If we are inside of a method, check to see if there are any ivars in
1871
1882
// scope, and if so, whether this is a reference to one of them.
@@ -1877,7 +1888,7 @@ std::pair<DeclContext *, bool> UnqualifiedLookupFactory::nonASTScopeBasedLookup(
1877
1888
auto r =
1878
1889
lookupInOneDeclContext (nextDC, isCascadingUse);
1879
1890
if (!r.hasValue ())
1880
- return std::make_pair ( nullptr , false ) ;
1891
+ return None ;
1881
1892
const bool isDone = r.getValue ().isDone ;
1882
1893
nextDC = r.getValue ().dc ;
1883
1894
isCascadingUse = r.getValue ().isCascadingUse ;
@@ -1886,9 +1897,10 @@ std::pair<DeclContext *, bool> UnqualifiedLookupFactory::nonASTScopeBasedLookup(
1886
1897
assert (nextDC != priorDC && " non-termination" );
1887
1898
priorDC = nextDC;
1888
1899
}
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 };
1892
1904
}
1893
1905
1894
1906
// clang-format off
0 commit comments