Skip to content

Commit 8730d01

Browse files
committed
Separate availability tests vs others
Fixing testing for different platforms. MacOS and iOS have backdeployment and availability to consider. Other platforms don't need to worry about that because they need to include the swift runtime in the installation package anyway, so the concurrency bits can ship with the installation.
1 parent d90835b commit 8730d01

File tree

2 files changed

+115
-44
lines changed

2 files changed

+115
-44
lines changed

test/Concurrency/async_main_resolution.swift

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
1-
// async main is nested deeper in protocols than sync, should use sync (always)
2-
// sync main is nested deeper in protocols than async, use async if supported
3-
// async and sync are same level, use async if supported
4-
5-
// async main is nested in the protocol chain from `MyMain`
6-
// Always choose Sync overload
7-
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DASYNC_NESTED -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
8-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.0 -DASYNC_NESTED -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
9-
10-
// sync main is deeper in the protocol chain from `MyMain`
11-
// Choose async when available
12-
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
13-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.0 -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
14-
15-
// sync and async main are at same level (In MainProtocol) to `MyMain`.
16-
// Choose async when available
17-
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DBOTH -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
18-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DBOTH -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
19-
20-
// async main is the only option on the protocol chain
21-
// Choose async if we support it, error otherwise
22-
// RUN: not %target-swift-frontend -target x86_64-apple-macosx10.9 -DASYNC_NESTED -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR
23-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DASYNC_NESTED -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
24-
25-
// sync main is the only option on the protocol chain
26-
// Always choose sync
27-
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
28-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
29-
30-
// No synchronous, choose async if we support it, error otherwise
31-
// RUN: not %target-swift-frontend -target x86_64-apple-macosx10.9 -DNO_SYNC -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR
32-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DNO_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
33-
34-
// No asynchronous, choose sync
35-
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
36-
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
37-
38-
// No main functions
39-
// RUN: not %target-swift-frontend -target x86_64-apple-macosx10.9 -DNO_SYNC -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR
40-
// RUN: not %target-swift-frontend -target x86_64-apple-macosx11.9 -DNO_SYNC -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR-ASYNC
1+
// Non-apple platforms don't need to worry about the version number as much
2+
// because they can pull in the concurrency libraries with the swift
3+
// installation.
4+
5+
// async main is nested deeper in protocols than sync, use sync
6+
// sync main is nested deeper in protocols than async, use async
7+
// async and sync are same level, use async
418

429
// REQUIRES: concurrency
10+
// UNSUPPORTED: VENDOR=apple
11+
12+
// Async is deeper in the protocol chain from `MyMain`, use sync
13+
// RUN: %target-swift-frontend -DASYNC_NESTED -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
14+
15+
// Sync is deeper in the protocol chain from `MyMain`, use async
16+
// RUN: %target-swift-frontend -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
17+
18+
// Async and sync are the same level, use async
19+
// RUN: %target-swift-frontend -DBOTH -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
4320

