aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp227
1 files changed, 95 insertions, 132 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index c651f30dd5..df2c8cc9be 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -9771,13 +9771,19 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
return ir_exec_const_result(codegen, analyzed_executable);
}
-static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
+static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value, ZigTypeId wanted_type) {
if (type_is_invalid(type_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
+ const char *expected_type_str = type_id_name(ZigTypeIdMetaType);
+
+ if (wanted_type != ZigTypeIdInvalid) {
+ expected_type_str = type_id_name(wanted_type);
+ }
+
if (type_value->value.type->id != ZigTypeIdMetaType) {
- ir_add_error(ira, type_value,
- buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));
+ ir_add_error( ira, type_value,
+ buf_sprintf("expected %s type, found '%s'", expected_type_str, buf_ptr(&type_value->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
@@ -9786,7 +9792,16 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
return ira->codegen->builtin_types.entry_invalid;
assert(const_val->data.x_type != nullptr);
- return const_val->data.x_type;
+
+ ZigType *out_type = const_val->data.x_type;
+
+ if (wanted_type != ZigTypeIdInvalid && out_type->id != wanted_type) {
+ ir_add_error(ira, type_value,
+ buf_sprintf( "expected %s type, found '%s'", expected_type_str, buf_ptr(&out_type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
+ return out_type;
}
static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
@@ -10986,7 +11001,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
- buf_sprintf("expected type '%s', found '%s'",
+ buf_sprintf("expected '%s' type, found '%s'",
buf_ptr(&wanted_type->name),
buf_ptr(&actual_type->name)));
report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);
@@ -12214,7 +12229,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
size_t op2_array_end;
if (op2_type->id == ZigTypeIdArray) {
if (op2_type->data.array.child_type != child_type) {
- ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
+ ir_add_error(ira, op2, buf_sprintf("expected array of '%s' type, found '%s'",
buf_ptr(&child_type->name),
buf_ptr(&op2->value.type->name)));
return ira->codegen->invalid_instruction;
@@ -12228,7 +12243,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
op2_val->data.x_ptr.data.base_array.is_cstr)
{
if (child_type != ira->codegen->builtin_types.entry_u8) {
- ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
+ ir_add_error(ira, op2, buf_sprintf("expected array of '%s' type, found '%s'",
buf_ptr(&child_type->name),
buf_ptr(&op2->value.type->name)));
return ira->codegen->invalid_instruction;
@@ -12239,7 +12254,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
} else if (is_slice(op2_type)) {
ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
if (ptr_type->data.pointer.child_type != child_type) {
- ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
+ ir_add_error(ira, op2, buf_sprintf("expected array of '%s' type, found '%s'",
buf_ptr(&child_type->name),
buf_ptr(&op2->value.type->name)));
return ira->codegen->invalid_instruction;
@@ -12253,7 +12268,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
op2_array_end = bigint_as_unsigned(&len_val->data.x_bigint);
} else {
ir_add_error(ira, op2,
- buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));
+ buf_sprintf("expected array or C string literal type, found '%s'", buf_ptr(&op2->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -12388,26 +12403,22 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
}
static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
- ZigType *op1_type = ir_resolve_type(ira, instruction->op1->child);
- if (type_is_invalid(op1_type))
- return ira->codegen->invalid_instruction;
-
- if (op1_type->id != ZigTypeIdErrorSet) {
- ir_add_error(ira, instruction->op1,
- buf_sprintf("expected error set type, found '%s'", buf_ptr(&op1_type->name)));
+ ZigType *op1_type = ir_resolve_type(ira, instruction->op1->child, ZigTypeIdErrorSet);
+ if (type_is_invalid(op1_type)) {
+ if (ira->codegen->errors.length != 0) {
+ add_error_note( ira->codegen
+ , ira->codegen->errors.last()
+ , instruction->base.source_node
+ , buf_sprintf("did you mean to use `or`?")
+ );
+ }
return ira->codegen->invalid_instruction;
}
- ZigType *op2_type = ir_resolve_type(ira, instruction->op2->child);
+ ZigType *op2_type = ir_resolve_type(ira, instruction->op2->child, ZigTypeIdErrorSet);
if (type_is_invalid(op2_type))
return ira->codegen->invalid_instruction;
- if (op2_type->id != ZigTypeIdErrorSet) {
- ir_add_error(ira, instruction->op2,
- buf_sprintf("expected error set type, found '%s'", buf_ptr(&op2_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
if (type_is_global_error_set(op1_type) ||
type_is_global_error_set(op2_type))
{
@@ -12495,7 +12506,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct
IrInstruction *var_type = nullptr;
if (decl_var_instruction->var_type != nullptr) {
var_type = decl_var_instruction->var_type->child;
- ZigType *proposed_type = ir_resolve_type(ira, var_type);
+ ZigType *proposed_type = ir_resolve_type(ira, var_type, ZigTypeIdInvalid);
explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
if (type_is_invalid(explicit_type)) {
var->value->type = ira->codegen->builtin_types.entry_invalid;
@@ -12824,21 +12835,14 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
{
Error err;
- ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->child);
+ ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->child, ZigTypeIdErrorSet);
if (type_is_invalid(err_set_type))
return ira->codegen->invalid_instruction;
- ZigType *payload_type = ir_resolve_type(ira, instruction->payload->child);
+ ZigType *payload_type = ir_resolve_type(ira, instruction->payload->child, ZigTypeIdInvalid);
if (type_is_invalid(payload_type))
return ira->codegen->invalid_instruction;
- if (err_set_type->id != ZigTypeIdErrorSet) {
- ir_add_error(ira, instruction->err_set->child,
- buf_sprintf("expected error set type, found type '%s'",
- buf_ptr(&err_set_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown)))
return ira->codegen->invalid_instruction;
ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);
@@ -12900,7 +12904,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c
ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
if (alloc_fn_type->id != ZigTypeIdFn) {
ir_add_error(ira, &call_instruction->base,
- buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));
+ buf_sprintf("expected allocation function type, found '%s'", buf_ptr(&alloc_fn_type->name)));
return ira->codegen->invalid_instruction;
}
@@ -13692,7 +13696,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
if (is_comptime || instr_is_comptime(fn_ref)) {
if (fn_ref->value.type->id == ZigTypeIdMetaType) {
- ZigType *dest_type = ir_resolve_type(ira, fn_ref);
+ ZigType *dest_type = ir_resolve_type(ira, fn_ref, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -13817,7 +13821,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
Error err;
IrInstruction *value = un_op_instruction->value->child;
- ZigType *type_entry = ir_resolve_type(ira, value);
+ ZigType *type_entry = ir_resolve_type(ira, value, ZigTypeIdInvalid);
if (type_is_invalid(type_entry))
return ira->codegen->invalid_instruction;
if ((err = ensure_complete_type(ira->codegen, type_entry)))
@@ -15300,16 +15304,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
IrInstructionPtrTypeChild *ptr_type_child_instruction)
{
IrInstruction *type_value = ptr_type_child_instruction->value->child;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdPointer);
if (type_is_invalid(type_entry))
return ira->codegen->invalid_instruction;
- if (type_entry->id != ZigTypeIdPointer) {
- ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
- buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
- return ira->codegen->invalid_instruction;
- }
-
return ir_const_type(ira, &ptr_type_child_instruction->base, type_entry->data.pointer.child_type);
}
@@ -15462,7 +15460,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
return ira->codegen->invalid_instruction;
}
- ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->child);
+ ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->child, ZigTypeIdInvalid);
if (type_is_invalid(child_type))
return ira->codegen->invalid_instruction;
@@ -15545,7 +15543,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
AsmOutput *asm_output = asm_expr->output_list.at(i);
if (asm_output->return_type) {
output_types[i] = asm_instruction->output_types[i]->child;
- return_type = ir_resolve_type(ira, output_types[i]);
+ return_type = ir_resolve_type(ira, output_types[i], ZigTypeIdInvalid);
if (type_is_invalid(return_type))
return ira->codegen->invalid_instruction;
}
@@ -15560,7 +15558,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
(input_value->value.type->id == ZigTypeIdComptimeInt ||
input_value->value.type->id == ZigTypeIdComptimeFloat)) {
ir_add_error_node(ira, input_value->source_node,
- buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value.type->name)));
+ buf_sprintf("expected sized integer or sized float type, found %s", buf_ptr(&input_value->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -15586,7 +15584,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
return ira->codegen->invalid_instruction;
IrInstruction *child_type_value = array_type_instruction->child_type->child;
- ZigType *child_type = ir_resolve_type(ira, child_type_value);
+ ZigType *child_type = ir_resolve_type(ira, child_type_value, ZigTypeIdInvalid);
if (type_is_invalid(child_type))
return ira->codegen->invalid_instruction;
switch (child_type->id) {
@@ -15635,7 +15633,7 @@ static IrInstruction *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInst
if (instruction->payload_type == nullptr) {
promise_type = ira->codegen->builtin_types.entry_promise;
} else {
- ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->child);
+ ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->child, ZigTypeIdInvalid);
if (type_is_invalid(payload_type))
return ira->codegen->invalid_instruction;
@@ -15650,7 +15648,7 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
{
Error err;
IrInstruction *type_value = size_of_instruction->type_value->child;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
if ((err = ensure_complete_type(ira->codegen, type_entry)))
return ira->codegen->invalid_instruction;
@@ -16485,7 +16483,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
size_t elem_count = instruction->item_count;
if (container_type_value->value.type->id == ZigTypeIdMetaType) {
- ZigType *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
@@ -16601,7 +16599,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {
IrInstruction *container_type_value = instruction->container_type->child;
- ZigType *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
@@ -16719,7 +16717,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
{
Error err;
IrInstruction *type_value = instruction->type_value->child;
- ZigType *container_type = ir_resolve_type(ira, type_value);
+ ZigType *container_type = ir_resolve_type(ira, type_value, ZigTypeIdStruct);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
@@ -16732,12 +16730,6 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
if (type_is_invalid(field_ptr->value.type))
return ira->codegen->invalid_instruction;
- if (container_type->id != ZigTypeIdStruct) {
- ir_add_error(ira, type_value,
- buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
if ((err = ensure_complete_type(ira->codegen, container_type)))
return ira->codegen->invalid_instruction;
@@ -16751,7 +16743,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
if (field_ptr->value.type->id != ZigTypeIdPointer) {
ir_add_error(ira, field_ptr,
- buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));
+ buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&field_ptr->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -16810,9 +16802,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
static TypeStructField *validate_byte_offset(IrAnalyze *ira,
IrInstruction *type_value,
IrInstruction *field_name_value,
- size_t *byte_offset)
+ size_t *byte_offset)
{
- ZigType *container_type = ir_resolve_type(ira, type_value);
+ ZigType *container_type = ir_resolve_type(ira, type_value, ZigTypeIdStruct);
if (type_is_invalid(container_type))
return nullptr;
@@ -16824,12 +16816,6 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
if (!field_name)
return nullptr;
- if (container_type->id != ZigTypeIdStruct) {
- ir_add_error(ira, type_value,
- buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
- return nullptr;
- }
-
TypeStructField *field = find_struct_type_field(container_type, field_name);
if (field == nullptr) {
ir_add_error(ira, field_name_value,
@@ -17807,7 +17793,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
{
Error err;
IrInstruction *type_value = instruction->type_value->child;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
if (type_is_invalid(type_entry))
return ira->codegen->invalid_instruction;
@@ -17835,7 +17821,7 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
IrInstructionTypeId *instruction)
{
IrInstruction *type_value = instruction->type_value->child;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
if (type_is_invalid(type_entry))
return ira->codegen->invalid_instruction;
@@ -17870,7 +17856,7 @@ static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ir
static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
IrInstruction *type_value = instruction->type_value->child;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
if (type_is_invalid(type_entry))
return ira->codegen->invalid_instruction;
@@ -18147,7 +18133,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction
static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
IrInstruction *dest_type_value = instruction->dest_type->child;
- ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -18200,7 +18186,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
}
static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -18233,7 +18219,7 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
}
static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -18273,16 +18259,10 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
}
static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdErrorSet);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
- if (dest_type->id != ZigTypeIdErrorSet) {
- ir_add_error(ira, instruction->dest_type,
- buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
IrInstruction *target = instruction->target->child;
if (type_is_invalid(target->value.type))
return ira->codegen->invalid_instruction;
@@ -18311,7 +18291,7 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali
static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
Error err;
- ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
+ ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child, ZigTypeIdInvalid);
if (type_is_invalid(dest_child_type))
return ira->codegen->invalid_instruction;
@@ -18408,7 +18388,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
if (!is_slice(target->value.type)) {
ir_add_error(ira, instruction->target,
- buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name)));
+ buf_sprintf("expected slice type, found '%s'", buf_ptr(&target->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -18427,7 +18407,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
}
static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -18445,7 +18425,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
}
static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -18501,7 +18481,7 @@ static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstr
return ira->codegen->invalid_instruction;
if (target->value.type->id != ZigTypeIdBool) {
- ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
+ ir_add_error(ira, instruction->target, buf_sprintf("expected bool type, found '%s'",
buf_ptr(&target->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -19082,7 +19062,7 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
IrInstruction *container = instruction->container->child;
if (type_is_invalid(container->value.type))
return ira->codegen->invalid_instruction;
- ZigType *container_type = ir_resolve_type(ira, container);
+ ZigType *container_type = ir_resolve_type(ira, container, ZigTypeIdInvalid);
if ((err = ensure_complete_type(ira->codegen, container_type)))
return ira->codegen->invalid_instruction;
@@ -19116,7 +19096,7 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
Error err;
IrInstruction *container_type_value = instruction->container_type->child;
- ZigType *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
@@ -19159,7 +19139,7 @@ static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstr
static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
Error err;
IrInstruction *container_type_value = instruction->container_type->child;
- ZigType *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value, ZigTypeIdInvalid);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
@@ -19252,7 +19232,7 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
IrInstruction *type_value = instruction->type_value->child;
if (type_is_invalid(type_value->value.type))
return ira->codegen->invalid_instruction;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value, ZigTypeIdInvalid);
if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusAlignmentKnown)))
return ira->codegen->invalid_instruction;
@@ -19302,16 +19282,10 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
if (type_is_invalid(type_value->value.type))
return ira->codegen->invalid_instruction;
- ZigType *dest_type = ir_resolve_type(ira, type_value);
+ ZigType *dest_type = ir_resolve_type(ira, type_value, ZigTypeIdInt);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
- if (dest_type->id != ZigTypeIdInt) {
- ir_add_error(ira, type_value,
- buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
IrInstruction *op1 = instruction->op1->child;
if (type_is_invalid(op1->value.type))
return ira->codegen->invalid_instruction;
@@ -19581,7 +19555,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->child;
if (type_is_invalid(param_type_value->value.type))
return ira->codegen->invalid_instruction;
- ZigType *param_type = ir_resolve_type(ira, param_type_value);
+ ZigType *param_type = ir_resolve_type(ira, param_type_value, ZigTypeIdInvalid);
switch (type_requires_comptime(ira->codegen, param_type)) {
case ReqCompTimeYes:
if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
@@ -19615,7 +19589,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
}
IrInstruction *return_type_value = instruction->return_type->child;
- fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
+ fn_type_id.return_type = ir_resolve_type(ira, return_type_value, ZigTypeIdInvalid);
if (type_is_invalid(fn_type_id.return_type))
return ira->codegen->invalid_instruction;
if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
@@ -19631,7 +19605,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
return ira->codegen->invalid_instruction;
}
IrInstruction *async_allocator_type_value = instruction->async_allocator_type_value->child;
- fn_type_id.async_allocator_type = ir_resolve_type(ira, async_allocator_type_value);
+ fn_type_id.async_allocator_type = ir_resolve_type(ira, async_allocator_type_value, ZigTypeIdInvalid);
if (type_is_invalid(fn_type_id.async_allocator_type))
return ira->codegen->invalid_instruction;
}
@@ -19939,7 +19913,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
result_type = get_slice_type(ira->codegen, result_ptr_type);
} else {
ir_add_error(ira, target,
- buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));
+ buf_sprintf("expected pointer or slice type, found '%s'", buf_ptr(&target_type->name)));
return ira->codegen->invalid_instruction;
}
@@ -19985,13 +19959,13 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
// validate src_type and dest_type.
if (get_src_ptr_type(src_type) == nullptr) {
- ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
+ ir_add_error(ira, ptr, buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&src_type->name)));
return ira->codegen->invalid_instruction;
}
if (get_src_ptr_type(dest_type) == nullptr) {
ir_add_error(ira, dest_type_src,
- buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
+ buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->invalid_instruction;
}
@@ -20059,7 +20033,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
IrInstruction *dest_type_value = instruction->dest_type->child;
- ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -20255,7 +20229,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->child;
- ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
@@ -20352,13 +20326,13 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct
static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->child;
- ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdInvalid);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
// We explicitly check for the size, so we can use get_src_ptr_type
if (get_src_ptr_type(dest_type) == nullptr) {
- ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
+ ir_add_error(ira, dest_type_value, buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->invalid_instruction;
}
@@ -20461,7 +20435,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru
// We check size explicitly so we can use get_src_ptr_type here.
if (get_src_ptr_type(target->value.type) == nullptr) {
ir_add_error(ira, target,
- buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));
+ buf_sprintf("expected Pointer type, found '%s'", buf_ptr(&target->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -20492,7 +20466,7 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru
static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
Error err;
- ZigType *child_type = ir_resolve_type(ira, instruction->child_type->child);
+ ZigType *child_type = ir_resolve_type(ira, instruction->child_type->child, ZigTypeIdInvalid);
if (type_is_invalid(child_type))
return ira->codegen->invalid_instruction;
@@ -20591,7 +20565,7 @@ static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrI
static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
IrInstruction *fn_type_inst = instruction->fn_type->child;
- ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
+ ZigType *fn_type = ir_resolve_type(ira, fn_type_inst, ZigTypeIdFn);
if (type_is_invalid(fn_type))
return ira->codegen->invalid_instruction;
@@ -20600,11 +20574,6 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
return ira->codegen->invalid_instruction;
- if (fn_type->id != ZigTypeIdFn) {
- ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
if (arg_index >= fn_type_id->param_count) {
ir_add_error(ira, arg_index_inst,
@@ -20629,7 +20598,7 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
Error err;
IrInstruction *target_inst = instruction->target->child;
- ZigType *enum_type = ir_resolve_type(ira, target_inst);
+ ZigType *enum_type = ir_resolve_type(ira, target_inst, ZigTypeIdInvalid);
if (type_is_invalid(enum_type))
return ira->codegen->invalid_instruction;
@@ -20654,7 +20623,7 @@ static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruct
return ira->codegen->invalid_instruction;
}
} else {
- ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'",
+ ir_add_error(ira, target_inst, buf_sprintf("expected enum or union type, found '%s'",
buf_ptr(&enum_type->name)));
return ira->codegen->invalid_instruction;
}
@@ -20808,7 +20777,7 @@ static IrInstruction *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInst
if (coro_handle->value.type->id != ZigTypeIdPromise ||
coro_handle->value.type->data.promise.result_type == nullptr)
{
- ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
+ ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T type, found '%s'",
buf_ptr(&coro_handle->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -20839,7 +20808,7 @@ static IrInstruction *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, I
}
static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
- ZigType *operand_type = ir_resolve_type(ira, op);
+ ZigType *operand_type = ir_resolve_type(ira, op, ZigTypeIdInvalid);
if (type_is_invalid(operand_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20969,12 +20938,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
}
static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
- ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->child);
+ ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->child, ZigTypeIdInvalid);
if (type_is_invalid(promise_type))
return ira->codegen->invalid_instruction;
if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {
- ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
+ ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T type, found '%s'",
buf_ptr(&promise_type->name)));
return ira->codegen->invalid_instruction;
}
@@ -20983,7 +20952,7 @@ static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira,
}
static IrInstruction *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
- ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->child);
+ ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->child, ZigTypeIdInvalid);
if (type_is_invalid(promise_result_type))
return ira->codegen->invalid_instruction;
@@ -21046,7 +21015,7 @@ static IrInstruction *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *i
}
static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
- ZigType *float_type = ir_resolve_type(ira, instruction->type->child);
+ ZigType *float_type = ir_resolve_type(ira, instruction->type->child, ZigTypeIdInvalid);
if (type_is_invalid(float_type))
return ira->codegen->invalid_instruction;
@@ -21113,7 +21082,7 @@ static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionS
}
static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {
- ZigType *int_type = ir_resolve_type(ira, instruction->type->child);
+ ZigType *int_type = ir_resolve_type(ira, instruction->type->child, ZigTypeIdInvalid);
if (type_is_invalid(int_type))
return ira->codegen->invalid_instruction;
@@ -21169,7 +21138,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
}
static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {
- ZigType *int_type = ir_resolve_type(ira, instruction->type->child);
+ ZigType *int_type = ir_resolve_type(ira, instruction->type->child, ZigTypeIdInvalid);
if (type_is_invalid(int_type))
return ira->codegen->invalid_instruction;
@@ -21240,7 +21209,7 @@ static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstr
if (target->value.type->id != ZigTypeIdEnum) {
ir_add_error(ira, instruction->target,
- buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));
+ buf_sprintf("expected enum type, found '%s'", buf_ptr(&target->value.type->name)));
return ira->codegen->invalid_instruction;
}
@@ -21255,16 +21224,10 @@ static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstr
static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->child;
- ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value, ZigTypeIdEnum);
if (type_is_invalid(dest_type))
return ira->codegen->invalid_instruction;
- if (dest_type->id != ZigTypeIdEnum) {
- ir_add_error(ira, instruction->dest_type,
- buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
- return ira->codegen->invalid_instruction;
- }
-
if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
return ira->codegen->invalid_instruction;