@@ -181,10 +181,27 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
181181 /// the operation closure.
182182 @inlinable
183183 @discardableResult
184- @_unsafeInheritExecutor
185- @backDeployed ( before: SwiftStdlib 5.8 )
186- public func withValue< R> ( _ valueDuringOperation: Value , operation: ( ) async throws -> R ,
184+ @available ( SwiftStdlib 5 . 1 , * )
185+ @backDeployed ( before: SwiftStdlib 6.0 )
186+ public func withValue< R> ( _ valueDuringOperation: Value ,
187+ operation: ( ) async throws -> R ,
188+ isolation: isolated ( any Actor ) ? = #isolation,
187189 file: String = #fileID, line: UInt = #line) async rethrows -> R {
190+ return try await withValueImpl (
191+ valueDuringOperation,
192+ operation: operation,
193+ isolation: isolation,
194+ file: file, line: line)
195+ }
196+
197+ @usableFromInline
198+ @discardableResult
199+ @_unsafeInheritExecutor // ABI compatibility with Swift 5.1
200+ @available ( SwiftStdlib 5 . 1 , * )
201+ @_silgen_name ( " $ss9TaskLocalC9withValue_9operation4file4lineqd__x_qd__yYaKXESSSutYaKlF " )
202+ internal func __abi_withValue< R> ( _ valueDuringOperation: Value ,
203+ operation: ( ) async throws -> R ,
204+ file: String = #fileID, line: UInt = #line) async rethrows -> R {
188205 return try await withValueImpl ( valueDuringOperation, operation: operation, file: file, line: line)
189206 }
190207
@@ -206,11 +223,30 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
206223 /// to swift_task_de/alloc for the copy as follows:
207224 /// - withValue contains the compiler-emitted calls swift_task_de/alloc.
208225 /// - withValueImpl contains the calls to _taskLocalValuePush/Pop
226+ @inlinable
227+ @discardableResult
228+ @available ( SwiftStdlib 5 . 1 , * )
229+ @backDeployed ( before: SwiftStdlib 6.0 )
230+ internal func withValueImpl< R> ( _ valueDuringOperation: __owned Value,
231+ operation: ( ) async throws -> R ,
232+ isolation: isolated ( any Actor ) ? ,
233+ file: String = #fileID, line: UInt = #line) async rethrows -> R {
234+ // check if we're not trying to bind a value from an illegal context; this may crash
235+ _checkIllegalTaskLocalBindingWithinWithTaskGroup ( file: file, line: line)
236+
237+ _taskLocalValuePush ( key: key, value: consume valueDuringOperation)
238+ defer { _taskLocalValuePop ( ) }
239+
240+ return try await operation ( )
241+ }
242+
209243 @inlinable
210244 @discardableResult
211245 @_unsafeInheritExecutor
246+ @available ( SwiftStdlib 5 . 1 , * )
212247 @backDeployed ( before: SwiftStdlib 5.9 )
213- internal func withValueImpl< R> ( _ valueDuringOperation: __owned Value, operation: ( ) async throws -> R ,
248+ internal func withValueImpl< R> ( _ valueDuringOperation: __owned Value,
249+ operation: ( ) async throws -> R ,
214250 file: String = #fileID, line: UInt = #line) async rethrows -> R {
215251 // check if we're not trying to bind a value from an illegal context; this may crash
216252 _checkIllegalTaskLocalBindingWithinWithTaskGroup ( file: file, line: line)
@@ -221,6 +257,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
221257 return try await operation ( )
222258 }
223259
260+
224261 /// Binds the task-local to the specific value for the duration of the
225262 /// synchronous operation.
226263 ///
0 commit comments