| ... | @@ -6375,7 +6375,7 @@ enum ImplicitCastMatchResult { | ... | @@ -6375,7 +6375,7 @@ enum ImplicitCastMatchResult { |
| 6375 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, | 6375 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, |
| 6376 | TypeTableEntry *actual_type, IrInstruction *value) | 6376 | TypeTableEntry *actual_type, IrInstruction *value) |
| 6377 | { | 6377 | { |
| 6378 | if (types_match_const_cast_only(expected_type, actual_type)) { | 6378 | if (types_match_const_cast_only(ira->codegen, expected_type, actual_type)) { |
| 6379 | return ImplicitCastMatchResultYes; | 6379 | return ImplicitCastMatchResultYes; |
| 6380 | } | 6380 | } |
| 6381 | | 6381 | |
| ... | @@ -6412,13 +6412,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6412,13 +6412,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6412 | return ImplicitCastMatchResultYes; | 6412 | return ImplicitCastMatchResultYes; |
| 6413 | } | 6413 | } |
| 6414 | | 6414 | |
| 6415 | // implicit conversion from error set to another error set | | |
| 6416 | if (expected_type->id == TypeTableEntryIdErrorSet && | | |
| 6417 | actual_type->id == TypeTableEntryIdErrorSet) | | |
| 6418 | { | | |
| 6419 | return ImplicitCastMatchResultYes; | | |
| 6420 | } | | |
| 6421 | | | |
| 6422 | // implicit conversion from T to U!?T | 6415 | // implicit conversion from T to U!?T |
| 6423 | if (expected_type->id == TypeTableEntryIdErrorUnion && | 6416 | if (expected_type->id == TypeTableEntryIdErrorUnion && |
| 6424 | expected_type->data.error_union.payload_type->id == TypeTableEntryIdMaybe && | 6417 | expected_type->data.error_union.payload_type->id == TypeTableEntryIdMaybe && |
| ... | @@ -6463,7 +6456,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6463,7 +6456,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6463 | assert(ptr_type->id == TypeTableEntryIdPointer); | 6456 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6464 | | 6457 | |
| 6465 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 6458 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6466 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 6459 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 6467 | { | 6460 | { |
| 6468 | return ImplicitCastMatchResultYes; | 6461 | return ImplicitCastMatchResultYes; |
| 6469 | } | 6462 | } |
| ... | @@ -6482,7 +6475,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6482,7 +6475,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6482 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; | 6475 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 6483 | | 6476 | |
| 6484 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 6477 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 6485 | types_match_const_cast_only(ptr_type->data.pointer.child_type, array_type->data.array.child_type)) | 6478 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type)) |
| 6486 | { | 6479 | { |
| 6487 | return ImplicitCastMatchResultYes; | 6480 | return ImplicitCastMatchResultYes; |
| 6488 | } | 6481 | } |
| ... | @@ -6498,7 +6491,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6498,7 +6491,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6498 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; | 6491 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6499 | assert(ptr_type->id == TypeTableEntryIdPointer); | 6492 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6500 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 6493 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6501 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 6494 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 6502 | { | 6495 | { |
| 6503 | return ImplicitCastMatchResultYes; | 6496 | return ImplicitCastMatchResultYes; |
| 6504 | } | 6497 | } |
| ... | @@ -6513,7 +6506,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6513,7 +6506,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6513 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; | 6506 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6514 | assert(ptr_type->id == TypeTableEntryIdPointer); | 6507 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6515 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 6508 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6516 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 6509 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 6517 | { | 6510 | { |
| 6518 | return ImplicitCastMatchResultYes; | 6511 | return ImplicitCastMatchResultYes; |
| 6519 | } | 6512 | } |
| ... | @@ -6593,7 +6586,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -6593,7 +6586,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6593 | // implicitly take a const pointer to something | 6586 | // implicitly take a const pointer to something |
| 6594 | if (!type_requires_comptime(actual_type)) { | 6587 | if (!type_requires_comptime(actual_type)) { |
| 6595 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); | 6588 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 6596 | if (types_match_const_cast_only(expected_type, const_ptr_actual)) { | 6589 | if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual)) { |
| 6597 | return ImplicitCastMatchResultYes; | 6590 | return ImplicitCastMatchResultYes; |
| 6598 | } | 6591 | } |
| 6599 | } | 6592 | } |
| ... | @@ -6769,11 +6762,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6769,11 +6762,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6769 | } | 6762 | } |
| 6770 | } | 6763 | } |
| 6771 | | 6764 | |
| 6772 | if (types_match_const_cast_only(prev_type, cur_type)) { | 6765 | if (types_match_const_cast_only(ira->codegen, prev_type, cur_type)) { |
| 6773 | continue; | 6766 | continue; |
| 6774 | } | 6767 | } |
| 6775 | | 6768 | |
| 6776 | if (types_match_const_cast_only(cur_type, prev_type)) { | 6769 | if (types_match_const_cast_only(ira->codegen, cur_type, prev_type)) { |
| 6777 | prev_inst = cur_inst; | 6770 | prev_inst = cur_inst; |
| 6778 | continue; | 6771 | continue; |
| 6779 | } | 6772 | } |
| ... | @@ -6796,26 +6789,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6796,26 +6789,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6796 | } | 6789 | } |
| 6797 | | 6790 | |
| 6798 | if (prev_type->id == TypeTableEntryIdErrorUnion && | 6791 | if (prev_type->id == TypeTableEntryIdErrorUnion && |
| 6799 | types_match_const_cast_only(prev_type->data.error_union.payload_type, cur_type)) | 6792 | types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type)) |
| 6800 | { | 6793 | { |
| 6801 | continue; | 6794 | continue; |
| 6802 | } | 6795 | } |
| 6803 | | 6796 | |
| 6804 | if (cur_type->id == TypeTableEntryIdErrorUnion && | 6797 | if (cur_type->id == TypeTableEntryIdErrorUnion && |
| 6805 | types_match_const_cast_only(cur_type->data.error_union.payload_type, prev_type)) | 6798 | types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type)) |
| 6806 | { | 6799 | { |
| 6807 | prev_inst = cur_inst; | 6800 | prev_inst = cur_inst; |
| 6808 | continue; | 6801 | continue; |
| 6809 | } | 6802 | } |
| 6810 | | 6803 | |
| 6811 | if (prev_type->id == TypeTableEntryIdMaybe && | 6804 | if (prev_type->id == TypeTableEntryIdMaybe && |
| 6812 | types_match_const_cast_only(prev_type->data.maybe.child_type, cur_type)) | 6805 | types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type)) |
| 6813 | { | 6806 | { |
| 6814 | continue; | 6807 | continue; |
| 6815 | } | 6808 | } |
| 6816 | | 6809 | |
| 6817 | if (cur_type->id == TypeTableEntryIdMaybe && | 6810 | if (cur_type->id == TypeTableEntryIdMaybe && |
| 6818 | types_match_const_cast_only(cur_type->data.maybe.child_type, prev_type)) | 6811 | types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type)) |
| 6819 | { | 6812 | { |
| 6820 | prev_inst = cur_inst; | 6813 | prev_inst = cur_inst; |
| 6821 | continue; | 6814 | continue; |
| ... | @@ -6853,7 +6846,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6853,7 +6846,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6853 | | 6846 | |
| 6854 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && | 6847 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6855 | cur_type->data.array.len != prev_type->data.array.len && | 6848 | cur_type->data.array.len != prev_type->data.array.len && |
| 6856 | types_match_const_cast_only(cur_type->data.array.child_type, prev_type->data.array.child_type)) | 6849 | types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type)) |
| 6857 | { | 6850 | { |
| 6858 | convert_to_const_slice = true; | 6851 | convert_to_const_slice = true; |
| 6859 | prev_inst = cur_inst; | 6852 | prev_inst = cur_inst; |
| ... | @@ -6862,7 +6855,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6862,7 +6855,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6862 | | 6855 | |
| 6863 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && | 6856 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6864 | cur_type->data.array.len != prev_type->data.array.len && | 6857 | cur_type->data.array.len != prev_type->data.array.len && |
| 6865 | types_match_const_cast_only(prev_type->data.array.child_type, cur_type->data.array.child_type)) | 6858 | types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type)) |
| 6866 | { | 6859 | { |
| 6867 | convert_to_const_slice = true; | 6860 | convert_to_const_slice = true; |
| 6868 | continue; | 6861 | continue; |
| ... | @@ -6871,7 +6864,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6871,7 +6864,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6871 | if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) && | 6864 | if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) && |
| 6872 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 6865 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6873 | cur_type->data.array.len == 0) && | 6866 | cur_type->data.array.len == 0) && |
| 6874 | types_match_const_cast_only(prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | 6867 | types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6875 | cur_type->data.array.child_type)) | 6868 | cur_type->data.array.child_type)) |
| 6876 | { | 6869 | { |
| 6877 | convert_to_const_slice = false; | 6870 | convert_to_const_slice = false; |
| ... | @@ -6881,7 +6874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -6881,7 +6874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6881 | if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) && | 6874 | if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) && |
| 6882 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 6875 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6883 | prev_type->data.array.len == 0) && | 6876 | prev_type->data.array.len == 0) && |
| 6884 | types_match_const_cast_only(cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | 6877 | types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6885 | prev_type->data.array.child_type)) | 6878 | prev_type->data.array.child_type)) |
| 6886 | { | 6879 | { |
| 6887 | prev_inst = cur_inst; | 6880 | prev_inst = cur_inst; |
| ... | @@ -7449,6 +7442,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -7449,6 +7442,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 7449 | return result; | 7442 | return result; |
| 7450 | } | 7443 | } |
| 7451 | | 7444 | |
| | 7445 | // TODO this is an explicit cast and should actually coerce the type |
| 7452 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, | 7446 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 7453 | TypeTableEntry *wanted_type) | 7447 | TypeTableEntry *wanted_type) |
| 7454 | { | 7448 | { |
| ... | @@ -7999,7 +7993,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -7999,7 +7993,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7999 | return value; | 7993 | return value; |
| 8000 | | 7994 | |
| 8001 | // explicit match or non-const to const | 7995 | // explicit match or non-const to const |
| 8002 | if (types_match_const_cast_only(wanted_type, actual_type)) { | 7996 | if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type)) { |
| 8003 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); | 7997 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| 8004 | } | 7998 | } |
| 8005 | | 7999 | |
| ... | @@ -8045,7 +8039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8045,7 +8039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8045 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 8039 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8046 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8040 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8047 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8041 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8048 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8042 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 8049 | { | 8043 | { |
| 8050 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); | 8044 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8051 | } | 8045 | } |
| ... | @@ -8063,7 +8057,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8063,7 +8057,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8063 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; | 8057 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 8064 | | 8058 | |
| 8065 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 8059 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 8066 | types_match_const_cast_only(ptr_type->data.pointer.child_type, array_type->data.array.child_type)) | 8060 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type)) |
| 8067 | { | 8061 | { |
| 8068 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); | 8062 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8069 | } | 8063 | } |
| ... | @@ -8079,7 +8073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8079,7 +8073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8079 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; | 8073 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8080 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8074 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8081 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8075 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8082 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8076 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 8083 | { | 8077 | { |
| 8084 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); | 8078 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |
| 8085 | if (type_is_invalid(cast1->value.type)) | 8079 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -8102,7 +8096,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8102,7 +8096,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8102 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; | 8096 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8103 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8097 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8104 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8098 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8105 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8099 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 8106 | { | 8100 | { |
| 8107 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); | 8101 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 8108 | if (type_is_invalid(cast1->value.type)) | 8102 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -8164,7 +8158,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8164,7 +8158,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8164 | | 8158 | |
| 8165 | // explicit cast from child type of maybe type to maybe type | 8159 | // explicit cast from child type of maybe type to maybe type |
| 8166 | if (wanted_type->id == TypeTableEntryIdMaybe) { | 8160 | if (wanted_type->id == TypeTableEntryIdMaybe) { |
| 8167 | if (types_match_const_cast_only(wanted_type->data.maybe.child_type, actual_type)) { | 8161 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type)) { |
| 8168 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); | 8162 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 8169 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || | 8163 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8170 | actual_type->id == TypeTableEntryIdNumLitFloat) | 8164 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | @@ -8186,7 +8180,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8186,7 +8180,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8186 | | 8180 | |
| 8187 | // explicit cast from child type of error type to error type | 8181 | // explicit cast from child type of error type to error type |
| 8188 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { | 8182 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { |
| 8189 | if (types_match_const_cast_only(wanted_type->data.error_union.payload_type, actual_type)) { | 8183 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type)) { |
| 8190 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); | 8184 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 8191 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || | 8185 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8192 | actual_type->id == TypeTableEntryIdNumLitFloat) | 8186 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | @@ -8208,7 +8202,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8208,7 +8202,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8208 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; | 8202 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8209 | assert(ptr_type->id == TypeTableEntryIdPointer); | 8203 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8210 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 8204 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8211 | types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | 8205 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) |
| 8212 | { | 8206 | { |
| 8213 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); | 8207 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 8214 | if (type_is_invalid(cast1->value.type)) | 8208 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -8235,7 +8229,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8235,7 +8229,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8235 | actual_type->id != TypeTableEntryIdMaybe) | 8229 | actual_type->id != TypeTableEntryIdMaybe) |
| 8236 | { | 8230 | { |
| 8237 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; | 8231 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; |
| 8238 | if (types_match_const_cast_only(wanted_child_type, actual_type) || | 8232 | if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type) || |
| 8239 | actual_type->id == TypeTableEntryIdNullLit || | 8233 | actual_type->id == TypeTableEntryIdNullLit || |
| 8240 | actual_type->id == TypeTableEntryIdNumLitInt || | 8234 | actual_type->id == TypeTableEntryIdNumLitInt || |
| 8241 | actual_type->id == TypeTableEntryIdNumLitFloat) | 8235 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | @@ -8385,7 +8379,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8385,7 +8379,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8385 | // explicit cast from something to const pointer of it | 8379 | // explicit cast from something to const pointer of it |
| 8386 | if (!type_requires_comptime(actual_type)) { | 8380 | if (!type_requires_comptime(actual_type)) { |
| 8387 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); | 8381 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 8388 | if (types_match_const_cast_only(wanted_type, const_ptr_actual)) { | 8382 | if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual)) { |
| 8389 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); | 8383 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); |
| 8390 | } | 8384 | } |
| 8391 | } | 8385 | } |
| ... | @@ -10386,12 +10380,17 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -10386,12 +10380,17 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 10386 | | 10380 | |
| 10387 | { | 10381 | { |
| 10388 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; | 10382 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 10389 | TypeTableEntry *return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); | 10383 | TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); |
| 10390 | if (type_is_invalid(return_type)) | 10384 | if (type_is_invalid(specified_return_type)) |
| 10391 | return ira->codegen->builtin_types.entry_invalid; | 10385 | return ira->codegen->builtin_types.entry_invalid; |
| 10392 | inst_fn_type_id.return_type = return_type; | 10386 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| | 10387 | TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); |
| | 10388 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| | 10389 | } else { |
| | 10390 | inst_fn_type_id.return_type = specified_return_type; |
| | 10391 | } |
| 10393 | | 10392 | |
| 10394 | if (type_requires_comptime(return_type)) { | 10393 | if (type_requires_comptime(specified_return_type)) { |
| 10395 | // Throw out our work and call the function as if it were comptime. | 10394 | // Throw out our work and call the function as if it were comptime. |
| 10396 | return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true, FnInlineAuto); | 10395 | return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true, FnInlineAuto); |
| 10397 | } | 10396 | } |