Skip to content
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

Mark all iterators as non-Sendable #280

Merged
merged 1 commit into from
Jul 27, 2023
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
46 changes: 23 additions & 23 deletions Sources/AsyncAlgorithms/AsyncAdjacentPairsSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@
//
//===----------------------------------------------------------------------===//

extension AsyncSequence {
/// An `AsyncSequence` that iterates over the adjacent pairs of the original
/// original `AsyncSequence`.
///
/// ```
/// for await (first, second) in (1...5).async.adjacentPairs() {
/// print("First: \(first), Second: \(second)")
/// }
///
/// // First: 1, Second: 2
/// // First: 2, Second: 3
/// // First: 3, Second: 4
/// // First: 4, Second: 5
/// ```
///
/// - Returns: An `AsyncSequence` where the element is a tuple of two adjacent elements
/// or the original `AsyncSequence`.
@inlinable
public func adjacentPairs() -> AsyncAdjacentPairsSequence<Self> {
AsyncAdjacentPairsSequence(self)
}
}

/// An `AsyncSequence` that iterates over the adjacent pairs of the original
/// `AsyncSequence`.
@frozen
Expand Down Expand Up @@ -60,29 +83,6 @@ public struct AsyncAdjacentPairsSequence<Base: AsyncSequence>: AsyncSequence {
}
}

extension AsyncSequence {
/// An `AsyncSequence` that iterates over the adjacent pairs of the original
/// original `AsyncSequence`.
///
/// ```
/// for await (first, second) in (1...5).async.adjacentPairs() {
/// print("First: \(first), Second: \(second)")
/// }
///
/// // First: 1, Second: 2
/// // First: 2, Second: 3
/// // First: 3, Second: 4
/// // First: 4, Second: 5
/// ```
///
/// - Returns: An `AsyncSequence` where the element is a tuple of two adjacent elements
/// or the original `AsyncSequence`.
@inlinable
public func adjacentPairs() -> AsyncAdjacentPairsSequence<Self> {
AsyncAdjacentPairsSequence(self)
}
}

extension AsyncAdjacentPairsSequence: Sendable where Base: Sendable, Base.Element: Sendable { }

