Skip to content

Commit da50a4c

Browse files
committed
---
yaml --- r: 278439 b: refs/heads/swift-5.1-old-llvm-branch c: ef9f99e h: refs/heads/master i: 278437: c5d9947 278435: a86fea0 278431: f6b73dc
1 parent 1733345 commit da50a4c

File tree

3 files changed

+77
-98
lines changed

3 files changed

+77
-98
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: 65f8f73992bd60f12a1a2b429045b3a9031e8fe7
1244+
refs/heads/swift-5.1-old-llvm-branch: ef9f99e37c69206017d2b56b024a90baa1b765bf
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/include/swift/AST/NameLookup.h

Lines changed: 52 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ struct LookupResultEntry {
8484
ValueDecl *getBaseDecl() const;
8585
};
8686

87+
class LegacyUnqualifiedLookup; // for verifyEqual below
88+
8789
/// This class implements and represents the result of performing
8890
/// unqualified lookup (i.e. lookup for a plain identifier).
8991
class UnqualifiedLookup {
@@ -108,9 +110,6 @@ class UnqualifiedLookup {
108110
///
109111
/// If the current DeclContext is nested in a function body, the SourceLoc
110112
/// is used to determine which declarations in that body are visible.
111-
UnqualifiedLookup(const char *dummy, DeclName Name, DeclContext *DC,
112-
LazyResolver *TypeResolver, SourceLoc Loc = SourceLoc(),
113-
Options options = Options());
114113
UnqualifiedLookup(DeclName Name, DeclContext *DC, LazyResolver *TypeResolver,
115114
SourceLoc Loc = SourceLoc(), Options options = Options());
116115

@@ -121,6 +120,10 @@ class UnqualifiedLookup {
121120
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
122121
/// will be Results from the innermost scope that had results, and the
123122
/// remaining elements of Results will be from parent scopes of this one.
123+
///
124+
/// Allows unqualified name lookup to return results from outer scopes.
125+
/// This is necessary for disambiguating calls to functions like `min` and
126+
/// `max`.
124127
size_t IndexOfFirstOuterResult;
125128

126129
/// Return true if anything was found by the name lookup.
@@ -129,69 +132,7 @@ class UnqualifiedLookup {
129132
/// Get the result as a single type, or a null type if that fails.
130133
TypeDecl *getSingleTypeResult();
131134

132-
public: // for exp debugging
133-
SourceFile const *recordedSF = nullptr;
134-
DeclName recordedName;
135-
bool recordedIsCascadingUse = false;
136-
};
137-
138-
inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
139-
UnqualifiedLookup::Flags flag2) {
140-
return UnqualifiedLookup::Options(flag1) | flag2;
141-
}
142-
143-
/// This class implements and represents the result of performing
144-
/// unqualified lookup (i.e. lookup for a plain identifier).
145-
class ExpUnqualifiedLookup {
146-
public:
147-
using Flags = UnqualifiedLookup::Flags;
148-
149-
using Options = UnqualifiedLookup::Options;
150-
151-
/// Lookup an unqualified identifier \p Name in the context.
152-
///
153-
/// If the current DeclContext is nested in a function body, the SourceLoc
154-
/// is used to determine which declarations in that body are visible.
155-
ExpUnqualifiedLookup(DeclName Name, DeclContext *DC,
156-
LazyResolver *TypeResolver, SourceLoc Loc = SourceLoc(),
157-
Options options = Options());
158-
159-
SmallVector<LookupResultEntry, 4> Results;
160-
/// The index of the first result that isn't from the innermost scope
161-
/// with results.
162-
///
163-
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
164-
/// will be Results from the innermost scope that had results, and the
165-
/// remaining elements of Results will be from parent scopes of this one.
166-
///
167-
/// Allows unqualified name lookup to return results from outer scopes.
168-
/// This is necessary for disambiguating calls to functions like `min` and
169-
/// `max`.
170-
size_t IndexOfFirstOuterResult;
171-
172-
/// Return true if anything was found by the name lookup.
173-
bool isSuccess() const { return !Results.empty(); }
174-
175-
/// Get the result as a single type, or a null type if that fails.
176-
TypeDecl *getSingleTypeResult();
177-
178-
bool operator==(const UnqualifiedLookup &other) const {
179-
if (Results.size() != other.Results.size())
180-
return false;
181-
for (size_t i: indices(Results)) {
182-
const auto &e = Results[i];
183-
const auto &oe = other.Results[i];
184-
if (e.getValueDecl() != oe.getValueDecl())
185-
return false;
186-
if (e.getDeclContext() != oe.getDeclContext())
187-
return false;
188-
if (e.getBaseDecl() != oe.getBaseDecl())
189-
return false;
190-
}
191-
return IndexOfFirstOuterResult == other.IndexOfFirstOuterResult;
192-
}
193-
194-
bool verifyEqual(const UnqualifiedLookup &) const;
135+
bool verifyEqual(const LegacyUnqualifiedLookup &&) const;
195136

196137
public: // for exp debugging
197138
SourceFile const *recordedSF = nullptr;
@@ -235,7 +176,51 @@ inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
235176
};
236177
std::vector<PerScopeLookupState> breadcrumbs;
237178
void dumpBreadcrumbs() const;
238-
};
179+
};
180+
181+
inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
182+
UnqualifiedLookup::Flags flag2) {
183+
return UnqualifiedLookup::Options(flag1) | flag2;
184+
}
185+
186+
/// This class implements and represents the result of performing
187+
/// unqualified lookup (i.e. lookup for a plain identifier).
188+
/// It is being kept around in order to check the refactoring against the new
189+
/// UnqualifiedLookup above.
190+
class LegacyUnqualifiedLookup {
191+
public:
192+
using Flags = UnqualifiedLookup::Flags;
193+
using Options = UnqualifiedLookup::Options;
194+
195+
/// Lookup an unqualified identifier \p Name in the context.
196+
///
197+
/// If the current DeclContext is nested in a function body, the SourceLoc
198+
/// is used to determine which declarations in that body are visible.
199+
LegacyUnqualifiedLookup(DeclName Name, DeclContext *DC,
200+
LazyResolver *TypeResolver,
201+
SourceLoc Loc = SourceLoc(),
202+
Options options = Options());
203+
204+
SmallVector<LookupResultEntry, 4> Results;
205+
/// The index of the first result that isn't from the innermost scope
206+
/// with results.
207+
///
208+
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
209+
/// will be Results from the innermost scope that had results, and the
210+
/// remaining elements of Results will be from parent scopes of this one.
211+
size_t IndexOfFirstOuterResult;
212+
213+
/// Return true if anything was found by the name lookup.
214+
bool isSuccess() const { return !Results.empty(); }
215+
216+
/// Get the result as a single type, or a null type if that fails.
217+
TypeDecl *getSingleTypeResult();
218+
219+
public: // for exp debugging
220+
SourceFile const *recordedSF = nullptr;
221+
DeclName recordedName;
222+
bool recordedIsCascadingUse = false;
223+
};
239224

