Skip to content

Commit 0ad792f

Browse files
committed
SILGen: Add explicit 'self' metadata parameter when 'self' is a mutable capture
If a closure uses DynamicSelfType but doesn't capture the 'self' value itself, we would add a dummy metatype capture so that IRGen can recover metadata. Also do this if we do capture a value of DynamicSelfType, but mutably, that is by address or by box, since IRGen doesn't know how to recover the metadata in that case. Fixes <rdar://problem/32288771>.
1 parent 84ed245 commit 0ad792f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,11 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
21312131

21322132
// We're capturing a 'self' value with dynamic 'Self' type;
21332133
// handle it specially.
2134-
if (captureType->getClassOrBoundGenericClass()) {
2134+
//
2135+
// However, only do this if its a 'let'; if the capture is
2136+
// mutable, we're going to be capturing a box or an address.
2137+
if (captureType->getClassOrBoundGenericClass() &&
2138+
capturedVar->isLet()) {
21352139
if (selfCapture)
21362140
selfCapture = selfCapture->mergeFlags(capture);
21372141
else

test/SILGen/dynamic_self.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ class Z {
229229
fn0()
230230

231231
var x = self
232-
let fn1 = { _ = x }
232+
let fn1 = { _ = x; _ = { _ = x } }
233233
fn1()
234234

235235
var xx = (self, self)
236-
let fn2 = { _ = xx }
236+
let fn2 = { _ = xx; _ = { _ = xx } }
237237
fn2()
238238

239239
return self.init()

0 commit comments

Comments
 (0)