Skip to content

[6.0] Enable failable initializers of noncopyable types #72779

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

Conversation

DougGregor
Copy link
Member

…members

An empty struct that is noncopyable can nonetheless have a `deinit`, so
it is not trivially destructible. In such cases, embedded them in
another empty struct means that the outer struct should also not be
trivially destructible. Make it so.

(cherry picked from commit b19a325)
Noncopyable types were prevented from having failable initializers
because `Optional` itself didn't support noncopyable types. Now
`Optional` does, so lift this restriction and add a test.

(cherry picked from commit bd696f9)
Only the non-zero-sized associated values of a type were considered
when determining whether an enum is copyable or was
trivially-destructible, meaning that a zero-sized, noncopyable type
with a `deinit` wouldn't get destroyed. Treat these associated values
as if they were a payload, and centralize the logic for figuring out
these overall aspects of the enum (copyable, trivially-destructible,
bitwise-takable) since the same checks were repeated.

Fixes rdar://118449507.
@DougGregor DougGregor requested a review from a team as a code owner April 2, 2024 19:03
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor DougGregor merged commit 94b4fb2 into swiftlang:release/6.0 Apr 3, 2024
@DougGregor DougGregor deleted the failability-init-of-noncopyable-6.0 branch April 3, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants