Skip to content

Commit 5e2361f

Browse files
committed
Fix more Sendable warnings and flaky test
# Motivation We still had some `Sendable` warnings left under strict Concurrency checking. # Modification This PR fixes a bunch of `Sendable` warnings but we still have some left in the validation tests. Additionally, I fixed a flaky test.
1 parent df46b4c commit 5e2361f

File tree

6 files changed

+77
-14
lines changed

6 files changed

+77
-14
lines changed

Package.swift

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.8
22

33
import PackageDescription
44

@@ -20,18 +20,33 @@ let package = Package(
2020
targets: [
2121
.target(
2222
name: "AsyncAlgorithms",
23-
dependencies: [.product(name: "Collections", package: "swift-collections")]
23+
dependencies: [.product(name: "Collections", package: "swift-collections")],
24+
swiftSettings: [
25+
.enableExperimentalFeature("StrictConcurrency=complete"),
26+
]
2427
),
2528
.target(
2629
name: "AsyncSequenceValidation",
27-
dependencies: ["_CAsyncSequenceValidationSupport", "AsyncAlgorithms"]),
30+
dependencies: ["_CAsyncSequenceValidationSupport", "AsyncAlgorithms"],
31+
swiftSettings: [
32+
.enableExperimentalFeature("StrictConcurrency=complete"),
33+
]
34+
),
2835
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
2936
.target(
3037
name: "AsyncAlgorithms_XCTest",
31-
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
38+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"],
39+
swiftSettings: [
40+
.enableExperimentalFeature("StrictConcurrency=complete"),
41+
]
42+
),
3243
.testTarget(
3344
name: "AsyncAlgorithmsTests",
34-
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"]),
45+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"],
46+
swiftSettings: [
47+
.enableExperimentalFeature("StrictConcurrency=complete"),
48+
]
49+
),
3550
]
3651
)
3752

Package@swift-5.7.swift

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// swift-tools-version: 5.6
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-async-algorithms",
7+
platforms: [
8+
.macOS("10.15"),
9+
.iOS("13.0"),
10+
.tvOS("13.0"),
11+
.watchOS("6.0")
12+
],
13+
products: [
14+
.library(name: "AsyncAlgorithms", targets: ["AsyncAlgorithms"]),
15+
.library(name: "AsyncSequenceValidation", targets: ["AsyncSequenceValidation"]),
16+
.library(name: "_CAsyncSequenceValidationSupport", type: .static, targets: ["AsyncSequenceValidation"]),
17+
.library(name: "AsyncAlgorithms_XCTest", targets: ["AsyncAlgorithms_XCTest"]),
18+
],
19+
dependencies: [.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.4"))],
20+
targets: [
21+
.target(
22+
name: "AsyncAlgorithms",
23+
dependencies: [.product(name: "Collections", package: "swift-collections")]
24+
),
25+
.target(
26+
name: "AsyncSequenceValidation",
27+
dependencies: ["_CAsyncSequenceValidationSupport", "AsyncAlgorithms"]),
28+
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
29+
.target(
30+
name: "AsyncAlgorithms_XCTest",
31+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
32+
.testTarget(
33+
name: "AsyncAlgorithmsTests",
34+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"]),
35+
]
36+
)
37+
38+
#if canImport(Darwin)
39+
import Darwin
40+
let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil
41+
#elseif canImport(Glibc)
42+
import Glibc
43+
let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil
44+
#else
45+
let buildingDocs = false
46+
#endif
47+
48+
// Only require the docc plugin when building documentation
49+
package.dependencies += buildingDocs ? [
50+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
51+
] : []

Sources/AsyncAlgorithms/Merge/MergeStorage.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ final class MergeStorage<
198198
private func iterateAsyncSequence<AsyncSequence: _Concurrency.AsyncSequence>(
199199
_ base: AsyncSequence,
200200
in taskGroup: inout ThrowingTaskGroup<Void, Error>
201-
) where AsyncSequence.Element == Base1.Element {
201+
) where AsyncSequence.Element == Base1.Element, AsyncSequence: Sendable {
202202
// For each upstream sequence we are adding a child task that
203203
// is consuming the upstream sequence
204204
taskGroup.addTask {

Tests/AsyncAlgorithmsTests/Interspersed/TestInterspersed.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ final class TestInterspersed: XCTestCase {
166166

167167
while let _ = await iterator.next() {}
168168

169-
let pastEnd = await iterator.next()
170-
XCTAssertNil(pastEnd)
171-
172-
// Information the parent task that we finished consuming
173169
await lockStepChannel.send(())
174170
}
175171

@@ -179,8 +175,7 @@ final class TestInterspersed: XCTestCase {
179175
// Now we cancel the child
180176
group.cancelAll()
181177

182-
// Waiting until the child task finished consuming
183-
_ = await lockStepChannel.first { _ in true }
178+
await group.waitForAll()
184179
}
185180
}
186181
}

Tests/AsyncAlgorithmsTests/Performance/ThroughputMeasurement.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class _ThroughputMetric: NSObject, XCTMetric, @unchecked Sendable {
5656
}
5757

5858
extension XCTestCase {
59-
public func measureChannelThroughput<Output>(output: @escaping @autoclosure () -> Output) async {
59+
public func measureChannelThroughput<Output: Sendable>(output: @Sendable @escaping @autoclosure () -> Output) async {
6060
let metric = _ThroughputMetric()
6161
let sampleTime: Double = 0.1
6262

@@ -85,7 +85,7 @@ extension XCTestCase {
8585
}
8686
}
8787

88-
public func measureThrowingChannelThroughput<Output>(output: @escaping @autoclosure () -> Output) async {
88+
public func measureThrowingChannelThroughput<Output: Sendable>(output: @Sendable @escaping @autoclosure () -> Output) async {
8989
let metric = _ThroughputMetric()
9090
let sampleTime: Double = 0.1
9191

Tests/AsyncAlgorithmsTests/TestChunk.swift

+2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import XCTest
1313
import AsyncSequenceValidation
1414
import AsyncAlgorithms
1515

16+
@Sendable
1617
func sumCharacters(_ array: [String]) -> String {
1718
return "\(array.reduce(into: 0) { $0 = $0 + Int($1)! })"
1819
}
1920

21+
@Sendable
2022
func concatCharacters(_ array: [String]) -> String {
2123
return array.joined()
2224
}

0 commit comments

Comments
 (0)