@@ -128,12 +128,12 @@ import Swift
128128/// - Throws: if the operation closure throws
129129/// - SeeAlso: ``TaskExecutor``
130130@_unavailableInEmbedded
131- @available ( SwiftStdlib 9999 , * )
132- @_unsafeInheritExecutor // calling withTaskExecutor MUST NOT perform the "usual" hop to global
133- public func withTaskExecutorPreference< T: Sendable > (
131+ @available ( SwiftStdlib 6 . 0 , * )
132+ public func withTaskExecutorPreference< T, Failure> (
134133 _ taskExecutor: ( any TaskExecutor ) ? ,
135- operation: @Sendable ( ) async throws -> T
136- ) async rethrows -> T {
134+ isolation: isolated ( any Actor ) ? = #isolation,
135+ operation: ( ) async throws ( Failure ) -> T
136+ ) async throws ( Failure) -> T {
137137 guard let taskExecutor else {
138138 // User explicitly passed a "nil" preference, so we invoke the operation
139139 // as is, which will hop to it's expected executor without any change in
@@ -159,9 +159,32 @@ public func withTaskExecutorPreference<T: Sendable>(
159159 return try await operation ( )
160160}
161161
162+ @_unavailableInEmbedded
163+ @available ( SwiftStdlib 6 . 0 , * )
164+ @_unsafeInheritExecutor // calling withTaskExecutor MUST NOT perform the "usual" hop to global
165+ @_silgen_name ( " $ss26withTaskExecutorPreference_9operationxSch_pSg_xyYaYbKXEtYaKs8SendableRzlF " )
166+ public func __abi__withTaskExecutorPreference< T: Sendable > (
167+ _ taskExecutor: ( any TaskExecutor ) ? ,
168+ operation: @Sendable ( ) async throws -> T
169+ ) async rethrows -> T {
170+ guard let taskExecutor else {
171+ return try await operation ( )
172+ }
173+
174+ let taskExecutorBuiltin : Builtin . Executor =
175+ taskExecutor. asUnownedTaskExecutor ( ) . executor
176+
177+ let record = _pushTaskExecutorPreference ( taskExecutorBuiltin)
178+ defer {
179+ _popTaskExecutorPreference ( record: record)
180+ }
181+
182+ return try await operation ( )
183+ }
184+
162185/// Task with specified executor -----------------------------------------------
163186
164- @available ( SwiftStdlib 9999 , * )
187+ @available ( SwiftStdlib 6 . 0 , * )
165188extension Task where Failure == Never {
166189 /// Runs the given nonthrowing operation asynchronously
167190 /// as part of a new top-level task on behalf of the current actor.
@@ -227,7 +250,7 @@ extension Task where Failure == Never {
227250 }
228251}
229252
230- @available ( SwiftStdlib 9999 , * )
253+ @available ( SwiftStdlib 6 . 0 , * )
231254extension Task where Failure == Error {
232255 /// Runs the given throwing operation asynchronously
233256 /// as part of a new top-level task on behalf of the current actor.
@@ -289,7 +312,7 @@ extension Task where Failure == Error {
289312
290313// ==== Detached tasks ---------------------------------------------------------
291314
292- @available ( SwiftStdlib 9999 , * )
315+ @available ( SwiftStdlib 6 . 0 , * )
293316extension Task where Failure == Never {
294317 /// Runs the given nonthrowing operation asynchronously
295318 /// as part of a new top-level task.
@@ -346,7 +369,7 @@ extension Task where Failure == Never {
346369 }
347370}
348371
349- @available ( SwiftStdlib 9999 , * )
372+ @available ( SwiftStdlib 6 . 0 , * )
350373extension Task where Failure == Error {
351374 /// Runs the given throwing operation asynchronously
352375 /// as part of a new top-level task.
@@ -407,7 +430,7 @@ extension Task where Failure == Error {
407430
408431// ==== Unsafe Current Task ----------------------------------------------------
409432
410- @available ( SwiftStdlib 9999 , * )
433+ @available ( SwiftStdlib 6 . 0 , * )
411434extension UnsafeCurrentTask {
412435
413436 /// The current ``TaskExecutor`` preference, if this task has one configured.
@@ -417,7 +440,7 @@ extension UnsafeCurrentTask {
417440 /// The lifetime of an executor is not guaranteed by an ``UnownedTaskExecutor``,
418441 /// so accessing it must be handled with great case -- and the program must use other
419442 /// means to guarantee the executor remains alive while it is in use.
420- @available ( SwiftStdlib 9999 , * )
443+ @available ( SwiftStdlib 6 . 0 , * )
421444 public var unownedTaskExecutor : UnownedTaskExecutor ? {
422445 let ref = _getPreferredTaskExecutor ( )
423446 return UnownedTaskExecutor ( ref)
@@ -426,18 +449,18 @@ extension UnsafeCurrentTask {
426449
427450// ==== Runtime ---------------------------------------------------------------
428451
429- @available ( SwiftStdlib 9999 , * )
452+ @available ( SwiftStdlib 6 . 0 , * )
430453@_silgen_name ( " swift_task_getPreferredTaskExecutor " )
431454internal func _getPreferredTaskExecutor( ) -> Builtin . Executor
432455
433456typealias TaskExecutorPreferenceStatusRecord = UnsafeRawPointer
434457
435- @available ( SwiftStdlib 9999 , * )
458+ @available ( SwiftStdlib 6 . 0 , * )
436459@_silgen_name ( " swift_task_pushTaskExecutorPreference " )
437460internal func _pushTaskExecutorPreference( _ executor: Builtin . Executor )
438461 -> TaskExecutorPreferenceStatusRecord
439462
440- @available ( SwiftStdlib 9999 , * )
463+ @available ( SwiftStdlib 6 . 0 , * )
441464@_silgen_name ( " swift_task_popTaskExecutorPreference " )
442465internal func _popTaskExecutorPreference(
443466 record: TaskExecutorPreferenceStatusRecord
@@ -447,7 +470,7 @@ internal func _popTaskExecutorPreference(
447470///
448471/// It can be used to compare against, and is semantically equivalent to
449472/// "no preference".
450- @available ( SwiftStdlib 9999 , * )
473+ @available ( SwiftStdlib 6 . 0 , * )
451474@usableFromInline
452475internal func _getUndefinedTaskExecutor( ) -> Builtin . Executor {
453476 // Similar to the `_getGenericSerialExecutor` this method relies
0 commit comments