| ... | ... | @@ -6375,7 +6375,7 @@ enum ImplicitCastMatchResult { |
| 6375 | 6375 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, |
| 6376 | 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 | 6379 | return ImplicitCastMatchResultYes; |
| 6380 | 6380 | } |
| 6381 | 6381 | |
| ... | ... | @@ -6412,13 +6412,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6412 | 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 | 6415 | // implicit conversion from T to U!?T |
| 6423 | 6416 | if (expected_type->id == TypeTableEntryIdErrorUnion && |
| 6424 | 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 | 6456 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6464 | 6457 | |
| 6465 | 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 | 6461 | return ImplicitCastMatchResultYes; |
| 6469 | 6462 | } |
| ... | ... | @@ -6482,7 +6475,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6482 | 6475 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 6483 | 6476 | |
| 6484 | 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 | 6480 | return ImplicitCastMatchResultYes; |
| 6488 | 6481 | } |
| ... | ... | @@ -6498,7 +6491,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6498 | 6491 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6499 | 6492 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6500 | 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 | 6496 | return ImplicitCastMatchResultYes; |
| 6504 | 6497 | } |
| ... | ... | @@ -6513,7 +6506,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6513 | 6506 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6514 | 6507 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6515 | 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 | 6511 | return ImplicitCastMatchResultYes; |
| 6519 | 6512 | } |
| ... | ... | @@ -6593,7 +6586,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6593 | 6586 | // implicitly take a const pointer to something |
| 6594 | 6587 | if (!type_requires_comptime(actual_type)) { |
| 6595 | 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 | 6590 | return ImplicitCastMatchResultYes; |
| 6598 | 6591 | } |
| 6599 | 6592 | } |
| ... | ... | @@ -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 | 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 | 6770 | prev_inst = cur_inst; |
| 6778 | 6771 | continue; |
| 6779 | 6772 | } |
| ... | ... | @@ -6796,26 +6789,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6796 | 6789 | } |
| 6797 | 6790 | |
| 6798 | 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 | 6794 | continue; |
| 6802 | 6795 | } |
| 6803 | 6796 | |
| 6804 | 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 | 6800 | prev_inst = cur_inst; |
| 6808 | 6801 | continue; |
| 6809 | 6802 | } |
| 6810 | 6803 | |
| 6811 | 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 | 6807 | continue; |
| 6815 | 6808 | } |
| 6816 | 6809 | |
| 6817 | 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 | 6813 | prev_inst = cur_inst; |
| 6821 | 6814 | continue; |
| ... | ... | @@ -6853,7 +6846,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6853 | 6846 | |
| 6854 | 6847 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6855 | 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 | 6851 | convert_to_const_slice = true; |
| 6859 | 6852 | prev_inst = cur_inst; |
| ... | ... | @@ -6862,7 +6855,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6862 | 6855 | |
| 6863 | 6856 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6864 | 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 | 6860 | convert_to_const_slice = true; |
| 6868 | 6861 | continue; |
| ... | ... | @@ -6871,7 +6864,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6871 | 6864 | if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) && |
| 6872 | 6865 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6873 | 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 | 6868 | cur_type->data.array.child_type)) |
| 6876 | 6869 | { |
| 6877 | 6870 | convert_to_const_slice = false; |
| ... | ... | @@ -6881,7 +6874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6881 | 6874 | if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) && |
| 6882 | 6875 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6883 | 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 | 6878 | prev_type->data.array.child_type)) |
| 6886 | 6879 | { |
| 6887 | 6880 | prev_inst = cur_inst; |
| ... | ... | @@ -7449,6 +7442,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 7449 | 7442 | return result; |
| 7450 | 7443 | } |
| 7451 | 7444 | |
| 7445 | // TODO this is an explicit cast and should actually coerce the type |
| 7452 | 7446 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 7453 | 7447 | TypeTableEntry *wanted_type) |
| 7454 | 7448 | { |
| ... | ... | @@ -7999,7 +7993,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7999 | 7993 | return value; |
| 8000 | 7994 | |
| 8001 | 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 | 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 | 8039 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8046 | 8040 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8047 | 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 | 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 | 8057 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 8064 | 8058 | |
| 8065 | 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 | 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 | 8073 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8080 | 8074 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8081 | 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 | 8078 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |
| 8085 | 8079 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8102,7 +8096,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8102 | 8096 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8103 | 8097 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8104 | 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 | 8101 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 8108 | 8102 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8164,7 +8158,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8164 | 8158 | |
| 8165 | 8159 | // explicit cast from child type of maybe type to maybe type |
| 8166 | 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 | 8162 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 8169 | 8163 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8170 | 8164 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8186,7 +8180,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8186 | 8180 | |
| 8187 | 8181 | // explicit cast from child type of error type to error type |
| 8188 | 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 | 8184 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 8191 | 8185 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8192 | 8186 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8208,7 +8202,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8208 | 8202 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8209 | 8203 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8210 | 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 | 8207 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 8214 | 8208 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8235,7 +8229,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8235 | 8229 | actual_type->id != TypeTableEntryIdMaybe) |
| 8236 | 8230 | { |
| 8237 | 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 | 8233 | actual_type->id == TypeTableEntryIdNullLit || |
| 8240 | 8234 | actual_type->id == TypeTableEntryIdNumLitInt || |
| 8241 | 8235 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8385,7 +8379,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8385 | 8379 | // explicit cast from something to const pointer of it |
| 8386 | 8380 | if (!type_requires_comptime(actual_type)) { |
| 8387 | 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 | 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 | 10380 | |
| 10387 | 10381 | { |
| 10388 | 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); |
| 10390 | | if (type_is_invalid(return_type)) |
| 10383 | TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); |
| 10384 | if (type_is_invalid(specified_return_type)) |
| 10391 | 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 | 10394 | // Throw out our work and call the function as if it were comptime. |
| 10396 | 10395 | return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true, FnInlineAuto); |
| 10397 | 10396 | } |