Skip to content

[6.0] Fix type lowering of ~Copyable and ~Escapable generics. #72946

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 5 commits into from
Apr 11, 2024

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Apr 10, 2024

--- CCC ---

Explanation: Fix type lowering of ~Copyable and ~Escapable generics.

Scope: Required to correctly suppress move-only diagnostics of conditionally copyable types when the type is statically copyable. Required to allow the definition of nonescapable enums.

Radar/SR Issues: rdar://125950218 ([nonescapable] support conditionally escapable enums)

Original PR: #72866

Risk: This only suppresses move-only diagnostics in some cases. It allows the use of ~Escapable on enums, which would always crash before.

Testing: Unit tests added

Reviewer: @slavapestov

atrick added 4 commits April 9, 2024 22:28
This fixes TypeLowering for ~Copyable generics, such as:

struct S<T: ~Copyable>: ~Copyable {
  var x: T
}

extension S: Copyable where T: Copyable  {}

func foo<T>(s: S<T>) -> ()

Previously, TypeLowering would ignore the implicit Copyable
requirement on the archetype 'T'.

(cherry picked from commit 22646bd)
Factor AbstractionPattern::conformsToKnownProtocol and lower ~Escapable using the same logic as ~Copyable.

Adds support for conditionally Escapable enums.

Correctly sets the SILType::isTrivial flags for conditionally escapable structs and enums in environments (extensions)
that provide an Escapable conformance, such as:

    struct NE<E: ~Escapable> : ~Escapable {}

    extension NE: Escapable {
      func foo() -> Self {
        // Self is both Escapable and trivial here.
        self
      }
    }

Fixes rdar://125950218 ([nonescapable] support conditionally escapable enums)

(cherry picked from commit a90b515)
@atrick atrick added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.0 labels Apr 10, 2024
@atrick atrick requested a review from a team as a code owner April 10, 2024 05:44
@atrick
Copy link
Contributor Author

atrick commented Apr 10, 2024

@swift-ci test

This is needed until initializer inference is merged. Then these extra
initializers can simply be deleted.
@atrick
Copy link
Contributor Author

atrick commented Apr 10, 2024

@swift-ci test

@atrick atrick merged commit c4c0153 into swiftlang:release/6.0 Apr 11, 2024
@atrick atrick deleted the 60-fix-nonescapable-lowering branch April 11, 2024 15:49
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.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants