Skip to content

[6.2] Improve LocalVariableUtils.gatherKnownLifetimeUses; dead ends #82797

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

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jul 4, 2025

Add a fake use for dead-end blocks. This allows gatherKnownLifetimeUses to be
used for local liveness by considering an "unreachable" instruction to generate
liveness. This is important when liveness is used as a boundary within which
access scopes may be extended. Otherwise, we are unable to extend access scopes
into dead-end blocks.

Fixes rdar://154406790 (Lifetime-dependent variable 'X' escapes its
scope but only if actor/class is final)

(cherry picked from commit 239255b)

--- CCC ---

Explanation: Fixes lifetime dependence access scope extension into "unreachable" code blocks.

Scope: This is required in order to pass Span/MutableSpan into a function that may throw.

let bufferSpan = array.mutableSpan
try! mayThrow(bufferSpan)

Otherwise, diagnostics report that the span escapes the array's access.

Radar/SR Issue: rdar://154406790 (Lifetime-dependent variable 'X' escapes its scope but only if actor/class is final)

main PR: #82796

Risk: Low. This adds a single condition to a utility that computes liveness. It improves the accuracy of that utility in an obvious way. That utility is only used by lifetime dependene diagnostics.

Testing: Added source and SIL unit tests.

Reviewer: Nate Chandler

Add a fake use for dead-end blocks. This allows gatherKnownLifetimeUses to be
used for local liveness by considering an "unreachable" instruction to generate
liveness. This is important when liveness is used as a boundary within which
access scopes may be extended. Otherwise, we are unable to extend access scopes
into dead-end blocks.

Fixes rdar://154406790 (Lifetime-dependent variable 'X' escapes its
scope but only if actor/class is final)

(cherry picked from commit 239255b)
@atrick atrick added the 🍒 release cherry pick Flag: Release branch cherry picks label Jul 4, 2025
@atrick atrick requested a review from a team as a code owner July 4, 2025 04:41
@atrick atrick requested a review from meg-gupta July 4, 2025 04:43
@atrick
Copy link
Contributor Author

atrick commented Jul 4, 2025

@swift-ci test

@atrick atrick enabled auto-merge July 4, 2025 06:00
@atrick atrick requested a review from tbkka July 4, 2025 14:42
@atrick atrick merged commit d03fd67 into swiftlang:release/6.2 Jul 7, 2025
5 checks passed
@atrick atrick deleted the 62-local-deadend branch July 7, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 6.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants