Skip to content

[6.2] Infer nonisolated conformances from witnesses #81344

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

@DougGregor DougGregor commented May 6, 2025

  • Explanation: If all of the witnesses to a conformance are nonisolated, then infer that conformance as nonisolated rather than global-actor-isolated. This is only relevant when InferIsolatedConformances is enabled, and prevents that inference to help maintain source compatibility. Related to this, don't force members introduced for compiler-synthesized conformances (Equatable, Hashable, Codable, etc.) to be nonisolated when inferring conditional conformances. This makes main-actor-by-default mode work with synthesized conformances so you can make a main-actor type Codable and it'll correctly turn that into a main-actor-isolated conformance.
  • Scope: Limited to inference of isolation on conformances and synthesized members under the upcoming feature InferIsolatedConformance or when defaulting to the main actor.
  • Issues: rdar://150691429
  • Original PRs: [SE-0470] Prohibit inference of isolated conformances with nonisolated witnesses #81296, [SE-0470] Fix synthesized conformances with default main actor isolation #81420
  • Risk: Low, due to narrow scope of the change.
  • Testing: CI.

DougGregor added 4 commits May 6, 2025 16:07
…d witnesses

If all of the witnesses to a conformance are nonisolated, then infer that
conformance as nonisolated rather than global-actor-isolated. This is
only relevant when InferIsolatedConformances is enabled, and prevents
that inference to help maintain source compatibility.
This request was looking through to the root conformance, which could
mess with the caching bits. Sink the "is nonisolated conformance" bit
down into ProtocolConformance, and have the request for a non-root
conformance be defined in terms of the request for the root
conformance.
This assertion will trigger whenever there is a cycle with a
split-cached request. Remove the assertion.
@DougGregor DougGregor requested a review from a team as a code owner May 6, 2025 23:10
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

I'm doing more investigation on this change still

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 test

@DougGregor DougGregor merged commit 009f868 into swiftlang:release/6.2 May 10, 2025
5 checks passed
@DougGregor DougGregor deleted the infer-nonisolated-conformances-from-witnesses-6.2 branch May 10, 2025 15:27
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