Skip to content

Commit 165b3e8

Browse files
authored
Merge pull request #71784 from jckarter/move-only-wrapped-yield
SILGen: Unwrap `@moveOnly` wrapped values before yielding them.
2 parents dfe9d33 + 88192ff commit 165b3e8

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5992,8 +5992,18 @@ void SILGenFunction::emitRawYield(SILLocation loc,
59925992
JumpDest unwindDest,
59935993
bool isUniqueYield) {
59945994
SmallVector<SILValue, 4> yieldValues;
5995-
for (auto arg : yieldArgs)
5996-
yieldValues.push_back(arg.getValue());
5995+
for (auto arg : yieldArgs) {
5996+
auto value = arg.getValue();
5997+
if (value->getType().isMoveOnlyWrapped()) {
5998+
if (value->getType().isAddress()) {
5999+
value = B.createMoveOnlyWrapperToCopyableAddr(loc, value);
6000+
} else {
6001+
value = B.createGuaranteedMoveOnlyWrapperToCopyableValue(loc, value);
6002+
}
6003+
}
6004+
6005+
yieldValues.push_back(value);
6006+
}
59976007

59986008
// The normal continuation block.
59996009
auto resumeBB = createBasicBlock();

test/SILGen/yield_borrowing.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-emit-silgen -verify %s
2+
struct Foo {
3+
var x: String
4+
5+
var y: Foo {
6+
borrowing _read {
7+
yield self
8+
}
9+
}
10+
}
11+
12+
struct BigFoo {
13+
var x: Any
14+
15+
var y: BigFoo {
16+
borrowing _read {
17+
yield self
18+
}
19+
}
20+
}

test/SILOptimizer/moveonly_borrowing_switch.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ extension List {
300300
}
301301
}
302302

303-
/*
304-
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
305-
off
306-
307303
var head: Element {
308304
_read {
309305
switch self {
@@ -314,7 +310,6 @@ extension List {
314310
}
315311
}
316312
}
317-
*/
318313
}
319314

320315
extension ChonkyList {
@@ -336,10 +331,6 @@ extension ChonkyList {
336331
}
337332
}
338333

339-
/*
340-
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
341-
off
342-
343334
var head: Element {
344335
_read {
345336
switch self {
@@ -350,5 +341,4 @@ extension ChonkyList {
350341
}
351342
}
352343
}
353-
*/
354344
}

0 commit comments

Comments
 (0)