Skip to content

Commit c20bd86

Browse files
committed
[Freestanding] Disable checked continuations.
In the task-to-thread model, there are no threading mechanisms by which work could be offloaded onto another thread. As such, callback based asynchronous APIs which are not Swift async do not make sense. rdar://99047747
1 parent 064b713 commit c20bd86

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

stdlib/public/Concurrency/CheckedContinuation.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Swift
1616
@_silgen_name("swift_continuation_logFailedCheck")
1717
internal func logFailedCheck(_ message: UnsafeRawPointer)
1818

19+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
1920
/// Implementation class that holds the `UnsafeContinuation` instance for
2021
/// a `CheckedContinuation`.
2122
@available(SwiftStdlib 5.1, *)
@@ -82,7 +83,9 @@ internal final class CheckedContinuationCanary: @unchecked Sendable {
8283
}
8384
}
8485
}
86+
#endif
8587

88+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
8689
/// A mechanism to interface
8790
/// between synchronous and asynchronous code,
8891
/// logging correctness violations.
@@ -296,4 +299,65 @@ public func withCheckedThrowingContinuation<T>(
296299
body(CheckedContinuation(continuation: $0, function: function))
297300
}
298301
}
302+
#else
303+
@available(SwiftStdlib 5.1, *)
304+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
305+
public struct CheckedContinuation<T, E: Error>: Sendable {
306+
@available(SwiftStdlib 5.1, *)
307+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
308+
public init(continuation: UnsafeContinuation<T, E>, function: String = #function) {
309+
fatalError("Unavailable in task-to-thread concurrency model")
310+
}
311+
312+
@available(SwiftStdlib 5.1, *)
313+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
314+
public func resume(returning value: __owned T) {
315+
fatalError("Unavailable in task-to-thread concurrency model")
316+
}
317+
318+
@available(SwiftStdlib 5.1, *)
319+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
320+
public func resume(throwing error: __owned E) {
321+
fatalError("Unavailable in task-to-thread concurrency model")
322+
}
323+
}
324+
@available(SwiftStdlib 5.1, *)
325+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
326+
extension CheckedContinuation {
327+
@available(SwiftStdlib 5.1, *)
328+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
329+
public func resume<Er: Error>(with result: Result<T, Er>) where E == Error {
330+
fatalError("Unavailable in task-to-thread concurrency model")
331+
}
332+
333+
@available(SwiftStdlib 5.1, *)
334+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
335+
public func resume(with result: Result<T, E>) {
336+
fatalError("Unavailable in task-to-thread concurrency model")
337+
}
299338

339+
@available(SwiftStdlib 5.1, *)
340+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
341+
public func resume() where T == Void {
342+
fatalError("Unavailable in task-to-thread concurrency model")
343+
}
344+
}
345+
346+
@available(SwiftStdlib 5.1, *)
347+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
348+
public func withCheckedContinuation<T>(
349+
function: String = #function,
350+
_ body: (CheckedContinuation<T, Never>) -> Void
351+
) async -> T {
352+
fatalError("Unavailable in task-to-thread concurrency model")
353+
}
354+
355+
@available(SwiftStdlib 5.1, *)
356+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
357+
public func withCheckedThrowingContinuation<T>(
358+
function: String = #function,
359+
_ body: (CheckedContinuation<T, Error>) -> Void
360+
) async throws -> T {
361+
fatalError("Unavailable in task-to-thread concurrency model")
362+
}
363+
#endif

test/stdlib/freestanding_diags_stdlib.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ func foo() async {
2424
asyncDetached { () async -> () in } // expected-error{{Unavailable in task-to-thread concurrency model}}
2525
asyncDetached { () async throws -> () in } // expected-error{{Unavailable in task-to-thread concurrency model}}
2626
_ = MainActor.self // expected-error{{Unavailable in task-to-thread concurrency model}}
27+
let _: Int = await withCheckedContinuation { _ in } // expected-error{{Unavailable in task-to-thread concurrency model}}
28+
do {
29+
let _: Int = try await withCheckedThrowingContinuation { _ in } // expected-error{{Unavailable in task-to-thread concurrency model}}
30+
} catch let error {
31+
_ = error
32+
}
33+
_ = CheckedContinuation<Int, Never>.self // expected-error{{Unavailable in task-to-thread concurrency model}}
2734
}
2835

2936
func foo2(

0 commit comments

Comments
 (0)