-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add proposal for @OptionSet macro #1968
base: main
Are you sure you want to change the base?
Conversation
| This will require the addition of the `@OptionSet` macro declaration to the standard library: | ||
|
|
||
| ```swift | ||
| @attached(member) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @attached(member) | |
| @attached(member, names: arbitrary) |
| ```swift | ||
| @attached(member) | ||
| @attached(conformance) | ||
| public macro OptionSet<RawType>() = #externalMacro(module: "MacroExamplesPlugin", type: "OptionSetMacro") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be used as @OptionSet<UInt8> or similar. If we want to infer the raw value type, we'll need to do something differently. And I think we'll want a defaulted parameter that provides the name of the Options enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposal and implementation(s) use RawType, but the (non-primary) associated type is RawValue.
OptionSet was included in the version of the Swift standard
library that shipped with beta 1:
https://github.com/apple/swift/blob/release/5.9-20230510/stdlib/public/core/Macros.swift#L93
However, it has since been reverted:
swiftlang/swift#66403 (merged into 'main')
swiftlang/swift#66404 (cherry pick to 5.9 release branch)
We should watch for it to be approved in the Swift Evolution process,
and then re-add the link (assuming it gets approved):
https://forums.swift.org/t/63547
swiftlang/swift-evolution#1968
Fixes: rdar://111109664
Relies on SE-0389