Skip to content

[NFC] Clean Up Unused Parameters in Unqualified Lookup #40069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,7 @@ class AbstractASTScopeDeclConsumer {
/// Look for members of a nominal type or extension scope.
///
/// \return true if the lookup should be stopped at this point.
virtual bool
lookInMembers(DeclContext *const scopeDC,
NominalTypeDecl *const nominal) = 0;
virtual bool lookInMembers(const DeclContext *scopeDC) const = 0;

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

/// Eventually this functionality should move into ASTScopeLookup
bool lookInMembers(DeclContext *const,
NominalTypeDecl *const) override {
bool lookInMembers(const DeclContext *) const override {
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/AST/ASTScopeLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ bool Portion::lookupMembersOf(const GenericTypeOrExtensionScope *,
bool GenericTypeOrExtensionWhereOrBodyPortion::lookupMembersOf(
const GenericTypeOrExtensionScope *scope,
ASTScopeImpl::DeclConsumer consumer) const {
auto nt = scope->getCorrespondingNominalTypeDecl().getPtrOrNull();
if (!nt)
if (scope->getCorrespondingNominalTypeDecl().isNull())
return false;
return consumer.lookInMembers(scope->getGenericContext(), nt);
return consumer.lookInMembers(scope->getGenericContext());
}

bool GenericTypeOrExtensionWherePortion::lookupMembersOf(
Expand Down
29 changes: 15 additions & 14 deletions lib/AST/UnqualifiedLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,33 @@ namespace {
/// Used to gather lookup results
class ASTScopeDeclConsumerForUnqualifiedLookup
: public AbstractASTScopeDeclConsumer {
private:
UnqualifiedLookupFactory &factory;

/// The 'self' parameter from the innermost scope containing the lookup
/// location to be used when an instance member of a type is accessed,
/// or nullptr if instance members should not be 'self' qualified.
DeclContext *candidateSelfDC;
/// or \c nullptr if instance members should not be 'self' qualified.
///
// FIXME: This field is currently reset to \c nullptr by `lookInMembers` as
// part of the lookup traversal of scopes. If, instead, consumers were
// created at each point in the traversal, this field would no longer need
// to be marked \c mutable.
mutable const DeclContext *candidateSelfDC;

void maybeUpdateSelfDC(VarDecl *var);

public:
ASTScopeDeclConsumerForUnqualifiedLookup(UnqualifiedLookupFactory &factory)
: factory(factory), candidateSelfDC(nullptr) {}

virtual ~ASTScopeDeclConsumerForUnqualifiedLookup() = default;

void maybeUpdateSelfDC(VarDecl *var);

bool consume(ArrayRef<ValueDecl *> values,
NullablePtr<DeclContext> baseDC = nullptr) override;

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

/// returns true if finished
bool lookInMembers(DeclContext *const scopeDC,
NominalTypeDecl *const nominal) override;
bool lookInMembers(const DeclContext *) const override;

#ifndef NDEBUG
void startingNextLookupStep() override {
Expand Down Expand Up @@ -539,8 +543,7 @@ void UnqualifiedLookupFactory::lookInASTScopes() {
ASTScope::unqualifiedLookup(DC->getParentSourceFile(), Loc, consumer);
}

void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(
VarDecl *var) {
void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(VarDecl *var) {
// We have a binding named 'self'.
//
// There are three possibilities:
Expand Down Expand Up @@ -649,8 +652,7 @@ bool ASTScopeDeclGatherer::consume(ArrayRef<ValueDecl *> valuesArg,

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

Expand Down Expand Up @@ -820,8 +822,7 @@ class ASTScopeDeclConsumerForLocalLookup
return (!stopAfterInnermostBraceStmt && !results.empty());
}

bool lookInMembers(DeclContext *const,
NominalTypeDecl *const) override {
bool lookInMembers(const DeclContext *) const override {
return true;
}

Expand Down