Skip to content

Move-only-check the result of modify coroutines. #70404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4913,6 +4913,10 @@ SILGenFunction::emitBeginApply(SILLocation loc, ManagedValue fn,
auto value = yieldValues[i];
auto info = yieldInfos[i];
if (info.isIndirectInOut()) {
if (value->getType().isMoveOnly()) {
value = B.createMarkUnresolvedNonCopyableValueInst(loc, value,
MarkUnresolvedNonCopyableValueInst::CheckKind::ConsumableAndAssignable);
}
yields.push_back(ManagedValue::forLValue(value));
} else if (info.isConsumed()) {
if (value->getType().isMoveOnly()) {
Expand Down
3 changes: 3 additions & 0 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ static bool isInOutDefThatNeedsEndOfFunctionLiveness(
return true;
}
}
if (auto bai = dyn_cast_or_null<BeginApplyInst>(operand->getDefiningInstruction())) {
return true;
}
}

return false;
Expand Down
36 changes: 36 additions & 0 deletions test/Interpreter/moveonly_read_modify_coroutines.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %target-run-simple-swift | %FileCheck %s
// REQUIRES: executable_test

struct NC: ~Copyable {
deinit { print("destroy") }
}

class C {
private var _data: NC = NC()

var data: NC {
_read { yield _data }
_modify { yield &_data }
}
}

func borrow(_ nc: borrowing NC) {}
func mod(_ nc: inout NC) {}

defer {
// CHECK: starting
print("starting")
do {
// CHECK-NEXT: destroy
test(C())
}
// CHECK: done
print("done")
}
func test(_ c: C) {
borrow(c.data)
borrow(c.data)

mod(&c.data)
mod(&c.data)
}
Loading