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
16// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -g %import-libdispatch -parse-as-library) | %FileCheck %s
27// 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
38// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
1520import StdlibUnittest
1621import Synchronization
1722
23+ #if TOPLEVEL_FACTORY
1824typealias DefaultExecutorFactory = SimpleExecutorFactory
25+ #endif
1926
2027struct SimpleExecutorFactory : ExecutorFactory {
2128 public static var mainExecutor : any MainExecutor {
@@ -28,6 +35,15 @@ struct SimpleExecutorFactory: ExecutorFactory {
2835 }
2936}
3037
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+
3147@available ( SwiftStdlib 6 . 2 , * )
3248final class SimpleMainExecutor : MainExecutor , @unchecked Sendable {
3349 public var isRunning : Bool = false
@@ -76,8 +92,30 @@ final class SimpleTaskExecutor: TaskExecutor, @unchecked Sendable {
7692 print ( " Hello World " )
7793}
7894
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+
79113@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+
81119 static func main( ) async {
82120 print ( " Hello " )
83121 await myAsyncFunction ( )
0 commit comments