Skip to content

ASTScope: Clean up IfConfigDecl handling and a couple of other things #34026

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
78 changes: 19 additions & 59 deletions include/swift/AST/ASTScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ class ASTScopeImpl {
bool verifyThatChildrenAreContainedWithin(SourceRange) const;
bool verifyThatThisNodeComeAfterItsPriorSibling() const;

virtual SourceRange
getSourceRangeOfEnclosedParamsOfASTNode(bool omitAssertions) const;

private:
bool checkSourceRangeAfterExpansion(const ASTContext &) const;

Expand Down Expand Up @@ -410,7 +407,7 @@ class ASTScopeImpl {
using DeclConsumer = namelookup::AbstractASTScopeDeclConsumer &;

/// Entry point into ASTScopeImpl-land for lookups
static llvm::SmallVector<const ASTScopeImpl *, 0>
static void
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc, DeclConsumer);

/// Entry point into ASTScopeImpl-land for labeled statement lookups.
Expand Down Expand Up @@ -460,22 +457,17 @@ class ASTScopeImpl {
/// duplicating work.
///
/// Look in this scope.
/// \param history are the scopes traversed for this lookup (including this
/// one) \param limit A scope into which lookup should not go. See \c
/// \param limit A scope into which lookup should not go. See \c
/// getLookupLimit. \param lastListSearched Last list searched.
/// \param consumer is the object to which found decls are reported.
void lookup(llvm::SmallVectorImpl<const ASTScopeImpl *> &history,
NullablePtr<const ASTScopeImpl> limit,
void lookup(NullablePtr<const ASTScopeImpl> limit,
NullablePtr<const GenericParamList> lastListSearched,
DeclConsumer consumer) const;

protected:
/// Find either locals or members (no scope has both)
/// \param history The scopes visited since the start of lookup (including
/// this one)
/// \return True if lookup is done
virtual bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *> history,
DeclConsumer consumer) const;
virtual bool lookupLocalsOrMembers(DeclConsumer consumer) const;

/// Returns isDone and the list searched, if any
std::pair<bool, NullablePtr<const GenericParamList>>
Expand Down Expand Up @@ -609,7 +601,6 @@ class Portion {
bool omitAssertions) const = 0;

virtual bool lookupMembersOf(const GenericTypeOrExtensionScope *scope,
ArrayRef<const ASTScopeImpl *>,
ASTScopeImpl::DeclConsumer consumer) const;

virtual NullablePtr<const ASTScopeImpl>
Expand Down Expand Up @@ -671,7 +662,6 @@ class Portion {
virtual ~GenericTypeOrExtensionWhereOrBodyPortion() {}

bool lookupMembersOf(const GenericTypeOrExtensionScope *scope,
ArrayRef<const ASTScopeImpl *>,
ASTScopeImpl::DeclConsumer consumer) const override;
};

Expand All @@ -684,7 +674,6 @@ class GenericTypeOrExtensionWherePortion final
: GenericTypeOrExtensionWhereOrBodyPortion("Where") {}

bool lookupMembersOf(const GenericTypeOrExtensionScope *scope,
ArrayRef<const ASTScopeImpl *>,
ASTScopeImpl::DeclConsumer consumer) const override;

ASTScopeImpl *expandScope(GenericTypeOrExtensionScope *,
Expand Down Expand Up @@ -788,8 +777,7 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {

protected:
bool
lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *> history,
ASTScopeImpl::DeclConsumer consumer) const override;
lookupLocalsOrMembers(ASTScopeImpl::DeclConsumer consumer) const override;
void printSpecifics(llvm::raw_ostream &out) const override;

public:
Expand Down Expand Up @@ -955,8 +943,7 @@ class GenericParamScope final : public ASTScopeImpl {
}

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

/// Concrete class for a function/initializer/deinitializer
Expand Down Expand Up @@ -991,13 +978,6 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {

NullablePtr<const void> getReferrent() const override;

protected:
SourceRange
getSourceRangeOfEnclosedParamsOfASTNode(bool omitAssertions) const override;

private:
static SourceLoc getParmsSourceLocOfAFD(AbstractFunctionDecl *);

protected:
NullablePtr<const GenericParamList> genericParams() const override;
};
Expand Down Expand Up @@ -1068,8 +1048,7 @@ class AbstractFunctionBodyScope : public ASTScopeImpl {
NullablePtr<ASTScopeImpl> getParentOfASTAncestorScopesToBeRescued() override;

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;

public:
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
Expand All @@ -1082,8 +1061,7 @@ class FunctionBodyScope final : public AbstractFunctionBodyScope {
FunctionBodyScope(AbstractFunctionDecl *e)
: AbstractFunctionBodyScope(e) {}
std::string getClassName() const override;
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer consumer) const override;
bool lookupLocalsOrMembers(DeclConsumer consumer) const override;
};

class DefaultArgumentInitializerScope final : public ASTScopeImpl {
Expand Down Expand Up @@ -1221,8 +1199,7 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
NullablePtr<const void> getReferrent() const override;

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
Expand All @@ -1249,8 +1226,7 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
virtual NullablePtr<DeclContext> getDeclContext() const override;

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

/// The scope introduced by a conditional clause in an if/guard/while
Expand Down Expand Up @@ -1312,8 +1288,7 @@ class ConditionalClausePatternUseScope final : public ASTScopeImpl {

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
void printSpecifics(llvm::raw_ostream &out) const override;
bool isLabeledStmtLookupTerminator() const override;
};
Expand All @@ -1340,8 +1315,7 @@ class CaptureListScope final : public ASTScopeImpl {
NullablePtr<Expr> getExprIfAny() const override { return expr; }
Expr *getExpr() const { return expr; }
NullablePtr<const void> getReferrent() const override;
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

/// For a closure with named parameters, this scope does the local bindings.
Expand Down Expand Up @@ -1374,8 +1348,7 @@ class ClosureParametersScope final : public ASTScopeImpl {
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

class TopLevelCodeScope final : public ASTScopeImpl {
Expand Down Expand Up @@ -1439,8 +1412,7 @@ class SpecializeAttributeScope final : public ASTScopeImpl {

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

/// A `@differentiable` attribute scope.
Expand Down Expand Up @@ -1473,8 +1445,7 @@ class DifferentiableAttributeScope final : public ASTScopeImpl {

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

class SubscriptDeclScope final : public ASTScopeImpl {
Expand Down Expand Up @@ -1507,9 +1478,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
NullablePtr<const void> getReferrent() const override;

protected:
SourceRange
getSourceRangeOfEnclosedParamsOfASTNode(bool omitAssertions) const override;

NullablePtr<const GenericParamList> genericParams() const override;
NullablePtr<AbstractStorageDecl>
getEnclosingAbstractStorageDecl() const override {
Expand Down Expand Up @@ -1566,10 +1534,6 @@ class EnumElementScope : public ASTScopeImpl {
NullablePtr<Decl> getDeclIfAny() const override { return decl; }
Decl *getDecl() const { return decl; }

protected:
SourceRange
getSourceRangeOfEnclosedParamsOfASTNode(bool omitAssertions) const override;

private:
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
};
Expand Down Expand Up @@ -1780,8 +1744,7 @@ class ForEachPatternScope final : public ASTScopeImpl {
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
bool isLabeledStmtLookupTerminator() const override;
};

Expand Down Expand Up @@ -1859,8 +1822,7 @@ class CaseLabelItemScope final : public ASTScopeImpl {
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
ASTScopeImpl::DeclConsumer) const override;
bool lookupLocalsOrMembers(ASTScopeImpl::DeclConsumer) const override;
};

/// The scope used for the body of a 'case' statement.
Expand Down Expand Up @@ -1888,8 +1850,7 @@ class CaseStmtBodyScope final : public ASTScopeImpl {
SourceRange
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
ASTScopeImpl::DeclConsumer) const override;
bool lookupLocalsOrMembers(ASTScopeImpl::DeclConsumer) const override;
bool isLabeledStmtLookupTerminator() const override;
};

Expand Down Expand Up @@ -1917,8 +1878,7 @@ class BraceStmtScope final : public AbstractStmtScope {
Stmt *getStmt() const override { return stmt; }

protected:
bool lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
DeclConsumer) const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};
} // namespace ast_scope
} // namespace swift
Expand Down
6 changes: 2 additions & 4 deletions include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,8 @@ class ASTScope {
/// Flesh out the tree for dumping
void buildFullyExpandedTree();

/// \return the scopes traversed
static llvm::SmallVector<const ast_scope::ASTScopeImpl *, 0>
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
namelookup::AbstractASTScopeDeclConsumer &);
static void unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
namelookup::AbstractASTScopeDeclConsumer &);

/// Entry point to record the visible statement labels from the given
/// point.
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ using namespace ast_scope;

#pragma mark ASTScope

llvm::SmallVector<const ASTScopeImpl *, 0> ASTScope::unqualifiedLookup(
void ASTScope::unqualifiedLookup(
SourceFile *SF, DeclNameRef name, SourceLoc loc,
namelookup::AbstractASTScopeDeclConsumer &consumer) {
if (auto *s = SF->getASTContext().Stats)
++s->getFrontendCounters().NumASTScopeLookups;
return ASTScopeImpl::unqualifiedLookup(SF, name, loc, consumer);
ASTScopeImpl::unqualifiedLookup(SF, name, loc, consumer);
}

llvm::SmallVector<LabeledStmt *, 4> ASTScope::lookupLabeledStmts(
Expand Down
Loading