Skip to content

Commit d122fd6

Browse files
committed
add _backDeploy and availability necessary for it
1 parent b3c3357 commit d122fd6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

stdlib/public/BackDeployConcurrency/TaskLocal.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
102102
self.defaultValue = defaultValue
103103
}
104104

105+
@usableFromInline
105106
var key: Builtin.RawPointer {
106107
unsafeBitCast(self, to: Builtin.RawPointer.self)
107108
}
@@ -135,7 +136,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
135136
/// If the value is a reference type, it will be retained for the duration of
136137
/// the operation closure.
137138
@discardableResult
139+
@inline(__always)
138140
@_unsafeInheritExecutor
141+
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
142+
@_backDeploy(before: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999) // SwiftStdlib 5.8 but it doesn't work with _backDeploy
139143
public func withValue<R>(_ valueDuringOperation: Value, operation: () async throws -> R,
140144
file: String = #file, line: UInt = #line) async rethrows -> R {
141145
// check if we're not trying to bind a value from an illegal context; this may crash
@@ -161,6 +165,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
161165
/// If the value is a reference type, it will be retained for the duration of
162166
/// the operation closure.
163167
@discardableResult
168+
@inline(__always)
164169
public func withValue<R>(_ valueDuringOperation: Value, operation: () throws -> R,
165170
file: String = #file, line: UInt = #line) rethrows -> R {
166171
// check if we're not trying to bind a value from an illegal context; this may crash
@@ -172,6 +177,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
172177
return try operation()
173178
}
174179

180+
@inline(__always)
175181
public var projectedValue: TaskLocal<Value> {
176182
get {
177183
self
@@ -213,23 +219,27 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
213219
// ==== ------------------------------------------------------------------------
214220

215221
@available(SwiftStdlib 5.1, *)
222+
@usableFromInline
216223
@_silgen_name("swift_task_localValuePush")
217224
func _taskLocalValuePush<Value>(
218225
key: Builtin.RawPointer/*: Key*/,
219226
value: __owned Value
220227
) // where Key: TaskLocal
221228

222229
@available(SwiftStdlib 5.1, *)
230+
@usableFromInline
223231
@_silgen_name("swift_task_localValuePop")
224232
func _taskLocalValuePop()
225233

226234
@available(SwiftStdlib 5.1, *)
235+
@usableFromInline
227236
@_silgen_name("swift_task_localValueGet")
228237
func _taskLocalValueGet(
229238
key: Builtin.RawPointer/*Key*/
230239
) -> UnsafeMutableRawPointer? // where Key: TaskLocal
231240

232241
@available(SwiftStdlib 5.1, *)
242+
@usableFromInline
233243
@_silgen_name("swift_task_localsCopyTo")
234244
func _taskLocalsCopy(
235245
to target: Builtin.NativeObject

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
102102
self.defaultValue = defaultValue
103103
}
104104

105+
@usableFromInline
105106
var key: Builtin.RawPointer {
106107
unsafeBitCast(self, to: Builtin.RawPointer.self)
107108
}
@@ -136,6 +137,8 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
136137
/// the operation closure.
137138
@discardableResult
138139
@_unsafeInheritExecutor
140+
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
141+
@_backDeploy(before: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999) // SwiftStdlib 5.8 but it doesn't work with _backDeploy
139142
public func withValue<R>(_ valueDuringOperation: Value, operation: () async throws -> R,
140143
file: String = #fileID, line: UInt = #line) async rethrows -> R {
141144
// check if we're not trying to bind a value from an illegal context; this may crash
@@ -161,6 +164,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
161164
/// If the value is a reference type, it will be retained for the duration of
162165
/// the operation closure.
163166
@discardableResult
167+
@inline(__always)
164168
public func withValue<R>(_ valueDuringOperation: Value, operation: () throws -> R,
165169
file: String = #fileID, line: UInt = #line) rethrows -> R {
166170
// check if we're not trying to bind a value from an illegal context; this may crash
@@ -172,6 +176,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
172176
return try operation()
173177
}
174178

179+
@inline(__always)
175180
public var projectedValue: TaskLocal<Value> {
176181
get {
177182
self
@@ -213,23 +218,27 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
213218
// ==== ------------------------------------------------------------------------
214219

215220
@available(SwiftStdlib 5.1, *)
221+
@usableFromInline
216222
@_silgen_name("swift_task_localValuePush")
217223
func _taskLocalValuePush<Value>(
218224
key: Builtin.RawPointer/*: Key*/,
219225
value: __owned Value
220226
) // where Key: TaskLocal
221227

222228
@available(SwiftStdlib 5.1, *)
229+
@usableFromInline
223230
@_silgen_name("swift_task_localValuePop")
224231
func _taskLocalValuePop()
225232

226233
@available(SwiftStdlib 5.1, *)
234+
@usableFromInline
227235
@_silgen_name("swift_task_localValueGet")
228236
func _taskLocalValueGet(
229237
key: Builtin.RawPointer/*Key*/
230238
) -> UnsafeMutableRawPointer? // where Key: TaskLocal
231239

232240
@available(SwiftStdlib 5.1, *)
241+
@usableFromInline
233242
@_silgen_name("swift_task_localsCopyTo")
234243
func _taskLocalsCopy(
235244
to target: Builtin.NativeObject

0 commit comments

Comments
 (0)