Commit Graph

320 Commits

Author SHA1 Message Date
Doug Gregor 5ac23be8fd Merge pull request #88862 from DougGregor/embedded-concurrency-minimized-dependencies
Minimize platform dependencies in the Embedded Swift Concurrency library
2026-05-07 10:37:32 -07:00
Doug Gregor 834b2ace1d [Concurrency runtime] Use swift_slow(Alloc|Dealloc) instead of malloc/free
Memory allocation in Swift should always go through the common Swift
entrypoints rather than have calls directly into the C standard
library. This goes through the platform abstraction layer in Embedded
Swift, for platforms that may not have a C standard library.
2026-05-06 08:24:31 -07:00
Alastair Houghton ed225ce9c9 Merge pull request #88685 from al45tair/eng/PR-163401438
[Concurrency][Runtime] Fix `isCurrentGlobalActorHook`.
2026-05-06 09:12:46 +01:00
Doug Gregor cb5b0ee938 [Embedded Concurrency] Route fatal errors to a new _swift_fatalError
Fatal errors in the concurrency runtime used a mix of
swift_Concurrency_fatalError[v] and manual calls to abort(). Drop the
dependency on abort() by routing all true fatal errors through
swift_Concurrency_fatalErrorv and eventually to a new
`_swift_fatalError` C entrypoint defined in the Embedded Swift
runtime, which (optionally) prints and then (always) traps.
2026-05-05 18:06:30 -07:00
Doug Gregor 4cffd16c2b [Embedded Concurrency] Cut out the failed check logging function.
This function isn't used in the Embedded Concurrency library, and
refers to another logging function that isn't provided in the Embedded
Swift runtime.
2026-05-05 16:56:36 -07:00
Alastair Houghton 5408ae3149 [Runtime] Fix function signatures to work for Wasm.
Wasm requires that the `SWIFT_CONTEXT` be the final argument,
because it uses stack-based parameter passing.

rdar://163401438
2026-05-05 16:56:25 +01:00
Alastair Houghton 0f63d6e3d2 [Concurrency][Runtime] Fix isCurrentGlobalActorHook.
We were crashing when using this hook function because the hook points
at a Swift function, which expects `self` to be set, but we weren't
telling the C compiler and so when we called through the function pointer
from C++ code, the relevant register wasn't set and we'd crash.

Fixes #85134

rdar://163401438
2026-04-27 17:29:34 +01:00
Doug Gregor 16bfa9be97 [Embedded] Enable throwing in the concurrency library
Now that we have untyped throws support in Embedded Swift, remove the
special cases that trapped when a task (or anything built on it)
throws. Introduce some tests that ensure that we can throw errors
through a Task or "async let" and catch the error.

