authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-04-19 17:20:25+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-20 22:39:34-04:00
logaca6b7018443bfc012f39be486f848d6e62c532c
tree2951e80d75b33e4409010ad1f803ddbbc300bdca
parent32e5248820a71895ed2833bdc1f91826c7a4dba7

stage1: Handle errors when generating block IR

Closes #5005

3 files changed, 19 insertions(+), 4 deletions(-)

src/analyze.cpp+3-1
......@@ -4610,7 +4610,9 @@ bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *sour
46104610 return false;
46114611 } else if (infer_fn->anal_state == FnAnalStateReady) {
46124612 analyze_fn_body(g, infer_fn);
4613 if (err_set_type->data.error_set.incomplete) {
4613 if (infer_fn->anal_state == FnAnalStateInvalid ||
4614 err_set_type->data.error_set.incomplete)
4615 {
46144616 assert(g->errors.length != 0);
46154617 return false;
46164618 }
src/ast_render.cpp+1-1
......@@ -571,7 +571,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
571571 {
572572 const char *defer_str = defer_string(node->data.defer.kind);
573573 fprintf(ar->f, "%s ", defer_str);
574 render_node_grouped(ar, node->data.return_expr.expr);
574 render_node_grouped(ar, node->data.defer.expr);
575575 break;
576576 }
577577 case NodeTypeVariableDeclaration:
src/ir.cpp+15-2
......@@ -5408,11 +5408,19 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54085408 }
54095409
54105410 bool is_continuation_unreachable = false;
5411 bool found_invalid_inst = false;
54115412 IrInstSrc *noreturn_return_value = nullptr;
54125413 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
54135414 AstNode *statement_node = block_node->data.block.statements.at(i);
54145415
54155416 IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope);
5417 if (statement_value == irb->codegen->invalid_inst_src) {
5418 // keep generating all the elements of the block in case of error,
5419 // we want to collect other compile errors
5420 found_invalid_inst = true;
5421 continue;
5422 }
5423
54165424 is_continuation_unreachable = instr_is_unreachable(statement_value);
54175425 if (is_continuation_unreachable) {
54185426 // keep the last noreturn statement value around in case we need to return it
......@@ -5420,7 +5428,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54205428 }
54215429 // This logic must be kept in sync with
54225430 // [STMT_EXPR_TEST_THING] <--- (search this token)
5423 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_inst_src) {
5431 if (statement_node->type == NodeTypeDefer) {
54245432 // defer starts a new scope
54255433 child_scope = statement_node->data.defer.child_scope;
54265434 assert(child_scope);
......@@ -5428,12 +5436,15 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54285436 // variable declarations start a new scope
54295437 IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value;
54305438 child_scope = decl_var_instruction->var->child_scope;
5431 } else if (statement_value != irb->codegen->invalid_inst_src && !is_continuation_unreachable) {
5439 } else if (!is_continuation_unreachable) {
54325440 // this statement's value must be void
54335441 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
54345442 }
54355443 }
54365444
5445 if (found_invalid_inst)
5446 return irb->codegen->invalid_inst_src;
5447
54375448 if (is_continuation_unreachable) {
54385449 assert(noreturn_return_value != nullptr);
54395450 if (block_node->data.block.name == nullptr || incoming_blocks.length == 0) {
......@@ -9905,6 +9916,8 @@ static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode
99059916 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
99069917 Scope *child_scope = &suspend_scope->base;
99079918 IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
9919 if (susp_res == irb->codegen->invalid_inst_src)
9920 return irb->codegen->invalid_inst_src;
99089921 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
99099922 }
99109923