Commit Graph

1608 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
86f5441294 [SerialExecutor] SerialExecutor.checkIsolated() to check its own tracking for isolation checks (#71172) 2024-03-29 07:06:34 +09:00
Doug Gregor
a8f3bb5e5e Implement AsyncIteratorProtocol.next() in terms of next(isolation:).
New async iterators should be able to implement only `next(isolation:)` and
get the older `next()` implementation via a default. Implement the
appropriate default witness.

Fixes rdar://125447861.
2024-03-28 12:59:12 -07:00
Allan Shortlidge
05a5bc4023 Merge pull request #72608 from tshortli/non-copyable-generics-2
AST/Frontend/stdlib: Fix condfails for NoncopyableGenerics and IsolatedAny
2024-03-28 08:23:24 -07:00
Allan Shortlidge
590d3353e6 Frontend: Introduce an alias for the IsolatedAny experimental feature.
To preserve compatibility with older compilers that do not allow `IsolatedAny`
to be enabled in production compilers, use an alias experimental feature when
building the stdlib (`IsolatedAny2`).

Also, add `@_allowFeatureSuppression(IsolatedAny)` in a couple spots it was
forgotten.

Partially resolves rdar://125138945
2024-03-27 22:20:50 -07:00
Allan Shortlidge
9e875f9839 Concurrency: Declare explicit Failure typealiases on AsyncSequence iterators.
Associated type inference ought to take care of providing the `Failure`
typealias for these `AsyncIteratorProtocol` types. However, the inferred
typealias is printed with `@_implements` in the `.swiftinterface`, guarded with
the `$AssociatedTypeImplements` language feature guard, which means older
compilers cannot see the typealias and therefore think the conformance is
incomplete. To make sure the `_Concurrency` module's interface is backward
compatible, we must manually define these typealiases temporarily.

Part of rdar://125138945
2024-03-27 18:09:53 -07:00
Yuta Saito
5d55621de3 Merge pull request #71508 from mtj0928/main 2024-03-21 22:39:54 +09:00
John McCall
a86b76a3e9 Use @isolated(any) function types for task functions.
The biggest annoyance here is having to clone all of the task creation
functions for Embedded Swift because it can't use `any Actor` right now.
2024-03-15 14:40:54 -04: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
Holly Borla
5d9ad87a82 [Concurrency] Task executors are available in Swift 6.0. 2024-03-13 09:56:24 -07:00
Holly Borla
154f47ecef Merge pull request #72252 from hborla/concurrency-lib-annotations
[Concurrency] Add a few missing `Sendable` annotations in the concurrency library.
2024-03-13 07:05:27 -07:00
Konrad `ktoso` Malawski
d4c347c3a1 [Concurrency] Adjustments to withTaskExecutorPreference (#71973) 2024-03-13 06:24:30 -07:00
Holly Borla
70d998a1bb [Concurrency] Make OptionalIsolatedParameters a conditionally suppressible
language feature, and suppress it for `Clock.measure`.

This allows the _Concurrency swiftinterface file to continue building with
compilers that do not support `OptionalIsolatedParameters`. The feature
suppression drops the `isolated` keyword and replaces `#isolation` with
`nil`.
2024-03-12 22:56:16 -07:00
Holly Borla
dfa7b866c7 [Concurrency] Clock.measure should inherit actor isolation. 2024-03-12 22:55:34 -07:00
Holly Borla
377b5274ff [Concurrency] Async{Throwing}Stream.init(unfolding:) should accept a
`@Sendable` closure.
2024-03-12 22:55:34 -07:00
Holly Borla
f78690bbb8 [Concurrency] ContinuousClock and SuspendingClock are Sendable. 2024-03-12 22:55:34 -07:00
Allan Shortlidge
32cd086068 Merge pull request #72259 from tshortli/typed-throws-without-actually-escaping
Concurrency: Guard use of `withoutActuallyEscaping()` in inlinable code
2024-03-12 15:12:03 -07:00
Allan Shortlidge
65c0ef830e Concurrency: Guard use of withoutActuallyEscaping() in inlinable code.
Since `withoutActuallyEscaping()` has adopted typed throws, it's no longer
visible to older compilers that do not support typed throws. We need to guard
use of the function in inlinable code to make sure the textual interface of
`_Concurrency` remains buildable with older compilers.

Resolves rdar://124352900
2024-03-12 10:34:57 -07:00
Mike Ash
3100be12fa [Runtime] Don't enable tracing in logd, diagnosticd, notifyd.
We can't use os_log functionality in logd, diagnosticd, or notifyd. Check for them and disable tracing in those processes.

Add a new TracingCommon.h for common code shared between swiftCore and swift_Concurrency tracing. Add a single function that checks if tracing should be enabled, which now checks if os_signpost_enabled is available, and if the process is one of these. Modify the tracing code to check this before creating os_log objects.

rdar://124226334
2024-03-11 21:06:15 -04:00
John McCall
14dcab6bcd Restore (TaskOptionRecordKind)0 to set the initial serial executor.
This has been the behavior of the runtime since the initial release.
Initially, it was thought that task executors would provide similar
functionality, so they naturally took over the enumerator.  After that
changed, we forgot to change it back.  Fortunately, we haven't released
any versions of Swift with the task executors feature yet, so it's not
too late to fix this.
2024-03-08 00:15:10 -05:00
eeckstein
d1ec089c72 Merge pull request #72088 from language-core/main
chore: fix some comments
2024-03-06 10:08:50 +01:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Allan Shortlidge
851b47fbcd Concurrency: Factor atomic operations in Task.sleep() into a Sendable wrapper.
When building the Swift standard library, the compiler warns:

```
warning: capture of 'wordPtr' with non-sendable type 'UnsafeMutablePointer<Builtin.Word>' in a `@Sendable` closure
```

This diagnostic will become an error in the Swift 6 language mode, so it needs
to be addressed. This PR factors the atomic operations used by the
implementation of `Task.sleep()` into an `@unchecked Sendable` wrapper in order
to convince the compiler that these operations are thread-safe. As an added
benefit, the code is more readable when the atomic operatios are abstracted
away. This refactor intentionally translates the existing implementation into a
wrapper as faithfully as possible and does not attempt to improve on any other
aspects of the implementation, such as the unsafe manual memory allocation and
deallocation.
2024-03-04 09:32:28 -08:00
Holly Borla
f1e14f8be7 [Concurrency] Mark extractIsolation as @_alwaysEmitIntoClient. 2024-02-27 18:29:28 -08:00
Holly Borla
59507ba361 [Concurrency] Add an API for extracting the isolation of a dynamically isolated
function value.
2024-02-26 17:59:27 -08:00
Doug Gregor
8c452b5cf5 Fix accidental ABI break with AsyncSequence.flatMap
At the type that I introduced type throws into AsyncSequence and its
algorithms, I accidentally dropped a `@preconcurrency` on the ABI
entrypoint, leading to a mangled name change.

Fixes rdar://123639030.
2024-02-26 12:38:56 -08:00
Doug Gregor
0c9c734f7e Merge pull request #71722 from DougGregor/diagnostic-style-swift-default 2024-02-24 14:42:38 -10:00
Mishal Shah
cb96ec2893 Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6 2024-02-22 09:44:44 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Mishal Shah
96d61d3c5c Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6 2024-02-20 14:31:55 -08:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Doug Gregor
8ed35de4e0 Switch to the 'Swift' diagnostic style as the default 2024-02-19 02:48:23 -10:00
Holly Borla
26621b804c [Concurrency] Enable optional isolated parameters. 2024-02-16 16:28:45 -08:00
Holly Borla
ddf2fc44f4 [Concurrency] Allow #isolation to have a more specific contextual type. 2024-02-16 16:27:54 -08:00
Mishal Shah
61ed95a32f Merge pull request #71599 from hborla/update-build-task-executor-feature-guard
[Features] Rename the `BuiltinBuildTaskExecutor` feature guard.
2024-02-14 00:09:54 -08:00
Holly Borla
56c2b34071 [Features] Rename the BuiltinBuildTaskExecutor feature guard.
The name of the `TaskExecutor` protocol was recently changed to remove
underscores after the feature was accepted in Swift Evolution. An implication
of that rename is that the `buildOrdinaryTaskExecutorRef` builtin changed
the type that it expected as the argument. However, the original change
landed in the standard library which as since produced swiftinterfaces
that contain the following inlinable code:

```
@inlinable public init<E>(ordinary executor: __shared E) where E : _Concurrency._TaskExecutor {
  #if $BuiltinBuildTaskExecutor
  self.executor = Builtin.buildOrdinaryTaskExecutorRef(executor)
  #else
  fatalError("Swift compiler is incompatible with this SDK version")
  #endif
}
```

When a compiler containing the protocol rename attempts to type check the
above inlinable code, it crashes because the builtin is expecting an argument
conforming to `TaskExecutor`, which doesn't exist in this version of the
standard library. The issue is that the current compiler still supports
the `$BuiltinBuildTaskExecutor` feature guard, but the builtin supported
has since changed.

To resolve this issue, we need to stop supporting the `$BuiltinBuildTaskExecutor`
feature guard and introduce a new one that is only supported by compiler versions
that contain the rename. This approach relies on nothing having adopted the
API, otherwise we would need to stage in the rename as a parallel set of APIs,
and only remove the old APIs once nothing is relying on the old _Concurrency
swiftinterfaces.
2024-02-13 20:16:42 -08:00
Konrad `ktoso` Malawski
c5dbeca0b1 [TaskExecutor] Remove un-necessary nonisolated(unsafe) (#71594) 2024-02-13 19:40:30 -08:00
Doug Gregor
a4f0709c2f Rename AsyncIteratorProtocol.next(_:) to next(isolation:)
Match the name of the method as specified in SE-0421
2024-02-09 14:18:37 -08:00
mtj0928
343f8e5df1 [docs] Fix examples for TaskLocal
TaskLocal doesn't support `static let`.
2024-02-10 00:43:31 +09:00
Kuba (Brecka) Mracek
ea6295e47f Merge pull request #71392 from kubamracek/revert-embedded-defines
Revert "Merge pull request #71278 from kubamracek/embedded-no-mach-defines"
2024-02-05 17:48:40 -08:00
Pavel Yaskevich
09991db863 Merge pull request #71327 from xedin/raise-unexpected-executor-log-level
[stdlib] Make expected actor isolation checking crash by default
2024-02-05 09:45:55 -08:00
Kuba Mracek
dba8d5d3a0 Revert "Merge pull request #71278 from kubamracek/embedded-no-mach-defines"
This reverts commit 21eddf0b1a, reversing
changes made to e2d516f3c9.
2024-02-05 09:05:22 -08: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
Kuba (Brecka) Mracek
21eddf0b1a Merge pull request #71278 from kubamracek/embedded-no-mach-defines
[embedded] Implicitly define __APPLE__ and __MACH__ when on -apple-none triples
2024-02-02 19:30:56 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Allan Shortlidge
ad2fcc6e38 [TaskExecutors] Add missing return type to _DefaultGlobalConcurrentExecutor.asUnownedTaskExecutor().
Addresses a warning that appears to point to a probable bug.
2024-02-01 18:41:30 -08:00
Kuba Mracek
e22aedbcc3 [embedded] Implicitly define __APPLE__ and __MACH__ when on -apple-none triples 2024-01-31 09:22:31 -08:00
Ian Anderson
9a35f83e25 Merge pull request #71075 from ian-twilightcoder/no-exit-in-shims
[Concurrency] [shims] Don't declare `exit` in  the concurrency shims
2024-01-30 11:29:11 -08:00
Ian Anderson
288f37b2c1 [Concurrency] [shims] Don't declare exit in the concurrency shims
Don't delete the OS declaration of `exit` because the concurrency shims aren't always imported, and so the shim declaration might not always be available.
Don't override the OS declaration of `exit` in the concurrency shims since we can't just delete the OS one. Instead, set up internal shims just for building Concurrency that forward declares `exit`.
2024-01-29 16:25:46 -08:00
Konrad `ktoso` Malawski
bd19d937f0 [TaskExecutor] Remove underscore from new APIs (#71145) 2024-01-30 06:27:54 +09:00
Doug Gregor
0cc529768a Merge pull request #70635 from DougGregor/async-sequence-typed-throws
Adopt typed throws in AsyncIteratorProtocol and AsyncSequence
2024-01-29 11:51:25 -08:00