Skip to content

Commit 7a7179d

Browse files
authored
Merge pull request swiftlang#35071 from DougGregor/with-one-unsafe-continuation
[Concurrency] Remove extraneous copies of withUnsafe(Throwing)Continuation
2 parents ae25ceb + 3e11ede commit 7a7179d

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ internal func _resumeUnsafeThrowingContinuationWithError<T>(
7979

8080
#endif
8181

82-
// Wrappers around unsafe continuation builtins
82+
/// The operation functions must resume the continuation *exactly once*.
83+
///
84+
/// The continuation will not begin executing until the operation function returns.
8385
@_alwaysEmitIntoClient
8486
public func withUnsafeContinuation<T>(
8587
_ fn: (UnsafeContinuation<T>) -> Void
@@ -89,6 +91,9 @@ public func withUnsafeContinuation<T>(
8991
}
9092
}
9193

94+
/// The operation functions must resume the continuation *exactly once*.
95+
///
96+
/// The continuation will not begin executing until the operation function returns.
9297
@_alwaysEmitIntoClient
9398
public func withUnsafeThrowingContinuation<T>(
9499
_ fn: (UnsafeThrowingContinuation<T>) -> Void

stdlib/public/Concurrency/Task.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -343,36 +343,6 @@ extension Task {
343343
}
344344
}
345345

346-
// ==== UnsafeContinuation -----------------------------------------------------
347-
348-
extension Task {
349-
/// The operation functions must resume the continuation *exactly once*.
350-
///
351-
/// The continuation will not begin executing until the operation function returns.
352-
///
353-
/// ### Suspension
354-
/// This function returns instantly and will never suspend.
355-
/* @instantaneous */
356-
public static func withUnsafeContinuation<T>(
357-
operation: (UnsafeContinuation<T>) -> Void
358-
) async -> T {
359-
fatalError("\(#function) not implemented yet.")
360-
}
361-
362-
/// The operation functions must resume the continuation *exactly once*.
363-
///
364-
/// The continuation will not begin executing until the operation function returns.
365-
///
366-
/// ### Suspension
367-
/// This function returns instantly and will never suspend.
368-
/* @instantaneous */
369-
public static func withUnsafeThrowingContinuation<T>(
370-
operation: (UnsafeThrowingContinuation<T>) -> Void
371-
) async throws -> T {
372-
fatalError("\(#function) not implemented yet.")
373-
}
374-
}
375-
376346
@_silgen_name("swift_task_getJobFlags")
377347
func getJobFlags(_ task: Builtin.NativeObject) -> Task.JobFlags
378348

test/Concurrency/async_tasks.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func buyVegetables(
2626

2727
// returns 1 or more vegetables or throws an error
2828
func buyVegetables(shoppingList: [String]) async throws -> [Vegetable] {
29-
await try Task.withUnsafeThrowingContinuation { continuation in
29+
await try withUnsafeThrowingContinuation { continuation in
3030
var veggies: [Vegetable] = []
3131

3232
buyVegetables(
@@ -43,22 +43,22 @@ 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{{invalid conversion from 'async' function of type '(UnsafeContinuation<String>) async -> Void' to synchronous function type '(UnsafeContinuation<String>) -> Void'}}
46+
let _: String = withUnsafeContinuation { continuation in // expected-error{{invalid conversion from 'async' function of type '(UnsafeContinuation<String>) async -> Void' to synchronous function type '(UnsafeContinuation<String>) -> Void'}}
4747
let s = await someAsyncFunc() // rdar://70610141 for getting a better error message here
4848
continuation.resume(returning: s)
4949
}
5050

51-
let _: String = await Task.withUnsafeContinuation { continuation in
51+
let _: String = await withUnsafeContinuation { continuation in
5252
continuation.resume(returning: "")
5353
}
5454
}
5555

5656
func test_unsafeThrowingContinuations() async {
57-
let _: String = await try Task.withUnsafeThrowingContinuation { continuation in
57+
let _: String = await try withUnsafeThrowingContinuation { continuation in
5858
continuation.resume(returning: "")
5959
}
6060

61-
let _: String = await try Task.withUnsafeThrowingContinuation { continuation in
61+
let _: String = await try withUnsafeThrowingContinuation { continuation in
6262
continuation.resume(throwing: MyError())
6363
}
6464

0 commit comments

Comments
 (0)