Commit Graph

20 Commits

Author SHA1 Message Date
Alex Martini
70536cd56a Match parameter name in docs to declaration 2024-08-01 10:28:26 -07:00
Slava Pestov
61d00cacd6 Concurrency: Fix default type witness for AsyncSequence.Failure
Setting this to Self.AsyncIterator.Failure doesn't work because
we replace it with its reduced type Self.Failure, and then if
you run a binary compiled against an older version of the stdlib
that does not declare the Failure associated type, we hit
infinite recursion while instantiating the witness table and
trying to populate the default type witness.

Instead, let's set the default to `any Error`. Associated type
inference is already smart enough to infer the type witness from
the AsyncIterator's Failure type; we don't need to rely on the
default mechanism for that.

Fixes rdar://129605725.
2024-06-14 22:43:49 -04:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Doug Gregor
3482ca02ad Add availability for the Failure associated type of async sequences 2024-01-25 16:04:46 -08:00
Doug Gregor
bb7a563e6c Switch async for-each loop over to _nextElement and drop @rethrows.
This couples together several changes to move entirely from
`@rethrows` over to typed throws:

* Use the `Failure` type to determine whether an async for-each loop
will throw, rather than depending on rethrows checking

* Introduce a special carve-out for `rethrows` functions that have a
generic requirement on an `AsyncSequence` or `AsyncIteratorProtocol`,
which uses that requirement's `Failure` type as potentially being part
of the thrown error type. This allows existing generic functions like
the following to continue to work:

    func f<S: AsyncSequence>(_: S) rethrows

* Switch SIL generation for the async for-each loop from the prior
`next()` over to the typed-throws version `_nextElement`.

* Remove `@rethrows` from `AsyncSequence` and `AsyncIteratorProtocol`
entirely. We are now fully dependent on typed throws.
2024-01-25 16:04:43 -08:00
Doug Gregor
a5bdb12b48 Adopt typed throws in AsyncIteratorProtocol and AsyncSequence
Introduce a new associated type `Failure` into the two protocols involved
in async sequences, which represents the type thrown when the sequence
fails. Introduce a defaulted `_nextElement()` operations that throws
`Failure` or produces the next element of the sequence. Provide a
default implementation of `_nextElement()` in terms of `next()` that
force-cases the thrown error to the `Failure` type.

Introduce special associated type inference logic for the `Failure`
type of an `AsyncIteratorProtocol` conformance when there is no
specific _nextElement()` witness. This inference logic looks at the
witness for `next()`:
* If `next()` throws nothing, `Failure` is inferred to `Never`.
* If `next()` throws, `Failure` is inferred to `any Error`.
* If `next()` rethrows, `Failure` is inferred to `T.Failure`, where
`T` is the first type parameter with a conformance to either
`AsyncSequence` or `AsyncIteratorProtocol`.

The default implementation and the inference rule, together, allow
existing async sequences to continue working as before, and set us up
for changing the contract of the `async for` loop to use
`_nextIterator()` rather than `next()`.

Give `AsyncSequence` and `AsyncIteratorProtocol` primary associated
types for the element and failure types, which will allow them to be
used more generally with existential and opaque types.
2024-01-25 16:04:42 -08:00
Jager-yoo
9b2b8b3a49 [stdlib] Correct actual print outputs in Concurrency files 2022-12-19 23:40:03 +09:00
Jager-yoo
b9bbe62006 [Concurrency] Revise Async- related files doc
- Revise '// Prints' comments style like the other stdlib files
- Remove verbose string interpolations and extra spaces
- Remove some unneeded parentheses
- Replace the majority of ' : ' with ': '
- Fix wrong indentation
- Keep files with a single empty line at the end
2022-05-16 14:55:27 +09:00
Alex Martini
4ad006e35c Match verb to its subject. 2022-02-09 17:22:52 -08:00
Alex Martini
64ab9dda79 Cherry pick Swift 5.5 doc changes in AsyncSequence.swift 2021-11-09 15:34:12 -08:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Stephen Celis
093c59da41 Fix AsyncSequence documentation typo 2021-06-17 10:55:01 -05:00
Chris Adamson
fcb91582c2 Better abstract for associatedtype AsyncIterator 2021-05-27 09:47:06 -04:00
Chris Adamson
7aac571b25 Correct indentation. 2021-05-27 09:41:32 -04:00
Chris Adamson
12d5d8edef Correct placement of doc comments in AsyncSequence
Also remove stray characters in doc comments for Actor, MainActor.
2021-05-27 09:32:48 -04:00
Chris Adamson
af4ebb4c46 Provide doc comments for AsyncSequence and related types (#37383)
* First draft docs for iterator, sequence type.

Also drop(while:), to get a feel for the AsyncSequence->AsyncSequence cases.

* Source docs for contains and reduce.

* Docs for methods in AsyncSequence.

This covers all the methods that return a single value. Still working on the extension methods that return new sequences.

* Early source docs for dropFirst(_:) and its type

* Correct doc format for dropFirst(_:).

* Prefix, plus some fixes.

* Docs for prefix(while:).

* Apply Philippe's snippet fixes.

* First draft docs on the map sequences.

Plus miscellaneous fixes throughout.

* Show result of flatMap example.

* More explicit cancellation guidance.

* Convert snippets to trailing closures.

* Correct misplaced doc comments.

* Apply suggestions from code review

Co-authored-by: Philippe Hausler <phausler@apple.com>

* Apply editorial feedback.

* Apply additional editorial feedback.

* Apply suggestions from code review

Co-authored-by: bjlanier <blanier@apple.com>

* Apply further editorial feedback.

Co-authored-by: Chris Adamson <cadamson@apple.com>
Co-authored-by: Philippe Hausler <phausler@apple.com>
Co-authored-by: bjlanier <blanier@apple.com>
2021-05-14 10:16:36 -04:00
Alexis Laferrière
10d115bd5c [Concurrency] Use the SwiftStdlib 5.5 macro instead of 9999 versions 2021-05-04 09:30:58 -07:00
Mike Ash
1173b737aa [Concurrency] Add availability to Concurrency APIs.
This allows programs to target older OSes while using Concurrency behind an availability check. When targeting older OSes, the symbols are weak-linked and the compiler will require the use of Concurrency features to be guarded by an availability check.

rdar://75850003
2021-04-01 10:42:08 -04: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
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