| ... | ... | @@ -45,6 +45,59 @@ static LVal make_lval_addr(bool is_const, bool is_volatile) { |
| 45 | 45 | return { true, is_const, is_volatile }; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | enum ConstCastResultId { |
| 49 | ConstCastResultIdOk, |
| 50 | ConstCastResultIdErrSet, |
| 51 | ConstCastResultIdErrSetGlobal, |
| 52 | ConstCastResultIdPointerChild, |
| 53 | ConstCastResultIdSliceChild, |
| 54 | ConstCastResultIdNullableChild, |
| 55 | ConstCastResultIdErrorUnionPayload, |
| 56 | ConstCastResultIdErrorUnionErrorSet, |
| 57 | ConstCastResultIdFnAlign, |
| 58 | ConstCastResultIdFnCC, |
| 59 | ConstCastResultIdFnVarArgs, |
| 60 | ConstCastResultIdFnIsGeneric, |
| 61 | ConstCastResultIdFnReturnType, |
| 62 | ConstCastResultIdFnArgCount, |
| 63 | ConstCastResultIdFnGenericArgCount, |
| 64 | ConstCastResultIdFnArg, |
| 65 | ConstCastResultIdFnArgNoAlias, |
| 66 | ConstCastResultIdType, |
| 67 | ConstCastResultIdUnresolvedInferredErrSet, |
| 68 | }; |
| 69 | |
| 70 | struct ConstCastErrSetMismatch { |
| 71 | ZigList<ErrorTableEntry *> missing_errors; |
| 72 | }; |
| 73 | |
| 74 | struct ConstCastOnly; |
| 75 | |
| 76 | struct ConstCastArg { |
| 77 | size_t arg_index; |
| 78 | ConstCastOnly *child; |
| 79 | }; |
| 80 | |
| 81 | struct ConstCastArgNoAlias { |
| 82 | size_t arg_index; |
| 83 | }; |
| 84 | |
| 85 | struct ConstCastOnly { |
| 86 | ConstCastResultId id; |
| 87 | union { |
| 88 | ConstCastErrSetMismatch error_set; |
| 89 | ConstCastOnly *pointer_child; |
| 90 | ConstCastOnly *slice_child; |
| 91 | ConstCastOnly *nullable_child; |
| 92 | ConstCastOnly *error_union_payload; |
| 93 | ConstCastOnly *error_union_error_set; |
| 94 | ConstCastOnly *return_type; |
| 95 | ConstCastArg fn_arg; |
| 96 | ConstCastArgNoAlias arg_no_alias; |
| 97 | } data; |
| 98 | }; |
| 99 | |
| 100 | |
| 48 | 101 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 49 | 102 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval); |
| 50 | 103 | static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); |
| ... | ... | @@ -6416,6 +6469,220 @@ static bool slice_is_const(TypeTableEntry *type) { |
| 6416 | 6469 | return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; |
| 6417 | 6470 | } |
| 6418 | 6471 | |
| 6472 | static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) { |
| 6473 | assert(err_set_type->id == TypeTableEntryIdErrorSet); |
| 6474 | FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; |
| 6475 | if (infer_fn != nullptr) { |
| 6476 | if (infer_fn->anal_state == FnAnalStateInvalid) { |
| 6477 | return false; |
| 6478 | } else if (infer_fn->anal_state == FnAnalStateReady) { |
| 6479 | analyze_fn_body(ira->codegen, infer_fn); |
| 6480 | if (err_set_type->data.error_set.infer_fn != nullptr) { |
| 6481 | assert(ira->codegen->errors.length != 0); |
| 6482 | return false; |
| 6483 | } |
| 6484 | } else { |
| 6485 | ir_add_error_node(ira, source_node, |
| 6486 | buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet", |
| 6487 | buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name))); |
| 6488 | return false; |
| 6489 | } |
| 6490 | } |
| 6491 | return true; |
| 6492 | } |
| 6493 | |
| 6494 | static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *expected_type, |
| 6495 | TypeTableEntry *actual_type, AstNode *source_node) |
| 6496 | { |
| 6497 | CodeGen *g = ira->codegen; |
| 6498 | ConstCastOnly result = {}; |
| 6499 | result.id = ConstCastResultIdOk; |
| 6500 | |
| 6501 | if (expected_type == actual_type) |
| 6502 | return result; |
| 6503 | |
| 6504 | // pointer const |
| 6505 | if (expected_type->id == TypeTableEntryIdPointer && |
| 6506 | actual_type->id == TypeTableEntryIdPointer && |
| 6507 | (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const) && |
| 6508 | (!actual_type->data.pointer.is_volatile || expected_type->data.pointer.is_volatile) && |
| 6509 | actual_type->data.pointer.bit_offset == expected_type->data.pointer.bit_offset && |
| 6510 | actual_type->data.pointer.unaligned_bit_count == expected_type->data.pointer.unaligned_bit_count && |
| 6511 | actual_type->data.pointer.alignment >= expected_type->data.pointer.alignment) |
| 6512 | { |
| 6513 | ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.pointer.child_type, actual_type->data.pointer.child_type, source_node); |
| 6514 | if (child.id != ConstCastResultIdOk) { |
| 6515 | result.id = ConstCastResultIdPointerChild; |
| 6516 | result.data.pointer_child = allocate_nonzero<ConstCastOnly>(1); |
| 6517 | *result.data.pointer_child = child; |
| 6518 | } |
| 6519 | return result; |
| 6520 | } |
| 6521 | |
| 6522 | // slice const |
| 6523 | if (expected_type->id == TypeTableEntryIdStruct && actual_type->id == TypeTableEntryIdStruct && |
| 6524 | expected_type->data.structure.is_slice && actual_type->data.structure.is_slice) |
| 6525 | { |
| 6526 | TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6527 | TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6528 | if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) && |
| 6529 | (!actual_ptr_type->data.pointer.is_volatile || expected_ptr_type->data.pointer.is_volatile) && |
| 6530 | actual_ptr_type->data.pointer.bit_offset == expected_ptr_type->data.pointer.bit_offset && |
| 6531 | actual_ptr_type->data.pointer.unaligned_bit_count == expected_ptr_type->data.pointer.unaligned_bit_count && |
| 6532 | actual_ptr_type->data.pointer.alignment >= expected_ptr_type->data.pointer.alignment) |
| 6533 | { |
| 6534 | ConstCastOnly child = types_match_const_cast_only(ira, expected_ptr_type->data.pointer.child_type, |
| 6535 | actual_ptr_type->data.pointer.child_type, source_node); |
| 6536 | if (child.id != ConstCastResultIdOk) { |
| 6537 | result.id = ConstCastResultIdSliceChild; |
| 6538 | result.data.slice_child = allocate_nonzero<ConstCastOnly>(1); |
| 6539 | *result.data.slice_child = child; |
| 6540 | } |
| 6541 | return result; |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | // maybe |
| 6546 | if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) { |
| 6547 | ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.maybe.child_type, actual_type->data.maybe.child_type, source_node); |
| 6548 | if (child.id != ConstCastResultIdOk) { |
| 6549 | result.id = ConstCastResultIdNullableChild; |
| 6550 | result.data.nullable_child = allocate_nonzero<ConstCastOnly>(1); |
| 6551 | *result.data.nullable_child = child; |
| 6552 | } |
| 6553 | return result; |
| 6554 | } |
| 6555 | |
| 6556 | // error union |
| 6557 | if (expected_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) { |
| 6558 | ConstCastOnly payload_child = types_match_const_cast_only(ira, expected_type->data.error_union.payload_type, actual_type->data.error_union.payload_type, source_node); |
| 6559 | if (payload_child.id != ConstCastResultIdOk) { |
| 6560 | result.id = ConstCastResultIdErrorUnionPayload; |
| 6561 | result.data.error_union_payload = allocate_nonzero<ConstCastOnly>(1); |
| 6562 | *result.data.error_union_payload = payload_child; |
| 6563 | return result; |
| 6564 | } |
| 6565 | ConstCastOnly error_set_child = types_match_const_cast_only(ira, expected_type->data.error_union.err_set_type, actual_type->data.error_union.err_set_type, source_node); |
| 6566 | if (error_set_child.id != ConstCastResultIdOk) { |
| 6567 | result.id = ConstCastResultIdErrorUnionErrorSet; |
| 6568 | result.data.error_union_error_set = allocate_nonzero<ConstCastOnly>(1); |
| 6569 | *result.data.error_union_error_set = error_set_child; |
| 6570 | return result; |
| 6571 | } |
| 6572 | return result; |
| 6573 | } |
| 6574 | |
| 6575 | // error set |
| 6576 | if (expected_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) { |
| 6577 | TypeTableEntry *contained_set = actual_type; |
| 6578 | TypeTableEntry *container_set = expected_type; |
| 6579 | |
| 6580 | if (!resolve_inferred_error_set(ira, container_set, source_node)) { |
| 6581 | result.id = ConstCastResultIdUnresolvedInferredErrSet; |
| 6582 | return result; |
| 6583 | } |
| 6584 | |
| 6585 | if (type_is_global_error_set(container_set)) { |
| 6586 | return result; |
| 6587 | } |
| 6588 | |
| 6589 | if (!resolve_inferred_error_set(ira, contained_set, source_node)) { |
| 6590 | result.id = ConstCastResultIdUnresolvedInferredErrSet; |
| 6591 | return result; |
| 6592 | } |
| 6593 | |
| 6594 | if (type_is_global_error_set(contained_set)) { |
| 6595 | result.id = ConstCastResultIdErrSetGlobal; |
| 6596 | return result; |
| 6597 | } |
| 6598 | |
| 6599 | ErrorTableEntry **errors = allocate<ErrorTableEntry *>(g->errors_by_index.length); |
| 6600 | for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) { |
| 6601 | ErrorTableEntry *error_entry = container_set->data.error_set.errors[i]; |
| 6602 | errors[error_entry->value] = error_entry; |
| 6603 | } |
| 6604 | for (uint32_t i = 0; i < contained_set->data.error_set.err_count; i += 1) { |
| 6605 | ErrorTableEntry *contained_error_entry = contained_set->data.error_set.errors[i]; |
| 6606 | ErrorTableEntry *error_entry = errors[contained_error_entry->value]; |
| 6607 | if (error_entry == nullptr) { |
| 6608 | if (result.id == ConstCastResultIdOk) { |
| 6609 | result.id = ConstCastResultIdErrSet; |
| 6610 | } |
| 6611 | result.data.error_set.missing_errors.append(contained_error_entry); |
| 6612 | } |
| 6613 | } |
| 6614 | free(errors); |
| 6615 | return result; |
| 6616 | } |
| 6617 | |
| 6618 | // fn |
| 6619 | if (expected_type->id == TypeTableEntryIdFn && |
| 6620 | actual_type->id == TypeTableEntryIdFn) |
| 6621 | { |
| 6622 | if (expected_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) { |
| 6623 | result.id = ConstCastResultIdFnAlign; |
| 6624 | return result; |
| 6625 | } |
| 6626 | if (expected_type->data.fn.fn_type_id.cc != actual_type->data.fn.fn_type_id.cc) { |
| 6627 | result.id = ConstCastResultIdFnCC; |
| 6628 | return result; |
| 6629 | } |
| 6630 | if (expected_type->data.fn.fn_type_id.is_var_args != actual_type->data.fn.fn_type_id.is_var_args) { |
| 6631 | result.id = ConstCastResultIdFnVarArgs; |
| 6632 | return result; |
| 6633 | } |
| 6634 | if (expected_type->data.fn.is_generic != actual_type->data.fn.is_generic) { |
| 6635 | result.id = ConstCastResultIdFnIsGeneric; |
| 6636 | return result; |
| 6637 | } |
| 6638 | if (!expected_type->data.fn.is_generic && |
| 6639 | actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable) |
| 6640 | { |
| 6641 | ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.fn.fn_type_id.return_type, actual_type->data.fn.fn_type_id.return_type, source_node); |
| 6642 | if (child.id != ConstCastResultIdOk) { |
| 6643 | result.id = ConstCastResultIdFnReturnType; |
| 6644 | result.data.return_type = allocate_nonzero<ConstCastOnly>(1); |
| 6645 | *result.data.return_type = child; |
| 6646 | } |
| 6647 | return result; |
| 6648 | } |
| 6649 | if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) { |
| 6650 | result.id = ConstCastResultIdFnArgCount; |
| 6651 | return result; |
| 6652 | } |
| 6653 | if (expected_type->data.fn.fn_type_id.next_param_index != actual_type->data.fn.fn_type_id.next_param_index) { |
| 6654 | result.id = ConstCastResultIdFnGenericArgCount; |
| 6655 | return result; |
| 6656 | } |
| 6657 | assert(expected_type->data.fn.is_generic || |
| 6658 | expected_type->data.fn.fn_type_id.next_param_index == expected_type->data.fn.fn_type_id.param_count); |
| 6659 | for (size_t i = 0; i < expected_type->data.fn.fn_type_id.next_param_index; i += 1) { |
| 6660 | // note it's reversed for parameters |
| 6661 | FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i]; |
| 6662 | FnTypeParamInfo *expected_param_info = &expected_type->data.fn.fn_type_id.param_info[i]; |
| 6663 | |
| 6664 | ConstCastOnly arg_child = types_match_const_cast_only(ira, actual_param_info->type, expected_param_info->type, source_node); |
| 6665 | if (arg_child.id != ConstCastResultIdOk) { |
| 6666 | result.id = ConstCastResultIdFnArg; |
| 6667 | result.data.fn_arg.arg_index = i; |
| 6668 | result.data.fn_arg.child = allocate_nonzero<ConstCastOnly>(1); |
| 6669 | *result.data.fn_arg.child = arg_child; |
| 6670 | return result; |
| 6671 | } |
| 6672 | |
| 6673 | if (expected_param_info->is_noalias != actual_param_info->is_noalias) { |
| 6674 | result.id = ConstCastResultIdFnArgNoAlias; |
| 6675 | result.data.arg_no_alias.arg_index = i; |
| 6676 | return result; |
| 6677 | } |
| 6678 | } |
| 6679 | return result; |
| 6680 | } |
| 6681 | |
| 6682 | result.id = ConstCastResultIdType; |
| 6683 | return result; |
| 6684 | } |
| 6685 | |
| 6419 | 6686 | enum ImplicitCastMatchResult { |
| 6420 | 6687 | ImplicitCastMatchResultNo, |
| 6421 | 6688 | ImplicitCastMatchResultYes, |
| ... | ... | @@ -6425,7 +6692,8 @@ enum ImplicitCastMatchResult { |
| 6425 | 6692 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, |
| 6426 | 6693 | TypeTableEntry *actual_type, IrInstruction *value) |
| 6427 | 6694 | { |
| 6428 | | ConstCastOnly const_cast_result = types_match_const_cast_only(ira->codegen, expected_type, actual_type); |
| 6695 | AstNode *source_node = value->source_node; |
| 6696 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, expected_type, actual_type, source_node); |
| 6429 | 6697 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 6430 | 6698 | return ImplicitCastMatchResultYes; |
| 6431 | 6699 | } |
| ... | ... | @@ -6520,7 +6788,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6520 | 6788 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6521 | 6789 | |
| 6522 | 6790 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6523 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6791 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6524 | 6792 | { |
| 6525 | 6793 | return ImplicitCastMatchResultYes; |
| 6526 | 6794 | } |
| ... | ... | @@ -6539,7 +6807,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6539 | 6807 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 6540 | 6808 | |
| 6541 | 6809 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 6542 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6810 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6543 | 6811 | { |
| 6544 | 6812 | return ImplicitCastMatchResultYes; |
| 6545 | 6813 | } |
| ... | ... | @@ -6555,7 +6823,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6555 | 6823 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6556 | 6824 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6557 | 6825 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6558 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6826 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6559 | 6827 | { |
| 6560 | 6828 | return ImplicitCastMatchResultYes; |
| 6561 | 6829 | } |
| ... | ... | @@ -6570,7 +6838,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6570 | 6838 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6571 | 6839 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6572 | 6840 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6573 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 6841 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6574 | 6842 | { |
| 6575 | 6843 | return ImplicitCastMatchResultYes; |
| 6576 | 6844 | } |
| ... | ... | @@ -6650,7 +6918,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6650 | 6918 | // implicitly take a const pointer to something |
| 6651 | 6919 | if (!type_requires_comptime(actual_type)) { |
| 6652 | 6920 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 6653 | | if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual).id == ConstCastResultIdOk) { |
| 6921 | if (types_match_const_cast_only(ira, expected_type, const_ptr_actual, source_node).id == ConstCastResultIdOk) { |
| 6654 | 6922 | return ImplicitCastMatchResultYes; |
| 6655 | 6923 | } |
| 6656 | 6924 | } |
| ... | ... | @@ -6658,27 +6926,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6658 | 6926 | return ImplicitCastMatchResultNo; |
| 6659 | 6927 | } |
| 6660 | 6928 | |
| 6661 | | static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) { |
| 6662 | | FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; |
| 6663 | | if (infer_fn != nullptr) { |
| 6664 | | if (infer_fn->anal_state == FnAnalStateInvalid) { |
| 6665 | | return false; |
| 6666 | | } else if (infer_fn->anal_state == FnAnalStateReady) { |
| 6667 | | analyze_fn_body(ira->codegen, infer_fn); |
| 6668 | | if (err_set_type->data.error_set.infer_fn != nullptr) { |
| 6669 | | assert(ira->codegen->errors.length != 0); |
| 6670 | | return false; |
| 6671 | | } |
| 6672 | | } else { |
| 6673 | | ir_add_error_node(ira, source_node, |
| 6674 | | buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet", |
| 6675 | | buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name))); |
| 6676 | | return false; |
| 6677 | | } |
| 6678 | | } |
| 6679 | | return true; |
| 6680 | | } |
| 6681 | | |
| 6682 | 6929 | static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) { |
| 6683 | 6930 | assert(instruction_count >= 1); |
| 6684 | 6931 | IrInstruction *prev_inst = instructions[0]; |
| ... | ... | @@ -6687,17 +6934,19 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6687 | 6934 | } |
| 6688 | 6935 | ErrorTableEntry **errors = nullptr; |
| 6689 | 6936 | TypeTableEntry *err_set_type = nullptr; |
| 6690 | | if (prev_inst->value.type == ira->codegen->builtin_types.entry_global_error_set) { |
| 6691 | | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 6692 | | } else if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { |
| 6693 | | err_set_type = prev_inst->value.type; |
| 6694 | | errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length); |
| 6695 | | if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) { |
| 6696 | | return ira->codegen->builtin_types.entry_invalid; |
| 6697 | | } |
| 6698 | | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| 6699 | | ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i]; |
| 6700 | | errors[error_entry->value] = error_entry; |
| 6937 | if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { |
| 6938 | if (type_is_global_error_set(prev_inst->value.type)) { |
| 6939 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 6940 | } else { |
| 6941 | err_set_type = prev_inst->value.type; |
| 6942 | if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) { |
| 6943 | return ira->codegen->builtin_types.entry_invalid; |
| 6944 | } |
| 6945 | errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length); |
| 6946 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| 6947 | ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i]; |
| 6948 | errors[error_entry->value] = error_entry; |
| 6949 | } |
| 6701 | 6950 | } |
| 6702 | 6951 | } |
| 6703 | 6952 | |
| ... | ... | @@ -6734,18 +6983,18 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6734 | 6983 | if (prev_type->id == TypeTableEntryIdErrorSet) { |
| 6735 | 6984 | assert(err_set_type != nullptr); |
| 6736 | 6985 | if (cur_type->id == TypeTableEntryIdErrorSet) { |
| 6737 | | if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 6986 | if (type_is_global_error_set(err_set_type)) { |
| 6738 | 6987 | continue; |
| 6739 | 6988 | } |
| 6740 | | if (cur_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 6989 | if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { |
| 6990 | return ira->codegen->builtin_types.entry_invalid; |
| 6991 | } |
| 6992 | if (type_is_global_error_set(cur_type)) { |
| 6741 | 6993 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 6742 | 6994 | prev_inst = cur_inst; |
| 6743 | 6995 | continue; |
| 6744 | 6996 | } |
| 6745 | 6997 | |
| 6746 | | if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { |
| 6747 | | return ira->codegen->builtin_types.entry_invalid; |
| 6748 | | } |
| 6749 | 6998 | // if err_set_type is a superset of cur_type, keep err_set_type. |
| 6750 | 6999 | // if cur_type is a superset of err_set_type, switch err_set_type to cur_type |
| 6751 | 7000 | bool prev_is_superset = true; |
| ... | ... | @@ -6791,12 +7040,15 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6791 | 7040 | assert(errors != nullptr); |
| 6792 | 7041 | continue; |
| 6793 | 7042 | } else if (cur_type->id == TypeTableEntryIdErrorUnion) { |
| 6794 | | if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 7043 | if (type_is_global_error_set(err_set_type)) { |
| 6795 | 7044 | prev_inst = cur_inst; |
| 6796 | 7045 | continue; |
| 6797 | 7046 | } |
| 6798 | 7047 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 6799 | | if (cur_err_set_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 7048 | if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { |
| 7049 | return ira->codegen->builtin_types.entry_invalid; |
| 7050 | } |
| 7051 | if (type_is_global_error_set(cur_err_set_type)) { |
| 6800 | 7052 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 6801 | 7053 | prev_inst = cur_inst; |
| 6802 | 7054 | continue; |
| ... | ... | @@ -6807,9 +7059,6 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6807 | 7059 | ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i]; |
| 6808 | 7060 | errors[error_entry->value] = nullptr; |
| 6809 | 7061 | } |
| 6810 | | if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { |
| 6811 | | return ira->codegen->builtin_types.entry_invalid; |
| 6812 | | } |
| 6813 | 7062 | for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) { |
| 6814 | 7063 | ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i]; |
| 6815 | 7064 | errors[error_entry->value] = error_entry; |
| ... | ... | @@ -6845,11 +7094,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6845 | 7094 | if (prev_type->id == TypeTableEntryIdArray) { |
| 6846 | 7095 | convert_to_const_slice = true; |
| 6847 | 7096 | } |
| 6848 | | if (cur_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 7097 | if (type_is_global_error_set(cur_type)) { |
| 6849 | 7098 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 6850 | 7099 | continue; |
| 6851 | 7100 | } |
| 6852 | | if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 7101 | if (err_set_type != nullptr && type_is_global_error_set(err_set_type)) { |
| 6853 | 7102 | continue; |
| 6854 | 7103 | } |
| 6855 | 7104 | if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { |
| ... | ... | @@ -6884,11 +7133,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6884 | 7133 | } |
| 6885 | 7134 | } |
| 6886 | 7135 | |
| 6887 | | if (types_match_const_cast_only(ira->codegen, prev_type, cur_type).id == ConstCastResultIdOk) { |
| 7136 | if (types_match_const_cast_only(ira, prev_type, cur_type, source_node).id == ConstCastResultIdOk) { |
| 6888 | 7137 | continue; |
| 6889 | 7138 | } |
| 6890 | 7139 | |
| 6891 | | if (types_match_const_cast_only(ira->codegen, cur_type, prev_type).id == ConstCastResultIdOk) { |
| 7140 | if (types_match_const_cast_only(ira, cur_type, prev_type, source_node).id == ConstCastResultIdOk) { |
| 6892 | 7141 | prev_inst = cur_inst; |
| 6893 | 7142 | continue; |
| 6894 | 7143 | } |
| ... | ... | @@ -6911,26 +7160,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6911 | 7160 | } |
| 6912 | 7161 | |
| 6913 | 7162 | if (prev_type->id == TypeTableEntryIdErrorUnion && |
| 6914 | | types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type).id == ConstCastResultIdOk) |
| 7163 | types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type, source_node).id == ConstCastResultIdOk) |
| 6915 | 7164 | { |
| 6916 | 7165 | continue; |
| 6917 | 7166 | } |
| 6918 | 7167 | |
| 6919 | 7168 | if (cur_type->id == TypeTableEntryIdErrorUnion && |
| 6920 | | types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type).id == ConstCastResultIdOk) |
| 7169 | types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type, source_node).id == ConstCastResultIdOk) |
| 6921 | 7170 | { |
| 6922 | 7171 | prev_inst = cur_inst; |
| 6923 | 7172 | continue; |
| 6924 | 7173 | } |
| 6925 | 7174 | |
| 6926 | 7175 | if (prev_type->id == TypeTableEntryIdMaybe && |
| 6927 | | types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type).id == ConstCastResultIdOk) |
| 7176 | types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, source_node).id == ConstCastResultIdOk) |
| 6928 | 7177 | { |
| 6929 | 7178 | continue; |
| 6930 | 7179 | } |
| 6931 | 7180 | |
| 6932 | 7181 | if (cur_type->id == TypeTableEntryIdMaybe && |
| 6933 | | types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type).id == ConstCastResultIdOk) |
| 7182 | types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, source_node).id == ConstCastResultIdOk) |
| 6934 | 7183 | { |
| 6935 | 7184 | prev_inst = cur_inst; |
| 6936 | 7185 | continue; |
| ... | ... | @@ -6968,7 +7217,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6968 | 7217 | |
| 6969 | 7218 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6970 | 7219 | cur_type->data.array.len != prev_type->data.array.len && |
| 6971 | | types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type).id == ConstCastResultIdOk) |
| 7220 | types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6972 | 7221 | { |
| 6973 | 7222 | convert_to_const_slice = true; |
| 6974 | 7223 | prev_inst = cur_inst; |
| ... | ... | @@ -6977,7 +7226,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6977 | 7226 | |
| 6978 | 7227 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6979 | 7228 | cur_type->data.array.len != prev_type->data.array.len && |
| 6980 | | types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type).id == ConstCastResultIdOk) |
| 7229 | types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6981 | 7230 | { |
| 6982 | 7231 | convert_to_const_slice = true; |
| 6983 | 7232 | continue; |
| ... | ... | @@ -6986,8 +7235,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6986 | 7235 | if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) && |
| 6987 | 7236 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6988 | 7237 | cur_type->data.array.len == 0) && |
| 6989 | | types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6990 | | cur_type->data.array.child_type).id == ConstCastResultIdOk) |
| 7238 | types_match_const_cast_only(ira, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 7239 | cur_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 6991 | 7240 | { |
| 6992 | 7241 | convert_to_const_slice = false; |
| 6993 | 7242 | continue; |
| ... | ... | @@ -6996,8 +7245,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6996 | 7245 | if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) && |
| 6997 | 7246 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6998 | 7247 | prev_type->data.array.len == 0) && |
| 6999 | | types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 7000 | | prev_type->data.array.child_type).id == ConstCastResultIdOk) |
| 7248 | types_match_const_cast_only(ira, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 7249 | prev_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 7001 | 7250 | { |
| 7002 | 7251 | prev_inst = cur_inst; |
| 7003 | 7252 | convert_to_const_slice = false; |
| ... | ... | @@ -7581,7 +7830,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 7581 | 7830 | zig_panic("TODO explicit error set cast"); |
| 7582 | 7831 | |
| 7583 | 7832 | if (container_set->data.error_set.infer_fn == nullptr && |
| 7584 | | container_set != ira->codegen->builtin_types.entry_global_error_set) |
| 7833 | !type_is_global_error_set(container_set)) |
| 7585 | 7834 | { |
| 7586 | 7835 | ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length); |
| 7587 | 7836 | for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) { |
| ... | ... | @@ -8103,7 +8352,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 8103 | 8352 | } else { |
| 8104 | 8353 | zig_unreachable(); |
| 8105 | 8354 | } |
| 8106 | | if (err_set_type != ira->codegen->builtin_types.entry_global_error_set) { |
| 8355 | if (!type_is_global_error_set(err_set_type)) { |
| 8107 | 8356 | if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) { |
| 8108 | 8357 | return ira->codegen->invalid_instruction; |
| 8109 | 8358 | } |
| ... | ... | @@ -8140,6 +8389,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8140 | 8389 | TypeTableEntry *wanted_type, IrInstruction *value) |
| 8141 | 8390 | { |
| 8142 | 8391 | TypeTableEntry *actual_type = value->value.type; |
| 8392 | AstNode *source_node = source_instr->source_node; |
| 8143 | 8393 | |
| 8144 | 8394 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| 8145 | 8395 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -8149,7 +8399,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8149 | 8399 | return value; |
| 8150 | 8400 | |
| 8151 | 8401 | // explicit match or non-const to const |
| 8152 | | if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type).id == ConstCastResultIdOk) { |
| 8402 | if (types_match_const_cast_only(ira, wanted_type, actual_type, source_node).id == ConstCastResultIdOk) { |
| 8153 | 8403 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| 8154 | 8404 | } |
| 8155 | 8405 | |
| ... | ... | @@ -8195,7 +8445,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8195 | 8445 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8196 | 8446 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8197 | 8447 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8198 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8448 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 8199 | 8449 | { |
| 8200 | 8450 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8201 | 8451 | } |
| ... | ... | @@ -8213,7 +8463,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8213 | 8463 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 8214 | 8464 | |
| 8215 | 8465 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 8216 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8466 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 8217 | 8467 | { |
| 8218 | 8468 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8219 | 8469 | } |
| ... | ... | @@ -8229,7 +8479,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8229 | 8479 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8230 | 8480 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8231 | 8481 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8232 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8482 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 8233 | 8483 | { |
| 8234 | 8484 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |
| 8235 | 8485 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8252,7 +8502,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8252 | 8502 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8253 | 8503 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8254 | 8504 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8255 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8505 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 8256 | 8506 | { |
| 8257 | 8507 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 8258 | 8508 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8314,7 +8564,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8314 | 8564 | |
| 8315 | 8565 | // explicit cast from child type of maybe type to maybe type |
| 8316 | 8566 | if (wanted_type->id == TypeTableEntryIdMaybe) { |
| 8317 | | if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type).id == ConstCastResultIdOk) { |
| 8567 | if (types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, actual_type, source_node).id == ConstCastResultIdOk) { |
| 8318 | 8568 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 8319 | 8569 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8320 | 8570 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8336,7 +8586,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8336 | 8586 | |
| 8337 | 8587 | // explicit cast from child type of error type to error type |
| 8338 | 8588 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { |
| 8339 | | if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type).id == ConstCastResultIdOk) { |
| 8589 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, source_node).id == ConstCastResultIdOk) { |
| 8340 | 8590 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 8341 | 8591 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8342 | 8592 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8358,7 +8608,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8358 | 8608 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8359 | 8609 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8360 | 8610 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8361 | | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) |
| 8611 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node).id == ConstCastResultIdOk) |
| 8362 | 8612 | { |
| 8363 | 8613 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 8364 | 8614 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8385,7 +8635,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8385 | 8635 | actual_type->id != TypeTableEntryIdMaybe) |
| 8386 | 8636 | { |
| 8387 | 8637 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; |
| 8388 | | if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type).id == ConstCastResultIdOk || |
| 8638 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk || |
| 8389 | 8639 | actual_type->id == TypeTableEntryIdNullLit || |
| 8390 | 8640 | actual_type->id == TypeTableEntryIdNumLitInt || |
| 8391 | 8641 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8535,7 +8785,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8535 | 8785 | // explicit cast from something to const pointer of it |
| 8536 | 8786 | if (!type_requires_comptime(actual_type)) { |
| 8537 | 8787 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 8538 | | if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual).id == ConstCastResultIdOk) { |
| 8788 | if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node).id == ConstCastResultIdOk) { |
| 8539 | 8789 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); |
| 8540 | 8790 | } |
| 8541 | 8791 | } |
| ... | ... | @@ -9700,8 +9950,8 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction |
| 9700 | 9950 | if (type_is_invalid(op2_type)) |
| 9701 | 9951 | return ira->codegen->builtin_types.entry_invalid; |
| 9702 | 9952 | |
| 9703 | | if (op1_type == ira->codegen->builtin_types.entry_global_error_set || |
| 9704 | | op2_type == ira->codegen->builtin_types.entry_global_error_set) |
| 9953 | if (type_is_global_error_set(op1_type) || |
| 9954 | type_is_global_error_set(op2_type)) |
| 9705 | 9955 | { |
| 9706 | 9956 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 9707 | 9957 | out_val->data.x_type = ira->codegen->builtin_types.entry_global_error_set; |
| ... | ... | @@ -11716,7 +11966,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 11716 | 11966 | } else if (child_type->id == TypeTableEntryIdErrorSet) { |
| 11717 | 11967 | ErrorTableEntry *err_entry; |
| 11718 | 11968 | TypeTableEntry *err_set_type; |
| 11719 | | if (child_type == ira->codegen->builtin_types.entry_global_error_set) { |
| 11969 | if (type_is_global_error_set(child_type)) { |
| 11720 | 11970 | auto existing_entry = ira->codegen->error_table.maybe_get(field_name); |
| 11721 | 11971 | if (existing_entry) { |
| 11722 | 11972 | err_entry = existing_entry->value; |
| ... | ... | @@ -14764,7 +15014,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 14764 | 15014 | if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) { |
| 14765 | 15015 | return ira->codegen->builtin_types.entry_invalid; |
| 14766 | 15016 | } |
| 14767 | | if (err_set_type != ira->codegen->builtin_types.entry_global_error_set && |
| 15017 | if (!type_is_global_error_set(err_set_type) && |
| 14768 | 15018 | err_set_type->data.error_set.err_count == 0) |
| 14769 | 15019 | { |
| 14770 | 15020 | assert(err_set_type->data.error_set.infer_fn == nullptr); |