Commit Graph

68 Commits

Author SHA1 Message Date
Allan Shortlidge
5cc7fff4ca Concurrency: Restore consume in TaskLocal.withValueImpl<R>(_:operation:).
It is no longer necessary to avoid using the `consume` keyword in inlinable
function bodies in the standard library in order to support older compilers.

Partially reverts https://github.com/apple/swift/pull/65599.

Resolves rdar://109165937.
2023-08-14 22:19:56 -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
Yuta Saito
00705b4b2a [Concurrency] Fix calling convention mismatch in AsyncStream
Functions defined in AsyncStream.cpp are called from Swift with swiftcc
but are defined with the C calling convention.
2023-06-11 12:26:52 +00:00
Allan Shortlidge
860b8cdf48 Concurrency: Revert workarounds for @backDeployed condfails.
All compilers that must be able to compile the standard library's textual
interface accept the following:
- back deployed functions declared without `@available`
- `@inlinable` back deployed functions
- `defer` blocks in back deployed functions

We can therefore revert the workarounds added in
https://github.com/apple/swift/pull/62946/ and
https://github.com/apple/swift/pull/62928/.

Resolves rdar://104085810
2023-05-08 18:21:08 -07:00
Allan Shortlidge
c0ee3ac866 Concurrency: Make _Concurrency module interface parsable by older compilers.
Revert a few unnecessary changes have been made to the _Concurrency module
recently that make its swiftinterface un-parseable by older compilers that we
need to support.

- The `consume` keyword is not understood by older compilers, so including it
  in inlinable code is a problem. It has no actual effect on lifetimes where it
  was used, so just omit it.
- Don't build the _Concurrency module with -enable-experimental-feature
  MoveOnly. The MoveOnly feature is now enabled by default in recent compilers,
  so the flag is superfluous when building the dylib. When emitting the
  interface, having the feature enabled explicitly exposes code guarded by
  `$MoveOnly` to older compilers that do not accept all of the code.

Resolves rdar://108793606
2023-05-02 15:27:05 -07:00
Nate Chandler
4fe988b7c2 [Concurrency] Nest stack traffic in withValue.
Because `_taskLocalValuePush` and `_taskLocalValuePop` can result in calls
to `swift_task_alloc` and `swift_task_dealloc` respectively, and because
the compiler hasn't been taught about that (e.g.
`SILInstruction::isAllocatingStack`,
`SILInstruction::isDeallocatingStack`, etc), calling them (push and pop)
from a function which makes use the stack for dynamically sized
allocations can result in violations of stack discipline of the form

```
swift_task_alloc // allocates %ptr_1
copy_value_witness // copies into %ptr_1
swift_task_localValuePush // calls swift_task_alloc and allocates %ptr_2
swift_task_dealloc // deallocates %ptr_1
swift_task_localValuePop // calls swift_task_dealloc and deallocates %ptr_2
```

Avoid the problem by not allocating dynamically sized stack space in the
function which calls `_taskLocalValuePush` and `_taskLocalValuePop`.
Split the calls to those functions into `withValueImpl` function which
takes its argument `__owned`.  Call that function from `withValue`,
ensuring that the necessary copy (to account for the fact that withValue
takes its argument `__guaranteed` but `_taskLocalValuePush` takes its
`__owned`) and associated stack traffic occur in `withValue`.

Still, allow `withValueImpl` to be inlined.  The stack nesting will be
preserved across it.

