Skip to content

Commit 0174f58

Browse files
authored
Cleanup Sendable conformances and @preconcurrency imports to build as strict concurrency clean (#230)
1 parent ae26222 commit 0174f58

29 files changed

+46
-253
lines changed

Sources/AsyncAlgorithms/AsyncBufferSequence.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public actor AsyncLimitBuffer<Element: Sendable>: AsyncBuffer {
198198
}
199199
}
200200

201-
extension AsyncSequence where Element: Sendable {
201+
extension AsyncSequence where Element: Sendable, Self: Sendable {
202202
/// Creates an asynchronous sequence that buffers elements using a buffer created from a supplied closure.
203203
///
204204
/// Use the `buffer(_:)` method to account for `AsyncSequence` types that may produce elements faster
@@ -224,7 +224,7 @@ extension AsyncSequence where Element: Sendable {
224224
}
225225

226226
/// An `AsyncSequence` that buffers elements utilizing an `AsyncBuffer`.
227-
public struct AsyncBufferSequence<Base: AsyncSequence, Buffer: AsyncBuffer> where Base.Element == Buffer.Input, Base.AsyncIterator: Sendable {
227+
public struct AsyncBufferSequence<Base: AsyncSequence & Sendable, Buffer: AsyncBuffer> where Base.Element == Buffer.Input {
228228
let base: Base
229229
let createBuffer: @Sendable () -> Buffer
230230

@@ -246,11 +246,11 @@ extension AsyncBufferSequence: AsyncSequence {
246246
let buffer: Buffer
247247
let state: AsyncBufferState<Buffer.Input, Buffer.Output>
248248

249-
init(_ iterator: Base.AsyncIterator, buffer: Buffer, state: AsyncBufferState<Buffer.Input, Buffer.Output>) {
249+
init(_ base: Base, buffer: Buffer, state: AsyncBufferState<Buffer.Input, Buffer.Output>) {
250250
self.buffer = buffer
251251
self.state = state
252252
task = Task {
253-
var iter = iterator
253+
var iter = base.makeAsyncIterator()
254254
do {
255255
while let item = try await iter.next() {
256256
await state.enqueue(item, buffer: buffer)
@@ -279,21 +279,21 @@ extension AsyncBufferSequence: AsyncSequence {
279279
}
280280

281281
enum State {
282-
case idle(Base.AsyncIterator, @Sendable () -> Buffer)
282+
case idle(Base, @Sendable () -> Buffer)
283283
case active(Active)
284284
}
285285

286286
var state: State
287287

288-
init(_ iterator: Base.AsyncIterator, createBuffer: @Sendable @escaping () -> Buffer) {
289-
state = .idle(iterator, createBuffer)
288+
init(_ base: Base, createBuffer: @Sendable @escaping () -> Buffer) {
289+
state = .idle(base, createBuffer)
290290
}
291291

292292
public mutating func next() async rethrows -> Element? {
293293
switch state {
294-
case .idle(let iterator, let createBuffer):
294+
case .idle(let base, let createBuffer):
295295
let bufferState = AsyncBufferState<Base.Element, Buffer.Output>()
296-
let buffer = Active(iterator, buffer: createBuffer(), state: bufferState)
296+
let buffer = Active(base, buffer: createBuffer(), state: bufferState)
297297
state = .active(buffer)
298298
return try await buffer.next()
299299
case .active(let buffer):
@@ -303,6 +303,6 @@ extension AsyncBufferSequence: AsyncSequence {
303303
}
304304

305305
public func makeAsyncIterator() -> Iterator {
306-
Iterator(base.makeAsyncIterator(), createBuffer: createBuffer)
306+
Iterator(base, createBuffer: createBuffer)
307307
}
308308
}

Sources/AsyncAlgorithms/AsyncChannel.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import OrderedCollections
12+
@preconcurrency import OrderedCollections
1313

1414
/// A channel for sending elements from one task to another with back pressure.
1515
///
@@ -58,7 +58,7 @@ public final class AsyncChannel<Element: Sendable>: AsyncSequence, Sendable {
5858
typealias Pending = ChannelToken<UnsafeContinuation<UnsafeContinuation<Element?, Never>?, Never>>
5959
typealias Awaiting = ChannelToken<UnsafeContinuation<Element?, Never>>
6060

61-
struct ChannelToken<Continuation>: Hashable {
61+
struct ChannelToken<Continuation: Sendable>: Hashable, Sendable {
6262
var generation: Int
6363
var continuation: Continuation?
6464

@@ -86,14 +86,14 @@ public final class AsyncChannel<Element: Sendable>: AsyncSequence, Sendable {
8686
case cancelled
8787
}
8888

89-
enum Emission {
89+
enum Emission : Sendable {
9090
case idle
9191
case pending(OrderedSet<Pending>)
9292
case awaiting(OrderedSet<Awaiting>)
9393
case finished
9494
}
9595

96-
struct State {
96+
struct State : Sendable {
9797
var emission: Emission = .idle
9898
var generation = 0
9999
}

Sources/AsyncAlgorithms/AsyncCompactedSequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ extension AsyncSequence {
6868
}
6969
}
7070

71-
extension AsyncCompactedSequence: Sendable where Base: Sendable, Base.Element: Sendable, Base.AsyncIterator: Sendable { }
71+
extension AsyncCompactedSequence: Sendable where Base: Sendable, Base.Element: Sendable { }

Sources/AsyncAlgorithms/AsyncInterspersedSequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ extension AsyncInterspersedSequence: AsyncSequence {
9999
}
100100
}
101101

102-
extension AsyncInterspersedSequence: Sendable where Base: Sendable, Base.Element: Sendable, Base.AsyncIterator: Sendable { }
102+
extension AsyncInterspersedSequence: Sendable where Base: Sendable, Base.Element: Sendable { }

Sources/AsyncAlgorithms/AsyncJoinedSequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ public struct AsyncJoinedSequence<Base: AsyncSequence>: AsyncSequence where Base
9191
}
9292

9393
extension AsyncJoinedSequence: Sendable
94-
where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable, Base.AsyncIterator: Sendable, Base.Element.AsyncIterator: Sendable { }
94+
where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable { }

Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ public struct AsyncRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncSequence
8585
}
8686
}
8787

88-
extension AsyncRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable, Base.AsyncIterator: Sendable { }
89-
90-
9188
/// An asynchronous sequence that omits repeated elements by testing them with an error-throwing predicate.
9289
public struct AsyncThrowingRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncSequence {
9390
public typealias Element = Base.Element
@@ -143,4 +140,6 @@ public struct AsyncThrowingRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncS
143140
}
144141
}
145142

146-
extension AsyncThrowingRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable, Base.AsyncIterator: Sendable { }
143+
144+
extension AsyncRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { }
145+
extension AsyncThrowingRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { }

Sources/AsyncAlgorithms/AsyncThrowingChannel.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import OrderedCollections
12+
@preconcurrency import OrderedCollections
1313

1414
/// An error-throwing channel for sending elements from on task to another with back pressure.
1515
///
@@ -61,7 +61,7 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
6161
typealias Pending = ChannelToken<UnsafeContinuation<UnsafeContinuation<Element?, Error>?, Never>>
6262
typealias Awaiting = ChannelToken<UnsafeContinuation<Element?, Error>>
6363

64-
struct ChannelToken<Continuation>: Hashable {
64+
struct ChannelToken<Continuation: Sendable>: Hashable, Sendable {
6565
var generation: Int
6666
var continuation: Continuation?
6767

@@ -95,14 +95,14 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
9595
case failed(Error)
9696
}
9797

98-
enum Emission {
98+
enum Emission: Sendable {
9999
case idle
100100
case pending(OrderedSet<Pending>)
101101
case awaiting(OrderedSet<Awaiting>)
102102
case terminated(Termination)
103103
}
104104

105-
struct State {
105+
struct State : Sendable {
106106
var emission: Emission = .idle
107107
var generation = 0
108108
}

Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public func combineLatest<
3535
public struct AsyncCombineLatest2Sequence<
3636
Base1: AsyncSequence,
3737
Base2: AsyncSequence
38-
>: AsyncSequence where
38+
>: AsyncSequence, Sendable where
3939
Base1: Sendable,
4040
Base1.Element: Sendable,
4141
Base2: Sendable,

Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct AsyncCombineLatest3Sequence<
3939
Base1: AsyncSequence,
4040
Base2: AsyncSequence,
4141
Base3: AsyncSequence
42-
>: AsyncSequence where
42+
>: AsyncSequence, Sendable where
4343
Base1: Sendable,
4444
Base1.Element: Sendable,
4545
Base2: Sendable,

Sources/AsyncAlgorithms/Zip/AsyncZip2Sequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public func zip<Base1: AsyncSequence, Base2: AsyncSequence>(
2020

2121
/// An asynchronous sequence that concurrently awaits values from two `AsyncSequence` types
2222
/// and emits a tuple of the values.
23-
public struct AsyncZip2Sequence<Base1: AsyncSequence, Base2: AsyncSequence>: AsyncSequence
23+
public struct AsyncZip2Sequence<Base1: AsyncSequence, Base2: AsyncSequence>: AsyncSequence, Sendable
2424
where Base1: Sendable, Base1.Element: Sendable, Base2: Sendable, Base2.Element: Sendable {
2525
public typealias Element = (Base1.Element, Base2.Element)
2626
public typealias AsyncIterator = Iterator

Sources/AsyncAlgorithms/Zip/AsyncZip3Sequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public func zip<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence
2121

2222
/// An asynchronous sequence that concurrently awaits values from three `AsyncSequence` types
2323
/// and emits a tuple of the values.
24-
public struct AsyncZip3Sequence<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence>: AsyncSequence
24+
public struct AsyncZip3Sequence<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence>: AsyncSequence, Sendable
2525
where Base1: Sendable, Base1.Element: Sendable, Base2: Sendable, Base2.Element: Sendable, Base3: Sendable, Base3.Element: Sendable {
2626
public typealias Element = (Base1.Element, Base2.Element, Base3.Element)
2727
public typealias AsyncIterator = Iterator

Tests/AsyncAlgorithmsTests/Performance/ThroughputMeasurement.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import AsyncAlgorithms
1313
import Foundation
14-
@preconcurrency import XCTest
14+
import XCTest
1515

1616
#if canImport(Darwin)
1717
public struct InfiniteAsyncSequence<Value: Sendable>: AsyncSequence, Sendable {

Tests/AsyncAlgorithmsTests/Support/ReportingSequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class ReportingSequence<Element>: Sequence, IteratorProtocol {
4343
}
4444
}
4545

46-
final class ReportingAsyncSequence<Element>: AsyncSequence, AsyncIteratorProtocol {
46+
final class ReportingAsyncSequence<Element: Sendable>: AsyncSequence, AsyncIteratorProtocol, @unchecked Sendable {
4747
enum Event: Equatable, CustomStringConvertible {
4848
case next
4949
case makeAsyncIterator

Tests/AsyncAlgorithmsTests/TestAdjacentPairs.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
@preconcurrency import XCTest
12+
import XCTest
1313
import AsyncAlgorithms
1414

1515
final class TestAdjacentPairs: XCTestCase {

0 commit comments

Comments
 (0)