Skip to content

Commit 05cb387

Browse files
committed
Concurrency: Revert workarounds for @backDeployed condfails.
All compilers that the standard library's textual interface must support: - Allow back deployed functions to be declared without `@available`. - Allow back deployed functions to be `@inlinable`. - Support `defer` blocks in back deployed functions. We can therefore revert the workarounds added in #62946 and #62928. Resolves rdar://104085810
1 parent 44489c7 commit 05cb387

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

stdlib/public/BackDeployConcurrency/TaskCancellation.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,17 @@ import Swift
3838
/// the operation gets to run.
3939
@_unsafeInheritExecutor // the operation runs on the same executor as we start out with
4040
@available(SwiftStdlib 5.1, *)
41-
@_backDeploy(before: SwiftStdlib 5.8)
41+
@backDeployed(before: SwiftStdlib 5.8)
4242
public func withTaskCancellationHandler<T>(
4343
operation: () async throws -> T,
4444
onCancel handler: @Sendable () -> Void
4545
) async rethrows -> T {
4646
// unconditionally add the cancellation record to the task.
4747
// if the task was already cancelled, it will be executed right away.
4848
let record = _taskAddCancellationHandler(handler: handler)
49-
do {
50-
let result = try await operation()
51-
_taskRemoveCancellationHandler(record: record)
52-
return result
53-
} catch {
54-
_taskRemoveCancellationHandler(record: record)
55-
throw error
56-
}
49+
defer { _taskRemoveCancellationHandler(record: record) }
50+
51+
return try await operation()
5752
}
5853

5954
@available(SwiftStdlib 5.1, *)

stdlib/public/BackDeployConcurrency/TaskLocal.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
135135
///
136136
/// If the value is a reference type, it will be retained for the duration of
137137
/// the operation closure.
138+
@inlinable
138139
@discardableResult
139140
@_unsafeInheritExecutor
140-
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
141-
@_backDeploy(before: SwiftStdlib 5.8)
141+
@backDeployed(before: SwiftStdlib 5.8)
142142
public func withValue<R>(_ valueDuringOperation: Value, operation: () async throws -> R,
143143
file: String = #file, line: UInt = #line) async rethrows -> R {
144144
return try await withValueImpl(valueDuringOperation, operation: operation, file: file, line: line)
@@ -165,8 +165,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
165165
@inlinable
166166
@discardableResult
167167
@_unsafeInheritExecutor
168-
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
169-
@_backDeploy(before: SwiftStdlib 5.9)
168+
@backDeployed(before: SwiftStdlib 5.9)
170169
internal func withValueImpl<R>(_ valueDuringOperation: __owned Value, operation: () async throws -> R,
171170
file: String = #fileID, line: UInt = #line) async rethrows -> R {
172171
// check if we're not trying to bind a value from an illegal context; this may crash

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,17 @@ import Swift
3838
/// the operation gets to run.
3939
@_unsafeInheritExecutor // the operation runs on the same executor as we start out with
4040
@available(SwiftStdlib 5.1, *)
41-
@_backDeploy(before: SwiftStdlib 5.8)
41+
@backDeployed(before: SwiftStdlib 5.8)
4242
public func withTaskCancellationHandler<T>(
4343
operation: () async throws -> T,
4444
onCancel handler: @Sendable () -> Void
4545
) async rethrows -> T {
4646
// unconditionally add the cancellation record to the task.
4747
// if the task was already cancelled, it will be executed right away.
4848
let record = _taskAddCancellationHandler(handler: handler)
49-
do {
50-
let result = try await operation()
51-
_taskRemoveCancellationHandler(record: record)
52-
return result
53-
} catch {
54-
_taskRemoveCancellationHandler(record: record)
55-
throw error
56-
}
49+
defer { _taskRemoveCancellationHandler(record: record) }
50+
51+
return try await operation()
5752
}
5853

5954
@available(SwiftStdlib 5.1, *)

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
135135
///
136136
/// If the value is a reference type, it will be retained for the duration of
137137
/// the operation closure.
138+
@inlinable
138139
@discardableResult
139140
@_unsafeInheritExecutor
140-
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
141-
@_backDeploy(before: SwiftStdlib 5.8)
141+
@backDeployed(before: SwiftStdlib 5.8)
142142
public func withValue<R>(_ valueDuringOperation: Value, operation: () async throws -> R,
143143
file: String = #fileID, line: UInt = #line) async rethrows -> R {
144144
return try await withValueImpl(valueDuringOperation, operation: operation, file: file, line: line)
@@ -165,8 +165,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
165165
@inlinable
166166
@discardableResult
167167
@_unsafeInheritExecutor
168-
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
169-
@_backDeploy(before: SwiftStdlib 5.9)
168+
@backDeployed(before: SwiftStdlib 5.9)
170169
internal func withValueImpl<R>(_ valueDuringOperation: __owned Value, operation: () async throws -> R,
171170
file: String = #fileID, line: UInt = #line) async rethrows -> R {
172171
// check if we're not trying to bind a value from an illegal context; this may crash

0 commit comments

Comments
 (0)