Commit Graph

1601 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
31b6ae2fcf Merge pull request #80984 from ktoso/task-names-update
[Concurrency][SE-review update] Task names update
2025-05-28 06:23:49 +09:00
Konrad 'ktoso' Malawski
97a4904c1f [Concurrency] Correct the signing of priority escalation handler 2025-05-23 17:02:19 -07:00
Alastair Houghton
3305e89ff9 Merge pull request #81639 from swiftlang/revert-81472-eng/PR-151147606
Revert "[Concurrency] Add underscore prefixes for not yet official API."
2025-05-22 15:36:52 +01:00
Pavel Yaskevich
a64984af45 Merge pull request #81572 from xedin/adopt-inheritActorContextAlways-in-Task-APIs
[stdlib] Adopt `@_inheritActorContext(always)` on `Task.immediate`
2025-05-20 09:05:35 -07:00
Alastair Houghton
28732f4a8b Revert "[Concurrency] Add underscore prefixes for not yet official API." 2025-05-20 15:44:26 +01:00
Pavel Yaskevich
0598b8c9f4 [stdlib] Task.immediate annotate operation parameter with @_implicitSelfCapture
Since the "operation" inherits the context of the actor it should
also be possible to reference its members without explicit use of
`self.`.
2025-05-19 18:01:23 -07:00
Pavel Yaskevich
8c05636e28 [stdlib] Concurrency: Add @_alwaysEmitIntoClient to add Task.*immediate* 2025-05-19 18:01:07 -07:00
Allan Shortlidge
a85caaf296 Concurrency: Address new -strict-memory-safety warnings. 2025-05-18 10:37:19 -07:00
Pavel Yaskevich
c3c1b4fca0 [stdlib] Adopt @_inheritActorContext(always) on Task.immediate
This change aligns implementation with the current SE-0472 proposal.
2025-05-16 14:27:46 -07:00
Alastair Houghton
7f97e8d10b Merge pull request #81472 from al45tair/eng/PR-151147606
[Concurrency] Add underscore prefixes for not yet official API.
2025-05-15 18:39:21 +01:00
Alastair Houghton
c0ccdffeb7 [Concurrency] Add underscore prefixes for not yet official API.
Custom main and global executors work hasn't passed Swift Evolution yet,
so we need to avoid leaking it as API until it does.

To that end, underscore all the things.

rdar://151147606
2025-05-14 11:57:06 +01:00
Saleem Abdulrasool
cab1f40218 Concurrency: silence warning on Windows
Prefer `strncpy_s` over `strncpy` which triggers a warning. This
function ensures that the copied string is null-terminated if the string
fits or simply returns an empty string (`\0`) if the string does not
fit. Prefer to use `_TRUNCATE` to copy as much of the name as fits and
ensure that it is null-terminated.
2025-05-13 09:48:33 -07:00
Alastair Houghton
485b8f6888 Merge pull request #81446 from al45tair/eng/PR-150531873
[Concurrency] Remove deprecation attribute for now.
2025-05-12 20:02:03 +01:00
Alastair Houghton
c6d1969afc [Concurrency] Remove deprecation attribute for now.
This deprecation attribute is possibly a little premature.

rdar://150531873
2025-05-12 15:35:45 +01:00
Pavel Yaskevich
99d810aa7d [stdlib] Temporarily bring back Task.startSynchronously as deprecated 2025-05-09 23:59:36 -07:00
Pavel Yaskevich
001eab867d [stdlib] SE-0472: Rename Task and*TaskGroup APIs to match the proposal
`Task.startSynchronously` -> `Task.immediate`
`*TaskGroup.startTaskSynchronously{UnlessCancelled}` -> `*TaskGroup.addImmediateTask{UnlessCancelled}`
2025-05-09 23:59:30 -07:00
Alastair Houghton
921d6d8d2c Merge pull request #81332 from al45tair/eng/PR-148899609
[Concurrency] Don't pass negative times to the Dispatch code.
2025-05-07 09:46:26 +01:00
Michael Gottesman
b34e2d72fb Merge pull request #81306 from gottesmm/pr-b6ba1a771d90007a5ee6da3e4dc657bfef32b320
[swift-settings] Now that we aren't using it immediately, remove it from tree.
2025-05-06 08:21:23 -07:00
Alastair Houghton
69c965e15c [Concurrency] Don't pass negative times to the Dispatch code.
Dispatch uses unsigned times, and cannot cope with times before its
clock started.  As such, passing negative times from Swift through to
the C++ code results in large unsigned values, which then causes us to
wait forever.  This is undesirable.

