Skip to content

[SE-0470] Fix synthesized conformances with default main actor isolation #81420

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

When defaulting to main-actor isolation, types that have synthesized conformances (e.g., for Equatable, Hashable, Codable) were getting nonisolated members by default. That would cause compiler errors because the conformances themselves defaulted to main-actor isolation when their types were.

Be careful to only mark these members as 'nonisolated' when it makes sense, and leave them to get the isolation of their enclosing type when the conformance might have isolation. This ensures that one can use synthesis of these protocols along with default main-actor mode.

There is a one-off trick here to force the synthesized CodingKeys to be nonisolated, because the CodingKey protocol requires Sendable. We'll separately consider whether to generalize this rule.

More of rdar://150691429.

When defaulting to main-actor isolation, types that have synthesized
conformances (e.g., for Equatable, Hashable, Codable) were getting
nonisolated members by default. That would cause compiler errors
because the conformances themselves defaulted to main-actor isolation
when their types were.

Be careful to only mark these members as 'nonisolated' when it makes
sense, and leave them to get the isolation of their enclosing type
when the conformance might have isolation. This ensures that one can
use synthesis of these protocols along with default main-actor mode.

There is a one-off trick here to force the synthesized CodingKeys to
be nonisolated, because the CodingKey protocol requires Sendable.
We'll separately consider whether to generalize this rule.

More of rdar://150691429.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@@ -1723,12 +1723,52 @@ bool swift::hasLetStoredPropertyWithInitialValue(NominalTypeDecl *nominal) {
});
}

/// Determine whether a synth
Copy link
Member

Choose a reason for hiding this comment

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

Nit: incomplete comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, fix incoming with another related PR

Copy link
Member Author

Choose a reason for hiding this comment

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

(Comment completed in #81450)

@DougGregor DougGregor merged commit c16e93f into swiftlang:main May 10, 2025
3 checks passed
@DougGregor DougGregor deleted the se-0470-synthesized-conformances-main-actor branch May 12, 2025 16:03
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