@@ -20,8 +20,8 @@ import SwiftShims
20
20
21
21
@available ( SwiftStdlib 5 . 1 , * )
22
22
extension SerialExecutor {
23
- /// Unconditionally if the current task is executing on the expected serial executor,
24
- /// and if not crash the program offering information about the executor mismatch .
23
+ /// Stops program execution if the current task is not executing on this
24
+ /// serial executor.
25
25
///
26
26
/// This function's effect varies depending on the build flag used:
27
27
///
@@ -32,9 +32,18 @@ extension SerialExecutor {
32
32
/// * In `-O` builds (the default for Xcode's Release configuration), stops
33
33
/// program execution.
34
34
///
35
- /// * In `-Ounchecked` builds, the optimizer may assume that this function is
36
- /// never called. Failure to satisfy that assumption is a serious
37
- /// programming error.
35
+ /// - Note: Because this check is performed against the actor's serial executor,
36
+ /// if another actor uses the same serial executor--by using
37
+ /// that actor's serial executor as its own ``Actor/unownedExecutor``--this
38
+ /// check will succeed. From a concurrency safety perspective, the
39
+ /// serial executor guarantees mutual exclusion of those two actors.
40
+ ///
41
+ /// - Parameters:
42
+ /// - message: The message to print if the assertion fails.
43
+ /// - file: The file name to print if the assertion fails. The default value is
44
+ /// the file where this method was called.
45
+ /// - line: The line number to print if the assertion fails The default value is
46
+ /// the line where this method was called.
38
47
@available ( SwiftStdlib 5 . 1 , * )
39
48
#if !$Embedded
40
49
@backDeployed ( before: SwiftStdlib 5.9 )
@@ -60,8 +69,8 @@ extension SerialExecutor {
60
69
61
70
@available ( SwiftStdlib 5 . 1 , * )
62
71
extension Actor {
63
- /// Unconditionally if the current task is executing on the serial executor of the passed in `actor`,
64
- /// and if not crash the program offering information about the executor mismatch .
72
+ /// Stops program execution if the current task is not executing on this
73
+ /// actor's serial executor.
65
74
///
66
75
/// This function's effect varies depending on the build flag used:
67
76
///
@@ -72,9 +81,18 @@ extension Actor {
72
81
/// * In `-O` builds (the default for Xcode's Release configuration), stops
73
82
/// program execution.
74
83
///
75
- /// * In `-Ounchecked` builds, the optimizer may assume that this function is
76
- /// never called. Failure to satisfy that assumption is a serious
77
- /// programming error.
84
+ /// - Note: This check is performed against the actor's serial executor,
85
+ /// meaning that / if another actor uses the same serial executor--by using
86
+ /// that actor's serial executor as its own ``Actor/unownedExecutor``--this
87
+ /// check will succeed , as from a concurrency safety perspective, the
88
+ /// serial executor guarantees mutual exclusion of those two actors.
89
+ ///
90
+ /// - Parameters:
91
+ /// - message: The message to print if the assertion fails.
92
+ /// - file: The file name to print if the assertion fails. The default is
93
+ /// where this method was called.
94
+ /// - line: The line number to print if the assertion fails The default is
95
+ /// where this method was called.
78
96
@available ( SwiftStdlib 5 . 1 , * )
79
97
#if !$Embedded
80
98
@backDeployed ( before: SwiftStdlib 5.9 )
@@ -100,8 +118,8 @@ extension Actor {
100
118
101
119
@available ( SwiftStdlib 5 . 1 , * )
102
120
extension GlobalActor {
103
- /// Unconditionally if the current task is executing on the serial executor of the passed in `actor`,
104
- /// and if not crash the program offering information about the executor mismatch .
121
+ /// Stops program execution if the current task is not executing on this
122
+ /// actor's serial executor.
105
123
///
106
124
/// This function's effect varies depending on the build flag used:
107
125
///
@@ -112,9 +130,18 @@ extension GlobalActor {
112
130
/// * In `-O` builds (the default for Xcode's Release configuration), stops
113
131
/// program execution.
114
132
///
115
- /// * In `-Ounchecked` builds, the optimizer may assume that this function is
116
- /// never called. Failure to satisfy that assumption is a serious
117
- /// programming error.
133
+ /// - Note: This check is performed against the actor's serial executor,
134
+ /// meaning that / if another actor uses the same serial executor--by using
135
+ /// that actor's serial executor as its own ``Actor/unownedExecutor``--this
136
+ /// check will succeed , as from a concurrency safety perspective, the
137
+ /// serial executor guarantees mutual exclusion of those two actors.
138
+ ///
139
+ /// - Parameters:
140
+ /// - message: The message to print if the assertion fails.
141
+ /// - file: The file name to print if the assertion fails. The default is
142
+ /// where this method was called.
143
+ /// - line: The line number to print if the assertion fails The default is
144
+ /// where this method was called.
118
145
@available ( SwiftStdlib 5 . 1 , * )
119
146
#if !$Embedded
120
147
@backDeployed ( before: SwiftStdlib 5.9 )
@@ -133,18 +160,30 @@ extension GlobalActor {
133
160
134
161
@available ( SwiftStdlib 5 . 1 , * )
135
162
extension SerialExecutor {
136
- /// Performs an executor check in debug builds.
163
+ /// Stops program execution if the current task is not executing on this
164
+ /// serial executor.
165
+ ///
166
+ /// This function's effect varies depending on the build flag used:
137
167
///
138
168
/// * In playgrounds and `-Onone` builds (the default for Xcode's Debug
139
- /// configuration): If `condition` evaluates to `false`, stop program
140
- /// execution in a debuggable state after printing `message`.
169
+ /// configuration), stops program execution in a debuggable state after
170
+ /// printing `message`.
141
171
///
142
172
/// * In `-O` builds (the default for Xcode's Release configuration),
143
- /// `condition` is not evaluated, and there are no effects.
173
+ /// the isolation check is not performed and there are no effects.
174
+ ///
175
+ /// - Note: This check is performed against the actor's serial executor,
176
+ /// meaning that / if another actor uses the same serial executor--by using
177
+ /// that actor's serial executor as its own ``Actor/unownedExecutor``--this
178
+ /// check will succeed , as from a concurrency safety perspective, the
179
+ /// serial executor guarantees mutual exclusion of those two actors.
144
180
///
145
- /// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
146
- /// may assume that it *always* evaluates to `true`. Failure to satisfy that
147
- /// assumption is a serious programming error.
181
+ /// - Parameters:
182
+ /// - message: The message to print if the assertion fails.
183
+ /// - file: The file name to print if the assertion fails. The default is
184
+ /// where this method was called.
185
+ /// - line: The line number to print if the assertion fails The default is
186
+ /// where this method was called.
148
187
@available ( SwiftStdlib 5 . 1 , * )
149
188
#if !$Embedded
150
189
@backDeployed ( before: SwiftStdlib 5.9 )
@@ -170,18 +209,30 @@ extension SerialExecutor {
170
209
171
210
@available ( SwiftStdlib 5 . 1 , * )
172
211
extension Actor {
173
- /// Performs an executor check in debug builds.
212
+ /// Stops program execution if the current task is not executing on this
213
+ /// actor's serial executor.
214
+ ///
215
+ /// This function's effect varies depending on the build flag used:
174
216
///
175
217
/// * In playgrounds and `-Onone` builds (the default for Xcode's Debug
176
- /// configuration): If `condition` evaluates to `false`, stop program
177
- /// execution in a debuggable state after printing `message`.
218
+ /// configuration), stops program execution in a debuggable state after
219
+ /// printing `message`.
178
220
///
179
221
/// * In `-O` builds (the default for Xcode's Release configuration),
180
- /// `condition` is not evaluated, and there are no effects.
222
+ /// the isolation check is not performed and there are no effects.
223
+ ///
224
+ /// - Note: This check is performed against the actor's serial executor,
225
+ /// meaning that / if another actor uses the same serial executor--by using
226
+ /// that actor's serial executor as its own ``Actor/unownedExecutor``--this
227
+ /// check will succeed , as from a concurrency safety perspective, the
228
+ /// serial executor guarantees mutual exclusion of those two actors.
181
229
///
182
- /// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
183
- /// may assume that it *always* evaluates to `true`. Failure to satisfy that
184
- /// assumption is a serious programming error.
230
+ /// - Parameters:
231
+ /// - message: The message to print if the assertion fails.
232
+ /// - file: The file name to print if the assertion fails. The default is
233
+ /// where this method was called.
234
+ /// - line: The line number to print if the assertion fails The default is
235
+ /// where this method was called.
185
236
@available ( SwiftStdlib 5 . 1 , * )
186
237
#if !$Embedded
187
238
@backDeployed ( before: SwiftStdlib 5.9 )
@@ -208,18 +259,30 @@ extension Actor {
208
259
209
260
@available ( SwiftStdlib 5 . 1 , * )
210
261
extension GlobalActor {
211
- /// Performs an executor check in debug builds.
262
+ /// Stops program execution if the current task is not executing on this
263
+ /// actor's serial executor.
264
+ ///
265
+ /// This function's effect varies depending on the build flag used:
212
266
///
213
267
/// * In playgrounds and `-Onone` builds (the default for Xcode's Debug
214
- /// configuration): If `condition` evaluates to `false`, stop program
215
- /// execution in a debuggable state after printing `message`.
268
+ /// configuration), stops program execution in a debuggable state after
269
+ /// printing `message`.
216
270
///
217
271
/// * In `-O` builds (the default for Xcode's Release configuration),
218
- /// `condition` is not evaluated, and there are no effects.
272
+ /// the isolation check is not performed and there are no effects.
219
273
///
220
- /// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
221
- /// may assume that it *always* evaluates to `true`. Failure to satisfy that
222
- /// assumption is a serious programming error.
274
+ /// - Note: This check is performed against the actor's serial executor,
275
+ /// meaning that / if another actor uses the same serial executor--by using
276
+ /// that actor's serial executor as its own ``Actor/unownedExecutor``--this
277
+ /// check will succeed , as from a concurrency safety perspective, the
278
+ /// serial executor guarantees mutual exclusion of those two actors.
279
+ ///
280
+ /// - Parameters:
281
+ /// - message: The message to print if the assertion fails.
282
+ /// - file: The file name to print if the assertion fails. The default is
283
+ /// where this method was called.
284
+ /// - line: The line number to print if the assertion fails The default is
285
+ /// where this method was called.
223
286
@available ( SwiftStdlib 5 . 1 , * )
224
287
#if !$Embedded
225
288
@backDeployed ( before: SwiftStdlib 5.9 )
@@ -238,19 +301,47 @@ extension GlobalActor {
238
301
239
302
@available ( SwiftStdlib 5 . 1 , * )
240
303
extension Actor {
241
- /// A safe way to synchronously assume that the current execution context belongs to the passed in actor.
304
+ /// Assume that the current task is executing on this actor's serial executor,
305
+ /// or stop program execution otherwise.
306
+ ///
307
+ /// You call this method to *assume and verify* that the currently
308
+ /// executing synchronous function is actually executing on the serial
309
+ /// executor of this actor.
310
+ ///
311
+ /// If that is the case, the operation is invoked with an `isolated` version
312
+ /// of the actor, allowing synchronous access to actor local state without
313
+ /// hopping through asynchronous boundaries.
314
+ ///
315
+ /// If the current context is not running on the actor's serial executor, or
316
+ /// if the actor is a reference to a remote actor, this method will crash
317
+ /// with a fatal error (similar to ``preconditionIsolated()``).
318
+ ///
319
+ /// Note that this check is performed against the passed in actor's serial
320
+ /// executor, meaning that if another actor uses the same serial executor--by
321
+ /// using that actor's ``Actor/unownedExecutor`` as its own
322
+ /// ``Actor/unownedExecutor``--this check will succeed, as from a concurrency
323
+ /// safety perspective, the serial executor guarantees mutual exclusion of
324
+ /// those two actors.
242
325
///
243
- /// This API should only be used as last resort, when it is not possible to express the current
244
- /// execution context definitely belongs to the specified actor in other ways. E.g. one may need to use
245
- /// this in a delegate style API, where a synchronous method is guaranteed to be called by the
246
- /// specified actor, however it is not possible to move this method as being declared on the specified actor.
326
+ /// This method can only be used from synchronous functions, as asynchronous
327
+ /// functions should instead perform a normal method call to the actor, which
328
+ /// will hop task execution to the target actor if necessary.
247
329
///
248
- /// - Warning: If the current executor is *not* the expected serial executor, this function will crash.
330
+ /// - Note: This check is performed against the actor's serial executor,
331
+ /// meaning that / if another actor uses the same serial executor--by using
332
+ /// another actor's executor as its own ``Actor/unownedExecutor``
333
+ /// --this check will succeed , as from a concurrency safety perspective,
334
+ /// the serial executor guarantees mutual exclusion of those two actors.
249
335
///
250
- /// Note that this check is performed against the passed in actor's serial executor, meaning that
251
- /// if another actor uses the same serial executor--by using that actor's ``Actor/unownedExecutor``
252
- /// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
253
- /// perspective, the serial executor guarantees mutual exclusion of those two actors.
336
+ /// - Parameters:
337
+ /// - operation: the operation that will be executed if the current context
338
+ /// is executing on the actors serial executor.
339
+ /// - file: The file name to print if the assertion fails. The default is
340
+ /// where this method was called.
341
+ /// - line: The line number to print if the assertion fails The default is
342
+ /// where this method was called.
343
+ /// - Returns: the return value of the `operation`
344
+ /// - Throws: rethrows the `Error` thrown by the operation if it threw
254
345
@available ( SwiftStdlib 5 . 1 , * )
255
346
#if !$Embedded
256
347
@backDeployed ( before: SwiftStdlib 5.9 )
0 commit comments