-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0407] [Macros] Provide member macros with information about "missing" conformances #67758
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
[SE-0407] [Macros] Provide member macros with information about "missing" conformances #67758
Conversation
@swift-ci please smoke test |
afe7a69
to
24f8cec
Compare
@swift-ci please smoke test |
24f8cec
to
5084caa
Compare
@swift-ci please smoke test |
5084caa
to
6b1d437
Compare
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
6b1d437
to
7b09944
Compare
@swift-ci please smoke test |
@swift-ci please build toolchain macOS |
7b09944
to
f34dda5
Compare
@swift-ci please smoke test |
@swift-ci please build toolchain macOS |
@swift-ci please smoke test |
@swift-ci please build toolchain macOS |
@swift-ci please smoke test |
f4a6556
to
95001a3
Compare
@swift-ci please smoke test |
Windows failure is unrelated; kicking this off again. |
@swift-ci please smoke test Windows |
…ormances Provide member macros with similar information about conformances to what extension macros receive, allowing member macros to document which conformances they care about (e.g., Decodable) and then receiving the list of conformances that aren't already available for the type in question. For example, a macro such as @attached(member, conformances: Decodable, Encodable, names: named(init(from:), encode(to:))) macro Codable() = ... Expanded on a type that is not already Decodable/Encodable would be provided with Decodable and Encodable (via the new `missingConformancesTo:` argument to the macro implementation) when the type itself does not conform to those types. Member macros still cannot produce conformances, so this is likely to be used in conjunction with extension macros most of the time. The extension macro declares the conformance, and can also declare any members that shouldn't be part of the primary type definition---such as initializers that shouldn't suppress the memberwise initializer. On the other hand, the member macro will need to define any members that must be in the primary definition, such as required initializers, members that must be overridable by subclasses, and stored properties. Codable synthesis is an example that benefits from member macros with conformances, because for classes it wants to introduce a required initializer for decoding and an overridable encode operation, and these must be members of the nominal type itself. Specifically, the `Codable` macro above is likely to have two attached member roles: @attached(member, conformances: Decodable, Encodable, names: named(init(from:), encode(to:))) @attached(extension, conformances: Decodable, Encodable, names: named(init(from:), encode(to:))) macro Codable() = ... where the "extension" role is responsible for defining the conformance (always), and the "member" creates the appropriate members for classes (`init` vs. `required init`). Tracked by rdar://112532829.
95001a3
to
596da31
Compare
@swift-ci please smoke test |
Provide member macros with similar information about conformances to what extension macros receive, allowing member macros to document which conformances they care about (e.g., Decodable) and then receiving the list of conformances that aren't already available for the type in question. For example, a macro such as
Expanded on a type that is not already Decodable/Encodable would be provided with Decodable and Encodable (via the new
missingConformancesTo:
argument to the macro implementation) when the type itself does not conform to those types.Member macros still cannot produce conformances, so this is likely to be used in conjunction with extension macros most of the time. The extension macro declares the conformance, and can also declare any members that shouldn't be part of the primary type definition---such as initializers that shouldn't suppress the memberwise initializer. On the other hand, the member macro will need to define any members that must be in the primary definition, such as required initializers, members that must be overridable by subclasses, and stored properties.
Codable synthesis is an example that benefits from member macros with conformances, because for classes it wants to introduce a required initializer for decoding and an overridable encode operation, and these must be members of the nominal type itself. Specifically, the
Codable
macro above is likely to have two attached member roles:where the "extension" role is responsible for defining the conformance (always), and the "member" creates the appropriate members for classes (
init
vs.required init
).Tracked by rdar://112532829.