Skip to content

Commit ac07031

Browse files
Merge pull request #60919 from nate-chandler/rdar99444461
[Freestanding] Disable Task.sleep and AsyncStream.
2 parents 0f8b42a + c574550 commit ac07031

12 files changed

+680
-1
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Swift
1414

15+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
1516
/// An asynchronous sequence generated from a closure that calls a continuation
1617
/// to produce new elements.
1718
///
@@ -429,3 +430,113 @@ extension AsyncStream.Continuation {
429430

430431
@available(SwiftStdlib 5.1, *)
431432
extension AsyncStream: @unchecked Sendable where Element: Sendable { }
433+
#else
434+
@available(SwiftStdlib 5.1, *)
435+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
436+
public struct AsyncStream<Element> {
437+
@available(SwiftStdlib 5.1, *)
438+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
439+
public struct Continuation: Sendable {
440+
@available(SwiftStdlib 5.1, *)
441+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
442+
public enum Termination {
443+
case finished
444+
case cancelled
445+
}
446+
@available(SwiftStdlib 5.1, *)
447+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
448+
public enum YieldResult {
449+
case enqueued(remaining: Int)
450+
case dropped(Element)
451+
case terminated
452+
}
453+
@available(SwiftStdlib 5.1, *)
454+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
455+
public enum BufferingPolicy {
456+
case unbounded
457+
case bufferingOldest(Int)
458+
case bufferingNewest(Int)
459+
}
460+
@discardableResult
461+
@available(SwiftStdlib 5.1, *)
462+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
463+
public func yield(_ value: __owned Element) -> YieldResult {
464+
fatalError("Unavailable in task-to-thread concurrency model")
465+
}
466+
@available(SwiftStdlib 5.1, *)
467+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
468+
public func finish() {
469+
fatalError("Unavailable in task-to-thread concurrency model")
470+
}
471+
@available(SwiftStdlib 5.1, *)
472+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
473+
public var onTermination: (@Sendable (Termination) -> Void)? {
474+
get {
475+
fatalError("Unavailable in task-to-thread concurrency model")
476+
}
477+
nonmutating set {
478+
fatalError("Unavailable in task-to-thread concurrency model")
479+
}
480+
}
481+
}
482+
@available(SwiftStdlib 5.1, *)
483+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
484+
public init(
485+
_ elementType: Element.Type = Element.self,
486+
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded,
487+
_ build: (Continuation) -> Void
488+
) {
489+
fatalError("Unavailable in task-to-thread concurrency model")
490+
}
491+
@available(SwiftStdlib 5.1, *)
492+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
493+
public init(
494+
unfolding produce: @escaping () async -> Element?,
495+
onCancel: (@Sendable () -> Void)? = nil
496+
) {
497+
fatalError("Unavailable in task-to-thread concurrency model")
498+
}
499+
}
500+
501+
@available(SwiftStdlib 5.1, *)
502+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
503+
extension AsyncStream {
504+
@available(SwiftStdlib 5.1, *)
505+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
506+
public struct Iterator {
507+
@available(SwiftStdlib 5.1, *)
508+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
509+
public mutating func next() async -> Element? {
510+
fatalError("Unavailable in task-to-thread concurrency model")
511+
}
512+
}
513+
@available(SwiftStdlib 5.1, *)
514+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
515+
public func makeAsyncIterator() -> Iterator {
516+
fatalError("Unavailable in task-to-thread concurrency model")
517+
}
518+
}
519+
520+
@available(SwiftStdlib 5.1, *)
521+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
522+
extension AsyncStream.Continuation {
523+
@discardableResult
524+
@available(SwiftStdlib 5.1, *)
525+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
526+
public func yield(
527+
with result: Result<Element, Never>
528+
) -> YieldResult {
529+
fatalError("Unavailable in task-to-thread concurrency model")
530+
}
531+
@discardableResult
532+
@available(SwiftStdlib 5.1, *)
533+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
534+
public func yield() -> YieldResult where Element == Void {
535+
fatalError("Unavailable in task-to-thread concurrency model")
536+
}
537+
}
538+
539+
@available(SwiftStdlib 5.1, *)
540+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
541+
extension AsyncStream: @unchecked Sendable where Element: Sendable { }
542+
#endif

stdlib/public/Concurrency/AsyncStreamBuffer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Swift
1414

15+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
1516
#if ASYNC_STREAM_STANDALONE
1617
@_exported import _Concurrency
1718
import Darwin
@@ -592,3 +593,4 @@ final class _AsyncStreamCriticalStorage<Contents>: @unchecked Sendable {
592593
return storage
593594
}
594595
}
596+
#endif

stdlib/public/Concurrency/AsyncThrowingStream.swift

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Swift
1414

