Skip to content

Commit 61c114c

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 b7f7f17 commit 61c114c

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
@@ -2099,7 +2099,11 @@ TypeConverter::getLoweredLocalCaptures(AnyFunctionRef fn) {
20992099

21002100
// We're capturing a 'self' value with dynamic 'Self' type;
21012101
// handle it specially.
2102-
if (captureType->getClassOrBoundGenericClass()) {
2102+
//
2103+
// However, only do this if its a 'let'; if the capture is
2104+
// mutable, we're going to be capturing a box or an address.
2105+
if (captureType->getClassOrBoundGenericClass() &&
2106+
capturedVar->isLet()) {
21032107
if (selfCapture)
21042108
selfCapture = selfCapture->mergeFlags(capture);
21052109
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)