Skip to content

Commit 003ca97

Browse files
authored
Merge pull request #33333 from DougGregor/concurrency-syntax-fixes
[Concurrency] Fix syntax tree creation
2 parents f9e54e1 + 6a5522f commit 003ca97

File tree

9 files changed

+39
-8
lines changed

9 files changed

+39
-8
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
397397
SourceLoc awaitLoc = consumeToken(tok::kw___await);
398398
ParserResult<Expr> sub = parseExprUnary(message, isExprBasic);
399399
if (!sub.hasCodeCompletion() && !sub.isNull()) {
400-
ElementContext.setCreateSyntax(SyntaxKind::TryExpr);
400+
ElementContext.setCreateSyntax(SyntaxKind::AwaitExpr);
401401
sub = makeParserResult(new (Context) AwaitExpr(awaitLoc, sub.get()));
402402
}
403403

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,10 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
465465
ParsedFunctionTypeSyntaxBuilder Builder(*SyntaxContext);
466466
Builder.useReturnType(std::move(*SyntaxContext->popIf<ParsedTypeSyntax>()));
467467
Builder.useArrow(SyntaxContext->popToken());
468-
if (asyncLoc.isValid())
469-
Builder.useAsyncKeyword(SyntaxContext->popToken());
470468
if (throwsLoc.isValid())
471469
Builder.useThrowsOrRethrowsKeyword(SyntaxContext->popToken());
470+
if (asyncLoc.isValid())
471+
Builder.useAsyncKeyword(SyntaxContext->popToken());
472472

473473
auto InputNode(std::move(*SyntaxContext->popIf<ParsedTypeSyntax>()));
474474
if (auto TupleTypeNode = InputNode.getAs<ParsedTupleTypeSyntax>()) {

test/Parse/async-syntax.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -verify-syntax-tree
2+
3+
func asyncGlobal1() async { }
4+
func asyncGlobal2() async throws { }
5+
6+
typealias AsyncFunc1 = () async -> ()
7+
typealias AsyncFunc2 = () async throws -> ()
8+
9+
func testTypeExprs() {
10+
let _ = [() async -> ()]()
11+
let _ = [() async throws -> ()]()
12+
}
13+
14+
func testAwaitOperator() async {
15+
let _ = __await asyncGlobal1()
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func doSomethingBig() async -> Int { return 0 }

test/Serialization/async.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t-scratch)
3+
// RUN: %target-swift-frontend -emit-module -o %t-scratch/def_async~partial.swiftmodule -primary-file %S/Inputs/def_async.swift -module-name def_async -enable-experimental-concurrency
4+
// RUN: %target-swift-frontend -merge-modules -emit-module -parse-as-library -enable-testing %t-scratch/def_async~partial.swiftmodule -module-name def_async -o %t/def_async.swiftmodule -enable-experimental-concurrency
5+
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown -enable-experimental-concurrency
6+
7+
import def_async
8+
9+
func testDoSomethingBig() {
10+
let _: () -> Int = doSomethingBig // expected-error{{cannot convert value of type '() async -> Int' to specified type '() -> Int'}}
11+
}

unittests/Syntax/TypeSyntaxTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ TEST(TypeSyntaxTests, FunctionTypeMakeAPIs) {
471471
auto Int = SyntaxFactory::makeTypeIdentifier("Int", {}, {});
472472
auto IntArg = SyntaxFactory::makeBlankTupleTypeElement()
473473
.withType(Int);
474-
auto Async = SyntaxFactory::makeContextualKeyword(
474+
auto Async = SyntaxFactory::makeIdentifier(
475475
"async", { }, { Trivia::spaces(1) });
476476
auto Throws = SyntaxFactory::makeThrowsKeyword({}, { Trivia::spaces(1) });
477477
auto Rethrows = SyntaxFactory::makeRethrowsKeyword({},

utils/gyb_syntax_support/DeclNodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
Node('FunctionSignature', kind='Syntax',
7777
children=[
7878
Child('Input', kind='ParameterClause'),
79-
Child('AsyncKeyword', kind='ContextualKeywordToken',
79+
Child('AsyncKeyword', kind='IdentifierToken',
80+
classification='Keyword',
8081
text_choices=['async'], is_optional=True),
8182
Child('ThrowsOrRethrowsKeyword', kind='Token',
8283
is_optional=True,

utils/gyb_syntax_support/ExprNodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@
191191
# NOTE: This appears only in SequenceExpr.
192192
Node('ArrowExpr', kind='Expr',
193193
children=[
194-
Child('AsyncKeyword', kind='ContextualKeywordToken',
194+
Child('AsyncKeyword', kind='IdentifierToken',
195+
classification='Keyword',
195196
text_choices=['async'], is_optional=True),
196197
Child('ThrowsToken', kind='ThrowsToken',
197198
is_optional=True),

utils/gyb_syntax_support/TypeNodes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@
167167
Child('Arguments', kind='TupleTypeElementList',
168168
collection_element_name='Argument'),
169169
Child('RightParen', kind='RightParenToken'),
170-
Child('AsyncKeyword', kind='Token', text_choices=['async'],
171-
is_optional=True),
170+
Child('AsyncKeyword', kind='IdentifierToken',
171+
classification='Keyword',
172+
text_choices=['async'], is_optional=True),
172173
Child('ThrowsOrRethrowsKeyword', kind='Token',
173174
is_optional=True,
174175
token_choices=[

0 commit comments

Comments
 (0)