rdar://107275872
2023-04-18 19:51:34 -07:00
L-j-h-c
913dcd62b8 [Gardening] fix typos across docs and codebase
fix typos across docs and codebase
2023-02-17 23:55:16 +09:00
Evan Wilde
c67e22e6aa Merge pull request #63192 from etcwilde/ewilde/fix-backdeploy-compat56-crash
Fixes for the compat56 library
2023-02-07 10:22:50 -08:00
Evan Wilde
4f7f786ee3 Fix SWIFT_TASK_DEBUG_LOG macro
The threading library changed in the BackDeployConcurrency library
resulting in the `SWIFT_TASK_DEBUG_LOG` macro not compiling. Fixing
that. Also adding the logging pieces to the Compatibility 56 library.
2023-01-24 10:15:12 -08:00
Konrad `ktoso` Malawski
943d1b830b [Concurrency] backdeploy library has no taskGroup_initializeWithFlags (#63006) 2023-01-13 19:08:47 +09:00
swift-ci
93a0a6d905 Merge pull request #62914 from ktoso/wip-task-group-twotypes
[Concurrency] DiscardingTaskGroup (rev 3)
2023-01-11 01:37:33 -08:00
Konrad `ktoso` Malawski
4b90cdbe5c Revert "cleanup"
This reverts commit 128e2b2099.
2023-01-11 13:03:22 +09:00
Konrad `ktoso` Malawski
128e2b2099 cleanup 2023-01-11 12:40:25 +09:00
Konrad `ktoso` Malawski
c59122fa92 remove changes in backdeploy lib, not needed 2023-01-11 11:58:34 +09:00
Konrad `ktoso` Malawski
6d63cf4994 fix cast type in getting task record 2023-01-11 11:55:52 +09:00
Allan Shortlidge
087aacc9fd [TaskLocals] Avoid use of defer in back deployed functions in the standard library.
Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (https://github.com/apple/swift/pull/62444) and for now we need the standard library interface to be compatible with those older compilers.

Resolves rdar://104045168
2023-01-10 10:44:15 -08:00
Allan Shortlidge
c7c806f768 [TaskLocals] Remove use of @inlinable with @_backDeploy temporarily. 2023-01-09 10:59:53 -08:00
Konrad `ktoso` Malawski
bf5ef5a4b0 undo any changes in backdeploy lib, we don't do any changes there 2023-01-09 19:00:18 +09:00
Konrad `ktoso` Malawski
7845de85c7 remove duplicated status logic 2023-01-09 13:18:23 +09:00
Konrad `ktoso` Malawski
6f38910058 DiscardingTaskGroup now shares some implementation with "Accumulating" TaskGroup 2023-01-09 11:35:04 +09:00
Konrad `ktoso` Malawski
54dec38a34 initial complete impl 2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
f8b85015c1 prepare flags
wip on options

implement discardResults as a flag passed to grout init
2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
1a3403524c [Concurrency] Optimize Void task group, to not store completed tasks anymore 2023-01-05 16:19:05 +09:00
Alex Martini
a98621c6d3 Merge pull request #62504 from Jager-yoo/revise-backdeployed-concurrency
[stdlib] Gardening BackDeployConcurrency files
2022-12-15 10:26:02 -08:00
Konrad `ktoso` Malawski
387d36242d [Concurrency] Fix missing inherit executor on withTaskCancellationHandler (#62546) 2022-12-13 21:45:11 +09:00
Konrad `ktoso` Malawski
f9c2bc0402 Apply suggestions from code review
Co-authored-by: Doug Gregor <dgregor@apple.com>
2022-12-13 10:39:46 +09:00
Konrad `ktoso` Malawski
342ce7ea19 cleaning up attributes 2022-12-12 12:02:31 +09:00
Jager-yoo
c96178ea6b [stdlib] Gardening BackDeployConcurrency files 2022-12-10 23:55:53 +09:00
Konrad `ktoso` Malawski
d122fd68fa add _backDeploy and availability necessary for it 2022-12-09 17:46:34 +09:00
Konrad `ktoso` Malawski
b3c335798d Better fix, using inheriting executor 2022-12-09 10:22:48 +09:00
Konrad `ktoso` Malawski
2178d9893f [Concurrency] tasklocal withValue inside actor is safe 2022-12-09 10:22:47 +09:00
lilli-nishikawa
86b8c5f75e stdlib: Fix typo in Actor.cpp 2022-12-06 12:30:00 +09:00
Kavon Farvardin
3c4dd9fad4 Merge pull request #61938 from kavon/annotate_inherits_backdeploy
add missing `@_unsafeInheritExecutor`'s to backdeploy library
2022-11-04 14:16:54 -07:00
Kavon Farvardin
3e9ab9a69a add missing @_unsafeInheritExecutor's to backdeploy library
resolves rdar://101934420
2022-11-04 10:28:16 -07:00
John McCall
7f737d235d Synchronize with cancellation when removing a task from a task group
We were detaching the child by just modifying the list, but the cancellation path was assuming that that would not be done without holding the task status lock.

This patch just fixes the current runtime; the back-deployment side is complicated.

Fixes rdar://88398824
2022-10-29 00:10:28 -04:00
Eric Miotto
9ba404e043 Don't target arm64/arm64e for the back-deployed Concurrency dylib for watchOS (#61665)
Addresses rdar://101389307
2022-10-21 15:15:54 -07:00
Egor Zhdan
84a1ffcb33 [Shims] Include SwiftShims headers without ../
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```

This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
       ^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
       ^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
2022-09-14 11:14:50 +01:00
Doug Gregor
c42025a571 Merge pull request #60661 from DougGregor/concurrency-api-sendable-fixes
[Concurrency] Fix a few annotations for the concurrency library
2022-08-19 16:47:32 -07:00
Doug Gregor
ee4f6b1f75 Make CheckedContinuation and UnsafeContinuation unconditionally Sendable.
The continuation types were conditionally `Sendable` based on whether
the result type of the continuation was `Sendable`. However,
conceptually, the return value is never leaving the current task, so
it is never actually crossing concurrency boundaries. Therefore, we
can make the continuation types unconditionally `Sendable`.

Fixes rdar://98462858.
2022-08-19 13:06:41 -07:00
Konrad `ktoso` Malawski
ecccce6113 [Concurrency] Deprecate one of the cancellation handler overloads (#60569) 2022-08-18 11:14:30 +09:00
Nate Chandler
34c08b8344 [TaskToThread] Add Task.runInline.
The new intrinsic, exposed via static functions on Task<T, Never> and
Task<T, Error> (rethrowing), begins an asynchronous context within a
synchronous caller's context.  This is only available for use under the
task-to-thread concurrency model, and even then only under SPI.
2022-07-08 08:44:18 -07:00
swift-ci
a66f937932 Merge pull request #59338 from sjavora/patch-1
Fix some typos in `AsyncThrowingStream.swift` docs
2022-06-09 03:37:51 -07:00
Alastair Houghton
a9fe9716da Merge pull request #59287 from al45tair/eng/PR-90776105-2
[Build][Runtime] Add a new threading library.
2022-06-09 02:41:53 -07:00
Šimon Javora
36011aa9b2 Fix some typos in AsyncThrowingStream.swift
nomally -> normally
2022-06-09 10:33:11 +02:00
Alastair Houghton
ede4010cc3 [BackDeployConcurrency] Fix to use the new threading library.
A copy of the older Concurrency sources was just added to BackDeployConcurrency,
replacing the `add_subdirectory(../Concurrency)` trick it was using previously.
These need to be adjusted to work with the threading library.  Fortunately, the
necessary adjustments are the same as those required for the existing
Concurrency library, give or take.

rdar://90776105
2022-06-07 15:45:36 +01:00
Alastair Houghton
0cf687aa2b [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-06-07 07:39:51 +01:00
Doug Gregor
06061a628a Fold away unnecessary SWIFT_CONCURRENCY_BACK_DEPLOYMENT checks 2022-06-06 14:57:48 -07:00
Mike Ash
fa09001923 Fix actor/job/task leaks in the back deployment runtime.
When initializing an actor, job, or task, use _swift_instantiateInertHeapObject to have the OS's libswiftCore set up the object's refcounts field, to ensure we get a valid initial state.

There is no equivalent for immortal objects, but by a stroke of luck the new representation for immortal refcounts happens to set the immortal bit in the old representation.

rdar://93087343
2022-06-06 14:56:59 -07:00
Doug Gregor
588a1eb519 Ensure that we enabled override hooks in the concurrency back-deployment lib
Fixes rdar://94184066.
2022-06-06 10:48:00 -07:00
Doug Gregor
ffb37ed057 Inline the Swift 5.6 concurrency library as a separate back-deploy library 2022-06-06 10:38:25 -07:00