Skip to content

Commit 2051971

Browse files
authored
Remove OptionSet macro from the standard library. (#66404)
1 parent f2e1a49 commit 2051971

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

stdlib/public/core/Macros.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,6 @@ public macro column<T: ExpressibleByIntegerLiteral>() -> T =
6363
@freestanding(expression)
6464
public macro dsohandle() -> UnsafeRawPointer = Builtin.DSOHandleMacro
6565

66-
/// Create an option set from a struct that contains a nested `Options` enum.
67-
///
68-
/// Attach this macro to a struct that contains a nested `Options` enum
69-
/// with an integer raw value. The struct will be transformed to conform to
70-
/// `OptionSet` by
71-
/// 1. Introducing a `rawValue` stored property to track which options are set,
72-
/// along with the necessary `RawType` typealias and initializers to satisfy
73-
/// the `OptionSet` protocol. The raw type is specified after `@OptionSet`,
74-
/// e.g., `@OptionSet<UInt8>`.
75-
/// 2. Introducing static properties for each of the cases within the `Options`
76-
/// enum, of the type of the struct.
77-
///
78-
/// The `Options` enum must have a raw value, where its case elements
79-
/// each indicate a different option in the resulting option set. For example,
80-
/// the struct and its nested `Options` enum could look like this:
81-
///
82-
/// @OptionSet<UInt8>
83-
/// struct ShippingOptions {
84-
/// private enum Options: Int {
85-
/// case nextDay
86-
/// case secondDay
87-
/// case priority
88-
/// case standard
89-
/// }
90-
/// }
91-
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
92-
@attached(conformance)
93-
public macro OptionSet<RawType>() =
94-
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
95-
9666
/// Produce the given warning message during compilation.
9767
@freestanding(declaration)
9868
public macro warning(_ message: String) = Builtin.WarningMacro

test/IDE/complete_optionset.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func foo() {
1616
ShippingOptions.#^MEMBER_STATIC^#
1717
}
1818

19+
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
20+
@attached(conformance)
21+
public macro OptionSet<RawType>() =
22+
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
23+
1924
// MEMBER_STATIC: Keyword[self]/CurrNominal: self[#ShippingOptions.Type#]; name=self
2025
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: RawValue[#UInt8#]; name=RawValue
2126
// MEMBER_STATIC: Decl[Constructor]/CurrNominal: init({#rawValue: ShippingOptions.RawValue#})[#ShippingOptions#]; name=init(rawValue:)

test/Macros/option_set.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
import Swift
66

7+
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
8+
@attached(conformance)
9+
public macro OptionSet<RawType>() =
10+
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
11+
712
@OptionSet<UInt8>
813
struct ShippingOptions {
914
private enum Options: Int {

test/SourceKit/Macros/macro_option_set.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func test(opts: ShippingOptions) {
1616
let _ = ShippingOptions.nextDay
1717
}
1818

19+
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
20+
@attached(conformance)
21+
public macro OptionSet<RawType>() =
22+
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
23+
1924
// REQUIRES: swift_swift_parser
2025

2126
// RUN: %empty-directory(%t)

0 commit comments

Comments
 (0)