Commit Graph

986 Commits

Author SHA1 Message Date
Yuta Saito
0ceab44032 [DiscardingTG] Fix runtime signature mismatch for statically known -> Void closure
Since https://github.com/apple/swift/pull/65613, DiscardingTG started to
accept `() -> Void` instead of `() -> T`, but it also changed the number
of arguments accepted by the closure from 3 to 2. So it should use
`non_future_adapter` instead of `future_adapter` to avoid runtime signature
mismatch.
2023-05-30 18:15:12 +00:00
swift-ci
9698128a36 Merge pull request #65613 from ktoso/wip-discarding-error-task-leak
[DiscardingTG] Undo pointer auth workaround; fix memory leaks
2023-05-25 19:06:48 -07:00
Mike Ash
dfd313cd6c [Runtime] Fast lookups of Concurrency types with standard manglings.
Have the Concurrency runtime register a struct containing pointers to all of its type descriptors with standard manglings. Then have the runtime use that struct to quickly look up those types, instead of using the standard, slower type lookup code.

rdar://109783861
2023-05-24 16:08:23 -04:00
Konrad `ktoso` Malawski
760cb44987 remove extra debug statements 2023-05-24 18:59:18 +02:00
Konrad `ktoso` Malawski
d82de55ae4 less code duplication 2023-05-24 18:46:57 +02:00
Konrad `ktoso` Malawski
9f5a707a30 back to println tests 2023-05-24 18:03:46 +02:00
Konrad `ktoso` Malawski
cad608eb81 [Discarding] Don't leak retained "first error" task when retaining it 2023-05-24 18:03:28 +02: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
da6f08a24e [Concurrency] Adopt stable keyword consuming instead of __owned
add test for warnings emitted when missing consuming attribute

use -emit-sil in mock SDK tests for better coverage
2023-05-11 15:18:54 +02:00
Allan Shortlidge
1bf94248a0 Merge pull request #65777 from tshortli/clean-up-back-deployed-concurrency-apis
Concurrency: Revert workarounds for `@backDeployed` condfails
2023-05-09 08:53:25 -07:00
Konrad `ktoso` Malawski
ca2987cd83 [Concurrency] Easier to handle deprecation of Job and friends 2023-05-09 14:38:15 +09: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
Evan Wilde
08c4646a0a Merge pull request #65719 from etcwilde/ewilde/discarding-task-group-availability
Fix DiscardingTaskGroup availability
2023-05-07 18:15:02 -07:00
Konrad `ktoso` Malawski
c7fedd4fb9 [Executors] Fix delegation chain of Excecutor.enqueue for Job specifically 2023-05-06 10:50:24 +09:00
Evan Wilde
c6f551c683 Fix discarding task-group availability
Discarding task groups aren't available in the 5.8-aligned OS's,
resulting in a loader error at launch if you try to use them.

Bumping the availability attributes to 5.9 on everything in
DiscardingTaskGroup.swift
2023-05-05 15:01:43 -07:00
Kavon Farvardin
8511317a97 Replace additional uses of noncopyable metatypes. 2023-05-04 11:44:27 -07:00
Kavon Farvardin
103bd043cd Revert "Revert "Prevent noncopyable metatypes from being converted to Any""
This reverts commit 1a3b42cd63.
2023-05-04 11:38:00 -07:00
Hamish Knight
1a3b42cd63 Revert "Prevent noncopyable metatypes from being converted to Any" 2023-05-04 12:10:10 +01:00
Kavon Farvardin
1df3912794 Merge pull request #65606 from kavon/noncopyable-metatypes
Prevent noncopyable metatypes from being converted to `Any`
2023-05-03 22:05:17 -07:00
Konrad `ktoso` Malawski
0bdb39f51e Merge pull request #65455 from ktoso/wip-bincompat-job-rename 2023-05-04 07:34:45 +09:00
Kavon Farvardin
4710fc675b Prevent noncopyable metatypes from being converted to Any
These metatypes are a gateway to more incorrect
uses of these noncopyable values because we don't
yet have the corresponding runtime support yet.
The other use cases of using metatypes of
noncopyable types in generics is not high enough to
warrant people using them yet.