4421
#if ASYNC_NESTED
4522
protocol AsyncMainProtocol { }
@@ -59,14 +36,12 @@ extension MainProtocol {
5936
#if NO_ASYNC
6037
#else
6138
extension AsyncMainProtocol {
62-
@available(macOS 10.15, *)
6339
static func main() async { }
6440
}
6541
#endif
6642

6743
#if BOTH
6844
extension MainProtocol {
69-
@available(macOS 10.15, *)
7045
static func main() async { }
7146
}
7247
#endif
@@ -79,10 +54,13 @@ extension MainProtocol {
7954
#endif
8055

8156

82-
// CHECK-IS-SYNC-LABEL: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () -> ()'
57+
58+
// CHECK-IS-SYNC-LABEL: "MyMain" interface type='MyMain.Type'
59+
// CHECK-IS-SYNC: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () -> ()'
8360
// CHECK-IS-SYNC: (declref_expr implicit type='(MyMain.Type) -> () -> ()'
8461

85-
// CHECK-IS-ASYNC-LABEL: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () async -> ()'
62+
// CHECK-IS-ASYNC-LABEL: "MyMain" interface type='MyMain.Type'
63+
// CHECK-IS-ASYNC: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () async -> ()'
8664
// CHECK-IS-ASYNC: (declref_expr implicit type='(MyMain.Type) -> () async -> ()'
8765

8866
// CHECK-IS-ERROR: error: 'MyMain' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// async main is nested deeper in protocols than sync, should use sync (always)
2+
// sync main is nested deeper in protocols than async, use async if supported
3+
// async and sync are same level, use async if supported
4+
5+
// async main is nested in the protocol chain from `MyMain`
6+
// Always choose Sync overload
7+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DASYNC_NESTED -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
8+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.0 -DASYNC_NESTED -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
9+
10+
// sync main is deeper in the protocol chain from `MyMain`
11+
// Choose async when available
12+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
13+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.0 -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
14+
15+
// sync and async main are at same level (In MainProtocol) to `MyMain`.
16+
// Choose async when available
17+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DBOTH -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
18+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DBOTH -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
19+
20+
// async main is the only option on the protocol chain
21+
// Choose async if we support it, error otherwise
22+
// RUN: not %target-swift-frontend -target x86_64-apple-macosx10.9 -DASYNC_NESTED -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR
23+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DASYNC_NESTED -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
24+
25+
// sync main is the only option on the protocol chain
26+
// Always choose sync
27+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
28+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DINHERIT_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
29+
30+
// No synchronous, choose async if we support it, error otherwise
31+
// RUN: not %target-swift-frontend -target x86_64-apple-macosx10.9 -DNO_SYNC -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR
32+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DNO_SYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-ASYNC
33+
34+
// No asynchronous, choose sync
35+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
36+
// RUN: %target-swift-frontend -target x86_64-apple-macosx11.9 -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-IS-SYNC
37+
38+
// No main functions
39+
// RUN: not %target-swift-frontend -target x86_64-apple-macosx10.9 -DNO_SYNC -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR
40+
// RUN: not %target-swift-frontend -target x86_64-apple-macosx11.9 -DNO_SYNC -DNO_ASYNC -typecheck -dump-ast -parse-as-library %s 2>&1 | %FileCheck %s --check-prefix=CHECK-IS-ERROR-ASYNC
41+
42+
// REQUIRES: concurrency
43+
// REQUIRES: OS=macosx
44+
45+
#if ASYNC_NESTED
46+
protocol AsyncMainProtocol { }
47+
protocol MainProtocol : AsyncMainProtocol { }
48+
#else
49+
protocol MainProtocol { }
50+
protocol AsyncMainProtocol : MainProtocol { }
51+
#endif
52+
53+
#if NO_SYNC
54+
#else
55+
extension MainProtocol {
56+
static func main() { }
57+
}
58+
#endif
59+
60+
#if NO_ASYNC
61+
#else
62+
extension AsyncMainProtocol {
63+
@available(macOS 10.15, *)
64+
static func main() async { }
65+
}
66+
#endif
67+
68+
#if BOTH
69+
extension MainProtocol {
70+
@available(macOS 10.15, *)
71+
static func main() async { }
72+
}
73+
#endif
74+
75+
76+
#if INHERIT_SYNC
77+
@main struct MyMain : MainProtocol {}
78+
#else
79+
@main struct MyMain : AsyncMainProtocol {}
80+
#endif
81+
82+
83+
// CHECK-IS-SYNC-LABEL: "MyMain" interface type='MyMain.Type'
84+
// CHECK-IS-SYNC: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () -> ()'
85+
// CHECK-IS-SYNC: (declref_expr implicit type='(MyMain.Type) -> () -> ()'
86+
87+
// CHECK-IS-ASYNC-LABEL: "MyMain" interface type='MyMain.Type'
88+
// CHECK-IS-ASYNC: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () async -> ()'
89+
// CHECK-IS-ASYNC: (declref_expr implicit type='(MyMain.Type) -> () async -> ()'
90+
91+
// CHECK-IS-ERROR: error: 'MyMain' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void
92+
93+
// CHECK-IS-ERROR-ASYNC: error: 'MyMain' is annotated with @main and must provide a main static function of type () -> Void, () throws -> Void, () async -> Void, or () async throws -> Void

0 commit comments

Comments
 (0)