@@ -181,10 +181,27 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
181
181
/// the operation closure.
182
182
@inlinable
183
183
@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,
187
189
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 {
188
205
return try await withValueImpl ( valueDuringOperation, operation: operation, file: file, line: line)
189
206
}
190
207
@@ -206,11 +223,30 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
206
223
/// to swift_task_de/alloc for the copy as follows:
207
224
/// - withValue contains the compiler-emitted calls swift_task_de/alloc.
208
225
/// - 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
+
209
243
@inlinable
210
244
@discardableResult
211
245
@_unsafeInheritExecutor
246
+ @available ( SwiftStdlib 5 . 1 , * )
212
247
@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 ,
214
250
file: String = #fileID, line: UInt = #line) async rethrows -> R {
215
251
// check if we're not trying to bind a value from an illegal context; this may crash
216
252
_checkIllegalTaskLocalBindingWithinWithTaskGroup ( file: file, line: line)
@@ -221,6 +257,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
221
257
return try await operation ( )
222
258
}
223
259
260
+
224
261
/// Binds the task-local to the specific value for the duration of the
225
262
/// synchronous operation.
226
263
///
0 commit comments