9
9
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
- import SwiftSyntax
13
12
14
13
/// Describes the ordering of a sequence of bytes that make up a word of
15
14
/// storage for a particular architecture.
@@ -43,18 +42,17 @@ public enum CanImportVersion {
43
42
/// Providing complete build configuration information effectively requires
44
43
/// a Swift compiler, because (for example) determining whether a module can
45
44
/// be imported is a complicated task only implemented in the Swift compiler.
46
- /// Therefore, many of the queries return `Bool?`, where `nil` indicates
47
- /// that the answer is not known. Clients that don't have a lot of context
48
- /// (such as an IDE that does not have access to the compiler command line)
49
- /// can return `nil`.
45
+ /// Therefore, queries are permitted to throw an error to report when they
46
+ /// cannot answer a query, in which case this error will be reported to
47
+ /// the caller.
50
48
public protocol BuildConfiguration {
51
49
/// Determine whether a given custom build condition has been set.
52
50
///
53
51
/// Custom build conditions can be set by the `-D` command line option to
54
52
/// the Swift compiler. For example, `-DDEBUG` sets the custom condition
55
53
/// named `DEBUG`, which could be checked with, e.g.,
56
54
///
57
- /// ```
55
+ /// ```swift
58
56
/// #if DEBUG
59
57
/// // ...
60
58
/// #endif
@@ -63,53 +61,49 @@ public protocol BuildConfiguration {
63
61
/// - Parameters:
64
62
/// - name: The name of the custom build condition being checked (e.g.,
65
63
/// `DEBUG`.
66
- /// - syntax: The syntax node for the name of the custom build
67
- /// configuration.
68
64
/// - Returns: Whether the custom condition is set.
69
- func isCustomConditionSet( name: String , syntax : ExprSyntax ) -> Bool ?
65
+ func isCustomConditionSet( name: String ) throws -> Bool
70
66
71
67
/// Determine whether the given feature is enabled.
72
68
///
73
69
/// Features are determined by the Swift compiler, language mode, and other
74
70
/// options such as `--enable-upcoming-feature`, and can be checked with
75
71
/// the `hasFeature` syntax, e.g.,
76
72
///
77
- /// ```
73
+ /// ```swift
78
74
/// #if hasFeature(VariadicGenerics)
79
75
/// // ...
80
76
/// #endif
81
77
/// ```
82
78
///
83
79
/// - Parameters:
84
80
/// - name: The name of the feature being checked.
85
- /// - syntax: The syntax node for the `hasFeature(<name>)`.
86
81
/// - Returns: Whether the requested feature is available.
87
- func hasFeature( name: String , syntax : ExprSyntax ) -> Bool ?
82
+ func hasFeature( name: String ) throws -> Bool
88
83
89
84
/// Determine whether the given attribute is available.
90
85
///
91
86
/// Attributes are determined by the Swift compiler. They can be checked
92
87
/// with `hasAttribute` syntax, e.g.,
93
88
///
94
- /// ```
89
+ /// ```swift
95
90
/// #if hasAttribute(available)
96
91
/// // ...
97
92
/// #endif
98
93
/// ```
99
94
///
100
95
/// - Parameters:
101
96
/// - name: The name of the attribute being queried.
102
- /// - syntax: The syntax node for the `hasAttribute(<name>)`.
103
97
/// - Returns: Whether the requested attribute is supported.
104
- func hasAttribute( name: String , syntax : ExprSyntax ) -> Bool ?
98
+ func hasAttribute( name: String ) throws -> Bool
105
99
106
100
/// Determine whether a module with the given import path can be imported,
107
101
/// with additional version information.
108
102
///
109
103
/// The availability of a module for import can be checked with `canImport`,
110
104
/// e.g.,
111
105
///
112
- /// ```
106
+ /// ```swift
113
107
/// #if canImport(UIKit)
114
108
/// // ...
115
109
/// #endif
@@ -126,142 +120,143 @@ public protocol BuildConfiguration {
126
120
/// - version: The version restriction on the imported module. For the
127
121
/// normal `canImport(<import-path>)` syntax, this will always be
128
122
/// `CanImportVersion.unversioned`.
129
- /// - syntax: The syntax node for the `canImport` expression.
130
123
/// - Returns: Whether the module can be imported.
131
- func canImport( importPath: [ String ] , version: CanImportVersion , syntax : ExprSyntax ) -> Bool ?
124
+ func canImport( importPath: [ String ] , version: CanImportVersion ) throws -> Bool
132
125
133
126
/// Determine whether the given name is the active target OS (e.g., Linux, iOS).
134
127
///
135
128
/// The target operating system can be queried with `os(<name>)`, e.g.,
136
129
///
137
- /// ```
130
+ /// ```swift
138
131
/// #if os(Linux)
139
132
/// // Linux-specific implementation
140
133
/// #endif
134
+ /// ```
141
135
///
142
136
/// - Parameters:
143
137
/// - name: The name of the operating system being queried, such as `Linux`,
144
138
/// `Windows`, `macOS`, etc.
145
- /// - syntax: The syntax node for the `os(<name>)` expression.
146
139
/// - Returns: Whether the given operating system name is the target operating
147
140
/// system, i.e., the operating system for which code is being generated.
148
- func isActiveTargetOS( name: String , syntax : ExprSyntax ) -> Bool ?
141
+ func isActiveTargetOS( name: String ) throws -> Bool
149
142
150
143
/// Determine whether the given name is the active target architecture
151
144
/// (e.g., x86_64, arm64).
152
145
///
153
146
/// The target processor architecture can be queried with `arch(<name>)`, e.g.,
154
147
///
155
- /// ```
148
+ /// ```swift
156
149
/// #if arch(x86_64)
157
150
/// // 64-bit x86 Intel-specific code
158
151
/// #endif
152
+ /// ```
159
153
///
160
154
/// - Parameters:
161
155
/// - name: The name of the target architecture to check.
162
- /// - syntax: The syntax node for the `arch(<name>)` expression.
163
156
/// - Returns: Whether the given processor architecture is the target
164
157
/// architecture.
165
- func isActiveTargetArchitecture( name: String , syntax : ExprSyntax ) -> Bool ?
158
+ func isActiveTargetArchitecture( name: String ) throws -> Bool
166
159
167
160
/// Determine whether the given name is the active target environment (e.g., simulator)
168
161
///
169
162
/// The target environment can be queried with `targetEnvironment(<name>)`,
170
163
/// e.g.,
171
164
///
172
- /// ```
165
+ /// ```swift
173
166
/// #if targetEnvironment(simulator)
174
167
/// // Simulator-specific code
175
168
/// #endif
169
+ /// ```
176
170
///
177
171
/// - Parameters:
178
172
/// - name: The name of the target environment to check.
179
- /// - syntax: The syntax node for the `targetEnvironment(<name>)`
180
- /// expression.
181
173
/// - Returns: Whether the target platform is for a specific environment,
182
174
/// such as a simulator or emulator.
183
- func isActiveTargetEnvironment( name: String , syntax : ExprSyntax ) -> Bool ?
175
+ func isActiveTargetEnvironment( name: String ) throws -> Bool
184
176
185
177
/// Determine whether the given name is the active target runtime (e.g., _ObjC vs. _Native)
186
178
///
187
179
/// The target runtime can only be queried by an experimental syntax
188
180
/// `_runtime(<name>)`, e.g.,
189
181
///
182
+ /// ```swift
190
183
/// #if _runtime(_ObjC)
191
184
/// // Code that depends on Swift being built for use with the Objective-C
192
185
/// // runtime, e.g., on Apple platforms.
193
186
/// #endif
187
+ /// ```
194
188
///
195
189
/// The only other runtime is "none", when Swift isn't tying into any other
196
190
/// specific runtime.
197
191
///
198
192
/// - Parameters:
199
193
/// - name: The name of the runtime.
200
- /// - syntax: The syntax node for the `_runtime(<name>)` expression.
201
194
/// - Returns: Whether the target runtime matches the given name.
202
- func isActiveTargetRuntime( name: String , syntax : ExprSyntax ) -> Bool ?
195
+ func isActiveTargetRuntime( name: String ) throws -> Bool
203
196
204
197
/// Determine whether the given name is the active target pointer authentication scheme (e.g., arm64e).
205
198
///
206
199
/// The target pointer authentication scheme describes how pointers are
207
200
/// signed, as a security mitigation. This scheme can only be queried by
208
201
/// an experimental syntax `_ptrath(<name>)`, e.g.,
209
202
///
210
- /// ```
203
+ /// ```swift
211
204
/// #if _ptrauth(arm64e)
212
205
/// // Special logic for arm64e pointer signing
213
206
/// #endif
214
- ///
207
+ /// ```
215
208
/// - Parameters:
216
209
/// - name: The name of the pointer authentication scheme to check.
217
- /// - syntax: The syntax node for the `_ptrauth(<name>)` expression.
218
210
/// - Returns: Whether the code generated for the target will use the given
219
211
/// pointer authentication scheme.
220
- func isActiveTargetPointerAuthentication( name: String , syntax : ExprSyntax ) -> Bool ?
212
+ func isActiveTargetPointerAuthentication( name: String ) throws -> Bool
221
213
222
214
/// The bit width of a data pointer for the target architecture.
223
215
///
224
216
/// The target's pointer bit with (which also corresponds to the number of
225
217
/// bits in `Int`/`UInt`) can only be queried with the experimental syntax
226
218
/// `_pointerBitWidth(_<bitwidth>)`, e.g.,
227
219
///
228
- /// ```
220
+ /// ```swift
229
221
/// #if _pointerBitWidth(32)
230
222
/// // 32-bit system
231
223
/// #endif
232
- var targetPointerBitWidth : Int ? { get }
224
+ /// ```
225
+ var targetPointerBitWidth : Int { get }
233
226
234
227
/// The endianness of the target architecture.
235
228
///
236
229
/// The target's endianness can onyl be queried with the experimental syntax
237
230
/// `_endian(<name>)`, where `<name>` can be either "big" or "little", e.g.,
238
231
///
232
+ /// ```swift
239
233
/// #if _endian(little)
240
234
/// // Swap some bytes around for network byte order
241
235
/// #endif
242
- var endianness : Endianness ? { get }
236
+ /// ```
237
+ var endianness : Endianness { get }
243
238
244
239
/// The effective language version, which can be set by the user (e.g., 5.0).
245
240
///
246
241
/// The language version can be queried with the `swift` directive that checks
247
242
/// how the supported language version compares, as described by
248
243
/// [SE-0212](https://github.com/apple/swift-evolution/blob/main/proposals/0212-compiler-version-directive.md). For example:
249
244
///
250
- /// ```
245
+ /// ```swift
251
246
/// #if swift(>=5.5)
252
247
/// // Hooray, we can use tasks!
253
248
/// ```
254
- var languageVersion : VersionTuple ? { get }
249
+ var languageVersion : VersionTuple { get }
255
250
256
251
/// The version of the compiler (e.g., 5.9).
257
252
///
258
253
/// The compiler version can be queried with the `compiler` directive that
259
254
/// checks the specific version of the compiler being used to process the
260
255
/// code, e.g.,
261
256
///
262
- /// ```
257
+ /// ```swift
263
258
/// #if compiler(>=5.7)
264
259
/// // Hoorway, we can implicitly open existentials!
265
260
/// #endif
266
- var compilerVersion : VersionTuple ? { get }
261
+ var compilerVersion : VersionTuple { get }
267
262
}
0 commit comments