mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-26 04:37:48 +00:00
Fix more Sendable warnings and flaky test (#281)
# 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.
This commit is contained in:
1 parent
f5d5fb6483
commit
7ac31f979f
6 files changed
+77
-14
No files matched your search
+20
-5
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version: 5.6
|
||||
// swift-tools-version: 5.8
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -20,18 +20,33 @@ let package = Package(
|
||||
targets: [
|
||||
.target(
|
||||
name: "AsyncAlgorithms",
|
||||
dependencies: [.product(name: "Collections", package: "swift-collections")]
|
||||
dependencies: [.product(name: "Collections", package: "swift-collections")],
|
||||
swiftSettings: [
|
||||
.enableExperimentalFeature("StrictConcurrency=complete"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "AsyncSequenceValidation",
|
||||
dependencies: ["_CAsyncSequenceValidationSupport", "AsyncAlgorithms"]),
|
||||
dependencies: ["_CAsyncSequenceValidationSupport", "AsyncAlgorithms"],
|
||||
swiftSettings: [
|
||||
.enableExperimentalFeature("StrictConcurrency=complete"),
|
||||
]
|
||||
),
|
||||
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
|
||||
.target(
|
||||
name: "AsyncAlgorithms_XCTest",
|
||||
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
|
||||
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"],
|
||||
swiftSettings: [
|
||||
.enableExperimentalFeature("StrictConcurrency=complete"),
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
name: "AsyncAlgorithmsTests",
|
||||
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"]),
|
||||
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"],
|
||||
swiftSettings: [
|
||||
.enableExperimentalFeature("StrictConcurrency=complete"),
|
||||
]
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// swift-tools-version: 5.6
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "swift-async-algorithms",
|
||||
platforms: [
|
||||
.macOS("10.15"),
|
||||
.iOS("13.0"),
|
||||
.tvOS("13.0"),
|
||||
.watchOS("6.0")
|
||||
],
|
||||
products: [
|
||||
.library(name: "AsyncAlgorithms", targets: ["AsyncAlgorithms"]),
|
||||
.library(name: "AsyncSequenceValidation", targets: ["AsyncSequenceValidation"]),
|
||||
.library(name: "_CAsyncSequenceValidationSupport", type: .static, targets: ["AsyncSequenceValidation"]),
|
||||
.library(name: "AsyncAlgorithms_XCTest", targets: ["AsyncAlgorithms_XCTest"]),
|
||||
],
|
||||
dependencies: [.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.4"))],
|
||||
targets: [
|
||||
.target(
|
||||
name: "AsyncAlgorithms",
|
||||
dependencies: [.product(name: "Collections", package: "swift-collections")]
|
||||
),
|
||||
.target(
|
||||
name: "AsyncSequenceValidation",
|
||||
dependencies: ["_CAsyncSequenceValidationSupport", "AsyncAlgorithms"]),
|
||||
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
|
||||
.target(
|
||||
name: "AsyncAlgorithms_XCTest",
|
||||
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
|
||||
.testTarget(
|
||||
name: "AsyncAlgorithmsTests",
|
||||
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"]),
|
||||
]
|
||||
)
|
||||
|
||||
#if canImport(Darwin)
|
||||
import Darwin
|
||||
let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil
|
||||
#elseif canImport(Glibc)
|
||||
import Glibc
|
||||
let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil
|
||||
#else
|
||||
let buildingDocs = false
|
||||
#endif
|
||||
|
||||
// Only require the docc plugin when building documentation
|
||||
package.dependencies += buildingDocs ? [
|
||||
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
|
||||
] : []
|
||||
@@ -198,7 +198,7 @@ final class MergeStorage<
|
||||
private func iterateAsyncSequence<AsyncSequence: _Concurrency.AsyncSequence>(
|
||||
_ base: AsyncSequence,
|
||||
in taskGroup: inout ThrowingTaskGroup<Void, Error>
|
||||
) where AsyncSequence.Element == Base1.Element {
|
||||
) where AsyncSequence.Element == Base1.Element, AsyncSequence: Sendable {
|
||||
// For each upstream sequence we are adding a child task that
|
||||
// is consuming the upstream sequence
|
||||
taskGroup.addTask {
|
||||
|
||||
@@ -166,10 +166,6 @@ final class TestInterspersed: XCTestCase {
|
||||
|
||||
while let _ = await iterator.next() {}
|
||||
|
||||
let pastEnd = await iterator.next()
|
||||
XCTAssertNil(pastEnd)
|
||||
|
||||
// Information the parent task that we finished consuming
|
||||
await lockStepChannel.send(())
|
||||
}
|
||||
|
||||
@@ -179,8 +175,7 @@ final class TestInterspersed: XCTestCase {
|
||||
// Now we cancel the child
|
||||
group.cancelAll()
|
||||
|
||||
// Waiting until the child task finished consuming
|
||||
_ = await lockStepChannel.first { _ in true }
|
||||
await group.waitForAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ final class _ThroughputMetric: NSObject, XCTMetric, @unchecked Sendable {
|
||||
}
|
||||
|
||||
extension XCTestCase {
|
||||
public func measureChannelThroughput<Output>(output: @escaping @autoclosure () -> Output) async {
|
||||
public func measureChannelThroughput<Output: Sendable>(output: @Sendable @escaping @autoclosure () -> Output) async {
|
||||
let metric = _ThroughputMetric()
|
||||
let sampleTime: Double = 0.1
|
||||
|
||||
@@ -85,7 +85,7 @@ extension XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public func measureThrowingChannelThroughput<Output>(output: @escaping @autoclosure () -> Output) async {
|
||||
public func measureThrowingChannelThroughput<Output: Sendable>(output: @Sendable @escaping @autoclosure () -> Output) async {
|
||||
let metric = _ThroughputMetric()
|
||||
let sampleTime: Double = 0.1
|
||||
|
||||
|
||||
@@ -13,10 +13,12 @@ import XCTest
|
||||
import AsyncSequenceValidation
|
||||
import AsyncAlgorithms
|
||||
|
||||
@Sendable
|
||||
func sumCharacters(_ array: [String]) -> String {
|
||||
return "\(array.reduce(into: 0) { $0 = $0 + Int($1)! })"
|
||||
}
|
||||
|
||||
@Sendable
|
||||
func concatCharacters(_ array: [String]) -> String {
|
||||
return array.joined()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user