Skip to content

Commit c23a617

Browse files
committed
[NFC] Clean Up Unused Fields in Unqualified Lookup
* Drop some unused fields * const-qualify a consumption method that is logically const - though it isn't physically const given the mutating use in ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers * Privatize some internal fields
1 parent 52df427 commit c23a617

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,7 @@ class AbstractASTScopeDeclConsumer {
641641
/// Look for members of a nominal type or extension scope.
642642
///
643643
/// \return true if the lookup should be stopped at this point.
644-
virtual bool
645-
lookInMembers(DeclContext *const scopeDC,
646-
NominalTypeDecl *const nominal) = 0;
644+
virtual bool lookInMembers(const DeclContext *scopeDC) const = 0;
647645

648646
/// Called for local VarDecls that might not yet be in scope.
649647
///
@@ -680,8 +678,7 @@ class ASTScopeDeclGatherer : public AbstractASTScopeDeclConsumer {
680678
NullablePtr<DeclContext> baseDC = nullptr) override;
681679

682680
/// Eventually this functionality should move into ASTScopeLookup
683-
bool lookInMembers(DeclContext *const,
684-
NominalTypeDecl *const) override {
681+
bool lookInMembers(const DeclContext *) const override {
685682
return false;
686683
}
687684

lib/AST/ASTScopeLookup.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,9 @@ bool Portion::lookupMembersOf(const GenericTypeOrExtensionScope *,
241241
bool GenericTypeOrExtensionWhereOrBodyPortion::lookupMembersOf(
242242
const GenericTypeOrExtensionScope *scope,
243243
ASTScopeImpl::DeclConsumer consumer) const {
244-
auto nt = scope->getCorrespondingNominalTypeDecl().getPtrOrNull();
245-
if (!nt)
244+
if (scope->getCorrespondingNominalTypeDecl().isNull())
246245
return false;
247-
return consumer.lookInMembers(scope->getGenericContext(), nt);
246+
return consumer.lookInMembers(scope->getGenericContext());
248247
}
249248

250249
bool GenericTypeOrExtensionWherePortion::lookupMembersOf(

lib/AST/UnqualifiedLookup.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,33 @@ namespace {
199199
/// Used to gather lookup results
200200
class ASTScopeDeclConsumerForUnqualifiedLookup
201201
: public AbstractASTScopeDeclConsumer {
202+
private:
202203
UnqualifiedLookupFactory &factory;
203204

204205
/// The 'self' parameter from the innermost scope containing the lookup
205206
/// location to be used when an instance member of a type is accessed,
206-
/// or nullptr if instance members should not be 'self' qualified.
207-
DeclContext *candidateSelfDC;
207+
/// or \c nullptr if instance members should not be 'self' qualified.
208+
///
209+
// FIXME: This field is currently reset to \c nullptr by `lookInMembers` as
210+
// part of the lookup traversal of scopes. If, instead, consumers were
211+
// created at each point in the traversal, this field would no longer need
212+
// to be marked \c mutable.
213+
mutable const DeclContext *candidateSelfDC;
214+
215+
void maybeUpdateSelfDC(VarDecl *var);
208216

209217
public:
210218
ASTScopeDeclConsumerForUnqualifiedLookup(UnqualifiedLookupFactory &factory)
211219
: factory(factory), candidateSelfDC(nullptr) {}
212220

213221
virtual ~ASTScopeDeclConsumerForUnqualifiedLookup() = default;
214222

215-
void maybeUpdateSelfDC(VarDecl *var);
216-
217223
bool consume(ArrayRef<ValueDecl *> values,
218224
NullablePtr<DeclContext> baseDC = nullptr) override;
219225

220226
bool consumePossiblyNotInScope(ArrayRef<VarDecl *> vars) override;
221227

222-
/// returns true if finished
223-
bool lookInMembers(DeclContext *const scopeDC,
224-
NominalTypeDecl *const nominal) override;
228+
bool lookInMembers(const DeclContext *) const override;
225229

226230
#ifndef NDEBUG
227231
void startingNextLookupStep() override {
@@ -539,8 +543,7 @@ void UnqualifiedLookupFactory::lookInASTScopes() {
539543
ASTScope::unqualifiedLookup(DC->getParentSourceFile(), Loc, consumer);
540544
}
541545

542-
void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(
543-
VarDecl *var) {
546+
void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(VarDecl *var) {
544547
// We have a binding named 'self'.
545548
//
546549
// There are three possibilities:
@@ -649,8 +652,7 @@ bool ASTScopeDeclGatherer::consume(ArrayRef<ValueDecl *> valuesArg,
649652

650653
// TODO: in future, migrate this functionality into ASTScopes
651654
bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers(
652-
DeclContext *const scopeDC,
653-
NominalTypeDecl *const nominal) {
655+
const DeclContext *scopeDC) const {
654656
if (candidateSelfDC) {
655657
if (auto *afd = dyn_cast<AbstractFunctionDecl>(candidateSelfDC)) {
656658
assert(factory.isInsideBodyOfFunction(afd) && "Should be inside");
@@ -672,7 +674,7 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers(
672674
// We're done looking inside a nominal type declaration. It is possible
673675
// that this nominal type is nested inside of another type, in which case
674676
// we will visit the outer type next. Make sure to clear out the known
675-
// 'self' parameeter context, since any members of the outer type are
677+
// 'self' parameter context, since any members of the outer type are
676678
// not accessed via the innermost 'self' parameter.
677679
candidateSelfDC = nullptr;
678680

@@ -820,8 +822,7 @@ class ASTScopeDeclConsumerForLocalLookup
820822
return (!stopAfterInnermostBraceStmt && !results.empty());
821823
}
822824

823-
bool lookInMembers(DeclContext *const,
824-
NominalTypeDecl *const) override {
825+
bool lookInMembers(const DeclContext *) const override {
825826
return true;
826827
}
827828

0 commit comments

Comments
 (0)