authorgravatar for mathieu.guaypaquet@gmail.comMathieu Guay-Paquet <mathieu.guaypaquet@gmail.com> 2021-02-16 23:43:36-05:00
committergravatar for mathieu.guaypaquet@gmail.comMathieu Guay-Paquet <mathieu.guaypaquet@gmail.com> 2021-02-16 23:43:36-05:00
log93f8110e5d9ca7e3ac81b33edd38709fac2c6acd
tree058d70c0bd9568e9a6ffa91c4d4fcaad7b6db68d
parentc0cfbe98f3069d1aabb29fb0e795c6582e88b75e

Allow async in nosuspend scope

Starting an async function call is actually a synchronous operation, since the caller is not awaiting on the callee for a return value. This commit removes the compiler code which generates the error and updates the relevant test case. In the presence of CallModifierAsync, the callee is expected to suspend, so it should not be changed to CallModifierNoSuspend.

2 files changed, 1 insertions(+), 7 deletions(-)

src/stage1/ir.cpp+1-6
...@@ -7607,12 +7607,7 @@ static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node,...@@ -7607,12 +7607,7 @@ static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node,
76077607
7608 bool is_nosuspend = get_scope_nosuspend(scope) != nullptr;7608 bool is_nosuspend = get_scope_nosuspend(scope) != nullptr;
7609 CallModifier modifier = node->data.fn_call_expr.modifier;7609 CallModifier modifier = node->data.fn_call_expr.modifier;
7610 if (is_nosuspend) {7610 if (is_nosuspend && modifier != CallModifierAsync) {
7611 if (modifier == CallModifierAsync) {
7612 add_node_error(irb->codegen, node,
7613 buf_sprintf("async call in nosuspend scope"));
7614 return irb->codegen->invalid_inst_src;
7615 }
7616 modifier = CallModifierNoSuspend;7611 modifier = CallModifierNoSuspend;
7617 }7612 }
76187613
test/compile_errors.zig-1
...@@ -1027,7 +1027,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1027,7 +1027,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1027 \\}1027 \\}
1028 \\fn foo() void {}1028 \\fn foo() void {}
1029 , &[_][]const u8{1029 , &[_][]const u8{
1030 "tmp.zig:3:21: error: async call in nosuspend scope",
1031 "tmp.zig:4:9: error: suspend in nosuspend scope",1030 "tmp.zig:4:9: error: suspend in nosuspend scope",
1032 });1031 });
10331032