@@ -273,11 +273,6 @@ class ScopeCreator final {
273273 // Implicit nodes may not have source information for name lookup.
274274 if (!isLocalizable (d))
275275 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
281276
282277 // Commented out for
283278 // validation-test/compiler_crashers_fixed/27962-swift-rebindselfinconstructorexpr-getcalledconstructor.swift
@@ -502,9 +497,6 @@ class ScopeCreator final {
502497 std::vector<ASTNode> expandIfConfigClausesThenCullAndSortElementsOrMembers (
503498 ArrayRef<ASTNode> input) const {
504499 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);
508500 return cleanedupNodes;
509501 }
510502
@@ -562,73 +554,6 @@ class ScopeCreator final {
562554 return culled;
563555 }
564556
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-
632557 // / Templated to work on either ASTNodes, Decl*'s, or whatnot.
633558 template <typename Rangeable>
634559 std::vector<Rangeable>
@@ -962,24 +887,6 @@ class NodeAdder
962887 : DeclVisibilityKind::LocalVariable;
963888 auto *insertionPoint = parentScope;
964889 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- }
983890 insertionPoint =
984891 scopeCreator
985892 .ifUniqueConstructExpandAndInsert <PatternEntryDeclScope>(
@@ -1058,15 +965,6 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
1058965 // Accessors are always nested within their abstract storage
1059966 // declaration. The nesting may not be immediate, because subscripts may
1060967 // 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- });
1070968
1071969 // Create scopes for `@differentiable` attributes.
1072970 forEachDifferentiableAttrInSourceOrder (
@@ -1075,9 +973,15 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
1075973 parent, diffAttr, asd);
1076974 });
1077975
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+ });
1081985}
1082986
1083987#pragma mark creation helpers
@@ -1693,8 +1597,12 @@ AbstractPatternEntryScope::AbstractPatternEntryScope(
16931597void AbstractPatternEntryScope::forEachVarDeclWithLocalizableAccessors (
16941598 ScopeCreator &scopeCreator, function_ref<void (VarDecl *)> foundOne) const {
16951599 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)
16981606 foundOne (var);
16991607 });
17001608}
@@ -2023,9 +1931,11 @@ class LocalizableDeclContextCollector : public ASTWalker {
20231931 record (pd->getDefaultArgumentInitContext ());
20241932 else if (auto *pbd = dyn_cast<PatternBindingDecl>(D))
20251933 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) {
20281936 ad->walk (*this );
1937+ });
1938+ }
20291939 return ASTWalker::walkToDeclPre (D);
20301940 }
20311941
0 commit comments