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