Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove the disable of availability and mark methods as available to clock/instant/duration #165

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

Merged
merged 7 commits into from
Jun 16, 2022
14 changes: 2 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,10 @@ let package = Package(
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
.target(
name: "AsyncAlgorithms_XCTest",
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"],
swiftSettings: [
.unsafeFlags([
"-Xfrontend", "-disable-availability-checking"
])
]),
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
.testTarget(
name: "AsyncAlgorithmsTests",
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"],
swiftSettings: [
.unsafeFlags([
"-Xfrontend", "-disable-availability-checking"
])
]),
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"]),
]
)

Expand Down
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,17 @@ Finally, add `import AsyncAlgorithms` to your source code.

## Getting Started

⚠️ Please note that this package currently requires a recent [Swift Trunk Development toolchain](https://www.swift.org/download/#trunk-development-main). More information on how to use custom toolchains with Xcode can be viewed [here](https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/AlternativeToolchains.html).
⚠️ Please note that this package requires Xcode 14 on macOS hosts. Previous versions of Xcode do not contain the required Swift version.

### Building/Testing Using Xcode on macOS

1. Download the most recent development Xcode toolchain.
2. Install the package
4. Select the development toolchain in Xcode
4. Open the `swift-async-algorithms` package directory in Xcode
5. Build or Test in Xcode as normal

⚠️ Note: `swift test` does not currently work properly with custom toolchains for this package.
1. In the `swift-async-algorithms` directory run `swift build` or `swift test` accordingly

### Building/Testing on Linux

1. Download the most recent development toolchain for your Linux distribution
2. Decompress the archive to a path in which the `swift` executable is in the binary search path environment variable (`$PATH`)
3. In the `swift-async-algorithms` directory run `swift build` or `swift test` accordingly

### Building with Swift 5.6

1. `git checkout swift-5.6`
2. run `swift build` or `swift test` accordingly

## Source Stability

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import _CAsyncSequenceValidationSupport

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
@resultBuilder
public struct AsyncSequenceValidationDiagram : Sendable {
public struct Component<T> {
Expand Down Expand Up @@ -97,15 +96,20 @@ public struct AsyncSequenceValidationDiagram : Sendable {
}

let queue: WorkQueue
let _clock: Clock

public var inputs: InputList
public let clock: Clock

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
public var clock: Clock {
_clock
}

internal init() {
let queue = WorkQueue()
self.queue = queue
self.inputs = InputList(queue: queue)
self.clock = Clock(queue: queue)
self._clock = Clock(queue: queue)
}
}

29 changes: 25 additions & 4 deletions Sources/AsyncSequenceValidation/Clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import AsyncAlgorithms

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram {
public struct Clock {
let queue: WorkQueue
Expand All @@ -22,8 +21,20 @@ extension AsyncSequenceValidationDiagram {
}
}

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram.Clock: Clock {

public protocol TestClock: Sendable {
associatedtype Instant: TestInstant

var now: Instant { get }

func sleep(until deadline: Self.Instant, tolerance: Self.Instant.Duration?) async throws
}

public protocol TestInstant: Equatable {
associatedtype Duration
}

extension AsyncSequenceValidationDiagram.Clock {
public struct Step: DurationProtocol, Hashable, CustomStringConvertible {
internal var rawValue: Int

Expand Down Expand Up @@ -66,7 +77,7 @@ extension AsyncSequenceValidationDiagram.Clock: Clock {
}
}

public struct Instant: InstantProtocol, CustomStringConvertible {
public struct Instant: CustomStringConvertible {
public typealias Duration = Step

let when: Step
Expand Down Expand Up @@ -111,3 +122,13 @@ extension AsyncSequenceValidationDiagram.Clock: Clock {
}
}
}

extension AsyncSequenceValidationDiagram.Clock.Instant: TestInstant { }

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram.Clock.Instant: InstantProtocol { }

extension AsyncSequenceValidationDiagram.Clock: TestClock { }

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram.Clock: Clock { }
1 change: 0 additions & 1 deletion Sources/AsyncSequenceValidation/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//
//===----------------------------------------------------------------------===//

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram {
struct Failure: Error, Equatable { }

Expand Down
1 change: 0 additions & 1 deletion Sources/AsyncSequenceValidation/Expectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//
//===----------------------------------------------------------------------===//

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram {
public struct ExpectationResult: Sendable {
public struct Event: Sendable {
Expand Down
1 change: 0 additions & 1 deletion Sources/AsyncSequenceValidation/Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//
//===----------------------------------------------------------------------===//

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram {
public struct Specification: Sendable {
public let specification: String
Expand Down
1 change: 0 additions & 1 deletion Sources/AsyncSequenceValidation/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import _CAsyncSequenceValidationSupport

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
struct Job: Hashable, @unchecked Sendable {
let job: JobRef

Expand Down
2 changes: 0 additions & 2 deletions Sources/AsyncSequenceValidation/TaskDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import _CAsyncSequenceValidationSupport
#endif

#if canImport(Darwin)
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
Unmanaged<TaskDriver>.fromOpaque(raw).takeRetainedValue().run()
return nil
Expand All @@ -34,7 +33,6 @@ func start_thread(_ raw: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? {
#error("TODO: Port TaskDriver threading to windows")
#endif

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
final class TaskDriver {
let work: (TaskDriver) -> Void
let queue: WorkQueue
Expand Down
8 changes: 3 additions & 5 deletions Sources/AsyncSequenceValidation/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ internal func _swiftJobRun(
_ executor: UnownedSerialExecutor
) -> ()

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
public protocol AsyncSequenceValidationTest: Sendable {
var inputs: [AsyncSequenceValidationDiagram.Specification] { get }
var output: AsyncSequenceValidationDiagram.Specification { get }

func test<C: Clock>(with clock: C, activeTicks: [C.Instant], output: AsyncSequenceValidationDiagram.Specification, _ event: (String) -> Void) async throws
func test<C: TestClock>(with clock: C, activeTicks: [C.Instant], output: AsyncSequenceValidationDiagram.Specification, _ event: (String) -> Void) async throws
}

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram {
struct Test<Operation: AsyncSequence>: AsyncSequenceValidationTest, @unchecked Sendable where Operation.Element == String {
let inputs: [Specification]
let sequence: Operation
let output: Specification

func test<C: _Concurrency.Clock>(with clock: C, activeTicks: [C.Instant], output: Specification, _ event: (String) -> Void) async throws {
func test<C: TestClock>(with clock: C, activeTicks: [C.Instant], output: Specification, _ event: (String) -> Void) async throws {
var iterator = sequence.makeAsyncIterator()
do {
for tick in activeTicks {
Expand Down Expand Up @@ -265,7 +263,7 @@ extension AsyncSequenceValidationDiagram {
@AsyncSequenceValidationDiagram _ build: (AsyncSequenceValidationDiagram) -> Test
) throws -> (ExpectationResult, [ExpectationFailure]) {
let diagram = AsyncSequenceValidationDiagram()
let clock = diagram.clock
let clock = diagram._clock
let test = build(diagram)
for index in 0..<test.inputs.count {
// fault in all inputs
Expand Down
3 changes: 0 additions & 3 deletions Sources/AsyncSequenceValidation/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@
//
//===----------------------------------------------------------------------===//

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
public protocol AsyncSequenceValidationTheme {
func token(_ character: Character, inValue: Bool) -> AsyncSequenceValidationDiagram.Token

func description(for token: AsyncSequenceValidationDiagram.Token) -> String
}

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationTheme where Self == AsyncSequenceValidationDiagram.ASCIITheme {
public static var ascii: AsyncSequenceValidationDiagram.ASCIITheme {
return AsyncSequenceValidationDiagram.ASCIITheme()
}
}

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram {
public enum Token: Sendable {
case step
Expand Down
1 change: 0 additions & 1 deletion Sources/AsyncSequenceValidation/WorkQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//
//===----------------------------------------------------------------------===//

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
struct WorkQueue: Sendable {
enum Item: CustomStringConvertible, Comparable {
case blocked(Token, AsyncSequenceValidationDiagram.Clock.Instant, UnsafeContinuation<Void, Error>)
Expand Down
31 changes: 20 additions & 11 deletions Tests/AsyncAlgorithmsTests/TestChunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func concatCharacters(_ array: [String]) -> String {
}

final class TestChunk: XCTestCase {

func test_signal_equalChunks() {
validate {
"ABC- DEF- GHI- |"
Expand Down Expand Up @@ -113,79 +112,89 @@ final class TestChunk: XCTestCase {
}
}

func test_time_equalChunks() {
func test_time_equalChunks() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"ABC- DEF- GHI- |"
$0.inputs[0].chunked(by: .repeating(every: .steps(4), clock: $0.clock)).map(concatCharacters)
"---'ABC'---'DEF'---'GHI'|"
}
}

func test_time_unequalChunks() {
func test_time_unequalChunks() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"AB------ A------- ABCDEFG- |"
$0.inputs[0].chunked(by: .repeating(every: .steps(8), clock: $0.clock)).map(concatCharacters)
"-------'AB' -------A -------'ABCDEFG'|"
}
}

func test_time_emptyChunks() {
func test_time_emptyChunks() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"-- 1- --|"
$0.inputs[0].chunked(by: .repeating(every: .steps(2), clock: $0.clock)).map(concatCharacters)
"-- -1 --|"
}
}

func test_time_error() {
func test_time_error() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"AB^"
$0.inputs[0].chunked(by: .repeating(every: .steps(5), clock: $0.clock)).map(concatCharacters)
"--^"
}
}

func test_time_unsignaledTrailingChunk() {
func test_time_unsignaledTrailingChunk() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"111-111|"
$0.inputs[0].chunked(by: .repeating(every: .steps(4), clock: $0.clock)).map(sumCharacters)
"---3---[3|]"
}
}

func test_timeAndCount_timeAlwaysPrevails() {
func test_timeAndCount_timeAlwaysPrevails() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"AB------ A------- ABCDEFG- |"
$0.inputs[0].chunks(ofCount: 42, or: .repeating(every: .steps(8), clock: $0.clock)).map(concatCharacters)
"-------'AB' -------A -------'ABCDEFG'|"
}
}

func test_timeAndCount_countAlwaysPrevails() {
func test_timeAndCount_countAlwaysPrevails() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"AB --A-B -|"
$0.inputs[0].chunks(ofCount: 2, or: .repeating(every: .steps(8), clock: $0.clock)).map(concatCharacters)
"-'AB'----'AB'-|"
}
}

func test_timeAndCount_countResetsAfterCount() {
func test_timeAndCount_countResetsAfterCount() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"ABCDE --- ABCDE |"
$0.inputs[0].chunks(ofCount: 5, or: .repeating(every: .steps(8), clock: $0.clock)).map(concatCharacters)
"----'ABCDE'--- ----'ABCDE'|"
}
}

func test_timeAndCount_countResetsAfterSignal() {
func test_timeAndCount_countResetsAfterSignal() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"AB------ ABCDE |"
$0.inputs[0].chunks(ofCount: 5, or: .repeating(every: .steps(8), clock: $0.clock)).map(concatCharacters)
"-------'AB' ----'ABCDE'|"
}
}

func test_timeAndCount_error() {
func test_timeAndCount_error() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") }
validate {
"ABC^"
$0.inputs[0].chunks(ofCount: 5, or: .repeating(every: .steps(8), clock: $0.clock)).map(concatCharacters)
Expand Down
Loading