| ... | @@ -164,7 +164,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig | ... | @@ -164,7 +164,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig |
| 164 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); | 164 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); |
| 165 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); | 165 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| 166 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 166 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 167 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); | 167 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing); |
| 168 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); | 168 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); |
| 169 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); | 169 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 170 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc); | 170 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc); |
| ... | @@ -616,10 +616,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { | ... | @@ -616,10 +616,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { |
| 616 | return IrInstructionIdRef; | 616 | return IrInstructionIdRef; |
| 617 | } | 617 | } |
| 618 | | 618 | |
| 619 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) { | | |
| 620 | return IrInstructionIdUnionInit; | | |
| 621 | } | | |
| 622 | | | |
| 623 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { | 619 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { |
| 624 | return IrInstructionIdCompileErr; | 620 | return IrInstructionIdCompileErr; |
| 625 | } | 621 | } |
| ... | @@ -1312,12 +1308,13 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop | ... | @@ -1312,12 +1308,13 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop |
| 1312 | } | 1308 | } |
| 1313 | | 1309 | |
| 1314 | static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1310 | static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1315 | IrInstruction *container_ptr, Buf *field_name) | 1311 | IrInstruction *container_ptr, Buf *field_name, bool initializing) |
| 1316 | { | 1312 | { |
| 1317 | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); | 1313 | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); |
| 1318 | instruction->container_ptr = container_ptr; | 1314 | instruction->container_ptr = container_ptr; |
| 1319 | instruction->field_name_buffer = field_name; | 1315 | instruction->field_name_buffer = field_name; |
| 1320 | instruction->field_name_expr = nullptr; | 1316 | instruction->field_name_expr = nullptr; |
| | 1317 | instruction->initializing = initializing; |
| 1321 | | 1318 | |
| 1322 | ir_ref_instruction(container_ptr, irb->current_basic_block); | 1319 | ir_ref_instruction(container_ptr, irb->current_basic_block); |
| 1323 | | 1320 | |
| ... | @@ -1337,9 +1334,10 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, As | ... | @@ -1337,9 +1334,10 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, As |
| 1337 | } | 1334 | } |
| 1338 | | 1335 | |
| 1339 | static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1336 | static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1340 | IrInstruction *union_ptr, TypeUnionField *field) | 1337 | IrInstruction *union_ptr, TypeUnionField *field, bool initializing) |
| 1341 | { | 1338 | { |
| 1342 | IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node); | 1339 | IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node); |
| | 1340 | instruction->initializing = initializing; |
| 1343 | instruction->union_ptr = union_ptr; | 1341 | instruction->union_ptr = union_ptr; |
| 1344 | instruction->field = field; | 1342 | instruction->field = field; |
| 1345 | | 1343 | |
| ... | @@ -1517,19 +1515,6 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop | ... | @@ -1517,19 +1515,6 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 1517 | return &container_init_fields_instruction->base; | 1515 | return &container_init_fields_instruction->base; |
| 1518 | } | 1516 | } |
| 1519 | | 1517 | |
| 1520 | static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, | | |
| 1521 | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) | | |
| 1522 | { | | |
| 1523 | IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node); | | |
| 1524 | union_init_instruction->union_type = union_type; | | |
| 1525 | union_init_instruction->field = field; | | |
| 1526 | union_init_instruction->init_value = init_value; | | |
| 1527 | | | |
| 1528 | ir_ref_instruction(init_value, irb->current_basic_block); | | |
| 1529 | | | |
| 1530 | return &union_init_instruction->base; | | |
| 1531 | } | | |
| 1532 | | | |
| 1533 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 1518 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1534 | IrInstructionUnreachable *unreachable_instruction = | 1519 | IrInstructionUnreachable *unreachable_instruction = |
| 1535 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); | 1520 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| ... | @@ -4121,7 +4106,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -4121,7 +4106,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode |
| 4121 | if (container_ref_instruction == irb->codegen->invalid_instruction) | 4106 | if (container_ref_instruction == irb->codegen->invalid_instruction) |
| 4122 | return container_ref_instruction; | 4107 | return container_ref_instruction; |
| 4123 | | 4108 | |
| 4124 | return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name); | 4109 | return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false); |
| 4125 | } | 4110 | } |
| 4126 | | 4111 | |
| 4127 | static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) { | 4112 | static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) { |
| ... | @@ -5594,7 +5579,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A | ... | @@ -5594,7 +5579,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5594 | AstNode *expr_node = entry_node->data.struct_val_field.expr; | 5579 | AstNode *expr_node = entry_node->data.struct_val_field.expr; |
| 5595 | | 5580 | |
| 5596 | IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node, | 5581 | IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node, |
| 5597 | container_ptr, name); | 5582 | container_ptr, name, true); |
| 5598 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); | 5583 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 5599 | result_loc_inst->base.id = ResultLocIdInstruction; | 5584 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5600 | result_loc_inst->base.source_instruction = field_ptr; | 5585 | result_loc_inst->base.source_instruction = field_ptr; |
| ... | @@ -6105,7 +6090,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -6105,7 +6090,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6105 | IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue"); | 6090 | IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue"); |
| 6106 | | 6091 | |
| 6107 | Buf *len_field_name = buf_create_from_str("len"); | 6092 | Buf *len_field_name = buf_create_from_str("len"); |
| 6108 | IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name); | 6093 | IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false); |
| 6109 | IrInstruction *len_val = ir_build_load_ptr(irb, parent_scope, node, len_ref); | 6094 | IrInstruction *len_val = ir_build_load_ptr(irb, parent_scope, node, len_ref); |
| 6110 | ir_build_br(irb, parent_scope, node, cond_block, is_comptime); | 6095 | ir_build_br(irb, parent_scope, node, cond_block, is_comptime); |
| 6111 | | 6096 | |
| ... | @@ -7496,7 +7481,7 @@ static IrInstruction *ir_gen_cancel_target(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -7496,7 +7481,7 @@ static IrInstruction *ir_gen_cancel_target(IrBuilder *irb, Scope *scope, AstNode |
| 7496 | IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst); | 7481 | IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst); |
| 7497 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); | 7482 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); |
| 7498 | IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, | 7483 | IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, |
| 7499 | atomic_state_field_name); | 7484 | atomic_state_field_name, false); |
| 7500 | | 7485 | |
| 7501 | // set the is_canceled bit | 7486 | // set the is_canceled bit |
| 7502 | IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node, | 7487 | IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node, |
| ... | @@ -7575,7 +7560,7 @@ static IrInstruction *ir_gen_resume_target(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -7575,7 +7560,7 @@ static IrInstruction *ir_gen_resume_target(IrBuilder *irb, Scope *scope, AstNode |
| 7575 | IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst); | 7560 | IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst); |
| 7576 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); | 7561 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); |
| 7577 | IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, | 7562 | IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, |
| 7578 | atomic_state_field_name); | 7563 | atomic_state_field_name, false); |
| 7579 | | 7564 | |
| 7580 | // clear the is_suspended bit | 7565 | // clear the is_suspended bit |
| 7581 | IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node, | 7566 | IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node, |
| ... | @@ -7642,12 +7627,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -7642,12 +7627,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7642 | | 7627 | |
| 7643 | IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, target_inst); | 7628 | IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, target_inst); |
| 7644 | Buf *result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME); | 7629 | Buf *result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME); |
| 7645 | IrInstruction *result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name); | 7630 | IrInstruction *result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name, false); |
| 7646 | | 7631 | |
| 7647 | if (irb->codegen->have_err_ret_tracing) { | 7632 | if (irb->codegen->have_err_ret_tracing) { |
| 7648 | IrInstruction *err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull); | 7633 | IrInstruction *err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull); |
| 7649 | Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME); | 7634 | Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME); |
| 7650 | IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name); | 7635 | IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name, false); |
| 7651 | ir_build_store_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr); | 7636 | ir_build_store_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr); |
| 7652 | } | 7637 | } |
| 7653 | | 7638 | |
| ... | @@ -7669,7 +7654,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -7669,7 +7654,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7669 | | 7654 | |
| 7670 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); | 7655 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); |
| 7671 | IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, | 7656 | IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, |
| 7672 | atomic_state_field_name); | 7657 | atomic_state_field_name, false); |
| 7673 | | 7658 | |
| 7674 | IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise); | 7659 | IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise); |
| 7675 | IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false); | 7660 | IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false); |
| ... | @@ -7723,12 +7708,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -7723,12 +7708,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7723 | ir_set_cursor_at_end_and_append_block(irb, no_suspend_block); | 7708 | ir_set_cursor_at_end_and_append_block(irb, no_suspend_block); |
| 7724 | if (irb->codegen->have_err_ret_tracing) { | 7709 | if (irb->codegen->have_err_ret_tracing) { |
| 7725 | Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME); | 7710 | Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME); |
| 7726 | IrInstruction *src_err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name); | 7711 | IrInstruction *src_err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name, false); |
| 7727 | IrInstruction *dest_err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull); | 7712 | IrInstruction *dest_err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull); |
| 7728 | ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr); | 7713 | ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr); |
| 7729 | } | 7714 | } |
| 7730 | Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME); | 7715 | Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME); |
| 7731 | IrInstruction *promise_result_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name); | 7716 | IrInstruction *promise_result_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name, false); |
| 7732 | // If the type of the result handle_is_ptr then this does not actually perform a load. But we need it to, | 7717 | // If the type of the result handle_is_ptr then this does not actually perform a load. But we need it to, |
| 7733 | // because we're about to destroy the memory. So we store it into our result variable. | 7718 | // because we're about to destroy the memory. So we store it into our result variable. |
| 7734 | IrInstruction *no_suspend_result = ir_build_load_ptr(irb, scope, node, promise_result_ptr); | 7719 | IrInstruction *no_suspend_result = ir_build_load_ptr(irb, scope, node, promise_result_ptr); |
| ... | @@ -8152,7 +8137,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -8152,7 +8137,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 8152 | build_decl_var_and_init(irb, coro_scope, node, irb->exec->coro_allocator_var, implicit_allocator_ptr, | 8137 | build_decl_var_and_init(irb, coro_scope, node, irb->exec->coro_allocator_var, implicit_allocator_ptr, |
| 8153 | "allocator", const_bool_false); | 8138 | "allocator", const_bool_false); |
| 8154 | Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME); | 8139 | Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME); |
| 8155 | IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name); | 8140 | IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name, false); |
| 8156 | IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr); | 8141 | IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr); |
| 8157 | IrInstruction *maybe_coro_mem_ptr = ir_build_coro_alloc_helper(irb, coro_scope, node, realloc_fn, coro_size); | 8142 | IrInstruction *maybe_coro_mem_ptr = ir_build_coro_alloc_helper(irb, coro_scope, node, realloc_fn, coro_size); |
| 8158 | IrInstruction *alloc_result_is_ok = ir_build_test_nonnull(irb, coro_scope, node, maybe_coro_mem_ptr); | 8143 | IrInstruction *alloc_result_is_ok = ir_build_test_nonnull(irb, coro_scope, node, maybe_coro_mem_ptr); |
| ... | @@ -8172,30 +8157,30 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -8172,30 +8157,30 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 8172 | | 8157 | |
| 8173 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); | 8158 | Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME); |
| 8174 | irb->exec->atomic_state_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, | 8159 | irb->exec->atomic_state_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, |
| 8175 | atomic_state_field_name); | 8160 | atomic_state_field_name, false); |
| 8176 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); | 8161 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); |
| 8177 | ir_build_store_ptr(irb, scope, node, irb->exec->atomic_state_field_ptr, zero); | 8162 | ir_build_store_ptr(irb, scope, node, irb->exec->atomic_state_field_ptr, zero); |
| 8178 | Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME); | 8163 | Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME); |
| 8179 | irb->exec->coro_result_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name); | 8164 | irb->exec->coro_result_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name, false); |
| 8180 | result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME); | 8165 | result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME); |
| 8181 | irb->exec->coro_result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name); | 8166 | irb->exec->coro_result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name, false); |
| 8182 | ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr, irb->exec->coro_result_field_ptr); | 8167 | ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr, irb->exec->coro_result_field_ptr); |
| 8183 | if (irb->codegen->have_err_ret_tracing) { | 8168 | if (irb->codegen->have_err_ret_tracing) { |
| 8184 | // initialize the error return trace | 8169 | // initialize the error return trace |
| 8185 | Buf *return_addresses_field_name = buf_create_from_str(RETURN_ADDRESSES_FIELD_NAME); | 8170 | Buf *return_addresses_field_name = buf_create_from_str(RETURN_ADDRESSES_FIELD_NAME); |
| 8186 | IrInstruction *return_addresses_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, return_addresses_field_name); | 8171 | IrInstruction *return_addresses_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, return_addresses_field_name, false); |
| 8187 | | 8172 | |
| 8188 | Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME); | 8173 | Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME); |
| 8189 | err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name); | 8174 | err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name, false); |
| 8190 | ir_build_mark_err_ret_trace_ptr(irb, scope, node, err_ret_trace_ptr); | 8175 | ir_build_mark_err_ret_trace_ptr(irb, scope, node, err_ret_trace_ptr); |
| 8191 | | 8176 | |
| 8192 | // coordinate with builtin.zig | 8177 | // coordinate with builtin.zig |
| 8193 | Buf *index_name = buf_create_from_str("index"); | 8178 | Buf *index_name = buf_create_from_str("index"); |
| 8194 | IrInstruction *index_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, index_name); | 8179 | IrInstruction *index_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, index_name, false); |
| 8195 | ir_build_store_ptr(irb, scope, node, index_ptr, zero); | 8180 | ir_build_store_ptr(irb, scope, node, index_ptr, zero); |
| 8196 | | 8181 | |
| 8197 | Buf *instruction_addresses_name = buf_create_from_str("instruction_addresses"); | 8182 | Buf *instruction_addresses_name = buf_create_from_str("instruction_addresses"); |
| 8198 | IrInstruction *addrs_slice_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, instruction_addresses_name); | 8183 | IrInstruction *addrs_slice_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, instruction_addresses_name, false); |
| 8199 | | 8184 | |
| 8200 | IrInstruction *slice_value = ir_build_slice(irb, scope, node, return_addresses_ptr, zero, nullptr, false); | 8185 | IrInstruction *slice_value = ir_build_slice(irb, scope, node, return_addresses_ptr, zero, nullptr, false); |
| 8201 | ir_build_store_ptr(irb, scope, node, addrs_slice_ptr, slice_value); | 8186 | ir_build_store_ptr(irb, scope, node, addrs_slice_ptr, slice_value); |
| ... | @@ -8256,7 +8241,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -8256,7 +8241,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 8256 | } | 8241 | } |
| 8257 | if (irb->codegen->have_err_ret_tracing) { | 8242 | if (irb->codegen->have_err_ret_tracing) { |
| 8258 | Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME); | 8243 | Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME); |
| 8259 | IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name); | 8244 | IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name, false); |
| 8260 | IrInstruction *dest_err_ret_trace_ptr = ir_build_load_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr); | 8245 | IrInstruction *dest_err_ret_trace_ptr = ir_build_load_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr); |
| 8261 | ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr, dest_err_ret_trace_ptr); | 8246 | ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr, dest_err_ret_trace_ptr); |
| 8262 | } | 8247 | } |
| ... | @@ -8291,7 +8276,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -8291,7 +8276,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 8291 | Buf *shrink_field_name = buf_create_from_str(ASYNC_SHRINK_FIELD_NAME); | 8276 | Buf *shrink_field_name = buf_create_from_str(ASYNC_SHRINK_FIELD_NAME); |
| 8292 | IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node, | 8277 | IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node, |
| 8293 | ImplicitAllocatorIdLocalVar); | 8278 | ImplicitAllocatorIdLocalVar); |
| 8294 | IrInstruction *shrink_fn_ptr = ir_build_field_ptr(irb, scope, node, implicit_allocator_ptr, shrink_field_name); | 8279 | IrInstruction *shrink_fn_ptr = ir_build_field_ptr(irb, scope, node, implicit_allocator_ptr, shrink_field_name, false); |
| 8295 | IrInstruction *shrink_fn = ir_build_load_ptr(irb, scope, node, shrink_fn_ptr); | 8280 | IrInstruction *shrink_fn = ir_build_load_ptr(irb, scope, node, shrink_fn_ptr); |
| 8296 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); | 8281 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); |
| 8297 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); | 8282 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); |
| ... | @@ -14722,7 +14707,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc | ... | @@ -14722,7 +14707,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 14722 | ir_assert(async_allocator_inst->value.type->id == ZigTypeIdPointer, &call_instruction->base); | 14707 | ir_assert(async_allocator_inst->value.type->id == ZigTypeIdPointer, &call_instruction->base); |
| 14723 | ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type; | 14708 | ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type; |
| 14724 | IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, realloc_field_name, &call_instruction->base, | 14709 | IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, realloc_field_name, &call_instruction->base, |
| 14725 | async_allocator_inst, container_type); | 14710 | async_allocator_inst, container_type, false); |
| 14726 | if (type_is_invalid(field_ptr_inst->value.type)) { | 14711 | if (type_is_invalid(field_ptr_inst->value.type)) { |
| 14727 | return ira->codegen->invalid_instruction; | 14712 | return ira->codegen->invalid_instruction; |
| 14728 | } | 14713 | } |
| ... | @@ -16580,7 +16565,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -16580,7 +16565,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 16580 | } | 16565 | } |
| 16581 | | 16566 | |
| 16582 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 16567 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 16583 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type) | 16568 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing) |
| 16584 | { | 16569 | { |
| 16585 | Error err; | 16570 | Error err; |
| 16586 | | 16571 | |
| ... | @@ -16664,15 +16649,19 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -16664,15 +16649,19 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 16664 | if (type_is_invalid(union_val->type)) | 16649 | if (type_is_invalid(union_val->type)) |
| 16665 | return ira->codegen->invalid_instruction; | 16650 | return ira->codegen->invalid_instruction; |
| 16666 | | 16651 | |
| 16667 | TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag); | 16652 | if (initializing) { |
| 16668 | if (actual_field == nullptr) | 16653 | bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value); |
| 16669 | zig_unreachable(); | 16654 | } else { |
| | 16655 | TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag); |
| | 16656 | if (actual_field == nullptr) |
| | 16657 | zig_unreachable(); |
| 16670 | | 16658 | |
| 16671 | if (field != actual_field) { | 16659 | if (field != actual_field) { |
| 16672 | ir_add_error_node(ira, source_instr->source_node, | 16660 | ir_add_error_node(ira, source_instr->source_node, |
| 16673 | buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name), | 16661 | buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name), |
| 16674 | buf_ptr(actual_field->name))); | 16662 | buf_ptr(actual_field->name))); |
| 16675 | return ira->codegen->invalid_instruction; | 16663 | return ira->codegen->invalid_instruction; |
| | 16664 | } |
| 16676 | } | 16665 | } |
| 16677 | | 16666 | |
| 16678 | ConstExprValue *payload_val = union_val->data.x_union.payload; | 16667 | ConstExprValue *payload_val = union_val->data.x_union.payload; |
| ... | @@ -16690,7 +16679,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -16690,7 +16679,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 16690 | } | 16679 | } |
| 16691 | } | 16680 | } |
| 16692 | | 16681 | |
| 16693 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field); | 16682 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| | 16683 | source_instr->source_node, container_ptr, field, initializing); |
| 16694 | result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, | 16684 | result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, |
| 16695 | PtrLenSingle, 0, 0, 0, false); | 16685 | PtrLenSingle, 0, 0, 0, false); |
| 16696 | return result; | 16686 | return result; |
| ... | @@ -16826,10 +16816,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -16826,10 +16816,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 16826 | if (container_type->id == ZigTypeIdPointer) { | 16816 | if (container_type->id == ZigTypeIdPointer) { |
| 16827 | ZigType *bare_type = container_ref_type(container_type); | 16817 | ZigType *bare_type = container_ref_type(container_type); |
| 16828 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); | 16818 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); |
| 16829 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); | 16819 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type, field_ptr_instruction->initializing); |
| 16830 | return result; | 16820 | return result; |
| 16831 | } else { | 16821 | } else { |
| 16832 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type); | 16822 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing); |
| 16833 | return result; | 16823 | return result; |
| 16834 | } | 16824 | } |
| 16835 | } else if (is_array_ref(container_type)) { | 16825 | } else if (is_array_ref(container_type)) { |
| ... | @@ -18120,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru | ... | @@ -18120,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 18120 | } | 18110 | } |
| 18121 | | 18111 | |
| 18122 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, | 18112 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, |
| 18123 | instruction->base.scope, instruction->base.source_node, target_value_ptr, field); | 18113 | instruction->base.scope, instruction->base.source_node, target_value_ptr, field, false); |
| 18124 | result->value.type = get_pointer_to_type(ira->codegen, field->type_entry, | 18114 | result->value.type = get_pointer_to_type(ira->codegen, field->type_entry, |
| 18125 | target_value_ptr->value.type->data.pointer.is_const); | 18115 | target_value_ptr->value.type->data.pointer.is_const); |
| 18126 | return result; | 18116 | return result; |
| ... | @@ -18386,11 +18376,10 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI | ... | @@ -18386,11 +18376,10 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI |
| 18386 | return result; | 18376 | return result; |
| 18387 | } | 18377 | } |
| 18388 | | 18378 | |
| 18389 | IrInstruction *new_instruction = ir_build_union_init(&ira->new_irb, | 18379 | // this instruction should not get to codegen |
| 18390 | instruction->scope, instruction->source_node, | 18380 | IrInstruction *new_instruction = ir_const(ira, instruction, container_type); |
| 18391 | container_type, type_field, casted_field_value); | 18381 | // this is how we signal to EndExpr the value is not comptime known |
| 18392 | new_instruction->value.type = container_type; | 18382 | new_instruction->value.special = ConstValSpecialRuntime; |
| 18393 | ir_add_alloca(ira, new_instruction, container_type); | | |
| 18394 | return new_instruction; | 18383 | return new_instruction; |
| 18395 | } | 18384 | } |
| 18396 | | 18385 | |
| ... | @@ -23907,7 +23896,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -23907,7 +23896,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 23907 | switch (instruction->id) { | 23896 | switch (instruction->id) { |
| 23908 | case IrInstructionIdInvalid: | 23897 | case IrInstructionIdInvalid: |
| 23909 | case IrInstructionIdWidenOrShorten: | 23898 | case IrInstructionIdWidenOrShorten: |
| 23910 | case IrInstructionIdUnionInit: | | |
| 23911 | case IrInstructionIdStructFieldPtr: | 23899 | case IrInstructionIdStructFieldPtr: |
| 23912 | case IrInstructionIdUnionFieldPtr: | 23900 | case IrInstructionIdUnionFieldPtr: |
| 23913 | case IrInstructionIdOptionalWrap: | 23901 | case IrInstructionIdOptionalWrap: |
| ... | @@ -24353,7 +24341,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24353,7 +24341,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24353 | case IrInstructionIdCast: | 24341 | case IrInstructionIdCast: |
| 24354 | case IrInstructionIdContainerInitList: | 24342 | case IrInstructionIdContainerInitList: |
| 24355 | case IrInstructionIdContainerInitFields: | 24343 | case IrInstructionIdContainerInitFields: |
| 24356 | case IrInstructionIdUnionInit: | | |
| 24357 | case IrInstructionIdFieldPtr: | 24344 | case IrInstructionIdFieldPtr: |
| 24358 | case IrInstructionIdElemPtr: | 24345 | case IrInstructionIdElemPtr: |
| 24359 | case IrInstructionIdVarPtr: | 24346 | case IrInstructionIdVarPtr: |