Commit Graph

1601 Commits

Author SHA1 Message Date
Alex Martini
0bd4ee3ca6 Merge pull request #80359 from amartini51/doc_fixes
Documentation fixes
2025-03-28 15:33:40 -07:00
Mike Ash
ecdcb82b97 Merge pull request #80316 from mikeash/lock-record-begone
[Concurrency] Eliminate StatusRecordLockRecord.
2025-03-28 17:18:40 -04: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
a418ce4931 [Concurrency] Fix some comments and a typo.
There were a couple of comments that needed updating, and a typo
in a function name.

rdar://141348916
2025-03-28 10:15:14 +00:00
Alastair Houghton
0c96a257f6 [Concurrency] Fix task-to-thread model linking.
We need to provide some of the additional functions, as stubs, for
task-to-thread model.

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
Nate Chandler
2af30b2f04 [NFC] CoroutineAccessors: Remove old runtime files
The functions are open-coded now.
2025-03-27 19:23:09 -07:00
nate-chandler
b878155a5a Merge pull request #80335 from nate-chandler/general-coro/20250326/2
[CoroutineAccessors] Move functions and add dealloc bit.
2025-03-27 19:19:25 -07:00
Alex Martini
7ee720bfc4 Use verb fragment, per API reference style 2025-03-27 16:51:25 -07:00
Nate Chandler
f30d8a603c [CoroutineAccessors] Rehome runtime functions.
Put them where they're meant to be, in swiftCore.
2025-03-27 11:37:26 -07:00
Pavel Yaskevich
6082173b8a Merge pull request #80280 from xedin/rdar-131732245
[TypeChecker] Avoid dropping pre-check diagnostics in `typeCheckParam…
2025-03-27 08:59:43 -07: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
Mike Ash
433ff598f5 Merge pull request #80319 from mikeash/priority-escalation-retry-fix
[Concurrency] Avoid de-escalating a task when racing to escalate.
2025-03-27 09:36:21 -04:00
nate-chandler
e8d871ced5 Merge pull request #80290 from nate-chandler/general-coro/20250325/1
[CoroutineAccessors] Directly reference allocators.
2025-03-26 21:47:09 -07:00
Allan Shortlidge
2f78ba8828 Sema: Extend _unsafeInheritExecutor_ hack to Clock.measure().
Fixes the bug in `swift::introduceUnsafeInheritExecutorReplacements()` that
prevented the hack from working with `Clock.measure()`. It isn't sufficient to
just check whether the nominal for the type base of a qualified lookup belongs
to the Concurrency module because that type may reference multiple types.
Instead, check all of the directly referenced types to match the behavior of
qualified lookup.

Resolves rdar://132581483.
2025-03-26 21:12:58 -07:00
Pavel Yaskevich
d656f74652 [TypeChecker] Avoid dropping pre-check diagnostics in typeCheckParameterDefault
`typeCheck{Expression, Target}` has a pre-check phase which would
replace some invalid AST nodes (i.e. name references that are not
available in the given declaration context) with `ErrorExpr`s and
emit a diagnostic. Such diagnostics were then dropped by `abort()`
call to a diagnostic transaction. This results in invalid code being
accepted by Sema and forwarded to SILGen.

Resolves: https://github.com/swiftlang/swift/issues/73986
Resolves: rdar://131732245
2025-03-26 14:22:32 -07:00
Max Desiatov
eb1a2960b6 Enable _Concurrency for Embedded Swift with WASI (#79292)
WASI with Embedded Swift provides WASI-libc and libc++ headers necessary to build the `_Concurrency` module for Wasm. We now add `wasm32-unknown-wasip1-wasm` triple to `EMBEDDED_STDLIB_TARGET_TRIPLES` when `SWIFT_WASI_SYSROOT_PATH` is set, which builds the necessary stdlib slice.

---------

Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
2025-03-26 21:14:05 +00:00
Mike Ash
7c3b06dc4f [Concurrency] Avoid de-escalating a task when racing to escalate.
Reload oldPriority each time through the compare_exchange loop. Without this, we might race with another escalating thread and end up trying to set a priority that's lower or equal to the priority set by the other thread. This results in an assertion failure when asserts are enabled, or attempt to lower the priority of the task when asserts are not enabled.

rdar://147888768
2025-03-26 15:44:57 -04:00
Mike Ash
6397e30856 [Concurrency] Eliminate StatusRecordLockRecord.
Move to a recursive lock inline in the Task. This avoids the need to allocate a lock record and simplifies the code somewhat.

Change Task's OpaquePrivateStorage to compute its size at build time based on the sizes of its components, rather than having it be a fixed size. It appears that the fixed size was intended to be part of the ABI, but that didn't happen and we're free to change this size. We need to expand it slightly when using pthread_mutex as the recursive lock, as pthread_mutex is pretty big. Other recursive locks allow it to shrink slightly.

We don't have a recursive mutex in our Threading support code, so add a RecursiveMutex type.

rdar://113898653
2025-03-26 14:52:37 -04:00
Nate Chandler
0c2a38b10b [CoroutineAccessors] Directly reference allocators
Replace the call to a runtime function that looks up the allocator with
a direct reference to a just-emittedd sought-after global allocator.
2025-03-26 08:35:35 -07:00
Dario Rexin
c89cb49a14 [Concurrency] Properly set task create flags in TaskGroup.startTaskSynchronously (#80299)
rdar://147907609

When starting tasks synchronously on task groups, the task create flags for isSynchronousStart and isDiscardingTask were always set to `false`. With this change the former will always be `true` and the latter conditionally `true` for discarding task groups.
2025-03-26 22:00:33 +09:00
Mike Ash
6a383b270e [Runtime] Ignore some global constructor warnings.
We have a few constructor functions that aren't wrapped in SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN/SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END and which have started to produce warnings in a new clang version. Explicitly allow these constructors by adding those.

rdar://147703947
2025-03-24 12:43:03 -04:00
Holly Borla
498d7ccc17 Merge pull request #80187 from hborla/task-macro-improvements
[Macros] Update the name and argument list for the `@Task` function body macro.
2025-03-24 08:46:32 -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
Saleem Abdulrasool
90d9ce76ba Concurrency: handle android similar to Linux
Android should use the dispatch based, Linux platform executor. However,
Android reports as `os(Android)` rather than `os(Linux)`. This adjusts
the condition to ensure that we have a platform executor factory for
Android.
2025-03-21 11:00:08 -07:00
Holly Borla
bac0a10ae2 [Macros] Update the name and argument list for the function body macro
that wraps a function or closure body in a new top-level task.
2025-03-21 06:21:45 -07:00
Alastair Houghton
8443b5f76c Merge pull request #79789 from al45tair/custom-executors
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-21 09:05:03 +00:00
Dario Rexin
35a44e5168 [Concurrency] Fix templated code in Task+startSynchronously.swift (#80100)
* [Concurrency] Fix templated code in Task+startSynchronously.swift

rdar://147348183

The gyb code always dropped the `throws` modifier, no matter which case was being processed.

* Update Task+startSynchronously.swift.gyb

* Fix abi tests
2025-03-20 18:29:31 -07:00
Dave Lee
6ca8e0d502 [Concurrency] Change signposts to use decimal format for task ids (#80154)
Change task ids to be formatted using decimal instead of hex.

An example of previous signposts:

```
task=e resumefn=0x2807722bc jobPriority=0 isChildTask=0, isFuture=1 isGroupChildTask=0 isAsyncLetTask=0 parent=0 group=0x0 asyncLet=0x0
```

this will now show `task=14` instead of `task=e`
2025-03-20 13:23:37 -07:00
Mike Ash
1e265c24d7 Merge pull request #80096 from mikeash/task-group-cancellation-lock-fix
[Concurrency] Fix a race when using cancelAll on a task group concurrently with child tasks being removed.
2025-03-20 11:53:31 -04:00
Alastair Houghton
c20aa667f2 [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
2025-03-19 11:15:00 +00:00
Mike Ash
38c4fce1a8 [Concurrency] Fix a race when using cancelAll on a task group concurrently with child tasks being removed.
_swift_taskGroup_cancelAllChildren relies on there being no concurrent modification when called from the owning task, but this is not guaranteed.

Rearrange things to always take the owning task's status record lock when walking the group's children. Split _swift_taskGroup_cancelAllChildren into two functions, one which assumes/requires the lock is already held, and one which acquires the lock. We don't have the owning task in this case, but we can either get it from the current task, or by looking at the parent of the child task we're working on.

rdar://147172991
2025-03-18 14:52:07 -04:00
Alastair Houghton
0da95eb20d [Concurrency] Fix some warnings, use typed throws.
Fix a couple of `unsafe` warnings.

Also update `withUnsafeExecutorPrivateData` to use typed throws instead of
`rethrow`.

rdar://141348916
2025-03-18 18:37:31 +00:00
Alastair Houghton
fb0396c509 [Concurrency] Fall back to allocating from the heap, fix a test.
`CooperativeExecutor` should fall back to heap allocations if the task
allocator isn't available when it's enqueuing delayed jobs.

Also, remove the reference to `DispatchGlobalExecutor` from the
custom executor test.

rdar://141348916
2025-03-18 17:59:57 +00:00
Alastair Houghton
60fb31cf01 [Concurrency][32-bit] Store timestamp out-of-line on 32-bit.
CooperativeExecutor needs to store its timestamp out-of-line for
32-bit architectures (like WASI).

rdar://141348916
2025-03-18 15:46:51 +00:00
Alastair Houghton
167449f3db [Concurrency] Fix a typo and use var not let.
Fix a typo that caused us to not include the correct code for platforms
that use "singlethreaded" concurrency.

Also use `var` not `let` for the computed property in `PlatformExecutorFactory`.

rdar://141348916
2025-03-18 10:39:41 +00:00
Konrad `ktoso` Malawski
85fcd69833 [Concurrency] Implement detecting isIsolatingCurrentContext user impls (#79946)
* [Concurrency] Detect non-default impls of isIsolatingCurrentContext

* [Concurrency] No need for trailing info about isIsolating... in conformance

* Apply changes from review
2025-03-18 09:39:11 +09:00
Konrad `ktoso` Malawski
85e4685f90 [Concurrency] Adjust task escalation APIs to SE accepted shapes (#79988)
* [Concurrency] Adjust task escalation APIs to SE accepted shapes

* adjust test a little bit

* Fix closure lifetime in withTaskPriorityEscalationHandler

* avoid bringing workaround func into abi by marking AEIC
2025-03-18 07:05:11 +09:00
Alastair Houghton
ad5b76a663 [Concurrency] Another missing availability annotation.
We need to annotate the `timestamp()` function for watchOS (apparently
not for macOS for some reason).

rdar://141348916
2025-03-17 18:48:17 +00:00
Alastair Houghton
ed08858998 [Concurrency] Fix availability.
Fix up availability after the non-Darwin changes.  Also update the
ABI baseline.

Fix a Win32 typo.

rdar://141348916
2025-03-17 16:24:06 +00:00
Alastair Houghton
f0defd83bd [Concurrency] Add CooperativeExecutor, use it.
Also tweak the sleep implementations to let the hooks run if there
isn't a `SchedulableExecutor` (for hooked mode).

rdar://141348916
2025-03-17 13:10:35 +00:00
Michael Gottesman
70bb344db3 [concurrency] Make extension have the same availability as its only containing declaration.
Otherwise in certain cases, we will run into:

1588 | extension GlobalActor {
     | |         `- error: 'GlobalActor' is only available in macOS 10.15 or newer
     | `- note: add @available attribute to enclosing extension
1589 |   @available(SwiftStdlib 6.2, *)
1590 |   @_silgen_name("_swift_task_isCurrentGlobalActor")

rdar://146848568
2025-03-14 13:18:56 -07:00
Alastair Houghton
a4f79f367a [Concurrency][Linux] Fix WASI build.
This doesn't actually add proper WASI support - it just fixes the
build so that we're no worse off than we were.

rdar://141348916
2025-03-14 14:57:15 +00:00
Konrad `ktoso` Malawski
57288d13c9 [Concurrency] task names dont need default nil arg (#80011) 2025-03-14 21:15:01 +09:00
Konrad `ktoso` Malawski
a92f37998e [freestanding] prefer strncpy with known length (#80005) 2025-03-14 04:44:09 -07:00
Alastair Houghton
8caa5c5c0d [Concurrency] Add a missing public.
The default implementation of `traits` on `Clock` needs to be `public`.

rdar://141348916
2025-03-14 10:01:37 +00:00
Doug Gregor
a1132ca169 [Concurrency] Remove unnecessary #ifs that break task-to-thread model
Fixes rdar://146968199
2025-03-13 16:43:19 -07:00
Alastair Houghton
d197f38226 [Concurrency] Make currentExecutor return a non-optional.
If we don't have any other executor to return, return the default
executor.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
00e7ef2d21 [Concurrency] Remove EventableExecutor, alter asSchedulable.
EventableExecutor is being removed, for now, but hopefully will
return in some form in the future.

The `asSchedulable` implementation needs to change for reasons of
ABI stability.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
444bbd5b00 [Concurrency] Update following pitch comments.
Remove `supportsScheduling` in favour of a type-based approach.

Update the storage for `ClockTraits` to `UInt32`.

Adjust ordering of executors for `currentExecutor`.

rdar://141348916
2025-03-13 13:37:43 +00:00