Skip to content

Commit 5160d19

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

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.
@@ -324,8 +328,10 @@ public protocol SerialExecutor: Executor {
324328
@available(SwiftStdlib 6.0, *)
325329
extension SerialExecutor {
326330

331+
#if !$Embedded
327332
@available(SwiftStdlib 6.2, *)
328333
public var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
334+
#endif
329335

330336
@available(SwiftStdlib 6.0, *)
331337
public func checkIsolated() {
@@ -565,9 +571,11 @@ public protocol MainExecutor: RunLoopExecutor, SerialExecutor, EventableExecutor
565571
/// executors.
566572
@available(SwiftStdlib 6.2, *)
567573
public protocol ExecutorFactory {
574+
#if !$Embedded
568575
/// Constructs and returns the main executor, which is started implicitly
569576
/// by the `async main` entry point and owns the "main" thread.
570577
static var mainExecutor: any MainExecutor { get }
578+
#endif
571579

572580
/// Constructs and returns the default or global executor, which is the
573581
/// default place in which we run tasks.
@@ -577,10 +585,13 @@ public protocol ExecutorFactory {
577585
@available(SwiftStdlib 6.2, *)
578586
@_silgen_name("swift_createExecutors")
579587
public func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
588+
#if !$Embedded
580589
MainActor._executor = factory.mainExecutor
590+
#endif
581591
Task._defaultExecutor = factory.defaultExecutor
582592
}
583593

594+
#if !$Embedded
584595
extension MainActor {
585596
@available(SwiftStdlib 6.2, *)
586597
static var _executor: (any MainExecutor)? = nil
@@ -598,6 +609,7 @@ extension MainActor {
598609
return _executor!
599610
}
600611
}
612+
#endif // !$Embedded
601613

602614
extension Task where Success == Never, Failure == Never {
603615
@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")
@@ -69,11 +71,13 @@ internal func _jobGetExecutorPrivateData(
6971
_ job: Builtin.Job
7072
) -> UnsafeMutableRawPointer
7173

74+
#if !$Embedded
7275
@available(SwiftStdlib 6.2, *)
7376
@_silgen_name("swift_getMainExecutor")
7477
internal func _getMainExecutor() -> any MainExecutor {
7578
return MainActor.executor
7679
}
80+
#endif
7781

7882
@available(SwiftStdlib 6.2, *)
7983
@_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)