Commit Graph

2 Commits

Author SHA1 Message Date
Michael Gottesman
20c3e1e92f [semantic-sil] Update 45 SILGen tests for ownership.
Very roughly this increases the total coverage of SILGen tests with ownership
enabled to ~20%.

rdar://33358110
2017-08-20 19:11:55 -07:00
Slava Pestov
c46987a06b SIL: Use CaptureKind::Box for weak and unowned captures in noescape closures
SILGen emits 'var' bindings as mutable heap-allocated boxes,
since they might be captured by escaping closures whose
lifetime exceeds that of the function itself.

Escaping closures capture the entire box; however for noescape
closures it is sufficient to capture only the address projected
from the box, because usually the box outlives the closure.

The one exception though is if the binding is introduced by
a capture list. In this case, the closure would outlive the box,
resulting in the contents of the box being released before the
closure was invoked.

Normally, capture lists cannot introduce 'var' bindings; the
one exception is when capturing a reference as 'weak'.

Fix the problem by capturing such bindings as a box and not as a
projection, even for noescape closures.

Fixes <rdar://problem/32718153>.
2017-06-13 15:11:46 -07:00