Skip to content

Commit d3d4d9a

Browse files
Update 0421-generalize-async-sequence.md (#2331)
* Update "5.11" to "6.0". * Fix "Simiarly" typo.
1 parent da5f77d commit d3d4d9a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

proposals/0421-generalize-async-sequence.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ protocol AsyncIteratorProtocol<Element, Failure> {
7979

8080
mutating func next() async throws -> Element?
8181

82-
@available(SwiftStdlib 5.11, *)
82+
@available(SwiftStdlib 6.0, *)
8383
associatedtype Failure: Error = any Error
8484

85-
@available(SwiftStdlib 5.11, *)
85+
@available(SwiftStdlib 6.0, *)
8686
mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Element?
8787
}
8888

@@ -91,7 +91,7 @@ public protocol AsyncSequence<Element, Failure> {
9191
associatedtype AsyncIterator: AsyncIteratorProtocol
9292
associatedtype Element where AsyncIterator.Element == Element
9393

94-
@available(SwiftStdlib 5.11, *)
94+
@available(SwiftStdlib 6.0, *)
9595
associatedtype Failure = AsyncIterator.Failure where AsyncIterator.Failure == Failure
9696

9797
func makeAsyncIterator() -> AsyncIterator
@@ -108,7 +108,7 @@ Concrete `AsyncSequence` and `AsyncIteratorProtocol` types determine whether cal
108108

109109
#### Error type inference from `for try await` loops
110110

111-
The `Failure` associated type is only accessible at runtime in the Swift 5.11 standard library; code running against older standard library versions does not include the `Failure` requirement in the witness tables for `AsyncSequence` and `AsyncIteratorProtocol` conformances. This impacts error type inference from `for try await` loops.
111+
The `Failure` associated type is only accessible at runtime in the Swift 6.0 standard library; code running against older standard library versions does not include the `Failure` requirement in the witness tables for `AsyncSequence` and `AsyncIteratorProtocol` conformances. This impacts error type inference from `for try await` loops.
112112

113113
When the thrown error type of an `AsyncIteratorProtocol` is available, either through the associated type witness (because the context has appropriate availability) or because the iterator type is concrete, iteration over an async sequence throws its `Failure` type:
114114

@@ -181,7 +181,7 @@ Because existing `AsyncIteratorProtocol`-conforming types only implement `next()
181181
extension AsyncIteratorProtocol {
182182
/// Default implementation of `next(isolation:)` in terms of `next()`, which is
183183
/// required to maintain backward compatibility with existing async iterators.
184-
@available(SwiftStdlib 5.11, *)
184+
@available(SwiftStdlib 6.0, *)
185185
@available(*, deprecated, message: "Provide an implementation of 'next(isolation:)'")
186186
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Element? {
187187
nonisolated(unsafe) var unsafeIterator = self
@@ -202,15 +202,15 @@ To enable conformances of `AsyncIteratorProtocol` to only implement `next(isolat
202202

203203
```swift
204204
extension AsyncIteratorProtocol {
205-
@available(SwiftStdlib 5.11, *)
205+
@available(SwiftStdlib 6.0, *)
206206
public mutating func next() async throws -> Element? {
207207
// Callers to `next()` will always run `next(isolation:)` on the generic executor.
208208
try await next(isolation: nil)
209209
}
210210
}
211211
```
212212

213-
Both function requirements of `AsyncIteratorProtocol` have default implementations that are written in terms of each other, meaning that it is a programmer error to implement neither of them. Types that are available prior to the Swift 5.11 standard library must provide an implementation of `next()`, because the default implementation is only available with the Swift 5.11 standard library.
213+
Both function requirements of `AsyncIteratorProtocol` have default implementations that are written in terms of each other, meaning that it is a programmer error to implement neither of them. Types that are available prior to the Swift 6.0 standard library must provide an implementation of `next()`, because the default implementation is only available with the Swift 6.0 standard library.
214214

215215
To avoid silently allowing conformances that implement neither requirement, and to facilitate the transition of conformances from `next()` to `next(isolation:)`, we add a new availability rule where the witness checker diagnoses a protocol conformance that uses an deprecated, obsoleted, or unavailable default witness implementation. Deprecated implementations will produce a warning, while obsoleted and unavailable implementations will produce an error.
216216

@@ -242,11 +242,11 @@ This proposal is purely an extension of the ABI of the standard library and does
242242

243243
## Implications on adoption
244244

245-
The associated `Failure` types of `AsyncSequence` and `AsyncIteratorProtocol` are only available at runtime with the Swift 5.11 standard library, because code that runs against prior standard library versions does not have a witness table entry for `Failure`. Code that needs to access the `Failure` type through the associated type, e.g. to dynamic cast to it or constrain it in a generic signature, must be availability constrained. For this reason, the default implementations of `next()` and `next(isolation:)` have the same availability as the Swift 5.11 standard library.
245+
The associated `Failure` types of `AsyncSequence` and `AsyncIteratorProtocol` are only available at runtime with the Swift 6.0 standard library, because code that runs against prior standard library versions does not have a witness table entry for `Failure`. Code that needs to access the `Failure` type through the associated type, e.g. to dynamic cast to it or constrain it in a generic signature, must be availability constrained. For this reason, the default implementations of `next()` and `next(isolation:)` have the same availability as the Swift 6.0 standard library.
246246

247-
This means that concrete `AsyncIteratorProtocol` conformances cannot switch over to implementing `next(isolation:)` only (without providing an implementation of `next()`) if they are available earlier than the Swift 5.11 standard library.
247+
This means that concrete `AsyncIteratorProtocol` conformances cannot switch over to implementing `next(isolation:)` only (without providing an implementation of `next()`) if they are available earlier than the Swift 6.0 standard library.
248248

249-
Simiarly, primary associated types of `AsyncSequence` and `AsyncIteratorProtocol` must be gated behind Swift 5.11 availability.
249+
Similarly, primary associated types of `AsyncSequence` and `AsyncIteratorProtocol` must be gated behind Swift 6.0 availability.
250250

251251
Once the concrete `AsyncIteratorProtocol` types in the standard library, such as `Async{Throwing}Stream.Iterator`, implement `next(isolation:)` directly, code that iterates over those concrete `AsyncSequence` types in an actor-isolated context may exhibit fewer hops to the generic executor at runtime.
252252

0 commit comments

Comments
 (0)