Skip to content

[6.2] Add Feature: NonescapableAccessorOnTrivial #82381

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

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jun 20, 2025

To guard the new UnsafeMutablePointer.mutableSpan APIs.

This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:

error: cannot infer lifetime dependence on the '_read' accessor because 'self'
is BitwiseCopyable, specify '@lifetime(borrow self)'

I don't know why the _read is synthesized in these cases, but apparently it's
always been that way.

Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard
~Escapable accessors when self is trivial)

(cherry picked from commit ae31edc)

The UnsafeMutablePointer.mutableSpan API was reverted here, pending this fix:
#82351

--- CCC ---

Explanation: Add a compile feature to guard the new UnsafeMutablePointer.mutableSpan APIs.
This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:

Scope: Only affects users of the supported experiment Lifetimes feature.

Radar/SR Issue: rdar://153773093 ([nonescapable] add a compiler feature to guard ~Escapable accessors when self is trivial)

main PR: #82380

Risk: Low

Testing: Added a unit test, manually inspected Swift.swiftinterface, rebuilt the Swift module with an old compiler.

Reviewer: Slava Pestov

@atrick atrick requested a review from a team as a code owner June 20, 2025 18:14
@atrick atrick added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels Jun 20, 2025
@atrick
Copy link
Contributor Author

atrick commented Jun 20, 2025

@swift-ci test

@atrick atrick marked this pull request as draft June 20, 2025 18:18
@atrick atrick force-pushed the 62-nonescapable-accessor-on-trivial branch from 728be36 to 572047d Compare June 20, 2025 22:57
To guard the new UnsafeMutablePointer.mutableSpan APIs.

This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:

    error: cannot infer lifetime dependence on the '_read' accessor because 'self'
    is BitwiseCopyable, specify '@Lifetime(borrow self)'

I don't know why the _read is synthesized in these cases, but apparently it's
always been that way.

Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard
~Escapable accessors when self is trivial)

(cherry picked from commit cc357f4)
@atrick atrick force-pushed the 62-nonescapable-accessor-on-trivial branch from 572047d to 4fa7e13 Compare June 20, 2025 23:01
@atrick atrick marked this pull request as ready for review June 20, 2025 23:12
@atrick
Copy link
Contributor Author

atrick commented Jun 20, 2025

@swift-ci test

@atrick atrick merged commit 156f68f into swiftlang:release/6.2 Jun 23, 2025
5 checks passed
@atrick atrick deleted the 62-nonescapable-accessor-on-trivial branch June 23, 2025 05:57
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.

3 participants