Commit Graph

1608 Commits

Author SHA1 Message Date
swift-ci
c19375790a Merge pull request #35977 from DougGregor/discardable-run-detached 2021-02-15 14:51:51 -08:00
Doug Gregor
6a5dfb8aa4 Mark Task.runDetached as @discardableResult.
Often, this API is used for its side effects and nobody cares about the
handle.
2021-02-15 12:21:49 -08:00
Konrad `ktoso` Malawski
d2bd6abe61 [Concurrency] TaskLocals allow configuring inheritance: never 2021-02-13 20:09:11 +09:00
Konrad `ktoso` Malawski
b811b12246 [Concurrency] TaskLocals lookup "skip" optimization 2021-02-13 10:39:22 +09:00
Konrad `ktoso` Malawski
1044723787 [Concurrency] Initial Task Local Values implementation 2021-02-13 10:39:22 +09:00
Philippe Hausler
8578584f61 Implementations for operators and async functions on AsyncSequence per SE-0298 (#35740)
* Implementations for operators and async functions on AsyncSequence per SE-0298

* Add trailing new lines to AsyncSequence adopter files

* Remove extra // from preambles

* Transition sequence properties and sequence initializers to internal

* Rename Upstream to Base

* Rename "Failable" asynchronous sequences to "Throwing"

* Make iteration consistent with closure lifetimes and track failure via state

* Use for await syntax for async function extensions on AsyncSequence

* Work-around rethrows calculations being incorrect for conformance + closure rethrowing

* Update testing names to reflect Throwing versus Failable

* Incorperate runAsyncAndBlock into the test function for suite calls

* Remove @frozen from AsyncSequence operators

* Back out reduce family functions for now due to IRGen bug

* Additional corrections for throwing cases and fix up potential linux crasher

* Add a upstream and throwing tests and correct flatMap's throwing behavior

* Unify parameter names to count

* Add a more helpful precondition on prefix

* Add tests for throwing cases of non closure async functions on AsyncSequence

* Correct missing count transition in dropFirst

* Correct missing , in assertion

* [NFC] add commentary on optimization in dropFirst on dropFirst

* Disable collect tests for non macOS platforms for now

* Disable all async sequence tests for non macOS platforms for now
2021-02-12 14:43:59 -08:00
swift-ci
06513524e9 Merge pull request #35940 from AnthonyLatsis/eof-warn 2021-02-12 11:37:40 -08:00
Jonathan Grynspan
36b03a499f Merge pull request #35868 from grynspan/main
[Concurrency] Simplify the type story for `Continuation` by eliminating `Throwing` variants
2021-02-12 12:55:13 -05:00
Evan
e813bbea76 Merge pull request #35911 from etcwilde/ewilde/deprecate-runAsyncAndBlock
Deprecate runAsyncAndBlock API
2021-02-12 09:51:04 -08:00
Anthony Latsis
39649161d0 Gardening: See to some missing newline warnings 2021-02-12 17:00:47 +03:00
Konrad `ktoso` Malawski
a55ebff942 [Concurrency] deprecate not implemented Task functions, until they're implemented 2021-02-12 16:33:16 +09:00
Konrad `ktoso` Malawski
e7cfc8c018 [Concurency] Improve priority testing, including multi-task escalation 2021-02-12 09:06:17 +09:00
Konrad `ktoso` Malawski
08de933288 [Concurrency] Task revisions 3
- introduce UnsafeCurrentTask
- implement Hashable, Equatable on tasks
- assume we'll have a way to get a task from sync context
- Task.Handle now has a Failure type as well
- Task.Handle.getResult
2021-02-12 09:06:17 +09:00
Konrad `ktoso` Malawski
30a86aa0cf [Concurrency] Temporarily remove Deadlines, we'll revisit this later 2021-02-12 09:06:17 +09:00
Nate Chandler
e2a8abc9e5 [Async CC] Make error indirect.
Previously, the error stored in the async context was of type SwiftError
*.  In order to enable the context to be callee released, make it
indirect and change its type to SwiftError **.

rdar://71378532
2021-02-11 11:34:47 -08:00
Jonathan Grynspan
7e7215459f Remove _Continuation protocol and duplicate the relevant code. 2021-02-11 12:54:19 -05:00
Evan Wilde
e83b0a2a84 Deprecate runAsyncAndBlock API
We don't want people using this as a means of jumping from synchronous
code to async code. It blocks the thread that it's running on and spawns
a new thread to run the async code.

This has a couple of drawbacks. First, if it blocks a thread that is
needed by the async code (i.e, calling something on the main actor while
blocking the main thread), it is an immediate deadlock. This is a bad
day for everyone. Second, it can easily lead to thread-explosions.

The proper entry-point for async code is to use something of the
following form:

```
@main
struct Main {
  static func main() async {
    // ...
  }
}
```

This should take care of most new code. There are still places where
folks will need to jump from synchronous code to async code. That still
needs to be designed and implemented, but we don't want people to come
to rely on `runAsyncAndBlock`.
2021-02-10 21:33:03 -08:00
Dario Rexin
e8b36abb63 [Concurrency] Enable concurrent global executor on non-Darwin platforms (#35871)
* [Concurrency] Enable concurrent global executor on non-Darwin platforms

* Fix runtime unittest build
2021-02-10 14:12:21 -08:00
Jonathan Grynspan
d8f7f20c4b [Concurrency] Simplify the type story for Continuation by eliminating Throwing variants
The goal of doing this is to reduce the amount of boilerplate and repeated code w.r.t. Continuation. Having just added `resume()` in four places, I got the sense that there was a lot of common code that was being duplicated. I removed the Throwing variants of these types (they can be expressed as Continuation<T, E:Error> instead of ThrowingContinuation<E>) and I broke out a significant amount of common code between CheckedContinuation and UnsafeContinuation into an implementation-only protocol to avoid repeating it. D.R.Y.

This change resolves rdar://74154769.
2021-02-10 12:09:33 -05:00
Evan Wilde
748f15e0d5 Update standard library actor class
This patch updates the once instance of actor class in the concurrency
library to actor. This is the actor for the MainActor global actor.
2021-02-10 08:05:57 -08:00
Jonathan Grynspan
6bddba2272 Merge pull request #35829 from grynspan/main
[Concurrency] Add `*Continuation.resume()` for continuations returning `Void`.

This change resolves rdar://74031110.
2021-02-09 12:16:05 -05:00
Jonathan Grynspan
ca423f44dd Fix whitespace 2021-02-08 23:30:46 -05:00
Joe Groff
7fdc65d5b8 Merge pull request #35793 from jckarter/checked-continuation-resume-with-result
CheckedContinuation: Add `resume(with: Result)` for parity with UnsafeContinuation
2021-02-08 15:52:55 -08:00
Jonathan Grynspan
49da0783ef Mark new function inlinable since it's trivial 2021-02-08 18:01:12 -05:00
Jonathan Grynspan
5db55aad1e Add *Continuation.resume() for continuations returning Void.
This change implements the changes proposed in swift-evolution PR #1264.
Existing test coverage should be sufficient here since the added function
simply calls into the existing `resume(returning:)` function.

This change resolves rdar://74031110.
2021-02-08 14:37:27 -05:00
Dario Rexin
bcd6416c89 Revert "[Concurrency] Build C only libdispatch before Swift on non-Darwin pla… (#35738)" (#35789)
This reverts commit 74e59ab77f.
2021-02-05 13:51:39 -08:00
Joe Groff
35802bfa36 CheckedContinuation: Add resume(with: Result) for parity with UnsafeContinuation 2021-02-05 11:52:45 -08:00
Doug Gregor
06dc593cec Merge pull request #35264 from DougGregor/concurrent-value-protocol
[Concurrency] Introduce "ConcurrentValue" protocol and checking.
2021-02-05 10:28:26 -08:00
nate-chandler
562eea10cb Merge pull request #35772 from nate-chandler/concurrency/runtime/rdar72357371
[Runtime] Ptrauth for runAsyncAndBlock.
2021-02-05 08:06:29 -08:00
Nate Chandler
c59b01feee [Runtime] Ptrauth for runAsyncAndBlock.
rdar://72357371
2021-02-04 20:19:26 -08:00
Dario Rexin
74e59ab77f [Concurrency] Build C only libdispatch before Swift on non-Darwin pla… (#35738)
* [Concurrency] Build C only libdispatch before Swift on non-Darwin platforms

_Concurrency depends on libdispatch and since it is not available by
default on non-Darwin platforms, it needs to be built before the Swift
project, so that the dependency can be resolved.

* Fix clibdispatch installation and BuildSystem tests

* Fix build system tests on Darwin and formatting
2021-02-04 17:15:30 -08:00
Doug Gregor
a632118d6a Sink ConcurrentValue into the standard library as a marker protocol
By making ConcurrentValue a marker protocol, it no longer has any ABI
impact whatsoever. Sink it down into the Standard Library so it's
easier to use, even from code that isn't building with concurrency
enabled.
2021-02-03 16:43:33 -08:00
Doug Gregor
27e0b1243e [Concurrency] Add the ConcurrentValue protocol.
The ConcurrentValue protocol indicates when a particular type is safe
to share in a concurrent context, e.g., that a copy of a given value
can be safely used concurrently with the value.
2021-02-03 16:43:33 -08:00
Mike Ash
662b553ffe Merge pull request #35620 from mikeash/debug-var-async-task-metadata
[Concurrency] Add a debug variable pointing to the metadata for AsyncTask.
2021-01-29 23:31:17 -05:00
Doug Gregor
c97637cb96 Merge pull request #35655 from DougGregor/concurrent-function-types-sil
[SIL] Add `@concurrent` function types to SIL
2021-01-29 15:43:45 -08:00
Doug Gregor
1f1f703afe Drop @concurrent from parameter to @asyncHandler entry point.
The async handler code doesn't really run concurrently with where it is
launched, despite the implementation currently using `runDetached`
internally. Drop the @concurrent and bitcase it back on when needed.
2021-01-29 09:53:22 -08:00
Saleem Abdulrasool
3cf257fc84 Merge pull request #35585 from compnerd/runless
Concurrency: avoid `CFRunLoopRun` on non-Darwin
2021-01-29 08:50:42 -08:00
Doug Gregor
581e6662b7 Adopt @concurrent in withCancellationHandler. 2021-01-28 13:20:18 -08:00
Doug Gregor
9efb44fde8 Adopt @concurrent in Task APIs 2021-01-28 10:03:09 -08:00
Mike Ash
329af74b15 [Concurrency] Add a debug variable pointing to the metadata for AsyncTask.
Debugging tools can use _swift_concurrency_debug_asyncTaskMetadata to identify memory blocks as async task allocations by looking at their isa/metadata pointer.

rdar://72906895
2021-01-27 13:45:22 -05:00
Arnold Schwaighofer
b0d31730de Merge pull request #35303 from aschwaighofer/introduce_swiftasync_lowering
Add llvm::Attribute::SwiftAsync to the context parameter
2021-01-26 06:03:19 -08:00
Saleem Abdulrasool
62f9050158 Merge pull request #35584 from compnerd/single-threaded-drain
Concurrency: support draining the main queue in single threaded mode
2021-01-25 20:06:32 -08:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
Saleem Abdulrasool
472e842215 Concurrency: avoid CFRunLoopRun on non-Darwin
The CoreFoundation implementation on non-Darwin platforms included in
Foundation is not meant to be used as a general purpose CoreFoundation
implementation.  Since non-Darwin targets do not default to providing a
CoreFoundation implementation, we should generally assume that the
symbol is not present.  This changes the non-Darwin paths to always use
`dispatch_main` rather than `CFRunLoopRun`.
2021-01-25 09:26:08 -08:00
Saleem Abdulrasool
4f740a4784 Concurrency: support draining the main queue in single threaded mode
When built in single threaded mode, the runtime does not use dispatch to
queue the tasks.  As a result, pumping the dispatch main queue will
simply wait indefinitely.  In the single threaded mode, simply halt
execution and drain all pending tasks before returning.  This allows
forward progress in the single threaded mode.
2021-01-25 09:23:04 -08:00
Saleem Abdulrasool
3c9e76d5fe Concurrency: attempt to handle Windows draining
Rather than just simply invoking abort on Windows, attempt to load
dispatch and execute the main loop by looking up `dispatch_main` in the
module.  Assuming that dispatch was used already, the `LoadLibraryW`
will provide the handle to the module currently mapped in.  This still
is not correct, since we do not link to libdispatch, so we cannot have
invoked any dispatch queuing methods.  However, this is better than the
previous behaviour of simply aborting.

This resolves the symptom in SR-14086, but not the underlying problem.
2021-01-24 14:44:11 -08:00
Konrad `ktoso` Malawski
80ee936a72 Revert "[Concurrency] isCanceled spelling to follow guidance" 2021-01-23 07:27:34 +09:00
Arnold Schwaighofer
daa72d3cc5 Add llvm::Attribute::SwiftAsync to the context parameter
* Adds support for generating code that uses swiftasync parameter lowering.

* Currently only arm64's llvm lowering supports the swift_async_context_addr intrinsic.

* Add arm64e pointer signing of updated swift_async_context_addr.

This commit needs the PR llvm-project#2291.

* [runtime] unittests should use just-built compiler if the runtime did

This will start to matter with the introduction of usage of swiftasync parameters which only very recent compilers support.

rdar://71499498
2021-01-22 10:01:55 -08:00
Konrad `ktoso` Malawski
8b37455774 [Concurrency] isCanceled spelling to follow guidance 2021-01-22 12:09:19 +09:00
Joe Groff
bd85d8308d Merge pull request #35392 from jckarter/checked-continuation-trap
Concurrency: Have CheckedContinuation trap on double resume.
2021-01-15 16:07:12 -08:00