diff --git a/cmake/modules/AddSwiftUnittests.cmake b/cmake/modules/AddSwiftUnittests.cmake index 3c1a985548bae..7cd1f62e6741b 100644 --- a/cmake/modules/AddSwiftUnittests.cmake +++ b/cmake/modules/AddSwiftUnittests.cmake @@ -65,6 +65,13 @@ function(add_swift_unittest test_dirname) _ENABLE_EXTENDED_ALIGNED_STORAGE) endif() + # some headers switch their inline implementations based on + # SWIFT_STDLIB_SINGLE_THREADED_RUNTIME definition + if(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME) + target_compile_definitions("${test_dirname}" PRIVATE + SWIFT_STDLIB_SINGLE_THREADED_RUNTIME) + endif() + if(NOT SWIFT_COMPILER_IS_MSVC_LIKE) if(SWIFT_USE_LINKER) target_link_options(${test_dirname} PRIVATE diff --git a/stdlib/public/Concurrency/GlobalExecutor.cpp b/stdlib/public/Concurrency/GlobalExecutor.cpp index f304b2a14c35f..4e2c3bf07fa15 100644 --- a/stdlib/public/Concurrency/GlobalExecutor.cpp +++ b/stdlib/public/Concurrency/GlobalExecutor.cpp @@ -102,7 +102,7 @@ static DelayedJob *DelayedJobQueue = nullptr; /// Get the next-in-queue storage slot. static Job *&nextInQueue(Job *cur) { - return reinterpret_cast(cur->SchedulerPrivate); + return reinterpret_cast(cur->SchedulerPrivate[Job::NextWaitingTaskIndex]); } /// Insert a job into the cooperative global queue. diff --git a/stdlib/public/Concurrency/Mutex.cpp b/stdlib/public/Concurrency/Mutex.cpp index 6f59f6fae932b..4b11bc2974f18 100644 --- a/stdlib/public/Concurrency/Mutex.cpp +++ b/stdlib/public/Concurrency/Mutex.cpp @@ -15,7 +15,6 @@ #include "../runtime/MutexPThread.cpp" #include "../runtime/MutexWin32.cpp" - #ifdef SWIFT_STDLIB_SINGLE_THREADED_RUNTIME #include "swift/Runtime/MutexSingleThreaded.h" #endif diff --git a/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift b/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift index 82ecf44b37155..6c0219b6e3394 100644 --- a/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift +++ b/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift @@ -7,6 +7,8 @@ // rdar://76038845 // REQUIRES: concurrency_runtime // UNSUPPORTED: back_deployment_runtime +// Disable on cooperative executor because it can't dispatch jobs before the end of main function +// UNSUPPORTED: single_threaded_runtime import Dispatch diff --git a/test/Concurrency/Runtime/cancellation_handler.swift b/test/Concurrency/Runtime/cancellation_handler.swift index 386994b639b1a..2392290e3ee81 100644 --- a/test/Concurrency/Runtime/cancellation_handler.swift +++ b/test/Concurrency/Runtime/cancellation_handler.swift @@ -5,8 +5,7 @@ // rdar://76038845 // REQUIRES: concurrency_runtime // UNSUPPORTED: back_deployment_runtime -// UNSUPPORTED: OS=windows-msvc -// UNSUPPORTED: OS=wasi +// UNSUPPORTED: single_threaded_runtime // for sleep #if canImport(Darwin) diff --git a/test/Concurrency/Runtime/data_race_detection.swift b/test/Concurrency/Runtime/data_race_detection.swift index eb3c4608be6a0..06434e32af041 100644 --- a/test/Concurrency/Runtime/data_race_detection.swift +++ b/test/Concurrency/Runtime/data_race_detection.swift @@ -8,6 +8,8 @@ // rdar://76038845 // REQUIRES: concurrency_runtime // UNSUPPORTED: back_deployment_runtime +// UNSUPPORTED: single_threaded_runtime + import _Concurrency import Dispatch @@ -57,14 +59,14 @@ actor MyActor { struct Runner { static func main() async { print("Launching a main-actor task") - // CHECK: warning: data race detected: @MainActor function at main/data_race_detection.swift:21 was not called on the main thread + // CHECK: warning: data race detected: @MainActor function at main/data_race_detection.swift:23 was not called on the main thread launchFromMainThread() sleep(1) let actor = MyActor() let actorFn = await actor.getTaskOnMyActor() print("Launching an actor-instance task") - // CHECK: warning: data race detected: actor-isolated function at main/data_race_detection.swift:50 was not called on the same actor + // CHECK: warning: data race detected: actor-isolated function at main/data_race_detection.swift:52 was not called on the same actor launchTask(actorFn) sleep(1) diff --git a/test/Concurrency/Runtime/mainactor.swift b/test/Concurrency/Runtime/mainactor.swift index e66bf6eb2d570..09c1742d96cc6 100644 --- a/test/Concurrency/Runtime/mainactor.swift +++ b/test/Concurrency/Runtime/mainactor.swift @@ -7,6 +7,7 @@ // rdar://76038845 // REQUIRES: concurrency_runtime // UNSUPPORTED: back_deployment_runtime +// UNSUPPORTED: single_threaded_runtime import Dispatch diff --git a/test/Interpreter/enforce_exclusive_access.swift b/test/Interpreter/enforce_exclusive_access.swift index 321dc5dfcd38b..a900089d1515f 100644 --- a/test/Interpreter/enforce_exclusive_access.swift +++ b/test/Interpreter/enforce_exclusive_access.swift @@ -4,6 +4,7 @@ // RUN: %target-codesign %t/a.out // RUN: %target-run %t/a.out // REQUIRES: executable_test +// UNSUPPORTED: single_threaded_runtime // Tests for traps at run time when enforcing exclusive access. diff --git a/unittests/runtime/CMakeLists.txt b/unittests/runtime/CMakeLists.txt index d7ae719204e7d..a72fcdd9cd894 100644 --- a/unittests/runtime/CMakeLists.txt +++ b/unittests/runtime/CMakeLists.txt @@ -84,12 +84,17 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND endif() endif() + if(NOT SWIFT_STDLIB_SINGLE_THREADED_RUNTIME) + list(APPEND PLATFORM_SOURCES Mutex.cpp) + endif() + # Don't complain about these files not being in the sources list. set(LLVM_OPTIONAL_SOURCES weak.mm Refcounting.mm Actor.cpp - TaskStatus.cpp) + TaskStatus.cpp + Mutex.cpp) add_swift_unittest(SwiftRuntimeTests Array.cpp @@ -97,7 +102,6 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND CompatibilityOverrideConcurrency.cpp Concurrent.cpp Metadata.cpp - Mutex.cpp Enum.cpp Refcounting.cpp Stdlib.cpp diff --git a/unittests/runtime/Concurrent.cpp b/unittests/runtime/Concurrent.cpp index c014fcb207001..f3b3ea9308b1e 100644 --- a/unittests/runtime/Concurrent.cpp +++ b/unittests/runtime/Concurrent.cpp @@ -45,6 +45,8 @@ TEST(ConcurrentReadableArrayTest, SingleThreaded) { check(); } +#ifndef SWIFT_STDLIB_SINGLE_THREADED_RUNTIME + TEST(ConcurrentReadableArrayTest, MultiThreaded) { const int insertCount = 100000; @@ -542,3 +544,4 @@ TEST(ConcurrentReadableHashMapTest, MultiThreaded4) { runTest(16, 1); runTest(16, 8); } +#endif // !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME diff --git a/validation-test/Runtime/ConcurrentMetadata.swift b/validation-test/Runtime/ConcurrentMetadata.swift index a006c5afb708b..60e8add4dc2cb 100644 --- a/validation-test/Runtime/ConcurrentMetadata.swift +++ b/validation-test/Runtime/ConcurrentMetadata.swift @@ -1,5 +1,6 @@ // RUN: %target-run-simple-swift // REQUIRES: executable_test +// UNSUPPORTED: single_threaded_runtime // Exercise the metadata cache from multiple threads to shake out any // concurrency bugs.