Skip to content

[6.2] [nonescapable] remove '@_lifetime' requirement on implicit accessors #82407

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 4 commits into from
Jun 25, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jun 23, 2025

  • Fix SILCombine of MarkDependenceInst.
    Do not eliminate a mark_dependence on a begin_apply scope even though the token
    has a trivial type.

    Ideally, token would have a non-trivial Builtin type to avoid special cases.

    (only relevant on 6.2)

  • Fix MoveOnlyObjectCheckerPImpl::check() changed flag
    Extract the special pattern matching logic that is otherwise unrelated to the
    check() function. This makes it obvious that the implementation was failing to
    set the 'changed' flag whenever needed.

    (cherry picked from commit c41715c)

  • Fix MoveOnlyObjectCheckerPImpl::check() for mark_dependence.
    Handle the presence of mark_dependence instructions after a begin_apply.

    Fixes a compiler crash:
    "copy of noncopyable typed value. This is a compiler bug. ..."

    (cherry picked from commit 7a29d9d)

  • [nonescapable] remove '@_lifetime' requirement on implicit accessors
    This avoids diagnostic errors on synthesized accessors, which are impossible for developers to understand.

    Fixes rdar://153793344 (Lifetime-dependent value returned by generated accessor '_read')

    (cherry picked from commit 855b3e4)

--- CCC ---

Explanation: Fix lifetime inference for synthesized accessors. Otherwise the diagnostics not actionable because they don't point to real source locations. It is always safe to infer for synthesized code because the compiler knows what is being generated. Tangentially, fix a potential miscompile in instruction simplification and frequent compiler crash in the move checker that were blocking this fix.

Scope: Affects most users of the supported Lifetimes feature when combining ~Copyable with ~Escapable types.

Radar/SR Issue: rdar://153793344 (Lifetime-dependent value returned by generated accessor '_read')

main PR: #82404

Risk: Low

  • a simple optimization is disabled under a very specific condition that only applies to non-escapable types.

  • the move checker now handles the presence of a mark_dependence instruction where previously it would always crash in that case. This is only expected to occur with non-escapable types.

  • lifetime diagnostics now handle synthesized accessors which developers are unaware of. This only loosens diagnostics to accept more cases that the compiler itself generates, not user code.

Testing: Added source and SIL unit tests

Reviewer: Meghana Gupta

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

atrick commented Jun 23, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Jun 23, 2025

@swift-ci test macOS

@atrick atrick requested a review from meg-gupta June 23, 2025 21:10
Copy link
Contributor

@meg-gupta meg-gupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@atrick atrick enabled auto-merge June 24, 2025 00:33
atrick added 3 commits June 24, 2025 12:54
Do not eliminate a mark_dependence on a begin_apply scope even though the token
has a trivial type.

Ideally, token would have a non-trivial Builtin type to avoid special cases.

(only relevant on 6.2)
Extract the special pattern matching logic that is otherwise unrelated to the
check() function. This makes it obvious that the implementation was failing to
set the 'changed' flag whenever needed.

(cherry picked from commit c41715c)
Handle the presence of mark_dependence instructions after a begin_apply.

Fixes a compiler crash:
"copy of noncopyable typed value. This is a compiler bug. ..."

(cherry picked from commit 7a29d9d)
@atrick atrick force-pushed the 62-fix-accessor-infer branch from 06c9e6d to a5b0987 Compare June 24, 2025 19:56
@atrick
Copy link
Contributor Author

atrick commented Jun 24, 2025

@swift-ci test

This avoids diagnostic errors on synthesized accessors, which are impossible for developers to understand.

Fixes rdar://153793344 (Lifetime-dependent value returned by generated accessor '_read')

(cherry picked from commit 855b3e4)
@atrick atrick force-pushed the 62-fix-accessor-infer branch from a5b0987 to d3002ed Compare June 24, 2025 22:13
@atrick
Copy link
Contributor Author

atrick commented Jun 24, 2025

@swift-ci test

@atrick atrick merged commit 0839675 into swiftlang:release/6.2 Jun 25, 2025
5 checks passed
@atrick atrick deleted the 62-fix-accessor-infer branch June 25, 2025 15:15
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