[Pitch] `@OptionSet` macro

+1 on using macros to synthesise options. As many have pointed out OptionSet brings pitfalls and synthesis removes much of the subtlety.

I am drawn to using static var for the options over a nested enum Options: Int because as mentioned the macro expansion diff is smaller which is a usability win and should not be understated.

It may take some time for me to get used to, but I much prefer when the code I am reading explicitly states the protocol conformance — generic constraints and protocol conformance already have a steep learning curve in Swift and using macros like @OptionSet makes this even steeper.

struct ShippingOptions: OptionSet { } // explicit and clear

@OptionSet
struct ShippingOptions { } // yes tooling can expand but this is an additional abstraction

I would be hesitant to support @OptionSet so quickly in this form to the standard library without some discussion on these forums about the feasibility of witness macros mentioned in the possible vision.

2 Likes