Skip to content

6.1: [OSSACompleteLifetime] Handle scoped addresses. #78081

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

Explanation: Support ending lifetimes of scoped addresses.

Currently, there are two permitted levels of validity of a value's lifetime in SIL: incomplete and complete. If a value has an incomplete lifetime, it is consumed on every function-exiting path; it is not consumed on at least one unreachable-terminated path. If a value has a complete lifetime, it is consumed on every path in the function, whether function-exiting or unreachable-terminated. An invalid lifetime which only lacks consuming uses on some function-exiting paths ("underconsumed") can be made valid by inserting consuming uses in such paths.

The SIL utility OSSALifetimeCompletion ends the lifetimes of various SSA values, ensuring that the value has a consuming use on every path in the function. The utility transforms underconsumed and incomplete lifetimes into complete lifetimes. It is run after SILGen on all values and by a number of passes which introduce values. SILGen produces incomplete lifetimes. The values introduced by passes may be underconsumed. Currently, passes also cause previously complete lifetimes to become incomplete. The utility transforms both incomplete and underconsumed lifetimes into complete lifetimes.

Previously, the utility didn't produce scope ends for scoped addresses (the results of the store_borrow and begin_access instructions). When completing all incomplete lifetimes in a function, this would result in verification errors when an inner lifetime (e.g. that of the value produced by a load_borrow) was completed but the outer lifetime (e.g. that of a store_borrow) was not. It would also prevent the utility from being used by passes which introduced store_borrows and begin_accesses.

Here, the utility is enhanced to also complete the scopes of such addresses. The utility requires the liveness of the value being completed. For values (i.e. not addresses), the utility relies on InteriorLiveness. That tool cannot be used for scoped addresses--it's only for values, not addresses. The preexisting ScopedAddressValue::computeTransitiveLiveness function, however, provides exactly the right liveness.

Scope: Affects optimized code.
Issue: rdar://141037060
Original PR: #78034
Risk: Low. The lifetime discovery is done via a preexisting utility.
Testing: Added tests.
Reviewer: Meghana Gupta ( @meg-gupta )

And deleted some type annotations which don't need to be checked.
Use a switch rather than several ifs.
In preparation for adding a second caller.
Avoid a separate declaration.
Complete scopes of scoped addresses (introduced by `store_borrow` and
`begin_access`) in dead end blocks via
`ScopedAddressValue::computeTransitiveLiveness`.

rdar://141037060
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review December 10, 2024 19:33
@nate-chandler nate-chandler requested a review from a team as a code owner December 10, 2024 19:33
@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

1 similar comment
@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

@nate-chandler nate-chandler merged commit 82cae9f into swiftlang:release/6.1 Dec 11, 2024
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.1/rdar141037060 branch December 11, 2024 19:08
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