From 540d2b03b1e19fa86ffc384fdef89c564c411c98 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 12 Feb 2021 13:37:56 -0800 Subject: [PATCH 1/2] [SE-0298: Async/Await: Sequences] Enable by default. One still needs to import the _Concurrency library to use it. --- CHANGELOG.md | 14 ++++++++++++++ lib/Parse/ParseStmt.cpp | 6 ++---- test/Parse/foreach_async.swift | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e617f12c71d67..cf1adc1cae404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,19 @@ Swift Next } ``` +* [SE-0298][]: + + The "for" loop can be used to traverse asynchronous sequences in asynchronous code: + + ```swift + for try await line in myFile.lines() { + // Do something with each line + } + ``` + + Asynchronous for loops use asynchronous sequences, defined by the protocol + `AsyncSequence` and its corresponding `AsyncIterator`. + **Add new entries to the top of this section, not here!** Swift 5.4 @@ -8309,6 +8322,7 @@ Swift 1.0 [SE-0286]: [SE-0287]: [SE-0296]: +[SE-0298: [SR-75]: [SR-106]: diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index cee8cf9b6ae84..7320136ee1ca6 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -2127,11 +2127,9 @@ ParserResult Parser::parseStmtForEach(LabeledStmtInfo LabelInfo) { SourceLoc AwaitLoc; SourceLoc TryLoc; - if (shouldParseExperimentalConcurrency() && - Tok.isContextualKeyword("await")) { + if (Tok.isContextualKeyword("await")) { AwaitLoc = consumeToken(); - } else if (shouldParseExperimentalConcurrency() && - Tok.is(tok::kw_try)) { + } else if (Tok.is(tok::kw_try)) { TryLoc = consumeToken(); if (Tok.isContextualKeyword("await")) { AwaitLoc = consumeToken(); diff --git a/test/Parse/foreach_async.swift b/test/Parse/foreach_async.swift index 2bd0c23562650..9c8309b54b642 100644 --- a/test/Parse/foreach_async.swift +++ b/test/Parse/foreach_async.swift @@ -1,5 +1,6 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency +// RUN: %target-typecheck-verify-swift // REQUIRES: concurrency +import _Concurrency struct AsyncRange: AsyncSequence, AsyncIteratorProtocol where Bound.Stride : SignedInteger { var range: Range.Iterator From dafe4fa9036dd4f5e326e98789d2626ee20988a9 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 12 Feb 2021 14:12:07 -0800 Subject: [PATCH 2/2] Fix typo in ChangeLog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf1adc1cae404..8198a3127a505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8322,7 +8322,7 @@ Swift 1.0 [SE-0286]: [SE-0287]: [SE-0296]: -[SE-0298: +[SE-0298]: [SR-75]: [SR-106]: