From 0339eee21ea02105cb109f6ec0d7054b43d6e623 Mon Sep 17 00:00:00 2001 From: Philippe Hausler Date: Tue, 9 Sep 2025 09:34:01 -0700 Subject: [PATCH] Fix up some availability issues w.r.t. sendable metatypes --- Sources/AsyncAlgorithms/AsyncShareSequence.swift | 10 ++++++---- Sources/AsyncAlgorithms/SendableMetatypes.swift | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 Sources/AsyncAlgorithms/SendableMetatypes.swift diff --git a/Sources/AsyncAlgorithms/AsyncShareSequence.swift b/Sources/AsyncAlgorithms/AsyncShareSequence.swift index 9367f67..6bdee70 100644 --- a/Sources/AsyncAlgorithms/AsyncShareSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncShareSequence.swift @@ -13,7 +13,7 @@ import Synchronization import DequeModule @available(AsyncAlgorithms 1.1, *) -extension AsyncSequence where Element: Sendable, Self: SendableMetatype, AsyncIterator: SendableMetatype { +extension AsyncSequence where Element: Sendable, Self: _AsyncSequenceSendableMetatype, AsyncIterator: _AsyncIteratorSendableMetatype { /// Creates a shared async sequence that allows multiple concurrent iterations over a single source. /// /// The `share` method transforms an async sequence into a shareable sequence that can be safely @@ -107,7 +107,7 @@ extension AsyncSequence where Element: Sendable, Self: SendableMetatype, AsyncIt // This type is typically not used directly; instead, use the `share()` method on any // async sequence that meets the sendability requirements. @available(AsyncAlgorithms 1.1, *) -struct AsyncShareSequence: Sendable where Base.Element: Sendable, Base: SendableMetatype, Base.AsyncIterator: SendableMetatype { +struct AsyncShareSequence: Sendable where Base.Element: Sendable, Base: _AsyncSequenceSendableMetatype, Base.AsyncIterator: _AsyncIteratorSendableMetatype { // Represents a single consumer's connection to the shared sequence. // // Each iterator of the shared sequence creates its own `Side` instance, which tracks @@ -586,7 +586,7 @@ struct AsyncShareSequence: Sendable where Base.Element: Sen if let factory { let task: Task // for the fancy dance of availability and canImport see the comment on the next check for details -#if canImport(_Concurrency, _version: 6.2) +#if swift(>=6.2) if #available(macOS 26.0, iOS 26.0, tvOS 26.0, visionOS 26.0, *) { task = Task(name: "Share Iteration") { [factory, self] in await iterationLoop(factory: factory) @@ -616,7 +616,9 @@ struct AsyncShareSequence: Sendable where Base.Element: Sen // the _Concurrency library. This menas for Darwin based OSes we have to have a fallback at runtime, // and for non-darwin OSes we need to verify against the ability to import that version. // Using this priority escalation means that the base task can avoid being detached. -#if canImport(_Concurrency, _version: 6.2) + // + // This is disabled for now until the 9999 availability is removed from `withTaskPriorityEscalationHandler` +#if false /*swift(>=6.2)*/ if #available(macOS 26.0, iOS 26.0, tvOS 26.0, visionOS 26.0, *) { return try await withTaskPriorityEscalationHandler { return await nextIteration(id) diff --git a/Sources/AsyncAlgorithms/SendableMetatypes.swift b/Sources/AsyncAlgorithms/SendableMetatypes.swift new file mode 100644 index 0000000..e8d4ba5 --- /dev/null +++ b/Sources/AsyncAlgorithms/SendableMetatypes.swift @@ -0,0 +1,7 @@ +#if compiler(>=6.2) +public typealias _AsyncSequenceSendableMetatype = SendableMetatype +public typealias _AsyncIteratorSendableMetatype = SendableMetatype +#else +public typealias _AsyncSequenceSendableMetatype = Any +public typealias _AsyncIteratorSendableMetatype = Any +#endif \ No newline at end of file