15+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
1516
/// An asynchronous sequence generated from an error-throwing closure that
1617
/// calls a continuation to produce new elements.
1718
///
@@ -474,3 +475,112 @@ extension AsyncThrowingStream.Continuation {
474475

475476
@available(SwiftStdlib 5.1, *)
476477
extension AsyncThrowingStream: @unchecked Sendable where Element: Sendable { }
478+
#else
479+
@available(SwiftStdlib 5.1, *)
480+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
481+
public struct AsyncThrowingStream<Element, Failure: Error> {
482+
@available(SwiftStdlib 5.1, *)
483+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
484+
public struct Continuation: Sendable {
485+
@available(SwiftStdlib 5.1, *)
486+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
487+
public enum Termination {
488+
case finished(Failure?)
489+
case cancelled
490+
}
491+
@available(SwiftStdlib 5.1, *)
492+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
493+
public enum YieldResult {
494+
case enqueued(remaining: Int)
495+
case dropped(Element)
496+
case terminated
497+
}
498+
@available(SwiftStdlib 5.1, *)
499+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
500+
public enum BufferingPolicy {
501+
case unbounded
502+
case bufferingOldest(Int)
503+
case bufferingNewest(Int)
504+
}
505+
@discardableResult
506+
@available(SwiftStdlib 5.1, *)
507+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
508+
public func yield(_ value: __owned Element) -> YieldResult {
509+
fatalError("Unavailable in task-to-thread concurrency model")
510+
}
511+
@available(SwiftStdlib 5.1, *)
512+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
513+
public func finish(throwing error: __owned Failure? = nil) {
514+
fatalError("Unavailable in task-to-thread concurrency model")
515+
}
516+
@available(SwiftStdlib 5.1, *)
517+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
518+
public var onTermination: (@Sendable (Termination) -> Void)? {
519+
get {
520+
fatalError("Unavailable in task-to-thread concurrency model")
521+
}
522+
nonmutating set {
523+
fatalError("Unavailable in task-to-thread concurrency model")
524+
}
525+
}
526+
}
527+
@available(SwiftStdlib 5.1, *)
528+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
529+
public init(
530+
_ elementType: Element.Type = Element.self,
531+
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded,
532+
_ build: (Continuation) -> Void
533+
) where Failure == Error {
534+
fatalError("Unavailable in task-to-thread concurrency model")
535+
}
536+
@available(SwiftStdlib 5.1, *)
537+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
538+
public init(
539+
unfolding produce: @escaping () async throws -> Element?
540+
) where Failure == Error {
541+
fatalError("Unavailable in task-to-thread concurrency model")
542+
}
543+
}
544+
545+
@available(SwiftStdlib 5.1, *)
546+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
547+
extension AsyncThrowingStream {
548+
@available(SwiftStdlib 5.1, *)
549+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
550+
public struct Iterator {
551+
@available(SwiftStdlib 5.1, *)
552+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
553+
public mutating func next() async throws -> Element? {
554+
fatalError("Unavailable in task-to-thread concurrency model")
555+
}
556+
}
557+
@available(SwiftStdlib 5.1, *)
558+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
559+
public func makeAsyncIterator() -> Iterator {
560+
fatalError("Unavailable in task-to-thread concurrency model")
561+
}
562+
}
563+
564+
@available(SwiftStdlib 5.1, *)
565+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
566+
extension AsyncThrowingStream.Continuation {
567+
@discardableResult
568+
@available(SwiftStdlib 5.1, *)
569+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
570+
public func yield(
571+
with result: Result<Element, Failure>
572+
) -> YieldResult where Failure == Error {
573+
fatalError("Unavailable in task-to-thread concurrency model")
574+
}
575+
@discardableResult
576+
@available(SwiftStdlib 5.1, *)
577+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
578+
public func yield() -> YieldResult where Element == Void {
579+
fatalError("Unavailable in task-to-thread concurrency model")
580+
}
581+
}
582+
583+
@available(SwiftStdlib 5.1, *)
584+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
585+
extension AsyncThrowingStream: @unchecked Sendable where Element: Sendable { }
586+
#endif

stdlib/public/Concurrency/Clock.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public protocol Clock<Duration>: Sendable {
3838
var now: Instant { get }
3939
var minimumResolution: Instant.Duration { get }
4040

41+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4142
func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws
43+
#endif
4244
}
4345

4446

stdlib/public/Concurrency/ContinuousClock.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ extension ContinuousClock: Clock {
7575
.seconds(seconds) + .nanoseconds(nanoseconds))
7676
}
7777

78+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
7879
/// Suspend task execution until a given deadline within a tolerance.
7980
/// If no tolerance is specified then the system may adjust the deadline
8081
/// to coalesce CPU wake-ups to more efficiently process the wake-ups in
@@ -93,6 +94,15 @@ extension ContinuousClock: Clock {
9394
tolerance: tolerance,
9495
clock: .continuous)
9596
}
97+
#else
98+
@available(SwiftStdlib 5.7, *)
99+
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
100+
public func sleep(
101+
until deadline: Instant, tolerance: Swift.Duration? = nil
102+
) async throws {
103+
fatalError("Unavailable in task-to-thread concurrency model")
104+
}
105+
#endif
96106
}
97107

98108
@available(SwiftStdlib 5.7, *)

0 commit comments

Comments
 (0)