Skip to content

Commit cca423f

Browse files
authored
Remove the disable of availability and mark methods as available to clock/instant/duration (apple#165)
* Remove the disable of availability and mark methods as available to clock/instant/duration * Rework availability to be more permissive for tests * Use hand coded values instead of defines (only available via Darwin versions of Dispatch) * Adjust additional test availability * Correct debounce test availability guard * Update build instructions to indicate Xcode requirements * Ensure the clock property of the validation diagram is only available for targets that can support it
1 parent 9a3e94d commit cca423f

18 files changed

+133
-87
lines changed

Package.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,10 @@ let package = Package(
2525
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
2626
.target(
2727
name: "AsyncAlgorithms_XCTest",
28-
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"],
29-
swiftSettings: [
30-
.unsafeFlags([
31-
"-Xfrontend", "-disable-availability-checking"
32-
])
33-
]),
28+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
3429
.testTarget(
3530
name: "AsyncAlgorithmsTests",
36-
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"],
37-
swiftSettings: [
38-
.unsafeFlags([
39-
"-Xfrontend", "-disable-availability-checking"
40-
])
41-
]),
31+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation", "AsyncAlgorithms_XCTest"]),
4232
]
4333
)
4434

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,17 @@ Finally, add `import AsyncAlgorithms` to your source code.
8787

8888
## Getting Started
8989

90-
⚠️ 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).
90+
⚠️ Please note that this package requires Xcode 14 on macOS hosts. Previous versions of Xcode do not contain the required Swift version.
9191

9292
### Building/Testing Using Xcode on macOS
9393

94-
1. Download the most recent development Xcode toolchain.
95-
2. Install the package
96-
4. Select the development toolchain in Xcode
97-
4. Open the `swift-async-algorithms` package directory in Xcode
98-
5. Build or Test in Xcode as normal
99-
100-
⚠️ Note: `swift test` does not currently work properly with custom toolchains for this package.
94+
1. In the `swift-async-algorithms` directory run `swift build` or `swift test` accordingly
10195

10296
### Building/Testing on Linux
10397

10498
1. Download the most recent development toolchain for your Linux distribution
10599
2. Decompress the archive to a path in which the `swift` executable is in the binary search path environment variable (`$PATH`)
106100
3. In the `swift-async-algorithms` directory run `swift build` or `swift test` accordingly
107-
108-
### Building with Swift 5.6
109-
110-
1. `git checkout swift-5.6`
111-
2. run `swift build` or `swift test` accordingly
112101

113102
## Source Stability
114103

Sources/AsyncSequenceValidation/AsyncSequenceValidationDiagram.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import _CAsyncSequenceValidationSupport
1313

14-
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
1514
@resultBuilder
1615
public struct AsyncSequenceValidationDiagram : Sendable {
1716
public struct Component<T> {
@@ -97,15 +96,20 @@ public struct AsyncSequenceValidationDiagram : Sendable {
9796
}
9897

9998
let queue: WorkQueue
99+
let _clock: Clock
100100

101101
public var inputs: InputList
102-
public let clock: Clock
102+
103+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
104+
public var clock: Clock {
105+
_clock
106+
}
103107

104108
internal init() {
105109
let queue = WorkQueue()
106110
self.queue = queue
107111
self.inputs = InputList(queue: queue)
108-
self.clock = Clock(queue: queue)
112+
self._clock = Clock(queue: queue)
109113
}
110114
}
111115

Sources/AsyncSequenceValidation/Clock.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import AsyncAlgorithms
1313

14-
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
1514
extension AsyncSequenceValidationDiagram {
1615
public struct Clock {
1716
let queue: WorkQueue
@@ -22,8 +21,20 @@ extension AsyncSequenceValidationDiagram {
2221
}
2322
}
2423

25-
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
26-
extension AsyncSequenceValidationDiagram.Clock: Clock {
24+
25+
public protocol TestClock: Sendable {
26+
associatedtype Instant: TestInstant
27+
28+
var now: Instant { get }
29+
30+
func sleep(until deadline: Self.Instant, tolerance: Self.Instant.Duration?) async throws
31+
}
32+
33+
public protocol TestInstant: Equatable {
34+
associatedtype Duration
35+
}
36+
37+
extension AsyncSequenceValidationDiagram.Clock {
2738
public struct Step: DurationProtocol, Hashable, CustomStringConvertible {
2839
internal var rawValue: Int
2940

@@ -66,7 +77,7 @@ extension AsyncSequenceValidationDiagram.Clock: Clock {
6677
}
6778
}
6879

69-
public struct Instant: InstantProtocol, CustomStringConvertible {
80+
public struct Instant: CustomStringConvertible {
7081
public typealias Duration = Step
7182

7283
let when: Step
@@ -111,3 +122,13 @@ extension AsyncSequenceValidationDiagram.Clock: Clock {
111122
}
112123
}
113124
}
125+
126+
extension AsyncSequenceValidationDiagram.Clock.Instant: TestInstant { }
127+
128+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
129+
extension AsyncSequenceValidationDiagram.Clock.Instant: InstantProtocol { }
130+
131+
extension AsyncSequenceValidationDiagram.Clock: TestClock { }
132+
133+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
134+
extension AsyncSequenceValidationDiagram.Clock: Clock { }

Sources/AsyncSequenceValidation/Event.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

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

Sources/AsyncSequenceValidation/Expectation.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
1312
extension AsyncSequenceValidationDiagram {
1413
public struct ExpectationResult: Sendable {
1514
public struct Event: Sendable {

Sources/AsyncSequenceValidation/Input.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
1312
extension AsyncSequenceValidationDiagram {
1413
public struct Specification: Sendable {
1514
public let specification: String

Sources/AsyncSequenceValidation/Job.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import _CAsyncSequenceValidationSupport
1313

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

Sources/AsyncSequenceValidation/TaskDriver.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import _CAsyncSequenceValidationSupport
2020
#endif
2121

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

37-
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
3836
final class TaskDriver {
3937
let work: (TaskDriver) -> Void
4038
let queue: WorkQueue

Sources/AsyncSequenceValidation/Test.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ internal func _swiftJobRun(
1919
_ executor: UnownedSerialExecutor
2020
) -> ()
2121

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

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

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

37-
func test<C: _Concurrency.Clock>(with clock: C, activeTicks: [C.Instant], output: Specification, _ event: (String) -> Void) async throws {
35+
func test<C: TestClock>(with clock: C, activeTicks: [C.Instant], output: Specification, _ event: (String) -> Void) async throws {
3836
var iterator = sequence.makeAsyncIterator()
3937
do {
4038
for tick in activeTicks {
@@ -265,7 +263,7 @@ extension AsyncSequenceValidationDiagram {
265263
@AsyncSequenceValidationDiagram _ build: (AsyncSequenceValidationDiagram) -> Test
266264
) throws -> (ExpectationResult, [ExpectationFailure]) {
267265
let diagram = AsyncSequenceValidationDiagram()
268-
let clock = diagram.clock
266+
let clock = diagram._clock
269267
let test = build(diagram)
270268
for index in 0..<test.inputs.count {
271269
// fault in all inputs

0 commit comments

Comments
 (0)