Skip to content

Commit 76dc6e1

Browse files
committed
[NFC] Cache preexisting synthesized accessor.
Move the bailout from getSynthesizedAccessor from the wrapper function into the evaluate body. Will enable the request to do work on non-synthesized accessors, which is required to provide a default implementation for modify2 and read2 members.
1 parent f6e145e commit 76dc6e1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,10 +3050,8 @@ bool AbstractStorageDecl::requiresOpaqueModify2Coroutine() const {
30503050
false);
30513051
}
30523052

3053-
AccessorDecl *AbstractStorageDecl::getSynthesizedAccessor(AccessorKind kind) const {
3054-
if (auto *accessor = getAccessor(kind))
3055-
return accessor;
3056-
3053+
AccessorDecl *
3054+
AbstractStorageDecl::getSynthesizedAccessor(AccessorKind kind) const {
30573055
ASTContext &ctx = getASTContext();
30583056
return evaluateOrDefault(ctx.evaluator,
30593057
SynthesizeAccessorRequest{const_cast<AbstractStorageDecl *>(this), kind},
@@ -7112,7 +7110,10 @@ void AbstractStorageDecl::setComputedSetter(AccessorDecl *setter) {
71127110
void
71137111
AbstractStorageDecl::setSynthesizedAccessor(AccessorKind kind,
71147112
AccessorDecl *accessor) {
7115-
assert(!getAccessor(kind) && "accessor already exists");
7113+
if (auto *current = getAccessor(kind)) {
7114+
assert(current == accessor && "different accessor of this kind exists");
7115+
return;
7116+
}
71167117
assert(accessor->getAccessorKind() == kind);
71177118

71187119
auto accessors = Accessors.getPointer();

lib/Sema/TypeCheckStorage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,10 @@ SynthesizeAccessorRequest::evaluate(Evaluator &evaluator,
26302630
AccessorKind kind) const {
26312631
auto &ctx = storage->getASTContext();
26322632

2633+
if (auto *accessor = storage->getAccessor(kind)) {
2634+
return accessor;
2635+
}
2636+
26332637
switch (kind) {
26342638
case AccessorKind::Get:
26352639
case AccessorKind::DistributedGet:

0 commit comments

Comments
 (0)