authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-19 19:54:51-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-19 19:54:51-05:00
log3ea4f264ffa4a189bc489113fe4ae24741e78466
tree5d0a1232fe984e456306664c270f42d29835466b
parent2419f0c91436106f85ea8b6ec183cdaea438a1d0

IR: update all error messages to be useful if generic instantiation


1 files changed, 73 insertions(+), 71 deletions(-)

src/ir.cpp+73-71
...@@ -4286,17 +4286,19 @@ static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg...@@ -4286,17 +4286,19 @@ static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg
4286 add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);4286 add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
4287}4287}
42884288
4289// TODO migrate the rest of the add_node_error errors to use this so that we get better4289static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {
4290// messages for generic instantiations
4291static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
4292 ira->new_irb.exec->invalid = true;4290 ira->new_irb.exec->invalid = true;
4293 ErrorMsg *err_msg = add_node_error(ira->codegen, source_instruction->source_node, msg);4291 ErrorMsg *err_msg = add_node_error(ira->codegen, source_node, msg);
4294 if (ira->new_irb.exec->parent_exec) {4292 if (ira->new_irb.exec->parent_exec) {
4295 add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10);4293 add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10);
4296 }4294 }
4297 return err_msg;4295 return err_msg;
4298}4296}
42994297
4298static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
4299 return ir_add_error_node(ira, source_instruction->source_node, msg);
4300}
4301
4300static IrInstruction *ir_exec_const_result(IrExecutable *exec) {4302static IrInstruction *ir_exec_const_result(IrExecutable *exec) {
4301 if (exec->basic_block_list.length != 1)4303 if (exec->basic_block_list.length != 1)
4302 return nullptr;4304 return nullptr;
...@@ -4546,7 +4548,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -4546,7 +4548,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
4546 return ira->codegen->builtin_types.entry_invalid;4548 return ira->codegen->builtin_types.entry_invalid;
4547 }4549 }
4548 } else {4550 } else {
4549 ErrorMsg *msg = add_node_error(ira->codegen, source_node,4551 ErrorMsg *msg = ir_add_error_node(ira, source_node,
4550 buf_sprintf("incompatible types: '%s' and '%s'",4552 buf_sprintf("incompatible types: '%s' and '%s'",
4551 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));4553 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
4552 add_error_note(ira->codegen, msg, prev_inst->source_node,4554 add_error_note(ira->codegen, msg, prev_inst->source_node,
...@@ -4561,11 +4563,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -4561,11 +4563,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
4561 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||4563 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
4562 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)4564 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
4563 {4565 {
4564 add_node_error(ira->codegen, source_node,4566 ir_add_error_node(ira, source_node,
4565 buf_sprintf("unable to make error union out of number literal"));4567 buf_sprintf("unable to make error union out of number literal"));
4566 return ira->codegen->builtin_types.entry_invalid;4568 return ira->codegen->builtin_types.entry_invalid;
4567 } else if (prev_inst->type_entry->id == TypeTableEntryIdNullLit) {4569 } else if (prev_inst->type_entry->id == TypeTableEntryIdNullLit) {
4568 add_node_error(ira->codegen, source_node,4570 ir_add_error_node(ira, source_node,
4569 buf_sprintf("unable to make error union out of null literal"));4571 buf_sprintf("unable to make error union out of null literal"));
4570 return ira->codegen->builtin_types.entry_invalid;4572 return ira->codegen->builtin_types.entry_invalid;
4571 } else {4573 } else {
...@@ -4575,7 +4577,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -4575,7 +4577,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
4575 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||4577 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
4576 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)4578 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
4577 {4579 {
4578 add_node_error(ira->codegen, source_node,4580 ir_add_error_node(ira, source_node,
4579 buf_sprintf("unable to make maybe out of number literal"));4581 buf_sprintf("unable to make maybe out of number literal"));
4580 return ira->codegen->builtin_types.entry_invalid;4582 return ira->codegen->builtin_types.entry_invalid;
4581 } else {4583 } else {
...@@ -4878,7 +4880,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -4878,7 +4880,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
4878 return nullptr;4880 return nullptr;
48794881
4880 if (fn_value->type_entry->id != TypeTableEntryIdFn) {4882 if (fn_value->type_entry->id != TypeTableEntryIdFn) {
4881 add_node_error(ira->codegen, fn_value->source_node,4883 ir_add_error_node(ira, fn_value->source_node,
4882 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->type_entry->name)));4884 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->type_entry->name)));
4883 return nullptr;4885 return nullptr;
4884 }4886 }
...@@ -5114,7 +5116,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -5114,7 +5116,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
5114 if (actual_type->data.array.len % child_type_size == 0) {5116 if (actual_type->data.array.len % child_type_size == 0) {
5115 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBytesToSlice, true);5117 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBytesToSlice, true);
5116 } else {5118 } else {
5117 add_node_error(ira->codegen, source_instr->source_node,5119 ir_add_error_node(ira, source_instr->source_node,
5118 buf_sprintf("unable to convert %s to %s: size mismatch",5120 buf_sprintf("unable to convert %s to %s: size mismatch",
5119 buf_ptr(&actual_type->name), buf_ptr(&wanted_type->name)));5121 buf_ptr(&actual_type->name), buf_ptr(&wanted_type->name)));
5120 return ira->codegen->invalid_instruction;5122 return ira->codegen->invalid_instruction;
...@@ -5222,7 +5224,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -5222,7 +5224,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
5222 {5224 {
5223 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpErrToInt, false);5225 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpErrToInt, false);
5224 } else {5226 } else {
5225 add_node_error(ira->codegen, source_instr->source_node,5227 ir_add_error_node(ira, source_instr->source_node,
5226 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));5228 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
5227 return ira->codegen->invalid_instruction;5229 return ira->codegen->invalid_instruction;
5228 }5230 }
...@@ -5257,7 +5259,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -5257,7 +5259,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
5257 }5259 }
5258 }5260 }
52595261
5260 add_node_error(ira->codegen, source_instr->source_node,5262 ir_add_error_node(ira, source_instr->source_node,
5261 buf_sprintf("invalid cast from type '%s' to '%s'",5263 buf_sprintf("invalid cast from type '%s' to '%s'",
5262 buf_ptr(&actual_type->name),5264 buf_ptr(&actual_type->name),
5263 buf_ptr(&wanted_type->name)));5265 buf_ptr(&wanted_type->name)));
...@@ -5329,7 +5331,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -5329,7 +5331,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
5329 return ira->codegen->invalid_instruction;5331 return ira->codegen->invalid_instruction;
5330 }5332 }
5331 } else {5333 } else {
5332 add_node_error(ira->codegen, source_instruction->source_node,5334 ir_add_error_node(ira, source_instruction->source_node,
5333 buf_sprintf("attempt to dereference non pointer type '%s'",5335 buf_sprintf("attempt to dereference non pointer type '%s'",
5334 buf_ptr(&type_entry->name)));5336 buf_ptr(&type_entry->name)));
5335 return ira->codegen->invalid_instruction;5337 return ira->codegen->invalid_instruction;
...@@ -5534,7 +5536,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -5534,7 +5536,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
5534 case TypeTableEntryIdBlock:5536 case TypeTableEntryIdBlock:
5535 case TypeTableEntryIdBoundFn:5537 case TypeTableEntryIdBoundFn:
5536 if (!is_equality_cmp) {5538 if (!is_equality_cmp) {
5537 add_node_error(ira->codegen, source_node,5539 ir_add_error_node(ira, source_node,
5538 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));5540 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
5539 return ira->codegen->builtin_types.entry_invalid;5541 return ira->codegen->builtin_types.entry_invalid;
5540 }5542 }
...@@ -5542,7 +5544,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -5542,7 +5544,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
55425544
5543 case TypeTableEntryIdEnum:5545 case TypeTableEntryIdEnum:
5544 if (!is_equality_cmp || resolved_type->data.enumeration.gen_field_count != 0) {5546 if (!is_equality_cmp || resolved_type->data.enumeration.gen_field_count != 0) {
5545 add_node_error(ira->codegen, source_node,5547 ir_add_error_node(ira, source_node,
5546 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));5548 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
5547 return ira->codegen->builtin_types.entry_invalid;5549 return ira->codegen->builtin_types.entry_invalid;
5548 }5550 }
...@@ -5556,7 +5558,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -5556,7 +5558,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
5556 case TypeTableEntryIdMaybe:5558 case TypeTableEntryIdMaybe:
5557 case TypeTableEntryIdErrorUnion:5559 case TypeTableEntryIdErrorUnion:
5558 case TypeTableEntryIdUnion:5560 case TypeTableEntryIdUnion:
5559 add_node_error(ira->codegen, source_node,5561 ir_add_error_node(ira, source_node,
5560 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));5562 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
5561 return ira->codegen->builtin_types.entry_invalid;5563 return ira->codegen->builtin_types.entry_invalid;
55625564
...@@ -5741,7 +5743,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -5741,7 +5743,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
5741 // float5743 // float
5742 } else {5744 } else {
5743 AstNode *source_node = bin_op_instruction->base.source_node;5745 AstNode *source_node = bin_op_instruction->base.source_node;
5744 add_node_error(ira->codegen, source_node,5746 ir_add_error_node(ira, source_node,
5745 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",5747 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
5746 buf_ptr(&op1->type_entry->name),5748 buf_ptr(&op1->type_entry->name),
5747 buf_ptr(&op2->type_entry->name)));5749 buf_ptr(&op2->type_entry->name)));
...@@ -5767,11 +5769,11 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -5767,11 +5769,11 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
5767 int err;5769 int err;
5768 if ((err = ir_eval_math_op(op1_val, resolved_type, op_id, op2_val, resolved_type, out_val))) {5770 if ((err = ir_eval_math_op(op1_val, resolved_type, op_id, op2_val, resolved_type, out_val))) {
5769 if (err == ErrorDivByZero) {5771 if (err == ErrorDivByZero) {
5770 add_node_error(ira->codegen, bin_op_instruction->base.source_node,5772 ir_add_error_node(ira, bin_op_instruction->base.source_node,
5771 buf_sprintf("division by zero is undefined"));5773 buf_sprintf("division by zero is undefined"));
5772 return ira->codegen->builtin_types.entry_invalid;5774 return ira->codegen->builtin_types.entry_invalid;
5773 } else if (err == ErrorOverflow) {5775 } else if (err == ErrorOverflow) {
5774 add_node_error(ira->codegen, bin_op_instruction->base.source_node,5776 ir_add_error_node(ira, bin_op_instruction->base.source_node,
5775 buf_sprintf("value cannot be represented in any integer type"));5777 buf_sprintf("value cannot be represented in any integer type"));
5776 return ira->codegen->builtin_types.entry_invalid;5778 return ira->codegen->builtin_types.entry_invalid;
5777 }5779 }
...@@ -6037,7 +6039,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -6037,7 +6039,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
6037 case TypeTableEntryIdNumLitFloat:6039 case TypeTableEntryIdNumLitFloat:
6038 case TypeTableEntryIdNumLitInt:6040 case TypeTableEntryIdNumLitInt:
6039 if (is_export || is_extern || casted_init_value->static_value.special == ConstValSpecialRuntime) {6041 if (is_export || is_extern || casted_init_value->static_value.special == ConstValSpecialRuntime) {
6040 add_node_error(ira->codegen, source_node, buf_sprintf("unable to infer variable type"));6042 ir_add_error_node(ira, source_node, buf_sprintf("unable to infer variable type"));
6041 result_type = ira->codegen->builtin_types.entry_invalid;6043 result_type = ira->codegen->builtin_types.entry_invalid;
6042 }6044 }
6043 break;6045 break;
...@@ -6045,14 +6047,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc...@@ -6045,14 +6047,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
6045 case TypeTableEntryIdVar:6047 case TypeTableEntryIdVar:
6046 case TypeTableEntryIdBlock:6048 case TypeTableEntryIdBlock:
6047 case TypeTableEntryIdNullLit:6049 case TypeTableEntryIdNullLit:
6048 add_node_error(ira->codegen, source_node,6050 ir_add_error_node(ira, source_node,
6049 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));6051 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));
6050 result_type = ira->codegen->builtin_types.entry_invalid;6052 result_type = ira->codegen->builtin_types.entry_invalid;
6051 break;6053 break;
6052 case TypeTableEntryIdMetaType:6054 case TypeTableEntryIdMetaType:
6053 case TypeTableEntryIdNamespace:6055 case TypeTableEntryIdNamespace:
6054 if (casted_init_value->static_value.special == ConstValSpecialRuntime) {6056 if (casted_init_value->static_value.special == ConstValSpecialRuntime) {
6055 add_node_error(ira->codegen, source_node,6057 ir_add_error_node(ira, source_node,
6056 buf_sprintf("variable of type '%s' must be constant", buf_ptr(&result_type->name)));6058 buf_sprintf("variable of type '%s' must be constant", buf_ptr(&result_type->name)));
6057 result_type = ira->codegen->builtin_types.entry_invalid;6059 result_type = ira->codegen->builtin_types.entry_invalid;
6058 }6060 }
...@@ -6212,7 +6214,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -6212,7 +6214,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
62126214
6213 if (fn_type_id->is_var_args) {6215 if (fn_type_id->is_var_args) {
6214 if (call_param_count < src_param_count) {6216 if (call_param_count < src_param_count) {
6215 ErrorMsg *msg = add_node_error(ira->codegen, source_node,6217 ErrorMsg *msg = ir_add_error_node(ira, source_node,
6216 buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count));6218 buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count));
6217 if (fn_proto_node) {6219 if (fn_proto_node) {
6218 add_error_note(ira->codegen, msg, fn_proto_node,6220 add_error_note(ira->codegen, msg, fn_proto_node,
...@@ -6221,7 +6223,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -6221,7 +6223,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
6221 return ira->codegen->builtin_types.entry_invalid;6223 return ira->codegen->builtin_types.entry_invalid;
6222 }6224 }
6223 } else if (src_param_count != call_param_count) {6225 } else if (src_param_count != call_param_count) {
6224 ErrorMsg *msg = add_node_error(ira->codegen, source_node,6226 ErrorMsg *msg = ir_add_error_node(ira, source_node,
6225 buf_sprintf("expected %zu arguments, found %zu", src_param_count, call_param_count));6227 buf_sprintf("expected %zu arguments, found %zu", src_param_count, call_param_count));
6226 if (fn_proto_node) {6228 if (fn_proto_node) {
6227 add_error_note(ira->codegen, msg, fn_proto_node,6229 add_error_note(ira->codegen, msg, fn_proto_node,
...@@ -6446,7 +6448,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -6446,7 +6448,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
6446 size_t actual_param_count = call_instruction->arg_count;6448 size_t actual_param_count = call_instruction->arg_count;
64476449
6448 if (actual_param_count != 1) {6450 if (actual_param_count != 1) {
6449 add_node_error(ira->codegen, call_instruction->base.source_node,6451 ir_add_error_node(ira, call_instruction->base.source_node,
6450 buf_sprintf("cast expression expects exactly one parameter"));6452 buf_sprintf("cast expression expects exactly one parameter"));
6451 return ira->codegen->builtin_types.entry_invalid;6453 return ira->codegen->builtin_types.entry_invalid;
6452 }6454 }
...@@ -6470,7 +6472,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -6470,7 +6472,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
6470 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,6472 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
6471 nullptr, first_arg_ptr, is_inline);6473 nullptr, first_arg_ptr, is_inline);
6472 } else {6474 } else {
6473 add_node_error(ira->codegen, fn_ref->source_node,6475 ir_add_error_node(ira, fn_ref->source_node,
6474 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));6476 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));
6475 return ira->codegen->builtin_types.entry_invalid;6477 return ira->codegen->builtin_types.entry_invalid;
6476 }6478 }
...@@ -6480,7 +6482,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction...@@ -6480,7 +6482,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
6480 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->type_entry,6482 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->type_entry,
6481 fn_ref, nullptr, false);6483 fn_ref, nullptr, false);
6482 } else {6484 } else {
6483 add_node_error(ira->codegen, fn_ref->source_node,6485 ir_add_error_node(ira, fn_ref->source_node,
6484 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));6486 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));
6485 return ira->codegen->builtin_types.entry_invalid;6487 return ira->codegen->builtin_types.entry_invalid;
6486 }6488 }
...@@ -6531,7 +6533,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct...@@ -6531,7 +6533,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
6531 case TypeTableEntryIdBlock:6533 case TypeTableEntryIdBlock:
6532 case TypeTableEntryIdUnreachable:6534 case TypeTableEntryIdUnreachable:
6533 case TypeTableEntryIdVar:6535 case TypeTableEntryIdVar:
6534 add_node_error(ira->codegen, un_op_instruction->base.source_node,6536 ir_add_error_node(ira, un_op_instruction->base.source_node,
6535 buf_sprintf("unable to wrap type '%s' in error type", buf_ptr(&meta_type->name)));6537 buf_sprintf("unable to wrap type '%s' in error type", buf_ptr(&meta_type->name)));
6536 // TODO if meta_type is type decl, add note pointing to type decl declaration6538 // TODO if meta_type is type decl, add note pointing to type decl declaration
6537 return ira->codegen->builtin_types.entry_invalid;6539 return ira->codegen->builtin_types.entry_invalid;
...@@ -6550,7 +6552,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp...@@ -6550,7 +6552,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
6550 } else if (ptr_type->id == TypeTableEntryIdPointer) {6552 } else if (ptr_type->id == TypeTableEntryIdPointer) {
6551 child_type = ptr_type->data.pointer.child_type;6553 child_type = ptr_type->data.pointer.child_type;
6552 } else {6554 } else {
6553 add_node_error(ira->codegen, un_op_instruction->base.source_node,6555 ir_add_error_node(ira, un_op_instruction->base.source_node,
6554 buf_sprintf("attempt to dereference non-pointer type '%s'",6556 buf_sprintf("attempt to dereference non-pointer type '%s'",
6555 buf_ptr(&ptr_type->name)));6557 buf_ptr(&ptr_type->name)));
6556 return ira->codegen->builtin_types.entry_invalid;6558 return ira->codegen->builtin_types.entry_invalid;
...@@ -6608,7 +6610,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -6608,7 +6610,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
6608 return ira->codegen->builtin_types.entry_type;6610 return ira->codegen->builtin_types.entry_type;
6609 }6611 }
6610 case TypeTableEntryIdUnreachable:6612 case TypeTableEntryIdUnreachable:
6611 add_node_error(ira->codegen, un_op_instruction->base.source_node,6613 ir_add_error_node(ira, un_op_instruction->base.source_node,
6612 buf_sprintf("type '%s' not nullable", buf_ptr(&type_entry->name)));6614 buf_sprintf("type '%s' not nullable", buf_ptr(&type_entry->name)));
6613 // TODO if it's a type decl, put an error note here pointing to the decl6615 // TODO if it's a type decl, put an error note here pointing to the decl
6614 return ira->codegen->builtin_types.entry_invalid;6616 return ira->codegen->builtin_types.entry_invalid;
...@@ -6813,7 +6815,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -6813,7 +6815,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
6813 if (resolved_type->id == TypeTableEntryIdNumLitFloat ||6815 if (resolved_type->id == TypeTableEntryIdNumLitFloat ||
6814 resolved_type->id == TypeTableEntryIdNumLitInt)6816 resolved_type->id == TypeTableEntryIdNumLitInt)
6815 {6817 {
6816 add_node_error(ira->codegen, phi_instruction->base.source_node,6818 ir_add_error_node(ira, phi_instruction->base.source_node,
6817 buf_sprintf("unable to infer expression type"));6819 buf_sprintf("unable to infer expression type"));
6818 return ira->codegen->builtin_types.entry_invalid;6820 return ira->codegen->builtin_types.entry_invalid;
6819 }6821 }
...@@ -6891,7 +6893,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -6891,7 +6893,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
6891 return array_type;6893 return array_type;
6892 } else if (array_type->id == TypeTableEntryIdArray) {6894 } else if (array_type->id == TypeTableEntryIdArray) {
6893 if (array_type->data.array.len == 0) {6895 if (array_type->data.array.len == 0) {
6894 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,6896 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
6895 buf_sprintf("index 0 outside array of size 0"));6897 buf_sprintf("index 0 outside array of size 0"));
6896 }6898 }
6897 TypeTableEntry *child_type = array_type->data.array.child_type;6899 TypeTableEntry *child_type = array_type->data.array.child_type;
...@@ -6901,7 +6903,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -6901,7 +6903,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
6901 } else if (is_slice(array_type)) {6903 } else if (is_slice(array_type)) {
6902 return_type = array_type->data.structure.fields[0].type_entry;6904 return_type = array_type->data.structure.fields[0].type_entry;
6903 } else {6905 } else {
6904 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,6906 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
6905 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));6907 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
6906 return ira->codegen->builtin_types.entry_invalid;6908 return ira->codegen->builtin_types.entry_invalid;
6907 }6909 }
...@@ -6917,7 +6919,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -6917,7 +6919,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
6917 if (array_type->id == TypeTableEntryIdArray) {6919 if (array_type->id == TypeTableEntryIdArray) {
6918 uint64_t array_len = array_type->data.array.len;6920 uint64_t array_len = array_type->data.array.len;
6919 if (index >= array_len) {6921 if (index >= array_len) {
6920 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,6922 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
6921 buf_sprintf("index %" PRIu64 " outside array of size %" PRIu64,6923 buf_sprintf("index %" PRIu64 " outside array of size %" PRIu64,
6922 index, array_len));6924 index, array_len));
6923 return ira->codegen->builtin_types.entry_invalid;6925 return ira->codegen->builtin_types.entry_invalid;
...@@ -6948,7 +6950,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -6948,7 +6950,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
6948 old_size = mem_size - offset;6950 old_size = mem_size - offset;
6949 }6951 }
6950 if (new_index >= mem_size) {6952 if (new_index >= mem_size) {
6951 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,6953 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
6952 buf_sprintf("index %" PRIu64 " outside pointer of size %" PRIu64, index, old_size));6954 buf_sprintf("index %" PRIu64 " outside pointer of size %" PRIu64, index, old_size));
6953 return ira->codegen->builtin_types.entry_invalid;6955 return ira->codegen->builtin_types.entry_invalid;
6954 }6956 }
...@@ -6959,7 +6961,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -6959,7 +6961,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
6959 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];6961 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
6960 uint64_t slice_len = len_field->data.x_bignum.data.x_uint;6962 uint64_t slice_len = len_field->data.x_bignum.data.x_uint;
6961 if (index >= slice_len) {6963 if (index >= slice_len) {
6962 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,6964 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
6963 buf_sprintf("index %" PRIu64 " outside slice of size %" PRIu64,6965 buf_sprintf("index %" PRIu64 " outside slice of size %" PRIu64,
6964 index, slice_len));6966 index, slice_len));
6965 return ira->codegen->builtin_types.entry_invalid;6967 return ira->codegen->builtin_types.entry_invalid;
...@@ -7009,7 +7011,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -7009,7 +7011,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
7009 return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value);7011 return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value);
7010 }7012 }
7011 }7013 }
7012 add_node_error(ira->codegen, field_ptr_instruction->base.source_node,7014 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
7013 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&bare_struct_type->name)));7015 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&bare_struct_type->name)));
7014 return ira->codegen->builtin_types.entry_invalid;7016 return ira->codegen->builtin_types.entry_invalid;
7015}7017}
...@@ -7138,7 +7140,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -7138,7 +7140,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
7138 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,7140 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
7139 usize, false, ConstPtrSpecialNone, ptr_is_const);7141 usize, false, ConstPtrSpecialNone, ptr_is_const);
7140 } else {7142 } else {
7141 add_node_error(ira->codegen, source_node,7143 ir_add_error_node(ira, source_node,
7142 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),7144 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
7143 buf_ptr(&container_type->name)));7145 buf_ptr(&container_type->name)));
7144 return ira->codegen->builtin_types.entry_invalid;7146 return ira->codegen->builtin_types.entry_invalid;
...@@ -7253,7 +7255,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -7253,7 +7255,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
7253 if (tld->visib_mod == VisibModPrivate &&7255 if (tld->visib_mod == VisibModPrivate &&
7254 tld->import != source_node->owner)7256 tld->import != source_node->owner)
7255 {7257 {
7256 ErrorMsg *msg = add_node_error(ira->codegen, source_node,7258 ErrorMsg *msg = ir_add_error_node(ira, source_node,
7257 buf_sprintf("'%s' is private", buf_ptr(field_name)));7259 buf_sprintf("'%s' is private", buf_ptr(field_name)));
7258 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));7260 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
7259 return ira->codegen->builtin_types.entry_invalid;7261 return ira->codegen->builtin_types.entry_invalid;
...@@ -7261,12 +7263,12 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -7261,12 +7263,12 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
7261 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var);7263 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var);
7262 } else {7264 } else {
7263 const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";7265 const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";
7264 add_node_error(ira->codegen, source_node,7266 ir_add_error_node(ira, source_node,
7265 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name));7267 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name));
7266 return ira->codegen->builtin_types.entry_invalid;7268 return ira->codegen->builtin_types.entry_invalid;
7267 }7269 }
7268 } else {7270 } else {
7269 add_node_error(ira->codegen, field_ptr_instruction->base.source_node,7271 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
7270 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));7272 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
7271 return ira->codegen->builtin_types.entry_invalid;7273 return ira->codegen->builtin_types.entry_invalid;
7272 }7274 }
...@@ -7348,7 +7350,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi...@@ -7348,7 +7350,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
7348 case TypeTableEntryIdInvalid:7350 case TypeTableEntryIdInvalid:
7349 return type_entry;7351 return type_entry;
7350 case TypeTableEntryIdVar:7352 case TypeTableEntryIdVar:
7351 add_node_error(ira->codegen, expr_value->source_node,7353 ir_add_error_node(ira, expr_value->source_node,
7352 buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name)));7354 buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name)));
7353 return ira->codegen->builtin_types.entry_invalid;7355 return ira->codegen->builtin_types.entry_invalid;
7354 case TypeTableEntryIdNumLitFloat:7356 case TypeTableEntryIdNumLitFloat:
...@@ -7402,7 +7404,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,...@@ -7402,7 +7404,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
7402 } else if (is_slice(type_entry)) {7404 } else if (is_slice(type_entry)) {
7403 ptr_type = type_entry->data.structure.fields[0].type_entry;7405 ptr_type = type_entry->data.structure.fields[0].type_entry;
7404 } else {7406 } else {
7405 add_node_error(ira->codegen, to_ptr_type_instruction->base.source_node,7407 ir_add_error_node(ira, to_ptr_type_instruction->base.source_node,
7406 buf_sprintf("expected array type, found '%s'", buf_ptr(&type_entry->name)));7408 buf_sprintf("expected array type, found '%s'", buf_ptr(&type_entry->name)));
7407 return ira->codegen->builtin_types.entry_invalid;7409 return ira->codegen->builtin_types.entry_invalid;
7408 }7410 }
...@@ -7423,7 +7425,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -7423,7 +7425,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
74237425
7424 // TODO handle typedefs7426 // TODO handle typedefs
7425 if (type_entry->id != TypeTableEntryIdPointer) {7427 if (type_entry->id != TypeTableEntryIdPointer) {
7426 add_node_error(ira->codegen, ptr_type_child_instruction->base.source_node,7428 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
7427 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));7429 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
7428 return ira->codegen->builtin_types.entry_invalid;7430 return ira->codegen->builtin_types.entry_invalid;
7429 }7431 }
...@@ -7468,7 +7470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,...@@ -7468,7 +7470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,
74687470
7469 AstNode *source_node = set_fn_visible_instruction->base.source_node;7471 AstNode *source_node = set_fn_visible_instruction->base.source_node;
7470 if (fn_entry->fn_export_set_node) {7472 if (fn_entry->fn_export_set_node) {
7471 ErrorMsg *msg = add_node_error(ira->codegen, source_node,7473 ErrorMsg *msg = ir_add_error_node(ira, source_node,
7472 buf_sprintf("function visibility set twice"));7474 buf_sprintf("function visibility set twice"));
7473 add_error_note(ira->codegen, msg, fn_entry->fn_export_set_node, buf_sprintf("first set here"));7475 add_error_note(ira->codegen, msg, fn_entry->fn_export_set_node, buf_sprintf("first set here"));
7474 return ira->codegen->builtin_types.entry_invalid;7476 return ira->codegen->builtin_types.entry_invalid;
...@@ -7477,7 +7479,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,...@@ -7477,7 +7479,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,
74777479
7478 AstNodeFnProto *fn_proto = &fn_entry->proto_node->data.fn_proto;7480 AstNodeFnProto *fn_proto = &fn_entry->proto_node->data.fn_proto;
7479 if (fn_proto->visib_mod != VisibModExport) {7481 if (fn_proto->visib_mod != VisibModExport) {
7480 ErrorMsg *msg = add_node_error(ira->codegen, source_node,7482 ErrorMsg *msg = ir_add_error_node(ira, source_node,
7481 buf_sprintf("function must be marked export to set function visibility"));7483 buf_sprintf("function must be marked export to set function visibility"));
7482 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("function declared here"));7484 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("function declared here"));
7483 return ira->codegen->builtin_types.entry_invalid;7485 return ira->codegen->builtin_types.entry_invalid;
...@@ -7520,14 +7522,14 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -7520,14 +7522,14 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
7520 } else if (type_arg->id == TypeTableEntryIdUnion) {7522 } else if (type_arg->id == TypeTableEntryIdUnion) {
7521 decls_scope = type_arg->data.unionation.decls_scope;7523 decls_scope = type_arg->data.unionation.decls_scope;
7522 } else {7524 } else {
7523 add_node_error(ira->codegen, target_instruction->source_node,7525 ir_add_error_node(ira, target_instruction->source_node,
7524 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));7526 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
7525 return ira->codegen->builtin_types.entry_invalid;7527 return ira->codegen->builtin_types.entry_invalid;
7526 }7528 }
7527 safety_off_ptr = &decls_scope->safety_off;7529 safety_off_ptr = &decls_scope->safety_off;
7528 safety_set_node_ptr = &decls_scope->safety_set_node;7530 safety_set_node_ptr = &decls_scope->safety_set_node;
7529 } else {7531 } else {
7530 add_node_error(ira->codegen, target_instruction->source_node,7532 ir_add_error_node(ira, target_instruction->source_node,
7531 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));7533 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
7532 return ira->codegen->builtin_types.entry_invalid;7534 return ira->codegen->builtin_types.entry_invalid;
7533 }7535 }
...@@ -7539,7 +7541,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -7539,7 +7541,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
75397541
7540 AstNode *source_node = set_debug_safety_instruction->base.source_node;7542 AstNode *source_node = set_debug_safety_instruction->base.source_node;
7541 if (*safety_set_node_ptr) {7543 if (*safety_set_node_ptr) {
7542 ErrorMsg *msg = add_node_error(ira->codegen, source_node,7544 ErrorMsg *msg = ir_add_error_node(ira, source_node,
7543 buf_sprintf("function test attribute set twice"));7545 buf_sprintf("function test attribute set twice"));
7544 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));7546 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
7545 return ira->codegen->builtin_types.entry_invalid;7547 return ira->codegen->builtin_types.entry_invalid;
...@@ -7571,7 +7573,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -7571,7 +7573,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
7571 case TypeTableEntryIdUndefLit:7573 case TypeTableEntryIdUndefLit:
7572 case TypeTableEntryIdNullLit:7574 case TypeTableEntryIdNullLit:
7573 case TypeTableEntryIdBlock:7575 case TypeTableEntryIdBlock:
7574 add_node_error(ira->codegen, slice_type_instruction->base.source_node,7576 ir_add_error_node(ira, slice_type_instruction->base.source_node,
7575 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&resolved_child_type->name)));7577 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&resolved_child_type->name)));
7576 // TODO if this is a typedecl, add error note showing the declaration of the type decl7578 // TODO if this is a typedecl, add error note showing the declaration of the type decl
7577 return ira->codegen->builtin_types.entry_invalid;7579 return ira->codegen->builtin_types.entry_invalid;
...@@ -7660,7 +7662,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -7660,7 +7662,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
7660 case TypeTableEntryIdUndefLit:7662 case TypeTableEntryIdUndefLit:
7661 case TypeTableEntryIdNullLit:7663 case TypeTableEntryIdNullLit:
7662 case TypeTableEntryIdBlock:7664 case TypeTableEntryIdBlock:
7663 add_node_error(ira->codegen, array_type_instruction->base.source_node,7665 ir_add_error_node(ira, array_type_instruction->base.source_node,
7664 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));7666 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
7665 // TODO if this is a typedecl, add error note showing the declaration of the type decl7667 // TODO if this is a typedecl, add error note showing the declaration of the type decl
7666 return ira->codegen->builtin_types.entry_invalid;7668 return ira->codegen->builtin_types.entry_invalid;
...@@ -7726,7 +7728,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira,...@@ -7726,7 +7728,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira,
7726 out_val->data.x_enum.tag = ira->codegen->target_oformat_index;7728 out_val->data.x_enum.tag = ira->codegen->target_oformat_index;
7727 return ira->codegen->builtin_types.entry_oformat_enum;7729 return ira->codegen->builtin_types.entry_oformat_enum;
7728 } else {7730 } else {
7729 add_node_error(ira->codegen, name_value->source_node,7731 ir_add_error_node(ira, name_value->source_node,
7730 buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(var_name)));7732 buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(var_name)));
7731 return ira->codegen->builtin_types.entry_invalid;7733 return ira->codegen->builtin_types.entry_invalid;
7732 }7734 }
...@@ -7755,7 +7757,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -7755,7 +7757,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
7755 case TypeTableEntryIdMetaType:7757 case TypeTableEntryIdMetaType:
7756 case TypeTableEntryIdFn:7758 case TypeTableEntryIdFn:
7757 case TypeTableEntryIdNamespace:7759 case TypeTableEntryIdNamespace:
7758 add_node_error(ira->codegen, size_of_instruction->base.source_node,7760 ir_add_error_node(ira, size_of_instruction->base.source_node,
7759 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));7761 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
7760 // TODO if this is a typedecl, add error note showing the declaration of the type decl7762 // TODO if this is a typedecl, add error note showing the declaration of the type decl
7761 return ira->codegen->builtin_types.entry_invalid;7763 return ira->codegen->builtin_types.entry_invalid;
...@@ -7831,7 +7833,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -7831,7 +7833,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
7831 if (type_entry->id == TypeTableEntryIdInvalid) {7833 if (type_entry->id == TypeTableEntryIdInvalid) {
7832 return ira->codegen->builtin_types.entry_invalid;7834 return ira->codegen->builtin_types.entry_invalid;
7833 } else if (type_entry->id != TypeTableEntryIdMaybe) {7835 } else if (type_entry->id != TypeTableEntryIdMaybe) {
7834 add_node_error(ira->codegen, unwrap_maybe_instruction->base.source_node,7836 ir_add_error_node(ira, unwrap_maybe_instruction->base.source_node,
7835 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));7837 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));
7836 return ira->codegen->builtin_types.entry_invalid;7838 return ira->codegen->builtin_types.entry_invalid;
7837 }7839 }
...@@ -7882,7 +7884,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC...@@ -7882,7 +7884,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
7882 ir_build_ctz_from(&ira->new_irb, &ctz_instruction->base, value);7884 ir_build_ctz_from(&ira->new_irb, &ctz_instruction->base, value);
7883 return value->type_entry;7885 return value->type_entry;
7884 } else {7886 } else {
7885 add_node_error(ira->codegen, ctz_instruction->base.source_node,7887 ir_add_error_node(ira, ctz_instruction->base.source_node,
7886 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));7888 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));
7887 return ira->codegen->builtin_types.entry_invalid;7889 return ira->codegen->builtin_types.entry_invalid;
7888 }7890 }
...@@ -7906,7 +7908,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC...@@ -7906,7 +7908,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
7906 ir_build_clz_from(&ira->new_irb, &clz_instruction->base, value);7908 ir_build_clz_from(&ira->new_irb, &clz_instruction->base, value);
7907 return value->type_entry;7909 return value->type_entry;
7908 } else {7910 } else {
7909 add_node_error(ira->codegen, clz_instruction->base.source_node,7911 ir_add_error_node(ira, clz_instruction->base.source_node,
7910 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));7912 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));
7911 return ira->codegen->builtin_types.entry_invalid;7913 return ira->codegen->builtin_types.entry_invalid;
7912 }7914 }
...@@ -8095,7 +8097,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -8095,7 +8097,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
8095 case TypeTableEntryIdUnion:8097 case TypeTableEntryIdUnion:
8096 case TypeTableEntryIdBlock:8098 case TypeTableEntryIdBlock:
8097 case TypeTableEntryIdBoundFn:8099 case TypeTableEntryIdBoundFn:
8098 add_node_error(ira->codegen, switch_target_instruction->base.source_node,8100 ir_add_error_node(ira, switch_target_instruction->base.source_node,
8099 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));8101 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
8100 // TODO if this is a typedecl, add error note showing the declaration of the type decl8102 // TODO if this is a typedecl, add error note showing the declaration of the type decl
8101 return ira->codegen->builtin_types.entry_invalid;8103 return ira->codegen->builtin_types.entry_invalid;
...@@ -8166,12 +8168,12 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -8166,12 +8168,12 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
8166 int err;8168 int err;
8167 if ((err = os_path_real(&full_path, abs_full_path))) {8169 if ((err = os_path_real(&full_path, abs_full_path))) {
8168 if (err == ErrorFileNotFound) {8170 if (err == ErrorFileNotFound) {
8169 add_node_error(ira->codegen, source_node,8171 ir_add_error_node(ira, source_node,
8170 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));8172 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
8171 return ira->codegen->builtin_types.entry_invalid;8173 return ira->codegen->builtin_types.entry_invalid;
8172 } else {8174 } else {
8173 ira->codegen->error_during_imports = true;8175 ira->codegen->error_during_imports = true;
8174 add_node_error(ira->codegen, source_node,8176 ir_add_error_node(ira, source_node,
8175 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));8177 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
8176 return ira->codegen->builtin_types.entry_invalid;8178 return ira->codegen->builtin_types.entry_invalid;
8177 }8179 }
...@@ -8186,11 +8188,11 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi...@@ -8186,11 +8188,11 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
81868188
8187 if ((err = os_fetch_file_path(abs_full_path, import_code))) {8189 if ((err = os_fetch_file_path(abs_full_path, import_code))) {
8188 if (err == ErrorFileNotFound) {8190 if (err == ErrorFileNotFound) {
8189 add_node_error(ira->codegen, source_node,8191 ir_add_error_node(ira, source_node,
8190 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));8192 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
8191 return ira->codegen->builtin_types.entry_invalid;8193 return ira->codegen->builtin_types.entry_invalid;
8192 } else {8194 } else {
8193 add_node_error(ira->codegen, source_node,8195 ir_add_error_node(ira, source_node,
8194 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));8196 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
8195 return ira->codegen->builtin_types.entry_invalid;8197 return ira->codegen->builtin_types.entry_invalid;
8196 }8198 }
...@@ -8233,7 +8235,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,...@@ -8233,7 +8235,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
8233 ir_build_load_ptr_from(&ira->new_irb, &array_len_instruction->base, len_ptr);8235 ir_build_load_ptr_from(&ira->new_irb, &array_len_instruction->base, len_ptr);
8234 return ira->codegen->builtin_types.entry_usize;8236 return ira->codegen->builtin_types.entry_usize;
8235 } else {8237 } else {
8236 add_node_error(ira->codegen, array_len_instruction->base.source_node,8238 ir_add_error_node(ira, array_len_instruction->base.source_node,
8237 buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->type_entry->name)));8239 buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->type_entry->name)));
8238 // TODO if this is a typedecl, add error note showing the declaration of the type decl8240 // TODO if this is a typedecl, add error note showing the declaration of the type decl
8239 return ira->codegen->builtin_types.entry_invalid;8241 return ira->codegen->builtin_types.entry_invalid;
...@@ -8276,7 +8278,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -8276,7 +8278,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
82768278
8277 TypeStructField *type_field = find_struct_type_field(container_type, field->name);8279 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
8278 if (!type_field) {8280 if (!type_field) {
8279 add_node_error(ira->codegen, field->source_node,8281 ir_add_error_node(ira, field->source_node,
8280 buf_sprintf("no member named '%s' in '%s'",8282 buf_sprintf("no member named '%s' in '%s'",
8281 buf_ptr(field->name), buf_ptr(&container_type->name)));8283 buf_ptr(field->name), buf_ptr(&container_type->name)));
8282 return ira->codegen->builtin_types.entry_invalid;8284 return ira->codegen->builtin_types.entry_invalid;
...@@ -8288,7 +8290,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -8288,7 +8290,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
8288 size_t field_index = type_field->src_index;8290 size_t field_index = type_field->src_index;
8289 AstNode *existing_assign_node = field_assign_nodes[field_index];8291 AstNode *existing_assign_node = field_assign_nodes[field_index];
8290 if (existing_assign_node) {8292 if (existing_assign_node) {
8291 ErrorMsg *msg = add_node_error(ira->codegen, field->source_node, buf_sprintf("duplicate field"));8293 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));
8292 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));8294 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
8293 continue;8295 continue;
8294 }8296 }
...@@ -8315,7 +8317,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -8315,7 +8317,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
8315 bool any_missing = false;8317 bool any_missing = false;
8316 for (size_t i = 0; i < actual_field_count; i += 1) {8318 for (size_t i = 0; i < actual_field_count; i += 1) {
8317 if (!field_assign_nodes[i]) {8319 if (!field_assign_nodes[i]) {
8318 add_node_error(ira->codegen, instruction->source_node,8320 ir_add_error_node(ira, instruction->source_node,
8319 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));8321 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));
8320 any_missing = true;8322 any_missing = true;
8321 }8323 }
...@@ -8330,7 +8332,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -8330,7 +8332,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
8330 }8332 }
83318333
8332 if (outside_fn) {8334 if (outside_fn) {
8333 add_node_error(ira->codegen, first_non_const_instruction->source_node,8335 ir_add_error_node(ira, first_non_const_instruction->source_node,
8334 buf_sprintf("unable to evaluate constant expression"));8336 buf_sprintf("unable to evaluate constant expression"));
8335 return ira->codegen->builtin_types.entry_invalid;8337 return ira->codegen->builtin_types.entry_invalid;
8336 }8338 }
...@@ -8401,7 +8403,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -8401,7 +8403,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
8401 }8403 }
84028404
8403 if (outside_fn) {8405 if (outside_fn) {
8404 add_node_error(ira->codegen, first_non_const_instruction->source_node,8406 ir_add_error_node(ira, first_non_const_instruction->source_node,
8405 buf_sprintf("unable to evaluate constant expression"));8407 buf_sprintf("unable to evaluate constant expression"));
8406 return ira->codegen->builtin_types.entry_invalid;8408 return ira->codegen->builtin_types.entry_invalid;
8407 }8409 }
...@@ -8415,13 +8417,13 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -8415,13 +8417,13 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
8415 zig_panic("TODO array container init");8417 zig_panic("TODO array container init");
8416 } else if (container_type->id == TypeTableEntryIdVoid) {8418 } else if (container_type->id == TypeTableEntryIdVoid) {
8417 if (elem_count != 0) {8419 if (elem_count != 0) {
8418 add_node_error(ira->codegen, instruction->base.source_node,8420 ir_add_error_node(ira, instruction->base.source_node,
8419 buf_sprintf("void expression expects no arguments"));8421 buf_sprintf("void expression expects no arguments"));
8420 return ira->codegen->builtin_types.entry_invalid;8422 return ira->codegen->builtin_types.entry_invalid;
8421 }8423 }
8422 return ir_analyze_void(ira, &instruction->base);8424 return ir_analyze_void(ira, &instruction->base);
8423 } else {8425 } else {
8424 add_node_error(ira->codegen, instruction->base.source_node,8426 ir_add_error_node(ira, instruction->base.source_node,
8425 buf_sprintf("type '%s' does not support array initialization",8427 buf_sprintf("type '%s' does not support array initialization",
8426 buf_ptr(&container_type->name)));8428 buf_ptr(&container_type->name)));
8427 return ira->codegen->builtin_types.entry_invalid;8429 return ira->codegen->builtin_types.entry_invalid;
...@@ -8594,7 +8596,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc...@@ -8594,7 +8596,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
8594 }8596 }
85958597
8596 if (errors.length > 0) {8598 if (errors.length > 0) {
8597 ErrorMsg *parent_err_msg = add_node_error(ira->codegen, node, buf_sprintf("C import failed"));8599 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
8598 for (size_t i = 0; i < errors.length; i += 1) {8600 for (size_t i = 0; i < errors.length; i += 1) {
8599 ErrorMsg *err_msg = errors.at(i);8601 ErrorMsg *err_msg = errors.at(i);
8600 err_msg_add_note(parent_err_msg, err_msg);8602 err_msg_add_note(parent_err_msg, err_msg);
...@@ -9380,7 +9382,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct...@@ -9380,7 +9382,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
9380 if (type_entry->id == TypeTableEntryIdInvalid) {9382 if (type_entry->id == TypeTableEntryIdInvalid) {
9381 return ira->codegen->builtin_types.entry_invalid;9383 return ira->codegen->builtin_types.entry_invalid;
9382 } else if (type_entry->id == TypeTableEntryIdUnreachable) {9384 } else if (type_entry->id == TypeTableEntryIdUnreachable) {
9383 add_node_error(ira->codegen, first_executing_node(instruction->type_value->source_node),9385 ir_add_error(ira, instruction->type_value,
9384 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));9386 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));
9385 return ira->codegen->builtin_types.entry_invalid;9387 return ira->codegen->builtin_types.entry_invalid;
9386 } else {9388 } else {