Skip to content

Commit c20aa66

Browse files
committed
[Concurrency] Disable various things for task-to-thread model.
When in task-to-thread model concurrency mode, there is no `MainActor` and we cannot use `ExecutorJob`, so disable various things. rdar://141348916
1 parent 0da95eb commit c20aa66

8 files changed

+37
-17
lines changed

stdlib/public/Concurrency/CooperativeExecutor.swift

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
14+
1315
import Swift
1416

1517
// Store the Timestamp in the executor private data, if it will fit; otherwise,
@@ -255,3 +257,5 @@ extension CooperativeExecutor: TaskExecutor {}
255257

256258
@available(SwiftStdlib 6.2, *)
257259
extension CooperativeExecutor: MainExecutor {}
260+
261+
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

stdlib/public/Concurrency/DummyExecutor.swift

+12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ public final class DummyMainExecutor: MainExecutor, @unchecked Sendable {
2626
fatalError("There is no executor implementation active")
2727
}
2828

29+
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
30+
public func enqueue(_ job: UnownedJob) {
31+
fatalError("There is no executor implementation active")
32+
}
33+
#else
2934
public func enqueue(_ job: consuming ExecutorJob) {
3035
fatalError("There is no executor implementation active")
3136
}
37+
#endif
3238

3339
public var isMainExecutor: Bool { true }
3440

