Skip to content

Enable MainActor in embedded concurrency, add ExecutorImpl.cpp #82331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 17 additions & 9 deletions stdlib/public/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ set(SWIFT_RUNTIME_CONCURRENCY_C_SOURCES
Actor.cpp
AsyncLet.cpp
Clock.cpp
GlobalExecutor.cpp
ConcurrencyHooks.cpp
GlobalExecutor.cpp
EmbeddedSupport.cpp
Error.cpp
ExecutorBridge.cpp
ExecutorChecks.cpp
ExecutorImpl.cpp
Setup.cpp
Task.cpp
TaskAlloc.cpp
Expand Down Expand Up @@ -167,12 +168,10 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
PlatformExecutorFreeBSD.swift
)

set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES
ExecutorImpl.cpp
)

set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES)
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES)
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES
)

if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES
Expand All @@ -195,10 +194,6 @@ else()
)
endif()

set(SWIFT_RUNTIME_CONCURRENCY_EMBEDDED_SWIFT_SOURCES
PlatformExecutorNone.swift
)

set(LLVM_OPTIONAL_SOURCES
DispatchGlobalExecutor.cpp
CooperativeGlobalExecutor.cpp
Expand Down Expand Up @@ -314,6 +309,19 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
endif()
endif()

if("${arch}" MATCHES "wasm32")
set(SWIFT_RUNTIME_CONCURRENCY_EMBEDDED_SWIFT_SOURCES
ExecutorImpl.swift
PlatformExecutorCooperative.swift
)
else()
set(SWIFT_RUNTIME_CONCURRENCY_EMBEDDED_SWIFT_SOURCES
ExecutorImpl.swift
PlatformExecutorNone.swift
)
endif()


set(SWIFT_SDK_embedded_THREADING_PACKAGE none)
set(SWIFT_SDK_embedded_ARCH_${arch}_MODULE "${mod}")
set(SWIFT_SDK_embedded_ARCH_${mod}_MODULE "${mod}")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/Executor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func _createDefaultExecutors() {
}
}

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

extension Task where Success == Never, Failure == Never {
@available(StdlibDeploymentTarget 6.2, *)
Expand Down
2 changes: 0 additions & 2 deletions stdlib/public/Concurrency/ExecutorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ internal func _jobGetExecutorPrivateData(
_ job: Builtin.Job
) -> UnsafeMutableRawPointer

#if !$Embedded
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(StdlibDeploymentTarget 6.2, *)
@_silgen_name("swift_getMainExecutor")
Expand All @@ -100,7 +99,6 @@ internal func _getMainExecutor() -> any SerialExecutor {
@_silgen_name("swift_getMainExecutor")
internal func _getMainExecutor() -> any SerialExecutor
#endif // SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
#endif // !$Embedded

@available(StdlibDeploymentTarget 6.2, *)
@_silgen_name("swift_dispatchMain")
Expand Down
3 changes: 0 additions & 3 deletions stdlib/public/Concurrency/MainActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import Swift

#if !$Embedded

#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
Expand Down Expand Up @@ -164,4 +162,3 @@ extension MainActor {
}
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

#endif // !$Embedded