authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-20 19:56:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-20 19:56:07-05:00
log4709fe1176ce88a35e877622dc977948846a3a43
tree89c8a5e0c2b1d6ce4d34ef6e3cc6d474289d30d1
parentc4ee37f5067e7dd2c017df1fd6c57c1fad92cf85

more robust detection of types that failed to resolve


3 files changed, 246 insertions(+), 196 deletions(-)

src/analyze.cpp+2
...@@ -1120,6 +1120,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {...@@ -1120,6 +1120,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {
1120 return type_entry->data.enumeration.is_invalid;1120 return type_entry->data.enumeration.is_invalid;
1121 case TypeTableEntryIdUnion:1121 case TypeTableEntryIdUnion:
1122 return type_entry->data.unionation.is_invalid;1122 return type_entry->data.unionation.is_invalid;
1123 case TypeTableEntryIdTypeDecl:
1124 return type_is_invalid(type_entry->data.type_decl.canonical_type);
1123 default:1125 default:
1124 return false;1126 return false;
1125 }1127 }
src/ir.cpp+206-190
...@@ -5705,7 +5705,7 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so...@@ -5705,7 +5705,7 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
5705static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type) {5705static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type) {
5706 TypeTableEntry *other_type_underlying = get_underlying_type(other_type);5706 TypeTableEntry *other_type_underlying = get_underlying_type(other_type);
57075707
5708 if (other_type_underlying->id == TypeTableEntryIdInvalid) {5708 if (type_is_invalid(other_type_underlying)) {
5709 return false;5709 return false;
5710 }5710 }
57115711
...@@ -5865,7 +5865,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -5865,7 +5865,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
5865static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {5865static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {
5866 assert(instruction_count >= 1);5866 assert(instruction_count >= 1);
5867 IrInstruction *prev_inst = instructions[0];5867 IrInstruction *prev_inst = instructions[0];
5868 if (prev_inst->value.type->id == TypeTableEntryIdInvalid) {5868 if (type_is_invalid(prev_inst->value.type)) {
5869 return ira->codegen->builtin_types.entry_invalid;5869 return ira->codegen->builtin_types.entry_invalid;
5870 }5870 }
5871 bool any_are_pure_error = (prev_inst->value.type->id == TypeTableEntryIdPureError);5871 bool any_are_pure_error = (prev_inst->value.type->id == TypeTableEntryIdPureError);
...@@ -5874,7 +5874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -5874,7 +5874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
5874 IrInstruction *cur_inst = instructions[i];5874 IrInstruction *cur_inst = instructions[i];
5875 TypeTableEntry *cur_type = cur_inst->value.type;5875 TypeTableEntry *cur_type = cur_inst->value.type;
5876 TypeTableEntry *prev_type = prev_inst->value.type;5876 TypeTableEntry *prev_type = prev_inst->value.type;
5877 if (cur_type->id == TypeTableEntryIdInvalid) {5877 if (type_is_invalid(cur_type)) {
5878 return cur_type;5878 return cur_type;
5879 } else if (prev_type->id == TypeTableEntryIdUnreachable) {5879 } else if (prev_type->id == TypeTableEntryIdUnreachable) {
5880 prev_inst = cur_inst;5880 prev_inst = cur_inst;
...@@ -6317,7 +6317,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -6317,7 +6317,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
6317 analyzed_executable.backward_branch_quota = backward_branch_quota;6317 analyzed_executable.backward_branch_quota = backward_branch_quota;
6318 analyzed_executable.begin_scope = scope;6318 analyzed_executable.begin_scope = scope;
6319 TypeTableEntry *result_type = ir_analyze(codegen, &ir_executable, &analyzed_executable, expected_type, node);6319 TypeTableEntry *result_type = ir_analyze(codegen, &ir_executable, &analyzed_executable, expected_type, node);
6320 if (result_type->id == TypeTableEntryIdInvalid)6320 if (type_is_invalid(result_type))
6321 return codegen->invalid_instruction;6321 return codegen->invalid_instruction;
63226322
6323 if (codegen->verbose) {6323 if (codegen->verbose) {
...@@ -6330,7 +6330,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -6330,7 +6330,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
6330}6330}
63316331
6332static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {6332static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
6333 if (type_value->value.type->id == TypeTableEntryIdInvalid)6333 if (type_is_invalid(type_value->value.type))
6334 return ira->codegen->builtin_types.entry_invalid;6334 return ira->codegen->builtin_types.entry_invalid;
63356335
6336 if (type_value->value.type->id != TypeTableEntryIdMetaType) {6336 if (type_value->value.type->id != TypeTableEntryIdMetaType) {
...@@ -6350,7 +6350,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -6350,7 +6350,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
6350 if (fn_value == ira->codegen->invalid_instruction)6350 if (fn_value == ira->codegen->invalid_instruction)
6351 return nullptr;6351 return nullptr;
63526352
6353 if (fn_value->value.type->id == TypeTableEntryIdInvalid)6353 if (type_is_invalid(fn_value->value.type))
6354 return nullptr;6354 return nullptr;
63556355
6356 if (fn_value->value.type->id != TypeTableEntryIdFn) {6356 if (fn_value->value.type->id != TypeTableEntryIdFn) {
...@@ -6372,7 +6372,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -6372,7 +6372,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
6372 if (instr_is_comptime(value)) {6372 if (instr_is_comptime(value)) {
6373 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;6373 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
6374 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);6374 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
6375 if (casted_payload->value.type->id == TypeTableEntryIdInvalid)6375 if (type_is_invalid(casted_payload->value.type))
6376 return ira->codegen->invalid_instruction;6376 return ira->codegen->invalid_instruction;
63776377
6378 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);6378 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
...@@ -6430,7 +6430,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -6430,7 +6430,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
6430 if (instr_is_comptime(value)) {6430 if (instr_is_comptime(value)) {
6431 TypeTableEntry *payload_type = wanted_type->data.error.child_type;6431 TypeTableEntry *payload_type = wanted_type->data.error.child_type;
6432 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);6432 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
6433 if (casted_payload->value.type->id == TypeTableEntryIdInvalid)6433 if (type_is_invalid(casted_payload->value.type))
6434 return ira->codegen->invalid_instruction;6434 return ira->codegen->invalid_instruction;
64356435
6436 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);6436 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
...@@ -6529,7 +6529,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -6529,7 +6529,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
6529static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,6529static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
6530 bool is_const, bool is_volatile)6530 bool is_const, bool is_volatile)
6531{6531{
6532 if (value->value.type->id == TypeTableEntryIdInvalid)6532 if (type_is_invalid(value->value.type))
6533 return ira->codegen->invalid_instruction;6533 return ira->codegen->invalid_instruction;
65346534
6535 if (value->id == IrInstructionIdLoadPtr) {6535 if (value->id == IrInstructionIdLoadPtr) {
...@@ -6752,9 +6752,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -6752,9 +6752,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
6752 TypeTableEntry *isize_type = ira->codegen->builtin_types.entry_isize;6752 TypeTableEntry *isize_type = ira->codegen->builtin_types.entry_isize;
6753 TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize;6753 TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize;
67546754
6755 if (wanted_type_canon->id == TypeTableEntryIdInvalid ||6755 if (type_is_invalid(wanted_type_canon) || type_is_invalid(actual_type_canon)) {
6756 actual_type_canon->id == TypeTableEntryIdInvalid)
6757 {
6758 return ira->codegen->invalid_instruction;6756 return ira->codegen->invalid_instruction;
6759 }6757 }
67606758
...@@ -7016,9 +7014,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -7016,9 +7014,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
7016static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {7014static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {
7017 assert(value);7015 assert(value);
7018 assert(value != ira->codegen->invalid_instruction);7016 assert(value != ira->codegen->invalid_instruction);
7019 assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);7017 assert(!expected_type || !type_is_invalid(expected_type));
7020 assert(value->value.type);7018 assert(value->value.type);
7021 assert(value->value.type->id != TypeTableEntryIdInvalid);7019 assert(!type_is_invalid(value->value.type));
7022 if (expected_type == nullptr)7020 if (expected_type == nullptr)
7023 return value; // anything will do7021 return value; // anything will do
7024 if (expected_type == value->value.type)7022 if (expected_type == value->value.type)
...@@ -7046,7 +7044,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ...@@ -7046,7 +7044,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
70467044
7047static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {7045static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
7048 TypeTableEntry *type_entry = ptr->value.type;7046 TypeTableEntry *type_entry = ptr->value.type;
7049 if (type_entry->id == TypeTableEntryIdInvalid) {7047 if (type_is_invalid(type_entry)) {
7050 return ira->codegen->invalid_instruction;7048 return ira->codegen->invalid_instruction;
7051 } else if (type_entry->id == TypeTableEntryIdPointer) {7049 } else if (type_entry->id == TypeTableEntryIdPointer) {
7052 TypeTableEntry *child_type = type_entry->data.pointer.child_type;7050 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
...@@ -7100,11 +7098,11 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst...@@ -7100,11 +7098,11 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
7100}7098}
71017099
7102static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {7100static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {
7103 if (value->value.type->id == TypeTableEntryIdInvalid)7101 if (type_is_invalid(value->value.type))
7104 return false;7102 return false;
71057103
7106 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize);7104 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize);
7107 if (casted_value->value.type->id == TypeTableEntryIdInvalid)7105 if (type_is_invalid(casted_value->value.type))
7108 return false;7106 return false;
71097107
7110 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);7108 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
...@@ -7116,11 +7114,11 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out...@@ -7116,11 +7114,11 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
7116}7114}
71177115
7118static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {7116static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
7119 if (value->value.type->id == TypeTableEntryIdInvalid)7117 if (type_is_invalid(value->value.type))
7120 return false;7118 return false;
71217119
7122 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);7120 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
7123 if (casted_value->value.type->id == TypeTableEntryIdInvalid)7121 if (type_is_invalid(casted_value->value.type))
7124 return false;7122 return false;
71257123
7126 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);7124 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
...@@ -7140,11 +7138,11 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)...@@ -7140,11 +7138,11 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
7140}7138}
71417139
7142static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {7140static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
7143 if (value->value.type->id == TypeTableEntryIdInvalid)7141 if (type_is_invalid(value->value.type))
7144 return false;7142 return false;
71457143
7146 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);7144 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);
7147 if (casted_value->value.type->id == TypeTableEntryIdInvalid)7145 if (type_is_invalid(casted_value->value.type))
7148 return false;7146 return false;
71497147
7150 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);7148 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
...@@ -7156,12 +7154,12 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -7156,12 +7154,12 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
7156}7154}
71577155
7158static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {7156static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
7159 if (value->value.type->id == TypeTableEntryIdInvalid)7157 if (type_is_invalid(value->value.type))
7160 return nullptr;7158 return nullptr;
71617159
7162 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);7160 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
7163 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);7161 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
7164 if (casted_value->value.type->id == TypeTableEntryIdInvalid)7162 if (type_is_invalid(casted_value->value.type))
7165 return nullptr;7163 return nullptr;
71667164
7167 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);7165 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
...@@ -7191,7 +7189,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,...@@ -7191,7 +7189,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
7191 IrInstructionReturn *return_instruction)7189 IrInstructionReturn *return_instruction)
7192{7190{
7193 IrInstruction *value = return_instruction->value->other;7191 IrInstruction *value = return_instruction->value->other;
7194 if (value->value.type->id == TypeTableEntryIdInvalid)7192 if (type_is_invalid(value->value.type))
7195 return ir_unreach_error(ira);7193 return ir_unreach_error(ira);
7196 ira->implicit_return_type_list.append(value);7194 ira->implicit_return_type_list.append(value);
71977195
...@@ -7211,11 +7209,11 @@ static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructio...@@ -7211,11 +7209,11 @@ static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructio
72117209
7212static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {7210static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
7213 IrInstruction *op1 = bin_op_instruction->op1->other;7211 IrInstruction *op1 = bin_op_instruction->op1->other;
7214 if (op1->value.type->id == TypeTableEntryIdInvalid)7212 if (type_is_invalid(op1->value.type))
7215 return ira->codegen->builtin_types.entry_invalid;7213 return ira->codegen->builtin_types.entry_invalid;
72167214
7217 IrInstruction *op2 = bin_op_instruction->op2->other;7215 IrInstruction *op2 = bin_op_instruction->op2->other;
7218 if (op2->value.type->id == TypeTableEntryIdInvalid)7216 if (type_is_invalid(op2->value.type))
7219 return ira->codegen->builtin_types.entry_invalid;7217 return ira->codegen->builtin_types.entry_invalid;
72207218
7221 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;7219 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
...@@ -7298,13 +7296,13 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -7298,13 +7296,13 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
72987296
7299 IrInstruction *instructions[] = {op1, op2};7297 IrInstruction *instructions[] = {op1, op2};
7300 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);7298 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);
7301 if (resolved_type->id == TypeTableEntryIdInvalid)7299 if (type_is_invalid(resolved_type))
7302 return resolved_type;7300 return resolved_type;
73037301
7304 AstNode *source_node = bin_op_instruction->base.source_node;7302 AstNode *source_node = bin_op_instruction->base.source_node;
7305 switch (resolved_type->id) {7303 switch (resolved_type->id) {
7306 case TypeTableEntryIdInvalid:7304 case TypeTableEntryIdInvalid:
7307 return ira->codegen->builtin_types.entry_invalid;7305 zig_unreachable(); // handled above
73087306
7309 case TypeTableEntryIdNumLitFloat:7307 case TypeTableEntryIdNumLitFloat:
7310 case TypeTableEntryIdNumLitInt:7308 case TypeTableEntryIdNumLitInt:
...@@ -7532,7 +7530,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -7532,7 +7530,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
7532 IrInstruction *op2 = bin_op_instruction->op2->other;7530 IrInstruction *op2 = bin_op_instruction->op2->other;
7533 IrInstruction *instructions[] = {op1, op2};7531 IrInstruction *instructions[] = {op1, op2};
7534 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);7532 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);
7535 if (resolved_type->id == TypeTableEntryIdInvalid)7533 if (type_is_invalid(resolved_type))
7536 return resolved_type;7534 return resolved_type;
7537 TypeTableEntry *canon_resolved_type = get_underlying_type(resolved_type);7535 TypeTableEntry *canon_resolved_type = get_underlying_type(resolved_type);
7538 IrBinOp op_id = bin_op_instruction->op_id;7536 IrBinOp op_id = bin_op_instruction->op_id;
...@@ -7602,12 +7600,12 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -7602,12 +7600,12 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
7602static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {7600static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
7603 IrInstruction *op1 = instruction->op1->other;7601 IrInstruction *op1 = instruction->op1->other;
7604 TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type);7602 TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type);
7605 if (op1_canon_type->id == TypeTableEntryIdInvalid)7603 if (type_is_invalid(op1_canon_type))
7606 return ira->codegen->builtin_types.entry_invalid;7604 return ira->codegen->builtin_types.entry_invalid;
76077605
7608 IrInstruction *op2 = instruction->op2->other;7606 IrInstruction *op2 = instruction->op2->other;
7609 TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type);7607 TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type);
7610 if (op2_canon_type->id == TypeTableEntryIdInvalid)7608 if (type_is_invalid(op2_canon_type))
7611 return ira->codegen->builtin_types.entry_invalid;7609 return ira->codegen->builtin_types.entry_invalid;
76127610
7613 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);7611 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
...@@ -7741,11 +7739,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -7741,11 +7739,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
77417739
7742static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {7740static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
7743 IrInstruction *op1 = instruction->op1->other;7741 IrInstruction *op1 = instruction->op1->other;
7744 if (op1->value.type->id == TypeTableEntryIdInvalid)7742 if (type_is_invalid(op1->value.type))
7745 return ira->codegen->builtin_types.entry_invalid;7743 return ira->codegen->builtin_types.entry_invalid;
77467744
7747 IrInstruction *op2 = instruction->op2->other;7745 IrInstruction *op2 = instruction->op2->other;
7748 if (op2->value.type->id == TypeTableEntryIdInvalid)7746 if (type_is_invalid(op2->value.type))
7749 return ira->codegen->builtin_types.entry_invalid;7747 return ira->codegen->builtin_types.entry_invalid;
77507748
7751 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);7749 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);
...@@ -7832,7 +7830,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -7832,7 +7830,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
7832 VariableTableEntry *var = decl_var_instruction->var;7830 VariableTableEntry *var = decl_var_instruction->var;
78337831
7834 IrInstruction *init_value = decl_var_instruction->init_value->other;7832 IrInstruction *init_value = decl_var_instruction->init_value->other;
7835 if (init_value->value.type->id == TypeTableEntryIdInvalid) {7833 if (type_is_invalid(init_value->value.type)) {
7836 var->value.type = ira->codegen->builtin_types.entry_invalid;7834 var->value.type = ira->codegen->builtin_types.entry_invalid;
7837 return var->value.type;7835 return var->value.type;
7838 }7836 }
...@@ -7849,7 +7847,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -7849,7 +7847,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
7849 var_type = decl_var_instruction->var_type->other;7847 var_type = decl_var_instruction->var_type->other;
7850 TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type);7848 TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type);
7851 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);7849 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
7852 if (explicit_type->id == TypeTableEntryIdInvalid) {7850 if (type_is_invalid(explicit_type)) {
7853 var->value.type = ira->codegen->builtin_types.entry_invalid;7851 var->value.type = ira->codegen->builtin_types.entry_invalid;
7854 return var->value.type;7852 return var->value.type;
7855 }7853 }
...@@ -7859,12 +7857,15 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -7859,12 +7857,15 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
78597857
7860 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);7858 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);
7861 TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type);7859 TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type);
7860 if (type_is_invalid(result_type)) {
7861 result_type = ira->codegen->builtin_types.entry_invalid;
7862 }
7863
7862 switch (result_type->id) {7864 switch (result_type->id) {
7863 case TypeTableEntryIdTypeDecl:7865 case TypeTableEntryIdTypeDecl:
7864 zig_unreachable();7866 zig_unreachable();
7865 case TypeTableEntryIdInvalid:7867 case TypeTableEntryIdInvalid:
7866 result_type = ira->codegen->builtin_types.entry_invalid;7868 break; // handled above
7867 break;
7868 case TypeTableEntryIdNumLitFloat:7869 case TypeTableEntryIdNumLitFloat:
7869 case TypeTableEntryIdNumLitInt:7870 case TypeTableEntryIdNumLitInt:
7870 if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) {7871 if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) {
...@@ -7912,7 +7913,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -7912,7 +7913,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
7912 var->value.type = result_type;7913 var->value.type = result_type;
7913 assert(var->value.type);7914 assert(var->value.type);
79147915
7915 if (result_type->id == TypeTableEntryIdInvalid) {7916 if (type_is_invalid(result_type)) {
7916 decl_var_instruction->base.other = &decl_var_instruction->base;7917 decl_var_instruction->base.other = &decl_var_instruction->base;
7917 return ira->codegen->builtin_types.entry_void;7918 return ira->codegen->builtin_types.entry_void;
7918 }7919 }
...@@ -7953,11 +7954,11 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -7953,11 +7954,11 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
7953 assert(param_decl_node->type == NodeTypeParamDecl);7954 assert(param_decl_node->type == NodeTypeParamDecl);
7954 AstNode *param_type_node = param_decl_node->data.param_decl.type;7955 AstNode *param_type_node = param_decl_node->data.param_decl.type;
7955 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);7956 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
7956 if (param_type->id == TypeTableEntryIdInvalid)7957 if (type_is_invalid(param_type))
7957 return false;7958 return false;
79587959
7959 IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type);7960 IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type);
7960 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)7961 if (type_is_invalid(casted_arg->value.type))
7961 return false;7962 return false;
79627963
7963 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad);7964 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
...@@ -7989,7 +7990,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -7989,7 +7990,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
7989 } else {7990 } else {
7990 AstNode *param_type_node = param_decl_node->data.param_decl.type;7991 AstNode *param_type_node = param_decl_node->data.param_decl.type;
7991 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);7992 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
7992 if (param_type->id == TypeTableEntryIdInvalid)7993 if (type_is_invalid(param_type))
7993 return false;7994 return false;
79947995
7995 bool is_var_type = (param_type->id == TypeTableEntryIdVar);7996 bool is_var_type = (param_type->id == TypeTableEntryIdVar);
...@@ -7998,7 +7999,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -7998,7 +7999,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
7998 casted_arg = arg;7999 casted_arg = arg;
7999 } else {8000 } else {
8000 casted_arg = ir_implicit_cast(ira, arg, param_type);8001 casted_arg = ir_implicit_cast(ira, arg, param_type);
8001 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)8002 if (type_is_invalid(casted_arg->value.type))
8002 return false;8003 return false;
8003 }8004 }
8004 }8005 }
...@@ -8102,7 +8103,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8102,7 +8103,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8102 first_arg = first_arg_ptr;8103 first_arg = first_arg_ptr;
8103 } else {8104 } else {
8104 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);8105 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
8105 if (first_arg->value.type->id == TypeTableEntryIdInvalid)8106 if (type_is_invalid(first_arg->value.type))
8106 return ira->codegen->builtin_types.entry_invalid;8107 return ira->codegen->builtin_types.entry_invalid;
8107 }8108 }
81088109
...@@ -8112,7 +8113,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8112,7 +8113,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81128113
8113 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {8114 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
8114 IrInstruction *old_arg = call_instruction->args[call_i]->other;8115 IrInstruction *old_arg = call_instruction->args[call_i]->other;
8115 if (old_arg->value.type->id == TypeTableEntryIdInvalid)8116 if (type_is_invalid(old_arg->value.type))
8116 return ira->codegen->builtin_types.entry_invalid;8117 return ira->codegen->builtin_types.entry_invalid;
81178118
8118 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))8119 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
...@@ -8121,7 +8122,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8121,7 +8122,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81218122
8122 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;8123 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
8123 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);8124 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
8124 if (return_type->id == TypeTableEntryIdInvalid)8125 if (type_is_invalid(return_type))
8125 return ira->codegen->builtin_types.entry_invalid;8126 return ira->codegen->builtin_types.entry_invalid;
81268127
8127 IrInstruction *result;8128 IrInstruction *result;
...@@ -8135,7 +8136,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8135,7 +8136,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8135 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,8136 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,
8136 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,8137 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,
8137 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);8138 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);
8138 if (result->value.type->id == TypeTableEntryIdInvalid)8139 if (type_is_invalid(result->value.type))
8139 return ira->codegen->builtin_types.entry_invalid;8140 return ira->codegen->builtin_types.entry_invalid;
81408141
8141 ira->codegen->memoized_fn_eval_table.put(exec_scope, result);8142 ira->codegen->memoized_fn_eval_table.put(exec_scope, result);
...@@ -8178,7 +8179,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8178,7 +8179,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8178 first_arg = first_arg_ptr;8179 first_arg = first_arg_ptr;
8179 } else {8180 } else {
8180 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);8181 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
8181 if (first_arg->value.type->id == TypeTableEntryIdInvalid)8182 if (type_is_invalid(first_arg->value.type))
8182 return ira->codegen->builtin_types.entry_invalid;8183 return ira->codegen->builtin_types.entry_invalid;
8183 }8184 }
81848185
...@@ -8193,7 +8194,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8193,7 +8194,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8193 size_t first_var_arg = inst_fn_type_id.param_count;8194 size_t first_var_arg = inst_fn_type_id.param_count;
8194 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {8195 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
8195 IrInstruction *arg = call_instruction->args[call_i]->other;8196 IrInstruction *arg = call_instruction->args[call_i]->other;
8196 if (arg->value.type->id == TypeTableEntryIdInvalid)8197 if (type_is_invalid(arg->value.type))
8197 return ira->codegen->builtin_types.entry_invalid;8198 return ira->codegen->builtin_types.entry_invalid;
81988199
8199 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);8200 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
...@@ -8224,7 +8225,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8224,7 +8225,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8224 {8225 {
8225 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;8226 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
8226 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);8227 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
8227 if (return_type->id == TypeTableEntryIdInvalid)8228 if (type_is_invalid(return_type))
8228 return ira->codegen->builtin_types.entry_invalid;8229 return ira->codegen->builtin_types.entry_invalid;
8229 inst_fn_type_id.return_type = return_type;8230 inst_fn_type_id.return_type = return_type;
82308231
...@@ -8241,7 +8242,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8241,7 +8242,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8241 } else {8242 } else {
8242 // finish instantiating the function8243 // finish instantiating the function
8243 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);8244 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);
8244 if (impl_fn->type_entry->id == TypeTableEntryIdInvalid)8245 if (type_is_invalid(impl_fn->type_entry))
8245 return ira->codegen->builtin_types.entry_invalid;8246 return ira->codegen->builtin_types.entry_invalid;
82468247
8247 impl_fn->ir_executable.source_node = call_instruction->base.source_node;8248 impl_fn->ir_executable.source_node = call_instruction->base.source_node;
...@@ -8272,16 +8273,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8272,16 +8273,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8272 first_arg = first_arg_ptr;8273 first_arg = first_arg_ptr;
8273 } else {8274 } else {
8274 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);8275 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
8275 if (first_arg->value.type->id == TypeTableEntryIdInvalid)8276 if (type_is_invalid(first_arg->value.type))
8276 return ira->codegen->builtin_types.entry_invalid;8277 return ira->codegen->builtin_types.entry_invalid;
8277 }8278 }
82788279
8279 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;8280 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
8280 if (param_type->id == TypeTableEntryIdInvalid)8281 if (type_is_invalid(param_type))
8281 return ira->codegen->builtin_types.entry_invalid;8282 return ira->codegen->builtin_types.entry_invalid;
82828283
8283 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);8284 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
8284 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)8285 if (type_is_invalid(casted_arg->value.type))
8285 return ira->codegen->builtin_types.entry_invalid;8286 return ira->codegen->builtin_types.entry_invalid;
82868287
8287 casted_args[next_arg_index] = casted_arg;8288 casted_args[next_arg_index] = casted_arg;
...@@ -8289,15 +8290,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8289,15 +8290,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8289 }8290 }
8290 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {8291 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
8291 IrInstruction *old_arg = call_instruction->args[call_i]->other;8292 IrInstruction *old_arg = call_instruction->args[call_i]->other;
8292 if (old_arg->value.type->id == TypeTableEntryIdInvalid)8293 if (type_is_invalid(old_arg->value.type))
8293 return ira->codegen->builtin_types.entry_invalid;8294 return ira->codegen->builtin_types.entry_invalid;
8294 IrInstruction *casted_arg;8295 IrInstruction *casted_arg;
8295 if (next_arg_index < src_param_count) {8296 if (next_arg_index < src_param_count) {
8296 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;8297 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
8297 if (param_type->id == TypeTableEntryIdInvalid)8298 if (type_is_invalid(param_type))
8298 return ira->codegen->builtin_types.entry_invalid;8299 return ira->codegen->builtin_types.entry_invalid;
8299 casted_arg = ir_implicit_cast(ira, old_arg, param_type);8300 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
8300 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)8301 if (type_is_invalid(casted_arg->value.type))
8301 return ira->codegen->builtin_types.entry_invalid;8302 return ira->codegen->builtin_types.entry_invalid;
8302 } else {8303 } else {
8303 casted_arg = old_arg;8304 casted_arg = old_arg;
...@@ -8310,7 +8311,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8310,7 +8311,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8310 assert(next_arg_index == call_param_count);8311 assert(next_arg_index == call_param_count);
83118312
8312 TypeTableEntry *return_type = fn_type_id->return_type;8313 TypeTableEntry *return_type = fn_type_id->return_type;
8313 if (return_type->id == TypeTableEntryIdInvalid)8314 if (type_is_invalid(return_type))
8314 return ira->codegen->builtin_types.entry_invalid;8315 return ira->codegen->builtin_types.entry_invalid;
83158316
8316 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,8317 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
...@@ -8322,7 +8323,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8322,7 +8323,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
83228323
8323static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {8324static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
8324 IrInstruction *fn_ref = call_instruction->fn_ref->other;8325 IrInstruction *fn_ref = call_instruction->fn_ref->other;
8325 if (fn_ref->value.type->id == TypeTableEntryIdInvalid)8326 if (type_is_invalid(fn_ref->value.type))
8326 return ira->codegen->builtin_types.entry_invalid;8327 return ira->codegen->builtin_types.entry_invalid;
83278328
8328 bool is_inline = call_instruction->is_comptime ||8329 bool is_inline = call_instruction->is_comptime ||
...@@ -8331,7 +8332,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -8331,7 +8332,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
8331 if (is_inline || instr_is_comptime(fn_ref)) {8332 if (is_inline || instr_is_comptime(fn_ref)) {
8332 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {8333 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {
8333 TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);8334 TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);
8334 if (dest_type->id == TypeTableEntryIdInvalid)8335 if (type_is_invalid(dest_type))
8335 return ira->codegen->builtin_types.entry_invalid;8336 return ira->codegen->builtin_types.entry_invalid;
83368337
8337 size_t actual_param_count = call_instruction->arg_count;8338 size_t actual_param_count = call_instruction->arg_count;
...@@ -8345,7 +8346,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -8345,7 +8346,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
8345 IrInstruction *arg = call_instruction->args[0]->other;8346 IrInstruction *arg = call_instruction->args[0]->other;
83468347
8347 IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg);8348 IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg);
8348 if (cast_instruction->value.type->id == TypeTableEntryIdInvalid)8349 if (type_is_invalid(cast_instruction->value.type))
8349 return ira->codegen->builtin_types.entry_invalid;8350 return ira->codegen->builtin_types.entry_invalid;
83508351
8351 ir_link_new_instruction(cast_instruction, &call_instruction->base);8352 ir_link_new_instruction(cast_instruction, &call_instruction->base);
...@@ -8383,11 +8384,16 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct...@@ -8383,11 +8384,16 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
83838384
8384 TypeTableEntry *meta_type = ir_resolve_type(ira, value);8385 TypeTableEntry *meta_type = ir_resolve_type(ira, value);
8385 TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type);8386 TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type);
8387
8388 if (type_is_invalid(underlying_meta_type))
8389 return ira->codegen->builtin_types.entry_invalid;
8390
8391
8386 switch (underlying_meta_type->id) {8392 switch (underlying_meta_type->id) {
8387 case TypeTableEntryIdTypeDecl:8393 case TypeTableEntryIdTypeDecl:
8394 case TypeTableEntryIdInvalid: // handled above
8388 zig_unreachable();8395 zig_unreachable();
8389 case TypeTableEntryIdInvalid:8396
8390 return ira->codegen->builtin_types.entry_invalid;
8391 case TypeTableEntryIdVoid:8397 case TypeTableEntryIdVoid:
8392 case TypeTableEntryIdBool:8398 case TypeTableEntryIdBool:
8393 case TypeTableEntryIdInt:8399 case TypeTableEntryIdInt:
...@@ -8433,7 +8439,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp...@@ -8433,7 +8439,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
84338439
8434 TypeTableEntry *ptr_type = value->value.type;8440 TypeTableEntry *ptr_type = value->value.type;
8435 TypeTableEntry *child_type;8441 TypeTableEntry *child_type;
8436 if (ptr_type->id == TypeTableEntryIdInvalid) {8442 if (type_is_invalid(ptr_type)) {
8437 return ira->codegen->builtin_types.entry_invalid;8443 return ira->codegen->builtin_types.entry_invalid;
8438 } else if (ptr_type->id == TypeTableEntryIdPointer) {8444 } else if (ptr_type->id == TypeTableEntryIdPointer) {
8439 child_type = ptr_type->data.pointer.child_type;8445 child_type = ptr_type->data.pointer.child_type;
...@@ -8509,7 +8515,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -8509,7 +8515,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
8509static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {8515static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
8510 IrInstruction *value = un_op_instruction->value->other;8516 IrInstruction *value = un_op_instruction->value->other;
8511 TypeTableEntry *expr_type = value->value.type;8517 TypeTableEntry *expr_type = value->value.type;
8512 if (expr_type->id == TypeTableEntryIdInvalid)8518 if (type_is_invalid(expr_type))
8513 return ira->codegen->builtin_types.entry_invalid;8519 return ira->codegen->builtin_types.entry_invalid;
85148520
8515 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);8521 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);
...@@ -8555,7 +8561,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un...@@ -8555,7 +8561,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
8555static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {8561static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
8556 IrInstruction *value = instruction->value->other;8562 IrInstruction *value = instruction->value->other;
8557 TypeTableEntry *expr_type = value->value.type;8563 TypeTableEntry *expr_type = value->value.type;
8558 if (expr_type->id == TypeTableEntryIdInvalid)8564 if (type_is_invalid(expr_type))
8559 return ira->codegen->builtin_types.entry_invalid;8565 return ira->codegen->builtin_types.entry_invalid;
85608566
8561 if (expr_type->id == TypeTableEntryIdInt) {8567 if (expr_type->id == TypeTableEntryIdInt) {
...@@ -8616,7 +8622,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr...@@ -8616,7 +8622,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
86168622
8617static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {8623static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
8618 IrInstruction *condition = cond_br_instruction->condition->other;8624 IrInstruction *condition = cond_br_instruction->condition->other;
8619 if (condition->value.type->id == TypeTableEntryIdInvalid)8625 if (type_is_invalid(condition->value.type))
8620 return ir_unreach_error(ira);8626 return ir_unreach_error(ira);
86218627
8622 bool is_comptime;8628 bool is_comptime;
...@@ -8667,7 +8673,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8667,7 +8673,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
8667 continue;8673 continue;
8668 IrInstruction *value = phi_instruction->incoming_values[i]->other;8674 IrInstruction *value = phi_instruction->incoming_values[i]->other;
8669 assert(value->value.type);8675 assert(value->value.type);
8670 if (value->value.type->id == TypeTableEntryIdInvalid)8676 if (type_is_invalid(value->value.type))
8671 return ira->codegen->builtin_types.entry_invalid;8677 return ira->codegen->builtin_types.entry_invalid;
86728678
8673 if (value->value.special != ConstValSpecialRuntime) {8679 if (value->value.special != ConstValSpecialRuntime) {
...@@ -8696,7 +8702,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8696,7 +8702,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
8696 if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable)8702 if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable)
8697 continue;8703 continue;
86988704
8699 if (new_value->value.type->id == TypeTableEntryIdInvalid)8705 if (type_is_invalid(new_value->value.type))
8700 return ira->codegen->builtin_types.entry_invalid;8706 return ira->codegen->builtin_types.entry_invalid;
87018707
87028708
...@@ -8718,7 +8724,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8718,7 +8724,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
87188724
8719 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node,8725 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node,
8720 new_incoming_values.items, new_incoming_values.length);8726 new_incoming_values.items, new_incoming_values.length);
8721 if (resolved_type->id == TypeTableEntryIdInvalid)8727 if (type_is_invalid(resolved_type))
8722 return resolved_type;8728 return resolved_type;
87238729
8724 if (resolved_type->id == TypeTableEntryIdNumLitFloat ||8730 if (resolved_type->id == TypeTableEntryIdNumLitFloat ||
...@@ -8756,7 +8762,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc...@@ -8756,7 +8762,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
8756 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)8762 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
8757{8763{
8758 assert(var->value.type);8764 assert(var->value.type);
8759 if (var->value.type->id == TypeTableEntryIdInvalid)8765 if (type_is_invalid(var->value.type))
8760 return var->value.type;8766 return var->value.type;
87618767
8762 bool comptime_var_mem = ir_get_var_is_comptime(var);8768 bool comptime_var_mem = ir_get_var_is_comptime(var);
...@@ -8816,11 +8822,11 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in...@@ -8816,11 +8822,11 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
88168822
8817static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {8823static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
8818 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;8824 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
8819 if (array_ptr->value.type->id == TypeTableEntryIdInvalid)8825 if (type_is_invalid(array_ptr->value.type))
8820 return ira->codegen->builtin_types.entry_invalid;8826 return ira->codegen->builtin_types.entry_invalid;
88218827
8822 IrInstruction *elem_index = elem_ptr_instruction->elem_index->other;8828 IrInstruction *elem_index = elem_ptr_instruction->elem_index->other;
8823 if (elem_index->value.type->id == TypeTableEntryIdInvalid)8829 if (type_is_invalid(elem_index->value.type))
8824 return ira->codegen->builtin_types.entry_invalid;8830 return ira->codegen->builtin_types.entry_invalid;
88258831
8826 // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing.8832 // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing.
...@@ -8830,7 +8836,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -8830,7 +8836,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
8830 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;8836 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
8831 TypeTableEntry *return_type;8837 TypeTableEntry *return_type;
88328838
8833 if (array_type->id == TypeTableEntryIdInvalid) {8839 if (type_is_invalid(array_type)) {
8834 return array_type;8840 return array_type;
8835 } else if (array_type->id == TypeTableEntryIdArray) {8841 } else if (array_type->id == TypeTableEntryIdArray) {
8836 if (array_type->data.array.len == 0) {8842 if (array_type->data.array.len == 0) {
...@@ -9019,7 +9025,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -9019,7 +9025,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
9019 return ira->codegen->builtin_types.entry_invalid;9025 return ira->codegen->builtin_types.entry_invalid;
9020 TldFn *tld_fn = (TldFn *)tld;9026 TldFn *tld_fn = (TldFn *)tld;
9021 FnTableEntry *fn_entry = tld_fn->fn_entry;9027 FnTableEntry *fn_entry = tld_fn->fn_entry;
9022 if (fn_entry->type_entry->id == TypeTableEntryIdInvalid)9028 if (type_is_invalid(fn_entry->type_entry))
9023 return ira->codegen->builtin_types.entry_invalid;9029 return ira->codegen->builtin_types.entry_invalid;
90249030
9025 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope,9031 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope,
...@@ -9113,7 +9119,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -9113,7 +9119,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
9113 FnTableEntry *fn_entry = tld_fn->fn_entry;9119 FnTableEntry *fn_entry = tld_fn->fn_entry;
9114 assert(fn_entry->type_entry);9120 assert(fn_entry->type_entry);
91159121
9116 if (fn_entry->type_entry->id == TypeTableEntryIdInvalid)9122 if (type_is_invalid(fn_entry->type_entry))
9117 return ira->codegen->builtin_types.entry_invalid;9123 return ira->codegen->builtin_types.entry_invalid;
91189124
9119 // TODO instead of allocating this every time, put it in the tld value and we can reference9125 // TODO instead of allocating this every time, put it in the tld value and we can reference
...@@ -9151,7 +9157,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -9151,7 +9157,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
91519157
9152static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {9158static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
9153 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;9159 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;
9154 if (container_ptr->value.type->id == TypeTableEntryIdInvalid)9160 if (type_is_invalid(container_ptr->value.type))
9155 return ira->codegen->builtin_types.entry_invalid;9161 return ira->codegen->builtin_types.entry_invalid;
91569162
9157 TypeTableEntry *container_type;9163 TypeTableEntry *container_type;
...@@ -9166,7 +9172,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9166,7 +9172,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9166 Buf *field_name = field_ptr_instruction->field_name;9172 Buf *field_name = field_ptr_instruction->field_name;
9167 AstNode *source_node = field_ptr_instruction->base.source_node;9173 AstNode *source_node = field_ptr_instruction->base.source_node;
91689174
9169 if (container_type->id == TypeTableEntryIdInvalid) {9175 if (type_is_invalid(container_type)) {
9170 return container_type;9176 return container_type;
9171 } else if (is_container_ref(container_type)) {9177 } else if (is_container_ref(container_type)) {
9172 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);9178 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
...@@ -9234,7 +9240,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9234,7 +9240,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
9234 zig_unreachable();9240 zig_unreachable();
9235 }9241 }
92369242
9237 if (child_type->id == TypeTableEntryIdInvalid) {9243 if (type_is_invalid(child_type)) {
9238 return ira->codegen->builtin_types.entry_invalid;9244 return ira->codegen->builtin_types.entry_invalid;
9239 } else if (is_container(child_type)) {9245 } else if (is_container(child_type)) {
9240 if (child_type->id == TypeTableEntryIdEnum) {9246 if (child_type->id == TypeTableEntryIdEnum) {
...@@ -9371,11 +9377,11 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc...@@ -9371,11 +9377,11 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc
93719377
9372static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {9378static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
9373 IrInstruction *ptr = store_ptr_instruction->ptr->other;9379 IrInstruction *ptr = store_ptr_instruction->ptr->other;
9374 if (ptr->value.type->id == TypeTableEntryIdInvalid)9380 if (type_is_invalid(ptr->value.type))
9375 return ptr->value.type;9381 return ptr->value.type;
93769382
9377 IrInstruction *value = store_ptr_instruction->value->other;9383 IrInstruction *value = store_ptr_instruction->value->other;
9378 if (value->value.type->id == TypeTableEntryIdInvalid)9384 if (type_is_invalid(value->value.type))
9379 return value->value.type;9385 return value->value.type;
93809386
9381 assert(ptr->value.type->id == TypeTableEntryIdPointer);9387 assert(ptr->value.type->id == TypeTableEntryIdPointer);
...@@ -9412,9 +9418,11 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -9412,9 +9418,11 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
9412static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {9418static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
9413 IrInstruction *expr_value = typeof_instruction->value->other;9419 IrInstruction *expr_value = typeof_instruction->value->other;
9414 TypeTableEntry *type_entry = expr_value->value.type;9420 TypeTableEntry *type_entry = expr_value->value.type;
9421 if (type_is_invalid(type_entry))
9422 return ira->codegen->builtin_types.entry_invalid;
9415 switch (type_entry->id) {9423 switch (type_entry->id) {
9416 case TypeTableEntryIdInvalid:9424 case TypeTableEntryIdInvalid:
9417 return type_entry;9425 zig_unreachable(); // handled above
9418 case TypeTableEntryIdVar:9426 case TypeTableEntryIdVar:
9419 ir_add_error_node(ira, expr_value->source_node,9427 ir_add_error_node(ira, expr_value->source_node,
9420 buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name)));9428 buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name)));
...@@ -9460,7 +9468,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,...@@ -9460,7 +9468,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
9460{9468{
9461 IrInstruction *value = to_ptr_type_instruction->value->other;9469 IrInstruction *value = to_ptr_type_instruction->value->other;
9462 TypeTableEntry *type_entry = value->value.type;9470 TypeTableEntry *type_entry = value->value.type;
9463 if (type_entry->id == TypeTableEntryIdInvalid)9471 if (type_is_invalid(type_entry))
9464 return type_entry;9472 return type_entry;
94659473
9466 TypeTableEntry *ptr_type;9474 TypeTableEntry *ptr_type;
...@@ -9489,7 +9497,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -9489,7 +9497,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
9489{9497{
9490 IrInstruction *type_value = ptr_type_child_instruction->value->other;9498 IrInstruction *type_value = ptr_type_child_instruction->value->other;
9491 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);9499 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
9492 if (type_entry->id == TypeTableEntryIdInvalid)9500 if (type_is_invalid(type_entry))
9493 return type_entry;9501 return type_entry;
94949502
9495 // TODO handle typedefs9503 // TODO handle typedefs
...@@ -9651,7 +9659,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -9651,7 +9659,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
9651{9659{
9652 IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other;9660 IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other;
9653 TypeTableEntry *target_type = target_instruction->value.type;9661 TypeTableEntry *target_type = target_instruction->value.type;
9654 if (target_type->id == TypeTableEntryIdInvalid)9662 if (type_is_invalid(target_type))
9655 return ira->codegen->builtin_types.entry_invalid;9663 return ira->codegen->builtin_types.entry_invalid;
9656 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);9664 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
9657 if (!target_val)9665 if (!target_val)
...@@ -9719,17 +9727,19 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -9719,17 +9727,19 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
9719 IrInstructionSliceType *slice_type_instruction)9727 IrInstructionSliceType *slice_type_instruction)
9720{9728{
9721 IrInstruction *child_type = slice_type_instruction->child_type->other;9729 IrInstruction *child_type = slice_type_instruction->child_type->other;
9722 if (child_type->value.type->id == TypeTableEntryIdInvalid)9730 if (type_is_invalid(child_type->value.type))
9723 return ira->codegen->builtin_types.entry_invalid;9731 return ira->codegen->builtin_types.entry_invalid;
9724 bool is_const = slice_type_instruction->is_const;9732 bool is_const = slice_type_instruction->is_const;
97259733
9726 TypeTableEntry *resolved_child_type = ir_resolve_type(ira, child_type);9734 TypeTableEntry *resolved_child_type = ir_resolve_type(ira, child_type);
9727 TypeTableEntry *canon_child_type = get_underlying_type(resolved_child_type);9735 TypeTableEntry *canon_child_type = get_underlying_type(resolved_child_type);
9736 if (type_is_invalid(canon_child_type))
9737 return ira->codegen->builtin_types.entry_invalid;
9738
9728 switch (canon_child_type->id) {9739 switch (canon_child_type->id) {
9729 case TypeTableEntryIdTypeDecl:9740 case TypeTableEntryIdTypeDecl:
9741 case TypeTableEntryIdInvalid: // handled above
9730 zig_unreachable();9742 zig_unreachable();
9731 case TypeTableEntryIdInvalid:
9732 return ira->codegen->builtin_types.entry_invalid;
9733 case TypeTableEntryIdVar:9743 case TypeTableEntryIdVar:
9734 case TypeTableEntryIdUnreachable:9744 case TypeTableEntryIdUnreachable:
9735 case TypeTableEntryIdUndefLit:9745 case TypeTableEntryIdUndefLit:
...@@ -9789,14 +9799,14 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA...@@ -9789,14 +9799,14 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
9789 if (asm_output->return_type) {9799 if (asm_output->return_type) {
9790 output_types[i] = asm_instruction->output_types[i]->other;9800 output_types[i] = asm_instruction->output_types[i]->other;
9791 return_type = ir_resolve_type(ira, output_types[i]);9801 return_type = ir_resolve_type(ira, output_types[i]);
9792 if (return_type->id == TypeTableEntryIdInvalid)9802 if (type_is_invalid(return_type))
9793 return ira->codegen->builtin_types.entry_invalid;9803 return ira->codegen->builtin_types.entry_invalid;
9794 }9804 }
9795 }9805 }
97969806
9797 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {9807 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
9798 input_list[i] = asm_instruction->input_list[i]->other;9808 input_list[i] = asm_instruction->input_list[i]->other;
9799 if (input_list[i]->value.type->id == TypeTableEntryIdInvalid)9809 if (type_is_invalid(input_list[i]->value.type))
9800 return ira->codegen->builtin_types.entry_invalid;9810 return ira->codegen->builtin_types.entry_invalid;
9801 }9811 }
98029812
...@@ -9816,11 +9826,12 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -9816,11 +9826,12 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
9816 IrInstruction *child_type_value = array_type_instruction->child_type->other;9826 IrInstruction *child_type_value = array_type_instruction->child_type->other;
9817 TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value);9827 TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value);
9818 TypeTableEntry *canon_child_type = get_underlying_type(child_type);9828 TypeTableEntry *canon_child_type = get_underlying_type(child_type);
9829 if (type_is_invalid(canon_child_type))
9830 return ira->codegen->builtin_types.entry_invalid;
9819 switch (canon_child_type->id) {9831 switch (canon_child_type->id) {
9820 case TypeTableEntryIdTypeDecl:9832 case TypeTableEntryIdTypeDecl:
9833 case TypeTableEntryIdInvalid: // handled above
9821 zig_unreachable();9834 zig_unreachable();
9822 case TypeTableEntryIdInvalid:
9823 return ira->codegen->builtin_types.entry_invalid;
9824 case TypeTableEntryIdVar:9835 case TypeTableEntryIdVar:
9825 case TypeTableEntryIdUnreachable:9836 case TypeTableEntryIdUnreachable:
9826 case TypeTableEntryIdUndefLit:9837 case TypeTableEntryIdUndefLit:
...@@ -9906,10 +9917,11 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -9906,10 +9917,11 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
9906 TypeTableEntry *canon_type_entry = get_underlying_type(type_entry);9917 TypeTableEntry *canon_type_entry = get_underlying_type(type_entry);
99079918
9908 ensure_complete_type(ira->codegen, type_entry);9919 ensure_complete_type(ira->codegen, type_entry);
9920 if (type_is_invalid(canon_type_entry))
9921 return ira->codegen->builtin_types.entry_invalid;
99099922
9910 switch (canon_type_entry->id) {9923 switch (canon_type_entry->id) {
9911 case TypeTableEntryIdInvalid:9924 case TypeTableEntryIdInvalid: // handled above
9912 return ira->codegen->builtin_types.entry_invalid;
9913 case TypeTableEntryIdTypeDecl:9925 case TypeTableEntryIdTypeDecl:
9914 zig_unreachable();9926 zig_unreachable();
9915 case TypeTableEntryIdVar:9927 case TypeTableEntryIdVar:
...@@ -9953,7 +9965,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -9953,7 +9965,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
99539965
9954static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {9966static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
9955 IrInstruction *value = instruction->value->other;9967 IrInstruction *value = instruction->value->other;
9956 if (value->value.type->id == TypeTableEntryIdInvalid)9968 if (type_is_invalid(value->value.type))
9957 return ira->codegen->builtin_types.entry_invalid;9969 return ira->codegen->builtin_types.entry_invalid;
99589970
9959 TypeTableEntry *type_entry = value->value.type;9971 TypeTableEntry *type_entry = value->value.type;
...@@ -9986,7 +9998,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -9986,7 +9998,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
9986 IrInstructionUnwrapMaybe *unwrap_maybe_instruction)9998 IrInstructionUnwrapMaybe *unwrap_maybe_instruction)
9987{9999{
9988 IrInstruction *value = unwrap_maybe_instruction->value->other;10000 IrInstruction *value = unwrap_maybe_instruction->value->other;
9989 if (value->value.type->id == TypeTableEntryIdInvalid)10001 if (type_is_invalid(value->value.type))
9990 return ira->codegen->builtin_types.entry_invalid;10002 return ira->codegen->builtin_types.entry_invalid;
999110003
9992 TypeTableEntry *ptr_type = value->value.type;10004 TypeTableEntry *ptr_type = value->value.type;
...@@ -10010,7 +10022,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -10010,7 +10022,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1001010022
10011 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;10023 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
10012 // TODO handle typedef10024 // TODO handle typedef
10013 if (type_entry->id == TypeTableEntryIdInvalid) {10025 if (type_is_invalid(type_entry)) {
10014 return ira->codegen->builtin_types.entry_invalid;10026 return ira->codegen->builtin_types.entry_invalid;
10015 } else if (type_entry->id != TypeTableEntryIdMaybe) {10027 } else if (type_entry->id != TypeTableEntryIdMaybe) {
10016 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,10028 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
...@@ -10047,7 +10059,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -10047,7 +10059,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1004710059
10048static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {10060static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
10049 IrInstruction *value = ctz_instruction->value->other;10061 IrInstruction *value = ctz_instruction->value->other;
10050 if (value->value.type->id == TypeTableEntryIdInvalid) {10062 if (type_is_invalid(value->value.type)) {
10051 return ira->codegen->builtin_types.entry_invalid;10063 return ira->codegen->builtin_types.entry_invalid;
10052 } else if (value->value.type->id == TypeTableEntryIdInt) {10064 } else if (value->value.type->id == TypeTableEntryIdInt) {
10053 if (value->value.special != ConstValSpecialRuntime) {10065 if (value->value.special != ConstValSpecialRuntime) {
...@@ -10069,7 +10081,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC...@@ -10069,7 +10081,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
1006910081
10070static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {10082static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
10071 IrInstruction *value = clz_instruction->value->other;10083 IrInstruction *value = clz_instruction->value->other;
10072 if (value->value.type->id == TypeTableEntryIdInvalid) {10084 if (type_is_invalid(value->value.type)) {
10073 return ira->codegen->builtin_types.entry_invalid;10085 return ira->codegen->builtin_types.entry_invalid;
10074 } else if (value->value.type->id == TypeTableEntryIdInt) {10086 } else if (value->value.type->id == TypeTableEntryIdInt) {
10075 if (value->value.special != ConstValSpecialRuntime) {10087 if (value->value.special != ConstValSpecialRuntime) {
...@@ -10090,7 +10102,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC...@@ -10090,7 +10102,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
10090}10102}
1009110103
10092static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {10104static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {
10093 if (value->value.type->id == TypeTableEntryIdInvalid)10105 if (type_is_invalid(value->value.type))
10094 return ira->codegen->invalid_instruction;10106 return ira->codegen->invalid_instruction;
1009510107
10096 if (value->value.type->id != TypeTableEntryIdEnum) {10108 if (value->value.type->id != TypeTableEntryIdEnum) {
...@@ -10119,7 +10131,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -10119,7 +10131,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
10119 IrInstructionSwitchBr *switch_br_instruction)10131 IrInstructionSwitchBr *switch_br_instruction)
10120{10132{
10121 IrInstruction *target_value = switch_br_instruction->target_value->other;10133 IrInstruction *target_value = switch_br_instruction->target_value->other;
10122 if (target_value->value.type->id == TypeTableEntryIdInvalid)10134 if (type_is_invalid(target_value->value.type))
10123 return ir_unreach_error(ira);10135 return ir_unreach_error(ira);
1012410136
10125 size_t case_count = switch_br_instruction->case_count;10137 size_t case_count = switch_br_instruction->case_count;
...@@ -10137,17 +10149,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -10137,17 +10149,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
10137 for (size_t i = 0; i < case_count; i += 1) {10149 for (size_t i = 0; i < case_count; i += 1) {
10138 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];10150 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
10139 IrInstruction *case_value = old_case->value->other;10151 IrInstruction *case_value = old_case->value->other;
10140 if (case_value->value.type->id == TypeTableEntryIdInvalid)10152 if (type_is_invalid(case_value->value.type))
10141 return ir_unreach_error(ira);10153 return ir_unreach_error(ira);
1014210154
10143 if (case_value->value.type->id == TypeTableEntryIdEnum) {10155 if (case_value->value.type->id == TypeTableEntryIdEnum) {
10144 case_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, case_value);10156 case_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, case_value);
10145 if (case_value->value.type->id == TypeTableEntryIdInvalid)10157 if (type_is_invalid(case_value->value.type))
10146 return ir_unreach_error(ira);10158 return ir_unreach_error(ira);
10147 }10159 }
1014810160
10149 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);10161 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);
10150 if (casted_case_value->value.type->id == TypeTableEntryIdInvalid)10162 if (type_is_invalid(casted_case_value->value.type))
10151 return ir_unreach_error(ira);10163 return ir_unreach_error(ira);
1015210164
10153 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);10165 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);
...@@ -10184,17 +10196,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -10184,17 +10196,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1018410196
10185 IrInstruction *old_value = old_case->value;10197 IrInstruction *old_value = old_case->value;
10186 IrInstruction *new_value = old_value->other;10198 IrInstruction *new_value = old_value->other;
10187 if (new_value->value.type->id == TypeTableEntryIdInvalid)10199 if (type_is_invalid(new_value->value.type))
10188 continue;10200 continue;
1018910201
10190 if (new_value->value.type->id == TypeTableEntryIdEnum) {10202 if (new_value->value.type->id == TypeTableEntryIdEnum) {
10191 new_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, new_value);10203 new_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, new_value);
10192 if (new_value->value.type->id == TypeTableEntryIdInvalid)10204 if (type_is_invalid(new_value->value.type))
10193 continue;10205 continue;
10194 }10206 }
1019510207
10196 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);10208 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);
10197 if (casted_new_value->value.type->id == TypeTableEntryIdInvalid)10209 if (type_is_invalid(casted_new_value->value.type))
10198 continue;10210 continue;
1019910211
10200 if (!ir_resolve_const(ira, casted_new_value, UndefBad))10212 if (!ir_resolve_const(ira, casted_new_value, UndefBad))
...@@ -10218,7 +10230,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -10218,7 +10230,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
10218 IrInstructionSwitchTarget *switch_target_instruction)10230 IrInstructionSwitchTarget *switch_target_instruction)
10219{10231{
10220 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->other;10232 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->other;
10221 if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid)10233 if (type_is_invalid(target_value_ptr->value.type))
10222 return ira->codegen->builtin_types.entry_invalid;10234 return ira->codegen->builtin_types.entry_invalid;
1022310235
10224 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);10236 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
...@@ -10231,6 +10243,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -10231,6 +10243,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
10231 }10243 }
10232 TypeTableEntry *canon_target_type = get_underlying_type(target_type);10244 TypeTableEntry *canon_target_type = get_underlying_type(target_type);
10233 ensure_complete_type(ira->codegen, target_type);10245 ensure_complete_type(ira->codegen, target_type);
10246 if (type_is_invalid(canon_target_type))
10247 return ira->codegen->builtin_types.entry_invalid;
1023410248
10235 switch (canon_target_type->id) {10249 switch (canon_target_type->id) {
10236 case TypeTableEntryIdInvalid:10250 case TypeTableEntryIdInvalid:
...@@ -10297,11 +10311,11 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -10297,11 +10311,11 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1029710311
10298static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {10312static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
10299 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;10313 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;
10300 if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid)10314 if (type_is_invalid(target_value_ptr->value.type))
10301 return ira->codegen->builtin_types.entry_invalid;10315 return ira->codegen->builtin_types.entry_invalid;
1030210316
10303 IrInstruction *prong_value = instruction->prong_value->other;10317 IrInstruction *prong_value = instruction->prong_value->other;
10304 if (prong_value->value.type->id == TypeTableEntryIdInvalid)10318 if (type_is_invalid(prong_value->value.type))
10305 return ira->codegen->builtin_types.entry_invalid;10319 return ira->codegen->builtin_types.entry_invalid;
1030610320
10307 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);10321 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
...@@ -10357,7 +10371,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc...@@ -10357,7 +10371,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc
1035710371
10358static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrInstructionGeneratedCode *instruction) {10372static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrInstructionGeneratedCode *instruction) {
10359 IrInstruction *value = instruction->value->other;10373 IrInstruction *value = instruction->value->other;
10360 if (value->value.type->id == TypeTableEntryIdInvalid)10374 if (type_is_invalid(value->value.type))
10361 return ira->codegen->builtin_types.entry_invalid;10375 return ira->codegen->builtin_types.entry_invalid;
1036210376
10363 if (instr_is_comptime(value)) {10377 if (instr_is_comptime(value)) {
...@@ -10452,7 +10466,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,...@@ -10452,7 +10466,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
10452{10466{
10453 IrInstruction *array_value = array_len_instruction->array_value->other;10467 IrInstruction *array_value = array_len_instruction->array_value->other;
10454 TypeTableEntry *canon_type = get_underlying_type(array_value->value.type);10468 TypeTableEntry *canon_type = get_underlying_type(array_value->value.type);
10455 if (canon_type->id == TypeTableEntryIdInvalid) {10469 if (type_is_invalid(canon_type)) {
10456 return ira->codegen->builtin_types.entry_invalid;10470 return ira->codegen->builtin_types.entry_invalid;
10457 } else if (canon_type->id == TypeTableEntryIdArray) {10471 } else if (canon_type->id == TypeTableEntryIdArray) {
10458 return ir_analyze_const_usize(ira, &array_len_instruction->base,10472 return ir_analyze_const_usize(ira, &array_len_instruction->base,
...@@ -10515,7 +10529,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -10515,7 +10529,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
10515 IrInstructionContainerInitFieldsField *field = &fields[i];10529 IrInstructionContainerInitFieldsField *field = &fields[i];
1051610530
10517 IrInstruction *field_value = field->value->other;10531 IrInstruction *field_value = field->value->other;
10518 if (field_value->value.type->id == TypeTableEntryIdInvalid)10532 if (type_is_invalid(field_value->value.type))
10519 return ira->codegen->builtin_types.entry_invalid;10533 return ira->codegen->builtin_types.entry_invalid;
1052010534
10521 TypeStructField *type_field = find_struct_type_field(container_type, field->name);10535 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
...@@ -10526,7 +10540,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -10526,7 +10540,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
10526 return ira->codegen->builtin_types.entry_invalid;10540 return ira->codegen->builtin_types.entry_invalid;
10527 }10541 }
1052810542
10529 if (type_field->type_entry->id == TypeTableEntryIdInvalid)10543 if (type_is_invalid(type_field->type_entry))
10530 return ira->codegen->builtin_types.entry_invalid;10544 return ira->codegen->builtin_types.entry_invalid;
1053110545
10532 IrInstruction *casted_field_value = ir_implicit_cast(ira, field_value, type_field->type_entry);10546 IrInstruction *casted_field_value = ir_implicit_cast(ira, field_value, type_field->type_entry);
...@@ -10593,13 +10607,13 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10593,13 +10607,13 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
10593 IrInstructionContainerInitList *instruction)10607 IrInstructionContainerInitList *instruction)
10594{10608{
10595 IrInstruction *container_type_value = instruction->container_type->other;10609 IrInstruction *container_type_value = instruction->container_type->other;
10596 if (container_type_value->value.type->id == TypeTableEntryIdInvalid)10610 if (type_is_invalid(container_type_value->value.type))
10597 return ira->codegen->builtin_types.entry_invalid;10611 return ira->codegen->builtin_types.entry_invalid;
1059810612
10599 size_t elem_count = instruction->item_count;10613 size_t elem_count = instruction->item_count;
10600 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {10614 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {
10601 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);10615 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
10602 if (container_type->id == TypeTableEntryIdInvalid)10616 if (type_is_invalid(container_type))
10603 return ira->codegen->builtin_types.entry_invalid;10617 return ira->codegen->builtin_types.entry_invalid;
1060410618
10605 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {10619 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {
...@@ -10624,7 +10638,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -10624,7 +10638,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1062410638
10625 for (size_t i = 0; i < elem_count; i += 1) {10639 for (size_t i = 0; i < elem_count; i += 1) {
10626 IrInstruction *arg_value = instruction->items[i]->other;10640 IrInstruction *arg_value = instruction->items[i]->other;
10627 if (arg_value->value.type->id == TypeTableEntryIdInvalid)10641 if (type_is_invalid(arg_value->value.type))
10628 return ira->codegen->builtin_types.entry_invalid;10642 return ira->codegen->builtin_types.entry_invalid;
1062910643
10630 IrInstruction *casted_arg = ir_implicit_cast(ira, arg_value, child_type);10644 IrInstruction *casted_arg = ir_implicit_cast(ira, arg_value, child_type);
...@@ -10744,9 +10758,11 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_...@@ -10744,9 +10758,11 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
10744{10758{
10745 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);10759 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
10746 TypeTableEntry *canon_type = get_underlying_type(target_type);10760 TypeTableEntry *canon_type = get_underlying_type(target_type);
10761 if (type_is_invalid(canon_type))
10762 return ira->codegen->builtin_types.entry_invalid;
10747 switch (canon_type->id) {10763 switch (canon_type->id) {
10748 case TypeTableEntryIdInvalid:10764 case TypeTableEntryIdInvalid:
10749 return ira->codegen->builtin_types.entry_invalid;10765 zig_unreachable();
10750 case TypeTableEntryIdInt:10766 case TypeTableEntryIdInt:
10751 {10767 {
10752 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);10768 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
...@@ -10831,7 +10847,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst...@@ -10831,7 +10847,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
10831 fprintf(stderr, "| ");10847 fprintf(stderr, "| ");
10832 for (size_t i = 0; i < instruction->msg_count; i += 1) {10848 for (size_t i = 0; i < instruction->msg_count; i += 1) {
10833 IrInstruction *msg = instruction->msg_list[i]->other;10849 IrInstruction *msg = instruction->msg_list[i]->other;
10834 if (msg->value.type->id == TypeTableEntryIdInvalid)10850 if (type_is_invalid(msg->value.type))
10835 return ira->codegen->builtin_types.entry_invalid;10851 return ira->codegen->builtin_types.entry_invalid;
10836 buf_resize(&buf, 0);10852 buf_resize(&buf, 0);
10837 render_const_value(&buf, &msg->value);10853 render_const_value(&buf, &msg->value);
...@@ -10848,11 +10864,11 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst...@@ -10848,11 +10864,11 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
1084810864
10849static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {10865static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
10850 IrInstruction *value = instruction->value->other;10866 IrInstruction *value = instruction->value->other;
10851 if (value->value.type->id == TypeTableEntryIdInvalid)10867 if (type_is_invalid(value->value.type))
10852 return ira->codegen->builtin_types.entry_invalid;10868 return ira->codegen->builtin_types.entry_invalid;
1085310869
10854 IrInstruction *casted_value = ir_implicit_cast(ira, value, value->value.type);10870 IrInstruction *casted_value = ir_implicit_cast(ira, value, value->value.type);
10855 if (casted_value->value.type->id == TypeTableEntryIdInvalid)10871 if (type_is_invalid(casted_value->value.type))
10856 return ira->codegen->builtin_types.entry_invalid;10872 return ira->codegen->builtin_types.entry_invalid;
1085710873
10858 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);10874 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
...@@ -10875,7 +10891,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc...@@ -10875,7 +10891,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
10875static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {10891static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
10876 IrInstruction *type_value = instruction->type_value->other;10892 IrInstruction *type_value = instruction->type_value->other;
10877 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);10893 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
10878 if (type_entry->id == TypeTableEntryIdInvalid)10894 if (type_is_invalid(type_entry))
10879 return ira->codegen->builtin_types.entry_invalid;10895 return ira->codegen->builtin_types.entry_invalid;
1088010896
10881 if (!type_entry->cached_const_name_val) {10897 if (!type_entry->cached_const_name_val) {
...@@ -10898,7 +10914,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc...@@ -10898,7 +10914,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
10898 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,10914 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
10899 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,10915 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
10900 &cimport_scope->buf, block_node, nullptr, nullptr);10916 &cimport_scope->buf, block_node, nullptr, nullptr);
10901 if (result->value.type->id == TypeTableEntryIdInvalid)10917 if (type_is_invalid(result->value.type))
10902 return ira->codegen->builtin_types.entry_invalid;10918 return ira->codegen->builtin_types.entry_invalid;
1090310919
10904 find_libc_include_path(ira->codegen);10920 find_libc_include_path(ira->codegen);
...@@ -10937,7 +10953,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc...@@ -10937,7 +10953,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
1093710953
10938static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {10954static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
10939 IrInstruction *name_value = instruction->name->other;10955 IrInstruction *name_value = instruction->name->other;
10940 if (name_value->value.type->id == TypeTableEntryIdInvalid)10956 if (type_is_invalid(name_value->value.type))
10941 return ira->codegen->builtin_types.entry_invalid;10957 return ira->codegen->builtin_types.entry_invalid;
1094210958
10943 Buf *include_name = ir_resolve_str(ira, name_value);10959 Buf *include_name = ir_resolve_str(ira, name_value);
...@@ -10956,7 +10972,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru...@@ -10956,7 +10972,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
1095610972
10957static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {10973static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
10958 IrInstruction *name = instruction->name->other;10974 IrInstruction *name = instruction->name->other;
10959 if (name->value.type->id == TypeTableEntryIdInvalid)10975 if (type_is_invalid(name->value.type))
10960 return ira->codegen->builtin_types.entry_invalid;10976 return ira->codegen->builtin_types.entry_invalid;
1096110977
10962 Buf *define_name = ir_resolve_str(ira, name);10978 Buf *define_name = ir_resolve_str(ira, name);
...@@ -10964,7 +10980,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc...@@ -10964,7 +10980,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
10964 return ira->codegen->builtin_types.entry_invalid;10980 return ira->codegen->builtin_types.entry_invalid;
1096510981
10966 IrInstruction *value = instruction->value->other;10982 IrInstruction *value = instruction->value->other;
10967 if (value->value.type->id == TypeTableEntryIdInvalid)10983 if (type_is_invalid(value->value.type))
10968 return ira->codegen->builtin_types.entry_invalid;10984 return ira->codegen->builtin_types.entry_invalid;
1096910985
10970 Buf *define_value = ir_resolve_str(ira, value);10986 Buf *define_value = ir_resolve_str(ira, value);
...@@ -10983,7 +10999,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc...@@ -10983,7 +10999,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
1098310999
10984static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {11000static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
10985 IrInstruction *name = instruction->name->other;11001 IrInstruction *name = instruction->name->other;
10986 if (name->value.type->id == TypeTableEntryIdInvalid)11002 if (type_is_invalid(name->value.type))
10987 return ira->codegen->builtin_types.entry_invalid;11003 return ira->codegen->builtin_types.entry_invalid;
1098811004
10989 Buf *undef_name = ir_resolve_str(ira, name);11005 Buf *undef_name = ir_resolve_str(ira, name);
...@@ -11002,7 +11018,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct...@@ -11002,7 +11018,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
1100211018
11003static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {11019static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
11004 IrInstruction *name = instruction->name->other;11020 IrInstruction *name = instruction->name->other;
11005 if (name->value.type->id == TypeTableEntryIdInvalid)11021 if (type_is_invalid(name->value.type))
11006 return ira->codegen->builtin_types.entry_invalid;11022 return ira->codegen->builtin_types.entry_invalid;
1100711023
11008 Buf *rel_file_path = ir_resolve_str(ira, name);11024 Buf *rel_file_path = ir_resolve_str(ira, name);
...@@ -11041,19 +11057,19 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr...@@ -11041,19 +11057,19 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
1104111057
11042static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {11058static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
11043 IrInstruction *ptr = instruction->ptr->other;11059 IrInstruction *ptr = instruction->ptr->other;
11044 if (ptr->value.type->id == TypeTableEntryIdInvalid)11060 if (type_is_invalid(ptr->value.type))
11045 return ira->codegen->builtin_types.entry_invalid;11061 return ira->codegen->builtin_types.entry_invalid;
1104611062
11047 IrInstruction *cmp_value = instruction->cmp_value->other;11063 IrInstruction *cmp_value = instruction->cmp_value->other;
11048 if (cmp_value->value.type->id == TypeTableEntryIdInvalid)11064 if (type_is_invalid(cmp_value->value.type))
11049 return ira->codegen->builtin_types.entry_invalid;11065 return ira->codegen->builtin_types.entry_invalid;
1105011066
11051 IrInstruction *new_value = instruction->new_value->other;11067 IrInstruction *new_value = instruction->new_value->other;
11052 if (new_value->value.type->id == TypeTableEntryIdInvalid)11068 if (type_is_invalid(new_value->value.type))
11053 return ira->codegen->builtin_types.entry_invalid;11069 return ira->codegen->builtin_types.entry_invalid;
1105411070
11055 IrInstruction *success_order_value = instruction->success_order_value->other;11071 IrInstruction *success_order_value = instruction->success_order_value->other;
11056 if (success_order_value->value.type->id == TypeTableEntryIdInvalid)11072 if (type_is_invalid(success_order_value->value.type))
11057 return ira->codegen->builtin_types.entry_invalid;11073 return ira->codegen->builtin_types.entry_invalid;
1105811074
11059 AtomicOrder success_order;11075 AtomicOrder success_order;
...@@ -11061,7 +11077,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct...@@ -11061,7 +11077,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
11061 return ira->codegen->builtin_types.entry_invalid;11077 return ira->codegen->builtin_types.entry_invalid;
1106211078
11063 IrInstruction *failure_order_value = instruction->failure_order_value->other;11079 IrInstruction *failure_order_value = instruction->failure_order_value->other;
11064 if (failure_order_value->value.type->id == TypeTableEntryIdInvalid)11080 if (type_is_invalid(failure_order_value->value.type))
11065 return ira->codegen->builtin_types.entry_invalid;11081 return ira->codegen->builtin_types.entry_invalid;
1106611082
11067 AtomicOrder failure_order;11083 AtomicOrder failure_order;
...@@ -11077,11 +11093,11 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct...@@ -11077,11 +11093,11 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
11077 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;11093 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
1107811094
11079 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type);11095 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type);
11080 if (casted_cmp_value->value.type->id == TypeTableEntryIdInvalid)11096 if (type_is_invalid(casted_cmp_value->value.type))
11081 return ira->codegen->builtin_types.entry_invalid;11097 return ira->codegen->builtin_types.entry_invalid;
1108211098
11083 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, child_type);11099 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, child_type);
11084 if (casted_new_value->value.type->id == TypeTableEntryIdInvalid)11100 if (type_is_invalid(casted_new_value->value.type))
11085 return ira->codegen->builtin_types.entry_invalid;11101 return ira->codegen->builtin_types.entry_invalid;
1108611102
11087 if (success_order < AtomicOrderMonotonic) {11103 if (success_order < AtomicOrderMonotonic) {
...@@ -11112,7 +11128,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct...@@ -11112,7 +11128,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
1111211128
11113static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {11129static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
11114 IrInstruction *order_value = instruction->order_value->other;11130 IrInstruction *order_value = instruction->order_value->other;
11115 if (order_value->value.type->id == TypeTableEntryIdInvalid)11131 if (type_is_invalid(order_value->value.type))
11116 return ira->codegen->builtin_types.entry_invalid;11132 return ira->codegen->builtin_types.entry_invalid;
1111711133
11118 AtomicOrder order;11134 AtomicOrder order;
...@@ -11125,18 +11141,18 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio...@@ -11125,18 +11141,18 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio
1112511141
11126static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstructionDivExact *instruction) {11142static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstructionDivExact *instruction) {
11127 IrInstruction *op1 = instruction->op1->other;11143 IrInstruction *op1 = instruction->op1->other;
11128 if (op1->value.type->id == TypeTableEntryIdInvalid)11144 if (type_is_invalid(op1->value.type))
11129 return ira->codegen->builtin_types.entry_invalid;11145 return ira->codegen->builtin_types.entry_invalid;
1113011146
11131 IrInstruction *op2 = instruction->op2->other;11147 IrInstruction *op2 = instruction->op2->other;
11132 if (op2->value.type->id == TypeTableEntryIdInvalid)11148 if (type_is_invalid(op2->value.type))
11133 return ira->codegen->builtin_types.entry_invalid;11149 return ira->codegen->builtin_types.entry_invalid;
1113411150
1113511151
11136 IrInstruction *peer_instructions[] = { op1, op2 };11152 IrInstruction *peer_instructions[] = { op1, op2 };
11137 TypeTableEntry *result_type = ir_resolve_peer_types(ira, instruction->base.source_node, peer_instructions, 2);11153 TypeTableEntry *result_type = ir_resolve_peer_types(ira, instruction->base.source_node, peer_instructions, 2);
1113811154
11139 if (result_type->id == TypeTableEntryIdInvalid)11155 if (type_is_invalid(result_type))
11140 return ira->codegen->builtin_types.entry_invalid;11156 return ira->codegen->builtin_types.entry_invalid;
1114111157
11142 TypeTableEntry *canon_type = get_underlying_type(result_type);11158 TypeTableEntry *canon_type = get_underlying_type(result_type);
...@@ -11151,11 +11167,11 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru...@@ -11151,11 +11167,11 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
11151 }11167 }
1115211168
11153 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, result_type);11169 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, result_type);
11154 if (casted_op1->value.type->id == TypeTableEntryIdInvalid)11170 if (type_is_invalid(casted_op1->value.type))
11155 return ira->codegen->builtin_types.entry_invalid;11171 return ira->codegen->builtin_types.entry_invalid;
1115611172
11157 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, result_type);11173 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, result_type);
11158 if (casted_op2->value.type->id == TypeTableEntryIdInvalid)11174 if (type_is_invalid(casted_op2->value.type))
11159 return ira->codegen->builtin_types.entry_invalid;11175 return ira->codegen->builtin_types.entry_invalid;
1116011176
11161 if (casted_op1->value.special == ConstValSpecialStatic &&11177 if (casted_op1->value.special == ConstValSpecialStatic &&
...@@ -11196,7 +11212,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc...@@ -11196,7 +11212,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
11196 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);11212 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
11197 TypeTableEntry *canon_dest_type = get_underlying_type(dest_type);11213 TypeTableEntry *canon_dest_type = get_underlying_type(dest_type);
1119811214
11199 if (canon_dest_type->id == TypeTableEntryIdInvalid)11215 if (type_is_invalid(canon_dest_type))
11200 return ira->codegen->builtin_types.entry_invalid;11216 return ira->codegen->builtin_types.entry_invalid;
1120111217
11202 if (canon_dest_type->id != TypeTableEntryIdInt &&11218 if (canon_dest_type->id != TypeTableEntryIdInt &&
...@@ -11210,7 +11226,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc...@@ -11210,7 +11226,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
11210 IrInstruction *target = instruction->target->other;11226 IrInstruction *target = instruction->target->other;
11211 TypeTableEntry *src_type = target->value.type;11227 TypeTableEntry *src_type = target->value.type;
11212 TypeTableEntry *canon_src_type = get_underlying_type(src_type);11228 TypeTableEntry *canon_src_type = get_underlying_type(src_type);
11213 if (canon_src_type->id == TypeTableEntryIdInvalid)11229 if (type_is_invalid(canon_src_type))
11214 return ira->codegen->builtin_types.entry_invalid;11230 return ira->codegen->builtin_types.entry_invalid;
1121511231
11216 if (canon_src_type->id != TypeTableEntryIdInt &&11232 if (canon_src_type->id != TypeTableEntryIdInt &&
...@@ -11262,13 +11278,13 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc...@@ -11262,13 +11278,13 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
1126211278
11263static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {11279static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
11264 IrInstruction *value = instruction->value->other;11280 IrInstruction *value = instruction->value->other;
11265 if (value->value.type->id == TypeTableEntryIdInvalid)11281 if (type_is_invalid(value->value.type))
11266 return ira->codegen->builtin_types.entry_invalid;11282 return ira->codegen->builtin_types.entry_invalid;
1126711283
11268 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;11284 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
1126911285
11270 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);11286 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
11271 if (casted_value->value.type->id == TypeTableEntryIdInvalid)11287 if (type_is_invalid(casted_value->value.type))
11272 return ira->codegen->builtin_types.entry_invalid;11288 return ira->codegen->builtin_types.entry_invalid;
1127311289
11274 if (casted_value->value.special != ConstValSpecialRuntime) {11290 if (casted_value->value.special != ConstValSpecialRuntime) {
...@@ -11283,11 +11299,11 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc...@@ -11283,11 +11299,11 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
1128311299
11284static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructionAlloca *instruction) {11300static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructionAlloca *instruction) {
11285 IrInstruction *type_value = instruction->type_value->other;11301 IrInstruction *type_value = instruction->type_value->other;
11286 if (type_value->value.type->id == TypeTableEntryIdInvalid)11302 if (type_is_invalid(type_value->value.type))
11287 return ira->codegen->builtin_types.entry_invalid;11303 return ira->codegen->builtin_types.entry_invalid;
1128811304
11289 IrInstruction *count_value = instruction->count->other;11305 IrInstruction *count_value = instruction->count->other;
11290 if (count_value->value.type->id == TypeTableEntryIdInvalid)11306 if (type_is_invalid(count_value->value.type))
11291 return ira->codegen->builtin_types.entry_invalid;11307 return ira->codegen->builtin_types.entry_invalid;
1129211308
11293 TypeTableEntry *child_type = ir_resolve_type(ira, type_value);11309 TypeTableEntry *child_type = ir_resolve_type(ira, type_value);
...@@ -11308,15 +11324,15 @@ static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructi...@@ -11308,15 +11324,15 @@ static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructi
1130811324
11309static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {11325static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
11310 IrInstruction *dest_ptr = instruction->dest_ptr->other;11326 IrInstruction *dest_ptr = instruction->dest_ptr->other;
11311 if (dest_ptr->value.type->id == TypeTableEntryIdInvalid)11327 if (type_is_invalid(dest_ptr->value.type))
11312 return ira->codegen->builtin_types.entry_invalid;11328 return ira->codegen->builtin_types.entry_invalid;
1131311329
11314 IrInstruction *byte_value = instruction->byte->other;11330 IrInstruction *byte_value = instruction->byte->other;
11315 if (byte_value->value.type->id == TypeTableEntryIdInvalid)11331 if (type_is_invalid(byte_value->value.type))
11316 return ira->codegen->builtin_types.entry_invalid;11332 return ira->codegen->builtin_types.entry_invalid;
1131711333
11318 IrInstruction *count_value = instruction->count->other;11334 IrInstruction *count_value = instruction->count->other;
11319 if (count_value->value.type->id == TypeTableEntryIdInvalid)11335 if (type_is_invalid(count_value->value.type))
11320 return ira->codegen->builtin_types.entry_invalid;11336 return ira->codegen->builtin_types.entry_invalid;
1132111337
11322 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);11338 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);
...@@ -11328,15 +11344,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi...@@ -11328,15 +11344,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
11328 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, 0, 0);11344 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, 0, 0);
1132911345
11330 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);11346 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
11331 if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid)11347 if (type_is_invalid(casted_dest_ptr->value.type))
11332 return ira->codegen->builtin_types.entry_invalid;11348 return ira->codegen->builtin_types.entry_invalid;
1133311349
11334 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);11350 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);
11335 if (casted_byte->value.type->id == TypeTableEntryIdInvalid)11351 if (type_is_invalid(casted_byte->value.type))
11336 return ira->codegen->builtin_types.entry_invalid;11352 return ira->codegen->builtin_types.entry_invalid;
1133711353
11338 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);11354 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
11339 if (casted_count->value.type->id == TypeTableEntryIdInvalid)11355 if (type_is_invalid(casted_count->value.type))
11340 return ira->codegen->builtin_types.entry_invalid;11356 return ira->codegen->builtin_types.entry_invalid;
1134111357
11342 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&11358 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
...@@ -11393,15 +11409,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi...@@ -11393,15 +11409,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1139311409
11394static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {11410static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
11395 IrInstruction *dest_ptr = instruction->dest_ptr->other;11411 IrInstruction *dest_ptr = instruction->dest_ptr->other;
11396 if (dest_ptr->value.type->id == TypeTableEntryIdInvalid)11412 if (type_is_invalid(dest_ptr->value.type))
11397 return ira->codegen->builtin_types.entry_invalid;11413 return ira->codegen->builtin_types.entry_invalid;
1139811414
11399 IrInstruction *src_ptr = instruction->src_ptr->other;11415 IrInstruction *src_ptr = instruction->src_ptr->other;
11400 if (src_ptr->value.type->id == TypeTableEntryIdInvalid)11416 if (type_is_invalid(src_ptr->value.type))
11401 return ira->codegen->builtin_types.entry_invalid;11417 return ira->codegen->builtin_types.entry_invalid;
1140211418
11403 IrInstruction *count_value = instruction->count->other;11419 IrInstruction *count_value = instruction->count->other;
11404 if (count_value->value.type->id == TypeTableEntryIdInvalid)11420 if (type_is_invalid(count_value->value.type))
11405 return ira->codegen->builtin_types.entry_invalid;11421 return ira->codegen->builtin_types.entry_invalid;
1140611422
11407 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);11423 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);
...@@ -11417,15 +11433,15 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi...@@ -11417,15 +11433,15 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
11417 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, 0, 0);11433 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, 0, 0);
1141811434
11419 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);11435 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
11420 if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid)11436 if (type_is_invalid(casted_dest_ptr->value.type))
11421 return ira->codegen->builtin_types.entry_invalid;11437 return ira->codegen->builtin_types.entry_invalid;
1142211438
11423 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);11439 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
11424 if (casted_src_ptr->value.type->id == TypeTableEntryIdInvalid)11440 if (type_is_invalid(casted_src_ptr->value.type))
11425 return ira->codegen->builtin_types.entry_invalid;11441 return ira->codegen->builtin_types.entry_invalid;
1142611442
11427 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);11443 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
11428 if (casted_count->value.type->id == TypeTableEntryIdInvalid)11444 if (type_is_invalid(casted_count->value.type))
11429 return ira->codegen->builtin_types.entry_invalid;11445 return ira->codegen->builtin_types.entry_invalid;
1143011446
11431 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&11447 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
...@@ -11514,7 +11530,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi...@@ -11514,7 +11530,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1151411530
11515static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {11531static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
11516 IrInstruction *ptr_ptr = instruction->ptr->other;11532 IrInstruction *ptr_ptr = instruction->ptr->other;
11517 if (ptr_ptr->value.type->id == TypeTableEntryIdInvalid)11533 if (type_is_invalid(ptr_ptr->value.type))
11518 return ira->codegen->builtin_types.entry_invalid;11534 return ira->codegen->builtin_types.entry_invalid;
1151911535
11520 TypeTableEntry *ptr_type = ptr_ptr->value.type;11536 TypeTableEntry *ptr_type = ptr_ptr->value.type;
...@@ -11523,21 +11539,21 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -11523,21 +11539,21 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
11523 TypeTableEntry *canon_array_type = get_underlying_type(non_canon_array_type);11539 TypeTableEntry *canon_array_type = get_underlying_type(non_canon_array_type);
1152411540
11525 IrInstruction *start = instruction->start->other;11541 IrInstruction *start = instruction->start->other;
11526 if (start->value.type->id == TypeTableEntryIdInvalid)11542 if (type_is_invalid(start->value.type))
11527 return ira->codegen->builtin_types.entry_invalid;11543 return ira->codegen->builtin_types.entry_invalid;
1152811544
11529 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;11545 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
11530 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);11546 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
11531 if (casted_start->value.type->id == TypeTableEntryIdInvalid)11547 if (type_is_invalid(casted_start->value.type))
11532 return ira->codegen->builtin_types.entry_invalid;11548 return ira->codegen->builtin_types.entry_invalid;
1153311549
11534 IrInstruction *end;11550 IrInstruction *end;
11535 if (instruction->end) {11551 if (instruction->end) {
11536 end = instruction->end->other;11552 end = instruction->end->other;
11537 if (end->value.type->id == TypeTableEntryIdInvalid)11553 if (type_is_invalid(end->value.type))
11538 return ira->codegen->builtin_types.entry_invalid;11554 return ira->codegen->builtin_types.entry_invalid;
11539 end = ir_implicit_cast(ira, end, usize);11555 end = ir_implicit_cast(ira, end, usize);
11540 if (end->value.type->id == TypeTableEntryIdInvalid)11556 if (type_is_invalid(end->value.type))
11541 return ira->codegen->builtin_types.entry_invalid;11557 return ira->codegen->builtin_types.entry_invalid;
11542 } else {11558 } else {
11543 end = nullptr;11559 end = nullptr;
...@@ -11692,13 +11708,13 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -11692,13 +11708,13 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1169211708
11693static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {11709static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
11694 IrInstruction *container = instruction->container->other;11710 IrInstruction *container = instruction->container->other;
11695 if (container->value.type->id == TypeTableEntryIdInvalid)11711 if (type_is_invalid(container->value.type))
11696 return ira->codegen->builtin_types.entry_invalid;11712 return ira->codegen->builtin_types.entry_invalid;
11697 TypeTableEntry *container_type = ir_resolve_type(ira, container);11713 TypeTableEntry *container_type = ir_resolve_type(ira, container);
11698 TypeTableEntry *canon_type = get_underlying_type(container_type);11714 TypeTableEntry *canon_type = get_underlying_type(container_type);
1169911715
11700 uint64_t result;11716 uint64_t result;
11701 if (canon_type->id == TypeTableEntryIdInvalid) {11717 if (type_is_invalid(canon_type)) {
11702 return ira->codegen->builtin_types.entry_invalid;11718 return ira->codegen->builtin_types.entry_invalid;
11703 } else if (canon_type->id == TypeTableEntryIdEnum) {11719 } else if (canon_type->id == TypeTableEntryIdEnum) {
11704 result = canon_type->data.enumeration.src_field_count;11720 result = canon_type->data.enumeration.src_field_count;
...@@ -11739,11 +11755,11 @@ static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIn...@@ -11739,11 +11755,11 @@ static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIn
1173911755
11740static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstructionAlignOf *instruction) {11756static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
11741 IrInstruction *type_value = instruction->type_value->other;11757 IrInstruction *type_value = instruction->type_value->other;
11742 if (type_value->value.type->id == TypeTableEntryIdInvalid)11758 if (type_is_invalid(type_value->value.type))
11743 return ira->codegen->builtin_types.entry_invalid;11759 return ira->codegen->builtin_types.entry_invalid;
11744 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);11760 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
1174511761
11746 if (type_entry->id == TypeTableEntryIdInvalid) {11762 if (type_is_invalid(type_entry)) {
11747 return ira->codegen->builtin_types.entry_invalid;11763 return ira->codegen->builtin_types.entry_invalid;
11748 } else if (type_entry->id == TypeTableEntryIdUnreachable) {11764 } else if (type_entry->id == TypeTableEntryIdUnreachable) {
11749 ir_add_error(ira, instruction->type_value,11765 ir_add_error(ira, instruction->type_value,
...@@ -11759,11 +11775,11 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct...@@ -11759,11 +11775,11 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
1175911775
11760static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {11776static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
11761 IrInstruction *type_value = instruction->type_value->other;11777 IrInstruction *type_value = instruction->type_value->other;
11762 if (type_value->value.type->id == TypeTableEntryIdInvalid)11778 if (type_is_invalid(type_value->value.type))
11763 return ira->codegen->builtin_types.entry_invalid;11779 return ira->codegen->builtin_types.entry_invalid;
11764 TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);11780 TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);
11765 TypeTableEntry *canon_type = get_underlying_type(dest_type);11781 TypeTableEntry *canon_type = get_underlying_type(dest_type);
11766 if (canon_type->id == TypeTableEntryIdInvalid)11782 if (type_is_invalid(canon_type))
11767 return ira->codegen->builtin_types.entry_invalid;11783 return ira->codegen->builtin_types.entry_invalid;
1176811784
11769 if (canon_type->id != TypeTableEntryIdInt) {11785 if (canon_type->id != TypeTableEntryIdInt) {
...@@ -11774,28 +11790,28 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -11774,28 +11790,28 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
11774 }11790 }
1177511791
11776 IrInstruction *op1 = instruction->op1->other;11792 IrInstruction *op1 = instruction->op1->other;
11777 if (op1->value.type->id == TypeTableEntryIdInvalid)11793 if (type_is_invalid(op1->value.type))
11778 return ira->codegen->builtin_types.entry_invalid;11794 return ira->codegen->builtin_types.entry_invalid;
1177911795
11780 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);11796 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
11781 if (casted_op1->value.type->id == TypeTableEntryIdInvalid)11797 if (type_is_invalid(casted_op1->value.type))
11782 return ira->codegen->builtin_types.entry_invalid;11798 return ira->codegen->builtin_types.entry_invalid;
1178311799
11784 IrInstruction *op2 = instruction->op2->other;11800 IrInstruction *op2 = instruction->op2->other;
11785 if (op2->value.type->id == TypeTableEntryIdInvalid)11801 if (type_is_invalid(op2->value.type))
11786 return ira->codegen->builtin_types.entry_invalid;11802 return ira->codegen->builtin_types.entry_invalid;
1178711803
11788 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);11804 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
11789 if (casted_op2->value.type->id == TypeTableEntryIdInvalid)11805 if (type_is_invalid(casted_op2->value.type))
11790 return ira->codegen->builtin_types.entry_invalid;11806 return ira->codegen->builtin_types.entry_invalid;
1179111807
11792 IrInstruction *result_ptr = instruction->result_ptr->other;11808 IrInstruction *result_ptr = instruction->result_ptr->other;
11793 if (result_ptr->value.type->id == TypeTableEntryIdInvalid)11809 if (type_is_invalid(result_ptr->value.type))
11794 return ira->codegen->builtin_types.entry_invalid;11810 return ira->codegen->builtin_types.entry_invalid;
1179511811
11796 TypeTableEntry *expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);11812 TypeTableEntry *expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
11797 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);11813 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
11798 if (casted_result_ptr->value.type->id == TypeTableEntryIdInvalid)11814 if (type_is_invalid(casted_result_ptr->value.type))
11799 return ira->codegen->builtin_types.entry_invalid;11815 return ira->codegen->builtin_types.entry_invalid;
1180011816
11801 if (casted_op1->value.special == ConstValSpecialStatic &&11817 if (casted_op1->value.special == ConstValSpecialStatic &&
...@@ -11838,13 +11854,13 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst...@@ -11838,13 +11854,13 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1183811854
11839static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {11855static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
11840 IrInstruction *value = instruction->value->other;11856 IrInstruction *value = instruction->value->other;
11841 if (value->value.type->id == TypeTableEntryIdInvalid)11857 if (type_is_invalid(value->value.type))
11842 return ira->codegen->builtin_types.entry_invalid;11858 return ira->codegen->builtin_types.entry_invalid;
1184311859
11844 TypeTableEntry *non_canon_type = value->value.type;11860 TypeTableEntry *non_canon_type = value->value.type;
1184511861
11846 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);11862 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
11847 if (canon_type->id == TypeTableEntryIdInvalid) {11863 if (type_is_invalid(canon_type)) {
11848 return ira->codegen->builtin_types.entry_invalid;11864 return ira->codegen->builtin_types.entry_invalid;
11849 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {11865 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
11850 if (instr_is_comptime(value)) {11866 if (instr_is_comptime(value)) {
...@@ -11876,7 +11892,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -11876,7 +11892,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
11876 IrInstructionUnwrapErrCode *instruction)11892 IrInstructionUnwrapErrCode *instruction)
11877{11893{
11878 IrInstruction *value = instruction->value->other;11894 IrInstruction *value = instruction->value->other;
11879 if (value->value.type->id == TypeTableEntryIdInvalid)11895 if (type_is_invalid(value->value.type))
11880 return ira->codegen->builtin_types.entry_invalid;11896 return ira->codegen->builtin_types.entry_invalid;
11881 TypeTableEntry *ptr_type = value->value.type;11897 TypeTableEntry *ptr_type = value->value.type;
1188211898
...@@ -11885,7 +11901,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -11885,7 +11901,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1188511901
11886 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;11902 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;
11887 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);11903 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
11888 if (canon_type->id == TypeTableEntryIdInvalid) {11904 if (type_is_invalid(canon_type)) {
11889 return ira->codegen->builtin_types.entry_invalid;11905 return ira->codegen->builtin_types.entry_invalid;
11890 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {11906 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
11891 if (instr_is_comptime(value)) {11907 if (instr_is_comptime(value)) {
...@@ -11918,7 +11934,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -11918,7 +11934,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
11918{11934{
11919 assert(instruction->value->other);11935 assert(instruction->value->other);
11920 IrInstruction *value = instruction->value->other;11936 IrInstruction *value = instruction->value->other;
11921 if (value->value.type->id == TypeTableEntryIdInvalid)11937 if (type_is_invalid(value->value.type))
11922 return ira->codegen->builtin_types.entry_invalid;11938 return ira->codegen->builtin_types.entry_invalid;
11923 TypeTableEntry *ptr_type = value->value.type;11939 TypeTableEntry *ptr_type = value->value.type;
1192411940
...@@ -11927,7 +11943,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -11927,7 +11943,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1192711943
11928 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;11944 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;
11929 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);11945 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
11930 if (canon_type->id == TypeTableEntryIdInvalid) {11946 if (type_is_invalid(canon_type)) {
11931 return ira->codegen->builtin_types.entry_invalid;11947 return ira->codegen->builtin_types.entry_invalid;
11932 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {11948 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
11933 TypeTableEntry *child_type = canon_type->data.error.child_type;11949 TypeTableEntry *child_type = canon_type->data.error.child_type;
...@@ -11980,13 +11996,13 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -11980,13 +11996,13 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
11980 FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];11996 FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];
11981 param_info->is_noalias = param_node->data.param_decl.is_noalias;11997 param_info->is_noalias = param_node->data.param_decl.is_noalias;
11982 param_info->type = ir_resolve_type(ira, param_type_value);11998 param_info->type = ir_resolve_type(ira, param_type_value);
11983 if (param_info->type->id == TypeTableEntryIdInvalid)11999 if (type_is_invalid(param_info->type))
11984 return ira->codegen->builtin_types.entry_invalid;12000 return ira->codegen->builtin_types.entry_invalid;
11985 }12001 }
1198612002
11987 IrInstruction *return_type_value = instruction->return_type->other;12003 IrInstruction *return_type_value = instruction->return_type->other;
11988 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);12004 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
11989 if (fn_type_id.return_type->id == TypeTableEntryIdInvalid)12005 if (type_is_invalid(fn_type_id.return_type))
11990 return ira->codegen->builtin_types.entry_invalid;12006 return ira->codegen->builtin_types.entry_invalid;
1199112007
11992 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12008 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
...@@ -11996,7 +12012,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -11996,7 +12012,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1199612012
11997static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {12013static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
11998 IrInstruction *value = instruction->value->other;12014 IrInstruction *value = instruction->value->other;
11999 if (value->value.type->id == TypeTableEntryIdInvalid)12015 if (type_is_invalid(value->value.type))
12000 return ira->codegen->builtin_types.entry_invalid;12016 return ira->codegen->builtin_types.entry_invalid;
1200112017
12002 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12018 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
...@@ -12009,7 +12025,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -12009,7 +12025,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
12009{12025{
12010 IrInstruction *target_value = instruction->target_value->other;12026 IrInstruction *target_value = instruction->target_value->other;
12011 TypeTableEntry *switch_type = target_value->value.type;12027 TypeTableEntry *switch_type = target_value->value.type;
12012 if (switch_type->id == TypeTableEntryIdInvalid)12028 if (type_is_invalid(switch_type))
12013 return ira->codegen->builtin_types.entry_invalid;12029 return ira->codegen->builtin_types.entry_invalid;
1201412030
12015 if (switch_type->id == TypeTableEntryIdEnumTag) {12031 if (switch_type->id == TypeTableEntryIdEnumTag) {
...@@ -12019,11 +12035,11 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -12019,11 +12035,11 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
12019 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];12035 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
1202012036
12021 IrInstruction *start_value = range->start->other;12037 IrInstruction *start_value = range->start->other;
12022 if (start_value->value.type->id == TypeTableEntryIdInvalid)12038 if (type_is_invalid(start_value->value.type))
12023 return ira->codegen->builtin_types.entry_invalid;12039 return ira->codegen->builtin_types.entry_invalid;
1202412040
12025 IrInstruction *end_value = range->end->other;12041 IrInstruction *end_value = range->end->other;
12026 if (end_value->value.type->id == TypeTableEntryIdInvalid)12042 if (type_is_invalid(end_value->value.type))
12027 return ira->codegen->builtin_types.entry_invalid;12043 return ira->codegen->builtin_types.entry_invalid;
1202812044
12029 size_t start_index;12045 size_t start_index;
...@@ -12070,7 +12086,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira...@@ -12070,7 +12086,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
12070static TypeTableEntry *ir_analyze_instruction_test_type(IrAnalyze *ira, IrInstructionTestType *instruction) {12086static TypeTableEntry *ir_analyze_instruction_test_type(IrAnalyze *ira, IrInstructionTestType *instruction) {
12071 IrInstruction *type_value = instruction->type_value->other;12087 IrInstruction *type_value = instruction->type_value->other;
12072 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);12088 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
12073 if (type_entry->id == TypeTableEntryIdInvalid)12089 if (type_is_invalid(type_entry))
12074 return ira->codegen->builtin_types.entry_invalid;12090 return ira->codegen->builtin_types.entry_invalid;
1207512091
12076 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12092 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
...@@ -12083,11 +12099,11 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,...@@ -12083,11 +12099,11 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,
12083{12099{
12084 IrInstruction *type_value = instruction->type_value->other;12100 IrInstruction *type_value = instruction->type_value->other;
12085 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);12101 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
12086 if (type_entry->id == TypeTableEntryIdInvalid)12102 if (type_is_invalid(type_entry))
12087 return ira->codegen->builtin_types.entry_invalid;12103 return ira->codegen->builtin_types.entry_invalid;
1208812104
12089 IrInstruction *target_value = instruction->target_value->other;12105 IrInstruction *target_value = instruction->target_value->other;
12090 if (target_value->value.type->id == TypeTableEntryIdInvalid)12106 if (type_is_invalid(target_value->value.type))
12091 return ira->codegen->builtin_types.entry_invalid;12107 return ira->codegen->builtin_types.entry_invalid;
1209212108
12093 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, type_entry, target_value->value.type,12109 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, type_entry, target_value->value.type,
test/run_tests.cpp+38-6
...@@ -93,10 +93,9 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,...@@ -93,10 +93,9 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,
93 return tc;93 return tc;
94}94}
9595
96static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {96static TestCase *add_compile_fail_case_extra(const char *case_name, const char *source, bool check_unused,
97 va_list ap;97 size_t count, va_list ap)
98 va_start(ap, count);98{
99
100 TestCase *test_case = allocate<TestCase>(1);99 TestCase *test_case = allocate<TestCase>(1);
101 test_case->case_name = case_name;100 test_case->case_name = case_name;
102 test_case->source_files.resize(1);101 test_case->source_files.resize(1);
...@@ -122,13 +121,30 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source...@@ -122,13 +121,30 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source
122121
123 test_case->compiler_args.append("--release");122 test_case->compiler_args.append("--release");
124 test_case->compiler_args.append("--strip");123 test_case->compiler_args.append("--strip");
125 test_case->compiler_args.append("--check-unused");124
125 if (check_unused) {
126 test_case->compiler_args.append("--check-unused");
127 }
126128
127 test_cases.append(test_case);129 test_cases.append(test_case);
128130
131 return test_case;
132}
133
134static TestCase *add_compile_fail_case_no_check_unused(const char *case_name, const char *source, size_t count, ...) {
135 va_list ap;
136 va_start(ap, count);
137 TestCase *result = add_compile_fail_case_extra(case_name, source, false, count, ap);
129 va_end(ap);138 va_end(ap);
139 return result;
140}
130141
131 return test_case;142static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
143 va_list ap;
144 va_start(ap, count);
145 TestCase *result = add_compile_fail_case_extra(case_name, source, true, count, ap);
146 va_end(ap);
147 return result;
132}148}
133149
134static void add_debug_safety_case(const char *case_name, const char *source) {150static void add_debug_safety_case(const char *case_name, const char *source) {
...@@ -1646,6 +1662,22 @@ fn bar(x: &const u3) -> u3 {...@@ -1646,6 +1662,22 @@ fn bar(x: &const u3) -> u3 {
1646}1662}
1647 )SOURCE", 1, ".tmp_source.zig:12:26: error: expected type '&const u3', found '&:3:6 const u3'");1663 )SOURCE", 1, ".tmp_source.zig:12:26: error: expected type '&const u3', found '&:3:6 const u3'");
16481664
1665 add_compile_fail_case_no_check_unused("referring to a struct that is invalid without --check-unused", R"SOURCE(
1666const UsbDeviceRequest = struct {
1667 Type: u8,
1668};
1669
1670export fn foo() {
1671 comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
1672}
1673
1674fn assert(ok: bool) {
1675 if (!ok) @unreachable();
1676}
1677 )SOURCE", 2,
1678 ".tmp_source.zig:11:14: error: unable to evaluate constant expression",
1679 ".tmp_source.zig:7:20: note: called from here");
1680
1649}1681}
16501682
1651//////////////////////////////////////////////////////////////////////////////1683//////////////////////////////////////////////////////////////////////////////