Skip to content

Commit 88192ff

Browse files
committed
SILGen: Unwrap @moveOnly wrapped values before yielding them.
1 parent 0491755 commit 88192ff

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
@@ -6011,8 +6011,18 @@ void SILGenFunction::emitRawYield(SILLocation loc,
60116011
JumpDest unwindDest,
60126012
bool isUniqueYield) {
60136013
SmallVector<SILValue, 4> yieldValues;
6014-
for (auto arg : yieldArgs)
6015-
yieldValues.push_back(arg.getValue());
6014+
for (auto arg : yieldArgs) {
6015+
auto value = arg.getValue();
6016+
if (value->getType().isMoveOnlyWrapped()) {
6017+
if (value->getType().isAddress()) {
6018+
value = B.createMoveOnlyWrapperToCopyableAddr(loc, value);
6019+
} else {
6020+
value = B.createGuaranteedMoveOnlyWrapperToCopyableValue(loc, value);
6021+
}
6022+
}
6023+
6024+
yieldValues.push_back(value);
6025+
}
60166026

60176027
// The normal continuation block.
60186028
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
@@ -299,10 +299,6 @@ extension List {
299299
}
300300
}
301301

302-
/*
303-
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
304-
off
305-
306302
var head: Element {
307303
_read {
308304
switch self {
@@ -313,7 +309,6 @@ extension List {
313309
}
314310
}
315311
}
316-
*/
317312
}
318313

319314
extension ChonkyList {
@@ -335,10 +330,6 @@ extension ChonkyList {
335330
}
336331
}
337332

338-
/*
339-
TODO: type mismatch because of `@moveOnly` wrapper. yield needs to peel it
340-
off
341-
342333
var head: Element {
343334
_read {
344335
switch self {
@@ -349,6 +340,5 @@ extension ChonkyList {
349340
}
350341
}
351342
}
352-
*/
353343
}
354344

0 commit comments

Comments
 (0)