@@ -273,11 +273,6 @@ class ScopeCreator final {
273
273
// Implicit nodes may not have source information for name lookup.
274
274
if (!isLocalizable (d))
275
275
return false ;
276
- // / In \c Parser::parseDeclVarGetSet fake PBDs are created. Ignore them.
277
- // / Example:
278
- // / \code
279
- // / class SR10903 { static var _: Int { 0 } }
280
- // / \endcode
281
276
282
277
// Commented out for
283
278
// validation-test/compiler_crashers_fixed/27962-swift-rebindselfinconstructorexpr-getcalledconstructor.swift
@@ -502,9 +497,6 @@ class ScopeCreator final {
502
497
std::vector<ASTNode> expandIfConfigClausesThenCullAndSortElementsOrMembers (
503
498
ArrayRef<ASTNode> input) const {
504
499
auto cleanedupNodes = sortBySourceRange (cull (expandIfConfigClauses (input)));
505
- // TODO: uncomment when working on not creating two pattern binding decls at
506
- // same location.
507
- // findCollidingPatterns(cleanedupNodes);
508
500
return cleanedupNodes;
509
501
}
510
502
@@ -562,73 +554,6 @@ class ScopeCreator final {
562
554
return culled;
563
555
}
564
556
565
- // / TODO: The parser yields two decls at the same source loc with the same
566
- // / kind. TODO: me when fixing parser's proclivity to create two
567
- // / PatternBindingDecls at the same source location, then move this to
568
- // / ASTVerifier.
569
- // /
570
- // / In all cases the first pattern seems to carry the initializer, and the
571
- // / second, the accessor
572
- void findCollidingPatterns (ArrayRef<ASTNode> input) const {
573
- auto dumpPBD = [&](PatternBindingDecl *pbd, const char *which) {
574
- llvm::errs () << " *** " << which
575
- << " pbd isImplicit: " << pbd->isImplicit ()
576
- << " , #entries: " << pbd->getNumPatternEntries () << " :" ;
577
- pbd->getSourceRange ().print (llvm::errs (), pbd->getASTContext ().SourceMgr ,
578
- false );
579
- llvm::errs () << " \n " ;
580
- llvm::errs () << " init: " << pbd->getInit (0 ) << " \n " ;
581
- if (pbd->getInit (0 )) {
582
- llvm::errs () << " SR (init): " ;
583
- pbd->getInit (0 )->getSourceRange ().print (
584
- llvm::errs (), pbd->getASTContext ().SourceMgr , false );
585
- llvm::errs () << " \n " ;
586
- pbd->getInit (0 )->dump (llvm::errs (), 0 );
587
- }
588
- llvm::errs () << " vars:\n " ;
589
- pbd->getPattern (0 )->forEachVariable ([&](VarDecl *vd) {
590
- llvm::errs () << " " << vd->getName ()
591
- << " implicit: " << vd->isImplicit ()
592
- << " #accs: " << vd->getAllAccessors ().size ()
593
- << " \n SR (var):" ;
594
- vd->getSourceRange ().print (llvm::errs (), pbd->getASTContext ().SourceMgr ,
595
- false );
596
- llvm::errs () << " \n SR (braces)" ;
597
- vd->getBracesRange ().print (llvm::errs (), pbd->getASTContext ().SourceMgr ,
598
- false );
599
- llvm::errs () << " \n " ;
600
- for (auto *a : vd->getAllAccessors ()) {
601
- llvm::errs () << " SR (acc): " ;
602
- a->getSourceRange ().print (llvm::errs (),
603
- pbd->getASTContext ().SourceMgr , false );
604
- llvm::errs () << " \n " ;
605
- a->dump (llvm::errs (), 0 );
606
- }
607
- });
608
- };
609
-
610
- Decl *lastD = nullptr ;
611
- for (auto n : input) {
612
- auto *d = n.dyn_cast <Decl *>();
613
- if (!d || !lastD || lastD->getStartLoc () != d->getStartLoc () ||
614
- lastD->getKind () != d->getKind ()) {
615
- lastD = d;
616
- continue ;
617
- }
618
- if (auto *pbd = dyn_cast<PatternBindingDecl>(lastD))
619
- dumpPBD (pbd, " prev" );
620
- if (auto *pbd = dyn_cast<PatternBindingDecl>(d)) {
621
- dumpPBD (pbd, " curr" );
622
- ASTScope_unreachable (" found colliding pattern binding decls" );
623
- }
624
- llvm::errs () << " Two same kind decls at same loc: \n " ;
625
- lastD->dump (llvm::errs ());
626
- llvm::errs () << " and\n " ;
627
- d->dump (llvm::errs ());
628
- ASTScope_unreachable (" Two same kind decls; unexpected kinds" );
629
- }
630
- }
631
-
632
557
// / Templated to work on either ASTNodes, Decl*'s, or whatnot.
633
558
template <typename Rangeable>
634
559
std::vector<Rangeable>
@@ -962,24 +887,6 @@ class NodeAdder
962
887
: DeclVisibilityKind::LocalVariable;
963
888
auto *insertionPoint = parentScope;
964
889
for (auto i : range (patternBinding->getNumPatternEntries ())) {
965
- // TODO: Won't need to do so much work to avoid creating one without
966
- // a SourceRange once parser is fixed to not create two
967
- // PatternBindingDecls with same locaiton and getSourceRangeOfThisASTNode
968
- // for PatternEntryDeclScope is simplified to use the PatternEntry's
969
- // source range.
970
- if (!patternBinding->getOriginalInit (i)) {
971
- bool found = false ;
972
- patternBinding->getPattern (i)->forEachVariable ([&](VarDecl *vd) {
973
- if (!vd->isImplicit ())
974
- found = true ;
975
- else
976
- found |= llvm::any_of (vd->getAllAccessors (), [&](AccessorDecl *a) {
977
- return isLocalizable (a);
978
- });
979
- });
980
- if (!found)
981
- continue ;
982
- }
983
890
insertionPoint =
984
891
scopeCreator
985
892
.ifUniqueConstructExpandAndInsert <PatternEntryDeclScope>(
@@ -1058,15 +965,6 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
1058
965
// Accessors are always nested within their abstract storage
1059
966
// declaration. The nesting may not be immediate, because subscripts may
1060
967
// have intervening scopes for generics.
1061
- AbstractStorageDecl *const enclosingAbstractStorageDecl =
1062
- parent->getEnclosingAbstractStorageDecl ().get ();
1063
-
1064
- std::vector<AccessorDecl *> accessorsToScope;
1065
- // Assume we don't have to deal with inactive clauses of IfConfigs here
1066
- llvm::copy_if (asd->getAllAccessors (), std::back_inserter (accessorsToScope),
1067
- [&](AccessorDecl *ad) {
1068
- return enclosingAbstractStorageDecl == ad->getStorage ();
1069
- });
1070
968
1071
969
// Create scopes for `@differentiable` attributes.
1072
970
forEachDifferentiableAttrInSourceOrder (
@@ -1075,9 +973,15 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
1075
973
parent, diffAttr, asd);
1076
974
});
1077
975
1078
- // Sort in order to include synthesized ones, which are out of order.
1079
- for (auto *accessor : sortBySourceRange (accessorsToScope))
1080
- addToScopeTree (accessor, parent);
976
+ AbstractStorageDecl *enclosingAbstractStorageDecl =
977
+ parent->getEnclosingAbstractStorageDecl ().get ();
978
+
979
+ asd->visitParsedAccessors ([&](AccessorDecl *ad) {
980
+ assert (enclosingAbstractStorageDecl == ad->getStorage ());
981
+ (void ) enclosingAbstractStorageDecl;
982
+
983
+ this ->addToScopeTree (ad, parent);
984
+ });
1081
985
}
1082
986
1083
987
#pragma mark creation helpers
@@ -1693,8 +1597,12 @@ AbstractPatternEntryScope::AbstractPatternEntryScope(
1693
1597
void AbstractPatternEntryScope::forEachVarDeclWithLocalizableAccessors (
1694
1598
ScopeCreator &scopeCreator, function_ref<void (VarDecl *)> foundOne) const {
1695
1599
getPatternEntry ().getPattern ()->forEachVariable ([&](VarDecl *var) {
1696
- if (llvm::any_of (var->getAllAccessors (),
1697
- [&](AccessorDecl *a) { return isLocalizable (a); }))
1600
+ bool hasParsedAccessors = false ;
1601
+ var->visitParsedAccessors ([&](AccessorDecl *) {
1602
+ hasParsedAccessors = true ;
1603
+ });
1604
+
1605
+ if (hasParsedAccessors)
1698
1606
foundOne (var);
1699
1607
});
1700
1608
}
@@ -2023,9 +1931,11 @@ class LocalizableDeclContextCollector : public ASTWalker {
2023
1931
record (pd->getDefaultArgumentInitContext ());
2024
1932
else if (auto *pbd = dyn_cast<PatternBindingDecl>(D))
2025
1933
recordInitializers (pbd);
2026
- else if (auto *vd = dyn_cast<VarDecl>(D))
2027
- for ( auto *ad : vd->getAllAccessors ())
1934
+ else if (auto *vd = dyn_cast<VarDecl>(D)) {
1935
+ vd->visitParsedAccessors ([&](AccessorDecl *ad) {
2028
1936
ad->walk (*this );
1937
+ });
1938
+ }
2029
1939
return ASTWalker::walkToDeclPre (D);
2030
1940
}
2031
1941
0 commit comments