| ... | @@ -41,6 +41,7 @@ struct IrAnalyze { | ... | @@ -41,6 +41,7 @@ struct IrAnalyze { |
| 41 | ZigList<IrInstruction *> src_implicit_return_type_list; | 41 | ZigList<IrInstruction *> src_implicit_return_type_list; |
| 42 | ZigList<IrSuspendPosition> resume_stack; | 42 | ZigList<IrSuspendPosition> resume_stack; |
| 43 | IrBasicBlock *const_predecessor_bb; | 43 | IrBasicBlock *const_predecessor_bb; |
| | 44 | size_t ref_count; |
| 44 | }; | 45 | }; |
| 45 | | 46 | |
| 46 | enum ConstCastResultId { | 47 | enum ConstCastResultId { |
| ... | @@ -252,6 +253,18 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n | ... | @@ -252,6 +253,18 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 252 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); | 253 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); |
| 253 | static ResultLoc *no_result_loc(void); | 254 | static ResultLoc *no_result_loc(void); |
| 254 | | 255 | |
| | 256 | static void ira_ref(IrAnalyze *ira) { |
| | 257 | ira->ref_count += 1; |
| | 258 | } |
| | 259 | static void ira_deref(IrAnalyze *ira) { |
| | 260 | if (ira->ref_count > 1) { |
| | 261 | ira->ref_count -= 1; |
| | 262 | return; |
| | 263 | } |
| | 264 | assert(ira->ref_count != 0); |
| | 265 | destroy(ira, "IrAnalyze"); |
| | 266 | } |
| | 267 | |
| 255 | static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) { | 268 | static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) { |
| 256 | assert(get_src_ptr_type(const_val->type) != nullptr); | 269 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| 257 | assert(const_val->special == ConstValSpecialStatic); | 270 | assert(const_val->special == ConstValSpecialStatic); |
| ... | @@ -16011,8 +16024,8 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, | ... | @@ -16011,8 +16024,8 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 16011 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); | 16024 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 16012 | result->value->special = ConstValSpecialLazy; | 16025 | result->value->special = ConstValSpecialLazy; |
| 16013 | | 16026 | |
| 16014 | LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1); | 16027 | LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType"); |
| 16015 | lazy_err_union_type->ira = ira; | 16028 | lazy_err_union_type->ira = ira; ira_ref(ira); |
| 16016 | result->value->data.x_lazy = &lazy_err_union_type->base; | 16029 | result->value->data.x_lazy = &lazy_err_union_type->base; |
| 16017 | lazy_err_union_type->base.id = LazyValueIdErrUnionType; | 16030 | lazy_err_union_type->base.id = LazyValueIdErrUnionType; |
| 16018 | | 16031 | |
| ... | @@ -17863,8 +17876,8 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp | ... | @@ -17863,8 +17876,8 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp |
| 17863 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); | 17876 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 17864 | result->value->special = ConstValSpecialLazy; | 17877 | result->value->special = ConstValSpecialLazy; |
| 17865 | | 17878 | |
| 17866 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1); | 17879 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType"); |
| 17867 | lazy_opt_type->ira = ira; | 17880 | lazy_opt_type->ira = ira; ira_ref(ira); |
| 17868 | result->value->data.x_lazy = &lazy_opt_type->base; | 17881 | result->value->data.x_lazy = &lazy_opt_type->base; |
| 17869 | lazy_opt_type->base.id = LazyValueIdOptType; | 17882 | lazy_opt_type->base.id = LazyValueIdOptType; |
| 17870 | | 17883 | |
| ... | @@ -19809,8 +19822,8 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -19809,8 +19822,8 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 19809 | IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type); | 19822 | IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type); |
| 19810 | result->value->special = ConstValSpecialLazy; | 19823 | result->value->special = ConstValSpecialLazy; |
| 19811 | | 19824 | |
| 19812 | LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1); | 19825 | LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType"); |
| 19813 | lazy_slice_type->ira = ira; | 19826 | lazy_slice_type->ira = ira; ira_ref(ira); |
| 19814 | result->value->data.x_lazy = &lazy_slice_type->base; | 19827 | result->value->data.x_lazy = &lazy_slice_type->base; |
| 19815 | lazy_slice_type->base.id = LazyValueIdSliceType; | 19828 | lazy_slice_type->base.id = LazyValueIdSliceType; |
| 19816 | | 19829 | |
| ... | @@ -19969,8 +19982,8 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi | ... | @@ -19969,8 +19982,8 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi |
| 19969 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); | 19982 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 19970 | result->value->special = ConstValSpecialLazy; | 19983 | result->value->special = ConstValSpecialLazy; |
| 19971 | | 19984 | |
| 19972 | LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1); | 19985 | LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf"); |
| 19973 | lazy_size_of->ira = ira; | 19986 | lazy_size_of->ira = ira; ira_ref(ira); |
| 19974 | result->value->data.x_lazy = &lazy_size_of->base; | 19987 | result->value->data.x_lazy = &lazy_size_of->base; |
| 19975 | lazy_size_of->base.id = LazyValueIdSizeOf; | 19988 | lazy_size_of->base.id = LazyValueIdSizeOf; |
| 19976 | | 19989 | |
| ... | @@ -24647,8 +24660,8 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct | ... | @@ -24647,8 +24660,8 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct |
| 24647 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); | 24660 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 24648 | result->value->special = ConstValSpecialLazy; | 24661 | result->value->special = ConstValSpecialLazy; |
| 24649 | | 24662 | |
| 24650 | LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1); | 24663 | LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf"); |
| 24651 | lazy_align_of->ira = ira; | 24664 | lazy_align_of->ira = ira; ira_ref(ira); |
| 24652 | result->value->data.x_lazy = &lazy_align_of->base; | 24665 | result->value->data.x_lazy = &lazy_align_of->base; |
| 24653 | lazy_align_of->base.id = LazyValueIdAlignOf; | 24666 | lazy_align_of->base.id = LazyValueIdAlignOf; |
| 24654 | | 24667 | |
| ... | @@ -25131,8 +25144,8 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct | ... | @@ -25131,8 +25144,8 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25131 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); | 25144 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 25132 | result->value->special = ConstValSpecialLazy; | 25145 | result->value->special = ConstValSpecialLazy; |
| 25133 | | 25146 | |
| 25134 | LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1); | 25147 | LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType"); |
| 25135 | lazy_fn_type->ira = ira; | 25148 | lazy_fn_type->ira = ira; ira_ref(ira); |
| 25136 | result->value->data.x_lazy = &lazy_fn_type->base; | 25149 | result->value->data.x_lazy = &lazy_fn_type->base; |
| 25137 | lazy_fn_type->base.id = LazyValueIdFnType; | 25150 | lazy_fn_type->base.id = LazyValueIdFnType; |
| 25138 | | 25151 | |
| ... | @@ -26172,8 +26185,8 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct | ... | @@ -26172,8 +26185,8 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 26172 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); | 26185 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 26173 | result->value->special = ConstValSpecialLazy; | 26186 | result->value->special = ConstValSpecialLazy; |
| 26174 | | 26187 | |
| 26175 | LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1); | 26188 | LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType"); |
| 26176 | lazy_ptr_type->ira = ira; | 26189 | lazy_ptr_type->ira = ira; ira_ref(ira); |
| 26177 | result->value->data.x_lazy = &lazy_ptr_type->base; | 26190 | result->value->data.x_lazy = &lazy_ptr_type->base; |
| 26178 | lazy_ptr_type->base.id = LazyValueIdPtrType; | 26191 | lazy_ptr_type->base.id = LazyValueIdPtrType; |
| 26179 | | 26192 | |
| ... | @@ -27646,7 +27659,8 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ | ... | @@ -27646,7 +27659,8 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27646 | assert(old_exec->first_err_trace_msg == nullptr); | 27659 | assert(old_exec->first_err_trace_msg == nullptr); |
| 27647 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); | 27660 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| 27648 | | 27661 | |
| 27649 | IrAnalyze *ira = allocate<IrAnalyze>(1); | 27662 | IrAnalyze *ira = allocate<IrAnalyze>(1, "IrAnalyze"); |
| | 27663 | ira->ref_count = 1; |
| 27650 | old_exec->analysis = ira; | 27664 | old_exec->analysis = ira; |
| 27651 | ira->codegen = codegen; | 27665 | ira->codegen = codegen; |
| 27652 | | 27666 | |
| ... | @@ -27713,6 +27727,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ | ... | @@ -27713,6 +27727,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27713 | ira->instruction_index += 1; | 27727 | ira->instruction_index += 1; |
| 27714 | } | 27728 | } |
| 27715 | | 27729 | |
| | 27730 | ZigType *res_type; |
| 27716 | if (new_exec->first_err_trace_msg != nullptr) { | 27731 | if (new_exec->first_err_trace_msg != nullptr) { |
| 27717 | codegen->trace_err = new_exec->first_err_trace_msg; | 27732 | codegen->trace_err = new_exec->first_err_trace_msg; |
| 27718 | if (codegen->trace_err != nullptr && new_exec->source_node != nullptr && | 27733 | if (codegen->trace_err != nullptr && new_exec->source_node != nullptr && |
| ... | @@ -27722,13 +27737,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ | ... | @@ -27722,13 +27737,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27722 | codegen->trace_err = add_error_note(codegen, codegen->trace_err, | 27737 | codegen->trace_err = add_error_note(codegen, codegen->trace_err, |
| 27723 | new_exec->source_node, buf_create_from_str("referenced here")); | 27738 | new_exec->source_node, buf_create_from_str("referenced here")); |
| 27724 | } | 27739 | } |
| 27725 | return ira->codegen->builtin_types.entry_invalid; | 27740 | res_type = ira->codegen->builtin_types.entry_invalid; |
| 27726 | } else if (ira->src_implicit_return_type_list.length == 0) { | 27741 | } else if (ira->src_implicit_return_type_list.length == 0) { |
| 27727 | return codegen->builtin_types.entry_unreachable; | 27742 | res_type = codegen->builtin_types.entry_unreachable; |
| 27728 | } else { | 27743 | } else { |
| 27729 | return ir_resolve_peer_types(ira, expected_type_source_node, expected_type, ira->src_implicit_return_type_list.items, | 27744 | res_type = ir_resolve_peer_types(ira, expected_type_source_node, expected_type, ira->src_implicit_return_type_list.items, |
| 27730 | ira->src_implicit_return_type_list.length); | 27745 | ira->src_implicit_return_type_list.length); |
| 27731 | } | 27746 | } |
| | 27747 | |
| | 27748 | // It is now safe to free Pass 1 IR instructions. |
| | 27749 | ira_deref(ira); |
| | 27750 | |
| | 27751 | return res_type; |
| 27732 | } | 27752 | } |
| 27733 | | 27753 | |
| 27734 | bool ir_has_side_effects(IrInstruction *instruction) { | 27754 | bool ir_has_side_effects(IrInstruction *instruction) { |
| ... | @@ -28064,6 +28084,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -28064,6 +28084,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28064 | val->special = ConstValSpecialStatic; | 28084 | val->special = ConstValSpecialStatic; |
| 28065 | assert(val->type->id == ZigTypeIdComptimeInt || val->type->id == ZigTypeIdInt); | 28085 | assert(val->type->id == ZigTypeIdComptimeInt || val->type->id == ZigTypeIdInt); |
| 28066 | bigint_init_unsigned(&val->data.x_bigint, align_in_bytes); | 28086 | bigint_init_unsigned(&val->data.x_bigint, align_in_bytes); |
| | 28087 | |
| | 28088 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28067 | return ErrorNone; | 28089 | return ErrorNone; |
| 28068 | } | 28090 | } |
| 28069 | case LazyValueIdSizeOf: { | 28091 | case LazyValueIdSizeOf: { |
| ... | @@ -28119,6 +28141,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -28119,6 +28141,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28119 | val->special = ConstValSpecialStatic; | 28141 | val->special = ConstValSpecialStatic; |
| 28120 | assert(val->type->id == ZigTypeIdComptimeInt || val->type->id == ZigTypeIdInt); | 28142 | assert(val->type->id == ZigTypeIdComptimeInt || val->type->id == ZigTypeIdInt); |
| 28121 | bigint_init_unsigned(&val->data.x_bigint, abi_size); | 28143 | bigint_init_unsigned(&val->data.x_bigint, abi_size); |
| | 28144 | |
| | 28145 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28122 | return ErrorNone; | 28146 | return ErrorNone; |
| 28123 | } | 28147 | } |
| 28124 | case LazyValueIdSliceType: { | 28148 | case LazyValueIdSliceType: { |
| ... | @@ -28197,6 +28221,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -28197,6 +28221,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28197 | val->special = ConstValSpecialStatic; | 28221 | val->special = ConstValSpecialStatic; |
| 28198 | assert(val->type->id == ZigTypeIdMetaType); | 28222 | assert(val->type->id == ZigTypeIdMetaType); |
| 28199 | val->data.x_type = get_slice_type(ira->codegen, slice_ptr_type); | 28223 | val->data.x_type = get_slice_type(ira->codegen, slice_ptr_type); |
| | 28224 | |
| | 28225 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28200 | return ErrorNone; | 28226 | return ErrorNone; |
| 28201 | } | 28227 | } |
| 28202 | case LazyValueIdPtrType: { | 28228 | case LazyValueIdPtrType: { |
| ... | @@ -28268,6 +28294,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -28268,6 +28294,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28268 | lazy_ptr_type->bit_offset_in_host, lazy_ptr_type->host_int_bytes, | 28294 | lazy_ptr_type->bit_offset_in_host, lazy_ptr_type->host_int_bytes, |
| 28269 | allow_zero, VECTOR_INDEX_NONE, nullptr, sentinel_val); | 28295 | allow_zero, VECTOR_INDEX_NONE, nullptr, sentinel_val); |
| 28270 | val->special = ConstValSpecialStatic; | 28296 | val->special = ConstValSpecialStatic; |
| | 28297 | |
| | 28298 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28271 | return ErrorNone; | 28299 | return ErrorNone; |
| 28272 | } | 28300 | } |
| 28273 | case LazyValueIdOptType: { | 28301 | case LazyValueIdOptType: { |
| ... | @@ -28290,16 +28318,21 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -28290,16 +28318,21 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28290 | assert(val->type->id == ZigTypeIdMetaType); | 28318 | assert(val->type->id == ZigTypeIdMetaType); |
| 28291 | val->data.x_type = get_optional_type(ira->codegen, payload_type); | 28319 | val->data.x_type = get_optional_type(ira->codegen, payload_type); |
| 28292 | val->special = ConstValSpecialStatic; | 28320 | val->special = ConstValSpecialStatic; |
| | 28321 | |
| | 28322 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28293 | return ErrorNone; | 28323 | return ErrorNone; |
| 28294 | } | 28324 | } |
| 28295 | case LazyValueIdFnType: { | 28325 | case LazyValueIdFnType: { |
| 28296 | LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(val->data.x_lazy); | 28326 | LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(val->data.x_lazy); |
| 28297 | ZigType *fn_type = ir_resolve_lazy_fn_type(lazy_fn_type->ira, source_node, lazy_fn_type); | 28327 | IrAnalyze *ira = lazy_fn_type->ira; |
| | 28328 | ZigType *fn_type = ir_resolve_lazy_fn_type(ira, source_node, lazy_fn_type); |
| 28298 | if (fn_type == nullptr) | 28329 | if (fn_type == nullptr) |
| 28299 | return ErrorSemanticAnalyzeFail; | 28330 | return ErrorSemanticAnalyzeFail; |
| 28300 | val->special = ConstValSpecialStatic; | 28331 | val->special = ConstValSpecialStatic; |
| 28301 | assert(val->type->id == ZigTypeIdMetaType); | 28332 | assert(val->type->id == ZigTypeIdMetaType); |
| 28302 | val->data.x_type = fn_type; | 28333 | val->data.x_type = fn_type; |
| | 28334 | |
| | 28335 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28303 | return ErrorNone; | 28336 | return ErrorNone; |
| 28304 | } | 28337 | } |
| 28305 | case LazyValueIdErrUnionType: { | 28338 | case LazyValueIdErrUnionType: { |
| ... | @@ -28328,6 +28361,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -28328,6 +28361,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28328 | assert(val->type->id == ZigTypeIdMetaType); | 28361 | assert(val->type->id == ZigTypeIdMetaType); |
| 28329 | val->data.x_type = get_error_union_type(ira->codegen, err_set_type, payload_type); | 28362 | val->data.x_type = get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 28330 | val->special = ConstValSpecialStatic; | 28363 | val->special = ConstValSpecialStatic; |
| | 28364 | |
| | 28365 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 28331 | return ErrorNone; | 28366 | return ErrorNone; |
| 28332 | } | 28367 | } |
| 28333 | } | 28368 | } |