Skip to content

Commit 5d806ed

Browse files
committed
Executor.swift: only enable MainActor in Embedded Swift for WASI
# Conflicts: # stdlib/public/Concurrency/Executor.swift
1 parent 0d98f00 commit 5d806ed

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

stdlib/public/Concurrency/Executor.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ extension Executor where Self: Equatable {
127127
}
128128

129129
extension Executor {
130-
131130
#if os(WASI) || !$Embedded
131+
// This defaults to `false` so that existing third-party Executor
132+
// implementations will work as expected.
132133
@available(StdlibDeploymentTarget 6.2, *)
133134
var isMainExecutor: Bool { false }
134-
#endif
135+
#endif // os(WASI) || !$Embedded
135136

136137
}
137138

@@ -346,10 +347,10 @@ public protocol SerialExecutor: Executor {
346347
@available(StdlibDeploymentTarget 6.0, *)
347348
extension SerialExecutor {
348349

349-
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
350+
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
350351
@available(StdlibDeploymentTarget 6.2, *)
351352
var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
352-
#endif
353+
#endif // os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
353354

354355
@available(StdlibDeploymentTarget 6.0, *)
355356
public func checkIsolated() {
@@ -556,6 +557,7 @@ protocol ExecutorFactory {
556557
/// Constructs and returns the main executor, which is started implicitly
557558
/// by the `async main` entry point and owns the "main" thread.
558559
static var mainExecutor: any MainExecutor { get }
560+
#endif // os(WASI) || !$Embedded
559561

560562
/// Constructs and returns the default or global executor, which is the
561563
/// default place in which we run tasks.
@@ -570,7 +572,7 @@ typealias DefaultExecutorFactory = PlatformExecutorFactory
570572
func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
571573
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
572574
MainActor._executor = factory.mainExecutor
573-
#endif
575+
#endif // os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
574576
Task._defaultExecutor = factory.defaultExecutor
575577
}
576578

0 commit comments

Comments
 (0)