Commit Graph

1607 Commits

Author SHA1 Message Date
Alastair Houghton
4f7be0814a [Concurrency] Update availability of UnimplementedExecutor.
We need it to be `StdlibDeploymentTarget 6.2` rather than
`SwiftStdlib 6.2`, so that we can update the availability definitions.

rdar://156710569
2025-07-25 15:45:46 -04:00
Yuta Saito
0a5a694b46 Merge pull request #83120 from kateinoigakukun/yt/cherry-pick-6.2-gh83086
[6.2][Concurrency] Fix runtime isolated-conformance checks with static stdlib
2025-07-17 22:00:15 +09:00
Konrad `ktoso` Malawski
8e4d9a3c8a [6.2][Concurrency] Remove symbols of startSynchronously, make it AEIC (#83089)
Co-authored-by: Pavel Yaskevich <pyaskevich@apple.com>
2025-07-17 00:44:36 -07:00
Yuta Saito
e6453a34a0 [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 23:50:31 +00:00
Alastair Houghton
eefdd69c8d Merge pull request #82915 from al45tair/eng/PR-151147606-take2
[Concurrency] Remove custom global executors from 6.2.
2025-07-14 16:20:57 +01:00
Konrad `ktoso` Malawski
9ac4ebc603 Merge pull request #82984 from ktoso/pick-task-group-docs 2025-07-12 05:01:37 +09:00
Alex Martini
12b998e4bc Revise doc comment for style & clarity
- Move the definition of 'structured concurrency' to the beginning of
  the section.
- Avoid future tense.  Fix some mixed future+present tense errors.
- Write bullet points as individual sentences, not as the clauses of one
  long sentence.
- Apple Style: Use 'since' only in the sense of 'after'.
- Apple Style: Use 'you' instead of 'one'.
- Apple Style: Close up 'non-' except when ambiguous.
- DevPubs style: Avoid bare 'this' for clarity.  Here, 'this guarantee'
  tells the reader what 'this' refers to.
- DevPubs style: Avoid 'may' which can be ambiguous between possibility
  and permission.
2025-07-11 12:00:54 +09:00
Alex Martini
430f49b98b Fix more 'cancel(l)ed' style issues 2025-07-11 11:45:25 +09:00
Alex Martini
929a167eda Remove stray spaces
These looks like the side effect of a find-and-replace for PR 82558
fixing 'cancelled' vs 'canceled'.
2025-07-11 11:45:22 +09:00
Konrad `ktoso` Malawski
7a6527af83 Merge pull request #82558 from ktoso/wip-cleanup-group-docs 2025-07-11 11:45:15 +09:00
Changhyun Kang
1416a74f11 [Concurrency] fix documentation typos in TaskGroup.swift (#82291) 2025-07-11 11:44:52 +09:00
Konrad 'ktoso' Malawski
fba13f8eda [Concurrency] Add missing Task.immediateDetached, which drops task locals 2025-07-11 08:45:08 +09:00
Konrad 'ktoso' Malawski
6f3099b564 [Concurrency] a few missing overloads for immediate tasks 2025-07-11 08:45:03 +09:00
Alastair Houghton
bd289dc548 [Concurrency] Remove custom global executors from 6.2.
The custom global executors work is not landing in 6.2, so make
sure it isn't public there.

rdar://151147606
2025-07-09 15:45:15 +01:00
Pavel Yaskevich
67c787dd1f Revert "[6.2][Concurrency] Remove deprecated Task.startSynchronously API" 2025-07-08 11:35:31 -07:00
Pavel Yaskevich
aa89147743 [Concurrency] Remove deprecated Task.startSynchronously API
This is the original spelling which was not accepted. We kept
it for a bit to give adopters time to switch but it's time to
remove it now.

(cherry picked from commit e108524d98)
2025-07-07 16:47:56 -07:00
Alastair Houghton
8eb879831c Merge pull request #81940 from al45tair/eng/PR-152498657
Rename SwiftStdlibCurrentOS to StdlibDeploymentTarget.
2025-07-07 12:04:38 +01:00
Alastair Houghton
0813e95569 Merge pull request #81440 from al45tair/currentos-availability
[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
2025-07-07 12:04:00 +01:00
Alastair Houghton
2323449a00 Merge pull request #82526 from al45tair/eng/PR-153531418-6.2
[Concurrency] Rename Dummy(Main|Task)Executor.
2025-07-03 15:07:34 +01:00
Alastair Houghton
c56ec77fdb Merge pull request #82564 from al45tair/eng/PR-154346018-6.2
[Concurrency] Prevent negative sleeps from sleeping forever.
2025-07-02 14:31:51 +01:00
Doug Gregor
7d10f95f6a Merge pull request #82662 from DougGregor/back-deploy-main-actor-isolated-deinit-6.2
[6.2] [SE-0371] Back-deploy support for main-actor-isolated deinit
2025-07-02 00:13:47 -07:00
Doug Gregor
a74e7e014a Don't implement swift_task_deinitOnExecutorMainActorBackDeploy in the task-to-thread model 2025-07-01 16:06:25 -07:00
Doug Gregor
42e1610607 Switch to the appropriate C calling convention for pthread_main_np 2025-07-01 08:15:04 -07:00
Konrad `ktoso` Malawski
8f9c14f4cb Merge pull request #82621 from ktoso/pick-deprecate-extractisolation 2025-07-01 15:20:09 +09:00
Konrad `ktoso` Malawski
0eb6263b6d [6.2][Concurrency] Remove experimental @Task macro (#82622) 2025-06-30 23:02:12 -07:00
Doug Gregor
dc27da053c [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:40:00 -07:00
Konrad 'ktoso' Malawski
b7ec436184 [Concurrency] Deprecate extractIsolation 2025-06-30 20:33:27 +09:00
Alastair Houghton
c9606ba668 [Concurrency] Prevent negative sleeps from sleeping forever.
Requests to sleep until a negative timestamp would result in sleeping
until `UINT64_MAX` nanoseconds from the start of the relevant clock,
which is about 585 years.

rdar://154346018
2025-06-27 11:13:57 +01:00
Alastair Houghton
0dde6a561d [Concurrency] Rename Dummy(Main|Task)Executor.
`UnimplementedExecutor` seems like a better name.

rdar://153531418
2025-06-26 10:55:00 +01:00
Konrad 'ktoso' Malawski
c81a7aa1a0 [Concurrency] Task.immediate returning Never error must not have throwing operation
rdar://153855920
2025-06-20 09:55:57 +09:00
Mike Ash
fbda570183 [6.2][Runtime] Remove redundant swift_auth_code_function, use existing swift_auth_code.
rdar://153169049
(cherry picked from commit ec6a042831)
2025-06-13 18:50:37 -04:00
Alastair Houghton
b3cbdf84ed [Concurrency] Fix null pointer dereference for task-to-thread model.
In task-to-thread concurrency mode, `_getMainExecutorAsSerialExecutor`
returns `SerialExecutorRef::generic()`, which is, give or take, NULL.
Unfortunately we'd declared it as returning `any SerialExecutor`,
rather than `(any SerialExecutor)?`, and then the `getMainExecutor()`
function was calling `asUnownedSerialExecutor()` on it, which then
crashes.

rdar://153152063
2025-06-12 11:53:35 +01:00
Alastair Houghton
9bf75384d0 Merge pull request #82182 from al45tair/eng/PR-150531873-6.2
[Concurrency] Remove deprecation attribute for now.
2025-06-12 09:37:14 +01:00
Alastair Houghton
008df00262 [Concurrency] Remove deprecation attribute for now.
This deprecation attribute is possibly a little premature.

rdar://150531873
2025-06-11 15:09:55 +01:00
Konrad 'ktoso' Malawski
b690384baf [Concurrency] Correct memory effect attributes of task_create
Without this, llvm would sometimes wrongly assume there's no indirect
accesses and the optimizations can lead to a runtime crash, by
optimizing away initializing options properly.

Resolves rdar://152548190
2025-06-11 22:05:17 +09:00
Konrad 'ktoso' Malawski
11fb1ad419 [Concurrency] Prefer swift_auth_code_function over swift_auth_code
This allows us to use constants, and not hardcoded numbers
2025-06-03 07:02:48 +09:00
Konrad 'ktoso' Malawski
e18f553eab Correct priority cancellation handler signing once more
Resolves rdar://150378890 for real this time, verified on arm64e myself
2025-06-02 21:40:18 +09:00
Mike Ash
90b232caa4 Merge pull request #81815 from mikeash/taskgroup-fixes-6.2
[6.2][Concurrency] Fix races/overflows in TaskGroup implementation.
2025-05-29 05:16:58 -04:00
Konrad `ktoso` Malawski
5baa624085 Merge pull request #81820 from ktoso/pick-abi-fix-startSynchronously
[6.2][Concurrent] Restored old symbol for obsoleted `Task.startSynchronously`
2025-05-29 16:19:38 +09:00
Mike Ash
b42c7fa172 [6.2][Concurrency] Fix races/overflows in TaskGroup implementation.
statusCompletePendingReadyWaiting(), offer(), and poll() did a one-off compare_exchange_strong which could fail if the group was concurrently cancelled. Put these into loops so that they are retried when needed.

DiscardingTaskGroup creation passed the group result type as the task result type. waitAll() would then use the group result type when collecting task results. Since the task result type is always Void in this case, this would overflow the result buffer if the group result type was larger. This often works as it writes into the free space of the task allocator, but can crash if it happens to be at the end of a page or the group result type is particularly large.

rdar://151663730
(cherry picked from commit 5be22fa7cc)
2025-05-28 20:59:17 -04:00
Konrad `ktoso` Malawski
c8a8183d26 [6.2][Concurrency][SE-review update] Task names update (#81132)
**Description**: This adds "task name" parameter to all task creating
functions.

This is done in a few ways, e.g. we can backdeploy this to 5.1 in APIs
which do not accept the `TaskExecutor` but it they do we provide a
version for 6.0+ etc. This was requested in the SE acceptable of this
proposal [Acceptance post
SE-0469](https://forums.swift.org/t/accepted-with-modifications-se-0469-task-naming/79438).

This moves all these declarations to gyb since going through them one by
one has become unmaintainable otherwise.

**Scope/Impact**: All task creation APIs now gain a new task name
parameter.
**Risk:** Medium, changes existing APIs rather than adding "even more
overloads" though this risk was discussed in the team and accepted. This
has a potential to be source breaking it someone used Task.init and
friends as function.
**Testing**: CI testing, source compatibility suite testing
**Reviewed by**: 

**Original PR:** 
- https://github.com/swiftlang/swift/pull/81107 build changes required
for this
- https://github.com/swiftlang/swift/pull/80984


**Radar:**

---------

Co-authored-by: Kuba Mracek <mracek@apple.com>
2025-05-29 07:52:33 +09:00
Pavel Yaskevich
f404274e6d [Concurrent] Restored old symbol for obsoleted Task.startSynchronously
https://github.com/swiftlang/swift/pull/80821 added `@isolated(any)`
which is an ABI breaking change but since we are not planning to keep
this API around, let's use `@_silgen_name` to bring the old name back
for now.

Resolves: rdar://152178221
2025-05-29 06:48:31 +09:00
Konrad 'ktoso' Malawski
fa817f951d [Concurrency] Correct the signing of priority escalation handler 2025-05-23 17:06:12 -07:00
Pavel Yaskevich
5997a4dec4 [stdlib] Adopt @_inheritActorContext(always) on Task.immediate
This change aligns implementation with the current SE-0472 proposal.

(cherry picked from commit c3c1b4fca0)
(cherry picked from commit 8c05636e28)
(cherry picked from commit 0598b8c9f4)
2025-05-22 11:32:37 -07:00
Allan Shortlidge
63adabb7ef Concurrency: Address new -strict-memory-safety warnings. 2025-05-19 09:24:13 -07:00
Pavel Yaskevich
b2e962068d [stdlib] Temporarily bring back Task.startSynchronously as deprecated
(cherry picked from commit 99d810aa7d)
2025-05-13 20:11:28 -07:00
Pavel Yaskevich
2bf00077e4 [stdlib] SE-0472: Rename Task and*TaskGroup APIs to match the proposal
`Task.startSynchronously` -> `Task.immediate`
`*TaskGroup.startTaskSynchronously{UnlessCancelled}` -> `*TaskGroup.addImmediateTask{UnlessCancelled}`

(cherry picked from commit 001eab867d)
2025-05-13 20:11:28 -07:00
Konrad 'ktoso' Malawski
910bc1a1a3 [Concurrency] Improve in order synchronous enqueue of startSynchronously
Previously there was still a sneaky hop which caused ordering issues.
This introduced a specific test startSynchronously_order which checks
that the task enqueues indeed are "immediate" and cleans up how we
handle this.

This also prepares for the being discussed in SE review direction of
this API that it SHOULD be ALLOWED to actually hop and NOT be
synchronous at all IF the isolation is specified on the closure and is
DIFFERENT than the callers dynamic isolation.

This effectively implements "synchronously run right now if dynamically
on the exact isolation as requested by the closure; otherwise enqueue
the task as usual".

resolves rdar://149284186
cc @drexin

(cherry picked from commit a24a28c217)
2025-05-13 20:10:35 -07:00
Alastair Houghton
02c160cdac Merge pull request #81335 from al45tair/eng/PR-148899609-6.2
[Concurrency] Don't pass negative times to the Dispatch code.
2025-05-13 11:29:35 +01:00
Alastair Houghton
d6ce27b0e6 Merge pull request #81326 from al45tair/eng/PR-150753884
[Concurrency] Make initial executor construction fully thread safe.
2025-05-12 11:56:45 +01:00