@@ -180,62 +180,6 @@ class ScopeCreator final {
180
180
addToScopeTreeAndReturnInsertionPoint (ASTNode, ASTScopeImpl *parent,
181
181
Optional<SourceLoc> endLoc);
182
182
183
- bool isWorthTryingToCreateScopeFor (ASTNode n) const {
184
- if (!n)
185
- return false ;
186
- if (n.is <Expr *>())
187
- return true ;
188
- // Cannot ignore implicit statements because implict return can contain
189
- // scopes in the expression, such as closures.
190
- // But must ignore other implicit statements, e.g. brace statments
191
- // if they can have no children and no stmt source range.
192
- // Deal with it in visitBraceStmt
193
- if (n.is <Stmt *>())
194
- return true ;
195
-
196
- auto *const d = n.get <Decl *>();
197
- // Implicit nodes may not have source information for name lookup.
198
- if (!isLocalizable (d))
199
- return false ;
200
-
201
- // Commented out for
202
- // validation-test/compiler_crashers_fixed/27962-swift-rebindselfinconstructorexpr-getcalledconstructor.swift
203
- // In that test the invalid PBD -> var decl which contains the desired
204
- // closure scope
205
- // if (const auto *PBD = dyn_cast<PatternBindingDecl>(d))
206
- // if (!isLocalizable(PBD))
207
- // return false;
208
- // / In
209
- // / \code
210
- // / @propertyWrapper
211
- // / public struct Wrapper<T> {
212
- // / public var value: T
213
- // /
214
- // / public init(body: () -> T) {
215
- // / self.value = body()
216
- // / }
217
- // / }
218
- // /
219
- // / let globalInt = 17
220
- // /
221
- // / @Wrapper(body: { globalInt })
222
- // / public var y: Int
223
- // / \endcode
224
- // / I'm seeing a dumped AST include:
225
- // / (pattern_binding_decl range=[test.swift:13:8 - line:12:29]
226
- const auto &SM = d->getASTContext ().SourceMgr ;
227
-
228
- // Once we allow invalid PatternBindingDecls (see
229
- // isWorthTryingToCreateScopeFor), then
230
- // IDE/complete_property_delegate_attribute.swift fails because we try to
231
- // expand a member whose source range is backwards.
232
- (void )SM;
233
- ASTScopeAssert (d->getStartLoc ().isInvalid () ||
234
- !SM.isBeforeInBuffer (d->getEndLoc (), d->getStartLoc ()),
235
- " end-before-start will break tree search via location" );
236
- return true ;
237
- }
238
-
239
183
template <typename Scope, typename ... Args>
240
184
ASTScopeImpl *constructExpandAndInsert (ASTScopeImpl *parent, Args... args) {
241
185
auto *child = new (ctx) Scope (args...);
@@ -339,26 +283,6 @@ class ScopeCreator final {
339
283
ASTScopeImpl *parent,
340
284
Optional<SourceLoc> endLoc);
341
285
342
- // / Remove VarDecls because we'll find them when we expand the
343
- // / PatternBindingDecls. Remove EnunCases
344
- // / because they overlap EnumElements and AST includes the elements in the
345
- // / members.
346
- std::vector<ASTNode> cull (ArrayRef<ASTNode> input) const {
347
- // TODO: Investigate whether to move the real EndLoc tracking of
348
- // SubscriptDecl up into AbstractStorageDecl. May have to cull more.
349
- std::vector<ASTNode> culled;
350
- llvm::copy_if (input, std::back_inserter (culled), [&](ASTNode n) {
351
- ASTScopeAssert (
352
- !n.isDecl (DeclKind::Accessor),
353
- " Should not find accessors in iterable types or brace statements" );
354
- return isLocalizable (n) &&
355
- !n.isDecl (DeclKind::Var) &&
356
- !n.isDecl (DeclKind::EnumCase) &&
357
- !n.isDecl (DeclKind::IfConfig);
358
- });
359
- return culled;
360
- }
361
-
362
286
SWIFT_DEBUG_DUMP { print (llvm::errs ()); }
363
287
364
288
void print (raw_ostream &out) const {
@@ -466,6 +390,10 @@ class NodeAdder
466
390
VISIT_AND_IGNORE (PoundDiagnosticDecl)
467
391
VISIT_AND_IGNORE (MissingMemberDecl)
468
392
393
+ // Only members of the active clause are in scope, and those
394
+ // are visited separately.
395
+ VISIT_AND_IGNORE (IfConfigDecl)
396
+
469
397
// This declaration is handled from the PatternBindingDecl
470
398
VISIT_AND_IGNORE (VarDecl)
471
399
@@ -612,14 +540,6 @@ class NodeAdder
612
540
return p;
613
541
}
614
542
615
- ASTScopeImpl *visitIfConfigDecl (IfConfigDecl *icd,
616
- ASTScopeImpl *p,
617
- ScopeCreator &scopeCreator) {
618
- ASTScope_unreachable (
619
- " Should be handled inside of "
620
- " expandIfConfigClausesThenCullAndSortElementsOrMembers" );
621
- }
622
-
623
543
ASTScopeImpl *visitReturnStmt (ReturnStmt *rs, ASTScopeImpl *p,
624
544
ScopeCreator &scopeCreator) {
625
545
if (rs->hasResult ())
@@ -657,9 +577,13 @@ ASTScopeImpl *
657
577
ScopeCreator::addToScopeTreeAndReturnInsertionPoint (ASTNode n,
658
578
ASTScopeImpl *parent,
659
579
Optional<SourceLoc> endLoc) {
660
- if (!isWorthTryingToCreateScopeFor (n) )
580
+ if (!n )
661
581
return parent;
662
582
583
+ if (auto *d = n.dyn_cast <Decl *>())
584
+ if (d->isImplicit ())
585
+ return parent;
586
+
663
587
NodeAdder adder (endLoc);
664
588
if (auto *p = n.dyn_cast <Decl *>())
665
589
return adder.visit (p, parent, *this );
@@ -874,8 +798,7 @@ ASTSourceFileScope::expandAScopeThatCreatesANewInsertionPoint(
874
798
std::vector<ASTNode> newNodes (decls.begin (), decls.end ());
875
799
insertionPoint =
876
800
scopeCreator.addSiblingsToScopeTree (insertionPoint,
877
- scopeCreator.cull (newNodes),
878
- endLoc);
801
+ newNodes, endLoc);
879
802
880
803
// Too slow to perform all the time:
881
804
// ASTScopeAssert(scopeCreator->containsAllDeclContextsFromAST(),
@@ -1002,8 +925,7 @@ BraceStmtScope::expandAScopeThatCreatesANewInsertionPoint(
1002
925
// elements in source order
1003
926
auto *insertionPoint =
1004
927
scopeCreator.addSiblingsToScopeTree (this ,
1005
- scopeCreator.cull (
1006
- stmt->getElements ()),
928
+ stmt->getElements (),
1007
929
endLoc);
1008
930
if (auto *s = scopeCreator.getASTContext ().Stats )
1009
931
++s->getFrontendCounters ().NumBraceStmtASTScopeExpansions ;
@@ -1365,7 +1287,6 @@ void GenericTypeOrExtensionScope::expandBody(ScopeCreator &) {}
1365
1287
1366
1288
void IterableTypeScope::expandBody (ScopeCreator &scopeCreator) {
1367
1289
auto nodes = asNodeVector (getIterableDeclContext ().get ()->getMembers ());
1368
- nodes = scopeCreator.cull (nodes);
1369
1290
scopeCreator.addSiblingsToScopeTree (this , nodes, None);
1370
1291
if (auto *s = scopeCreator.getASTContext ().Stats )
1371
1292
++s->getFrontendCounters ().NumIterableTypeBodyASTScopeExpansions ;
0 commit comments