6.1: [OSSACompleteLifetime] Handle scoped addresses. #78081
Merged
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.
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
andbegin_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 aload_borrow
) was completed but the outer lifetime (e.g. that of astore_borrow
) was not. It would also prevent the utility from being used by passes which introducedstore_borrow
s andbegin_access
es.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 preexistingScopedAddressValue::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 )