Skip to content

Commit cb70220

Browse files
authored
Merge pull request #34226 from slavapestov/astscope-source-range-sorting
ASTScope: Stop sorting declarations by source range
2 parents a373e85 + 14620a3 commit cb70220

File tree

7 files changed

+202
-341
lines changed

7 files changed

+202
-341
lines changed

include/swift/AST/ASTScope.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ class ASTScopeImpl {
194194
#pragma mark - source ranges
195195

196196
public:
197-
/// Return signum of ranges. Centralize the invariant that ASTScopes use ends.
198-
static int compare(SourceRange, SourceRange, const SourceManager &,
199-
bool ensureDisjoint);
200-
201197
CharSourceRange getCharSourceRangeOfScope(SourceManager &SM,
202198
bool omitAssertions = false) const;
203199
bool isCharSourceRangeCached() const;
@@ -224,7 +220,6 @@ class ASTScopeImpl {
224220
virtual NullablePtr<DeclAttribute> getDeclAttributeIfAny() const {
225221
return nullptr;
226222
}
227-
virtual NullablePtr<const void> getReferrent() const { return nullptr; }
228223

229224
#pragma mark - debugging and printing
230225

@@ -470,9 +465,6 @@ class Portion {
470465
virtual NullablePtr<const ASTScopeImpl>
471466
getLookupLimitFor(const GenericTypeOrExtensionScope *) const;
472467

473-
virtual const Decl *
474-
getReferrentOfScope(const GenericTypeOrExtensionScope *s) const;
475-
476468
virtual NullablePtr<ASTScopeImpl>
477469
insertionPointForDeferredExpansion(IterableTypeScope *) const = 0;
478470
};
@@ -493,9 +485,6 @@ class Portion {
493485
NullablePtr<const ASTScopeImpl>
494486
getLookupLimitFor(const GenericTypeOrExtensionScope *) const override;
495487

496-
const Decl *
497-
getReferrentOfScope(const GenericTypeOrExtensionScope *s) const override;
498-
499488
NullablePtr<ASTScopeImpl>
500489
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
501490
};
@@ -570,7 +559,6 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {
570559

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

575563
private:
576564
AnnotatedInsertionPoint
@@ -745,7 +733,6 @@ class GenericParamScope final : public ASTScopeImpl {
745733

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

791-
NullablePtr<const void> getReferrent() const override;
792-
793778
protected:
794779
NullablePtr<const GenericParamList> genericParams() const override;
795780
};
@@ -902,7 +887,6 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
902887
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
903888
return attr;
904889
}
905-
NullablePtr<const void> getReferrent() const override;
906890

907891
private:
908892
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
@@ -970,8 +954,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
970954
SourceRange
971955
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
972956

973-
NullablePtr<const void> getReferrent() const override;
974-
975957
protected:
976958
bool lookupLocalsOrMembers(DeclConsumer) const override;
977959
bool isLabeledStmtLookupTerminator() const override;
@@ -1072,7 +1054,6 @@ class CaptureListScope final : public ASTScopeImpl {
10721054
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
10731055
NullablePtr<Expr> getExprIfAny() const override { return expr; }
10741056
Expr *getExpr() const { return expr; }
1075-
NullablePtr<const void> getReferrent() const override;
10761057
bool lookupLocalsOrMembers(DeclConsumer) const override;
10771058
};
10781059

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

10991079
protected:
11001080
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
@@ -1128,7 +1108,6 @@ class TopLevelCodeScope final : public ASTScopeImpl {
11281108
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
11291109
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
11301110
Decl *getDecl() const { return decl; }
1131-
NullablePtr<const void> getReferrent() const override;
11321111
};
11331112

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

11581136
protected:
11591137
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
@@ -1183,7 +1161,6 @@ class DifferentiableAttributeScope final : public ASTScopeImpl {
11831161
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
11841162
return differentiableAttr;
11851163
}
1186-
NullablePtr<const void> getReferrent() const override;
11871164

11881165
protected:
11891166
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
@@ -1214,7 +1191,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
12141191
public:
12151192
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
12161193
Decl *getDecl() const { return decl; }
1217-
NullablePtr<const void> getReferrent() const override;
12181194

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

12491224
protected:
12501225
bool isLabeledStmtLookupTerminator() const override;

include/swift/AST/DeclContext.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,20 @@ class IterableDeclContext {
782782
/// abstractions on top of member loading, such as a name lookup table.
783783
DeclRange getCurrentMembersWithoutLoading() const;
784784

785-
/// Add a member to this context. If the hint decl is specified, the new decl
786-
/// is inserted immediately after the hint.
787-
void addMember(Decl *member, Decl *hint = nullptr);
785+
/// Add a member to this context.
786+
///
787+
/// If the hint decl is specified, the new decl is inserted immediately
788+
/// after the hint.
789+
///
790+
/// If insertAtHead is set, the new decl is inserted at the beginning of
791+
/// the list.
792+
///
793+
/// Otherwise, it is inserted at the end.
794+
void addMember(Decl *member, Decl *hint = nullptr, bool insertAtHead = false);
795+
796+
/// Add a member in the right place to preserve source order. This should
797+
/// only be called from the code completion delayed parsing path.
798+
void addMemberPreservingSourceOrder(Decl *member);
788799

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

871879
/// Define simple_display for DeclContexts but not for subclasses in order to

0 commit comments

Comments
 (0)