Commit Graph

309 Commits

Author SHA1 Message Date
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
Kuba Mracek
db94dc7d36 [Concurrency] Fix memory leak around mismatched refcounting in Concurrency 2024-10-31 21:43:02 -07:00
Mike Ash
bb09297598 [Concurrency] Fix getTaskId.
We should build a 64-bit value from the two 32-bit Id fields, but we were shifting one field by the other. Coincidentally, this managed to produce the correct value until the ID goes beyond 2^32, but after that it's weird and wrong.
2024-10-30 16:53:48 -04:00
Mykola Pokhylets
2acf5b6b6b Refactoring of the TaskLocal::Item
Replace NextLinkType with Item::Kind with more clear definition.
Use llvm::PointerIntPair<>.
Use hierarchy of classes instead of optional fields inside Item.
Combined Storage::copyToOnlyOnlyFromCurrentGroup() into Storage::initializeLinkParent().
Also create parent task marker when copying items created inside withTaskGroup().
Removed Storage::peekHeadLinkType().
2024-10-27 12:32:21 +01:00
Konrad `ktoso` Malawski
bd554ba524 Merge pull request #76883 from nickolas-pohilets/mpokhylets/move-task-locals-header 2024-10-10 19:38:35 +09:00
Alastair Houghton
a0a77fa401 Merge pull request #76870 from al45tair/eng/PR-137286187
[Concurrency] Remove C++ runtime references from embedded Concurrency.
2024-10-09 12:33:26 +01:00
Allan Shortlidge
0c09c6d778 Concurrency: Fix warnings in the runtime.
Addresses an unused variable warning and an unreachable code warning.
2024-10-08 14:49:17 -07:00
Alastair Houghton
54a495527e [Concurrency] Remove C++ runtime references from embedded Concurrency.
In embedded mode, we mustn't have references to the C++ library, because
some embedded platforms don't include the C++ library.

Additionally, it's good to avoid use of global operator new and operator
delete, because they can be globally overridden and this has bitten us
in the past.

rdar://137286187
2024-10-07 10:30:27 +01:00
Mykola Pokhylets
cb4c880af1 Move TaskLocal.h out of ABI folder, because it describes implementation details 2024-10-06 14:37:11 +02:00
Kuba Mracek
ed441eb1bf [Concurrency] Include more pieces of Concurrency in Embedded (AsyncStream, continuations)
We have been only including a subset of files and functionality on Embedded Concurrency, let's instead include all the
source files, and have a fine grained opt out on things that don't yet work. Namely, this is still avoiding clocks, task
sleeping and custom executors.

Add a test for AsyncStream and continuations on Embedded Concurrency.
2024-10-02 09:22:36 -07:00
Alastair Houghton
f8d6012d9a Merge pull request #76483 from al45tair/eng/PR-135380149
[Concurrency] Build executors as their own separate object modules.
2024-10-02 09:39:46 +01:00
Michael Gottesman
cb8e8b505a Fix syntax highlighting by changing how we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH.
The way that we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH freaks out the
syntax highlighting of editors like emacs. It causes the whole file to be
highlighted like it is part of the include string.

To work around this, this patch creates a separate file called
CompatibilityOverrideIncludePath.h that just includes
COMPATIBILITY_OVERRIDE_INCLUDE_PATH. So its syntax highlighting is borked, but
at least in the actual files that contain real code, the syntax highlighting is
restored.
2024-10-01 16:17:16 -07:00