[4.2] Implement verification that noescape closures passed to Objecti… #16348
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…ve-C are not escaped
The series of commit introduces a
copy_block_without_escaping
blockinstruction that ties a swift closure sentinel to the block that is
escaped.
SILGen emits this instruction when it generates a conversion from a
@noescape
swift closure to a block.The ClosureLifetimeFixup pass then lowers
copy_block_without_escaping
into acopy_block
andis_escaping
/cond_fail
/destroy_value
combination at a pointthat succeeds the end of the block's lifetime.
As a result whenever a semantic noescape Swift closure synchronously
escapes to Objective C we will trap with an error after we return from
the Objective C call.
rdar://39682865
Cherry-pick of #16236
Commits:
Mandatory pass will clean it up and replace it by a copy_block and
is_escaping/cond_fail/release combination on the %closure in follow-up
patches.
The instruction marks the dependence of a block on a closure that is
used as an 'withoutActuallyEscaping' sentinel.
SIL: Allow is_escaping_closure on optional closure types
SILGen: Emit withoutActuallyEscaping verification for @NoEscape closures stored in blocks
SIL: Add getSingleDealloc to AllocStack and remove two copies of it
I am going to introduce a third use in a follow-up
Replace:
%copy = copy_block_without_escaping %block withoutEscaping %closure
...
destroy_value %copy
by (roughly) the instruction sequence:
%copy = copy_block %block
...
destroy_value %copy
%e = is_escaping %closure
cond_fail %e
destroy_value %closure
After the copy_block_without_actually_escaping change it might see a
mark_dependence instruction on a noescape closure.
The pattern we see for noescape closure passed to objective c is different:
There is the additional without actually escaping closure sentinel.
Fix test cases after SIL representation changes
Executable test case for passing a noescape closure to Objective-c which
escapes the closure.
We expect the program to crash with an explanation.
Objective C closures when reporting that a closure has escaped
rdar://39682865
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.