| ... | @@ -17,10 +17,6 @@ | ... | @@ -17,10 +17,6 @@ |
| 17 | | 17 | |
| 18 | #include <errno.h> | 18 | #include <errno.h> |
| 19 | | 19 | |
| 20 | struct IrExecContext { | | |
| 21 | ZigList<ZigValue *> mem_slot_list; | | |
| 22 | }; | | |
| 23 | | | |
| 24 | struct IrBuilder { | 20 | struct IrBuilder { |
| 25 | CodeGen *codegen; | 21 | CodeGen *codegen; |
| 26 | IrExecutable *exec; | 22 | IrExecutable *exec; |
| ... | @@ -32,7 +28,6 @@ struct IrAnalyze { | ... | @@ -32,7 +28,6 @@ struct IrAnalyze { |
| 32 | CodeGen *codegen; | 28 | CodeGen *codegen; |
| 33 | IrBuilder old_irb; | 29 | IrBuilder old_irb; |
| 34 | IrBuilder new_irb; | 30 | IrBuilder new_irb; |
| 35 | IrExecContext exec_context; | | |
| 36 | size_t old_bb_index; | 31 | size_t old_bb_index; |
| 37 | size_t instruction_index; | 32 | size_t instruction_index; |
| 38 | ZigType *explicit_return_type; | 33 | ZigType *explicit_return_type; |
| ... | @@ -42,6 +37,7 @@ struct IrAnalyze { | ... | @@ -42,6 +37,7 @@ struct IrAnalyze { |
| 42 | IrBasicBlock *const_predecessor_bb; | 37 | IrBasicBlock *const_predecessor_bb; |
| 43 | size_t ref_count; | 38 | size_t ref_count; |
| 44 | size_t break_debug_id; // for debugging purposes | 39 | size_t break_debug_id; // for debugging purposes |
| | 40 | IrInstruction *return_ptr; |
| 45 | | 41 | |
| 46 | // For the purpose of using in a debugger | 42 | // For the purpose of using in a debugger |
| 47 | void dump(); | 43 | void dump(); |
| ... | @@ -238,10 +234,10 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -238,10 +234,10 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 238 | ZigType *dest_type); | 234 | ZigType *dest_type); |
| 239 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 235 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 240 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, | 236 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 241 | bool non_null_comptime, bool allow_discard); | 237 | bool allow_discard); |
| 242 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 238 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 243 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, | 239 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 244 | bool non_null_comptime, bool allow_discard); | 240 | bool allow_discard); |
| 245 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, | 241 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 246 | IrInstruction *base_ptr, bool safety_check_on, bool initializing); | 242 | IrInstruction *base_ptr, bool safety_check_on, bool initializing); |
| 247 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, | 243 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| ... | @@ -640,7 +636,6 @@ static void ira_deref(IrAnalyze *ira) { | ... | @@ -640,7 +636,6 @@ static void ira_deref(IrAnalyze *ira) { |
| 640 | //destroy(ira->old_irb.exec, "IrExecutablePass1"); | 636 | //destroy(ira->old_irb.exec, "IrExecutablePass1"); |
| 641 | ira->src_implicit_return_type_list.deinit(); | 637 | ira->src_implicit_return_type_list.deinit(); |
| 642 | ira->resume_stack.deinit(); | 638 | ira->resume_stack.deinit(); |
| 643 | ira->exec_context.mem_slot_list.deinit(); | | |
| 644 | destroy(ira, "IrAnalyze"); | 639 | destroy(ira, "IrAnalyze"); |
| 645 | } | 640 | } |
| 646 | | 641 | |
| ... | @@ -813,12 +808,6 @@ static size_t exec_next_debug_id(IrExecutable *exec) { | ... | @@ -813,12 +808,6 @@ static size_t exec_next_debug_id(IrExecutable *exec) { |
| 813 | return result; | 808 | return result; |
| 814 | } | 809 | } |
| 815 | | 810 | |
| 816 | static size_t exec_next_mem_slot(IrExecutable *exec) { | | |
| 817 | size_t result = exec->mem_slot_count; | | |
| 818 | exec->mem_slot_count += 1; | | |
| 819 | return result; | | |
| 820 | } | | |
| 821 | | | |
| 822 | static ZigFn *exec_fn_entry(IrExecutable *exec) { | 811 | static ZigFn *exec_fn_entry(IrExecutable *exec) { |
| 823 | return exec->fn_entry; | 812 | return exec->fn_entry; |
| 824 | } | 813 | } |
| ... | @@ -859,16 +848,46 @@ static void ir_ref_var(ZigVar *var) { | ... | @@ -859,16 +848,46 @@ static void ir_ref_var(ZigVar *var) { |
| 859 | var->ref_count += 1; | 848 | var->ref_count += 1; |
| 860 | } | 849 | } |
| 861 | | 850 | |
| | 851 | static void create_result_ptr(CodeGen *codegen, ZigType *expected_type, |
| | 852 | ZigValue **out_result, ZigValue **out_result_ptr) |
| | 853 | { |
| | 854 | ZigValue *result = create_const_vals(1); |
| | 855 | ZigValue *result_ptr = create_const_vals(1); |
| | 856 | result->special = ConstValSpecialUndef; |
| | 857 | result->type = expected_type; |
| | 858 | result_ptr->special = ConstValSpecialStatic; |
| | 859 | result_ptr->type = get_pointer_to_type(codegen, result->type, false); |
| | 860 | result_ptr->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| | 861 | result_ptr->data.x_ptr.special = ConstPtrSpecialRef; |
| | 862 | result_ptr->data.x_ptr.data.ref.pointee = result; |
| | 863 | |
| | 864 | *out_result = result; |
| | 865 | *out_result_ptr = result_ptr; |
| | 866 | } |
| | 867 | |
| 862 | ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { | 868 | ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { |
| 863 | ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, | 869 | Error err; |
| 864 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, | | |
| 865 | node, nullptr, ira->new_irb.exec, nullptr, UndefBad); | | |
| 866 | | 870 | |
| | 871 | ZigValue *result; |
| | 872 | ZigValue *result_ptr; |
| | 873 | create_result_ptr(ira->codegen, ira->codegen->builtin_types.entry_type, &result, &result_ptr); |
| | 874 | |
| | 875 | if ((err = ir_eval_const_value(ira->codegen, scope, node, result_ptr, |
| | 876 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| | 877 | nullptr, nullptr, node, nullptr, ira->new_irb.exec, nullptr, UndefBad))) |
| | 878 | { |
| | 879 | return ira->codegen->builtin_types.entry_invalid; |
| | 880 | } |
| 867 | if (type_is_invalid(result->type)) | 881 | if (type_is_invalid(result->type)) |
| 868 | return ira->codegen->builtin_types.entry_invalid; | 882 | return ira->codegen->builtin_types.entry_invalid; |
| 869 | | 883 | |
| 870 | assert(result->special != ConstValSpecialRuntime); | 884 | assert(result->special != ConstValSpecialRuntime); |
| 871 | return result->data.x_type; | 885 | ZigType *res_type = result->data.x_type; |
| | 886 | |
| | 887 | destroy(result_ptr, "ZigValue"); |
| | 888 | destroy(result, "ZigValue"); |
| | 889 | |
| | 890 | return res_type; |
| 872 | } | 891 | } |
| 873 | | 892 | |
| 874 | static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) { | 893 | static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) { |
| ... | @@ -1839,9 +1858,11 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so | ... | @@ -1839,9 +1858,11 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so |
| 1839 | return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr); | 1858 | return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr); |
| 1840 | } | 1859 | } |
| 1841 | | 1860 | |
| 1842 | static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { | 1861 | static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| | 1862 | ZigType *ty) |
| | 1863 | { |
| 1843 | IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, | 1864 | IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, |
| 1844 | source_instruction->scope, source_instruction->source_node); | 1865 | scope, source_node); |
| 1845 | instruction->base.value->type = ty; | 1866 | instruction->base.value->type = ty; |
| 1846 | return &instruction->base; | 1867 | return &instruction->base; |
| 1847 | } | 1868 | } |
| ... | @@ -3649,6 +3670,7 @@ static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNod | ... | @@ -3649,6 +3670,7 @@ static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNod |
| 3649 | { | 3670 | { |
| 3650 | IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node); | 3671 | IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node); |
| 3651 | instruction->result_loc = result_loc; | 3672 | instruction->result_loc = result_loc; |
| | 3673 | instruction->base.is_gen = true; |
| 3652 | | 3674 | |
| 3653 | return &instruction->base; | 3675 | return &instruction->base; |
| 3654 | } | 3676 | } |
| ... | @@ -4315,7 +4337,6 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s | ... | @@ -4315,7 +4337,6 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 4315 | ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar"); | 4337 | ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar"); |
| 4316 | variable_entry->parent_scope = parent_scope; | 4338 | variable_entry->parent_scope = parent_scope; |
| 4317 | variable_entry->shadowable = is_shadowable; | 4339 | variable_entry->shadowable = is_shadowable; |
| 4318 | variable_entry->mem_slot_index = SIZE_MAX; | | |
| 4319 | variable_entry->is_comptime = is_comptime; | 4340 | variable_entry->is_comptime = is_comptime; |
| 4320 | variable_entry->src_arg_index = SIZE_MAX; | 4341 | variable_entry->src_arg_index = SIZE_MAX; |
| 4321 | variable_entry->const_value = create_const_vals(1); | 4342 | variable_entry->const_value = create_const_vals(1); |
| ... | @@ -4379,7 +4400,6 @@ static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *n | ... | @@ -4379,7 +4400,6 @@ static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *n |
| 4379 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, | 4400 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, |
| 4380 | (is_underscored ? true : is_shadowable), is_comptime, false); | 4401 | (is_underscored ? true : is_shadowable), is_comptime, false); |
| 4381 | if (is_comptime != nullptr || gen_is_const) { | 4402 | if (is_comptime != nullptr || gen_is_const) { |
| 4382 | var->mem_slot_index = exec_next_mem_slot(irb->exec); | | |
| 4383 | var->owner_exec = irb->exec; | 4403 | var->owner_exec = irb->exec; |
| 4384 | } | 4404 | } |
| 4385 | assert(var->child_scope); | 4405 | assert(var->child_scope); |
| ... | @@ -4516,6 +4536,10 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -4516,6 +4536,10 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4516 | // only generate unconditional defers | 4536 | // only generate unconditional defers |
| 4517 | | 4537 | |
| 4518 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); | 4538 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); |
| | 4539 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| | 4540 | result_loc_ret->base.id = ResultLocIdReturn; |
| | 4541 | ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base); |
| | 4542 | ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base)); |
| 4519 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); | 4543 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| 4520 | return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result)); | 4544 | return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result)); |
| 4521 | } | 4545 | } |
| ... | @@ -9182,6 +9206,10 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -9182,6 +9206,10 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 9182 | if (!instr_is_unreachable(result)) { | 9206 | if (!instr_is_unreachable(result)) { |
| 9183 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr)); | 9207 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr)); |
| 9184 | // no need for save_err_ret_addr because this cannot return error | 9208 | // no need for save_err_ret_addr because this cannot return error |
| | 9209 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| | 9210 | result_loc_ret->base.id = ResultLocIdReturn; |
| | 9211 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); |
| | 9212 | ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base)); |
| 9185 | ir_mark_gen(ir_build_return(irb, scope, result->source_node, result)); | 9213 | ir_mark_gen(ir_build_return(irb, scope, result->source_node, result)); |
| 9186 | } | 9214 | } |
| 9187 | | 9215 | |
| ... | @@ -9280,19 +9308,12 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va | ... | @@ -9280,19 +9308,12 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va |
| 9280 | return val; | 9308 | return val; |
| 9281 | } | 9309 | } |
| 9282 | | 9310 | |
| 9283 | static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { | 9311 | static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutable *exec) { |
| 9284 | IrBasicBlock *bb = exec->basic_block_list.at(0); | 9312 | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 9285 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { | 9313 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| 9286 | IrInstruction *instruction = bb->instruction_list.at(i); | 9314 | IrInstruction *instruction = bb->instruction_list.at(i); |
| 9287 | if (instruction->id == IrInstructionIdReturn) { | 9315 | if (instruction->id == IrInstructionIdReturn) { |
| 9288 | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; | 9316 | return ErrorNone; |
| 9289 | IrInstruction *operand = ret_inst->operand; | | |
| 9290 | if (operand->value->special == ConstValSpecialRuntime) { | | |
| 9291 | exec_add_error_node(codegen, exec, operand->source_node, | | |
| 9292 | buf_sprintf("unable to evaluate constant expression")); | | |
| 9293 | return codegen->invalid_instruction->value; | | |
| 9294 | } | | |
| 9295 | return operand->value; | | |
| 9296 | } else if (ir_has_side_effects(instruction)) { | 9317 | } else if (ir_has_side_effects(instruction)) { |
| 9297 | if (instr_is_comptime(instruction)) { | 9318 | if (instr_is_comptime(instruction)) { |
| 9298 | switch (instruction->id) { | 9319 | switch (instruction->id) { |
| ... | @@ -9308,8 +9329,8 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { | ... | @@ -9308,8 +9329,8 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 9308 | continue; | 9329 | continue; |
| 9309 | } | 9330 | } |
| 9310 | exec_add_error_node(codegen, exec, instruction->source_node, | 9331 | exec_add_error_node(codegen, exec, instruction->source_node, |
| 9311 | buf_sprintf("unable to evaluate constant expression")); | 9332 | buf_sprintf("unable to evaluate constant expression")); |
| 9312 | return codegen->invalid_instruction->value; | 9333 | return ErrorSemanticAnalyzeFail; |
| 9313 | } | 9334 | } |
| 9314 | } | 9335 | } |
| 9315 | zig_unreachable(); | 9336 | zig_unreachable(); |
| ... | @@ -11696,26 +11717,29 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc | ... | @@ -11696,26 +11717,29 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11696 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); | 11717 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); |
| 11697 | | 11718 | |
| 11698 | if (instr_is_comptime(array_ptr)) { | 11719 | if (instr_is_comptime(array_ptr)) { |
| 11699 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); | 11720 | ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| | 11721 | if (array_ptr_val == nullptr) |
| | 11722 | return ira->codegen->invalid_instruction; |
| | 11723 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node); |
| 11700 | if (pointee == nullptr) | 11724 | if (pointee == nullptr) |
| 11701 | return ira->codegen->invalid_instruction; | 11725 | return ira->codegen->invalid_instruction; |
| 11702 | if (pointee->special != ConstValSpecialRuntime) { | 11726 | if (pointee->special != ConstValSpecialRuntime) { |
| 11703 | assert(array_ptr->value->type->id == ZigTypeIdPointer); | 11727 | assert(array_ptr_val->type->id == ZigTypeIdPointer); |
| 11704 | ZigType *array_type = array_ptr->value->type->data.pointer.child_type; | 11728 | ZigType *array_type = array_ptr_val->type->data.pointer.child_type; |
| 11705 | assert(is_slice(wanted_type)); | 11729 | assert(is_slice(wanted_type)); |
| 11706 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; | 11730 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 11707 | | 11731 | |
| 11708 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); | 11732 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11709 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); | 11733 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11710 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; | 11734 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 11711 | result->value->type = wanted_type; | 11735 | result->value->type = wanted_type; |
| 11712 | return result; | 11736 | return result; |
| 11713 | } | 11737 | } |
| 11714 | } | 11738 | } |
| 11715 | | 11739 | |
| 11716 | if (result_loc == nullptr) result_loc = no_result_loc(); | 11740 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11717 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, | 11741 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, |
| 11718 | false, true); | 11742 | nullptr, true, true); |
| 11719 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { | 11743 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11720 | return result_loc_inst; | 11744 | return result_loc_inst; |
| 11721 | } | 11745 | } |
| ... | @@ -12020,15 +12044,17 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll | ... | @@ -12020,15 +12044,17 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll |
| 12020 | return value->value; | 12044 | return value->value; |
| 12021 | } | 12045 | } |
| 12022 | | 12046 | |
| 12023 | ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | 12047 | Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12024 | ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, | 12048 | ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota, |
| 12025 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, | 12049 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 12026 | IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) | 12050 | IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) |
| 12027 | { | 12051 | { |
| 12028 | Error err; | 12052 | Error err; |
| 12029 | | 12053 | |
| 12030 | if (expected_type != nullptr && type_is_invalid(expected_type)) | 12054 | src_assert(return_ptr->type->id == ZigTypeIdPointer, source_node); |
| 12031 | return codegen->invalid_instruction->value; | 12055 | |
| | 12056 | if (type_is_invalid(return_ptr->type)) |
| | 12057 | return ErrorSemanticAnalyzeFail; |
| 12032 | | 12058 | |
| 12033 | IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1"); | 12059 | IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1"); |
| 12034 | ir_executable->source_node = source_node; | 12060 | ir_executable->source_node = source_node; |
| ... | @@ -12040,11 +12066,11 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -12040,11 +12066,11 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12040 | ir_executable->begin_scope = scope; | 12066 | ir_executable->begin_scope = scope; |
| 12041 | | 12067 | |
| 12042 | if (!ir_gen(codegen, node, scope, ir_executable)) | 12068 | if (!ir_gen(codegen, node, scope, ir_executable)) |
| 12043 | return codegen->invalid_instruction->value; | 12069 | return ErrorSemanticAnalyzeFail; |
| 12044 | | 12070 | |
| 12045 | if (ir_executable->first_err_trace_msg != nullptr) { | 12071 | if (ir_executable->first_err_trace_msg != nullptr) { |
| 12046 | codegen->trace_err = ir_executable->first_err_trace_msg; | 12072 | codegen->trace_err = ir_executable->first_err_trace_msg; |
| 12047 | return codegen->invalid_instruction->value; | 12073 | return ErrorSemanticAnalyzeFail; |
| 12048 | } | 12074 | } |
| 12049 | | 12075 | |
| 12050 | if (codegen->verbose_ir) { | 12076 | if (codegen->verbose_ir) { |
| ... | @@ -12065,9 +12091,10 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -12065,9 +12091,10 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12065 | analyzed_executable->backward_branch_count = backward_branch_count; | 12091 | analyzed_executable->backward_branch_count = backward_branch_count; |
| 12066 | analyzed_executable->backward_branch_quota = backward_branch_quota; | 12092 | analyzed_executable->backward_branch_quota = backward_branch_quota; |
| 12067 | analyzed_executable->begin_scope = scope; | 12093 | analyzed_executable->begin_scope = scope; |
| 12068 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); | 12094 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, |
| | 12095 | return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr); |
| 12069 | if (type_is_invalid(result_type)) { | 12096 | if (type_is_invalid(result_type)) { |
| 12070 | return codegen->invalid_instruction->value; | 12097 | return ErrorSemanticAnalyzeFail; |
| 12071 | } | 12098 | } |
| 12072 | | 12099 | |
| 12073 | if (codegen->verbose_ir) { | 12100 | if (codegen->verbose_ir) { |
| ... | @@ -12076,14 +12103,16 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -12076,14 +12103,16 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12076 | fprintf(stderr, "}\n"); | 12103 | fprintf(stderr, "}\n"); |
| 12077 | } | 12104 | } |
| 12078 | | 12105 | |
| 12079 | ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); | 12106 | if ((err = ir_exec_scan_for_side_effects(codegen, analyzed_executable))) |
| 12080 | if (type_is_invalid(result->type)) | 12107 | return err; |
| 12081 | return codegen->invalid_instruction->value; | | |
| 12082 | | 12108 | |
| | 12109 | ZigValue *result = const_ptr_pointee(nullptr, codegen, return_ptr, source_node); |
| | 12110 | if (result == nullptr) |
| | 12111 | return ErrorSemanticAnalyzeFail; |
| 12083 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) | 12112 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 12084 | return codegen->invalid_instruction->value; | 12113 | return err; |
| 12085 | | 12114 | |
| 12086 | return result; | 12115 | return ErrorNone; |
| 12087 | } | 12116 | } |
| 12088 | | 12117 | |
| 12089 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { | 12118 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { |
| ... | @@ -12268,7 +12297,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so | ... | @@ -12268,7 +12297,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 12268 | } | 12297 | } |
| 12269 | IrInstruction *result_loc_inst = nullptr; | 12298 | IrInstruction *result_loc_inst = nullptr; |
| 12270 | if (result_loc != nullptr) { | 12299 | if (result_loc != nullptr) { |
| 12271 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); | 12300 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 12272 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { | 12301 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12273 | return result_loc_inst; | 12302 | return result_loc_inst; |
| 12274 | } | 12303 | } |
| ... | @@ -12311,7 +12340,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -12311,7 +12340,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 12311 | IrInstruction *result_loc_inst; | 12340 | IrInstruction *result_loc_inst; |
| 12312 | if (handle_is_ptr(wanted_type)) { | 12341 | if (handle_is_ptr(wanted_type)) { |
| 12313 | if (result_loc == nullptr) result_loc = no_result_loc(); | 12342 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12314 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); | 12343 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 12315 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { | 12344 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12316 | return result_loc_inst; | 12345 | return result_loc_inst; |
| 12317 | } | 12346 | } |
| ... | @@ -12430,7 +12459,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so | ... | @@ -12430,7 +12459,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 12430 | IrInstruction *result_loc_inst; | 12459 | IrInstruction *result_loc_inst; |
| 12431 | if (handle_is_ptr(wanted_type)) { | 12460 | if (handle_is_ptr(wanted_type)) { |
| 12432 | if (result_loc == nullptr) result_loc = no_result_loc(); | 12461 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12433 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); | 12462 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 12434 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { | 12463 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12435 | return result_loc_inst; | 12464 | return result_loc_inst; |
| 12436 | } | 12465 | } |
| ... | @@ -12503,8 +12532,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -12503,8 +12532,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 12503 | | 12532 | |
| 12504 | IrInstruction *result_loc; | 12533 | IrInstruction *result_loc; |
| 12505 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { | 12534 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { |
| 12506 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, | 12535 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, |
| 12507 | false, true); | 12536 | nullptr, true, true); |
| 12508 | } else { | 12537 | } else { |
| 12509 | result_loc = nullptr; | 12538 | result_loc = nullptr; |
| 12510 | } | 12539 | } |
| ... | @@ -13232,7 +13261,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * | ... | @@ -13232,7 +13261,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 13232 | result_loc = no_result_loc(); | 13261 | result_loc = no_result_loc(); |
| 13233 | } | 13262 | } |
| 13234 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, | 13263 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| 13235 | true, false, true); | 13264 | true, true); |
| 13236 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { | 13265 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 13237 | return result_loc_inst; | 13266 | return result_loc_inst; |
| 13238 | } | 13267 | } |
| ... | @@ -14117,7 +14146,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -14117,7 +14146,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14117 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { | 14146 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { |
| 14118 | if (result_loc == nullptr) result_loc = no_result_loc(); | 14147 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 14119 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, | 14148 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, |
| 14120 | true, false, true); | 14149 | true, true); |
| 14121 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { | 14150 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 14122 | return result_loc_inst; | 14151 | return result_loc_inst; |
| 14123 | } | 14152 | } |
| ... | @@ -16043,7 +16072,7 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source | ... | @@ -16043,7 +16072,7 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16043 | bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope); | 16072 | bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope); |
| 16044 | | 16073 | |
| 16045 | IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), | 16074 | IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 16046 | new_type, nullptr, false, false, true); | 16075 | new_type, nullptr, false, true); |
| 16047 | uint32_t new_field_count = op1_field_count + op2_field_count; | 16076 | uint32_t new_field_count = op1_field_count + op2_field_count; |
| 16048 | | 16077 | |
| 16049 | new_type->data.structure.src_field_count = new_field_count; | 16078 | new_type->data.structure.src_field_count = new_field_count; |
| ... | @@ -16631,29 +16660,14 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, | ... | @@ -16631,29 +16660,14 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16631 | break; | 16660 | break; |
| 16632 | } | 16661 | } |
| 16633 | | 16662 | |
| 16634 | if (var->var_type != nullptr && !is_comptime_var) { | 16663 | while (var->next_var != nullptr) { |
| 16635 | // This is at least the second time we've seen this variable declaration during analysis. | 16664 | var = var->next_var; |
| 16636 | // This means that this is actually a different variable due to, e.g. an inline while loop. | | |
| 16637 | // We make a new variable so that it can hold a different type, and so the debug info can | | |
| 16638 | // be distinct. | | |
| 16639 | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, | | |
| 16640 | buf_create_from_str(var->name), var->src_is_const, var->gen_is_const, | | |
| 16641 | var->shadowable, var->is_comptime, true); | | |
| 16642 | new_var->owner_exec = var->owner_exec; | | |
| 16643 | new_var->align_bytes = var->align_bytes; | | |
| 16644 | if (var->mem_slot_index != SIZE_MAX) { | | |
| 16645 | ZigValue *vals = create_const_vals(1); | | |
| 16646 | new_var->mem_slot_index = ira->exec_context.mem_slot_list.length; | | |
| 16647 | ira->exec_context.mem_slot_list.append(vals); | | |
| 16648 | } | | |
| 16649 | | | |
| 16650 | var->next_var = new_var; | | |
| 16651 | var = new_var; | | |
| 16652 | } | 16665 | } |
| 16653 | | 16666 | |
| 16654 | // This must be done after possibly creating a new variable above | 16667 | // This must be done after possibly creating a new variable above |
| 16655 | var->ref_count = 0; | 16668 | var->ref_count = 0; |
| 16656 | | 16669 | |
| | 16670 | var->ptr_instruction = var_ptr; |
| 16657 | var->var_type = result_type; | 16671 | var->var_type = result_type; |
| 16658 | assert(var->var_type); | 16672 | assert(var->var_type); |
| 16659 | | 16673 | |
| ... | @@ -16695,16 +16709,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, | ... | @@ -16695,16 +16709,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16695 | var_ptr->value->special = ConstValSpecialRuntime; | 16709 | var_ptr->value->special = ConstValSpecialRuntime; |
| 16696 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); | 16710 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 16697 | } | 16711 | } |
| 16698 | | 16712 | if (instr_is_comptime(var_ptr) && |
| 16699 | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { | 16713 | (is_comptime_var || (var_class_requires_const && var->gen_is_const))) |
| 16700 | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); | 16714 | { |
| 16701 | ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); | 16715 | return ir_const_void(ira, &decl_var_instruction->base); |
| 16702 | copy_const_val(mem_slot, init_val); | | |
| 16703 | ira_ref(var->owner_exec->analysis); | | |
| 16704 | | | |
| 16705 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { | | |
| 16706 | return ir_const_void(ira, &decl_var_instruction->base); | | |
| 16707 | } | | |
| 16708 | } | 16716 | } |
| 16709 | } else if (is_comptime_var) { | 16717 | } else if (is_comptime_var) { |
| 16710 | ir_add_error(ira, &decl_var_instruction->base, | 16718 | ir_add_error(ira, &decl_var_instruction->base, |
| ... | @@ -17161,7 +17169,7 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out | ... | @@ -17161,7 +17169,7 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out |
| 17161 | } | 17169 | } |
| 17162 | | 17170 | |
| 17163 | static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 17171 | static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 17164 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) | 17172 | ResultLoc *result_loc, ZigType *value_type) |
| 17165 | { | 17173 | { |
| 17166 | if (type_is_invalid(value_type)) | 17174 | if (type_is_invalid(value_type)) |
| 17167 | return ira->codegen->invalid_instruction; | 17175 | return ira->codegen->invalid_instruction; |
| ... | @@ -17181,7 +17189,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su | ... | @@ -17181,7 +17189,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su |
| 17181 | // when calling this function, at the callsite must check for result type noreturn and propagate it up | 17189 | // when calling this function, at the callsite must check for result type noreturn and propagate it up |
| 17182 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 17190 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 17183 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, | 17191 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 17184 | bool non_null_comptime, bool allow_discard) | 17192 | bool allow_discard) |
| 17185 | { | 17193 | { |
| 17186 | Error err; | 17194 | Error err; |
| 17187 | if (result_loc->resolved_loc != nullptr) { | 17195 | if (result_loc->resolved_loc != nullptr) { |
| ... | @@ -17201,54 +17209,58 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17201,54 +17209,58 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17201 | return nullptr; | 17209 | return nullptr; |
| 17202 | } | 17210 | } |
| 17203 | // need to return a result location and don't have one. use a stack allocation | 17211 | // need to return a result location and don't have one. use a stack allocation |
| 17204 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | 17212 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 17205 | force_runtime, non_null_comptime); | | |
| 17206 | } | 17213 | } |
| 17207 | case ResultLocIdVar: { | 17214 | case ResultLocIdVar: { |
| 17208 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); | 17215 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| 17209 | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); | 17216 | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); |
| 17210 | | 17217 | |
| | 17218 | IrInstructionAllocaSrc *alloca_src = |
| | 17219 | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); |
| | 17220 | |
| | 17221 | ZigVar *var = result_loc_var->var; |
| | 17222 | if (var->var_type != nullptr && !ir_get_var_is_comptime(var)) { |
| | 17223 | // This is at least the second time we've seen this variable declaration during analysis. |
| | 17224 | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| | 17225 | // We make a new variable so that it can hold a different type, and so the debug info can |
| | 17226 | // be distinct. |
| | 17227 | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, |
| | 17228 | buf_create_from_str(var->name), var->src_is_const, var->gen_is_const, |
| | 17229 | var->shadowable, var->is_comptime, true); |
| | 17230 | new_var->owner_exec = var->owner_exec; |
| | 17231 | new_var->align_bytes = var->align_bytes; |
| | 17232 | |
| | 17233 | var->next_var = new_var; |
| | 17234 | var = new_var; |
| | 17235 | } |
| 17211 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { | 17236 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { |
| 17212 | ir_add_error(ira, result_loc->source_instruction, | 17237 | ir_add_error(ira, result_loc->source_instruction, |
| 17213 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); | 17238 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); |
| 17214 | return ira->codegen->invalid_instruction; | 17239 | return ira->codegen->invalid_instruction; |
| 17215 | } | 17240 | } |
| 17216 | | 17241 | if (alloca_src->base.child == nullptr || var->ptr_instruction == nullptr) { |
| 17217 | IrInstructionAllocaSrc *alloca_src = | 17242 | bool force_comptime; |
| 17218 | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); | 17243 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 17219 | bool force_comptime; | 17244 | return ira->codegen->invalid_instruction; |
| 17220 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) | | |
| 17221 | return ira->codegen->invalid_instruction; | | |
| 17222 | bool is_comptime = force_comptime || (!force_runtime && value != nullptr && | | |
| 17223 | value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); | | |
| 17224 | | | |
| 17225 | if (alloca_src->base.child == nullptr || is_comptime) { | | |
| 17226 | uint32_t align = 0; | 17245 | uint32_t align = 0; |
| 17227 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { | 17246 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { |
| 17228 | return ira->codegen->invalid_instruction; | 17247 | return ira->codegen->invalid_instruction; |
| 17229 | } | 17248 | } |
| 17230 | IrInstruction *alloca_gen; | 17249 | IrInstruction *alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, |
| 17231 | if (is_comptime && value != nullptr) { | 17250 | value_type, align, alloca_src->name_hint, force_comptime); |
| 17232 | if (align > value->value->llvm_align) { | 17251 | if (force_runtime) { |
| 17233 | value->value->llvm_align = align; | 17252 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 17234 | } | 17253 | alloca_gen->value->special = ConstValSpecialRuntime; |
| 17235 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); | | |
| 17236 | } else { | | |
| 17237 | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, | | |
| 17238 | alloca_src->name_hint, force_comptime); | | |
| 17239 | if (force_runtime) { | | |
| 17240 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; | | |
| 17241 | alloca_gen->value->special = ConstValSpecialRuntime; | | |
| 17242 | } | | |
| 17243 | } | 17254 | } |
| 17244 | if (alloca_src->base.child != nullptr && !result_loc->written) { | 17255 | if (alloca_src->base.child != nullptr && !result_loc->written) { |
| 17245 | alloca_src->base.child->ref_count = 0; | 17256 | alloca_src->base.child->ref_count = 0; |
| 17246 | } | 17257 | } |
| 17247 | alloca_src->base.child = alloca_gen; | 17258 | alloca_src->base.child = alloca_gen; |
| | 17259 | var->ptr_instruction = alloca_gen; |
| 17248 | } | 17260 | } |
| 17249 | result_loc->written = true; | 17261 | result_loc->written = true; |
| 17250 | result_loc->resolved_loc = is_comptime ? nullptr : alloca_src->base.child; | 17262 | result_loc->resolved_loc = alloca_src->base.child; |
| 17251 | return result_loc->resolved_loc; | 17263 | return alloca_src->base.child; |
| 17252 | } | 17264 | } |
| 17253 | case ResultLocIdInstruction: { | 17265 | case ResultLocIdInstruction: { |
| 17254 | result_loc->written = true; | 17266 | result_loc->written = true; |
| ... | @@ -17260,27 +17272,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17260,27 +17272,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17260 | reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true; | 17272 | reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true; |
| 17261 | ira->src_implicit_return_type_list.append(value); | 17273 | ira->src_implicit_return_type_list.append(value); |
| 17262 | } | 17274 | } |
| 17263 | if (!non_null_comptime) { | | |
| 17264 | bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime; | | |
| 17265 | if (is_comptime) | | |
| 17266 | return nullptr; | | |
| 17267 | } | | |
| 17268 | bool has_bits; | | |
| 17269 | if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits))) | | |
| 17270 | return ira->codegen->invalid_instruction; | | |
| 17271 | if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) { | | |
| 17272 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); | | |
| 17273 | if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) { | | |
| 17274 | return nullptr; | | |
| 17275 | } | | |
| 17276 | } | | |
| 17277 | | | |
| 17278 | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); | | |
| 17279 | result_loc->written = true; | 17275 | result_loc->written = true; |
| 17280 | result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type); | 17276 | result_loc->resolved_loc = ira->return_ptr; |
| 17281 | if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->scope)) { | | |
| 17282 | set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc); | | |
| 17283 | } | | |
| 17284 | return result_loc->resolved_loc; | 17277 | return result_loc->resolved_loc; |
| 17285 | } | 17278 | } |
| 17286 | case ResultLocIdPeer: { | 17279 | case ResultLocIdPeer: { |
| ... | @@ -17289,7 +17282,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17289,7 +17282,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17289 | | 17282 | |
| 17290 | if (peer_parent->peers.length == 1) { | 17283 | if (peer_parent->peers.length == 1) { |
| 17291 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 17284 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17292 | value_type, value, force_runtime, non_null_comptime, true); | 17285 | value_type, value, force_runtime, true); |
| 17293 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; | 17286 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 17294 | result_peer->suspend_pos.instruction_index = SIZE_MAX; | 17287 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| 17295 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 17288 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| ... | @@ -17307,11 +17300,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17307,11 +17300,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17307 | return ira->codegen->invalid_instruction; | 17300 | return ira->codegen->invalid_instruction; |
| 17308 | if (is_condition_comptime) { | 17301 | if (is_condition_comptime) { |
| 17309 | peer_parent->skipped = true; | 17302 | peer_parent->skipped = true; |
| 17310 | if (non_null_comptime) { | 17303 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17311 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 17304 | value_type, value, force_runtime, true); |
| 17312 | value_type, value, force_runtime, non_null_comptime, true); | | |
| 17313 | } | | |
| 17314 | return nullptr; | | |
| 17315 | } | 17305 | } |
| 17316 | bool peer_parent_has_type; | 17306 | bool peer_parent_has_type; |
| 17317 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) | 17307 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) |
| ... | @@ -17319,7 +17309,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17319,7 +17309,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17319 | if (peer_parent_has_type) { | 17309 | if (peer_parent_has_type) { |
| 17320 | peer_parent->skipped = true; | 17310 | peer_parent->skipped = true; |
| 17321 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 17311 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17322 | value_type, value, force_runtime || !is_condition_comptime, true, true); | 17312 | value_type, value, force_runtime || !is_condition_comptime, true); |
| 17323 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 17313 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17324 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 17314 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17325 | { | 17315 | { |
| ... | @@ -17344,7 +17334,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17344,7 +17334,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17344 | } | 17334 | } |
| 17345 | | 17335 | |
| 17346 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 17336 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17347 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); | 17337 | peer_parent->resolved_type, nullptr, force_runtime, true); |
| 17348 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 17338 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17349 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 17339 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17350 | { | 17340 | { |
| ... | @@ -17357,16 +17347,13 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17357,16 +17347,13 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17357 | return result_loc->resolved_loc; | 17347 | return result_loc->resolved_loc; |
| 17358 | } | 17348 | } |
| 17359 | case ResultLocIdCast: { | 17349 | case ResultLocIdCast: { |
| 17360 | if (value != nullptr && value->value->special != ConstValSpecialRuntime && !non_null_comptime) | | |
| 17361 | return nullptr; | | |
| 17362 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); | 17350 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); |
| 17363 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); | 17351 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| 17364 | if (type_is_invalid(dest_type)) | 17352 | if (type_is_invalid(dest_type)) |
| 17365 | return ira->codegen->invalid_instruction; | 17353 | return ira->codegen->invalid_instruction; |
| 17366 | | 17354 | |
| 17367 | if (dest_type == ira->codegen->builtin_types.entry_var) { | 17355 | if (dest_type == ira->codegen->builtin_types.entry_var) { |
| 17368 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | 17356 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 17369 | force_runtime, non_null_comptime); | | |
| 17370 | } | 17357 | } |
| 17371 | | 17358 | |
| 17372 | IrInstruction *casted_value; | 17359 | IrInstruction *casted_value; |
| ... | @@ -17380,7 +17367,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17380,7 +17367,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17380 | } | 17367 | } |
| 17381 | | 17368 | |
| 17382 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, | 17369 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 17383 | dest_type, casted_value, force_runtime, non_null_comptime, true); | 17370 | dest_type, casted_value, force_runtime, true); |
| 17384 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 17371 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17385 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 17372 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17386 | { | 17373 | { |
| ... | @@ -17430,8 +17417,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17430,8 +17417,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17430 | // We will not be able to provide a result location for this value. Create | 17417 | // We will not be able to provide a result location for this value. Create |
| 17431 | // a new result location. | 17418 | // a new result location. |
| 17432 | result_cast->parent->written = false; | 17419 | result_cast->parent->written = false; |
| 17433 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | 17420 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 17434 | force_runtime, non_null_comptime); | | |
| 17435 | } | 17421 | } |
| 17436 | | 17422 | |
| 17437 | result_loc->written = true; | 17423 | result_loc->written = true; |
| ... | @@ -17477,12 +17463,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17477,12 +17463,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17477 | bitcasted_value = nullptr; | 17463 | bitcasted_value = nullptr; |
| 17478 | } | 17464 | } |
| 17479 | | 17465 | |
| 17480 | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) { | 17466 | if (bitcasted_value != nullptr && type_is_invalid(bitcasted_value->value->type)) { |
| 17481 | return bitcasted_value; | 17467 | return bitcasted_value; |
| 17482 | } | 17468 | } |
| 17483 | | 17469 | |
| 17484 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, | 17470 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 17485 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); | 17471 | dest_type, bitcasted_value, force_runtime, true); |
| 17486 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 17472 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17487 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 17473 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17488 | { | 17474 | { |
| ... | @@ -17526,7 +17512,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -17526,7 +17512,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17526 | | 17512 | |
| 17527 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 17513 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 17528 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime, | 17514 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 17529 | bool non_null_comptime, bool allow_discard) | 17515 | bool allow_discard) |
| 17530 | { | 17516 | { |
| 17531 | Error err; | 17517 | Error err; |
| 17532 | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && | 17518 | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && |
| ... | @@ -17538,7 +17524,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17538,7 +17524,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17538 | } | 17524 | } |
| 17539 | bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr; | 17525 | bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr; |
| 17540 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, | 17526 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 17541 | value, force_runtime, non_null_comptime, allow_discard); | 17527 | value, force_runtime, allow_discard); |
| 17542 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) | 17528 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) |
| 17543 | return result_loc; | 17529 | return result_loc; |
| 17544 | | 17530 | |
| ... | @@ -17685,7 +17671,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, | ... | @@ -17685,7 +17671,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17685 | return ira->codegen->invalid_instruction; | 17671 | return ira->codegen->invalid_instruction; |
| 17686 | } | 17672 | } |
| 17687 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 17673 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 17688 | implicit_elem_type, nullptr, false, true, true); | 17674 | implicit_elem_type, nullptr, false, true); |
| 17689 | if (result_loc != nullptr) | 17675 | if (result_loc != nullptr) |
| 17690 | return result_loc; | 17676 | return result_loc; |
| 17691 | | 17677 | |
| ... | @@ -17694,7 +17680,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, | ... | @@ -17694,7 +17680,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17694 | instruction->result_loc->id == ResultLocIdReturn) | 17680 | instruction->result_loc->id == ResultLocIdReturn) |
| 17695 | { | 17681 | { |
| 17696 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), | 17682 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 17697 | implicit_elem_type, nullptr, false, true, true); | 17683 | implicit_elem_type, nullptr, false, true); |
| 17698 | if (result_loc != nullptr && | 17684 | if (result_loc != nullptr && |
| 17699 | (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) | 17685 | (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 17700 | { | 17686 | { |
| ... | @@ -17798,7 +17784,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -17798,7 +17784,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *sourc |
| 17798 | } else { | 17784 | } else { |
| 17799 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); | 17785 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 17800 | IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, | 17786 | IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 17801 | frame_type, nullptr, true, true, false); | 17787 | frame_type, nullptr, true, false); |
| 17802 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 17788 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 17803 | return result_loc; | 17789 | return result_loc; |
| 17804 | } | 17790 | } |
| ... | @@ -17934,10 +17920,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, | ... | @@ -17934,10 +17920,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 17934 | var = var->next_var; | 17920 | var = var->next_var; |
| 17935 | } | 17921 | } |
| 17936 | | 17922 | |
| 17937 | if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) { | 17923 | if (var->ptr_instruction != nullptr) { |
| 17938 | assert(ira->codegen->errors.length != 0); | 17924 | return var->ptr_instruction; |
| 17939 | return ira->codegen->invalid_instruction; | | |
| 17940 | } | 17925 | } |
| | 17926 | |
| 17941 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) | 17927 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) |
| 17942 | return ira->codegen->invalid_instruction; | 17928 | return ira->codegen->invalid_instruction; |
| 17943 | | 17929 | |
| ... | @@ -17957,13 +17943,6 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, | ... | @@ -17957,13 +17943,6 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 17957 | | 17943 | |
| 17958 | if (value_is_comptime(var->const_value)) { | 17944 | if (value_is_comptime(var->const_value)) { |
| 17959 | mem_slot = var->const_value; | 17945 | mem_slot = var->const_value; |
| 17960 | } else if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) { | | |
| 17961 | // find the relevant exec_context | | |
| 17962 | assert(var->owner_exec != nullptr); | | |
| 17963 | assert(var->owner_exec->analysis != nullptr); | | |
| 17964 | IrExecContext *exec_context = &var->owner_exec->analysis->exec_context; | | |
| 17965 | assert(var->mem_slot_index < exec_context->mem_slot_list.length); | | |
| 17966 | mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index); | | |
| 17967 | } | 17946 | } |
| 17968 | | 17947 | |
| 17969 | if (mem_slot != nullptr) { | 17948 | if (mem_slot != nullptr) { |
| ... | @@ -18297,10 +18276,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -18297,10 +18276,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18297 | if (result == nullptr) { | 18276 | if (result == nullptr) { |
| 18298 | // Analyze the fn body block like any other constant expression. | 18277 | // Analyze the fn body block like any other constant expression. |
| 18299 | AstNode *body_node = fn_entry->body_node; | 18278 | AstNode *body_node = fn_entry->body_node; |
| 18300 | result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type, | 18279 | ZigValue *result_ptr; |
| 18301 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry, | 18280 | create_result_ptr(ira->codegen, return_type, &result, &result_ptr); |
| 18302 | nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, | 18281 | if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr, |
| 18303 | UndefOk); | 18282 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| | 18283 | fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, |
| | 18284 | UndefOk))) |
| | 18285 | { |
| | 18286 | return ira->codegen->invalid_instruction; |
| | 18287 | } |
| | 18288 | destroy(result_ptr, "ZigValue"); |
| | 18289 | result_ptr = nullptr; |
| 18304 | | 18290 | |
| 18305 | if (inferred_err_set_type != nullptr) { | 18291 | if (inferred_err_set_type != nullptr) { |
| 18306 | inferred_err_set_type->data.error_set.incomplete = false; | 18292 | inferred_err_set_type->data.error_set.incomplete = false; |
| ... | @@ -18407,14 +18393,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -18407,14 +18393,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18407 | } | 18393 | } |
| 18408 | | 18394 | |
| 18409 | if (fn_proto_node->data.fn_proto.align_expr != nullptr) { | 18395 | if (fn_proto_node->data.fn_proto.align_expr != nullptr) { |
| 18410 | ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, | 18396 | ZigValue *align_result; |
| 18411 | fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen), | 18397 | ZigValue *result_ptr; |
| 18412 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, | 18398 | create_result_ptr(ira->codegen, get_align_amt_type(ira->codegen), &align_result, &result_ptr); |
| 18413 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, | 18399 | if ((err = ir_eval_const_value(ira->codegen, impl_fn->child_scope, |
| 18414 | nullptr, UndefBad); | 18400 | fn_proto_node->data.fn_proto.align_expr, result_ptr, |
| 18415 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, | 18401 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| | 18402 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, |
| | 18403 | nullptr, UndefBad))) |
| | 18404 | { |
| | 18405 | return ira->codegen->invalid_instruction; |
| | 18406 | } |
| | 18407 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb, |
| 18416 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); | 18408 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 18417 | copy_const_val(const_instruction->base.value, align_result); | 18409 | const_instruction->base.value = align_result; |
| | 18410 | destroy(result_ptr, "ZigValue"); |
| 18418 | | 18411 | |
| 18419 | uint32_t align_bytes = 0; | 18412 | uint32_t align_bytes = 0; |
| 18420 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); | 18413 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| ... | @@ -18491,7 +18484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -18491,7 +18484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18491 | IrInstruction *result_loc; | 18484 | IrInstruction *result_loc; |
| 18492 | if (handle_is_ptr(impl_fn_type_id->return_type)) { | 18485 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 18493 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, | 18486 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18494 | impl_fn_type_id->return_type, nullptr, true, true, false); | 18487 | impl_fn_type_id->return_type, nullptr, true, false); |
| 18495 | if (result_loc != nullptr) { | 18488 | if (result_loc != nullptr) { |
| 18496 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 18489 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18497 | return result_loc; | 18490 | return result_loc; |
| ... | @@ -18623,7 +18616,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -18623,7 +18616,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18623 | IrInstruction *result_loc; | 18616 | IrInstruction *result_loc; |
| 18624 | if (handle_is_ptr(return_type)) { | 18617 | if (handle_is_ptr(return_type)) { |
| 18625 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, | 18618 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18626 | return_type, nullptr, true, true, false); | 18619 | return_type, nullptr, true, false); |
| 18627 | if (result_loc != nullptr) { | 18620 | if (result_loc != nullptr) { |
| 18628 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 18621 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18629 | return result_loc; | 18622 | return result_loc; |
| ... | @@ -19307,7 +19300,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh | ... | @@ -19307,7 +19300,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19307 | | 19300 | |
| 19308 | // In case resolving the parent activates a suspend, do it now | 19301 | // In case resolving the parent activates a suspend, do it now |
| 19309 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, | 19302 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 19310 | peer_parent->resolved_type, nullptr, false, false, true); | 19303 | peer_parent->resolved_type, nullptr, false, true); |
| 19311 | if (parent_result_loc != nullptr && | 19304 | if (parent_result_loc != nullptr && |
| 19312 | (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) | 19305 | (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) |
| 19313 | { | 19306 | { |
| ... | @@ -19702,8 +19695,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -19702,8 +19695,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19702 | | 19695 | |
| 19703 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && | 19696 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && |
| 19704 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && | 19697 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 19705 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || | 19698 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar)) |
| 19706 | array_type->id == ZigTypeIdArray)) | | |
| 19707 | { | 19699 | { |
| 19708 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, | 19700 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 19709 | elem_ptr_instruction->base.source_node); | 19701 | elem_ptr_instruction->base.source_node); |
| ... | @@ -19768,6 +19760,11 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -19768,6 +19760,11 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19768 | (array_type->id != ZigTypeIdPointer || | 19760 | (array_type->id != ZigTypeIdPointer || |
| 19769 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) | 19761 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 19770 | { | 19762 | { |
| | 19763 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| | 19764 | elem_ptr_instruction->base.source_node, array_ptr_val, UndefBad))) |
| | 19765 | { |
| | 19766 | return ira->codegen->invalid_instruction; |
| | 19767 | } |
| 19771 | if (array_type->id == ZigTypeIdPointer) { | 19768 | if (array_type->id == ZigTypeIdPointer) { |
| 19772 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); | 19769 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 19773 | ZigValue *out_val = result->value; | 19770 | ZigValue *out_val = result->value; |
| ... | @@ -21129,6 +21126,8 @@ static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIns | ... | @@ -21129,6 +21126,8 @@ static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIns |
| 21129 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, | 21126 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 21130 | IrInstruction *base_ptr, bool safety_check_on, bool initializing) | 21127 | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 21131 | { | 21128 | { |
| | 21129 | Error err; |
| | 21130 | |
| 21132 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); | 21131 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); |
| 21133 | if (type_is_invalid(type_entry)) | 21132 | if (type_is_invalid(type_entry)) |
| 21134 | return ira->codegen->invalid_instruction; | 21133 | return ira->codegen->invalid_instruction; |
| ... | @@ -21209,9 +21208,14 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr | ... | @@ -21209,9 +21208,14 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21209 | break; | 21208 | break; |
| 21210 | } | 21209 | } |
| 21211 | } | 21210 | } |
| 21212 | } else if (optional_value_is_null(optional_val)) { | 21211 | } else { |
| 21213 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); | 21212 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 21214 | return ira->codegen->invalid_instruction; | 21213 | source_instr->source_node, optional_val, UndefBad))) |
| | 21214 | return ira->codegen->invalid_instruction; |
| | 21215 | if (optional_value_is_null(optional_val)) { |
| | 21216 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| | 21217 | return ira->codegen->invalid_instruction; |
| | 21218 | } |
| 21215 | } | 21219 | } |
| 21216 | | 21220 | |
| 21217 | IrInstruction *result; | 21221 | IrInstruction *result; |
| ... | @@ -23812,11 +23816,18 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct | ... | @@ -23812,11 +23816,18 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23812 | | 23816 | |
| 23813 | // Execute the C import block like an inline function | 23817 | // Execute the C import block like an inline function |
| 23814 | ZigType *void_type = ira->codegen->builtin_types.entry_void; | 23818 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| 23815 | ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, | 23819 | ZigValue *cimport_result; |
| | 23820 | ZigValue *result_ptr; |
| | 23821 | create_result_ptr(ira->codegen, void_type, &cimport_result, &result_ptr); |
| | 23822 | if ((err = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, result_ptr, |
| 23816 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, | 23823 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 23817 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad); | 23824 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad))) |
| | 23825 | { |
| | 23826 | return ira->codegen->invalid_instruction; |
| | 23827 | } |
| 23818 | if (type_is_invalid(cimport_result->type)) | 23828 | if (type_is_invalid(cimport_result->type)) |
| 23819 | return ira->codegen->invalid_instruction; | 23829 | return ira->codegen->invalid_instruction; |
| | 23830 | destroy(result_ptr, "ZigValue"); |
| 23820 | | 23831 | |
| 23821 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope); | 23832 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope); |
| 23822 | Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, | 23833 | Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, |
| ... | @@ -24169,7 +24180,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi | ... | @@ -24169,7 +24180,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 24169 | IrInstruction *result_loc; | 24180 | IrInstruction *result_loc; |
| 24170 | if (handle_is_ptr(result_type)) { | 24181 | if (handle_is_ptr(result_type)) { |
| 24171 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 24182 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24172 | result_type, nullptr, true, false, true); | 24183 | result_type, nullptr, true, true); |
| 24173 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 24184 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 24174 | return result_loc; | 24185 | return result_loc; |
| 24175 | } | 24186 | } |
| ... | @@ -24434,7 +24445,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru | ... | @@ -24434,7 +24445,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24434 | } | 24445 | } |
| 24435 | | 24446 | |
| 24436 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 24447 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24437 | dest_slice_type, nullptr, true, false, true); | 24448 | dest_slice_type, nullptr, true, true); |
| 24438 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { | 24449 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { |
| 24439 | return result_loc; | 24450 | return result_loc; |
| 24440 | } | 24451 | } |
| ... | @@ -24519,7 +24530,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct | ... | @@ -24519,7 +24530,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 24519 | } | 24530 | } |
| 24520 | | 24531 | |
| 24521 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 24532 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24522 | dest_slice_type, nullptr, true, false, true); | 24533 | dest_slice_type, nullptr, true, true); |
| 24523 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 24534 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 24524 | return result_loc; | 24535 | return result_loc; |
| 24525 | } | 24536 | } |
| ... | @@ -25560,7 +25571,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -25560,7 +25571,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25560 | } | 25571 | } |
| 25561 | | 25572 | |
| 25562 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 25573 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 25563 | return_type, nullptr, true, false, true); | 25574 | return_type, nullptr, true, true); |
| 25564 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 25575 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 25565 | return result_loc; | 25576 | return result_loc; |
| 25566 | } | 25577 | } |
| ... | @@ -28318,7 +28329,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -28318,7 +28329,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 28318 | | 28329 | |
| 28319 | bool was_written = instruction->result_loc->written; | 28330 | bool was_written = instruction->result_loc->written; |
| 28320 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 28331 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 28321 | value->value->type, value, false, false, true); | 28332 | value->value->type, value, false, true); |
| 28322 | if (result_loc != nullptr) { | 28333 | if (result_loc != nullptr) { |
| 28323 | if (type_is_invalid(result_loc->value->type)) | 28334 | if (type_is_invalid(result_loc->value->type)) |
| 28324 | return ira->codegen->invalid_instruction; | 28335 | return ira->codegen->invalid_instruction; |
| ... | @@ -28353,7 +28364,7 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns | ... | @@ -28353,7 +28364,7 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns |
| 28353 | return operand; | 28364 | return operand; |
| 28354 | | 28365 | |
| 28355 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, | 28366 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 28356 | &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); | 28367 | &instruction->result_loc_cast->base, operand->value->type, operand, false, true); |
| 28357 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) | 28368 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 28358 | return result_loc; | 28369 | return result_loc; |
| 28359 | | 28370 | |
| ... | @@ -28369,15 +28380,15 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst | ... | @@ -28369,15 +28380,15 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst |
| 28369 | return operand; | 28380 | return operand; |
| 28370 | | 28381 | |
| 28371 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, | 28382 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 28372 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); | 28383 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true); |
| 28373 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) | 28384 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 28374 | return result_loc; | 28385 | return result_loc; |
| 28375 | | 28386 | |
| 28376 | if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { | 28387 | ZigType *dest_type = ir_resolve_type(ira, |
| 28377 | return instruction->result_loc_bit_cast->parent->gen_instruction; | 28388 | instruction->result_loc_bit_cast->base.source_instruction->child); |
| 28378 | } | 28389 | if (type_is_invalid(dest_type)) |
| 28379 | | 28390 | return ira->codegen->invalid_instruction; |
| 28380 | return result_loc; | 28391 | return ir_analyze_bit_cast(ira, &instruction->base, operand, dest_type); |
| 28381 | } | 28392 | } |
| 28382 | | 28393 | |
| 28383 | static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, | 28394 | static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| ... | @@ -28508,7 +28519,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction | ... | @@ -28508,7 +28519,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 28508 | IrInstruction *result_loc; | 28519 | IrInstruction *result_loc; |
| 28509 | if (type_has_bits(result_type)) { | 28520 | if (type_has_bits(result_type)) { |
| 28510 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 28521 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 28511 | result_type, nullptr, true, true, true); | 28522 | result_type, nullptr, true, true); |
| 28512 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) | 28523 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 28513 | return result_loc; | 28524 | return result_loc; |
| 28514 | } else { | 28525 | } else { |
| ... | @@ -28900,7 +28911,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -28900,7 +28911,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 28900 | // This function attempts to evaluate IR code while doing type checking and other analysis. | 28911 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 28901 | // It emits a new IrExecutable which is partially evaluated IR code. | 28912 | // It emits a new IrExecutable which is partially evaluated IR code. |
| 28902 | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, | 28913 | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| 28903 | ZigType *expected_type, AstNode *expected_type_source_node) | 28914 | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr) |
| 28904 | { | 28915 | { |
| 28905 | assert(old_exec->first_err_trace_msg == nullptr); | 28916 | assert(old_exec->first_err_trace_msg == nullptr); |
| 28906 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); | 28917 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| ... | @@ -28919,12 +28930,6 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ | ... | @@ -28919,12 +28930,6 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 28919 | ira->new_irb.codegen = codegen; | 28930 | ira->new_irb.codegen = codegen; |
| 28920 | ira->new_irb.exec = new_exec; | 28931 | ira->new_irb.exec = new_exec; |
| 28921 | | 28932 | |
| 28922 | ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); | | |
| 28923 | ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count); | | |
| 28924 | for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) { | | |
| 28925 | ira->exec_context.mem_slot_list.items[i] = &vals[i]; | | |
| 28926 | } | | |
| 28927 | | | |
| 28928 | IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); | 28933 | IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 28929 | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); | 28934 | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 28930 | ir_ref_bb(new_entry_bb); | 28935 | ir_ref_bb(new_entry_bb); |
| ... | @@ -28933,6 +28938,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ | ... | @@ -28933,6 +28938,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 28933 | | 28938 | |
| 28934 | ir_start_bb(ira, old_entry_bb, nullptr); | 28939 | ir_start_bb(ira, old_entry_bb, nullptr); |
| 28935 | | 28940 | |
| | 28941 | if (result_ptr != nullptr) { |
| | 28942 | assert(result_ptr->type->id == ZigTypeIdPointer); |
| | 28943 | IrInstructionConst *const_inst = ir_create_instruction<IrInstructionConst>( |
| | 28944 | &ira->new_irb, new_exec->begin_scope, new_exec->source_node); |
| | 28945 | const_inst->base.value = result_ptr; |
| | 28946 | ira->return_ptr = &const_inst->base; |
| | 28947 | } else { |
| | 28948 | assert(new_exec->begin_scope != nullptr); |
| | 28949 | assert(new_exec->source_node != nullptr); |
| | 28950 | ira->return_ptr = ir_build_return_ptr(ira, new_exec->begin_scope, new_exec->source_node, |
| | 28951 | get_pointer_to_type(codegen, expected_type, false)); |
| | 28952 | } |
| | 28953 | |
| 28936 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { | 28954 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 28937 | IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); | 28955 | IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 28938 | | 28956 | |