Skip to content

Commit 14620a3

Browse files
committed
ASTScope: Remove source range sorting
1 parent ee0d008 commit 14620a3

File tree

3 files changed

+5
-63
lines changed

3 files changed

+5
-63
lines changed

include/swift/AST/ASTScope.h

Lines changed: 0 additions & 4 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;

lib/AST/ASTScopeCreation.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -359,27 +359,6 @@ class ScopeCreator final {
359359
return culled;
360360
}
361361

362-
/// Templated to work on either ASTNodes, Decl*'s, or whatnot.
363-
template <typename Rangeable>
364-
std::vector<Rangeable>
365-
sortBySourceRange(std::vector<Rangeable> toBeSorted) const {
366-
auto compareNodes = [&](Rangeable n1, Rangeable n2) {
367-
return isNotAfter(n1, n2);
368-
};
369-
std::stable_sort(toBeSorted.begin(), toBeSorted.end(), compareNodes);
370-
return toBeSorted;
371-
}
372-
373-
template <typename Rangeable>
374-
bool isNotAfter(Rangeable n1, Rangeable n2) const {
375-
const auto r1 = getRangeableSourceRange(n1);
376-
const auto r2 = getRangeableSourceRange(n2);
377-
378-
const int signum = ASTScopeImpl::compare(r1, r2, ctx.SourceMgr,
379-
/*ensureDisjoint=*/true);
380-
return -1 == signum;
381-
}
382-
383362
SWIFT_DEBUG_DUMP { print(llvm::errs()); }
384363

385364
void print(raw_ostream &out) const {
@@ -895,8 +874,7 @@ ASTSourceFileScope::expandAScopeThatCreatesANewInsertionPoint(
895874
std::vector<ASTNode> newNodes(decls.begin(), decls.end());
896875
insertionPoint =
897876
scopeCreator.addSiblingsToScopeTree(insertionPoint,
898-
scopeCreator.sortBySourceRange(
899-
scopeCreator.cull(newNodes)),
877+
scopeCreator.cull(newNodes),
900878
endLoc);
901879

902880
// Too slow to perform all the time:
@@ -1024,9 +1002,8 @@ BraceStmtScope::expandAScopeThatCreatesANewInsertionPoint(
10241002
// elements in source order
10251003
auto *insertionPoint =
10261004
scopeCreator.addSiblingsToScopeTree(this,
1027-
scopeCreator.sortBySourceRange(
1028-
scopeCreator.cull(
1029-
stmt->getElements())),
1005+
scopeCreator.cull(
1006+
stmt->getElements()),
10301007
endLoc);
10311008
if (auto *s = scopeCreator.getASTContext().Stats)
10321009
++s->getFrontendCounters().NumBraceStmtASTScopeExpansions;
@@ -1388,7 +1365,7 @@ void GenericTypeOrExtensionScope::expandBody(ScopeCreator &) {}
13881365

13891366
void IterableTypeScope::expandBody(ScopeCreator &scopeCreator) {
13901367
auto nodes = asNodeVector(getIterableDeclContext().get()->getMembers());
1391-
nodes = scopeCreator.sortBySourceRange(scopeCreator.cull(nodes));
1368+
nodes = scopeCreator.cull(nodes);
13921369
scopeCreator.addSiblingsToScopeTree(this, nodes, None);
13931370
if (auto *s = scopeCreator.getASTContext().Stats)
13941371
++s->getFrontendCounters().NumIterableTypeBodyASTScopeExpansions;

lib/AST/ASTScopeSourceRange.cpp

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -371,35 +371,4 @@ SourceLoc ast_scope::extractNearestSourceLoc(
371371
std::tuple<ASTScopeImpl *, ScopeCreator *> scopeAndCreator) {
372372
const ASTScopeImpl *scope = std::get<0>(scopeAndCreator);
373373
return scope->getSourceRangeOfThisASTNode().Start;
374-
}
375-
376-
int ASTScopeImpl::compare(const SourceRange lhs, const SourceRange rhs,
377-
const SourceManager &SM, const bool ensureDisjoint) {
378-
ASTScopeAssert(!SM.isBeforeInBuffer(lhs.End, lhs.Start),
379-
"Range is backwards.");
380-
ASTScopeAssert(!SM.isBeforeInBuffer(rhs.End, rhs.Start),
381-
"Range is backwards.");
382-
383-
auto cmpLoc = [&](const SourceLoc lhs, const SourceLoc rhs) {
384-
return lhs == rhs ? 0 : SM.isBeforeInBuffer(lhs, rhs) ? -1 : 1;
385-
};
386-
// Establish that we use end locations throughout ASTScopes here
387-
const int endOrder = cmpLoc(lhs.End, rhs.End);
388-
389-
#ifndef NDEBUG
390-
if (ensureDisjoint) {
391-
const int startOrder = cmpLoc(lhs.Start, rhs.Start);
392-
393-
if (startOrder * endOrder == -1) {
394-
llvm::errs() << "*** Start order contradicts end order between: ***\n";
395-
lhs.print(llvm::errs(), SM, false);
396-
llvm::errs() << "\n*** and: ***\n";
397-
rhs.print(llvm::errs(), SM, false);
398-
}
399-
ASTScopeAssert(startOrder * endOrder != -1,
400-
"Start order contradicts end order");
401-
}
402-
#endif
403-
404-
return endOrder;
405-
}
374+
}

0 commit comments

Comments
 (0)