Skip to content

[6.2] [SE-0466 experimental amendment] Don't infer @mainactor on types conforming to Sendable #82590

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

  • Explanation: When the default isolation is main-actor, don't infer @MainActor for a type that conforms to a protocol P in its primary definition when P inherits from SendableMetatype. Such types should remain non-isolated
    because they're highly unlikely to be able to implement the P conformance (which cannot be isolated). This feature is under an active pitch, so for now it is behind the experimental flag SendableProhibitsMainActorInference.
  • Scope: Fairly narrow. Affects the inference rules for main-actor-by-default mode.
  • Issues: rdar://151029300 + lots of dupes where this is needed to get existing or sensible code compiling under main-actor-by-default mode.
  • Original PRs: [SE-0466] Don't infer @MainActor on types conforming to Sendable #81468
  • Risk: Low. Only affects a new opt-in mode, tuning some inference rules.
  • Testing: CI, some projects that have adopted main-actor-by-default mode.
  • Reviewers:

When the default isolation is main-actor, don't infer @mainactor
for a type that conforms to a protocol P in its primary definition when
P inherits from Sendable. Such types should remain non-isolated
because they're highly unlikely to be able to implement the P
conformance (which cannot be isolated).

Put this feature behind a new experimental flag,
SendableProhibitsMainActorInference.

Implements rdar://151029300
@DougGregor DougGregor requested a review from a team as a code owner June 27, 2025 22:45
@DougGregor DougGregor enabled auto-merge June 27, 2025 22:45
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 2f83882 into swiftlang:release/6.2 Jun 28, 2025
5 checks passed
@DougGregor DougGregor deleted the no-main-actor-when-conforming-to-sendable-6.2 branch June 28, 2025 15:07
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.

3 participants