rdar://148899609
2025-05-06 15:56:07 +01:00
Michael Gottesman
9d59dbed17 [swift-settings] Now that we aren't using it immediately, remove it from tree.
We can always get it back from the git history.

rdar://150695113
2025-05-05 13:39:03 -07:00
Doug Gregor
f358c1e6b7 Revert "[Concurrency] Hashable funcs should be inlinable for AsyncStream"
This reverts commit 06bb7183f4.
2025-05-05 10:43:11 -07:00
Philippe Hausler
c4088252d0 [Concurrency] An implementation of system epochs for continuous and suspending clocks (#80409)
This implements
[SE-0473](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0473-clock-epochs.md)
2025-05-05 08:45:24 -07:00
Evan Wilde
91a0692bd1 Merge pull request #81227 from etcwilde/ewilde/FreeBSDPlatformExecutor
Add platform executor module for FreeBSD
2025-05-04 13:07:32 -07:00
Alastair Houghton
3b89d6d137 Merge pull request #81195 from al45tair/eng/PR-150290165
[Concurrency] Fix copy-paste error.
2025-05-04 18:33:50 +01:00
Doug Gregor
3a01fc18b4 Make the _Concurrency library depend on _Builtin_float 2025-05-01 22:01:38 -07:00
Mike Ash
a1dbdd59d1 [Concurrency] Remove useless comment about assert in AsyncTask::complete().
This comment is really about an assert that's no longer present, so it should just go away.
2025-05-01 11:22:39 -04: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
62c6159027 Merge pull request #81229 from ktoso/wip-escalation-handler-priority-auth
[Concurrency] Fix ptr auth for task priority escalation handler
2025-05-01 19:53:54 +09: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
Evan Wilde
4a41e50730 Add platform executor module for FreeBSD
Effectively the same as Linux and OpenBSD. If Dispatch is disabled, this
will fail because the dispatch executor isn't defined.
2025-04-30 17:08:53 -07:00
Mike Ash
325b66ab20 [Concurrency] Fix alreadyLocked in withStatusRecordLock.
If the preloaded status is locked, then we need to reload it in order to distinguish between the current thread holding the lock and another thread holding the lock. Without this, if another thread holds the lock, then we won't set the is-locked bit. We'll still actually hold the lock, but other threads may perform operations locklessly if the bit is not set, which can cause a crash. By reloading status in that case, we ensure that the bit is always set correctly.

This manifested as crashes in task cancellation but could cause other task-related issues as well.

Also remove an assert of !isStatusRecordLocked() in AsyncTask::complete(). We allow other threads to access tasks and take the lock for things like cancellation, so the lock may legitimately be held at that point.

rdar://150327908
2025-04-30 13:53:31 -04: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
Alastair Houghton
0a5fa056e7 [Concurrency] Fix copy-paste error.
The `__builtin_add_overflow` should have been adding to `leeway`, not to
`deadline`.

rdar://150290165
2025-04-30 10:14:22 +01:00
Konrad 'ktoso' Malawski
6872707574 [embedded][Concurrency] Further refine C-api boundary for isIsolating... 2025-04-29 22:29:26 +09:00
Konrad 'ktoso' Malawski
ea16df04ac [Concurrency] adjust how we fail creating an IsIsolatingCurrentContextDecision 2025-04-29 20:08:56 +09:00
Konrad 'ktoso' Malawski
e1dc854f8f [Concurrency] Change isIsolatingCurrent... to return Bool?
This changes the isIsolatingCurrentContext function to return `Bool?`
and removes all the witness table trickery we did previously to detect
if it was implemented or not. This comes at a cost of trying to invoke
it always, before `checkIsolated`, but it makes for an simpler
implementation and more checkable even by third party Swift code which
may want to ask this question.

Along with the `withSerialExecutor` function, this now enables us to
check the isolation at runtime when we have an `any Actor` e.g. from
`#isolation`.

Updates SE-0471 according to
https://forums.swift.org/t/se-0471-improved-custom-serialexecutor-isolation-checking-for-concurrency-runtime/78834/
review discussions
2025-04-29 20:08:55 +09:00
Konrad 'ktoso' Malawski
06bb7183f4 [Concurrency] Hashable funcs should be inlinable for AsyncStream 2025-04-28 16:17:10 +09:00
Evan Wilde
1bff8cda36 Merge pull request #80877 from 3405691582/platform_executor
Add a platform executor module for OpenBSD.
2025-04-27 17:44:10 -07:00
Kuba (Brecka) Mracek
642a6ca7e6 Merge pull request #81107 from kubamracek/embedded-conc-arch-cmake
[embedded] Make the CMake setup for Embedded Concurrency distinguish ARCH and SUBDIR for builds products
2025-04-26 15:51:42 -07:00
Kuba Mracek
c5aa98a449 [embedded] Make the CMake setup for Embedded Concurrency distnguish ARCH and SUBDIR for builds products 2025-04-26 07:03:19 -07:00
Doug Gregor
050a514588 [Strict memory safety] Update standard library for unsafe treated as a call effect 2025-04-25 21:54:23 -07:00
3405691582
db942def27 Add a platform executor module for OpenBSD.
This is basically the same as the one for Linux, but it would be
somewhat awkward to add the platform conditional on a file named for
Linux when OpenBSD is not Linux.

Important note: if Dispatch is disabled, then this will cause a
compilation error (probably not just for OpenBSD either), because
PlatformExecutorFactory is both defined in PlatformExecutorNone.swift
and PlatformExecutor<...>.swift in this case.

Because this only bites OpenBSD bootstrap builds, and since OpenBSD
support has been upstreamed to Dispatch, default to the Dispatch
implementation for now to get this in, and we'll refactor in a different
pr.
2025-04-25 14:05:58 -04:00
Konrad 'ktoso' Malawski
7112f7ea56 [Concurrency] Support ~Copyable in withSerialExecutor 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
fcbd7dbc0d [Concurrency] Support ~Copyable return type in withSerialExeutor 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
84764de38c [Concurrency] Fix code completion test given new actor method 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
20fe3b0dea [Concurrency] Offer way to get SerialExecutor from Actor 2025-04-25 18:40:23 +09:00
Kuba (Brecka) Mracek
685572ed49 Merge pull request #80977 from kubamracek/embedded-concurrency-function-sections
[embedded][Concurrency] Build C++ runtime Concurrency code with -ffunction-sections and more embedded friendly flags
2025-04-23 07:11:17 -07:00
Kuba Mracek
04df4ad12e [embedded][Concurrency] Also apply non-Darwin flags in Concurrency C++ runtime builds when targeting armv7m/armv7em 2025-04-22 15:51:15 -07:00
Alastair Houghton
77eb4f05ec Merge pull request #80896 from al45tair/eng/PR-149346132
[Concurrency] Make initial executor construction fully thread safe.
2025-04-22 16:25:26 +01:00
Kuba Mracek
71ed50c360 [embedded][Concurrency] Build C++ runtime Concurrency code with -ffunction-sections and more embedded friendly flags 2025-04-21 18:21:12 -07:00