mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SILGen: Unwrap @moveOnly wrapped values before yielding them.
This commit is contained in:
@@ -6011,8 +6011,18 @@ void SILGenFunction::emitRawYield(SILLocation loc,
|
|||||||
JumpDest unwindDest,
|
JumpDest unwindDest,
|
||||||
bool isUniqueYield) {
|
bool isUniqueYield) {
|
||||||
SmallVector<SILValue, 4> yieldValues;
|
SmallVector<SILValue, 4> yieldValues;
|
||||||
for (auto arg : yieldArgs)
|
for (auto arg : yieldArgs) {
|
||||||
yieldValues.push_back(arg.getValue());
|
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.
|
// The normal continuation block.
|
||||||
auto resumeBB = createBasicBlock();
|
auto resumeBB = createBasicBlock();
|
||||||
|
|||||||
20
test/SILGen/yield_borrowing.swift
Normal file
20
test/SILGen/yield_borrowing.swift
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -299,10 +299,6 @@ extension List {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
|
|
||||||
off
|
|
||||||
|
|
||||||
var head: Element {
|
var head: Element {
|
||||||
_read {
|
_read {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -313,7 +309,6 @@ extension List {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ChonkyList {
|
extension ChonkyList {
|
||||||
@@ -335,10 +330,6 @@ extension ChonkyList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
|
|
||||||
off
|
|
||||||
|
|
||||||
var head: Element {
|
var head: Element {
|
||||||
_read {
|
_read {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -349,6 +340,5 @@ extension ChonkyList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user