Skip to content

[SE-0466] Don't infer @MainActor on types conforming to Sendable #81468

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

Conversation

DougGregor
Copy link
Member

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).

Implements rdar://151029300

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

Intentionally not merging because this need more discussion and experimentation

@DougGregor
Copy link
Member Author

(I'm going to put this behind an experimental flag so we can play with it more)

@DougGregor DougGregor force-pushed the no-main-actor-when-conforming-to-sendable branch from 3a14322 to 54f057a Compare June 27, 2025 19:18
@DougGregor DougGregor requested a review from jckarter as a code owner June 27, 2025 19:18
@DougGregor DougGregor force-pushed the no-main-actor-when-conforming-to-sendable branch from 54f057a to 6e2306f Compare June 27, 2025 19:19
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

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 force-pushed the no-main-actor-when-conforming-to-sendable branch from 6e2306f to ee9f6f8 Compare June 27, 2025 19:24
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Windows

@groue
Copy link

groue commented Jun 28, 2025

Hello,

This is a very welcome change 👍. It is good that libraries can influence the default MainActor isolation.

I add this comment because Sendable is quite a big requirement. Why not using SendableMetaType instead? For more information, please see this comment: #82249 (comment)

@DougGregor DougGregor merged commit b75d8f0 into swiftlang:main Jun 28, 2025
3 checks passed
@DougGregor DougGregor deleted the no-main-actor-when-conforming-to-sendable branch June 28, 2025 15:08
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