Skip to content

5.9: [MoveChecker] Complete lifetimes before checking. #68381

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

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Sep 7, 2023

Description: Fix wrong move-only diagnostic in no-return functions.

The move-checker for objects relies on a utility (CanonicalizeOSSALifetime) to eliminate spurious copies. That utility is permitted to bail out in the face of SIL it doesn't understand. In particular, the utility bails out if lifetimes are not complete; such lifetimes occur in no-return functions. The checker, however, just issues a diagnostic Usage of a noncopyable type that compiler can't verify. This is a compiler bug. in the face of that bail out.

Since the move-checker relies on the utility not bailing out, the fix is for the move-checker to transform the SIL before using the utility--specifically, to complete OSSA lifetimes via OSSALifetimeCompletion. This must be done for each value which will be checked and values derived from it via ownership and forwarding operations.

This is the first use of OSSALifetimeCompletion on release/5.9. The utility is, however, already in use on main in TempRValueElimination and Mem2Reg. As a result, several fixes from main need to be picked up on release/5.9.

Risk: Low. This only affects functions with move-only values, but the fix is to use the OSSALifetimeCompletion utility on release/5.9 for the first time.

Scope: Narrow. Only functions with move-only values are affected.

Original PR: #68342

Reviewed By: Meghana Gupta ( @meg-gupta )

Testing: Added test.

Resolves: rdar://115185992

@nate-chandler nate-chandler force-pushed the cherrypick/release/5.9/gh68328 branch from bc2413f to 4cda39e Compare September 7, 2023 20:17
@nate-chandler nate-chandler reopened this Sep 7, 2023
@nate-chandler nate-chandler force-pushed the cherrypick/release/5.9/gh68328 branch from 4cda39e to ea5af4f Compare September 8, 2023 14:21
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review September 8, 2023 19:48
@nate-chandler nate-chandler requested a review from a team as a code owner September 8, 2023 19:48
@nate-chandler nate-chandler requested a review from tbkka September 9, 2023 17:49
meg-gupta and others added 7 commits September 12, 2023 08:01
end_borrow was not considered as a lifetime ending use,
leading to insertion of redundant end_borrows at boundaries.
A dead end block can be visited multiple times on each of its
predecessors path. Use BasicBlockWorklist::pushIfNotVisited api for insertion.
…gOperand kinds

Not all BorrowingOperand introduce a BorrowedValue. Add a new api to get the defining value
for use in InteriorLivenessVisitor::handleInnerBorrow.
…me completion

Since partial_apply [on_stack] is considered as a BorrowingOperand now,
and BorrowingOperand::visitScopeEndingUses can be called on the its forwarded values
lifetime ends, update the assertion to reflect this.
Before move-checking values, complete the lifetimes of all the values
derived from them via copy, borrow, and move.

Collect all such values and their derived transitive values and then
complete the lifetimes of each, visiting the instructions which produce
them in post-order.

Once OSSALifetimeCommpletion runs as part of SILGenCleanup, this code
can be deleted.
@nate-chandler nate-chandler force-pushed the cherrypick/release/5.9/gh68328 branch from ea5af4f to 2bad5c7 Compare September 12, 2023 15:02
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler merged commit 9036b03 into swiftlang:release/5.9 Sep 12, 2023
@nate-chandler nate-chandler deleted the cherrypick/release/5.9/gh68328 branch September 12, 2023 22: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.

3 participants