| ... | @@ -187,9 +187,9 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -187,9 +187,9 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 187 | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, | 187 | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 188 | ZigType *dest_type); | 188 | ZigType *dest_type); |
| 189 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 189 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 190 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value); | 190 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool non_null_comptime); |
| 191 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 191 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 192 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime); | 192 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime); |
| 193 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, | 193 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 194 | IrInstruction *base_ptr, bool safety_check_on, bool initializing); | 194 | IrInstruction *base_ptr, bool safety_check_on, bool initializing); |
| 195 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, | 195 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| ... | @@ -10844,7 +10844,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc | ... | @@ -10844,7 +10844,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 10844 | } | 10844 | } |
| 10845 | | 10845 | |
| 10846 | if (result_loc == nullptr) result_loc = no_result_loc(); | 10846 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 10847 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true); | 10847 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); |
| 10848 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 10848 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 10849 | return result_loc_inst; | 10849 | return result_loc_inst; |
| 10850 | } | 10850 | } |
| ... | @@ -11282,7 +11282,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so | ... | @@ -11282,7 +11282,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11282 | } | 11282 | } |
| 11283 | IrInstruction *result_loc_inst = nullptr; | 11283 | IrInstruction *result_loc_inst = nullptr; |
| 11284 | if (result_loc != nullptr) { | 11284 | if (result_loc != nullptr) { |
| 11285 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true); | 11285 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); |
| 11286 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 11286 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11287 | return result_loc_inst; | 11287 | return result_loc_inst; |
| 11288 | } | 11288 | } |
| ... | @@ -11325,7 +11325,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -11325,7 +11325,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11325 | IrInstruction *result_loc_inst; | 11325 | IrInstruction *result_loc_inst; |
| 11326 | if (handle_is_ptr(wanted_type)) { | 11326 | if (handle_is_ptr(wanted_type)) { |
| 11327 | if (result_loc == nullptr) result_loc = no_result_loc(); | 11327 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11328 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true); | 11328 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); |
| 11329 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 11329 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11330 | return result_loc_inst; | 11330 | return result_loc_inst; |
| 11331 | } | 11331 | } |
| ... | @@ -11410,7 +11410,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so | ... | @@ -11410,7 +11410,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11410 | IrInstruction *result_loc_inst; | 11410 | IrInstruction *result_loc_inst; |
| 11411 | if (handle_is_ptr(wanted_type)) { | 11411 | if (handle_is_ptr(wanted_type)) { |
| 11412 | if (result_loc == nullptr) result_loc = no_result_loc(); | 11412 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11413 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true); | 11413 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); |
| 11414 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 11414 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11415 | return result_loc_inst; | 11415 | return result_loc_inst; |
| 11416 | } | 11416 | } |
| ... | @@ -11483,7 +11483,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -11483,7 +11483,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 11483 | | 11483 | |
| 11484 | IrInstruction *result_loc; | 11484 | IrInstruction *result_loc; |
| 11485 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { | 11485 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { |
| 11486 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true); | 11486 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, false); |
| 11487 | } else { | 11487 | } else { |
| 11488 | result_loc = nullptr; | 11488 | result_loc = nullptr; |
| 11489 | } | 11489 | } |
| ... | @@ -11527,7 +11527,7 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s | ... | @@ -11527,7 +11527,7 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s |
| 11527 | if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); | 11527 | if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); |
| 11528 | | 11528 | |
| 11529 | if (result_loc == nullptr) result_loc = no_result_loc(); | 11529 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11530 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true); | 11530 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); |
| 11531 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 11531 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11532 | return result_loc_inst; | 11532 | return result_loc_inst; |
| 11533 | } | 11533 | } |
| ... | @@ -12180,7 +12180,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * | ... | @@ -12180,7 +12180,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 12180 | result->value.type = array_type; | 12180 | result->value.type = array_type; |
| 12181 | return result; | 12181 | return result; |
| 12182 | } | 12182 | } |
| 12183 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true); | 12183 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, false); |
| 12184 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 12184 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12185 | return result_loc_inst; | 12185 | return result_loc_inst; |
| 12186 | } | 12186 | } |
| ... | @@ -12761,7 +12761,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -12761,7 +12761,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 12761 | IrInstruction *result_loc_inst; | 12761 | IrInstruction *result_loc_inst; |
| 12762 | if (type_entry->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { | 12762 | if (type_entry->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { |
| 12763 | if (result_loc == nullptr) result_loc = no_result_loc(); | 12763 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12764 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true); | 12764 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, false); |
| 12765 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 12765 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12766 | return result_loc_inst; | 12766 | return result_loc_inst; |
| 12767 | } | 12767 | } |
| ... | @@ -14910,7 +14910,7 @@ static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { | ... | @@ -14910,7 +14910,7 @@ static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { |
| 14910 | | 14910 | |
| 14911 | // when calling this function, at the callsite must check for result type noreturn and propagate it up | 14911 | // when calling this function, at the callsite must check for result type noreturn and propagate it up |
| 14912 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 14912 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 14913 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value) | 14913 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool non_null_comptime) |
| 14914 | { | 14914 | { |
| 14915 | Error err; | 14915 | Error err; |
| 14916 | if (result_loc->resolved_loc != nullptr) { | 14916 | if (result_loc->resolved_loc != nullptr) { |
| ... | @@ -14984,9 +14984,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -14984,9 +14984,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14984 | return result_loc->resolved_loc; | 14984 | return result_loc->resolved_loc; |
| 14985 | } | 14985 | } |
| 14986 | case ResultLocIdReturn: { | 14986 | case ResultLocIdReturn: { |
| 14987 | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; | 14987 | if (!non_null_comptime) { |
| 14988 | if (is_comptime) | 14988 | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; |
| 14989 | return nullptr; | 14989 | if (is_comptime) |
| | 14990 | return nullptr; |
| | 14991 | } |
| 14990 | if (!type_has_bits(ira->explicit_return_type) || !handle_is_ptr(ira->explicit_return_type)) | 14992 | if (!type_has_bits(ira->explicit_return_type) || !handle_is_ptr(ira->explicit_return_type)) |
| 14991 | return nullptr; | 14993 | return nullptr; |
| 14992 | | 14994 | |
| ... | @@ -15005,6 +15007,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15005,6 +15007,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15005 | return ira->codegen->invalid_instruction; | 15007 | return ira->codegen->invalid_instruction; |
| 15006 | peer_parent->skipped = is_comptime; | 15008 | peer_parent->skipped = is_comptime; |
| 15007 | if (peer_parent->skipped) { | 15009 | if (peer_parent->skipped) { |
| | 15010 | if (non_null_comptime) { |
| | 15011 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| | 15012 | value_type, value, false, non_null_comptime); |
| | 15013 | } |
| 15008 | return nullptr; | 15014 | return nullptr; |
| 15009 | } | 15015 | } |
| 15010 | | 15016 | |
| ... | @@ -15016,7 +15022,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15016,7 +15022,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15016 | } | 15022 | } |
| 15017 | | 15023 | |
| 15018 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 15024 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 15019 | peer_parent->resolved_type, nullptr, false); | 15025 | peer_parent->resolved_type, nullptr, false, non_null_comptime); |
| 15020 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | 15026 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 15021 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) | 15027 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 15022 | { | 15028 | { |
| ... | @@ -15066,7 +15072,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15066,7 +15072,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15066 | } | 15072 | } |
| 15067 | | 15073 | |
| 15068 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, | 15074 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 15069 | dest_type, bitcasted_value, false); | 15075 | dest_type, bitcasted_value, false, non_null_comptime); |
| 15070 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | 15076 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 15071 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) | 15077 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 15072 | { | 15078 | { |
| ... | @@ -15094,10 +15100,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15094,10 +15100,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15094 | } | 15100 | } |
| 15095 | | 15101 | |
| 15096 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 15102 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 15097 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime) | 15103 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| | 15104 | bool non_null_comptime) |
| 15098 | { | 15105 | { |
| 15099 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, | 15106 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 15100 | value); | 15107 | value, non_null_comptime); |
| 15101 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) | 15108 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) |
| 15102 | return result_loc; | 15109 | return result_loc; |
| 15103 | | 15110 | |
| ... | @@ -15144,23 +15151,16 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn | ... | @@ -15144,23 +15151,16 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn |
| 15144 | ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); | 15151 | ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); |
| 15145 | if (type_is_invalid(implicit_elem_type)) | 15152 | if (type_is_invalid(implicit_elem_type)) |
| 15146 | return ira->codegen->invalid_instruction; | 15153 | return ira->codegen->invalid_instruction; |
| 15147 | ResultLoc *old_result_loc = instruction->result_loc; | 15154 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 15148 | for (;;) { | 15155 | implicit_elem_type, nullptr, false, true); |
| 15149 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, old_result_loc, | 15156 | if (result_loc != nullptr) |
| 15150 | implicit_elem_type, nullptr, false); | 15157 | return result_loc; |
| 15151 | if (result_loc != nullptr) | | |
| 15152 | return result_loc; | | |
| 15153 | | 15158 | |
| 15154 | if (instruction->result_loc->id == ResultLocIdPeer) { | 15159 | IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); |
| 15155 | old_result_loc = reinterpret_cast<ResultLocPeer *>(instruction->result_loc)->parent->parent; | 15160 | result->value.special = ConstValSpecialUndef; |
| 15156 | continue; | 15161 | IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); |
| 15157 | } | 15162 | ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 15158 | IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); | 15163 | return ptr; |
| 15159 | result->value.special = ConstValSpecialUndef; | | |
| 15160 | IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); | | |
| 15161 | ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; | | |
| 15162 | return ptr; | | |
| 15163 | } | | |
| 15164 | } | 15164 | } |
| 15165 | | 15165 | |
| 15166 | static void ir_reset_result(ResultLoc *result_loc) { | 15166 | static void ir_reset_result(ResultLoc *result_loc) { |
| ... | @@ -15500,7 +15500,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -15500,7 +15500,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 15500 | // * "string literal used as comptime slice is memoized" | 15500 | // * "string literal used as comptime slice is memoized" |
| 15501 | // * "comptime modification of const struct field" - except modified to avoid | 15501 | // * "comptime modification of const struct field" - except modified to avoid |
| 15502 | // ConstPtrMutComptimeVar, thus defeating the logic below. | 15502 | // ConstPtrMutComptimeVar, thus defeating the logic below. |
| 15503 | bool same_global_refs = ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; | 15503 | bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar; |
| 15504 | copy_const_val(dest_val, &value->value, same_global_refs); | 15504 | copy_const_val(dest_val, &value->value, same_global_refs); |
| 15505 | if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) { | 15505 | if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) { |
| 15506 | ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr; | 15506 | ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr; |
| ... | @@ -15986,7 +15986,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -15986,7 +15986,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15986 | IrInstruction *result_loc; | 15986 | IrInstruction *result_loc; |
| 15987 | if (handle_is_ptr(impl_fn_type_id->return_type)) { | 15987 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 15988 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, | 15988 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15989 | impl_fn_type_id->return_type, nullptr, true); | 15989 | impl_fn_type_id->return_type, nullptr, true, false); |
| 15990 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 15990 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 15991 | return result_loc; | 15991 | return result_loc; |
| 15992 | } | 15992 | } |
| ... | @@ -16106,7 +16106,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -16106,7 +16106,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 16106 | IrInstruction *result_loc; | 16106 | IrInstruction *result_loc; |
| 16107 | if (handle_is_ptr(return_type)) { | 16107 | if (handle_is_ptr(return_type)) { |
| 16108 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, | 16108 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 16109 | return_type, nullptr, true); | 16109 | return_type, nullptr, true, false); |
| 16110 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 16110 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 16111 | return result_loc; | 16111 | return result_loc; |
| 16112 | } | 16112 | } |
| ... | @@ -16198,7 +16198,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source | ... | @@ -16198,7 +16198,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 16198 | | 16198 | |
| 16199 | if (dst_size <= src_size) { | 16199 | if (dst_size <= src_size) { |
| 16200 | if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) { | 16200 | if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) { |
| 16201 | copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst); | 16201 | copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar); |
| 16202 | return ErrorNone; | 16202 | return ErrorNone; |
| 16203 | } | 16203 | } |
| 16204 | Buf buf = BUF_INIT; | 16204 | Buf buf = BUF_INIT; |
| ... | @@ -16600,7 +16600,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh | ... | @@ -16600,7 +16600,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 16600 | | 16600 | |
| 16601 | // In case resolving the parent activates a suspend, do it now | 16601 | // In case resolving the parent activates a suspend, do it now |
| 16602 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, | 16602 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 16603 | peer_parent->resolved_type, nullptr, false); | 16603 | peer_parent->resolved_type, nullptr, false, false); |
| 16604 | if (parent_result_loc != nullptr && | 16604 | if (parent_result_loc != nullptr && |
| 16605 | (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) | 16605 | (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) |
| 16606 | { | 16606 | { |
| ... | @@ -17246,11 +17246,10 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction | ... | @@ -17246,11 +17246,10 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 17246 | field_val->special = ConstValSpecialUndef; | 17246 | field_val->special = ConstValSpecialUndef; |
| 17247 | field_val->type = struct_type->data.structure.fields[i].type_entry; | 17247 | field_val->type = struct_type->data.structure.fields[i].type_entry; |
| 17248 | ConstParent *parent = get_const_val_parent(ira->codegen, field_val); | 17248 | ConstParent *parent = get_const_val_parent(ira->codegen, field_val); |
| 17249 | if (parent != nullptr) { | 17249 | assert(parent != nullptr); |
| 17250 | parent->id = ConstParentIdStruct; | 17250 | parent->id = ConstParentIdStruct; |
| 17251 | parent->data.p_struct.struct_val = struct_val; | 17251 | parent->data.p_struct.struct_val = struct_val; |
| 17252 | parent->data.p_struct.field_index = i; | 17252 | parent->data.p_struct.field_index = i; |
| 17253 | } | | |
| 17254 | } | 17253 | } |
| 17255 | } | 17254 | } |
| 17256 | IrInstruction *result; | 17255 | IrInstruction *result; |
| ... | @@ -17264,7 +17263,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction | ... | @@ -17264,7 +17263,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 17264 | } | 17263 | } |
| 17265 | ConstExprValue *const_val = &result->value; | 17264 | ConstExprValue *const_val = &result->value; |
| 17266 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; | 17265 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| 17267 | const_val->data.x_ptr.mut = struct_ptr->value.data.x_ptr.mut; | 17266 | const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 17268 | const_val->data.x_ptr.data.base_struct.struct_val = struct_val; | 17267 | const_val->data.x_ptr.data.base_struct.struct_val = struct_val; |
| 17269 | const_val->data.x_ptr.data.base_struct.field_index = field->src_index; | 17268 | const_val->data.x_ptr.data.base_struct.field_index = field->src_index; |
| 17270 | return result; | 17269 | return result; |
| ... | @@ -17414,6 +17413,11 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, | ... | @@ -17414,6 +17413,11 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 17414 | link_lib->symbols.append(symbol_name); | 17413 | link_lib->symbols.append(symbol_name); |
| 17415 | } | 17414 | } |
| 17416 | | 17415 | |
| | 17416 | static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) { |
| | 17417 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected")); |
| | 17418 | emit_error_notes_for_ref_stack(ira->codegen, msg); |
| | 17419 | return ira->codegen->invalid_instruction; |
| | 17420 | } |
| 17417 | | 17421 | |
| 17418 | static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { | 17422 | static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 17419 | resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node); | 17423 | resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node); |
| ... | @@ -17428,6 +17432,9 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -17428,6 +17432,9 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 17428 | { | 17432 | { |
| 17429 | TldVar *tld_var = (TldVar *)tld; | 17433 | TldVar *tld_var = (TldVar *)tld; |
| 17430 | ZigVar *var = tld_var->var; | 17434 | ZigVar *var = tld_var->var; |
| | 17435 | if (var == nullptr) { |
| | 17436 | return ir_error_dependency_loop(ira, source_instruction); |
| | 17437 | } |
| 17431 | if (tld_var->extern_lib_name != nullptr) { | 17438 | if (tld_var->extern_lib_name != nullptr) { |
| 17432 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); | 17439 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); |
| 17433 | } | 17440 | } |
| ... | @@ -17443,23 +17450,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -17443,23 +17450,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 17443 | if (type_is_invalid(fn_entry->type_entry)) | 17450 | if (type_is_invalid(fn_entry->type_entry)) |
| 17444 | return ira->codegen->invalid_instruction; | 17451 | return ira->codegen->invalid_instruction; |
| 17445 | | 17452 | |
| 17446 | // TODO instead of allocating this every time, put it in the tld value and we can reference | | |
| 17447 | // the same one every time | | |
| 17448 | ConstExprValue *const_val = create_const_vals(1); | | |
| 17449 | const_val->special = ConstValSpecialStatic; | | |
| 17450 | const_val->type = fn_entry->type_entry; | | |
| 17451 | const_val->data.x_ptr.data.fn.fn_entry = fn_entry; | | |
| 17452 | const_val->data.x_ptr.special = ConstPtrSpecialFunction; | | |
| 17453 | const_val->data.x_ptr.mut = ConstPtrMutComptimeConst; | | |
| 17454 | | | |
| 17455 | if (tld_fn->extern_lib_name != nullptr) { | 17453 | if (tld_fn->extern_lib_name != nullptr) { |
| 17456 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node); | 17454 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node); |
| 17457 | } | 17455 | } |
| 17458 | | 17456 | |
| 17459 | bool ptr_is_const = true; | 17457 | IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope, |
| 17460 | bool ptr_is_volatile = false; | 17458 | source_instruction->source_node, fn_entry); |
| 17461 | return ir_get_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, | 17459 | return ir_get_ref(ira, source_instruction, fn_inst, true, false); |
| 17462 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); | | |
| 17463 | } | 17460 | } |
| 17464 | } | 17461 | } |
| 17465 | zig_unreachable(); | 17462 | zig_unreachable(); |
| ... | @@ -19673,12 +19670,6 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, | ... | @@ -19673,12 +19670,6 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 19673 | return ir_const_unsigned(ira, &instruction->base, bit_offset); | 19670 | return ir_const_unsigned(ira, &instruction->base, bit_offset); |
| 19674 | } | 19671 | } |
| 19675 | | 19672 | |
| 19676 | static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) { | | |
| 19677 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected")); | | |
| 19678 | emit_error_notes_for_ref_stack(ira->codegen, msg); | | |
| 19679 | return ira->codegen->invalid_instruction; | | |
| 19680 | } | | |
| 19681 | | | |
| 19682 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { | 19673 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { |
| 19683 | Buf *field_name_buf; | 19674 | Buf *field_name_buf; |
| 19684 | | 19675 | |
| ... | @@ -21088,7 +21079,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi | ... | @@ -21088,7 +21079,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 21088 | IrInstruction *result_loc; | 21079 | IrInstruction *result_loc; |
| 21089 | if (handle_is_ptr(result_type)) { | 21080 | if (handle_is_ptr(result_type)) { |
| 21090 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 21081 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 21091 | result_type, nullptr, true); | 21082 | result_type, nullptr, true, false); |
| 21092 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 21083 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 21093 | return result_loc; | 21084 | return result_loc; |
| 21094 | } | 21085 | } |
| ... | @@ -21345,7 +21336,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru | ... | @@ -21345,7 +21336,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 21345 | } | 21336 | } |
| 21346 | | 21337 | |
| 21347 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 21338 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 21348 | dest_slice_type, nullptr, true); | 21339 | dest_slice_type, nullptr, true, false); |
| 21349 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 21340 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 21350 | return result_loc; | 21341 | return result_loc; |
| 21351 | } | 21342 | } |
| ... | @@ -21422,7 +21413,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct | ... | @@ -21422,7 +21413,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 21422 | } | 21413 | } |
| 21423 | | 21414 | |
| 21424 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 21415 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 21425 | dest_slice_type, nullptr, true); | 21416 | dest_slice_type, nullptr, true, false); |
| 21426 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 21417 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 21427 | return result_loc; | 21418 | return result_loc; |
| 21428 | } | 21419 | } |
| ... | @@ -22164,7 +22155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -22164,7 +22155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 22164 | } | 22155 | } |
| 22165 | | 22156 | |
| 22166 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 22157 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 22167 | return_type, nullptr, true); | 22158 | return_type, nullptr, true, false); |
| 22168 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 22159 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 22169 | return result_loc; | 22160 | return result_loc; |
| 22170 | } | 22161 | } |
| ... | @@ -23729,58 +23720,15 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru | ... | @@ -23729,58 +23720,15 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru |
| 23729 | static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, | 23720 | static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 23730 | IrInstructionDeclRef *instruction) | 23721 | IrInstructionDeclRef *instruction) |
| 23731 | { | 23722 | { |
| 23732 | Tld *tld = instruction->tld; | 23723 | IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld); |
| 23733 | LVal lval = instruction->lval; | 23724 | if (type_is_invalid(ref_instruction->value.type)) |
| 23734 | | | |
| 23735 | resolve_top_level_decl(ira->codegen, tld, instruction->base.source_node); | | |
| 23736 | if (tld->resolution == TldResolutionInvalid) | | |
| 23737 | return ira->codegen->invalid_instruction; | 23725 | return ira->codegen->invalid_instruction; |
| 23738 | | 23726 | |
| 23739 | switch (tld->id) { | 23727 | if (instruction->lval == LValPtr) { |
| 23740 | case TldIdContainer: | 23728 | return ref_instruction; |
| 23741 | case TldIdCompTime: | 23729 | } else { |
| 23742 | zig_unreachable(); | 23730 | return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr); |
| 23743 | case TldIdVar: { | | |
| 23744 | TldVar *tld_var = (TldVar *)tld; | | |
| 23745 | ZigVar *var = tld_var->var; | | |
| 23746 | | | |
| 23747 | if (var == nullptr) { | | |
| 23748 | return ir_error_dependency_loop(ira, &instruction->base); | | |
| 23749 | } | | |
| 23750 | | | |
| 23751 | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); | | |
| 23752 | if (type_is_invalid(var_ptr->value.type)) | | |
| 23753 | return ira->codegen->invalid_instruction; | | |
| 23754 | | | |
| 23755 | if (tld_var->extern_lib_name != nullptr) { | | |
| 23756 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node); | | |
| 23757 | } | | |
| 23758 | | | |
| 23759 | if (lval == LValPtr) { | | |
| 23760 | return var_ptr; | | |
| 23761 | } else { | | |
| 23762 | return ir_get_deref(ira, &instruction->base, var_ptr, nullptr); | | |
| 23763 | } | | |
| 23764 | } | | |
| 23765 | case TldIdFn: { | | |
| 23766 | TldFn *tld_fn = (TldFn *)tld; | | |
| 23767 | ZigFn *fn_entry = tld_fn->fn_entry; | | |
| 23768 | ir_assert(fn_entry->type_entry, &instruction->base); | | |
| 23769 | | | |
| 23770 | if (tld_fn->extern_lib_name != nullptr) { | | |
| 23771 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, instruction->base.source_node); | | |
| 23772 | } | | |
| 23773 | | | |
| 23774 | IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope, | | |
| 23775 | instruction->base.source_node, fn_entry); | | |
| 23776 | if (lval == LValPtr) { | | |
| 23777 | return ir_get_ref(ira, &instruction->base, ref_instruction, true, false); | | |
| 23778 | } else { | | |
| 23779 | return ref_instruction; | | |
| 23780 | } | | |
| 23781 | } | | |
| 23782 | } | 23731 | } |
| 23783 | zig_unreachable(); | | |
| 23784 | } | 23732 | } |
| 23785 | | 23733 | |
| 23786 | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { | 23734 | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| ... | @@ -24655,7 +24603,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -24655,7 +24603,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 24655 | | 24603 | |
| 24656 | bool was_written = instruction->result_loc->written; | 24604 | bool was_written = instruction->result_loc->written; |
| 24657 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 24605 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24658 | value->value.type, value, false); | 24606 | value->value.type, value, false, false); |
| 24659 | if (result_loc != nullptr) { | 24607 | if (result_loc != nullptr) { |
| 24660 | if (type_is_invalid(result_loc->value.type)) | 24608 | if (type_is_invalid(result_loc->value.type)) |
| 24661 | return ira->codegen->invalid_instruction; | 24609 | return ira->codegen->invalid_instruction; |
| ... | @@ -24684,7 +24632,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst | ... | @@ -24684,7 +24632,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst |
| 24684 | return operand; | 24632 | return operand; |
| 24685 | | 24633 | |
| 24686 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, | 24634 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 24687 | &instruction->result_loc_bit_cast->base, operand->value.type, operand, false); | 24635 | &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false); |
| 24688 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) | 24636 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 24689 | return result_loc; | 24637 | return result_loc; |
| 24690 | | 24638 | |