| ... | @@ -1773,11 +1773,17 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour | ... | @@ -1773,11 +1773,17 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour |
| 1773 | return &instruction->base; | 1773 | return &instruction->base; |
| 1774 | } | 1774 | } |
| 1775 | | 1775 | |
| 1776 | static IrInstruction *ir_build_err_wrap_payload(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { | 1776 | static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction, |
| 1777 | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(irb, scope, source_node); | 1777 | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 1778 | instruction->value = value; | 1778 | { |
| | 1779 | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>( |
| | 1780 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| | 1781 | instruction->base.value.type = result_type; |
| | 1782 | instruction->operand = operand; |
| | 1783 | instruction->result_loc = result_loc; |
| 1779 | | 1784 | |
| 1780 | ir_ref_instruction(value, irb->current_basic_block); | 1785 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| | 1786 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 1781 | | 1787 | |
| 1782 | return &instruction->base; | 1788 | return &instruction->base; |
| 1783 | } | 1789 | } |
| ... | @@ -11078,12 +11084,13 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so | ... | @@ -11078,12 +11084,13 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11078 | } | 11084 | } |
| 11079 | | 11085 | |
| 11080 | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, | 11086 | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 11081 | IrInstruction *value, ZigType *wanted_type) | 11087 | IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 11082 | { | 11088 | { |
| 11083 | assert(wanted_type->id == ZigTypeIdErrorUnion); | 11089 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 11084 | | 11090 | |
| | 11091 | ZigType *payload_type = wanted_type->data.error_union.payload_type; |
| | 11092 | ZigType *err_set_type = wanted_type->data.error_union.err_set_type; |
| 11085 | if (instr_is_comptime(value)) { | 11093 | if (instr_is_comptime(value)) { |
| 11086 | ZigType *payload_type = wanted_type->data.error_union.payload_type; | | |
| 11087 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); | 11094 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 11088 | if (type_is_invalid(casted_payload->value.type)) | 11095 | if (type_is_invalid(casted_payload->value.type)) |
| 11089 | return ira->codegen->invalid_instruction; | 11096 | return ira->codegen->invalid_instruction; |
| ... | @@ -11093,7 +11100,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -11093,7 +11100,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11093 | return ira->codegen->invalid_instruction; | 11100 | return ira->codegen->invalid_instruction; |
| 11094 | | 11101 | |
| 11095 | ConstExprValue *err_set_val = create_const_vals(1); | 11102 | ConstExprValue *err_set_val = create_const_vals(1); |
| 11096 | err_set_val->type = wanted_type->data.error_union.err_set_type; | 11103 | err_set_val->type = err_set_type; |
| 11097 | err_set_val->special = ConstValSpecialStatic; | 11104 | err_set_val->special = ConstValSpecialStatic; |
| 11098 | err_set_val->data.x_err_set = nullptr; | 11105 | err_set_val->data.x_err_set = nullptr; |
| 11099 | | 11106 | |
| ... | @@ -11106,10 +11113,19 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -11106,10 +11113,19 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11106 | return &const_instruction->base; | 11113 | return &const_instruction->base; |
| 11107 | } | 11114 | } |
| 11108 | | 11115 | |
| 11109 | IrInstruction *result = ir_build_err_wrap_payload(&ira->new_irb, source_instr->scope, source_instr->source_node, value); | 11116 | IrInstruction *result_loc_inst; |
| 11110 | result->value.type = wanted_type; | 11117 | if (handle_is_ptr(wanted_type)) { |
| | 11118 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| | 11119 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr); |
| | 11120 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| | 11121 | return result_loc_inst; |
| | 11122 | } |
| | 11123 | } else { |
| | 11124 | result_loc_inst = nullptr; |
| | 11125 | } |
| | 11126 | |
| | 11127 | IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11111 | result->value.data.rh_error_union = RuntimeHintErrorUnionNonError; | 11128 | result->value.data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 11112 | ir_add_alloca(ira, result, wanted_type); | | |
| 11113 | return result; | 11129 | return result; |
| 11114 | } | 11130 | } |
| 11115 | | 11131 | |
| ... | @@ -12057,12 +12073,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12057,12 +12073,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12057 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, | 12073 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, |
| 12058 | source_node, false).id == ConstCastResultIdOk) | 12074 | source_node, false).id == ConstCastResultIdOk) |
| 12059 | { | 12075 | { |
| 12060 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); | 12076 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, result_loc); |
| 12061 | } else if (actual_type->id == ZigTypeIdComptimeInt || | 12077 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 12062 | actual_type->id == ZigTypeIdComptimeFloat) | 12078 | actual_type->id == ZigTypeIdComptimeFloat) |
| 12063 | { | 12079 | { |
| 12064 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { | 12080 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { |
| 12065 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); | 12081 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, result_loc); |
| 12066 | } else { | 12082 | } else { |
| 12067 | return ira->codegen->invalid_instruction; | 12083 | return ira->codegen->invalid_instruction; |
| 12068 | } | 12084 | } |
| ... | @@ -24447,7 +24463,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24447,7 +24463,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24447 | case IrInstructionIdTestErr: | 24463 | case IrInstructionIdTestErr: |
| 24448 | case IrInstructionIdUnwrapErrCode: | 24464 | case IrInstructionIdUnwrapErrCode: |
| 24449 | case IrInstructionIdErrWrapCode: | 24465 | case IrInstructionIdErrWrapCode: |
| 24450 | case IrInstructionIdErrWrapPayload: | | |
| 24451 | case IrInstructionIdFnProto: | 24466 | case IrInstructionIdFnProto: |
| 24452 | case IrInstructionIdTestComptime: | 24467 | case IrInstructionIdTestComptime: |
| 24453 | case IrInstructionIdPtrCastSrc: | 24468 | case IrInstructionIdPtrCastSrc: |
| ... | @@ -24512,6 +24527,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24512,6 +24527,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24512 | (IrInstructionUnwrapErrPayload *)instruction; | 24527 | (IrInstructionUnwrapErrPayload *)instruction; |
| 24513 | return unwrap_err_payload_instruction->safety_check_on; | 24528 | return unwrap_err_payload_instruction->safety_check_on; |
| 24514 | } | 24529 | } |
| | 24530 | case IrInstructionIdErrWrapPayload: |
| | 24531 | return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 24515 | } | 24532 | } |
| 24516 | zig_unreachable(); | 24533 | zig_unreachable(); |
| 24517 | } | 24534 | } |