Skip to content

Commit bcfef22

Browse files
committed
[Concurrency][Embedded] Remove MainActor/MainExecutor everywhere.
Embedded Swift doesn't have MainActor, so remove it. rdar://141348916
1 parent 26da3d0 commit bcfef22

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

stdlib/public/Concurrency/Executor.swift

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public protocol Executor: AnyObject, Sendable {
3636
func enqueue(_ job: consuming ExecutorJob)
3737
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
3838

39+
#if !$Embedded
3940
// The functions below could have been added to a separate protocol,
4041
// but doing that would then mean doing an `as?` cast in e.g.
4142
// enqueueOnGlobalExecutor (in ExecutorBridge.swift), which is
@@ -44,6 +45,7 @@ public protocol Executor: AnyObject, Sendable {
4445
/// `true` if this is the main executor.
4546
@available(SwiftStdlib 6.2, *)
4647
var isMainExecutor: Bool { get }
48+
#endif
4749

4850
/// `true` if this Executor supports scheduling.
4951
///
@@ -116,10 +118,12 @@ extension Executor where Self: Equatable {
116118
// Delay support
117119
extension Executor {
118120

121+
#if !$Embedded
119122
// This defaults to `false` so that existing third-party Executor
120123
// implementations will work as expected.
121124
@available(SwiftStdlib 6.2, *)
122125
public var isMainExecutor: Bool { false }
126+
#endif
123127

124128
// This defaults to `false` so that existing third-party TaskExecutor
125129
// implementations will work as expected.
@@ -327,8 +331,10 @@ public protocol SerialExecutor: Executor {
327331
@available(SwiftStdlib 6.0, *)
328332
extension SerialExecutor {
329333

334+
#if !$Embedded
330335
@available(SwiftStdlib 6.2, *)
331336
public var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
337+
#endif
332338

333339
@available(SwiftStdlib 6.0, *)
334340
public func checkIsolated() {
@@ -578,9 +584,11 @@ public protocol MainExecutor: RunLoopExecutor, SerialExecutor, EventableExecutor
578584
/// executors.
579585
@available(SwiftStdlib 6.2, *)
580586
public protocol ExecutorFactory {
587+
#if !$Embedded
581588
/// Constructs and returns the main executor, which is started implicitly
582589
/// by the `async main` entry point and owns the "main" thread.
583590
static var mainExecutor: any MainExecutor { get }
591+
#endif
584592

585593
/// Constructs and returns the default or global executor, which is the
586594
/// default place in which we run tasks.
@@ -590,10 +598,13 @@ public protocol ExecutorFactory {
590598
@available(SwiftStdlib 6.2, *)
591599
@_silgen_name("swift_createExecutors")
592600
public func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
601+
#if !$Embedded
593602
MainActor._executor = factory.mainExecutor
603+
#endif
594604
Task._defaultExecutor = factory.defaultExecutor
595605
}
596606

607+
#if !$Embedded
597608
extension MainActor {
598609
@available(SwiftStdlib 6.2, *)
599610
static var _executor: (any MainExecutor)? = nil
@@ -611,6 +622,7 @@ extension MainActor {
611622
return _executor!
612623
}
613624
}
625+
#endif // !$Embedded
614626

615627
extension Task where Success == Never, Failure == Never {
616628
@available(SwiftStdlib 6.2, *)

stdlib/public/Concurrency/ExecutorBridge.swift

+4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import Swift
2121
@_silgen_name("_swift_exit")
2222
internal func _exit(result: CInt)
2323

24+
#if !$Embedded
2425
@available(SwiftStdlib 6.2, *)
2526
@_silgen_name("_swift_task_isMainExecutorSwift")
2627
internal func _isMainExecutor<E>(_ executor: E) -> Bool where E: SerialExecutor {
2728
return executor.isMainExecutor
2829
}
30+
#endif
2931

3032
@available(SwiftStdlib 6.2, *)
3133
@_silgen_name("_swift_task_checkIsolatedSwift")
@@ -77,11 +79,13 @@ internal func _jobGetExecutorPrivateData(
7779
_ job: Builtin.Job
7880
) -> UnsafeMutableRawPointer
7981

82+
#if !$Embedded
8083
@available(SwiftStdlib 6.2, *)
8184
@_silgen_name("swift_getMainExecutor")
8285
internal func _getMainExecutor() -> any MainExecutor {
8386
return MainActor.executor
8487
}
88+
#endif
8589

8690
@available(SwiftStdlib 6.2, *)
8791
@_silgen_name("swift_dispatchMain")

stdlib/public/Concurrency/MainActor.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import Swift
1414

15+
#if !$Embedded
16+
1517
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
1618
@available(SwiftStdlib 5.1, *)
1719
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
@@ -160,4 +162,6 @@ extension MainActor {
160162
try assumeIsolated(operation, file: file, line: line)
161163
}
162164
}
163-
#endif
165+
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
166+
167+
#endif // !$Embedded

0 commit comments

Comments
 (0)