Skip to content

Commit 7fc0b2c

Browse files
authored
Merge pull request #35954 from DougGregor/enable-se-0298
[SE-0298: Async/Await: Sequences] Enable by default.
2 parents 55199f5 + dafe4fa commit 7fc0b2c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ Swift Next
6161
}
6262
```
6363

64+
* [SE-0298][]:
65+
66+
The "for" loop can be used to traverse asynchronous sequences in asynchronous code:
67+
68+
```swift
69+
for try await line in myFile.lines() {
70+
// Do something with each line
71+
}
72+
```
73+
74+
Asynchronous for loops use asynchronous sequences, defined by the protocol
75+
`AsyncSequence` and its corresponding `AsyncIterator`.
76+
6477
**Add new entries to the top of this section, not here!**
6578

6679
Swift 5.4
@@ -8309,6 +8322,7 @@ Swift 1.0
83098322
[SE-0286]: <https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md>
83108323
[SE-0287]: <https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md>
83118324
[SE-0296]: <https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md>
8325+
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
83128326

83138327
[SR-75]: <https://bugs.swift.org/browse/SR-75>
83148328
[SR-106]: <https://bugs.swift.org/browse/SR-106>

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,11 +2127,9 @@ ParserResult<Stmt> Parser::parseStmtForEach(LabeledStmtInfo LabelInfo) {
21272127
SourceLoc AwaitLoc;
21282128
SourceLoc TryLoc;
21292129

2130-
if (shouldParseExperimentalConcurrency() &&
2131-
Tok.isContextualKeyword("await")) {
2130+
if (Tok.isContextualKeyword("await")) {
21322131
AwaitLoc = consumeToken();
2133-
} else if (shouldParseExperimentalConcurrency() &&
2134-
Tok.is(tok::kw_try)) {
2132+
} else if (Tok.is(tok::kw_try)) {
21352133
TryLoc = consumeToken();
21362134
if (Tok.isContextualKeyword("await")) {
21372135
AwaitLoc = consumeToken();

test/Parse/foreach_async.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
1+
// RUN: %target-typecheck-verify-swift
22
// REQUIRES: concurrency
3+
import _Concurrency
34

45
struct AsyncRange<Bound: Comparable & Strideable>: AsyncSequence, AsyncIteratorProtocol where Bound.Stride : SignedInteger {
56
var range: Range<Bound>.Iterator

0 commit comments

Comments
 (0)