authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-27 17:31:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-28 15:10:48-04:00
log4f594527c02985272d61c198d7c5aafa7d777e50
tree0516075056d80bfc01ee779288aad90c9350b0f6
parenta3222b5ff1d6698e3e72890276900de34c85d11d
signaturelock-open Commit is signed but in an unrecognized format.

detect async fn recursion and emit compile error


2 files changed, 8 insertions(+), 0 deletions(-)

src/analyze.cpp+7
...@@ -4398,6 +4398,7 @@ static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode...@@ -4398,6 +4398,7 @@ static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode
4398 }4398 }
4399 }4399 }
4400 if (callee_is_async) {4400 if (callee_is_async) {
4401 bool bad_recursion = (fn->inferred_async_node == inferred_async_none);
4401 fn->inferred_async_node = call_node;4402 fn->inferred_async_node = call_node;
4402 fn->inferred_async_fn = callee;4403 fn->inferred_async_fn = callee;
4403 if (must_not_be_async) {4404 if (must_not_be_async) {
...@@ -4407,6 +4408,12 @@ static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode...@@ -4407,6 +4408,12 @@ static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode
4407 add_async_error_notes(g, msg, fn);4408 add_async_error_notes(g, msg, fn);
4408 return ErrorSemanticAnalyzeFail;4409 return ErrorSemanticAnalyzeFail;
4409 }4410 }
4411 if (bad_recursion) {
4412 ErrorMsg *msg = add_node_error(g, fn->proto_node,
4413 buf_sprintf("recursive function cannot be async"));
4414 add_async_error_notes(g, msg, fn);
4415 return ErrorSemanticAnalyzeFail;
4416 }
4410 if (fn->assumed_non_async != nullptr) {4417 if (fn->assumed_non_async != nullptr) {
4411 ErrorMsg *msg = add_node_error(g, fn->proto_node,4418 ErrorMsg *msg = add_node_error(g, fn->proto_node,
4412 buf_sprintf("unable to infer whether '%s' should be async",4419 buf_sprintf("unable to infer whether '%s' should be async",
src/codegen.cpp+1
...@@ -3917,6 +3917,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3917,6 +3917,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3917 if (instruction->modifier == CallModifierAsync) {3917 if (instruction->modifier == CallModifierAsync) {
3918 frame_result_loc = result_loc;3918 frame_result_loc = result_loc;
3919 } else {3919 } else {
3920 src_assert(instruction->frame_result_loc != nullptr, instruction->base.source_node);
3920 frame_result_loc_uncasted = ir_llvm_value(g, instruction->frame_result_loc);3921 frame_result_loc_uncasted = ir_llvm_value(g, instruction->frame_result_loc);
3921 src_assert(instruction->fn_entry != nullptr, instruction->base.source_node);3922 src_assert(instruction->fn_entry != nullptr, instruction->base.source_node);
3922 frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted,3923 frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted,