-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Motivation
SE-0466 makes it so that protocols inheriting from SendableMetatype
(i.e. Sendable
) automatically suppress main actor inference when the type is conformed inline:
Default isolation does not apply in the following cases:
[…]
- Declarations whose primary definition directly conforms to a protocol that inherits SendableMetatype
While this works for direct conformances:
protocol MyProtocol: Sendable {}
struct MyType: MyProtocol {} // ✅
It does not work for a macro that provides a conformance:
@attached(extension, conformances: MyProtocol)
macro MyMacro() = …
@MyMacro struct MyType {} // 🛑
While the macro expansion does not define the conformance on the primary definition, and instead does so on an extension, the macro providing the conformance is declared directly on the primary definition, so the spirit of the proposal would seem to apply here.
If the goal is to provide tools that make concurrency approachable, using such a macro should ideally not require the user know that they must also add nonisolated
to the call site:
@MyMacro nonisolated struct MyType {} // ✅
Proposed solution
Suppressing main-actor inference of types that conform to SendableMetatype
protocols should be extended to extension macros.
Alternatives considered
Bring back "conformance macros" as their own thing so that macros can extend the primary declaration.
Additional information
No response