[5.9] SILGen: Provide a reabstracted writeback for inout parameters emitted in a more abstract closure literal context. #67251
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.
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 whenT
was itself a function type, we failed to handle the abstraction difference of theinout
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