Skip to content

Commit

Permalink
Fix more Sendable warnings and flaky test
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
FranzBusch committed Jul 28, 2023
1 parent df46b4c commit 5e2361f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
25 changes: 20 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.6
// swift-tools-version: 5.8

import PackageDescription

Expand All @@ -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"),
]
),
]
)

Expand Down
51 changes: 51 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -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"),
] : []
2 changes: 1 addition & 1 deletion Sources/AsyncAlgorithms/Merge/MergeStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Tests/AsyncAlgorithmsTests/TestChunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 5e2361f

Please sign in to comment.