| ... | ... | @@ -891,6 +891,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) { |
| 891 | 891 | return IrInstructionIdAlignCast; |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) { |
| 895 | return IrInstructionIdImplicitCast; |
| 896 | } |
| 897 | |
| 894 | 898 | static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) { |
| 895 | 899 | return IrInstructionIdOpaqueType; |
| 896 | 900 | } |
| ... | ... | @@ -1574,17 +1578,15 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1574 | 1578 | } |
| 1575 | 1579 | |
| 1576 | 1580 | static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1577 | | ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *ptr) |
| 1581 | ZigVar *var, IrInstruction *align_value, IrInstruction *ptr) |
| 1578 | 1582 | { |
| 1579 | 1583 | IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node); |
| 1580 | 1584 | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| 1581 | 1585 | decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1582 | 1586 | decl_var_instruction->var = var; |
| 1583 | | decl_var_instruction->var_type = var_type; |
| 1584 | 1587 | decl_var_instruction->align_value = align_value; |
| 1585 | 1588 | decl_var_instruction->ptr = ptr; |
| 1586 | 1589 | |
| 1587 | | if (var_type != nullptr) ir_ref_instruction(var_type, irb->current_basic_block); |
| 1588 | 1590 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); |
| 1589 | 1591 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1590 | 1592 | |
| ... | ... | @@ -1655,27 +1657,6 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1655 | 1657 | return &instruction->base; |
| 1656 | 1658 | } |
| 1657 | 1659 | |
| 1658 | | static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) { |
| 1659 | | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); |
| 1660 | | instruction->ptr = ptr; |
| 1661 | | |
| 1662 | | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1663 | | |
| 1664 | | return &instruction->base; |
| 1665 | | } |
| 1666 | | |
| 1667 | | static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1668 | | IrInstruction *value) |
| 1669 | | { |
| 1670 | | IrInstructionPtrTypeChild *instruction = ir_build_instruction<IrInstructionPtrTypeChild>( |
| 1671 | | irb, scope, source_node); |
| 1672 | | instruction->value = value; |
| 1673 | | |
| 1674 | | ir_ref_instruction(value, irb->current_basic_block); |
| 1675 | | |
| 1676 | | return &instruction->base; |
| 1677 | | } |
| 1678 | | |
| 1679 | 1660 | static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) { |
| 1680 | 1661 | IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node); |
| 1681 | 1662 | instruction->is_cold = is_cold; |
| ... | ... | @@ -2780,6 +2761,19 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode |
| 2780 | 2761 | return &instruction->base; |
| 2781 | 2762 | } |
| 2782 | 2763 | |
| 2764 | static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2765 | IrInstruction *dest_type, IrInstruction *target) |
| 2766 | { |
| 2767 | IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node); |
| 2768 | instruction->dest_type = dest_type; |
| 2769 | instruction->target = target; |
| 2770 | |
| 2771 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 2772 | ir_ref_instruction(target, irb->current_basic_block); |
| 2773 | |
| 2774 | return &instruction->base; |
| 2775 | } |
| 2776 | |
| 2783 | 2777 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2784 | 2778 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); |
| 2785 | 2779 | |
| ... | ... | @@ -3199,11 +3193,10 @@ static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstructio |
| 3199 | 3193 | } |
| 3200 | 3194 | |
| 3201 | 3195 | static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3202 | | IrInstruction *value, LVal lval, ResultLoc *result_loc) |
| 3196 | IrInstruction *value, ResultLoc *result_loc) |
| 3203 | 3197 | { |
| 3204 | 3198 | IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node); |
| 3205 | 3199 | instruction->value = value; |
| 3206 | | instruction->lval = lval; |
| 3207 | 3200 | instruction->result_loc = result_loc; |
| 3208 | 3201 | |
| 3209 | 3202 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -5399,8 +5392,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode |
| 5399 | 5392 | } |
| 5400 | 5393 | |
| 5401 | 5394 | static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) { |
| 5402 | | // TODO remove the lval parameter here |
| 5403 | | ir_build_end_expr(irb, scope, inst->source_node, inst, LValNone, result_loc); |
| 5395 | ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc); |
| 5404 | 5396 | return inst; |
| 5405 | 5397 | } |
| 5406 | 5398 | |
| ... | ... | @@ -5607,9 +5599,12 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5607 | 5599 | return irb->codegen->invalid_instruction; |
| 5608 | 5600 | } |
| 5609 | 5601 | |
| 5602 | // Used for the type expr and the align expr |
| 5603 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); |
| 5604 | |
| 5610 | 5605 | IrInstruction *type_instruction; |
| 5611 | 5606 | if (variable_declaration->type != nullptr) { |
| 5612 | | type_instruction = ir_gen_node(irb, variable_declaration->type, scope); |
| 5607 | type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope); |
| 5613 | 5608 | if (type_instruction == irb->codegen->invalid_instruction) |
| 5614 | 5609 | return type_instruction; |
| 5615 | 5610 | } else { |
| ... | ... | @@ -5635,7 +5630,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5635 | 5630 | |
| 5636 | 5631 | IrInstruction *align_value = nullptr; |
| 5637 | 5632 | if (variable_declaration->align_expr != nullptr) { |
| 5638 | | align_value = ir_gen_node(irb, variable_declaration->align_expr, scope); |
| 5633 | align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope); |
| 5639 | 5634 | if (align_value == irb->codegen->invalid_instruction) |
| 5640 | 5635 | return align_value; |
| 5641 | 5636 | } |
| ... | ... | @@ -5656,19 +5651,24 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5656 | 5651 | result_loc_var->base.id = ResultLocIdVar; |
| 5657 | 5652 | result_loc_var->base.source_instruction = alloca; |
| 5658 | 5653 | result_loc_var->var = var; |
| 5654 | ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr; |
| 5659 | 5655 | |
| 5660 | 5656 | // Temporarily set the name of the IrExecutable to the VariableDeclaration |
| 5661 | 5657 | // so that the struct or enum from the init expression inherits the name. |
| 5662 | 5658 | Buf *old_exec_name = irb->exec->name; |
| 5663 | 5659 | irb->exec->name = variable_declaration->symbol; |
| 5664 | | IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone, |
| 5665 | | &result_loc_var->base); |
| 5660 | IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone, init_result_loc); |
| 5666 | 5661 | irb->exec->name = old_exec_name; |
| 5667 | 5662 | |
| 5668 | 5663 | if (init_value == irb->codegen->invalid_instruction) |
| 5669 | | return init_value; |
| 5664 | return irb->codegen->invalid_instruction; |
| 5665 | |
| 5666 | if (type_instruction != nullptr) { |
| 5667 | IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, node, type_instruction, init_value); |
| 5668 | ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base); |
| 5669 | } |
| 5670 | 5670 | |
| 5671 | | return ir_build_var_decl_src(irb, scope, node, var, type_instruction, align_value, alloca); |
| 5671 | return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca); |
| 5672 | 5672 | } |
| 5673 | 5673 | |
| 5674 | 5674 | static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| ... | ... | @@ -5725,7 +5725,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5725 | 5725 | err_val_ptr, false); |
| 5726 | 5726 | IrInstruction *var_value = node->data.while_expr.var_is_ptr ? |
| 5727 | 5727 | var_ptr_value : ir_build_load_ptr(irb, payload_scope, symbol_node, var_ptr_value); |
| 5728 | | ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, nullptr, var_value); |
| 5728 | ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_value); |
| 5729 | 5729 | } |
| 5730 | 5730 | |
| 5731 | 5731 | ZigList<IrInstruction *> incoming_values = {0}; |
| ... | ... | @@ -5767,7 +5767,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5767 | 5767 | true, false, false, is_comptime); |
| 5768 | 5768 | Scope *err_scope = err_var->child_scope; |
| 5769 | 5769 | IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); |
| 5770 | | ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, nullptr, err_var_value); |
| 5770 | ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_var_value); |
| 5771 | 5771 | |
| 5772 | 5772 | IrInstruction *else_result = ir_gen_node(irb, else_node, err_scope); |
| 5773 | 5773 | if (else_result == irb->codegen->invalid_instruction) |
| ... | ... | @@ -5811,7 +5811,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5811 | 5811 | IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false); |
| 5812 | 5812 | IrInstruction *var_value = node->data.while_expr.var_is_ptr ? |
| 5813 | 5813 | var_ptr_value : ir_build_load_ptr(irb, child_scope, symbol_node, var_ptr_value); |
| 5814 | | ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, nullptr, var_value); |
| 5814 | ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_value); |
| 5815 | 5815 | |
| 5816 | 5816 | ZigList<IrInstruction *> incoming_values = {0}; |
| 5817 | 5817 | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| ... | ... | @@ -5953,14 +5953,6 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5953 | 5953 | if (array_val_ptr == irb->codegen->invalid_instruction) |
| 5954 | 5954 | return array_val_ptr; |
| 5955 | 5955 | |
| 5956 | | IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr); |
| 5957 | | IrInstruction *elem_var_type; |
| 5958 | | if (node->data.for_expr.elem_is_ptr) { |
| 5959 | | elem_var_type = pointer_type; |
| 5960 | | } else { |
| 5961 | | elem_var_type = ir_build_ptr_type_child(irb, parent_scope, elem_node, pointer_type); |
| 5962 | | } |
| 5963 | | |
| 5964 | 5956 | IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node, |
| 5965 | 5957 | ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline); |
| 5966 | 5958 | |
| ... | ... | @@ -5970,7 +5962,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5970 | 5962 | Scope *child_scope = elem_var->child_scope; |
| 5971 | 5963 | |
| 5972 | 5964 | IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); |
| 5973 | | ir_build_var_decl_src(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value); |
| 5965 | ir_build_var_decl_src(irb, child_scope, elem_node, elem_var, nullptr, undefined_value); |
| 5974 | 5966 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); |
| 5975 | 5967 | |
| 5976 | 5968 | AstNode *index_var_source_node; |
| ... | ... | @@ -5985,10 +5977,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5985 | 5977 | } |
| 5986 | 5978 | child_scope = index_var->child_scope; |
| 5987 | 5979 | |
| 5988 | | IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize); |
| 5989 | 5980 | IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0); |
| 5990 | 5981 | IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1); |
| 5991 | | ir_build_var_decl_src(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero); |
| 5982 | ir_build_var_decl_src(irb, child_scope, index_var_source_node, index_var, nullptr, zero); |
| 5992 | 5983 | IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var); |
| 5993 | 5984 | |
| 5994 | 5985 | |
| ... | ... | @@ -6380,7 +6371,6 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 6380 | 6371 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); |
| 6381 | 6372 | Scope *var_scope; |
| 6382 | 6373 | if (var_symbol) { |
| 6383 | | IrInstruction *var_type = nullptr; |
| 6384 | 6374 | bool is_shadowable = false; |
| 6385 | 6375 | bool is_const = true; |
| 6386 | 6376 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| ... | ... | @@ -6388,7 +6378,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 6388 | 6378 | |
| 6389 | 6379 | IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false); |
| 6390 | 6380 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value); |
| 6391 | | ir_build_var_decl_src(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 6381 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value); |
| 6392 | 6382 | var_scope = var->child_scope; |
| 6393 | 6383 | } else { |
| 6394 | 6384 | var_scope = subexpr_scope; |
| ... | ... | @@ -6455,7 +6445,6 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6455 | 6445 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); |
| 6456 | 6446 | Scope *var_scope; |
| 6457 | 6447 | if (var_symbol) { |
| 6458 | | IrInstruction *var_type = nullptr; |
| 6459 | 6448 | bool is_shadowable = false; |
| 6460 | 6449 | IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val); |
| 6461 | 6450 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| ... | ... | @@ -6463,7 +6452,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6463 | 6452 | |
| 6464 | 6453 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false); |
| 6465 | 6454 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value); |
| 6466 | | ir_build_var_decl_src(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 6455 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value); |
| 6467 | 6456 | var_scope = var->child_scope; |
| 6468 | 6457 | } else { |
| 6469 | 6458 | var_scope = subexpr_scope; |
| ... | ... | @@ -6481,14 +6470,13 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6481 | 6470 | if (else_node) { |
| 6482 | 6471 | Scope *err_var_scope; |
| 6483 | 6472 | if (err_symbol) { |
| 6484 | | IrInstruction *var_type = nullptr; |
| 6485 | 6473 | bool is_shadowable = false; |
| 6486 | 6474 | bool is_const = true; |
| 6487 | 6475 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 6488 | 6476 | err_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 6489 | 6477 | |
| 6490 | 6478 | IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); |
| 6491 | | ir_build_var_decl_src(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 6479 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value); |
| 6492 | 6480 | err_var_scope = var->child_scope; |
| 6493 | 6481 | } else { |
| 6494 | 6482 | err_var_scope = subexpr_scope; |
| ... | ... | @@ -6551,8 +6539,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 6551 | 6539 | var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, |
| 6552 | 6540 | target_value_ptr); |
| 6553 | 6541 | } |
| 6554 | | IrInstruction *var_type = nullptr; // infer the type |
| 6555 | | ir_build_var_decl_src(irb, scope, var_symbol_node, var, var_type, nullptr, var_value); |
| 6542 | ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_value); |
| 6556 | 6543 | } else { |
| 6557 | 6544 | child_scope = scope; |
| 6558 | 6545 | } |
| ... | ... | @@ -7018,7 +7005,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7018 | 7005 | is_const, is_const, is_shadowable, is_comptime); |
| 7019 | 7006 | err_scope = var->child_scope; |
| 7020 | 7007 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); |
| 7021 | | ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, nullptr, err_val); |
| 7008 | ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_val); |
| 7022 | 7009 | } else { |
| 7023 | 7010 | err_scope = parent_scope; |
| 7024 | 7011 | } |
| ... | ... | @@ -7509,7 +7496,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7509 | 7496 | IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); |
| 7510 | 7497 | IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type); |
| 7511 | 7498 | ir_build_await_bookkeeping(irb, scope, node, promise_result_type); |
| 7512 | | ir_build_var_decl_src(irb, scope, node, result_var, promise_result_type, nullptr, undefined_value); |
| 7499 | ir_build_var_decl_src(irb, scope, node, result_var, nullptr, undefined_value); |
| 7513 | 7500 | IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var); |
| 7514 | 7501 | ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr); |
| 7515 | 7502 | IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle); |
| ... | ... | @@ -7940,17 +7927,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7940 | 7927 | |
| 7941 | 7928 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 7942 | 7929 | IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); |
| 7943 | | ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type); |
| 7944 | | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); |
| 7945 | 7930 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa |
| 7946 | | ir_build_var_decl_src(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); |
| 7931 | ir_build_var_decl_src(irb, coro_scope, node, promise_var, nullptr, undef); |
| 7947 | 7932 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); |
| 7948 | 7933 | |
| 7949 | 7934 | ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 7950 | 7935 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); |
| 7951 | | IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, |
| 7952 | | get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); |
| 7953 | | ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value); |
| 7936 | ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, nullptr, null_value); |
| 7954 | 7937 | irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var); |
| 7955 | 7938 | |
| 7956 | 7939 | u8_ptr_type = ir_build_const_type(irb, coro_scope, node, |
| ... | ... | @@ -7960,11 +7943,11 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7960 | 7943 | coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr); |
| 7961 | 7944 | coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 7962 | 7945 | IrInstruction *coro_size = ir_build_coro_size(irb, coro_scope, node); |
| 7963 | | ir_build_var_decl_src(irb, coro_scope, node, coro_size_var, nullptr, nullptr, coro_size); |
| 7946 | ir_build_var_decl_src(irb, coro_scope, node, coro_size_var, nullptr, coro_size); |
| 7964 | 7947 | IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node, |
| 7965 | 7948 | ImplicitAllocatorIdArg); |
| 7966 | 7949 | irb->exec->coro_allocator_var = ir_create_var(irb, node, coro_scope, nullptr, true, true, true, const_bool_false); |
| 7967 | | ir_build_var_decl_src(irb, coro_scope, node, irb->exec->coro_allocator_var, nullptr, nullptr, implicit_allocator_ptr); |
| 7950 | ir_build_var_decl_src(irb, coro_scope, node, irb->exec->coro_allocator_var, nullptr, implicit_allocator_ptr); |
| 7968 | 7951 | Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME); |
| 7969 | 7952 | IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name); |
| 7970 | 7953 | IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr); |
| ... | ... | @@ -14375,20 +14358,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z |
| 14375 | 14358 | case ResultLocIdNone: |
| 14376 | 14359 | return nullptr; |
| 14377 | 14360 | case ResultLocIdVar: { |
| 14378 | | // TODO implicit cast? |
| 14379 | 14361 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| 14380 | 14362 | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); |
| 14381 | 14363 | IrInstructionAllocaSrc *alloca_src = |
| 14382 | 14364 | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); |
| 14383 | 14365 | if (alloca_src->base.child == nullptr) { |
| 14384 | | uint32_t align = 0; // TODO |
| 14385 | | bool force_comptime = false; // TODO |
| 14386 | 14366 | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime && |
| 14387 | 14367 | result_loc_var->var->gen_is_const; |
| 14388 | 14368 | IrInstruction *alloca_gen; |
| 14389 | 14369 | if (is_comptime) { |
| 14390 | 14370 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| 14391 | 14371 | } else { |
| 14372 | uint32_t align = 0; |
| 14373 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) { |
| 14374 | return ira->codegen->invalid_instruction; |
| 14375 | } |
| 14376 | bool force_comptime; |
| 14377 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 14378 | return ira->codegen->invalid_instruction; |
| 14392 | 14379 | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, |
| 14393 | 14380 | alloca_src->name_hint, force_comptime); |
| 14394 | 14381 | } |
| ... | ... | @@ -14409,6 +14396,19 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z |
| 14409 | 14396 | zig_unreachable(); |
| 14410 | 14397 | } |
| 14411 | 14398 | |
| 14399 | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { |
| 14400 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 14401 | if (type_is_invalid(dest_type)) |
| 14402 | return ira->codegen->invalid_instruction; |
| 14403 | |
| 14404 | IrInstruction *target = instruction->target->child; |
| 14405 | if (type_is_invalid(target->value.type)) |
| 14406 | return ira->codegen->invalid_instruction; |
| 14407 | |
| 14408 | return ir_implicit_cast(ira, target, dest_type); |
| 14409 | } |
| 14410 | |
| 14411 | |
| 14412 | 14412 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, |
| 14413 | 14413 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, |
| 14414 | 14414 | IrInstruction *async_allocator_inst) |
| ... | ... | @@ -23612,8 +23612,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 23612 | 23612 | if (type_is_invalid(value->value.type)) |
| 23613 | 23613 | return ira->codegen->invalid_instruction; |
| 23614 | 23614 | |
| 23615 | | assert(instruction->lval == LValNone); |
| 23616 | | |
| 23617 | 23615 | if (instruction->result_loc->id == ResultLocIdPeer) { |
| 23618 | 23616 | ResultLocPeer *result_peer = reinterpret_cast<ResultLocPeer *>(instruction->result_loc); |
| 23619 | 23617 | ResultLocPeerParent *peer_parent = result_peer->parent; |
| ... | ... | @@ -23640,7 +23638,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 23640 | 23638 | } |
| 23641 | 23639 | } |
| 23642 | 23640 | IrInstruction *result_loc = ir_resolve_result(ira, instruction->result_loc, value->value.type, value); |
| 23643 | | if (result_loc != nullptr) { |
| 23641 | if (result_loc != nullptr && !type_is_invalid(result_loc->value.type)) { |
| 23644 | 23642 | ir_analyze_store_ptr(ira, &instruction->base, result_loc, value); |
| 23645 | 23643 | } |
| 23646 | 23644 | |
| ... | ... | @@ -23874,6 +23872,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 23874 | 23872 | return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction); |
| 23875 | 23873 | case IrInstructionIdAlignCast: |
| 23876 | 23874 | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); |
| 23875 | case IrInstructionIdImplicitCast: |
| 23876 | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); |
| 23877 | 23877 | case IrInstructionIdOpaqueType: |
| 23878 | 23878 | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); |
| 23879 | 23879 | case IrInstructionIdSetAlignStack: |
| ... | ... | @@ -24165,6 +24165,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24165 | 24165 | case IrInstructionIdTypeInfo: |
| 24166 | 24166 | case IrInstructionIdTypeId: |
| 24167 | 24167 | case IrInstructionIdAlignCast: |
| 24168 | case IrInstructionIdImplicitCast: |
| 24168 | 24169 | case IrInstructionIdOpaqueType: |
| 24169 | 24170 | case IrInstructionIdArgType: |
| 24170 | 24171 | case IrInstructionIdTagType: |