@@ -43,9 +49,15 @@ public final class DummyMainExecutor: MainExecutor, @unchecked Sendable {
4349
public final class DummyTaskExecutor: TaskExecutor, @unchecked Sendable {
4450
public init() {}
4551

52+
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
53+
public func enqueue(_ job: UnownedJob) {
54+
fatalError("There is no executor implementation active")
55+
}
56+
#else
4657
public func enqueue(_ job: consuming ExecutorJob) {
4758
fatalError("There is no executor implementation active")
4859
}
60+
#endif
4961

5062
public var isMainExecutor: Bool { false }
5163
}

stdlib/public/Concurrency/Executor.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +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
39+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4040
// The functions below could have been added to a separate protocol,
4141
// but doing that would then mean doing an `as?` cast in e.g.
4242
// enqueueOnGlobalExecutor (in ExecutorBridge.swift), which is
@@ -51,7 +51,7 @@ public protocol Executor: AnyObject, Sendable {
5151
@available(SwiftStdlib 6.2, *)
5252
public protocol SchedulableExecutor: Executor {
5353

54-
#if !$Embedded
54+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
5555

5656
/// Enqueue a job to run after a specified delay.
5757
///
@@ -94,7 +94,7 @@ public protocol SchedulableExecutor: Executor {
9494
tolerance: C.Duration?,
9595
clock: C)
9696

97-
#endif // !$Embedded
97+
#endif // !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
9898

9999
}
100100

@@ -125,7 +125,7 @@ extension Executor where Self: Equatable {
125125

126126
extension Executor {
127127

128-
#if !$Embedded
128+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
129129
// This defaults to `false` so that existing third-party Executor
130130
// implementations will work as expected.
131131
@available(SwiftStdlib 6.2, *)
@@ -138,7 +138,7 @@ extension Executor {
138138
@available(SwiftStdlib 6.2, *)
139139
extension SchedulableExecutor {
140140

141-
#if !$Embedded
141+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
142142

143143
@available(SwiftStdlib 6.2, *)
144144
public func enqueue<C: Clock>(_ job: consuming ExecutorJob,
@@ -162,7 +162,7 @@ extension SchedulableExecutor {
162162
tolerance: tolerance, clock: clock)
163163
}
164164

165-
#endif // !$Embedded
165+
#endif // !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
166166
}
167167

168168
/// A service that executes jobs.
@@ -331,7 +331,7 @@ public protocol SerialExecutor: Executor {
331331
@available(SwiftStdlib 6.0, *)
332332
extension SerialExecutor {
333333

334-
#if !$Embedded
334+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
335335
@available(SwiftStdlib 6.2, *)
336336
public var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
337337
#endif
@@ -542,13 +542,13 @@ public protocol ExecutorFactory {
542542
@available(SwiftStdlib 6.2, *)
543543
@_silgen_name("swift_createExecutors")
544544
public func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
545-
#if !$Embedded
545+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
546546
MainActor._executor = factory.mainExecutor
547547
#endif
548548
Task._defaultExecutor = factory.defaultExecutor
549549
}
550550

551-
#if !$Embedded
551+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
552552
extension MainActor {
553553
@available(SwiftStdlib 6.2, *)
554554
static var _executor: (any MainExecutor)? = nil
@@ -566,7 +566,7 @@ extension MainActor {
566566
return _executor!
567567
}
568568
}
569-
#endif // !$Embedded
569+
#endif // !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
570570

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

stdlib/public/Concurrency/ExecutorBridge.swift

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

24-
#if !$Embedded
24+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
2525
@available(SwiftStdlib 6.2, *)
2626
@_silgen_name("_swift_task_isMainExecutorSwift")
2727
internal func _isMainExecutor<E>(_ executor: E) -> Bool where E: SerialExecutor {
@@ -79,7 +79,7 @@ internal func _jobGetExecutorPrivateData(
7979
_ job: Builtin.Job
8080
) -> UnsafeMutableRawPointer
8181

82-
#if !$Embedded
82+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
8383
@available(SwiftStdlib 6.2, *)
8484
@_silgen_name("swift_getMainExecutor")
8585
internal func _getMainExecutor() -> any MainExecutor {

stdlib/public/Concurrency/ExecutorImpl.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
import Swift
2222

23+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
2324
@available(SwiftStdlib 6.2, *)
2425
@_silgen_name("swift_task_asyncMainDrainQueueImpl")
2526
internal func drainMainQueue() {
2627
try! MainActor.executor.run()
2728
_exit(result: 0)
2829
}
30+
#endif
2931

3032
@available(SwiftStdlib 6.2, *)
3133
@_silgen_name("swift_task_donateThreadToGlobalExecutorUntilImpl")
@@ -40,6 +42,7 @@ internal func dontateToGlobalExecutor(
4042
}
4143
}
4244

45+
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4346
@available(SwiftStdlib 6.2, *)
4447
@_silgen_name("swift_task_getMainExecutorImpl")
4548
internal func getMainExecutor() -> UnownedSerialExecutor {
@@ -51,14 +54,15 @@ internal func getMainExecutor() -> UnownedSerialExecutor {
5154
internal func enqueueOnMainExecutor(job unownedJob: UnownedJob) {
5255
MainActor.executor.enqueue(unownedJob)
5356
}
57+
#endif
5458

5559
@available(SwiftStdlib 6.2, *)
5660
@_silgen_name("swift_task_enqueueGlobalImpl")
5761
internal func enqueueOnGlobalExecutor(job unownedJob: UnownedJob) {
5862
Task.defaultExecutor.enqueue(unownedJob)
5963
}
6064

61-
#if !$Embedded
65+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
6266
@available(SwiftStdlib 6.2, *)
6367
@_silgen_name("swift_task_enqueueGlobalWithDelayImpl")
6468
internal func enqueueOnGlobalExecutor(delay: CUnsignedLongLong,

stdlib/public/Concurrency/MainActor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import Swift
2222

2323
@inlinable
2424
public nonisolated var unownedExecutor: UnownedSerialExecutor {
25-
return UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
25+
return unsafe UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
2626
}
2727

2828
@inlinable
2929
public static var sharedUnownedExecutor: UnownedSerialExecutor {
30-
return UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
30+
return unsafe UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
3131
}
3232

3333
@inlinable

stdlib/public/Concurrency/PlatformExecutorDarwin.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if !$Embedded && (os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS))
13+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY && (os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS))
1414

1515
import Swift
1616

stdlib/public/Concurrency/Task.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ extension Task where Success == Never, Failure == Never {
12541254
priority: Int(Task.currentPriority.rawValue),
12551255
continuation: continuation)
12561256

1257-
#if !$Embedded
1257+
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
12581258
if #available(SwiftStdlib 6.2, *) {
12591259
let executor = Task.currentExecutor
12601260

0 commit comments

Comments
 (0)