Skip to content

[5.9] ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible. #66779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jckarter
Copy link
Contributor

Issue: rdar://110137169
• Explanation: Fixes a bug where attempting to capture a noncopyable value in a nonescaping closure would be incorrectly rejected.
• Scope of Issue: Fixes an incorrect diagnostic on correct code.
• Origination: Noncopyable types feature work
• Risk: Low. The change is focused to only affect noncopyable types, so existing code won't be affected.
• Reviewed By: @atrick and @gottesmm
• Automated Testing: Swift CI
• Dependencies: None
• Builder Impact: Not applicable
• Directions for QE: None

…aptures when possible.

SILGen introduces a copy of the capture, because the semantics of escaping partial_apply's
requires the closure to take ownership of the parameters. We don't know when a closure is
strictly nonescaping or its final lifetime until ClosureLifetimeFixup runs, but that replaces
the consume of the copy with a borrow of the copy normally, hoping later passes fix it up.
We can't wait that long for move-only types, which can't be copied, so try to remove the
copy up front when the copy lives long enough and has no interfering uses other than the
partial_apply. rdar://110137169
@jckarter jckarter requested a review from a team as a code owner June 20, 2023 19:42
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter merged commit 2d1cbb6 into swiftlang:release/5.9 Jun 21, 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.

2 participants