Skip to content

Commit 4b11faa

Browse files
authored
Clean up some more warnings via an additional Sendability pass audit (#72)
1 parent 624eea0 commit 4b11faa

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

Sources/AsyncAlgorithms/AsyncBufferedByteIterator.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,13 @@ public struct AsyncBufferedByteIterator: AsyncIteratorProtocol, Sendable {
6767
@frozen @usableFromInline
6868
internal struct _AsyncBytesBuffer: @unchecked Sendable {
6969
@usableFromInline
70-
final class Storage {
71-
fileprivate let readFunction: @Sendable (UnsafeMutableRawBufferPointer) async throws -> Int
70+
final class Storage: Sendable {
7271
fileprivate let buffer: UnsafeMutableRawBufferPointer
73-
fileprivate var finished = false
7472

7573
init(
76-
capacity: Int,
77-
readFunction: @Sendable @escaping (UnsafeMutableRawBufferPointer) async throws -> Int
74+
capacity: Int
7875
) {
7976
precondition(capacity > 0)
80-
self.readFunction = readFunction
8177
buffer = UnsafeMutableRawBufferPointer.allocate(
8278
byteCount: capacity,
8379
alignment: MemoryLayout<AnyObject>.alignment
@@ -93,33 +89,37 @@ internal struct _AsyncBytesBuffer: @unchecked Sendable {
9389
@usableFromInline internal var nextPointer: UnsafeRawPointer
9490
@usableFromInline internal var endPointer: UnsafeRawPointer
9591

92+
internal let readFunction: @Sendable (UnsafeMutableRawBufferPointer) async throws -> Int
93+
internal var finished = false
94+
9695
@usableFromInline init(
9796
capacity: Int,
9897
readFunction: @Sendable @escaping (UnsafeMutableRawBufferPointer) async throws -> Int
9998
) {
100-
let s = Storage(capacity: capacity, readFunction: readFunction)
99+
let s = Storage(capacity: capacity)
100+
self.readFunction = readFunction
101101
storage = s
102102
nextPointer = UnsafeRawPointer(s.buffer.baseAddress!)
103103
endPointer = nextPointer
104104
}
105105

106106
@inline(never) @usableFromInline
107107
internal mutating func reloadBufferAndNext() async throws -> UInt8? {
108-
if storage.finished {
108+
if finished {
109109
return nil
110110
}
111111
try Task.checkCancellation()
112112
do {
113-
let readSize: Int = try await storage.readFunction(storage.buffer)
113+
let readSize: Int = try await readFunction(storage.buffer)
114114
if readSize == 0 {
115-
storage.finished = true
115+
finished = true
116116
nextPointer = endPointer
117117
return nil
118118
}
119119
nextPointer = UnsafeRawPointer(storage.buffer.baseAddress!)
120120
endPointer = nextPointer + readSize
121121
} catch {
122-
storage.finished = true
122+
finished = true
123123
nextPointer = endPointer
124124
throw error
125125
}

Sources/AsyncAlgorithms/AsyncCombineLatest3Sequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public func combineLatest<Base1: AsyncSequence, Base2: AsyncSequence, Base3: Asy
1313
AsyncCombineLatest3Sequence(base1, base2, base3)
1414
}
1515

16-
public struct AsyncCombineLatest3Sequence<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence>
16+
public struct AsyncCombineLatest3Sequence<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence>: Sendable
1717
where
1818
Base1: Sendable, Base2: Sendable, Base3: Sendable,
1919
Base1.Element: Sendable, Base2.Element: Sendable, Base3.Element: Sendable,
@@ -32,7 +32,7 @@ public struct AsyncCombineLatest3Sequence<Base1: AsyncSequence, Base2: AsyncSequ
3232
extension AsyncCombineLatest3Sequence: AsyncSequence {
3333
public typealias Element = (Base1.Element, Base2.Element, Base3.Element)
3434

35-
public struct Iterator: AsyncIteratorProtocol {
35+
public struct Iterator: AsyncIteratorProtocol, Sendable {
3636
var iterator: AsyncCombineLatest2Sequence<AsyncCombineLatest2Sequence<Base1, Base2>, Base3>.Iterator
3737

3838
init(_ base1: Base1.AsyncIterator, _ base2: Base2.AsyncIterator, _ base3: Base3.AsyncIterator) {

Sources/AsyncSequenceValidation/Expectation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
extension AsyncSequenceValidationDiagram {
13-
public struct ExpectationResult {
13+
public struct ExpectationResult: Sendable {
1414
public var expected: [(Clock.Instant, Result<String?, Error>)]
1515
public var actual: [(Clock.Instant, Result<String?, Error>)]
1616
}
1717

18-
public struct ExpectationFailure: CustomStringConvertible {
19-
public enum Kind {
18+
public struct ExpectationFailure: Sendable, CustomStringConvertible {
19+
public enum Kind: Sendable {
2020
case expectedFinishButGotValue(String)
2121
case expectedMismatch(String, String)
2222
case expectedValueButGotFinished(String)

Sources/AsyncSequenceValidation/Input.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension AsyncSequenceValidationDiagram {
2121
let queue: WorkQueue
2222
let index: Int
2323

24-
public struct Iterator: AsyncIteratorProtocol {
24+
public struct Iterator: AsyncIteratorProtocol, Sendable {
2525
let state: ManagedCriticalState<State>
2626
let queue: WorkQueue
2727
let index: Int

Sources/AsyncSequenceValidation/Theme.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension AsyncSequenceValidationTheme where Self == AsyncSequenceValidationDiag
2020
}
2121

2222
extension AsyncSequenceValidationDiagram {
23-
public enum Token {
23+
public enum Token: Sendable {
2424
case step
2525
case error
2626
case finish
@@ -34,7 +34,7 @@ extension AsyncSequenceValidationDiagram {
3434
case value(String)
3535
}
3636

37-
public struct ASCIITheme: AsyncSequenceValidationTheme {
37+
public struct ASCIITheme: AsyncSequenceValidationTheme, Sendable {
3838
public func token(_ character: Character, inValue: Bool) -> AsyncSequenceValidationDiagram.Token {
3939
switch character {
4040
case "-": return .step

Tests/AsyncAlgorithmsTests/TestValidator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

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

1515
final class TestValidator: XCTestCase {

0 commit comments

Comments
 (0)