Skip to content

Conversation

@atrick
Copy link
Contributor

@atrick atrick commented Dec 10, 2025

Fixes a bug in MandatoryDestroyHoisting where a captured value is destroyed
before a copy of the closure.

On-stack closures can be copied, and all copied uses must be within the borrow
scope of the captured operand. This is just like any other non-Escapable value,
so treat it as such by checking Value.mayEscape rather than Type.Escapable.

Originally, I wanted to make it illegal to copy of partial_apply [on_stack], but
it looks like we still allow it.

I would rather not complicate any logic yet with special handling for this
case. To fix any performance concerns, we might be able to simplify the
representation instead by banning copy_value on on-stack closures.

Fixes rdar://165850554 swift-frontend crash: While running "CopyPropagation" -
Invalid SIL provided to OSSACompleteLifetime?!)

--- CCC ---

Explanation: Fixes a bug in liveness utilities to handle copies of on-stack closures

Scope: Miscompilation at -Onone exposed by the recently added MandatoryDestroyHoisting pass

Radar/SR Issue: rdar://165850554 crash - "CopyPropagation" - Invalid SIL provided to OSSACompleteLifetime?!

main PR: #85934

Risk: Low. This one-line change makes liveness conservative for on-stack closures. This could block optimization in theory, but the pass in question is new, and improving optimization requires a larger change to the SIL representation.

Testing: Added SIL unit test.

Reviewer: Meghana Gupta

(cherry picked from commit f7c3c6f)

Fixes a bug in MandatoryDestroyHoisting where a captured value is destroyed
before a copy of the closure.

On-stack closures can be copied, and all copied uses must be within the borrow
scope of the captured operand. This is just like any other non-Escapable value,
so treat it as such by checking `Value.mayEscape` rather than `Type.Escapable`.

Originally, I wanted to make it illegal to copy of partial_apply [on_stack], but
it looks like we still allow it.

I would rather not complicate any logic yet with special handling for this
case. To fix any performance concerns, we might be able to simplify the
representation instead by banning copy_value on on-stack closures.

Fixes rdar://165850554 swift-frontend crash: While running "CopyPropagation" -
Invalid SIL provided to OSSACompleteLifetime?!)

(cherry picked from commit f7c3c6f)
@atrick atrick requested a review from a team as a code owner December 10, 2025 18:20
@atrick atrick added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.3 labels Dec 10, 2025
@atrick atrick requested review from meg-gupta and tbkka December 10, 2025 18:21
@atrick
Copy link
Contributor Author

atrick commented Dec 10, 2025

@swift-ci test

@atrick atrick enabled auto-merge December 10, 2025 20:32
@atrick
Copy link
Contributor Author

atrick commented Dec 10, 2025

@swift-ci test windows

@atrick atrick merged commit 7056b35 into swiftlang:release/6.3 Dec 11, 2025
5 checks passed
@atrick atrick deleted the 63-fix-closure-liveness branch December 11, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍒 release cherry pick Flag: Release branch cherry picks swift 6.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants