Commit Graph

1607 Commits

Author SHA1 Message Date
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
Kuba Mracek
7e00fe4b36 [embedded] Use hasFeature(Embedded) instead of in TaskGroup.swift+DiscardingTaskGroup.swift 2024-10-01 15:00:53 -07:00
Kuba Mracek
a2dcb6045c [embedded] Introduce a new swift_taskGroup_initializeWithOptions runtime entrypoint 2024-10-01 14:56:38 -07:00
Alastair Houghton
cf77aa37df [Concurrency] Fix macOS build issue.
We need to use the `swift` namespace in `NonDispatchGlobalExecutor.cpp`.

rdar://135380149
2024-10-01 14:02:52 +01:00
Kuba Mracek
9b56ea03d2 [Concurrency] Drop the cloned code for Embedded around 'any actor' 2024-09-30 10:30:09 -07:00
Alastair Houghton
e6882f243f [Concurrency] Fix Linux/Windows build issues.
Define `NOMINMAX` and `WIN32_LEAN_AND_MEAN` when including `<Windows.h>`.

Don't export the interface from DLLs.

Make sure we include `<new>` when using placement operator new.

rdar://135380149
2024-09-30 17:18:09 +01:00
Alastair Houghton
837513dc16 [Concurrency] Fix test failures, add struct layout checks.
We were missing a field in `SwiftJob`, which broke various things.  To
avoid that problem in future, this PR adds a set of static asserts to
check the layout of various structures and that we're using the same
values as well.

Also added some functions to the ABI, and fixed things so that if you
enable the debug logging the library still builds (there was an extra
`_` in `Actor.cpp` that caused a build failure).

Finally, renamed `Hooks.cpp` to `ConcurrencyHooks.cpp`.

rdar://135380149
2024-09-30 17:16:33 +01:00
Alastair Houghton
31df4edb7c [Concurrency] Add a test for the new custom executor feature.
Added an executor implementation and a test that tries to use it.
Also fix up a few issues in `ExecutorImpl.h`.

rdar://135380149
2024-09-30 17:15:40 +01:00
Alastair Houghton
4ef4305f13 [Concurrency] Install ExecutorImpl.h in include/swift in toolchain.
When Embedded Concurrency is enabled, install `ExecutorImpl.h` in the
`include/swift` directory in the toolchain.

rdar://135380149
2024-09-30 17:15:40 +01:00
Alastair Houghton
26b5fa697a [Concurrency] Rename ExecutorHooks.h, tidy up the interface.
`ExecutorHooks.h` is now nothing to do with hooks, so rename it.  Also
there are some additional functions it should declare, and a couple of
places where we've slightly messed up the boundary, for instance
`swift_task_asyncMainDrainQueue` was defined in `Task.cpp` rather than
in the executor implementations, which is wrong, so fix that too.

`CooperativeGlobalExecutor.cpp` now builds against the interface from
`ExecutorImpl.h`, rather than including the all the concurrency headers.

rdar://135380149
2024-09-30 17:15:40 +01:00
Alastair Houghton
efe5d660f2 [Concurrency] Refactor executors so they are in their own object module.
C++ executor implementations were `#include`ed into `GlobalExecutor.cpp`,
which makes it difficult to replace the global executor when using the
Embedded Concurrency library.  Refactor things so that they build into
separate objects, which means replacing them is just a matter of writing
the relevant functions yourself.

rdar://135380149
2024-09-30 17:15:38 +01:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
Mykola Pokhylets
aeb71c4cb4 Disable retain count checks in actor deinit for embedded runtime 2024-09-30 03:41:40 +01:00
Kuba Mracek
f1c2334c9a [Concurrency] Enable TaskGroup/DiscardingTaskGroup in Embedded Swift 2024-09-28 17:52:05 -07:00
Mike Ash
efa62e7c33 [Concurrency] Fix crash from calling fromTaskExecutorPreference after enqueueing job.
After we've enqueued a job, another thread may run it and destroy it. Don't try to get the job's task executor preference when we try to schedule it. Instead, get the task executor preference before enqueueing the job, then use that preference when scheduling if necessary. Since getting the executor preference is potentially somewhat expensive (we need to search the status records for an executor preference record), only do this if the pre-compare-and-swap states look like they'll need it.

