Skip to content

Conversation

jckarter
Copy link
Contributor

@jckarter jckarter commented Jul 12, 2023

Issue: rdar://111563642
Explanation: When a literal closure is passed into a generic context that takes an (inout T) -> () function argument, we emit the closure literal with the abstraction pattern expected by the callee, but when T was itself a function type, we failed to handle the abstraction difference of the inout parameter locally, leading to compiler crashes. This patch fixes that by having the closure perform reabstraction on the initial value going in, storing it to a local buffer to represent the inout parameter locally, then reabstracting back to the expected representation and writing back to the original inout parameter.
Scope of Issue: Fixes a regression.
Origination: Last year's thunk elimination optimizations.
Risk: Low. The fix is targeted to a relatively rare situation, which currently crashes the compiler, and should have minimal effect on other code.
Reviewed by: @atrick
Cherry picked from: #67239

… in a more abstract closure literal context.

When we emit closure literals in the context of a generic parameter, the parameters of the
closure may be more abstract than they would normally be for the closure's abstract type.
We handled this by reabstracting value parameters to their usual substituted representation
in the prolog, but neglected to do so for `inout` parameters too. In this case, we need to take
the initial value, reabstract it to provide a local variable with the substituted representation,
and then take the final value, reabstract it back, and write back to the original inout parameter
on function exit.

Fixes rdar://111563642.
@jckarter jckarter requested a review from a team as a code owner July 12, 2023 15:57
@jckarter
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jckarter jckarter merged commit eda4d7a into swiftlang:release/5.9 Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants