Skip to content

Commit 3103be6

Browse files
committed
Update SILGen for mutate accessors
1 parent 10925c4 commit 3103be6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5706,7 +5706,8 @@ std::optional<ManagedValue>
57065706
SILGenFunction::tryEmitProjectedLValue(SILLocation loc, LValue &&src,
57075707
TSanKind tsanKind) {
57085708
assert(src.getAccessKind() == SGFAccessKind::BorrowedAddressRead ||
5709-
src.getAccessKind() == SGFAccessKind::BorrowedObjectRead);
5709+
src.getAccessKind() == SGFAccessKind::BorrowedObjectRead ||
5710+
src.getAccessKind() == SGFAccessKind::Write);
57105711

57115712
for (auto component = src.begin(); component != src.end(); component++) {
57125713
if (component->get()->getKind() != PathComponent::BorrowMutateKind &&

lib/SILGen/SILGenStmt.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@ SILValue SILGenFunction::emitUncheckedGuaranteedConversion(SILValue value) {
726726
bool SILGenFunction::emitGuaranteedReturn(
727727
SILLocation loc, Expr *ret, SmallVectorImpl<SILValue> &directResults) {
728728
auto *afd = cast<AbstractFunctionDecl>(FunctionDC->getAsDecl());
729-
assert(cast<AccessorDecl>(afd)->isBorrowAccessor());
730-
729+
assert(cast<AccessorDecl>(afd)->isBorrowAccessor() ||
730+
cast<AccessorDecl>(afd)->isMutateAccessor());
731731

732732
auto emitLoadBorrowFromGuaranteedAddress =
733733
[&](ManagedValue guaranteedAddress) -> SILValue {
@@ -762,13 +762,25 @@ bool SILGenFunction::emitGuaranteedReturn(
762762
// Emit return value at +0.
763763
FormalEvaluationScope scope(*this);
764764
LValueOptions options;
765+
766+
if (cast<AccessorDecl>(afd)->isMutateAccessor()) {
767+
options = options.forGuaranteedAddressReturn(true);
768+
} else {
769+
assert(cast<AccessorDecl>(afd)->isBorrowAccessor());
770+
if (F.getSelfArgument()->getType().isObject()) {
771+
options = options.forGuaranteedReturn(true);
772+
} else {
773+
options = options.forGuaranteedAddressReturn(true);
774+
}
775+
}
776+
765777
auto lvalue = emitLValue(ret,
766778
F.getSelfArgument()->getType().isObject()
767779
? SGFAccessKind::BorrowedObjectRead
768-
: SGFAccessKind::BorrowedAddressRead,
769-
F.getSelfArgument()->getType().isObject()
770-
? options.forGuaranteedReturn(true)
771-
: options.forGuaranteedAddressReturn(true));
780+
: cast<AccessorDecl>(afd)->isBorrowAccessor()
781+
? SGFAccessKind::BorrowedAddressRead
782+
: SGFAccessKind::Write,
783+
options);
772784

773785
// If the accessor is annotated with @_unsafeSelfDependentResultAttr,
774786
// disable diagnosing the return expression.

0 commit comments

Comments
 (0)