1
+ // RUN: %target-run-simple-swift(-DTOPLEVEL_FACTORY -Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
2
+ // RUN: %target-run-simple-swift(-DPROTOCOL_FACTORY -Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
3
+ // RUN: %target-run-simple-swift(-DPROTOCOL_FACTORY_OVERRIDDEN -Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
4
+ // RUN: %target-run-simple-swift(-DPROTOCOL_FACTORY_DEFAULT -Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
5
+ // RUN: %target-run-simple-swift(-DPROTOCOL_FACTORY_DEFAULT2 -Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
1
6
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
2
7
3
8
// REQUIRES: concurrency
13
18
import StdlibUnittest
14
19
import Synchronization
15
20
21
+ #if TOPLEVEL_FACTORY
16
22
typealias DefaultExecutorFactory = SimpleExecutorFactory
23
+ #endif
17
24
18
25
struct SimpleExecutorFactory : ExecutorFactory {
19
26
public static var mainExecutor : any MainExecutor {
@@ -26,6 +33,15 @@ struct SimpleExecutorFactory: ExecutorFactory {
26
33
}
27
34
}
28
35
36
+ struct FatalExecutorFactory : ExecutorFactory {
37
+ public static var mainExecutor : any MainExecutor {
38
+ fatalError ( " mainExecutor called on FatalExecutorFactory " )
39
+ }
40
+ public static var defaultExecutor : any TaskExecutor {
41
+ fatalError ( " taskExecutor called on FatalExecutorFactory " )
42
+ }
43
+ }
44
+
29
45
@available ( SwiftStdlib 6 . 2 , * )
30
46
final class SimpleMainExecutor : MainExecutor , @unchecked Sendable {
31
47
public var isRunning : Bool = false
@@ -74,8 +90,30 @@ func myAsyncFunction() async {
74
90
print ( " Hello World " )
75
91
}
76
92
93
+ protocol AppProtocol {
94
+ #if PROTOCOL_FACTORY
95
+ associatedtype DefaultExecutorFactory
96
+ #endif
97
+ #if PROTOCOL_FACTORY_DEFAULT
98
+ associatedtype DefaultExecutorFactory = SimpleExecutorFactory
99
+ #endif
100
+ #if PROTOCOL_FACTORY_DEFAULT2 || PROTOCOL_FACTORY_OVERRIDDEN
101
+ associatedtype DefaultExecutorFactory = FatalExecutorFactory
102
+ #endif
103
+ }
104
+
105
+ #if PROTOCOL_FACTORY || PROTOCOL_FACTORY_DEFAULT2
106
+ extension AppProtocol {
107
+ typealias DefaultExecutorFactory = SimpleExecutorFactory
108
+ }
109
+ #endif
110
+
77
111
@available ( SwiftStdlib 6 . 2 , * )
78
- @main struct Main {
112
+ @main struct Main : AppProtocol {
113
+ #if !TOPLEVEL_FACTORY && !PROTOCOL_FACTORY && !PROTOCOL_FACTORY_DEFAULT && !PROTOCOL_FACTORY_DEFAULT2
114
+ typealias DefaultExecutorFactory = SimpleExecutorFactory
115
+ #endif
116
+
79
117
static func main( ) async {
80
118
print ( " Hello " )
81
119
await myAsyncFunction ( )
0 commit comments