resolves rdar://106452518
2023-05-03 10:23:11 -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
Konrad `ktoso` Malawski
8d6980ec10 [Executors] Make move to ExecutorJob binary compatible; deprecate Job 2023-05-02 14:44:11 +09:00
Konrad `ktoso` Malawski
fe90d44e4c [Executors] Remove accidentally added availability on asUnownedSerialExecutor (#65407) 2023-04-26 06:14:12 +09:00
nate-chandler
d20b8d26b8 Merge pull request #65274 from nate-chandler/rdar107275872
[Concurrency] Nest stack traffic in withValue.
2023-04-19 11:52:41 -07:00
Evan Wilde
b8396e6449 Merge pull request #65271 from etcwilde/ewilde/fix-startOnMainActor
Fix main executor check in `startOnMainActor`
2023-04-19 07:49:18 -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
Evan Wilde
ad81f8d557 Allow discarding startOnMainActor results
Adding discardableResult to startOnMainActor
2023-04-18 16:40:54 -07:00
Evan Wilde
c18c37b6ba Use isCurrentExecutor check in startOnMainActorImpl
startOnMainActor checked the current executor directly, which in some
cases came back as a `nullptr`. This happens with older API which don't
know to set the current executor. `swift_task_isCurrentExecutor` knows
how to check for the current dispatch queue and the main thread though,
so switching the main-executor check to use that API instead.
2023-04-18 16:38:29 -07:00
Konrad `ktoso` Malawski
97d2f4fd36 Fix pointer auth issues for discarding task group operation pointer (#65220) 2023-04-18 12:51:45 +09:00
Kavon Farvardin
8f13679582 add missing rename of Job -> ExecutorJob 2023-04-12 13:37:43 -07:00
Konrad `ktoso` Malawski
80b93863a9 [Concurrency] Rename Job to ExecutorJob, ease transition with typealias (#65006) 2023-04-11 14:52:10 +09:00
Konrad `ktoso` Malawski
b666fc672e [Executors] Remote distributed actors get "crash on enqueue" default executor (#64969) 2023-04-10 19:12:03 +09:00
Konrad `ktoso` Malawski
b8780c9d9e [Executors] Move assert/assume APIs onto actors; assumeIsolated() (#64812) 2023-04-04 07:44:43 +09:00
swift-ci
3be14e0a4a Merge pull request #64622 from kavon/bifurcate-moveonly-featureflag
Fix minimal stdlib builds with noncopyable types
2023-03-28 14:44:24 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
Kavon Farvardin
5c8447587f explicitly enable MoveOnly feature when building _Concurrency lib
We ran into an issue on minimal stdlib build configurations, because they
pull slightly older toolchains to build and test the stdlib. The noncopyable
`Job` type was adopted immediately after such types were enabled by default,
before the toolchain builds could catch up. Adding this flag to the build of
the `_Concurrency` lib should make things more robust when somewhat older
compilers are building this part of the stdlib.

part of resolving rdar://106849189
2023-03-24 16:00:22 -07:00
Kavon Farvardin
363448a0d7 bring back the noncopyable Job type in the _Concurrency lib
This reverts commit abe377ce68.

Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com>
2023-03-24 08:58:40 -07:00
Konrad `ktoso` Malawski
abe377ce68 [Workaround][Concurrency] Mark Job as NOT moveonly until we fix moveonly types (#64536) 2023-03-23 07:43:51 +09:00
Konrad `ktoso` Malawski
345c221f56 [Concurrency] Distributed actor's unownedExecutor should be optional (#64499) 2023-03-22 08:40:41 +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
Konrad `ktoso` Malawski
ac0c3b75c6 [Concurrency] Freeze JobPriority, comment that Flags location is assumed (#64267) 2023-03-10 16:49:37 +09:00
Kavon Farvardin
4c65c33668 Merge pull request #64211 from kavon/assumeOn-task2thread-guarding
guard assume on executor API against task-to-thread runtimes
2023-03-09 09:34:01 -08: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
Kavon Farvardin
f40d90f885 fix another unguarded use of MainActor 2023-03-08 14:12:13 -08:00
Kavon Farvardin
18d976f8fa guard assume on executor API against task-to-thread runtimes 2023-03-08 12:02:06 -08:00
Konrad `ktoso` Malawski
5fbdd8197d Minor mistake in group docs comment cocs snippet
We say in a comment here that we print the error and cancel, but we don't actually have the print below. This PR adds that missing print in the docs snippet.
2023-03-08 22:56:09 +09:00
swift-ci
f284e72956 Merge pull request #62201 from mdznr/documentation_grammar
[NFC] Correct grammar in documentation for `AsyncStream.Continuation.finish()`
2023-03-07 15:02:41 -08:00