@@ -116,6 +116,34 @@ public struct UnownedSerialExecutor: Sendable {
116
116
117
117
}
118
118
119
+ /// Checks if the current task is running on the expected executor.
120
+ ///
121
+ /// Generally, Swift programs should be constructed such that it is statically
122
+ /// known that a specific executor is used, for example by using global actors or
123
+ /// custom executors. However, in some APIs it may be useful to provide an
124
+ /// additional runtime check for this, especially when moving towards Swift
125
+ /// concurrency from other runtimes which frequently use such assertions.
126
+ /// - Parameter executor: The expected executor.
127
+ @available ( SwiftStdlib 5 . 9 , * )
128
+ @_silgen_name ( " swift_task_isOnExecutor " )
129
+ public func _taskIsOnExecutor< Executor: SerialExecutor > ( _ executor: Executor ) -> Bool
130
+
131
+ @available ( SwiftStdlib 5 . 1 , * )
132
+ @_transparent
133
+ public // COMPILER_INTRINSIC
134
+ func _checkExpectedExecutor( _filenameStart: Builtin . RawPointer ,
135
+ _filenameLength: Builtin . Word ,
136
+ _filenameIsASCII: Builtin . Int1 ,
137
+ _line: Builtin . Word ,
138
+ _executor: Builtin . Executor ) {
139
+ if _taskIsCurrentExecutor ( _executor) {
140
+ return
141
+ }
142
+
143
+ _reportUnexpectedExecutor (
144
+ _filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
145
+ }
146
+
119
147
/// Primarily a debug utility.
120
148
///
121
149
/// If the passed in Job is a Task, returns the complete 64bit TaskId,
@@ -165,121 +193,4 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
165
193
return UnownedSerialExecutor ( ordinary: self )
166
194
}
167
195
}
168
- #endif
169
-
170
- // ==== -----------------------------------------------------------------------
171
- // - MARK: Executor assertions
172
-
173
- /// Checks if the current task is running on the expected executor.
174
- ///
175
- /// Do note that if multiple actors share the same serial executor,
176
- /// this assertion checks for the executor, not specific actor instance.
177
- ///
178
- /// Generally, Swift programs should be constructed such that it is statically
179
- /// known that a specific executor is used, for example by using global actors or
180
- /// custom executors. However, in some APIs it may be useful to provide an
181
- /// additional runtime check for this, especially when moving towards Swift
182
- /// concurrency from other runtimes which frequently use such assertions.
183
- @available ( SwiftStdlib 5 . 9 , * )
184
- public func preconditionOnSerialExecutor(
185
- _ executor: some SerialExecutor ,
186
- _ message: @autoclosure ( ) -> String = " " ,
187
- file: StaticString = #fileID, line: UInt = #line) {
188
- preconditionOnSerialExecutor ( executor. asUnownedSerialExecutor ( ) , file: file, line: line)
189
- }
190
-
191
- @available ( SwiftStdlib 5 . 9 , * )
192
- public func preconditionOnSerialExecutor(
193
- _ unowned: UnownedSerialExecutor ,
194
- _ message: @autoclosure ( ) -> String = " " ,
195
- file: StaticString = #fileID, line: UInt = #line) {
196
- if _taskIsCurrentExecutor ( unowned. executor) {
197
- return
198
- }
199
-
200
- // TODO: log on what executor it was instead of the expected one
201
- let message = " Expected executor \( unowned) ; \( message ( ) ) "
202
- preconditionFailure (
203
- message,
204
- file: file, line: line)
205
- }
206
-
207
- /// Same as ``preconditionOnSerialExecutor(_:_:file:line)`` however only in DEBUG mode.
208
- @available ( SwiftStdlib 5 . 9 , * )
209
- public func assertOnSerialExecutor(
210
- _ executor: some SerialExecutor ,
211
- _ message: @autoclosure ( ) -> String = " " ,
212
- file: StaticString = #fileID, line: UInt = #line) {
213
- assertOnSerialExecutor ( executor. asUnownedSerialExecutor ( ) , file: file, line: line)
214
- }
215
-
216
- @available ( SwiftStdlib 5 . 9 , * )
217
- public func assertOnSerialExecutor(
218
- _ unowned: UnownedSerialExecutor ,
219
- _ message: @autoclosure ( ) -> String = " " ,
220
- file: StaticString = #fileID, line: UInt = #line) {
221
- if _isDebugAssertConfiguration ( ) {
222
- if _taskIsCurrentExecutor ( unowned. executor) {
223
- return
224
- }
225
-
226
- // TODO: log on what executor it was instead of the expected one
227
- // TODO: fixme use assertion here?
228
- fatalError ( " Expected executor \( unowned) ; \( message ( ) ) " , file: file, line: line)
229
- }
230
- }
231
-
232
- /// Checks if the current task is running on the expected executor.
233
- ///
234
- /// Generally, Swift programs should be constructed such that it is statically
235
- /// known that a specific executor is used, for example by using global actors or
236
- /// custom executors. However, in some APIs it may be useful to provide an
237
- /// additional runtime check for this, especially when moving towards Swift
238
- /// concurrency from other runtimes which frequently use such assertions.
239
- /// - Parameter executor: The expected executor.
240
- @available ( SwiftStdlib 5 . 9 , * )
241
- @_silgen_name ( " swift_task_isOnExecutor " )
242
- func _taskIsOnExecutor( _ executor: some SerialExecutor ) -> Bool
243
-
244
- @available ( SwiftStdlib 5 . 1 , * )
245
- @_transparent
246
- public // COMPILER_INTRINSIC
247
- func _checkExpectedExecutor( _filenameStart: Builtin . RawPointer ,
248
- _filenameLength: Builtin . Word ,
249
- _filenameIsASCII: Builtin . Int1 ,
250
- _line: Builtin . Word ,
251
- _executor: Builtin . Executor ) {
252
- if _taskIsCurrentExecutor ( _executor) {
253
- return
254
- }
255
-
256
- _reportUnexpectedExecutor (
257
- _filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
258
- }
259
-
260
- @available ( SwiftStdlib 5 . 9 , * )
261
- @_alwaysEmitIntoClient // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
262
- func _checkExpectedExecutor(
263
- _ _executor: Builtin . Executor ,
264
- file: String ,
265
- line: Int ) {
266
- if _taskIsCurrentExecutor ( _executor) {
267
- return
268
- }
269
-
270
- file. utf8CString. withUnsafeBufferPointer { ( _ bufPtr: UnsafeBufferPointer < CChar > ) in
271
- let fileBasePtr : Builtin . RawPointer = bufPtr. baseAddress!. _rawValue
272
-
273
- // string lengths exclude trailing \0 byte, which should be there!
274
- let fileLength : Builtin . Word = ( bufPtr. count - 1 ) . _builtinWordValue
275
-
276
- // we're handing it UTF-8
277
- let falseByte : Int8 = 0
278
- let fileIsASCII : Builtin . Int1 = Builtin . trunc_Int8_Int1 ( falseByte. _value)
279
-
280
- _reportUnexpectedExecutor (
281
- fileBasePtr, fileLength, fileIsASCII,
282
- line. _builtinWordValue,
283
- _executor)
284
- }
285
- }
196
+ #endif // SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
0 commit comments