Fixes rdar://175590869.
2026-04-25 11:50:31 -07:00
Konrad `ktoso` Malawski e4b0a2c8e8 [Concurrency] Allow getting unsafe task from Job and name as well (#84370) 2026-04-17 21:34:50 +09:00
Konrad `ktoso` Malawski 68c8641321 Task Cancellation Shields (#85637)
This is a follow up from the "async" `deinit` work, which will allow us
to guarantee cleanup code to run in deinitializers, even if they need to
call asynchronous code, and even if they may be run in a task that was
cancelled: by "shielding" it from cancellation.

This is incomplete, the child handling needs some more love.

SE proposal: https://github.com/swiftlang/swift-evolution/pull/3037/
2026-02-16 09:35:27 +09:00
Bryce Wilson b30f63530a [Concurrency] Set thread base priority when running escalated Tasks (#84895) 2025-11-20 09:58:08 +09:00
John McCall 3cfda35b7c Remove the unused swift_asyncLet_{start,end,wait,wait_throwing} runtime
functions.

These were introduced in an early draft implementation of async let, but
never used by a released compiler. They are not used as symbols by any
app binaries. There's no reason to keep carrying them.

While I'm at it, dramatically improve the documentation of the remaining
async let API functions.
2025-11-03 13:45:18 -08:00
Yuta Saito 30e0fa5133 [Concurrency] Fix runtime isolated-conformance checks with static stdlib
Most of linkers pull object files from static archives only if any
symbol from that object file is referenced, even if the object contains
a ctor code. `Setup.cpp` didn't have any symbols referenced from
other code, so it was not linked in when the concurrency runtime was
linked in statically. This commit moves the ctor code to `Task.cpp`
to ensure that it is always linked in.
2025-07-16 06:28:04 +00:00
Konrad 'ktoso' Malawski 358c3e9dcf [Concurrency] a few missing overloads for immediate tasks 2025-07-10 12:40:41 +09:00
Mike Ash ec6a042831 [Runtime] Remove redundant swift_auth_code_function, use existing swift_auth_code.
rdar://153169049
2025-06-13 18:46:23 -04:00
Konrad 'ktoso' Malawski 7305efabdd [Concurrency] Prefer swift_auth_code_function over swift_auth_code
This allows us to use constants, and not hardcoded numbers
2025-06-03 06:59:42 +09:00
Konrad 'ktoso' Malawski 2c99a669d3 Correct priority cancellation handler signing once more
Resolves rdar://150378890 for real this time, verified on arm64e myself
2025-06-02 21:32:57 +09:00
Konrad 'ktoso' Malawski 97a4904c1f [Concurrency] Correct the signing of priority escalation handler 2025-05-23 17:02:19 -07:00
Alastair Houghton 23a181730f Merge pull request #81200 from al45tair/eng/PR-150310927
[Concurrency] Fix issue with using Dispatch queues as executors.
2025-05-01 11:56:43 +01:00
Konrad 'ktoso' Malawski 8fccafd2fa [Concurrency] Fix ptr auth for task priority escalation handler
We missed to sign the handler. Along the way the signature of it
changed, so adjust for that.

How to get the number:

```
func PROPER(bar: (TaskPriority, TaskPriority) -> Void) {
    let p = TaskPriority.default
    bar(p, p)
}
```

```
-> % swiftc -target arm64e-apple-macos13 example.swift -S -o - | swift demangle | grep -a3 autda
	stur	x8, [x29, #-64]
	mov	x17, x8
	movk	x17, #11839, lsl #48 <<<<<<<<<
	autda	x16, x17
	ldr	x8, [x16, #64]
	lsr	x8, x8, #0
	add	x8, x8, #15
```

Resolves rdar://150378890
2025-05-01 12:07:35 +09:00
Alastair Houghton e843a24a99 [Concurrency] Fix issue with using Dispatch queues as executors.
We were failing to switch executors to Dispatch queues, where those
were being used as executors, which caused a variety of unusual
symptoms.

rdar://150310927
2025-04-30 14:18:42 +01:00
Konrad `ktoso` Malawski 7dcdd30fe0 Avoid unused variable warning 2025-04-14 16:00:07 +09:00
Mike Ash 433ca8ea81 Merge pull request #80516 from mikeash/function-cast
[Runtime] Add function_cast, switch from std::bit_cast.
2025-04-11 05:15:25 -04:00
Mike Ash 185b739cf1 [Runtime] Add function_cast, switch from std::bit_cast.
Function types aren't always trivially copyable, e.g. with address-discriminated signed pointers on ARM64e. Introduce a function_cast helper and use that instead.
2025-04-10 20:29:02 -04:00
Mike Ash 4290f0add4 Merge pull request #80447 from mikeash/fix-task-sizes
[Concurrency] Fix task status and private storage sizes.
2025-04-09 13:14:40 -04:00
Mike Ash e3057031da [RemoteMirror] Fix AsyncTask child iteration.
Iterating child tasks depends on knowing the size of AsyncTask, and changing the size of the task broke it. Instead of relying on mirroring the full structure in our out-of-process definitions, add a debug variable to libswift_Concurrency that contains the size of AsyncTask.

While we're there, add some more validation to child task enumeration. Check each child task's metadata pointer to make sure that it actually points to the AsyncTask metadata, and have the inner loop also increment and check ChildTaskLoopCount to stop runaway iteration in that loop.
2025-04-08 13:09:29 -04:00
Konrad `ktoso` Malawski 8d72db58fe Merge pull request #80522 from ktoso/wip-better-assertion-pop-record
[Concurrency] Improve assertion to validate we pop the EXACT record we intend to
2025-04-04 18:11:56 +09:00
Konrad 'ktoso' Malawski 0cb39ddd8a [Concurrency] Improve assertion to validate we pop the EXACT record we intend to 2025-04-04 13:25:58 +09:00
Artem Chikin 69b4ea3469 Merge pull request #80421 from swiftlang/revert-80246-playing-with-pointy-pointers
Revert "Concurrency: remove workaround for silencing UB"
2025-04-03 16:12:53 -07:00
Konrad `ktoso` Malawski 28c4930f4f [Concurrency] Avoid inserting handler record in already cancelled task. (#80456)
This avoids the potential to race with the triggering coming from
task_cancel, because we first set the cancelled flag, and only THEN
take the lock and iterate over the inserted records. Because of this we
could: T1 flip the cancelled bit; T2 observes that, and triggers
"immediately" during installing the handler record. T1 then proceeds to
lock records and trigger it again, causing a double trigger of the
cancellation handler.

resolves https://github.com/swiftlang/swift/issues/80161
resolves rdar://147493150
2025-04-02 19:21:18 +09:00
Konrad `ktoso` Malawski 240a43b054 Revert "Concurrency: remove workaround for silencing UB" 2025-04-01 07:09:57 +09:00
Alastair Houghton b1c345f1be Merge pull request #80266 from al45tair/custom-executors-take2
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-31 09:53:48 +01:00
Alastair Houghton 6e28716319 [Concurrency] Address some review comments.
Tweaked diagnostic to use a string instead of a type.  Renamed the
feature in `FeatureAvailability.def` (and added the `TaskExecutor`
feature to 6.2).  Also fixed the `swift_getActiveExecutor()`
function to return the main executor only when on the main thread.

rdar://141348916
2025-03-28 10:15:14 +00:00
Alastair Houghton 47fa71787f Revert "Merge pull request #80224 from glessard/revert-79789-custom-executors"
This reverts commit 06f6358067, reversing
changes made to 033f6679e8.
2025-03-28 10:15:07 +00:00
Saleem Abdulrasool 87f2b88ada Concurrency: remove workaround for silencing UB
The newer clang properly identifies UB on invalid pointer casts. This
was previously being silenced by suppressing the warnings. Adjust the
code to use `std::bit_cast` (or the shim implementation) to avoid the
UB in this code.
2025-03-27 08:27:06 -07:00
Alastair Houghton 8b15b05c63 Revert "[Concurrency] Provide a Swift interface for custom main and global executors." 2025-03-22 02:38:11 -07:00
Alastair Houghton 090c375b7b [Concurrency] Swift interface for custom main and global executors.
Reorganise the Concurrency code so that it's possible to completely
implement executors (both main and global) in Swift.

Provide API to choose the desired executors for your application.

Also make `Task.Sleep` wait using the current executor, not the global
executor, and expose APIs on `Clock` to allow for conversion between
time bases.

rdar://141348916
2025-03-13 13:34:41 +00:00
Konrad `ktoso` Malawski fda7f539fb Reapply "Task names" (#79562) (#79600) 2025-03-08 10:58:49 +09:00
Konrad `ktoso` Malawski f55964df26 [Concurrency] Initial steps for startSynchronously for Task (#79608)
* [Concurrency] Initial steps for startSynchronously for Task

* [Concurrency] Rename to _startSynchronously while in development

* [Concurrency] StartSynchronously special executor to avoid switching

* startSynchronously bring back more info output

* [Concurrency] startSynchronously with more custom executor tests

* add missing ABI additions to test for x86

* [Concurrency] gyb generate _startSynchronously

* [Concurrency] %import dispatch for Linux startSynchronously test

* [Concurrency] Add TaskGroup.startTaskSynchronously funcs

* [Concurrency] DispatchSerialQueue does not exist on linux still
2025-02-27 02:34:33 -08:00
Konrad `ktoso` Malawski 09003d6f11 Revert "Merge pull request #77609 from ktoso/wip-task-names" (#79562)
This reverts commit 4ab5d2604f.
2025-02-23 22:59:21 -08:00
Konrad `ktoso` Malawski 4ab5d2604f Merge pull request #77609 from ktoso/wip-task-names
[Concurrency] Task names
2025-02-21 22:28:33 +09:00
Allan Shortlidge 6e3eb96d91 Concurrency: Fix an unused variable warning. 2025-02-13 07:40:53 -08:00
Konrad `ktoso` Malawski 29d95cef85 [Concurrency] Fix ptrauth value for __ptrauth_swift_escalation_notification_function
Previously these records were not used at all, so changing this has no
impact on existing runtimes. Note that we changedd the FunctionType
because the previous one was slightly incorrect -- the context comes
LAST in the type, not first.
2025-02-08 17:18:59 +09:00
Konrad `ktoso` Malawski 67e6373c23 [Concurrency] minor renames of new API for adding escalation handlers 2025-02-08 17:18:58 +09:00
Konrad `ktoso` Malawski 655bd67f67 [Concurrency] Task priority escalation handler API 2025-02-08 17:18:58 +09:00
John McCall d8d70d9aac Add support for creating a task with a self-consuming task function.
Not used yet.
2024-11-15 22:51:57 -05:00
Allan Shortlidge 1ee4924542 Concurrency: Suppress -Wcast-function-type-mismatch warnings. 2024-11-13 09:51:29 -08:00
Allan Shortlidge 3f42ec25f9 Concurrency: Fix warnings about unused functions. 2024-11-13 09:51:29 -08:00
Mike Ash fcdec961b0 Merge pull request #77306 from swiftlang/fix-getTaskId
[Concurrency] Fix getTaskId.
2024-11-04 20:03:19 -05:00
Kuba Mracek d78be484fc [Concurrency] Avoid reinterpret_cast in Concurrency/Task.cpp, fixes crashes in libdispatch 2024-11-01 10:31:58 -07:00