Commit Graph

231 Commits

Author SHA1 Message Date
Rokhini Prabhu
1f466c2312 Merge pull request #70603 from swiftlang/rokhinip/clear-scheduler-private-fields-executor
Clear out the SchedulerPrivate fields before enqueueing the task
2024-06-27 09:52:31 -07:00
Konrad `ktoso` Malawski
a43abe6a90 [Concurrency] Remove OPTNONE workaround for old clang version
This reverts c07aa9c425 which was done to
avoid a crash in optimnized caused by this PR:
https://github.com/apple/swift/pull/41088

Since this was almost 2 years ago, we probably don't have this issue
anymore as far as I can see other resolved issues, so try to remove the
workaround.

Resolves rdar://88711954
2024-06-20 20:03:33 +09:00
Konrad `ktoso` Malawski
083fdaa0de Merge pull request #73998 from nickolas-pohilets/mpokhylets/fix-32-build 2024-06-04 13:49:19 +09:00
Konrad `ktoso` Malawski
0c44645832 [Concurrency] Implement defensive copying in task groups, rather than crashing (#73978) 2024-05-31 11:27:03 -07:00
Mykola Pokhylets
987b641a7c Updated HeaderFooterLayout to correctly handle empty Header or Footer 2024-05-30 21:56:28 +02:00
Mykola Pokhylets
a891b8f0fb Move isDistributedRemoteActor outside #if 2024-05-30 21:55:58 +02:00
Mykola Pokhylets
b5e039d1e0 Fixed 32-bit build with SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION 2024-05-30 13:15:39 +02:00
Mykola Pokhylets
6298d41edf Reapply "Fix quadratic performance of the ListMerger in specific usage pattern"
This reverts commit 2640ff613b.
2024-05-30 13:08:42 +02:00
Konrad `ktoso` Malawski
7c0e1f599a [Concurrency] Fix embedded, cannot refer to runtime/env vars from Actor.cpp 2024-05-28 18:19:55 +09:00
Konrad `ktoso` Malawski
153806b71a [Concurrency] Reshape initial values of executor checking so tests pass on Linux 2024-05-27 17:02:26 +09:00
Konrad `ktoso` Malawski
d36f99540c [Concurrency] Always assume that if expecting main actor and are on main thread that this is equal 2024-05-27 17:02:26 +09:00
Konrad `ktoso` Malawski
7790609fc8 [Concurrency] Futher prevent crashes in legacy mode of isCurrentExecutor 2024-05-27 17:02:26 +09:00
Konrad `ktoso` Malawski
481c928d67 [Concurrency] Fix missing return in legacy isSameExecutor mode detection
resolves rdar://128425368
resolves rdar://127400013
2024-05-27 17:02:25 +09:00
Andrew Trick
2640ff613b Revert "Fix quadratic performance of the ListMerger in specific usage pattern" 2024-05-21 16:23:57 -07:00
Mykola Pokhylets
9ba09ff63d Process incoming queue when obtaining drainer lock 2024-05-10 11:05:22 +02:00
Mykola Pokhylets
40c38f9803 Using multiple insertion points to ensure all jobs are always inserted in O(1)
Fully separated unprocessed jobs and processed jobs
Reverse jobs after updating status to minimise contention
2024-05-10 11:05:22 +02:00
Mykola Pokhylets
21a70e10c7 Fixed quadratic performance of ListMerger when each executed job creates 2+ new jobs of the same priority
See https://forums.swift.org/t/quadratic-performance-of-the-listmerger-in-specific-use-case/69393
2024-05-10 11:05:22 +02:00
Konrad `ktoso` Malawski
b2bd17635f [Concurrency] Fix too eager early return in checkIsolation mode detecting (#73495) 2024-05-09 03:12:37 -07:00
Konrad `ktoso` Malawski
86f5441294 [SerialExecutor] SerialExecutor.checkIsolated() to check its own tracking for isolation checks (#71172) 2024-03-29 07:06:34 +09:00
John McCall
b0cee67d04 Properly save and restore the current task in the runtime so that tasks
can be reentrantly executed.

I don't think doing this is *actually a good idea*, but corrupting the
runtime is an even worse idea, and the overhead here is very low.
2024-03-15 00:40:54 -04:00
Pavel Yaskevich
87878461a5 [stdlib] Make expected actor isolation checking crash by default
Only affects projects compiled with `-enable-actor-data-race-checks` flag.
2024-02-02 23:53:18 -08:00
Konrad `ktoso` Malawski
bd19d937f0 [TaskExecutor] Remove underscore from new APIs (#71145) 2024-01-30 06:27:54 +09:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
Rokhini Prabhu
61bec0d786 Always clear out the SchedulerPrivate fields before enqueueing the task
into the executor
2023-12-21 19:22:05 -08:00
Rokhini Prabhu
ed8ed32dba Clean up Concurrency build system so that all the logic around choice of
which executor for which type of setting, is consolidated and we have a
single knob we use to determine when to use dispatch as our global
executor.

Radar-Id: rdar://problem/119416196
2023-12-13 16:09:51 -08:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Konrad `ktoso` Malawski
5546f4da7b Rename ExecutorRef to SerialExecutorRef 2023-11-01 18:39:44 +09:00
Kuba Mracek
5d8c55eacb [embedded] Initial Swift Concurrency for embedded Swift 2023-10-06 20:04:03 -07:00
Allan Shortlidge
b4f3a9fb06 NFC: Address warnings about unused functions. 2023-09-07 18:09:19 -07:00
Mike Ash
9f9929a1d0 [Concurrency] Fix crash when actor is dynamically subclassed.
Dynamic subclasses have a NULL type descriptor. Make sure isDefaultActorClass doesn't try to dereference that NULL descriptor.

rdar://112223265
2023-08-02 19:05:10 -04:00
Doug Gregor
3f0d61cc5d [Concurrency runtime] Don't read from the actor after transitioning state
Once we have transitioned the actor into a new state, we report the
state change as a trace event so it can be noted by tools (e.g.,
Instruments). However, the act of transitioning to a new state can mean
that there is an opportunity for another thread to deallocate the
actor. This means that the tracing call cannot depend on dereferencing
the actor pointer.

A refactoring a few months ago to move the bit that indicates when a
distributed actor is remote from inside the atomic actor state out to a
separate field (because it's constant for a given actor instance),
which introduced a dereference of the actor instance in forming the
tracing call. This introduced a narrow window in which a race
condition could occur: the actor transitions to an idle state, and is
then deallocate before the trace event for the actor transition occurs,
leading to a use-after-free.

Fetch this bit of information earlier in the process, before any state
changes and when we know the actor is still allocated, and pass it
through to the tracing code.

Fixes rdar://108497870.
2023-05-18 15:57:27 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
Konrad `ktoso` Malawski
e0877594da [Concurrency] Custom executors with move-only Job (#63569) 2023-03-18 14:02:43 +09:00
Konrad `ktoso` Malawski
5d2a311dda [Executors] assumeOnLocalDistributedActorExecutor (isolated Act) -> 2023-03-16 13:23:47 +09:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Kavon Farvardin
c100fe01bc guard use of enqueueStealer when using actors-as-locks
skip escalation in this case.
2023-03-08 14:55:36 -08:00
Rokhini Prabhu
0bb5a89d56 Fixup isEnqueued call on actor state which really is isScheduled
Radar-Id: rdar://problem/101864092
2023-03-03 11:44:56 -08:00
Rokhini Prabhu
9b6c873239 Escalate an actor if a job in the queue of the actor has been escalated.
Radar-Id: rdar://problem/101864092
2023-02-28 13:52:26 -08:00
Rokhini Prabhu
4515654a62 Remove redundant call to swift_dispatch_lock_override_end() since that
is only needed for acknowledging asynchronous overrides from other
threads, onto the thread itself. It is not needed for self-overrides.

Radar-Id: rdar://problem/101864092
2023-02-28 13:51:46 -08:00
Rokhini Prabhu
d63ce1372c Change memory barriers in actor runtime so that we have acquire upon
lock() and release on unlock() and use consume when are relying on
address dependency HW load ordering. Adjust tsan annotations to match.

Radar-Id: rdar://problem/101864092
2023-02-28 13:51:46 -08:00
Rokhini Prabhu
534811c3dc When a task gets enqueued on an executor, start tracking which executor
it is enqueued on. This way, we have the necessary bookkeeping to
escalate an executor when a task that is enqueued, is escalated.

Radar-Id: rdar://problem/101864092
2023-02-25 17:01:03 -08:00
Rokhini Prabhu
17b1ada520 Add extra comments around memory barriers in Actor runtime atomics logic
Radar-Id: rdar://problem/88093007
2023-01-18 10:43:07 -08:00
Kuba (Brecka) Mracek
e9d1d3096a Stop using SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY under SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY (#62735)
Using single-threaded concurrency was a temporary solution, now that the task-to-thread model actually supports multiple threads, let's switch off of it. Instead, let's introduce a "global executor none" option (implicitly set under the task-to-thread model) to denote that the concurrency model is not using a global executor.

rdar://99448771
2023-01-03 15:24:57 -08:00
Rokhini Prabhu
28493d01be Merge pull request #62716 from apple/eng/PR-103426321-mutex-initialization
[Task-to-Thread] Make sure to explicitly initialize the drainLock in DefaultActorImpl::initialize
2022-12-21 09:15:55 -08:00
Rokhini Prabhu
1ba0462c27 [Task-to-Thread] Make sure to explicitly initialize the drainLock in
DefaultActorImpl::initialize or we could end up waiting on a garbage
lock value

Radar-Id: rdar://problem/103426321
2022-12-20 16:47:48 -08:00
Priya Avhad
d792c07fdc Stealer support for actor runtime. 2022-12-07 21:04:45 +05:30
Erik Eckstein
525550644c concurrency runtime: fix unused variable/label warnings 2022-11-21 19:50:39 +01:00
Rokhini Prabhu
b2f51dd3de Implement continuations in task-to-thread model.
This is done using a condition variable upon which the awaiting thread
will block if the continuation has not be resumed by the point of await.
The resuming thread will signal this condition variable, thereby
unblocking the awaiting thread.

Rdar://99977665
2022-11-09 15:58:53 -08:00
Rokhini Prabhu
ab16a647d8 [Freestanding] In a task-to-thread model where we don't have the means
to create extra threads to process jobs, actors should really behave
like locks.
2022-09-14 18:33:54 -07:00
Rokhini Prabhu
4c0f88bdee Move isDistributedRemote out of ActiveActorStatus since it does not need
to be modified in the atomic - it is set once and never changed again
2022-09-13 13:15:26 -07:00