| ... | ... | @@ -9433,6 +9433,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 9433 | 9433 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| 9434 | 9434 | assert(union_field != nullptr); |
| 9435 | 9435 | type_ensure_zero_bits_known(ira->codegen, union_field->type_entry); |
| 9436 | if (type_is_invalid(union_field->type_entry)) |
| 9437 | return ira->codegen->invalid_instruction; |
| 9436 | 9438 | if (!union_field->type_entry->zero_bits) { |
| 9437 | 9439 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 9438 | 9440 | union_field->enum_field->decl_index); |
| ... | ... | @@ -10015,6 +10017,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10015 | 10017 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |
| 10016 | 10018 | actual_type->id == TypeTableEntryIdNumLitInt) |
| 10017 | 10019 | { |
| 10020 | ensure_complete_type(ira->codegen, wanted_type); |
| 10021 | if (type_is_invalid(wanted_type)) |
| 10022 | return ira->codegen->invalid_instruction; |
| 10018 | 10023 | if (wanted_type->id == TypeTableEntryIdEnum) { |
| 10019 | 10024 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value); |
| 10020 | 10025 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -12766,6 +12771,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 12766 | 12771 | TypeTableEntry *type_entry = ir_resolve_type(ira, value); |
| 12767 | 12772 | if (type_is_invalid(type_entry)) |
| 12768 | 12773 | return ira->codegen->builtin_types.entry_invalid; |
| 12774 | ensure_complete_type(ira->codegen, type_entry); |
| 12775 | if (type_is_invalid(type_entry)) |
| 12776 | return ira->codegen->builtin_types.entry_invalid; |
| 12777 | |
| 12769 | 12778 | switch (type_entry->id) { |
| 12770 | 12779 | case TypeTableEntryIdInvalid: |
| 12771 | 12780 | zig_unreachable(); |
| ... | ... | @@ -13187,6 +13196,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 13187 | 13196 | |
| 13188 | 13197 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 13189 | 13198 | ensure_complete_type(ira->codegen, return_type->data.pointer.child_type); |
| 13199 | if (type_is_invalid(return_type->data.pointer.child_type)) |
| 13200 | return ira->codegen->builtin_types.entry_invalid; |
| 13201 | |
| 13190 | 13202 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 13191 | 13203 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| 13192 | 13204 | uint64_t ptr_align = return_type->data.pointer.alignment; |
| ... | ... | @@ -13696,7 +13708,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 13696 | 13708 | } |
| 13697 | 13709 | if (child_type->id == TypeTableEntryIdEnum) { |
| 13698 | 13710 | ensure_complete_type(ira->codegen, child_type); |
| 13699 | | if (child_type->data.enumeration.is_invalid) |
| 13711 | if (type_is_invalid(child_type)) |
| 13700 | 13712 | return ira->codegen->builtin_types.entry_invalid; |
| 13701 | 13713 | |
| 13702 | 13714 | TypeEnumField *field = find_enum_type_field(child_type, field_name); |
| ... | ... | @@ -14569,27 +14581,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 14569 | 14581 | return ira->codegen->builtin_types.entry_invalid; |
| 14570 | 14582 | |
| 14571 | 14583 | TypeTableEntry *ptr_type = value->value.type; |
| 14572 | | if (ptr_type->id == TypeTableEntryIdMetaType) { |
| 14584 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 14585 | |
| 14586 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; |
| 14587 | if (type_is_invalid(type_entry)) { |
| 14588 | return ira->codegen->builtin_types.entry_invalid; |
| 14589 | } else if (type_entry->id == TypeTableEntryIdMetaType) { |
| 14573 | 14590 | // surprise! actually this is just ??T not an unwrap maybe instruction |
| 14574 | | TypeTableEntry *ptr_type_ptr = ir_resolve_type(ira, value); |
| 14575 | | assert(ptr_type_ptr->id == TypeTableEntryIdPointer); |
| 14576 | | TypeTableEntry *child_type = ptr_type_ptr->data.pointer.child_type; |
| 14591 | ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value); |
| 14592 | assert(ptr_val->type->id == TypeTableEntryIdMetaType); |
| 14593 | TypeTableEntry *child_type = ptr_val->data.x_type; |
| 14594 | |
| 14577 | 14595 | type_ensure_zero_bits_known(ira->codegen, child_type); |
| 14578 | 14596 | TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type); |
| 14579 | 14597 | TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1); |
| 14580 | | TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, layer2, true); |
| 14581 | 14598 | |
| 14582 | 14599 | IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope, |
| 14583 | | unwrap_maybe_instruction->base.source_node, result_type); |
| 14584 | | ir_link_new_instruction(const_instr, &unwrap_maybe_instruction->base); |
| 14585 | | return const_instr->value.type; |
| 14586 | | } |
| 14587 | | |
| 14588 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 14589 | | |
| 14590 | | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; |
| 14591 | | if (type_is_invalid(type_entry)) { |
| 14592 | | return ira->codegen->builtin_types.entry_invalid; |
| 14600 | unwrap_maybe_instruction->base.source_node, layer2); |
| 14601 | IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr, |
| 14602 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile); |
| 14603 | ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base); |
| 14604 | return result_instr->value.type; |
| 14593 | 14605 | } else if (type_entry->id != TypeTableEntryIdMaybe) { |
| 14594 | 14606 | ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node, |
| 14595 | 14607 | buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name))); |
| ... | ... | @@ -15115,6 +15127,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir |
| 15115 | 15127 | assert(container_type->id == TypeTableEntryIdUnion); |
| 15116 | 15128 | |
| 15117 | 15129 | ensure_complete_type(ira->codegen, container_type); |
| 15130 | if (type_is_invalid(container_type)) |
| 15131 | return ira->codegen->builtin_types.entry_invalid; |
| 15118 | 15132 | |
| 15119 | 15133 | if (instr_field_count != 1) { |
| 15120 | 15134 | ir_add_error(ira, instruction, |
| ... | ... | @@ -15182,6 +15196,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 15182 | 15196 | } |
| 15183 | 15197 | |
| 15184 | 15198 | ensure_complete_type(ira->codegen, container_type); |
| 15199 | if (type_is_invalid(container_type)) |
| 15200 | return ira->codegen->builtin_types.entry_invalid; |
| 15185 | 15201 | |
| 15186 | 15202 | size_t actual_field_count = container_type->data.structure.src_field_count; |
| 15187 | 15203 | |
| ... | ... | @@ -15687,6 +15703,8 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, |
| 15687 | 15703 | return ira->codegen->builtin_types.entry_invalid; |
| 15688 | 15704 | |
| 15689 | 15705 | ensure_complete_type(ira->codegen, container_type); |
| 15706 | if (type_is_invalid(container_type)) |
| 15707 | return ira->codegen->builtin_types.entry_invalid; |
| 15690 | 15708 | |
| 15691 | 15709 | IrInstruction *field_name_value = instruction->field_name->other; |
| 15692 | 15710 | Buf *field_name = ir_resolve_str(ira, field_name_value); |
| ... | ... | @@ -15740,6 +15758,9 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 15740 | 15758 | assert(type_info_var->type->id == TypeTableEntryIdMetaType); |
| 15741 | 15759 | |
| 15742 | 15760 | ensure_complete_type(ira->codegen, type_info_var->data.x_type); |
| 15761 | if (type_is_invalid(type_info_var->data.x_type)) |
| 15762 | return ira->codegen->builtin_types.entry_invalid; |
| 15763 | |
| 15743 | 15764 | type_info_type = type_info_var->data.x_type; |
| 15744 | 15765 | assert(type_info_type->id == TypeTableEntryIdUnion); |
| 15745 | 15766 | } |
| ... | ... | @@ -15765,26 +15786,37 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 15765 | 15786 | VariableTableEntry *var = tld->var; |
| 15766 | 15787 | |
| 15767 | 15788 | ensure_complete_type(ira->codegen, var->value->type); |
| 15789 | if (type_is_invalid(var->value->type)) |
| 15790 | return ira->codegen->builtin_types.entry_invalid; |
| 15768 | 15791 | assert(var->value->type->id == TypeTableEntryIdMetaType); |
| 15769 | 15792 | return var->value->data.x_type; |
| 15770 | 15793 | } |
| 15771 | 15794 | |
| 15772 | | static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) |
| 15795 | static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) |
| 15773 | 15796 | { |
| 15774 | 15797 | TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition"); |
| 15775 | 15798 | ensure_complete_type(ira->codegen, type_info_definition_type); |
| 15799 | if (type_is_invalid(type_info_definition_type)) |
| 15800 | return false; |
| 15801 | |
| 15776 | 15802 | ensure_field_index(type_info_definition_type, "name", 0); |
| 15777 | 15803 | ensure_field_index(type_info_definition_type, "is_pub", 1); |
| 15778 | 15804 | ensure_field_index(type_info_definition_type, "data", 2); |
| 15779 | 15805 | |
| 15780 | 15806 | TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type); |
| 15781 | 15807 | ensure_complete_type(ira->codegen, type_info_definition_data_type); |
| 15808 | if (type_is_invalid(type_info_definition_data_type)) |
| 15809 | return false; |
| 15782 | 15810 | |
| 15783 | 15811 | TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type); |
| 15784 | 15812 | ensure_complete_type(ira->codegen, type_info_fn_def_type); |
| 15813 | if (type_is_invalid(type_info_fn_def_type)) |
| 15814 | return false; |
| 15785 | 15815 | |
| 15786 | 15816 | TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type); |
| 15787 | 15817 | ensure_complete_type(ira->codegen, type_info_fn_def_inline_type); |
| 15818 | if (type_is_invalid(type_info_fn_def_inline_type)) |
| 15819 | return false; |
| 15788 | 15820 | |
| 15789 | 15821 | // Loop through our definitions once to figure out how many definitions we will generate info for. |
| 15790 | 15822 | auto decl_it = decls_scope->decl_table.entry_iterator(); |
| ... | ... | @@ -15799,7 +15831,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15799 | 15831 | resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node); |
| 15800 | 15832 | if (curr_entry->value->resolution != TldResolutionOk) |
| 15801 | 15833 | { |
| 15802 | | return; |
| 15834 | return false; |
| 15803 | 15835 | } |
| 15804 | 15836 | } |
| 15805 | 15837 | |
| ... | ... | @@ -15864,6 +15896,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15864 | 15896 | { |
| 15865 | 15897 | VariableTableEntry *var = ((TldVar *)curr_entry->value)->var; |
| 15866 | 15898 | ensure_complete_type(ira->codegen, var->value->type); |
| 15899 | if (type_is_invalid(var->value->type)) |
| 15900 | return false; |
| 15901 | |
| 15867 | 15902 | if (var->value->type->id == TypeTableEntryIdMetaType) |
| 15868 | 15903 | { |
| 15869 | 15904 | // We have a variable of type 'type', so it's actually a type definition. |
| ... | ... | @@ -15991,6 +16026,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 15991 | 16026 | { |
| 15992 | 16027 | TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry; |
| 15993 | 16028 | ensure_complete_type(ira->codegen, type_entry); |
| 16029 | if (type_is_invalid(type_entry)) |
| 16030 | return false; |
| 16031 | |
| 15994 | 16032 | // This is a type. |
| 15995 | 16033 | bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0); |
| 15996 | 16034 | |
| ... | ... | @@ -16011,6 +16049,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop |
| 16011 | 16049 | } |
| 16012 | 16050 | |
| 16013 | 16051 | assert(definition_index == definition_count); |
| 16052 | return true; |
| 16014 | 16053 | } |
| 16015 | 16054 | |
| 16016 | 16055 | static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry) |
| ... | ... | @@ -16019,6 +16058,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16019 | 16058 | assert(!type_is_invalid(type_entry)); |
| 16020 | 16059 | |
| 16021 | 16060 | ensure_complete_type(ira->codegen, type_entry); |
| 16061 | if (type_is_invalid(type_entry)) |
| 16062 | return nullptr; |
| 16022 | 16063 | |
| 16023 | 16064 | const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field, |
| 16024 | 16065 | TypeTableEntry *type_info_enum_field_type) { |
| ... | ... | @@ -16246,7 +16287,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16246 | 16287 | } |
| 16247 | 16288 | // defs: []TypeInfo.Definition |
| 16248 | 16289 | ensure_field_index(result->type, "defs", 3); |
| 16249 | | ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope); |
| 16290 | if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope)) |
| 16291 | return nullptr; |
| 16250 | 16292 | |
| 16251 | 16293 | break; |
| 16252 | 16294 | } |
| ... | ... | @@ -16401,7 +16443,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16401 | 16443 | } |
| 16402 | 16444 | // defs: []TypeInfo.Definition |
| 16403 | 16445 | ensure_field_index(result->type, "defs", 3); |
| 16404 | | ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope); |
| 16446 | if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope)) |
| 16447 | return nullptr; |
| 16405 | 16448 | |
| 16406 | 16449 | break; |
| 16407 | 16450 | } |
| ... | ... | @@ -16412,6 +16455,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16412 | 16455 | buf_init_from_str(&ptr_field_name, "ptr"); |
| 16413 | 16456 | TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry; |
| 16414 | 16457 | ensure_complete_type(ira->codegen, ptr_type); |
| 16458 | if (type_is_invalid(ptr_type)) |
| 16459 | return nullptr; |
| 16415 | 16460 | buf_deinit(&ptr_field_name); |
| 16416 | 16461 | |
| 16417 | 16462 | result = create_ptr_like_type_info("Slice", ptr_type); |
| ... | ... | @@ -16482,7 +16527,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16482 | 16527 | } |
| 16483 | 16528 | // defs: []TypeInfo.Definition |
| 16484 | 16529 | ensure_field_index(result->type, "defs", 2); |
| 16485 | | ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope); |
| 16530 | if (!ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope)) |
| 16531 | return nullptr; |
| 16486 | 16532 | |
| 16487 | 16533 | break; |
| 16488 | 16534 | } |
| ... | ... | @@ -17502,6 +17548,11 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst |
| 17502 | 17548 | if (type_is_invalid(container_type)) |
| 17503 | 17549 | return ira->codegen->builtin_types.entry_invalid; |
| 17504 | 17550 | |
| 17551 | ensure_complete_type(ira->codegen, container_type); |
| 17552 | if (type_is_invalid(container_type)) |
| 17553 | return ira->codegen->builtin_types.entry_invalid; |
| 17554 | |
| 17555 | |
| 17505 | 17556 | uint64_t member_index; |
| 17506 | 17557 | IrInstruction *index_value = instruction->member_index->other; |
| 17507 | 17558 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| ... | ... | @@ -17544,6 +17595,10 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst |
| 17544 | 17595 | if (type_is_invalid(container_type)) |
| 17545 | 17596 | return ira->codegen->builtin_types.entry_invalid; |
| 17546 | 17597 | |
| 17598 | ensure_complete_type(ira->codegen, container_type); |
| 17599 | if (type_is_invalid(container_type)) |
| 17600 | return ira->codegen->builtin_types.entry_invalid; |
| 17601 | |
| 17547 | 17602 | uint64_t member_index; |
| 17548 | 17603 | IrInstruction *index_value = instruction->member_index->other; |
| 17549 | 17604 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| ... | ... | @@ -18485,7 +18540,12 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 18485 | 18540 | return ira->codegen->builtin_types.entry_invalid; |
| 18486 | 18541 | |
| 18487 | 18542 | ensure_complete_type(ira->codegen, dest_type); |
| 18543 | if (type_is_invalid(dest_type)) |
| 18544 | return ira->codegen->builtin_types.entry_invalid; |
| 18545 | |
| 18488 | 18546 | ensure_complete_type(ira->codegen, src_type); |
| 18547 | if (type_is_invalid(src_type)) |
| 18548 | return ira->codegen->builtin_types.entry_invalid; |
| 18489 | 18549 | |
| 18490 | 18550 | if (get_codegen_ptr_type(src_type) != nullptr) { |
| 18491 | 18551 | ir_add_error(ira, value, |
| ... | ... | @@ -18724,6 +18784,9 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc |
| 18724 | 18784 | if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes)) |
| 18725 | 18785 | return ira->codegen->builtin_types.entry_invalid; |
| 18726 | 18786 | } else { |
| 18787 | type_ensure_zero_bits_known(ira->codegen, child_type); |
| 18788 | if (type_is_invalid(child_type)) |
| 18789 | return ira->codegen->builtin_types.entry_invalid; |
| 18727 | 18790 | align_bytes = get_abi_alignment(ira->codegen, child_type); |
| 18728 | 18791 | } |
| 18729 | 18792 | |