Skip to content

Commit 822f857

Browse files
authored
Merge pull request #34817 from jckarter/coalesce-unsafe-continuations
Coalesce multiple `Unsafe*Continuation` definitions.
2 parents 3aec862 + f922eb2 commit 822f857

File tree

3 files changed

+8
-45
lines changed

3 files changed

+8
-45
lines changed

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public struct PartialAsyncTask {
2424
public struct UnsafeContinuation<T> {
2525
private var context: UnsafeRawPointer
2626

27-
public func resume(_: __owned T) { }
27+
public func resume(returning: __owned T) { }
2828
}
2929

3030
@frozen
3131
public struct UnsafeThrowingContinuation<T> {
3232
private var context: UnsafeRawPointer
3333

34-
public func resume(_: __owned T) { }
35-
public func fail(_: __owned Error) { }
34+
public func resume(returning: __owned T) { }
35+
public func resume(throwing: __owned Error) { }
3636
}
3737

3838
#if _runtime(_ObjC)
@@ -45,7 +45,7 @@ internal func _resumeUnsafeContinuation<T>(
4545
_ continuation: UnsafeContinuation<T>,
4646
_ value: __owned T
4747
) {
48-
continuation.resume(value)
48+
continuation.resume(returning: value)
4949
}
5050

5151
@_alwaysEmitIntoClient
@@ -54,7 +54,7 @@ internal func _resumeUnsafeThrowingContinuation<T>(
5454
_ continuation: UnsafeThrowingContinuation<T>,
5555
_ value: __owned T
5656
) {
57-
continuation.resume(value)
57+
continuation.resume(returning: value)
5858
}
5959

6060
@_alwaysEmitIntoClient
@@ -63,7 +63,7 @@ internal func _resumeUnsafeThrowingContinuationWithError<T>(
6363
_ continuation: UnsafeThrowingContinuation<T>,
6464
_ error: __owned Error
6565
) {
66-
continuation.fail(error)
66+
continuation.resume(throwing: error)
6767
}
6868

6969
#endif

stdlib/public/Concurrency/Task.swift

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -340,43 +340,6 @@ extension Task {
340340
// ==== UnsafeContinuation -----------------------------------------------------
341341

342342
extension Task {
343-
public struct UnsafeContinuation<T> {
344-
/// Return a value into the continuation and make the task schedulable.
345-
///
346-
/// The task will never run synchronously, even if the task does not
347-
/// need to be resumed on a specific executor.
348-
///
349-
/// This is appropriate when the caller is something "busy", like an event
350-
/// loop, and doesn't want to be potentially delayed by arbitrary work.
351-
public func resume(returning: T) {
352-
fatalError("\(#function) not implemented yet.")
353-
}
354-
}
355-
356-
public struct UnsafeThrowingContinuation<T, E: Error> {
357-
/// Return a value into the continuation and make the task schedulable.
358-
///
359-
/// The task will never run synchronously, even if the task does not
360-
/// need to be resumed on a specific executor.
361-
///
362-
/// This is appropriate when the caller is something "busy", like an event
363-
/// loop, and doesn't want to be potentially delayed by arbitrary work.
364-
public func resume(returning: T) {
365-
fatalError("\(#function) not implemented yet.")
366-
}
367-
368-
/// Resume the continuation with an error and make the task schedulable.
369-
///
370-
/// The task will never run synchronously, even if the task does not
371-
/// need to be resumed on a specific executor.
372-
///
373-
/// This is appropriate when the caller is something "busy", like an event
374-
/// loop, and doesn't want to be potentially delayed by arbitrary work.
375-
public func resume(throwing: E) {
376-
fatalError("\(#function) not implemented yet.")
377-
}
378-
}
379-
380343
/// The operation functions must resume the continuation *exactly once*.
381344
///
382345
/// The continuation will not begin executing until the operation function returns.
@@ -398,7 +361,7 @@ extension Task {
398361
/// This function returns instantly and will never suspend.
399362
/* @instantaneous */
400363
public static func withUnsafeThrowingContinuation<T>(
401-
operation: (UnsafeThrowingContinuation<T, Error>) -> Void
364+
operation: (UnsafeThrowingContinuation<T>) -> Void
402365
) async throws -> T {
403366
fatalError("\(#function) not implemented yet.")
404367
}

test/Concurrency/async_tasks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func buyVegetables(shoppingList: [String]) async throws -> [Vegetable] {
4343
func test_unsafeContinuations() async {
4444
// the closure should not allow async operations;
4545
// after all: if you have async code, just call it directly, without the unsafe continuation
46-
let _: String = Task.withUnsafeContinuation { continuation in // expected-error{{cannot convert value of type '(_) async -> ()' to expected argument type '(Task.UnsafeContinuation<String>) -> Void'}}
46+
let _: String = Task.withUnsafeContinuation { continuation in // expected-error{{cannot convert value of type '(_) async -> ()' to expected argument type '(UnsafeContinuation<String>) -> Void'}}
4747
let s = await someAsyncFunc() // rdar://70610141 for getting a better error message here
4848
continuation.resume(returning: s)
4949
}

0 commit comments

Comments
 (0)