SILGen: Unwrap @moveOnly wrapped values before yielding them.

This commit is contained in:
Joe Groff
2024-02-20 16:40:36 -08:00
parent 0491755de9
commit 88192ffb70
3 changed files with 32 additions and 12 deletions

View File

@@ -6011,8 +6011,18 @@ void SILGenFunction::emitRawYield(SILLocation loc,
JumpDest unwindDest,
bool isUniqueYield) {
SmallVector<SILValue, 4> yieldValues;
for (auto arg : yieldArgs)
yieldValues.push_back(arg.getValue());
for (auto arg : yieldArgs) {
auto value = arg.getValue();
if (value->getType().isMoveOnlyWrapped()) {
if (value->getType().isAddress()) {
value = B.createMoveOnlyWrapperToCopyableAddr(loc, value);
} else {
value = B.createGuaranteedMoveOnlyWrapperToCopyableValue(loc, value);
}
}
yieldValues.push_back(value);
}
// The normal continuation block.
auto resumeBB = createBasicBlock();

View File

@@ -0,0 +1,20 @@
// RUN: %target-swift-emit-silgen -verify %s
struct Foo {
var x: String
var y: Foo {
borrowing _read {
yield self
}
}
}
struct BigFoo {
var x: Any
var y: BigFoo {
borrowing _read {
yield self
}
}
}

View File

@@ -299,10 +299,6 @@ extension List {
}
}
/*
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
off
var head: Element {
_read {
switch self {
@@ -313,7 +309,6 @@ extension List {
}
}
}
*/
}
extension ChonkyList {
@@ -335,10 +330,6 @@ extension ChonkyList {
}
}
/*
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
off
var head: Element {
_read {
switch self {
@@ -349,6 +340,5 @@ extension ChonkyList {
}
}
}
*/
}