Skip to content
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

6.1: [OSSACanonicalizeGuaranteed] Don't rewrite consuming uses of move-only values. #78574

Conversation

nate-chandler
Copy link
Contributor

Explanation: Fix a miscompile which introduced a copy of a noncopyable value.

SILCombine uses the CanonicalizeBorrowScope utility to eliminate copies of guaranteed function arguments. The utility walks the def-use tree of the argument, walking through copies and moves, walking into the uses of forwarding operations, producing copies as needed for any consuming uses for the value produced by a chain of forwarding operations. These days, some forwarding operations produce noncopyable values such as struct $Noncopyable, however. If the tree included a chain like consume(struct $Noncopyable(copy(%arg))), it was previously rewritten as consume(copy(struct $Noncopyable(%arg))). This is invalid (copies of noncopyable values are invalid). Here, this is fixed by bailing out of rewriting uses of a particular def in the tree (e.g. struct $Noncopyable(copy(%arg))) if one of the uses is a consuming use of a noncopyable value. This bailout (two lines) required a bit of tweaking to the utility because it was written not to bailout when processing arguments--at the time, there were no cases in which it ought to.
Scope: Affects optimized code.
Issue: rdar://142520491
Original PR: #78552
Risk: Low.
Testing: Added tests.
Reviewer: Meghana Gupta ( @meg-gupta )

Replace large nested condition with early exit.
Allow rewriting of arguments to bail out.  This is necessary because not
all forwarding instructions allow rewriting of forward(copy) as
copy(forward) (e.g. when forward produces a move-only value).
When visiting a consuming use of a move-only value (which can be
produced by a forwarding operation), the inner rewriter must bail out.
Otherwise, it would produce a copy of that move-only value.

rdar://142520491
On main type annotations are not always required but on 6.1 they are.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review January 11, 2025 15:57
@nate-chandler nate-chandler requested a review from a team as a code owner January 11, 2025 15:57
@nate-chandler nate-chandler merged commit 202de3a into swiftlang:release/6.1 Jan 13, 2025
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.1/rdar142520491 branch January 13, 2025 19:17
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