Skip to content

Commit 996100c

Browse files
committed
ASTScope: Remove old SourceRange machinery
1 parent e52413f commit 996100c

File tree

5 files changed

+5
-362
lines changed

5 files changed

+5
-362
lines changed

include/swift/AST/ASTScope.h

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,13 @@ class ASTScopeImpl {
141141
ASTScopeImpl *parent = nullptr; // null at the root
142142

143143
/// Child scopes, sorted by source range.
144-
/// Must clear source range change whenever this changes
145144
Children storedChildren;
146145

147146
bool wasExpanded = false;
148147

149148
/// Can clear storedChildren, so must remember this
150149
bool haveAddedCleanup = false;
151150

152-
// Must be updated after last child is added and after last child's source
153-
// position is known
154-
mutable Optional<SourceRange> cachedSourceRange;
155-
156-
// When ignoring ASTNodes in a scope, they still must count towards a scope's
157-
// source range. So include their ranges here
158-
SourceRange sourceRangeOfIgnoredASTNodes;
159-
160151
mutable Optional<CharSourceRange> cachedCharSourceRange;
161152

162153
#pragma mark - constructor / destructor
@@ -194,9 +185,6 @@ class ASTScopeImpl {
194185
public:
195186
void addChild(ASTScopeImpl *child, ASTContext &);
196187

197-
private:
198-
NullablePtr<ASTScopeImpl> getPriorSibling() const;
199-
200188
public:
201189
void preOrderDo(function_ref<void(ASTScopeImpl *)>);
202190
/// Like preorderDo but without myself.
@@ -205,67 +193,15 @@ class ASTScopeImpl {
205193

206194
#pragma mark - source ranges
207195

208-
#pragma mark - source range queries
209-
210196
public:
211197
/// Return signum of ranges. Centralize the invariant that ASTScopes use ends.
212198
static int compare(SourceRange, SourceRange, const SourceManager &,
213199
bool ensureDisjoint);
214200

215-
SourceRange getSourceRangeOfScope(bool omitAssertions = false) const;
216-
217201
CharSourceRange getCharSourceRangeOfScope(SourceManager &SM,
218202
bool omitAssertions = false) const;
219203
bool isCharSourceRangeCached() const;
220204

221-
/// InterpolatedStringLiteralExprs and EditorPlaceHolders respond to
222-
/// getSourceRange with the starting point. But we might be asked to lookup an
223-
/// identifer within one of them. So, find the real source range of them here.
224-
SourceRange getEffectiveSourceRange(ASTNode) const;
225-
226-
void computeAndCacheSourceRangeOfScope(bool omitAssertions = false) const;
227-
bool isSourceRangeCached(bool omitAssertions = false) const;
228-
229-
bool checkSourceRangeOfThisASTNode() const;
230-
231-
/// For debugging
232-
bool doesRangeMatch(unsigned start, unsigned end, StringRef file = "",
233-
StringRef className = "");
234-
235-
unsigned countDescendants() const;
236-
237-
/// Make sure that when the argument is executed, there are as many
238-
/// descendants after as before.
239-
void assertThatTreeDoesNotShrink(function_ref<void()>);
240-
241-
private:
242-
SourceRange computeSourceRangeOfScope(bool omitAssertions = false) const;
243-
SourceRange
244-
computeSourceRangeOfScopeWithChildASTNodes(bool omitAssertions = false) const;
245-
bool ensureNoAncestorsSourceRangeIsCached() const;
246-
247-
#pragma mark - source range adjustments
248-
private:
249-
SourceRange widenSourceRangeForIgnoredASTNodes(SourceRange range) const;
250-
251-
/// If the scope refers to a Decl whose source range tells the whole story,
252-
/// for example a NominalTypeScope, it is not necessary to widen the source
253-
/// range by examining the children. In that case we could just return
254-
/// the childlessRange here.
255-
/// But, we have not marked such scopes yet. Doing so would be an
256-
/// optimization.
257-
SourceRange widenSourceRangeForChildren(SourceRange range,
258-
bool omitAssertions) const;
259-
260-
/// Even ASTNodes that do not form scopes must be included in a Scope's source
261-
/// range. Widen the source range of the receiver to include the (ignored)
262-
/// node.
263-
void widenSourceRangeForIgnoredASTNode(ASTNode);
264-
265-
private:
266-
void clearCachedSourceRangesOfMeAndAncestors();
267-
268-
public: // public for debugging
269205
/// Returns source range of this node alone, without factoring in any
270206
/// children.
271207
virtual SourceRange
@@ -331,19 +267,11 @@ class ASTScopeImpl {
331267
void setWasExpanded() { wasExpanded = true; }
332268
virtual ASTScopeImpl *expandSpecifically(ScopeCreator &) = 0;
333269

334-
private:
335-
/// Compare the pre-expasion range with the post-expansion range and return
336-
/// false if lazyiness couild miss lookups.
337-
bool checkLazySourceRange(const ASTContext &) const;
338-
339270
public:
340271
/// Some scopes can be expanded lazily.
341-
/// Such scopes must: not change their source ranges after expansion, and
342-
/// their expansion must return an insertion point outside themselves.
343-
/// After a node is expanded, its source range (getSourceRangeofThisASTNode
344-
/// union children's ranges) must be same as this.
272+
/// Such scopes must return an insertion point outside themselves when
273+
/// expanded.
345274
virtual NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion();
346-
virtual SourceRange sourceRangeForDeferredExpansion() const;
347275

348276
private:
349277
virtual ScopeCreator &getScopeCreator();
@@ -547,8 +475,6 @@ class Portion {
547475

548476
virtual NullablePtr<ASTScopeImpl>
549477
insertionPointForDeferredExpansion(IterableTypeScope *) const = 0;
550-
virtual SourceRange
551-
sourceRangeForDeferredExpansion(const IterableTypeScope *) const = 0;
552478
};
553479

554480
// For the whole Decl scope of a GenericType or an Extension
@@ -572,8 +498,6 @@ class Portion {
572498

573499
NullablePtr<ASTScopeImpl>
574500
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
575-
SourceRange
576-
sourceRangeForDeferredExpansion(const IterableTypeScope *) const override;
577501
};
578502

579503
/// GenericTypeOrExtension = GenericType or Extension
@@ -605,8 +529,6 @@ class GenericTypeOrExtensionWherePortion final
605529

606530
NullablePtr<ASTScopeImpl>
607531
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
608-
SourceRange
609-
sourceRangeForDeferredExpansion(const IterableTypeScope *) const override;
610532
};
611533

612534
/// Behavior specific to representing the Body of a NominalTypeDecl or
@@ -624,8 +546,6 @@ class IterableTypeBodyPortion final
624546

625547
NullablePtr<ASTScopeImpl>
626548
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
627-
SourceRange
628-
sourceRangeForDeferredExpansion(const IterableTypeScope *) const override;
629549
};
630550

631551
/// GenericType or Extension scope
@@ -722,7 +642,6 @@ class IterableTypeScope : public GenericTypeScope {
722642

723643
public:
724644
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
725-
SourceRange sourceRangeForDeferredExpansion() const override;
726645

727646
void countBodies(ScopeCreator &) const;
728647
};
@@ -931,7 +850,6 @@ class FunctionBodyScope : public ASTScopeImpl {
931850
public:
932851
std::string getClassName() const override;
933852
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
934-
SourceRange sourceRangeForDeferredExpansion() const override;
935853
};
936854

937855
class DefaultArgumentInitializerScope final : public ASTScopeImpl {

lib/AST/ASTScope.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,4 @@ void ASTScopeImpl::postOrderDo(function_ref<void(ASTScopeImpl *)> fn) {
197197
for (auto *child : getChildren())
198198
child->postOrderDo(fn);
199199
fn(this);
200-
}
201-
202-
unsigned ASTScopeImpl::countDescendants() const {
203-
unsigned count = 0;
204-
const_cast<ASTScopeImpl *>(this)->preOrderDo(
205-
[&](ASTScopeImpl *) { ++count; });
206-
return count - 1;
207-
}
208-
209-
// Can fail if a subscope is lazy and not reexpanded
210-
void ASTScopeImpl::assertThatTreeDoesNotShrink(function_ref<void()> fn) {
211-
#ifndef NDEBUG
212-
unsigned beforeCount = countDescendants();
213-
#endif
214-
fn();
215-
#ifndef NDEBUG
216-
unsigned afterCount = countDescendants();
217-
ASTScopeAssert(beforeCount <= afterCount, "shrank?!");
218-
#endif
219-
}
200+
}

lib/AST/ASTScopeCreation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ class NodeAdder
572572
#define VISIT_AND_IGNORE(What) \
573573
NullablePtr<ASTScopeImpl> visit##What(What *w, ASTScopeImpl *p, \
574574
ScopeCreator &) { \
575-
p->widenSourceRangeForIgnoredASTNode(w); \
576575
return p; \
577576
}
578577

@@ -766,10 +765,9 @@ class NodeAdder
766765

767766
NullablePtr<ASTScopeImpl> visitExpr(Expr *expr, ASTScopeImpl *p,
768767
ScopeCreator &scopeCreator) {
769-
if (expr) {
770-
p->widenSourceRangeForIgnoredASTNode(expr);
768+
if (expr)
771769
scopeCreator.addExprToScopeTree(expr, p);
772-
}
770+
773771
return p;
774772
}
775773
};
@@ -894,7 +892,6 @@ void ASTScopeImpl::addChild(ASTScopeImpl *child, ASTContext &ctx) {
894892
haveAddedCleanup = true;
895893
}
896894
storedChildren.push_back(child);
897-
clearCachedSourceRangesOfMeAndAncestors();
898895
}
899896

900897
#pragma mark implementations of expansion

lib/AST/ASTScopeLookup.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ ASTScopeImpl *ASTScopeImpl::findInnermostEnclosingScopeImpl(
7272
scopeCreator);
7373
}
7474

75-
bool ASTScopeImpl::checkSourceRangeOfThisASTNode() const {
76-
const auto r = getSourceRangeOfThisASTNode();
77-
(void)r;
78-
ASTScopeAssert(!getSourceManager().isBeforeInBuffer(r.End, r.Start),
79-
"Range is backwards.");
80-
return true;
81-
}
82-
8375
/// If the \p loc is in a new buffer but \p range is not, consider the location
8476
/// is at the start of replaced range. Otherwise, returns \p loc as is.
8577
static SourceLoc translateLocForReplacedRange(SourceManager &sourceMgr,

0 commit comments

Comments
 (0)