Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
090c375
[Concurrency] Swift interface for custom main and global executors.
al45tair Feb 7, 2025
55afa47
[Concurrency] More work on the custom executor implementation.
al45tair Mar 7, 2025
d89ea19
[Concurrency] Add clock traits.
al45tair Mar 10, 2025
5ae6de2
[Concurrency] Fix potential ABI breakages.
al45tair Mar 10, 2025
2298651
[Concurrency] Rename ExecutorJob back to PartialAsyncTask.
al45tair Mar 10, 2025
3a7fc7c
[Concurrency] Remove spurious printf().
al45tair Mar 10, 2025
ef0e09d
[Concurrency][Embedded] Remove MainActor/MainExecutor everywhere.
al45tair Mar 11, 2025
d14b937
[Concurrency] Don't use blocks.
al45tair Mar 11, 2025
b33666c
[Concurrency] Fixes from initial review.
al45tair Mar 11, 2025
fc67cc3
[Concurrency] Mark expressions as `unsafe`.
al45tair Mar 11, 2025
23d0ca7
[Concurrency] Update header file.
al45tair Mar 11, 2025
444bbd5
[Concurrency] Update following pitch comments.
al45tair Mar 12, 2025
00e7ef2
[Concurrency] Remove EventableExecutor, alter asSchedulable.
al45tair Mar 13, 2025
d197f38
[Concurrency] Make `currentExecutor` return a non-optional.
al45tair Mar 13, 2025
f782499
[Concurrency][Tests] Fix baseline-asserts.
al45tair Mar 13, 2025
ff0ce62
[Concurrency][Tests] Linux doesn't have DispatchTime.advanced(by:).
al45tair Mar 13, 2025
869622f
[Concurrency][Tests] Remove spurious line in baseline-asserts.
al45tair Mar 14, 2025
8caa5c5
[Concurrency] Add a missing `public`.
al45tair Mar 14, 2025
a4f79f3
[Concurrency][Linux] Fix WASI build.
al45tair Mar 14, 2025
14b0e73
[Concurrency][Tests] Add missing `traits` symbol to baseline-asserts.
al45tair Mar 14, 2025
f0defd8
[Concurrency] Add CooperativeExecutor, use it.
al45tair Mar 17, 2025
ed08858
[Concurrency] Fix availability.
al45tair Mar 17, 2025
ad5b76a
[Concurrency] Another missing availability annotation.
al45tair Mar 17, 2025
167449f
[Concurrency] Fix a typo and use `var` not `let`.
al45tair Mar 18, 2025
4576d53
[Concurrency][Tests] Require `libdispatch` in the sleep test.
al45tair Mar 18, 2025
60fb31c
[Concurrency][32-bit] Store timestamp out-of-line on 32-bit.
al45tair Mar 18, 2025
fb0396c
[Concurrency] Fall back to allocating from the heap, fix a test.
al45tair Mar 18, 2025
0da95eb
[Concurrency] Fix some warnings, use typed throws.
al45tair Mar 18, 2025
c20aa66
[Concurrency] Disable various things for task-to-thread model.
al45tair Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[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
  • Loading branch information
al45tair committed Mar 19, 2025
commit c20aa667f210bc0d80760671b8fce38af9e6bbb4
4 changes: 4 additions & 0 deletions stdlib/public/Concurrency/CooperativeExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//

#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

import Swift

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

@available(SwiftStdlib 6.2, *)
extension CooperativeExecutor: MainExecutor {}

#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
12 changes: 12 additions & 0 deletions stdlib/public/Concurrency/DummyExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ public final class DummyMainExecutor: MainExecutor, @unchecked Sendable {
fatalError("There is no executor implementation active")
}

#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
public func enqueue(_ job: UnownedJob) {
fatalError("There is no executor implementation active")
}
#else
public func enqueue(_ job: consuming ExecutorJob) {
fatalError("There is no executor implementation active")
}
#endif

public var isMainExecutor: Bool { true }

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

#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
public func enqueue(_ job: UnownedJob) {
fatalError("There is no executor implementation active")
}
#else
public func enqueue(_ job: consuming ExecutorJob) {
fatalError("There is no executor implementation active")
}
#endif

public var isMainExecutor: Bool { false }
}
20 changes: 10 additions & 10 deletions stdlib/public/Concurrency/Executor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public protocol Executor: AnyObject, Sendable {
func enqueue(_ job: consuming ExecutorJob)
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
// The functions below could have been added to a separate protocol,
// but doing that would then mean doing an `as?` cast in e.g.
// enqueueOnGlobalExecutor (in ExecutorBridge.swift), which is
Expand All @@ -51,7 +51,7 @@ public protocol Executor: AnyObject, Sendable {
@available(SwiftStdlib 6.2, *)
public protocol SchedulableExecutor: Executor {

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

/// Enqueue a job to run after a specified delay.
///
Expand Down Expand Up @@ -94,7 +94,7 @@ public protocol SchedulableExecutor: Executor {
tolerance: C.Duration?,
clock: C)

#endif // !$Embedded
#endif // !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

}

Expand Down Expand Up @@ -125,7 +125,7 @@ extension Executor where Self: Equatable {

extension Executor {

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

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

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

#endif // !$Embedded
#endif // !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
}

/// A service that executes jobs.
Expand Down Expand Up @@ -331,7 +331,7 @@ public protocol SerialExecutor: Executor {
@available(SwiftStdlib 6.0, *)
extension SerialExecutor {

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 6.2, *)
public var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
#endif
Expand Down Expand Up @@ -542,13 +542,13 @@ public protocol ExecutorFactory {
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_createExecutors")
public func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
MainActor._executor = factory.mainExecutor
#endif
Task._defaultExecutor = factory.defaultExecutor
}

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
extension MainActor {
@available(SwiftStdlib 6.2, *)
static var _executor: (any MainExecutor)? = nil
Expand All @@ -566,7 +566,7 @@ extension MainActor {
return _executor!
}
}
#endif // !$Embedded
#endif // !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

extension Task where Success == Never, Failure == Never {
@available(SwiftStdlib 6.2, *)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/ExecutorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Swift
@_silgen_name("_swift_exit")
internal func _exit(result: CInt)

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

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_getMainExecutor")
internal func _getMainExecutor() -> any MainExecutor {
Expand Down
6 changes: 5 additions & 1 deletion stdlib/public/Concurrency/ExecutorImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

import Swift

#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_task_asyncMainDrainQueueImpl")
internal func drainMainQueue() {
try! MainActor.executor.run()
_exit(result: 0)
}
#endif

@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_task_donateThreadToGlobalExecutorUntilImpl")
Expand All @@ -40,6 +42,7 @@ internal func dontateToGlobalExecutor(
}
}

#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_task_getMainExecutorImpl")
internal func getMainExecutor() -> UnownedSerialExecutor {
Expand All @@ -51,14 +54,15 @@ internal func getMainExecutor() -> UnownedSerialExecutor {
internal func enqueueOnMainExecutor(job unownedJob: UnownedJob) {
MainActor.executor.enqueue(unownedJob)
}
#endif

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

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_task_enqueueGlobalWithDelayImpl")
internal func enqueueOnGlobalExecutor(delay: CUnsignedLongLong,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/MainActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import Swift

@inlinable
public nonisolated var unownedExecutor: UnownedSerialExecutor {
return UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
return unsafe UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
}

@inlinable
public static var sharedUnownedExecutor: UnownedSerialExecutor {
return UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
return unsafe UnownedSerialExecutor(Builtin.buildMainActorExecutorRef())
}

@inlinable
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/PlatformExecutorDarwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

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

import Swift

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ extension Task where Success == Never, Failure == Never {
priority: Int(Task.currentPriority.rawValue),
continuation: continuation)

#if !$Embedded
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
if #available(SwiftStdlib 6.2, *) {
let executor = Task.currentExecutor

Expand Down