Skip to content

ASTScope: Stop sorting declarations by source range #34226

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
25 changes: 0 additions & 25 deletions include/swift/AST/ASTScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ class ASTScopeImpl {
#pragma mark - source ranges

public:
/// Return signum of ranges. Centralize the invariant that ASTScopes use ends.
static int compare(SourceRange, SourceRange, const SourceManager &,
bool ensureDisjoint);

CharSourceRange getCharSourceRangeOfScope(SourceManager &SM,
bool omitAssertions = false) const;
bool isCharSourceRangeCached() const;
Expand All @@ -224,7 +220,6 @@ class ASTScopeImpl {
virtual NullablePtr<DeclAttribute> getDeclAttributeIfAny() const {
return nullptr;
}
virtual NullablePtr<const void> getReferrent() const { return nullptr; }

#pragma mark - debugging and printing

Expand Down Expand Up @@ -470,9 +465,6 @@ class Portion {
virtual NullablePtr<const ASTScopeImpl>
getLookupLimitFor(const GenericTypeOrExtensionScope *) const;

virtual const Decl *
getReferrentOfScope(const GenericTypeOrExtensionScope *s) const;

virtual NullablePtr<ASTScopeImpl>
insertionPointForDeferredExpansion(IterableTypeScope *) const = 0;
};
Expand All @@ -493,9 +485,6 @@ class Portion {
NullablePtr<const ASTScopeImpl>
getLookupLimitFor(const GenericTypeOrExtensionScope *) const override;

const Decl *
getReferrentOfScope(const GenericTypeOrExtensionScope *s) const override;

NullablePtr<ASTScopeImpl>
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
};
Expand Down Expand Up @@ -570,7 +559,6 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {

virtual Decl *getDecl() const = 0;
NullablePtr<Decl> getDeclIfAny() const override { return getDecl(); }
NullablePtr<const void> getReferrent() const override;

private:
AnnotatedInsertionPoint
Expand Down Expand Up @@ -745,7 +733,6 @@ class GenericParamScope final : public ASTScopeImpl {

/// Actually holder is always a GenericContext, need to test if
/// ProtocolDecl or SubscriptDecl but will refactor later.
NullablePtr<const void> getReferrent() const override;
std::string getClassName() const override;
SourceRange
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
Expand Down Expand Up @@ -788,8 +775,6 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
Decl *getDecl() const { return decl; }

NullablePtr<const void> getReferrent() const override;

protected:
NullablePtr<const GenericParamList> genericParams() const override;
};
Expand Down Expand Up @@ -902,7 +887,6 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
return attr;
}
NullablePtr<const void> getReferrent() const override;

private:
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
Expand Down Expand Up @@ -970,8 +954,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
SourceRange
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;

NullablePtr<const void> getReferrent() const override;

protected:
bool lookupLocalsOrMembers(DeclConsumer) const override;
bool isLabeledStmtLookupTerminator() const override;
Expand Down Expand Up @@ -1072,7 +1054,6 @@ class CaptureListScope final : public ASTScopeImpl {
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
NullablePtr<Expr> getExprIfAny() const override { return expr; }
Expr *getExpr() const { return expr; }
NullablePtr<const void> getReferrent() const override;
bool lookupLocalsOrMembers(DeclConsumer) const override;
};

Expand All @@ -1094,7 +1075,6 @@ class ClosureParametersScope final : public ASTScopeImpl {
}
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
Expr *getExpr() const { return closureExpr; }
NullablePtr<const void> getReferrent() const override;

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
Expand Down Expand Up @@ -1128,7 +1108,6 @@ class TopLevelCodeScope final : public ASTScopeImpl {
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
Decl *getDecl() const { return decl; }
NullablePtr<const void> getReferrent() const override;
};

/// The \c _@specialize attribute.
Expand All @@ -1153,7 +1132,6 @@ class SpecializeAttributeScope final : public ASTScopeImpl {
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
return specializeAttr;
}
NullablePtr<const void> getReferrent() const override;

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
Expand Down Expand Up @@ -1183,7 +1161,6 @@ class DifferentiableAttributeScope final : public ASTScopeImpl {
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
return differentiableAttr;
}
NullablePtr<const void> getReferrent() const override;

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
Expand Down Expand Up @@ -1214,7 +1191,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
public:
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
Decl *getDecl() const { return decl; }
NullablePtr<const void> getReferrent() const override;

protected:
NullablePtr<const GenericParamList> genericParams() const override;
Expand Down Expand Up @@ -1244,7 +1220,6 @@ class AbstractStmtScope : public ASTScopeImpl {
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
virtual Stmt *getStmt() const = 0;
NullablePtr<Stmt> getStmtIfAny() const override { return getStmt(); }
NullablePtr<const void> getReferrent() const override;

protected:
bool isLabeledStmtLookupTerminator() const override;
Expand Down
22 changes: 15 additions & 7 deletions include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,20 @@ class IterableDeclContext {
/// abstractions on top of member loading, such as a name lookup table.
DeclRange getCurrentMembersWithoutLoading() const;

/// Add a member to this context. If the hint decl is specified, the new decl
/// is inserted immediately after the hint.
void addMember(Decl *member, Decl *hint = nullptr);
/// Add a member to this context.
///
/// If the hint decl is specified, the new decl is inserted immediately
/// after the hint.
///
/// If insertAtHead is set, the new decl is inserted at the beginning of
/// the list.
///
/// Otherwise, it is inserted at the end.
void addMember(Decl *member, Decl *hint = nullptr, bool insertAtHead = false);

/// Add a member in the right place to preserve source order. This should
/// only be called from the code completion delayed parsing path.
void addMemberPreservingSourceOrder(Decl *member);

/// Check whether there are lazily-loaded members.
bool hasLazyMembers() const {
Expand Down Expand Up @@ -862,10 +873,7 @@ class IterableDeclContext {
private:
/// Add a member to the list for iteration purposes, but do not notify the
/// subclass that we have done so.
///
/// This is used internally when loading members, because loading a
/// member is an invisible addition.
void addMemberSilently(Decl *member, Decl *hint = nullptr) const;
void addMemberSilently(Decl *member, Decl *hint, bool insertAtHead) const;
};

/// Define simple_display for DeclContexts but not for subclasses in order to
Expand Down
Loading