Skip to content

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Oct 2, 2025

  • LifetimeDependenceDiagnostics: extend temp alloc to unreachable.
    When a non-Escapable value depends on the address of a trivial value, we use a
    special computeAddressableRange analysis to compute the trivial value's
    scope. Extend that analysis to include unreachable paths.

    Fixes this pattern:

    inlineStorage.span.withUnsafeBytes
    

    where inlineStorage is a trivial type defined in the user module. This
    does not reproduce directly with InlineArray, but it is a problem for
    user modules that have their own trivial wrapper around an InlineArray.

    Fixes rdar://161630684 (Incorrect diagnostic: error: lifetime-dependent value escapes its scope)

    (cherry picked from commit 98b7d59)

--- CCC ---

Explanation: Fix a lifetime diagnostic regression that incorrectly
reports an escaping span in the following pattern:

inlineStorage.span.withUnsafeBytes { ... }

Scope: The diagnostic fires in code that uses both experimental
features: AddressableTypes & Lifetimes. It occurs when users create a
wrapper around an InlineArray and try to return a span from that
wrapper. We've seen two cases of this in the wild. A previous bug fix
was over-conservative resulting an a conservative diagnostic.

Radar/SR Issue: rdar://161630684 (Incorrect diagnostic: error: lifetime-dependent value escapes its scope)

main PR: #84641

Risk: Low. This adds an extra check in the utility that computes
liveness for lifetime dependence diagnostics. This check only affects
temporary on-stack copies that have an addressable dependency.

Testing: Added source and SIL unit tests.

Reviewer: Meghana Gupta

@atrick atrick added the 🍒 release cherry pick Flag: Release branch cherry picks label Oct 2, 2025
@atrick atrick requested a review from a team as a code owner October 2, 2025 23:48
@atrick atrick added swift 6.2 🍒 release cherry pick Flag: Release branch cherry picks labels Oct 2, 2025
@atrick atrick requested review from meg-gupta and tbkka October 2, 2025 23:48
@atrick
Copy link
Contributor Author

atrick commented Oct 2, 2025

@swift-ci test

@atrick atrick enabled auto-merge October 2, 2025 23:49
@atrick
Copy link
Contributor Author

atrick commented Oct 3, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Oct 3, 2025

@swift-ci test

atrick added 3 commits October 3, 2025 20:50
When a non-Escapable value depends on the address of a trivial value, we use a
special computeAddressableRange analysis to compute the trivial value's
scope. Extend that analysis to include unreachable paths.

Fixes this pattern:

    inlineStorage.span.withUnsafeBytes

where inlineStorage is a trivial type defined in the user module. This
does not reproduce directly with InlineArray, but it is a problem for
user modules that have their own trivial wrapper around an InlineArray.

Fixes rdar://161630684 (Incorrect diagnostic: lifetime-dependent value escapes its scope)

(cherry picked from commit 98b7d59)
@atrick atrick force-pushed the 62-lifedep-tempaddress-unreachable branch from 61d2198 to ed158ff Compare October 4, 2025 03:50
@atrick
Copy link
Contributor Author

atrick commented Oct 4, 2025

@swift-ci test

@atrick atrick merged commit 7992a52 into swiftlang:release/6.2 Oct 4, 2025
5 checks passed
@atrick atrick deleted the 62-lifedep-tempaddress-unreachable branch October 4, 2025 15:05
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