@@ -965,15 +965,6 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
965
965
// Accessors are always nested within their abstract storage
966
966
// declaration. The nesting may not be immediate, because subscripts may
967
967
// have intervening scopes for generics.
968
- AbstractStorageDecl *const enclosingAbstractStorageDecl =
969
- parent->getEnclosingAbstractStorageDecl ().get ();
970
-
971
- std::vector<AccessorDecl *> accessorsToScope;
972
- // Assume we don't have to deal with inactive clauses of IfConfigs here
973
- llvm::copy_if (asd->getAllAccessors (), std::back_inserter (accessorsToScope),
974
- [&](AccessorDecl *ad) {
975
- return enclosingAbstractStorageDecl == ad->getStorage ();
976
- });
977
968
978
969
// Create scopes for `@differentiable` attributes.
979
970
forEachDifferentiableAttrInSourceOrder (
@@ -982,9 +973,15 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
982
973
parent, diffAttr, asd);
983
974
});
984
975
985
- // Sort in order to include synthesized ones, which are out of order.
986
- for (auto *accessor : sortBySourceRange (accessorsToScope))
987
- 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
+ });
988
985
}
989
986
990
987
#pragma mark creation helpers
@@ -1600,8 +1597,12 @@ AbstractPatternEntryScope::AbstractPatternEntryScope(
1600
1597
void AbstractPatternEntryScope::forEachVarDeclWithLocalizableAccessors (
1601
1598
ScopeCreator &scopeCreator, function_ref<void (VarDecl *)> foundOne) const {
1602
1599
getPatternEntry ().getPattern ()->forEachVariable ([&](VarDecl *var) {
1603
- if (llvm::any_of (var->getAllAccessors (),
1604
- [&](AccessorDecl *a) { return isLocalizable (a); }))
1600
+ bool hasParsedAccessors = false ;
1601
+ var->visitParsedAccessors ([&](AccessorDecl *) {
1602
+ hasParsedAccessors = true ;
1603
+ });
1604
+
1605
+ if (hasParsedAccessors)
1605
1606
foundOne (var);
1606
1607
});
1607
1608
}
@@ -1930,9 +1931,11 @@ class LocalizableDeclContextCollector : public ASTWalker {
1930
1931
record (pd->getDefaultArgumentInitContext ());
1931
1932
else if (auto *pbd = dyn_cast<PatternBindingDecl>(D))
1932
1933
recordInitializers (pbd);
1933
- else if (auto *vd = dyn_cast<VarDecl>(D))
1934
- for ( auto *ad : vd->getAllAccessors ())
1934
+ else if (auto *vd = dyn_cast<VarDecl>(D)) {
1935
+ vd->visitParsedAccessors ([&](AccessorDecl *ad) {
1935
1936
ad->walk (*this );
1937
+ });
1938
+ }
1936
1939
return ASTWalker::walkToDeclPre (D);
1937
1940
}
1938
1941
0 commit comments