Skip to content

[Freestanding] Disable checked continuations. #60790

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 1 commit into from
Aug 31, 2022
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
64 changes: 64 additions & 0 deletions stdlib/public/Concurrency/CheckedContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Swift
@_silgen_name("swift_continuation_logFailedCheck")
internal func logFailedCheck(_ message: UnsafeRawPointer)

#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
/// Implementation class that holds the `UnsafeContinuation` instance for
/// a `CheckedContinuation`.
@available(SwiftStdlib 5.1, *)
Expand Down Expand Up @@ -82,7 +83,9 @@ internal final class CheckedContinuationCanary: @unchecked Sendable {
}
}
}
#endif

#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
/// A mechanism to interface
/// between synchronous and asynchronous code,
/// logging correctness violations.
Expand Down Expand Up @@ -296,4 +299,65 @@ public func withCheckedThrowingContinuation<T>(
body(CheckedContinuation(continuation: $0, function: function))
}
}
#else
Copy link
Collaborator

@theblixguy theblixguy Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered using SE-0367? I think using that you can conditionally add the available attribute on the main declaration and avoid having to duplicate it.

So for example just above main declaration public struct CheckedContinuation, you can add:

#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
  @available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation also changes.

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public struct CheckedContinuation<T, E: Error>: Sendable {
@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public init(continuation: UnsafeContinuation<T, E>, function: String = #function) {
fatalError("Unavailable in task-to-thread concurrency model")
}

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func resume(returning value: __owned T) {
fatalError("Unavailable in task-to-thread concurrency model")
}

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func resume(throwing error: __owned E) {
fatalError("Unavailable in task-to-thread concurrency model")
}
}
@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
extension CheckedContinuation {
@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func resume<Er: Error>(with result: Result<T, Er>) where E == Error {
fatalError("Unavailable in task-to-thread concurrency model")
}

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func resume(with result: Result<T, E>) {
fatalError("Unavailable in task-to-thread concurrency model")
}

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func resume() where T == Void {
fatalError("Unavailable in task-to-thread concurrency model")
}
}

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func withCheckedContinuation<T>(
function: String = #function,
_ body: (CheckedContinuation<T, Never>) -> Void
) async -> T {
fatalError("Unavailable in task-to-thread concurrency model")
}

@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
public func withCheckedThrowingContinuation<T>(
function: String = #function,
_ body: (CheckedContinuation<T, Error>) -> Void
) async throws -> T {
fatalError("Unavailable in task-to-thread concurrency model")
}
#endif
7 changes: 7 additions & 0 deletions test/stdlib/freestanding_diags_stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func foo() async {
asyncDetached { () async -> () in } // expected-error{{Unavailable in task-to-thread concurrency model}}
asyncDetached { () async throws -> () in } // expected-error{{Unavailable in task-to-thread concurrency model}}
_ = MainActor.self // expected-error{{Unavailable in task-to-thread concurrency model}}
let _: Int = await withCheckedContinuation { _ in } // expected-error{{Unavailable in task-to-thread concurrency model}}
do {
let _: Int = try await withCheckedThrowingContinuation { _ in } // expected-error{{Unavailable in task-to-thread concurrency model}}
} catch let error {
_ = error
}
_ = CheckedContinuation<Int, Never>.self // expected-error{{Unavailable in task-to-thread concurrency model}}
}

func foo2(
Expand Down