Skip to content

Commit f922eb2

Browse files
committed
Coalesce multiple Unsafe*Continuation definitions.
We somehow ended up with a set hidden in `Task` as well as a set at top level. SILGen currently hooks into the top-level ones, so shed the `Task`-namespaced versions for now.
1 parent 6722d71 commit f922eb2

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
@@ -347,43 +347,6 @@ extension Task {
347347
// ==== UnsafeContinuation -----------------------------------------------------
348348

349349
extension Task {
350-
public struct UnsafeContinuation<T> {
351-
/// Return a value into the continuation and make the task schedulable.
352-
///
353-
/// The task will never run synchronously, even if the task does not
354-
/// need to be resumed on a specific executor.
355-
///
356-
/// This is appropriate when the caller is something "busy", like an event
357-
/// loop, and doesn't want to be potentially delayed by arbitrary work.
358-
public func resume(returning: T) {
359-
fatalError("\(#function) not implemented yet.")
360-
}
361-
}
362-
363-
public struct UnsafeThrowingContinuation<T, E: Error> {
364-
/// Return a value into the continuation and make the task schedulable.
365-
///
366-
/// The task will never run synchronously, even if the task does not
367-
/// need to be resumed on a specific executor.
368-
///
369-
/// This is appropriate when the caller is something "busy", like an event
370-
/// loop, and doesn't want to be potentially delayed by arbitrary work.
371-
public func resume(returning: T) {
372-
fatalError("\(#function) not implemented yet.")
373-
}
374-
375-
/// Resume the continuation with an error and make the task schedulable.
376-
///
377-
/// The task will never run synchronously, even if the task does not
378-
/// need to be resumed on a specific executor.
379-
///
380-
/// This is appropriate when the caller is something "busy", like an event
381-
/// loop, and doesn't want to be potentially delayed by arbitrary work.
382-
public func resume(throwing: E) {
383-
fatalError("\(#function) not implemented yet.")
384-
}
385-
}
386-
387350
/// The operation functions must resume the continuation *exactly once*.
388351
///
389352
/// The continuation will not begin executing until the operation function returns.
@@ -405,7 +368,7 @@ extension Task {
405368
/// This function returns instantly and will never suspend.
406369
/* @instantaneous */
407370
public static func withUnsafeThrowingContinuation<T>(
408-
operation: (UnsafeThrowingContinuation<T, Error>) -> Void
371+
operation: (UnsafeThrowingContinuation<T>) -> Void
409372
) async throws -> T {
410373
fatalError("\(#function) not implemented yet.")
411374
}

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)