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: [OSSACompleteLifetime] Recurse into scoped addresses. #78207

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Dec 16, 2024

Explanation: Fix lifetime completion of scoped addresses.

In #78081 , support for completing lifetimes of scoped addresses (store_borrow, begin_access) was added. That support relied on the ScopedAddressValue::computeTransitiveLiveness function, however. That function does not actually produce liveness that includes all transitive uses: specifically, it doesn't include the end_borrows of load_borrows. The result was that lifetimes of scoped addresses would be ended before the lifetimes of load_borrows that they enclose, which is invalid.

Here, this is fixed by writing a variation of computeTransitiveLiveness's callee findTransitiveUsesForAddress. Like the latter, the new variation (written directly in OSSALifetimeCompletion) uses a TransitiveAddressWalker. Unlike it, however, it includes the end_borrows of load_borrows.

Additionally, the new walker completes inner lifetimes that are discovered while visiting the transitive uses of the scoped address. That brings this case into parity with what's done when completing lifetimes for values.

Scope: Affects optimized code.
Issue: rdar://141246601
Original PR: #78180
Risk: Low.
Testing: Added test.
Reviewer: Meghana Gupta ( @meg-gupta )

Previously, when determining and completing lifetimes of scoped
addresses, `computeTransitiveLiveness` was used to determine the
liveness used for completing the lifetime.

That approach had two problems:
(1) The function does not find scope-ending uses of `load_borrow`s.
    The result was determining that the lifetime of the enclosing
    `store_borrow` ended before that of the `load_borrow`.
(2) The function did not complete lifetimes of values defined within the
    scoped address whose lifetimes the scoped address had to contain.
    This was an inconsistency between the handling of scoped addresses
    and that of values.

Here, both are addressed by implementing a `TransitiveAddressWalker` (as
`computeTransitiveLiveness`'s callee does) which not only visits
existing `end_borrow`s of `load_borrows` but completes them (and other
inner guaranteed values or scoped addresses).

rdar://141246601
On main type annotations are not always required but on 6.1 they are.
@nate-chandler nate-chandler force-pushed the cherrypick/release/6.1/rdar141246601 branch from 41bc060 to 1726b32 Compare December 16, 2024 16:44
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review December 16, 2024 22:56
@nate-chandler nate-chandler requested a review from a team as a code owner December 16, 2024 22:56
@nate-chandler nate-chandler merged commit 98ab6b2 into swiftlang:release/6.1 Dec 16, 2024
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.1/rdar141246601 branch December 16, 2024 23:41
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