Skip to content

[Concurrency] Define and use the SwiftStdlib 5.5 availability macro in tests #37269

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 2 commits into from
May 10, 2021
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
8 changes: 4 additions & 4 deletions test/Concurrency/Runtime/actor_counters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
actor Counter {
private var value = 0
private let scratchBuffer: UnsafeMutableBufferPointer<Int>
Expand All @@ -31,7 +31,7 @@ actor Counter {
}


@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func worker(identity: Int, counters: [Counter], numIterations: Int) async {
for i in 0..<numIterations {
let counterIndex = Int.random(in: 0 ..< counters.count)
Expand All @@ -41,7 +41,7 @@ func worker(identity: Int, counters: [Counter], numIterations: Int) async {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
// Create counter actors.
var counters: [Counter] = []
Expand All @@ -68,7 +68,7 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
print("DONE!")
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
// Useful for debugging: specify counter/worker/iteration counts
Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/Runtime/async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import StdlibUnittest

var asyncTests = TestSuite("Async")

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
actor MyActor {
func synchronous() { }

Expand All @@ -31,7 +31,7 @@ actor MyActor {
}
}

if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
if #available(SwiftStdlib 5.5, *) {
let actor = MyActor()

asyncTests.test("Detach") {
Expand Down
14 changes: 7 additions & 7 deletions test/Concurrency/Runtime/async_initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
actor NameGenerator {
private var counter = 0
private var prefix : String
Expand All @@ -19,13 +19,13 @@ actor NameGenerator {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
protocol Person {
init() async
var name : String { get set }
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
class EarthPerson : Person {
private static let oracle = NameGenerator("Earthling")

Expand All @@ -40,7 +40,7 @@ class EarthPerson : Person {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
class NorthAmericaPerson : EarthPerson {
private static let oracle = NameGenerator("NorthAmerican")
required init() async {
Expand All @@ -53,7 +53,7 @@ class NorthAmericaPerson : EarthPerson {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
class PrecariousClass {
init?(nilIt : Int) async {
let _ : Optional<Int> = await (detach { nil }).get()
Expand Down Expand Up @@ -87,7 +87,7 @@ enum Something : Error {
case bogus
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
struct PrecariousStruct {
init?(nilIt : Int) async {
let _ : Optional<Int> = await (detach { nil }).get()
Expand Down Expand Up @@ -122,7 +122,7 @@ struct PrecariousStruct {
// CHECK-NEXT: struct threw
// CHECK: done

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct RunIt {
static func main() async {
let people : [Person] = [
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/Runtime/async_let_fibonacci.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func fib(_ n: Int) -> Int {
return first
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func asyncFib(_ n: Int) async -> Int {
if n == 0 || n == 1 {
return n
Expand All @@ -39,7 +39,7 @@ func asyncFib(_ n: Int) async -> Int {
return result
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func runFibonacci(_ n: Int) async {
let result = await asyncFib(n)

Expand All @@ -48,7 +48,7 @@ func runFibonacci(_ n: Int) async {
assert(result == fib(n))
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await runFibonacci(10)
Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/Runtime/async_let_throws.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func boom() throws -> Int {
throw Boom()
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func test() async {
async let result = boom()

Expand All @@ -25,7 +25,7 @@ func test() async {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await test()
Expand Down
20 changes: 10 additions & 10 deletions test/Concurrency/Runtime/async_sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ import StdlibUnittest
// Utility functions for closure based operators to force them into throwing
// and async and throwing async contexts.

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func throwing<T>(_ value: T) throws -> T {
return value
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func asynchronous<T>(_ value: T) async -> T {
return value
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func asynchronousThrowing<T>(_ value: T) async throws -> T {
return value
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
struct Failure: Error, Equatable {
var value = 1
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func failable<T, E: Error>(
_ results: [Result<T, E>]
) -> AsyncThrowingMapSequence<AsyncLazySequence<[Result<T, E>]>, T> {
return results.async.map { try $0.get() }
}


@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
extension Sequence {
@inlinable
public var async: AsyncLazySequence<Self> {
Expand All @@ -52,7 +52,7 @@ extension Sequence {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
public struct AsyncLazySequence<S: Sequence>: AsyncSequence {
public typealias Element = S.Element
public typealias AsyncIterator = Iterator
Expand Down Expand Up @@ -85,7 +85,7 @@ public struct AsyncLazySequence<S: Sequence>: AsyncSequence {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
extension AsyncSequence {
@inlinable
public func collect() async rethrows -> [Element] {
Expand All @@ -98,7 +98,7 @@ extension AsyncSequence {
}
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
extension AsyncSequence where Element: Equatable {
func `throw`(_ error: Error, on element: Element) -> AsyncThrowingMapSequence<Self, Element> {
return map { (value: Element) throws -> Element in
Expand All @@ -110,7 +110,7 @@ extension AsyncSequence where Element: Equatable {

@main struct Main {
static func main() async {
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
if #available(SwiftStdlib 5.5, *) {

var AsyncLazySequenceTests = TestSuite("AsyncLazySequence")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: use_os_stdlib

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func printWaitPrint(_ int: Int) async -> Int {
print("start, cancelled:\(Task.isCancelled), id:\(int)")
while !Task.isCancelled {
Expand All @@ -17,7 +17,7 @@ func printWaitPrint(_ int: Int) async -> Int {
return int
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func test() async {
let h = detach {
await printWaitPrint(0)
Expand Down Expand Up @@ -68,7 +68,7 @@ func test() async {
print("exit")
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await test()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import Dispatch

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func test_detach_cancel_child_early() async {
print(#function) // CHECK: test_detach_cancel_child_early
let h: Task.Handle<Bool, Error> = detach {
Expand All @@ -35,7 +35,7 @@ func test_detach_cancel_child_early() async {
print("was cancelled: \(got)") // CHECK: was cancelled: true
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await test_detach_cancel_child_early()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import Dispatch

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func test_detach_cancel_while_child_running() async {
let h: Task.Handle<Bool, Error> = detach {
async let childCancelled: Bool = { () -> Bool in
Expand All @@ -34,7 +34,7 @@ func test_detach_cancel_while_child_running() async {
print("was cancelled: \(got)") // CHECK: was cancelled: true
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await test_detach_cancel_while_child_running()
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/Runtime/async_task_detach.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class X {

struct Boom: Error {}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func test_detach() async {
let x = X()
let h = detach {
Expand All @@ -33,7 +33,7 @@ func test_detach() async {
// CHECK: X: deinit
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
func test_detach_throw() async {
let x = X()
let h = detach {
Expand All @@ -51,7 +51,7 @@ func test_detach_throw() async {
}


@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await test_detach()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// UNSUPPORTED: OS=windows-msvc

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
let handle = detach {
Expand Down
Loading