Skip to content

Commit c662c10

Browse files
committed
ASTScope: Use visitParsedAccessors() instead of getAllAccessors()
1 parent 85ae227 commit c662c10

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -965,15 +965,6 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
965965
// Accessors are always nested within their abstract storage
966966
// declaration. The nesting may not be immediate, because subscripts may
967967
// 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-
});
977968

978969
// Create scopes for `@differentiable` attributes.
979970
forEachDifferentiableAttrInSourceOrder(
@@ -982,9 +973,15 @@ void ScopeCreator::addChildrenForAllLocalizableAccessorsInSourceOrder(
982973
parent, diffAttr, asd);
983974
});
984975

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+
});
988985
}
989986

990987
#pragma mark creation helpers
@@ -1600,8 +1597,12 @@ AbstractPatternEntryScope::AbstractPatternEntryScope(
16001597
void AbstractPatternEntryScope::forEachVarDeclWithLocalizableAccessors(
16011598
ScopeCreator &scopeCreator, function_ref<void(VarDecl *)> foundOne) const {
16021599
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)
16051606
foundOne(var);
16061607
});
16071608
}
@@ -1930,9 +1931,11 @@ class LocalizableDeclContextCollector : public ASTWalker {
19301931
record(pd->getDefaultArgumentInitContext());
19311932
else if (auto *pbd = dyn_cast<PatternBindingDecl>(D))
19321933
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) {
19351936
ad->walk(*this);
1937+
});
1938+
}
19361939
return ASTWalker::walkToDeclPre(D);
19371940
}
19381941

lib/AST/ASTScopeLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ bool DifferentiableAttributeScope::lookupLocalsOrMembers(
371371
if (auto *afd = dyn_cast<AbstractFunctionDecl>(attributedDeclaration)) {
372372
return visitAbstractFunctionDecl(afd);
373373
} else if (auto *asd = dyn_cast<AbstractStorageDecl>(attributedDeclaration)) {
374-
for (auto *accessor : asd->getAllAccessors())
374+
if (auto *accessor = asd->getParsedAccessor(AccessorKind::Get))
375375
if (visitAbstractFunctionDecl(accessor))
376376
return true;
377377
}

0 commit comments

Comments
 (0)