rdar://136281920
2024-09-27 17:32:29 -04:00
Konrad `ktoso` Malawski
d89347bed0 Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-20 18:34:45 +09:00
Konrad `ktoso` Malawski
b3c5bc47fe Merge pull request #76560 from amartini51/task_docs_style 2024-09-20 15:06:12 +09:00
Alex Martini
44ecc6325f Revise for documentation style
- Use the spelling "canceled" per Apple Style Guide
- Use code voice for symbol name
- Use contractions
- Avoid parenthesis for asides
- Change "it" to "that function" to reduce ambiguity
2024-09-18 15:42:14 -07:00
Alastair Houghton
0963036734 [Build] Make sure we declare LINUX_STATIC dependencies on Musl.
Everywhere there's a `SWIFT_MODULE_DEPENDS_LINUX Glibc`, there should be
a corresponding `SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl`.

This usually won't bite us, depending on build order and parallelism, but
I hit one of these yesterday so went looking to see if there were any
others.

rdar://136208589
2024-09-18 09:40:58 +01:00
Konrad `ktoso` Malawski
57bf319577 Update Task.swift 2024-09-18 09:38:02 +09:00
Konrad `ktoso` Malawski
6c8d0c9e1b Apply suggestions from code review
Co-authored-by: Alex Martini <amartini@apple.com>
2024-09-18 09:29:04 +09:00
Konrad `ktoso` Malawski
5e29d51674 Apply suggestions from code review
Co-authored-by: Alex Martini <amartini@apple.com>
2024-09-18 09:13:18 +09:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Konrad `ktoso` Malawski
6d37240ef2 Update Task.cancel() with more details
Add more details into cancel() docs, some developers were worried if they are allowed to call it concurrently and multiple times etc.
2024-09-17 09:38:43 +09:00
Mike Ash
bc6c027a1f [Concurrency] Add a debug variable that holds the current version of the concurrency library.
This allows lldb to know which version of the internals layout it needs to use.

rdar://135886268
2024-09-16 09:14:03 -04:00
Konrad `ktoso` Malawski
4aaf47181e Merge pull request #75878 from jamieQ/stream-termination 2024-09-11 22:42:52 +09:00
Allan Shortlidge
ba3cd79b6f Concurrency: Remove superflous _SwiftConcurrencyShims imports.
The `_SwiftConcurrencyShims` module was imported `@_implementationOnly` which
was causing warnings to be emitted during the stdlib build. The module
currently serves no purpose; the only declaration it contains is a defunct
`_SwiftContext` struct which is not referenced by anything. The module needs to
continue to exist for source compatibility, though, since it is part of the
toolchain and imported publicly from other modules.
2024-09-09 12:20:13 -07:00
Alastair Houghton
e98e43141a Merge pull request #75948 from RSilicon/atom
Specify atomicity for compare_exchange_strong
2024-09-08 09:46:09 +01:00
Alastair Houghton
e34d23f56e Merge pull request #76310 from al45tair/eng/PR-135413803
[Windows][Concurrency] Use the same clock as Dispatch.
2024-09-07 08:42:59 +01:00
Alastair Houghton
8e91ae48e6 [Concurrency][Windows] Remove use of GetProcAddress().
Since we're linking `mincore.lib`, we don't need to use
`GetProcAddress()` to find `Query[Unbiased]InterruptTimePrecise()`.

rdar://135413803
2024-09-06 17:16:27 +01:00
Alastair Houghton
86c643ddc8 [Concurrency][Windows] Also update swift_get_clock_res().
I should have updated this to match as well.

rdar://135413803
2024-09-06 15:51:55 +01:00
Alastair Houghton
f5b146b095 [Windows][Concurrency] Use the same clock as Dispatch.
The Concurrency runtime calculates deadlines for scheduling itself
using `swift_get_time()`; unfortunately, on Windows that was using
`QueryPerformanceCounter()`, while Dispatch uses
`QueryInterruptTimePrecise()`.  The problem with that is that the two do
not necessarily correspond *at all*.  In general
`QueryPerformanceCounter()` may be using any of a number of hardware
timers depending on the machine on which we're running.

