@@ -218,7 +218,7 @@ class ScopeCreator final {
218218 ASTScopeImpl *const organicInsertionPoint,
219219 ArrayRef<ASTNode> nodesOrDeclsToAdd) {
220220 auto *ip = insertionPoint;
221- for (auto nd : sortBySourceRange ( cull ( nodesOrDeclsToAdd)) ) {
221+ for (auto nd : nodesOrDeclsToAdd) {
222222 auto *const newIP =
223223 addToScopeTreeAndReturnInsertionPoint (nd, ip).getPtrOr (ip);
224224 ip = newIP;
@@ -419,9 +419,6 @@ class ScopeCreator final {
419419 void addChildrenForKnownAttributes (ValueDecl *decl,
420420 ASTScopeImpl *parent);
421421
422- public:
423-
424- private:
425422 // / Remove VarDecls because we'll find them when we expand the
426423 // / PatternBindingDecls. Remove EnunCases
427424 // / because they overlap EnumElements and AST includes the elements in the
@@ -463,7 +460,6 @@ class ScopeCreator final {
463460 return -1 == signum;
464461 }
465462
466- public:
467463 SWIFT_DEBUG_DUMP { print (llvm::errs ()); }
468464
469465 void print (raw_ostream &out) const {
@@ -950,7 +946,9 @@ ASTSourceFileScope::expandAScopeThatCreatesANewInsertionPoint(
950946 // Assume that decls are only added at the end, in source order
951947 std::vector<ASTNode> newNodes (decls.begin (), decls.end ());
952948 insertionPoint =
953- scopeCreator.addSiblingsToScopeTree (insertionPoint, this , newNodes);
949+ scopeCreator.addSiblingsToScopeTree (insertionPoint, this ,
950+ scopeCreator.sortBySourceRange (
951+ scopeCreator.cull (newNodes)));
954952 // Too slow to perform all the time:
955953 // ASTScopeAssert(scopeCreator->containsAllDeclContextsFromAST(),
956954 // "ASTScope tree missed some DeclContexts or made some up");
@@ -1068,7 +1066,10 @@ BraceStmtScope::expandAScopeThatCreatesANewInsertionPoint(
10681066 // TODO: remove the sort after fixing parser to create brace statement
10691067 // elements in source order
10701068 auto *insertionPoint =
1071- scopeCreator.addSiblingsToScopeTree (this , this , stmt->getElements ());
1069+ scopeCreator.addSiblingsToScopeTree (this , this ,
1070+ scopeCreator.sortBySourceRange (
1071+ scopeCreator.cull (
1072+ stmt->getElements ())));
10721073 if (auto *s = scopeCreator.getASTContext ().Stats )
10731074 ++s->getFrontendCounters ().NumBraceStmtASTScopeExpansions ;
10741075 return {
@@ -1414,6 +1415,7 @@ void GenericTypeOrExtensionScope::expandBody(ScopeCreator &) {}
14141415
14151416void IterableTypeScope::expandBody (ScopeCreator &scopeCreator) {
14161417 auto nodes = asNodeVector (getIterableDeclContext ().get ()->getMembers ());
1418+ nodes = scopeCreator.sortBySourceRange (scopeCreator.cull (nodes));
14171419 scopeCreator.addSiblingsToScopeTree (this , this , nodes);
14181420 if (auto *s = scopeCreator.getASTContext ().Stats )
14191421 ++s->getFrontendCounters ().NumIterableTypeBodyASTScopeExpansions ;
0 commit comments