Skip to content

[6.2] Fix LifetimeDependenceDiagnostics: allow inout assignment to Void. #82832

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

Closed
wants to merge 1 commit into from

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jul 7, 2025

Bypess lifetime dependence diagnostics completely for immortal values. We did
not do this initially because we wanted to potentially consider a value with a missing
dependency to mean that it could not escape the current function. But now we use
Void as a stand-in for immortal values.

This is needed for reassigning a Span/MutableSpan to an empty, immortal
Span:

func inoutToImmortal(_ s: inout RawSpan) {
  let tmp = RawSpan(_unsafeBytes: UnsafeRawBufferPointer(start: nil, count: 0))
  s = _overrideLifetime(tmp, borrowing: ())
}

Fixes rdar://152572002 ([GH:#81976] Cannot reinitialize inout parameter of type
MutableSpan<T>?)

(cherry picked from commit ac94d7d)

--- CCC ---

Explanation: Fix lifetime diagnostics to allow assigning an immortal value to an inout parameter.

Scope: This only affects adopters of experimental but supported @_lifetime syntax. The following example would incorrectly report a lifetime error:

func inoutToImmortal(_ s: inout RawSpan) {
  let tmp = RawSpan(_unsafeBytes: UnsafeRawBufferPointer(start: nil, count: 0))
  s = _overrideLifetime(tmp, borrowing: ())
}

Radar/SR Issue: rdar://152572002 ([GH:#81976] Cannot reinitialize inout parameter of type MutableSpan<T>?)

main PR: #82831

Risk: Low. No new logic is introduced. The existing check for immortal values is moved earlier to handle inout parameters as well as return value. The risk is that diagnostics are less restrictive.

Testing: Added source-level unit test.

Reviewer: TBD

@atrick atrick requested a review from a team as a code owner July 7, 2025 07:20
@atrick atrick added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels Jul 7, 2025
@atrick
Copy link
Contributor Author

atrick commented Jul 7, 2025

@swift-ci test

@atrick atrick force-pushed the 62-reassign-immortal branch from 5e11357 to 71fcc78 Compare July 7, 2025 15:44
Bypess lifetime dependence diagnostics completely for immortal values. We did
not do this initially because we wanted to potentially consider a value with a missing
dependency to mean that it could not escape the current function. But now we use
`Void` as a stand-in for immortal values.

This is needed for reassigning a Span/MutableSpan to an empty, immortal
Span:

    func inoutToImmortal(_ s: inout RawSpan) {
      let tmp = RawSpan(_unsafeBytes: UnsafeRawBufferPointer(start: nil, count: 0))
      s = _overrideLifetime(tmp, borrowing: ())
    }

Fixes rdar://152572002 ([GH:swiftlang#81976] Cannot reinitialize inout parameter of type
`MutableSpan<T>?`)

(cherry picked from commit ac94d7d)
@atrick atrick force-pushed the 62-reassign-immortal branch from 71fcc78 to e215541 Compare July 7, 2025 15:45
@atrick
Copy link
Contributor Author

atrick commented Jul 7, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Jul 7, 2025

Deciding not to cherry-pick this. There are workarounds for the known cases and we should be cautious about making diagnostics more permissive.

@atrick atrick closed this Jul 7, 2025
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.

1 participant