In the VM I was testing on, the two differed by 20ms, but the worst case
is that they are completely unrelated, in which case `Task.sleep()` will
wait essentially a random amount of time.

rdar://135413803
2024-09-06 15:39:22 +01:00
Allan Shortlidge
a39ee131ad Concurrency: swift_deletedAsyncMethodError() should be internal.
This function is an implementation detail of the runtime, not something that
clients of the _Concurrency library should be able to directly name. Make it
`@usableFromInline internal` instead of `public` so that it remains as ABI but
doesn't show up in auto-complete or documentation.
2024-09-05 11:12:58 -07:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Allan Shortlidge
29f172f3c1 Concurrency: Suppress a -Wc++23-extensions warning.
Fixes the following warning:

```
warning: label at end of compound statement is a C++23 extension [-Wc++23-extensions]
```
2024-09-03 13:09:28 -07:00
Mykola Pokhylets
e0ad7bde82 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/AST/ASTPrinter.cpp
#	lib/AST/FeatureSet.cpp
2024-08-29 11:28:43 +02:00
Mykola Pokhylets
d6673c78bd Implemented zombie actor state in SWIFT_CONCURRENCY_ACTORS_AS_LOCKS mode using additional reference counter 2024-08-26 19:41:17 +02:00
Holly Borla
d88b7995b5 Merge pull request #76079 from hborla/async-stream-sendable
[Concurrency] Add missing `Sendable` conformances to nested value types in `Async{Throwing}Stream`.
2024-08-26 10:07:56 -07:00
Mykola Pokhylets
a7ac32fc8f Disabled isolated deinit for SWIFT_CONCURRENCY_ACTORS_AS_LOCKS in the runtime 2024-08-26 17:46:47 +02:00
Holly Borla
ee4c034d6c [Concurrency] Add missing Sendable conformances to nested value types
in `Async{Throwing}Stream`.
2024-08-25 20:22:29 -07:00
Jamie
3bea96a310 [stdlib]: Propagate AsyncStream termination to all consumers
As of the changes in https://github.com/swiftlang/swift/pull/41713 to
enable Sendability for AsyncStream, it has been possible to create
multiple stream consumers operating concurrently. This change fixes
behavior in the case that the underlying stream is terminated while
multiple pending continuations are outstanding. Previously such
consumers would have been leaked (never resumed). Now, they are notified
of the stream's termination and resumed appropriately.

Resolves #66541 & #71412
2024-08-20 07:26:18 -05:00
Doug Gregor
8378562e12 Adopt @unsafe throughout the standard library
Annotate all of the `Unsafe*` types and `unsafe` functions in the standard
library (including concurrency, synchronization, etc.) as `@unsafe`. Add a
few tests to ensure that we detect uses of these types in clients that
have disabled unsafe code.
2024-08-19 14:33:09 -07:00
Rose
ea2b116764 Specify atomicity for compare_exchange_strong
waitQueue only needs to atomically be set to nullptr
2024-08-18 18:28:45 -04:00
Harlan Haskins
a721ef63f6 Un-deprecate Task.startOnMainActor (#75544) 2024-08-16 06:36:18 +09:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Mykola Pokhylets
66871b922d Deterministically crash in DefaultActorImpl::destroy() when self escapes in deinit 2024-08-15 12:43:48 +02:00
Mykola Pokhylets
6151731d26 Updated implementation to handle SWIFT_CONCURRENCY_ACTORS_AS_LOCKS 2024-08-13 12:30:21 +02:00
Alex Martini
906efcbe93 Merge pull request #75625 from amartini51/param_132944086
Match parameter names in documentation to declaration

Fixes: rdar://132944086
2024-08-08 09:22:11 -07:00
Richard L Zarth III
e2c9541537 Allow TaskGroup's ChildTaskResult Type To Be Inferred (#74517)
Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com>
2024-08-07 11:11:33 +09:00