@available(*, unavailable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension AsyncTimerSequence: Sendable { }
extension AsyncTimerSequence.Iterator: Sendable { }
```

Since all the types comprising `AsyncTimerSequence` and it's `Iterator` are `Sendable` these types are also `Sendable`.
Since all the types comprising `AsyncTimerSequence` are `Sendable` these types are also `Sendable`.

## Credits/Inspiration

Expand Down
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncChain3Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ extension AsyncChain3Sequence: AsyncSequence {
}

extension AsyncChain3Sequence: Sendable where Base1: Sendable, Base2: Sendable, Base3: Sendable { }

@available(*, unavailable)
extension AsyncChain3Sequence.Iterator: Sendable { }
4 changes: 3 additions & 1 deletion Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ public struct AsyncChunkedByGroupSequence<Base: AsyncSequence, Collected: RangeR
}

extension AsyncChunkedByGroupSequence : Sendable where Base : Sendable, Base.Element : Sendable { }
extension AsyncChunkedByGroupSequence.Iterator : Sendable where Base.AsyncIterator : Sendable, Base.Element : Sendable { }

@available(*, unavailable)
extension AsyncChunkedByGroupSequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ public struct AsyncChunkedOnProjectionSequence<Base: AsyncSequence, Subject: Equ
}

extension AsyncChunkedOnProjectionSequence : Sendable where Base : Sendable, Base.Element : Sendable { }
extension AsyncChunkedOnProjectionSequence.Iterator : Sendable where Base.AsyncIterator : Sendable, Base.Element : Sendable, Subject : Sendable { }

@available(*, unavailable)
extension AsyncChunkedOnProjectionSequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ public struct AsyncChunksOfCountOrSignalSequence<Base: AsyncSequence, Collected:
return Iterator(iterator: merge(chain(base.map { Either.element($0) }, [.terminal].async), signal.map { _ in Either.signal }).makeAsyncIterator(), count: count)
}
}

@available(*, unavailable)
extension AsyncChunksOfCountOrSignalSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncChunksOfCountSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ public struct AsyncChunksOfCountSequence<Base: AsyncSequence, Collected: RangeRe

extension AsyncChunksOfCountSequence : Sendable where Base : Sendable, Base.Element : Sendable { }
extension AsyncChunksOfCountSequence.Iterator : Sendable where Base.AsyncIterator : Sendable, Base.Element : Sendable { }

@available(*, unavailable)
extension AsyncChunksOfCountSequence.Iterator: Sendable { }
37 changes: 19 additions & 18 deletions Sources/AsyncAlgorithms/AsyncCompactedSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
//
//===----------------------------------------------------------------------===//

extension AsyncSequence {
/// Returns a new `AsyncSequence` that iterates over every non-nil element from the
/// original `AsyncSequence`.
///
/// Produces the same result as `c.compactMap { $0 }`.
///
/// - Returns: An `AsyncSequence` where the element is the unwrapped original
/// element and iterates over every non-nil element from the original
/// `AsyncSequence`.
@inlinable
public func compacted<Unwrapped>() -> AsyncCompactedSequence<Self, Unwrapped>
where Element == Unwrapped? {
AsyncCompactedSequence(self)
}
}

/// An `AsyncSequence` that iterates over every non-nil element from the original
/// `AsyncSequence`.
@frozen
Expand Down Expand Up @@ -50,22 +66,7 @@ public struct AsyncCompactedSequence<Base: AsyncSequence, Element>: AsyncSequenc
}
}

extension AsyncSequence {
/// Returns a new `AsyncSequence` that iterates over every non-nil element from the
/// original `AsyncSequence`.
///
/// Produces the same result as `c.compactMap { $0 }`.
///
/// - Returns: An `AsyncSequence` where the element is the unwrapped original
/// element and iterates over every non-nil element from the original
/// `AsyncSequence`.
///
/// Complexity: O(1)
@inlinable
public func compacted<Unwrapped>() -> AsyncCompactedSequence<Self, Unwrapped>
where Element == Unwrapped? {
AsyncCompactedSequence(self)
}
}

extension AsyncCompactedSequence: Sendable where Base: Sendable, Base.Element: Sendable { }

@available(*, unavailable)
extension AsyncCompactedSequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ extension AsyncExclusiveReductionsSequence: AsyncSequence {
}

extension AsyncExclusiveReductionsSequence: Sendable where Base: Sendable, Element: Sendable { }

@available(*, unavailable)
extension AsyncExclusiveReductionsSequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ extension AsyncInclusiveReductionsSequence: AsyncSequence {
}

extension AsyncInclusiveReductionsSequence: Sendable where Base: Sendable { }

@available(*, unavailable)
extension AsyncInclusiveReductionsSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ public struct AsyncJoinedBySeparatorSequence<Base: AsyncSequence, Separator: Asy

extension AsyncJoinedBySeparatorSequence: Sendable
where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable, Separator: Sendable { }

@available(*, unavailable)
extension AsyncJoinedBySeparatorSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncJoinedSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ public struct AsyncJoinedSequence<Base: AsyncSequence>: AsyncSequence where Base

extension AsyncJoinedSequence: Sendable
where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable { }

@available(*, unavailable)
extension AsyncJoinedSequence.Iterator: Sendable { }
6 changes: 6 additions & 0 deletions Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ public struct AsyncThrowingRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncS

extension AsyncRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { }
extension AsyncThrowingRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { }

@available(*, unavailable)
extension AsyncRemoveDuplicatesSequence.Iterator: Sendable { }

@available(*, unavailable)
extension AsyncThrowingRemoveDuplicatesSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncSyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ public struct AsyncSyncSequence<Base: Sequence>: AsyncSequence {
}

extension AsyncSyncSequence: Sendable where Base: Sendable { }

@available(*, unavailable)
extension AsyncSyncSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncThrottleSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ extension AsyncThrottleSequence: AsyncSequence {

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncThrottleSequence: Sendable where Base: Sendable, Element: Sendable { }

@available(*, unavailable)
extension AsyncThrottleSequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ extension AsyncThrowingExclusiveReductionsSequence: AsyncSequence {
}

extension AsyncThrowingExclusiveReductionsSequence: Sendable where Base: Sendable, Element: Sendable { }

@available(*, unavailable)
extension AsyncThrowingExclusiveReductionsSequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Async Algorithms open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

extension AsyncSequence {
/// Returns an asynchronous sequence containing the accumulated results of combining the
/// elements of the asynchronous sequence using the given error-throwing closure.
Expand Down Expand Up @@ -89,3 +100,6 @@ extension AsyncThrowingInclusiveReductionsSequence: AsyncSequence {
}

extension AsyncThrowingInclusiveReductionsSequence: Sendable where Base: Sendable { }

@available(*, unavailable)
extension AsyncThrowingInclusiveReductionsSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/AsyncTimerSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ extension AsyncTimerSequence where C == SuspendingClock {

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncTimerSequence: Sendable { }

@available(*, unavailable)
extension AsyncTimerSequence.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/Channels/AsyncChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ public final class AsyncChannel<Element: Sendable>: AsyncSequence, @unchecked Se
}
}
}

@available(*, unavailable)
extension AsyncChannel.Iterator: Sendable { }
3 changes: 3 additions & 0 deletions Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
}
}
}

@available(*, unavailable)
extension AsyncThrowingChannel.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ public struct AsyncCombineLatest2Sequence<
}
}
}

@available(*, unavailable)
extension AsyncCombineLatest2Sequence.Iterator: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ public struct AsyncCombineLatest3Sequence<
}
}
}

@available(*, unavailable)
extension AsyncCombineLatest3Sequence.Iterator: Sendable { }
9 changes: 6 additions & 3 deletions Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ public struct AsyncDebounceSequence<Base: AsyncSequence, C: Clock>: Sendable whe
extension AsyncDebounceSequence: AsyncSequence {
public typealias Element = Base.Element

public func makeAsyncIterator() -> AsyncIterator {
public func makeAsyncIterator() -> Iterator {
let storage = DebounceStorage(
base: self.base,
interval: self.interval,
tolerance: self.tolerance,
clock: self.clock
)
return AsyncIterator(storage: storage)
return Iterator(storage: storage)
}
}

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncDebounceSequence {
public struct AsyncIterator: AsyncIteratorProtocol {
public struct Iterator: AsyncIteratorProtocol {
/// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped.
///
/// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself.
Expand Down Expand Up @@ -97,3 +97,6 @@ extension AsyncDebounceSequence {
}
}
}

@available(*, unavailable)
extension AsyncDebounceSequence.Iterator: Sendable { }
9 changes: 6 additions & 3 deletions Sources/AsyncAlgorithms/Merge/AsyncMerge2Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ public struct AsyncMerge2Sequence<
}

extension AsyncMerge2Sequence: AsyncSequence {
public func makeAsyncIterator() -> AsyncIterator {
public func makeAsyncIterator() -> Iterator {
let storage = MergeStorage<Base1, Base2, Base1>(
base1: base1,
base2: base2,
base3: nil
)
return AsyncIterator(storage: storage)
return Iterator(storage: storage)
}
}

extension AsyncMerge2Sequence {
public struct AsyncIterator: AsyncIteratorProtocol {
public struct Iterator: AsyncIteratorProtocol {
/// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped.
///
/// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself.
Expand Down Expand Up @@ -92,3 +92,6 @@ extension AsyncMerge2Sequence {
}
}
}

@available(*, unavailable)
extension AsyncMerge2Sequence.Iterator: Sendable { }
9 changes: 6 additions & 3 deletions Sources/AsyncAlgorithms/Merge/AsyncMerge3Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ public struct AsyncMerge3Sequence<
}

extension AsyncMerge3Sequence: AsyncSequence {
public func makeAsyncIterator() -> AsyncIterator {
public func makeAsyncIterator() -> Iterator {
let storage = MergeStorage(
base1: base1,
base2: base2,
base3: base3
)
return AsyncIterator(storage: storage)
return Iterator(storage: storage)
}
}

public extension AsyncMerge3Sequence {
struct AsyncIterator: AsyncIteratorProtocol {
struct Iterator: AsyncIteratorProtocol {
/// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped.
///
/// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself.
Expand Down Expand Up @@ -103,3 +103,6 @@ public extension AsyncMerge3Sequence {
}
}
}

@available(*, unavailable)
extension AsyncMerge3Sequence.Iterator: Sendable { }
Loading