Skip to content

Commit d45ab0b

Browse files
committed
Regularize nextDC, priorDC
1 parent 6635f39 commit d45ab0b

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ class UnqualifiedLookupFactory {
174174
void dump() const;
175175
};
176176

177-
struct PerScopeLookupState {
178-
bool isDone;
179-
DeclContext *childOfNextDC;
177+
struct PerDeclInfo {
178+
bool isDoneWithThisDecl;
179+
DeclContext *lookupContextForThisDecl;
180180
Optional<PlacesToSearch> placesToSearch;
181181
Optional<bool> isCascadingUse;
182182

@@ -204,7 +204,7 @@ class UnqualifiedLookupFactory {
204204
SmallVector<LookupResultEntry, 4> UnavailableInnerResults;
205205

206206
public: // for exp debugging
207-
std::vector<PerScopeLookupState> breadcrumbs;
207+
std::vector<PerDeclInfo> breadcrumbs;
208208
SourceFile const *recordedSF = nullptr;
209209
DeclName recordedName;
210210
bool recordedIsCascadingUse = false;
@@ -280,7 +280,7 @@ class UnqualifiedLookupFactory {
280280
const Optional<bool> isCascadingUseArg);
281281

282282
struct LookupInOneDeclContextResult {
283-
DeclContext *dc;
283+
DeclContext *completedDC;
284284
Optional<bool> isCascadingUse;
285285
};
286286

@@ -289,34 +289,33 @@ class UnqualifiedLookupFactory {
289289
lookupInOneDeclContext(DeclContext *dc,
290290
const Optional<bool> isCascadingUseArg);
291291

292-
Optional<PerScopeLookupState>
292+
Optional<PerDeclInfo>
293293
lookupInAppropriateContext(DeclContext *dc, Optional<bool> isCascadingUse);
294294

295295
// TODO: use objects & virtuals
296296

297-
Optional<PerScopeLookupState>
297+
Optional<PerDeclInfo>
298298
lookupInPatternBindingInitializer(PatternBindingInitializer *PBI,
299299
Optional<bool> isCascadingUse);
300300

301-
Optional<PerScopeLookupState>
302-
lookupInFunctionDecl(AbstractFunctionDecl *AFD,
303-
Optional<bool> isCascadingUse);
301+
Optional<PerDeclInfo> lookupInFunctionDecl(AbstractFunctionDecl *AFD,
302+
Optional<bool> isCascadingUse);
304303

305-
Optional<PerScopeLookupState> lookupInClosure(AbstractClosureExpr *ACE,
306-
Optional<bool> isCascadingUse);
304+
Optional<PerDeclInfo> lookupInClosure(AbstractClosureExpr *ACE,
305+
Optional<bool> isCascadingUse);
307306

308307
template <typename NominalTypeDeclOrExtensionDecl>
309-
Optional<PerScopeLookupState>
308+
Optional<PerDeclInfo>
310309
lookupInNominalTypeOrExtension(NominalTypeDeclOrExtensionDecl *D,
311310
Optional<bool> isCascadingUse) const;
312311

313-
Optional<PerScopeLookupState>
312+
Optional<PerDeclInfo>
314313
lookupInDefaultArgumentInitializer(DefaultArgumentInitializer *I,
315314
Optional<bool> isCascadingUse) const;
316315

317316
bool isOutsideBodyOfFunction(const AbstractFunctionDecl *const AFD) const;
318317

319-
Optional<PerScopeLookupState>
318+
Optional<PerDeclInfo>
320319
lookupInMiscContext(DeclContext *dc, Optional<bool> isCascadingUse) const;
321320

322321
/// Check the generic parameters of our context.
@@ -677,7 +676,7 @@ UnqualifiedLookupFactory::nonASTScopeBasedLookup(
677676
auto r = lookupInOneDeclContext(nextDC, isCascadingUse);
678677
if (!r.hasValue())
679678
return None;
680-
nextDC = r.getValue().dc;
679+
nextDC = r.getValue().completedDC->getParentForLookup();
681680
isCascadingUse = r.getValue().isCascadingUse;
682681
assert(nextDC != priorDC && "non-termination");
683682
priorDC = nextDC;
@@ -697,31 +696,33 @@ UnqualifiedLookupFactory::lookupInOneDeclContext(
697696
const auto r = lookupInAppropriateContext(dc, isCascadingUseArg);
698697
if (!r.hasValue())
699698
return None;
700-
const bool isDone = r.getValue().isDone;
699+
const bool isDoneWithThisDecl = r.getValue().isDoneWithThisDecl;
701700
breadcrumbs.push_back(r.getValue());
702-
auto childOfNextDC = r.getValue().childOfNextDC;
701+
auto lookupContextForThisDecl = r.getValue().lookupContextForThisDecl;
703702
auto placesToSearch = std::move(r.getValue().placesToSearch);
704703
auto isCascadingUse = r.getValue().isCascadingUse;
705704

706-
if (isDone)
707-
return LookupInOneDeclContextResult{childOfNextDC, isCascadingUse};
705+
if (isDoneWithThisDecl)
706+
return LookupInOneDeclContextResult{lookupContextForThisDecl,
707+
isCascadingUse};
708708

709-
if (addGenericParametersHereAndInEnclosingScopes(childOfNextDC))
709+
if (addGenericParametersHereAndInEnclosingScopes(lookupContextForThisDecl))
710710
return None;
711711
if (placesToSearch.hasValue() && !placesToSearch.getValue().empty()) {
712712
auto startIndexOfInnerResults = Results.size();
713-
placesToSearch.getValue().addToResults(
714-
Name, isCascadingUse.getValue(), baseNLOptions, childOfNextDC, Results);
713+
placesToSearch.getValue().addToResults(Name, isCascadingUse.getValue(),
714+
baseNLOptions,
715+
lookupContextForThisDecl, Results);
715716
if (handleUnavailableInnerResults(startIndexOfInnerResults))
716717
return None;
717718
}
718719
// TODO: What if !BaseDC && lookupDecls non-empty?
719-
DeclContext *nextDC = childOfNextDC->getParentForLookup();
720-
return LookupInOneDeclContextResult{nextDC, isCascadingUse};
720+
return LookupInOneDeclContextResult{lookupContextForThisDecl,
721+
isCascadingUse};
721722
}
722723
// clang-format on
723724

724-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
725+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
725726
UnqualifiedLookupFactory::lookupInAppropriateContext(
726727
DeclContext *dc, Optional<bool> isCascadingUse) {
727728
if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
@@ -740,7 +741,7 @@ UnqualifiedLookupFactory::lookupInAppropriateContext(
740741
return lookupInMiscContext(dc, isCascadingUse);
741742
}
742743

743-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
744+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
744745
UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
745746
PatternBindingInitializer *PBI, Optional<bool> isCascadingUse) {
746747
auto *PBD = PBI->getBinding();
@@ -754,7 +755,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
754755
return None;
755756
DeclContext *const parent = PBI->getParent();
756757
// clang-format off
757-
return PerScopeLookupState{
758+
return PerDeclInfo{
758759
false,
759760
parent,
760761
PlacesToSearch(parent, PBI, parent, parent),
@@ -767,7 +768,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
767768
if (PBD->getDeclContext()->isTypeContext()) {
768769
DeclContext *const surroundingContext = PBI->getParent();
769770
// clang-format off
770-
return PerScopeLookupState{
771+
return PerDeclInfo{
771772
false,
772773
surroundingContext,
773774
PlacesToSearch(surroundingContext, surroundingContext,
@@ -781,7 +782,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
781782
// There's not much to find here, we'll keep going up to a parent
782783
// context.
783784
// clang-format off
784-
return PerScopeLookupState{
785+
return PerDeclInfo{
785786
false,
786787
PBI,
787788
None,
@@ -790,7 +791,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
790791
// clang-format on
791792
}
792793

793-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
794+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
794795
UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
795796
Optional<bool> isCascadingUse) {
796797
// Look for local variables; normally, the parser resolves these
@@ -827,7 +828,7 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
827828
if (isLookupDoneWithoutIncludingOuterResults())
828829
return None;
829830
// clang-format off
830-
return PerScopeLookupState{
831+
return PerDeclInfo{
831832
false,
832833
fnParent,
833834
PlacesToSearch(
@@ -848,15 +849,15 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
848849
if (isLookupDoneWithoutIncludingOuterResults())
849850
return None;
850851
// clang-format off
851-
return PerScopeLookupState{
852+
return PerDeclInfo{
852853
false,
853854
AFD,
854855
None,
855856
returnValueForIsCascadingUse};
856857
// clang-format on
857858
}
858859

859-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
860+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
860861
UnqualifiedLookupFactory::lookupInClosure(AbstractClosureExpr *ACE,
861862
Optional<bool> isCascadingUse) {
862863
// Look for local variables; normally, the parser resolves these
@@ -877,7 +878,7 @@ UnqualifiedLookupFactory::lookupInClosure(AbstractClosureExpr *ACE,
877878
}
878879
}
879880
// clang-format off
880-
return PerScopeLookupState{
881+
return PerDeclInfo{
881882
false,
882883
ACE,
883884
None,
@@ -887,11 +888,11 @@ UnqualifiedLookupFactory::lookupInClosure(AbstractClosureExpr *ACE,
887888
}
888889

889890
template <typename NominalTypeDeclOrExtensionDecl>
890-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
891+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
891892
UnqualifiedLookupFactory::lookupInNominalTypeOrExtension(
892893
NominalTypeDeclOrExtensionDecl *D, Optional<bool> isCascadingUse) const {
893894
// clang-format off
894-
return PerScopeLookupState{
895+
return PerDeclInfo{
895896
false,
896897
D,
897898
shouldLookupMembers(D, Loc)
@@ -903,14 +904,15 @@ UnqualifiedLookupFactory::lookupInNominalTypeOrExtension(
903904
// clang-format on
904905
}
905906

906-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
907+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
907908
UnqualifiedLookupFactory::lookupInDefaultArgumentInitializer(
908909
DefaultArgumentInitializer *I, Optional<bool> isCascadingUse) const {
909910
// In a default argument, skip immediately out of both the
910911
// initializer and the function.
911912
// clang-format off
912-
return PerScopeLookupState{true,
913-
I->getParent()->getParent(),
913+
return PerDeclInfo{
914+
true,
915+
I->getParent(),
914916
None,
915917
false};
916918
// clang-format on
@@ -923,15 +925,15 @@ bool UnqualifiedLookupFactory::isOutsideBodyOfFunction(
923925
!SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc);
924926
}
925927

926-
Optional<UnqualifiedLookupFactory::PerScopeLookupState>
928+
Optional<UnqualifiedLookupFactory::PerDeclInfo>
927929
UnqualifiedLookupFactory::lookupInMiscContext(
928930
DeclContext *dc, Optional<bool> isCascadingUse) const {
929931
// clang-format off
930932
assert(isa<TopLevelCodeDecl>(dc) ||
931933
isa<Initializer>(dc) ||
932934
isa<TypeAliasDecl>(dc) ||
933935
isa<SubscriptDecl>(dc));
934-
return PerScopeLookupState{
936+
return PerDeclInfo{
935937
false,
936938
dc,
937939
None,
@@ -1757,16 +1759,16 @@ void UnqualifiedLookupFactory::dumpBreadcrumbs() const {
17571759
auto &e = llvm::errs();
17581760
for (size_t i : indices(breadcrumbs)) {
17591761
e << i << "\n";
1760-
const PerScopeLookupState &s = breadcrumbs[i];
1762+
const PerDeclInfo &s = breadcrumbs[i];
17611763
s.dump();
17621764
}
17631765
}
17641766

1765-
void UnqualifiedLookupFactory::PerScopeLookupState::dump() const {
1767+
void UnqualifiedLookupFactory::PerDeclInfo::dump() const {
17661768
auto &e = llvm::errs();
1767-
e << (isDone ? "done: " : "not done: ");
1769+
e << (isDoneWithThisDecl ? "done: " : "not done: ");
17681770
e << " dc: ";
1769-
childOfNextDC->dumpContext();
1771+
lookupContextForThisDecl->dumpContext();
17701772
if (placesToSearch.hasValue())
17711773
placesToSearch.getValue().dump();
17721774
}

0 commit comments

Comments
 (0)