Skip to content

Concurrency: Revert workarounds for @backDeployed condfails #65777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions stdlib/public/BackDeployConcurrency/TaskCancellation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,17 @@ import Swift
/// the operation gets to run.
@_unsafeInheritExecutor // the operation runs on the same executor as we start out with
@available(SwiftStdlib 5.1, *)
@_backDeploy(before: SwiftStdlib 5.8)
@backDeployed(before: SwiftStdlib 5.8)
public func withTaskCancellationHandler<T>(
operation: () async throws -> T,
onCancel handler: @Sendable () -> Void
) async rethrows -> T {
// unconditionally add the cancellation record to the task.
// if the task was already cancelled, it will be executed right away.
let record = _taskAddCancellationHandler(handler: handler)
do {
let result = try await operation()
_taskRemoveCancellationHandler(record: record)
return result
} catch {
_taskRemoveCancellationHandler(record: record)
throw error
}
defer { _taskRemoveCancellationHandler(record: record) }

return try await operation()
}

@available(SwiftStdlib 5.1, *)
Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/BackDeployConcurrency/TaskLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
///
/// If the value is a reference type, it will be retained for the duration of
/// the operation closure.
@inlinable
@discardableResult
@_unsafeInheritExecutor
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
@_backDeploy(before: SwiftStdlib 5.8)
@backDeployed(before: SwiftStdlib 5.8)
public func withValue<R>(_ valueDuringOperation: Value, operation: () async throws -> R,
file: String = #file, line: UInt = #line) async rethrows -> R {
return try await withValueImpl(valueDuringOperation, operation: operation, file: file, line: line)
Expand All @@ -165,8 +165,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
@inlinable
@discardableResult
@_unsafeInheritExecutor
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
@_backDeploy(before: SwiftStdlib 5.9)
@backDeployed(before: SwiftStdlib 5.9)
internal func withValueImpl<R>(_ valueDuringOperation: __owned Value, operation: () async throws -> R,
file: String = #fileID, line: UInt = #line) async rethrows -> R {
// check if we're not trying to bind a value from an illegal context; this may crash
Expand Down
13 changes: 4 additions & 9 deletions stdlib/public/Concurrency/TaskCancellation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,17 @@ import Swift
/// the operation gets to run.
@_unsafeInheritExecutor // the operation runs on the same executor as we start out with
@available(SwiftStdlib 5.1, *)
@_backDeploy(before: SwiftStdlib 5.8)
@backDeployed(before: SwiftStdlib 5.8)
public func withTaskCancellationHandler<T>(
operation: () async throws -> T,
onCancel handler: @Sendable () -> Void
) async rethrows -> T {
// unconditionally add the cancellation record to the task.
// if the task was already cancelled, it will be executed right away.
let record = _taskAddCancellationHandler(handler: handler)
do {
let result = try await operation()
_taskRemoveCancellationHandler(record: record)
return result
} catch {
_taskRemoveCancellationHandler(record: record)
throw error
}
defer { _taskRemoveCancellationHandler(record: record) }

return try await operation()
}

@available(SwiftStdlib 5.1, *)
Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/Concurrency/TaskLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
///
/// If the value is a reference type, it will be retained for the duration of
/// the operation closure.
@inlinable
@discardableResult
@_unsafeInheritExecutor
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
@_backDeploy(before: SwiftStdlib 5.8)
@backDeployed(before: SwiftStdlib 5.8)
public func withValue<R>(_ valueDuringOperation: Value, operation: () async throws -> R,
file: String = #fileID, line: UInt = #line) async rethrows -> R {
return try await withValueImpl(valueDuringOperation, operation: operation, file: file, line: line)
Expand All @@ -165,8 +165,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
@inlinable
@discardableResult
@_unsafeInheritExecutor
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method
@_backDeploy(before: SwiftStdlib 5.9)
@backDeployed(before: SwiftStdlib 5.9)
internal func withValueImpl<R>(_ valueDuringOperation: __owned Value, operation: () async throws -> R,
file: String = #fileID, line: UInt = #line) async rethrows -> R {
// check if we're not trying to bind a value from an illegal context; this may crash
Expand Down
6 changes: 4 additions & 2 deletions test/api-digester/stability-concurrency-abi.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
// false positives, or if you have special permission to break things.) You can
// find a diff of what needs to be added in the output of the failed test run.
// The order of lines doesn't matter, and you can also include comments to refer
// to any bugs you filed. Remember that in almost all cases you'll want to edit
// the stability-stdlib-abi-without-asserts.test file instead of this one.
// to any bugs you filed.
//
// Thank you for your help ensuring the stdlib remains compatible with its past!
// -- Your friendly stdlib engineers
Expand Down Expand Up @@ -72,4 +71,7 @@ Func SerialExecutor.enqueue(_:) has been added as a protocol requirement
// rdar://106833284 (ABI checker confused with overload getting deprecated)
Func Executor.enqueue(_:) is a new API without @available attribute

// This function correctly inherits its availability from the TaskLocal struct.
Func TaskLocal.withValueImpl(_:operation:file:line:) is a new API without @available attribute

// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment above.)