240225
/// Describes the reason why a certain declaration is visible.
241226
enum class DeclVisibilityKind {

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

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ SelfBounds swift::getSelfBoundsFromWhereClause(
694694
SelfBoundsFromWhereClauseRequest{decl}, {});
695695
}
696696

697-
// TODO: change name when ExpUnqualifiedLookup is adopted to
697+
// TODO: change name when UnqualifiedLookup is adopted to
698698
// populatePlacesToSearchFromContext
699699
static void
700700
populateLookupDeclsFromContext(DeclContext *dc,
@@ -787,19 +787,9 @@ bool shouldLookupMembers(D *decl, SourceLoc loc) {
787787
}
788788
} // end anonymous namespace
789789

790-
UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
791-
LazyResolver *TypeResolver, SourceLoc Loc,
792-
Options options)
793-
: UnqualifiedLookup("dummy", Name, DC, TypeResolver, Loc, options) {
794-
assert(ExpUnqualifiedLookup(Name, DC, TypeResolver, Loc, options)
795-
.verifyEqual(*this) &&
796-
"bad refactoring");
797-
}
798-
799-
UnqualifiedLookup::UnqualifiedLookup(const char *dummy, DeclName Name,
800-
DeclContext *DC,
801-
LazyResolver *TypeResolver, SourceLoc Loc,
802-
Options options)
790+
LegacyUnqualifiedLookup::LegacyUnqualifiedLookup(DeclName Name, DeclContext *DC,
791+
LazyResolver *TypeResolver,
792+
SourceLoc Loc, Options options)
803793
: IndexOfFirstOuterResult(0) {
804794
ModuleDecl &M = *DC->getParentModule();
805795
ASTContext &Ctx = M.getASTContext();
@@ -1306,21 +1296,21 @@ UnqualifiedLookup::UnqualifiedLookup(const char *dummy, DeclName Name,
13061296
(void)shouldReturnBasedOnResults(/*noMoreOuterResults=*/true);
13071297
}
13081298

1309-
TypeDecl* UnqualifiedLookup::getSingleTypeResult() {
1299+
TypeDecl *LegacyUnqualifiedLookup::getSingleTypeResult() {
13101300
if (Results.size() != 1)
13111301
return nullptr;
13121302
return dyn_cast<TypeDecl>(Results.back().getValueDecl());
13131303
}
13141304

1315-
ExpUnqualifiedLookup::PlacesToSearch::PlacesToSearch(
1305+
UnqualifiedLookup::PlacesToSearch::PlacesToSearch(
13161306
DeclContext *fromWhence, DeclContext *whereNonTypesAreMembers,
13171307
DeclContext *whereTypesAreMembers, DeclContext *placesHolder)
13181308
: fromWhence(fromWhence), whereNonTypesAreMembers(whereNonTypesAreMembers),
13191309
whereTypesAreMembers(whereTypesAreMembers) {
13201310
populateLookupDeclsFromContext(placesHolder, places);
13211311
}
13221312

1323-
void ExpUnqualifiedLookup::PlacesToSearch::dump() const {
1313+
void UnqualifiedLookup::PlacesToSearch::dump() const {
13241314
llvm::errs() << "fromWhence: ";
13251315
fromWhence->dumpContext();
13261316
llvm::errs() << "whereNonTypesAreMembers: ";
@@ -1336,10 +1326,10 @@ void ExpUnqualifiedLookup::PlacesToSearch::dump() const {
13361326
namespace {
13371327
class UnqualifiedLookupFactory {
13381328
public:
1339-
using Flags = UnqualifiedLookup::Flags;
1340-
using Options = UnqualifiedLookup::Options;
1341-
using PlacesToSearch = ExpUnqualifiedLookup::PlacesToSearch;
1342-
using PerScopeLookupState = ExpUnqualifiedLookup::PerScopeLookupState;
1329+
using Flags = LegacyUnqualifiedLookup::Flags;
1330+
using Options = LegacyUnqualifiedLookup::Options;
1331+
using PlacesToSearch = UnqualifiedLookup::PlacesToSearch;
1332+
using PerScopeLookupState = UnqualifiedLookup::PerScopeLookupState;
13431333

13441334
private:
13451335
// Inputs
@@ -1377,7 +1367,7 @@ namespace {
13771367
LazyResolver *TypeResolver,
13781368
SourceLoc Loc,
13791369
Options options,
1380-
ExpUnqualifiedLookup &lookupToBeCreated);
1370+
UnqualifiedLookup &lookupToBeCreated);
13811371
// clang-format on
13821372

13831373
void fillInLookup();
@@ -1388,7 +1378,7 @@ namespace {
13881378
astScopeBasedLookup(DeclContext *dc, Optional<bool> isCascadingUse);
13891379

13901380
static NLOptions
1391-
computeBaseNLOptions(const UnqualifiedLookup::Options options,
1381+
computeBaseNLOptions(const LegacyUnqualifiedLookup::Options options,
13921382
const bool isOriginallyTypeLookup);
13931383

13941384
/// Return true if done with lookup.
@@ -1519,10 +1509,10 @@ namespace {
15191509
};
15201510
} // namespace
15211511

1522-
#pragma mark ExpUnqualifiedLookup functions
1512+
#pragma mark UnqualifiedLookup functions
15231513

15241514
// clang-format off
1525-
ExpUnqualifiedLookup::ExpUnqualifiedLookup(DeclName Name,
1515+
UnqualifiedLookup::UnqualifiedLookup(DeclName Name,
15261516
DeclContext *const DC,
15271517
LazyResolver *TypeResolver,
15281518
SourceLoc Loc,
@@ -1531,15 +1521,19 @@ ExpUnqualifiedLookup::ExpUnqualifiedLookup(DeclName Name,
15311521
: IndexOfFirstOuterResult(0) {
15321522
UnqualifiedLookupFactory(Name, DC, TypeResolver, Loc, options, *this)
15331523
.fillInLookup();
1524+
assert(verifyEqual(
1525+
LegacyUnqualifiedLookup(Name, DC, TypeResolver, Loc, options)) &&
1526+
"bad refactoring");
15341527
}
15351528

1536-
TypeDecl* ExpUnqualifiedLookup::getSingleTypeResult() {
1529+
TypeDecl *UnqualifiedLookup::getSingleTypeResult() {
15371530
if (Results.size() != 1)
15381531
return nullptr;
15391532
return dyn_cast<TypeDecl>(Results.back().getValueDecl());
15401533
}
15411534

1542-
bool ExpUnqualifiedLookup::verifyEqual(const UnqualifiedLookup &other) const {
1535+
bool UnqualifiedLookup::verifyEqual(
1536+
const LegacyUnqualifiedLookup &&other) const {
15431537
assert(Results.size() == other.Results.size());
15441538
for (size_t i: indices(Results)) {
15451539
const auto &e = Results[i];
@@ -1560,7 +1554,7 @@ bool ExpUnqualifiedLookup::verifyEqual(const UnqualifiedLookup &other) const {
15601554
return true;
15611555
}
15621556

1563-
void ExpUnqualifiedLookup::dumpBreadcrumbs() const {
1557+
void UnqualifiedLookup::dumpBreadcrumbs() const {
15641558
auto &e = llvm::errs();
15651559
for (size_t i : indices(breadcrumbs)) {
15661560
e << i << "\n";
@@ -1569,7 +1563,7 @@ void ExpUnqualifiedLookup::dumpBreadcrumbs() const {
15691563
}
15701564
}
15711565

1572-
void ExpUnqualifiedLookup::PerScopeLookupState::dump() const {
1566+
void UnqualifiedLookup::PerScopeLookupState::dump() const {
15731567
auto &e = llvm::errs();
15741568
e << (isDone ? "done: " : "not done: ");
15751569
e << " dc: ";
@@ -1587,7 +1581,7 @@ UnqualifiedLookupFactory::UnqualifiedLookupFactory(
15871581
LazyResolver *TypeResolver,
15881582
SourceLoc Loc,
15891583
Options options,
1590-
ExpUnqualifiedLookup &lookupToBeCreated)
1584+
UnqualifiedLookup &lookupToBeCreated)
15911585
:
15921586
Name(Name),
15931587
DC(DC),

0 commit comments

Comments
 (0)