Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more Sendable warnings and flaky test #281

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ perfection!

]
),
.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be 5.7 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be 5.6 since we don’t use any 5.7 toolchain feature in here. The name of the file is the important part.


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