authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 20:52:40-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 20:52:40-05:00
log132e2fa5d9cc17088082cf4797701214c20845f1
treefaf24be2d876da8ec77edcc5e5fa56b5217a7099
parentcfc9f7422f3b0e4077eca42d7b71cd5523dad0a9

errors from inline fn calls include stack trace


5 files changed, 26 insertions(+), 10 deletions(-)

src/all_types.hpp+2
...@@ -55,6 +55,8 @@ struct IrExecutable {...@@ -55,6 +55,8 @@ struct IrExecutable {
55 bool is_inline;55 bool is_inline;
56 FnTableEntry *fn_entry;56 FnTableEntry *fn_entry;
57 Buf *c_import_buf;57 Buf *c_import_buf;
58 AstNode *source_node;
59 IrExecutable *parent_exec;
58};60};
5961
60enum OutType {62enum OutType {
src/analyze.cpp+1-1
...@@ -875,7 +875,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod...@@ -875,7 +875,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod
875 size_t backward_branch_count = 0;875 size_t backward_branch_count = 0;
876 return ir_eval_const_value(g, scope, node, type_entry,876 return ir_eval_const_value(g, scope, node, type_entry,
877 &backward_branch_count, default_backward_branch_quota,877 &backward_branch_count, default_backward_branch_quota,
878 nullptr, nullptr, node, type_name);878 nullptr, nullptr, node, type_name, nullptr);
879}879}
880880
881TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {881TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
src/ir.cpp+19-6
...@@ -4169,9 +4169,17 @@ IrInstruction *ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {...@@ -4169,9 +4169,17 @@ IrInstruction *ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {
4169 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);4169 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
4170}4170}
41714171
4172static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) {
4173 if (!exec || !exec->source_node || limit < 0) return;
4174 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
4175 add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
4176}
4177
4172static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {4178static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
4173 ira->new_irb.exec->invalid = true;4179 ira->new_irb.exec->invalid = true;
4174 return add_node_error(ira->codegen, source_instruction->source_node, msg);4180 ErrorMsg *err_msg = add_node_error(ira->codegen, source_instruction->source_node, msg);
4181 add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10);
4182 return err_msg;
4175}4183}
41764184
4177static IrInstruction *ir_exec_const_result(IrExecutable *exec) {4185static IrInstruction *ir_exec_const_result(IrExecutable *exec) {
...@@ -4680,9 +4688,12 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un...@@ -4680,9 +4688,12 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
46804688
4681IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,4689IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
4682 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,4690 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
4683 FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name)4691 FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
4692 IrExecutable *parent_exec)
4684{4693{
4685 IrExecutable ir_executable = {0};4694 IrExecutable ir_executable = {0};
4695 ir_executable.source_node = source_node;
4696 ir_executable.parent_exec = parent_exec;
4686 ir_executable.name = exec_name;4697 ir_executable.name = exec_name;
4687 ir_executable.is_inline = true;4698 ir_executable.is_inline = true;
4688 ir_executable.fn_entry = fn_entry;4699 ir_executable.fn_entry = fn_entry;
...@@ -4700,6 +4711,8 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -4700,6 +4711,8 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
4700 fprintf(stderr, "}\n");4711 fprintf(stderr, "}\n");
4701 }4712 }
4702 IrExecutable analyzed_executable = {0};4713 IrExecutable analyzed_executable = {0};
4714 analyzed_executable.source_node = source_node;
4715 analyzed_executable.parent_exec = parent_exec;
4703 analyzed_executable.name = exec_name;4716 analyzed_executable.name = exec_name;
4704 analyzed_executable.is_inline = true;4717 analyzed_executable.is_inline = true;
4705 analyzed_executable.fn_entry = fn_entry;4718 analyzed_executable.fn_entry = fn_entry;
...@@ -4730,7 +4743,7 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value...@@ -4730,7 +4743,7 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value
4730 return ira->codegen->builtin_types.entry_invalid;4743 return ira->codegen->builtin_types.entry_invalid;
47314744
4732 if (type_value->type_entry->id != TypeTableEntryIdMetaType) {4745 if (type_value->type_entry->id != TypeTableEntryIdMetaType) {
4733 add_node_error(ira->codegen, type_value->source_node,4746 ir_add_error(ira, type_value,
4734 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->type_entry->name)));4747 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->type_entry->name)));
4735 return ira->codegen->builtin_types.entry_invalid;4748 return ira->codegen->builtin_types.entry_invalid;
4736 }4749 }
...@@ -5152,7 +5165,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ...@@ -5152,7 +5165,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
5152 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->type_entry, value);5165 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->type_entry, value);
5153 switch (result) {5166 switch (result) {
5154 case ImplicitCastMatchResultNo:5167 case ImplicitCastMatchResultNo:
5155 add_node_error(ira->codegen, first_executing_node(value->source_node),5168 ir_add_error(ira, value,
5156 buf_sprintf("expected type '%s', found '%s'",5169 buf_sprintf("expected type '%s', found '%s'",
5157 buf_ptr(&expected_type->name),5170 buf_ptr(&expected_type->name),
5158 buf_ptr(&value->type_entry->name)));5171 buf_ptr(&value->type_entry->name)));
...@@ -6147,7 +6160,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -6147,7 +6160,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
6147 AstNode *body_node = fn_entry->fn_def_node->data.fn_def.body;6160 AstNode *body_node = fn_entry->fn_def_node->data.fn_def.body;
6148 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,6161 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,
6149 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,6162 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,
6150 nullptr, call_instruction->base.source_node, nullptr);6163 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);
6151 if (result->type_entry->id == TypeTableEntryIdInvalid)6164 if (result->type_entry->id == TypeTableEntryIdInvalid)
6152 return ira->codegen->builtin_types.entry_invalid;6165 return ira->codegen->builtin_types.entry_invalid;
61536166
...@@ -8432,7 +8445,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc...@@ -8432,7 +8445,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
8432 TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void;8445 TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void;
8433 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,8446 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
8434 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,8447 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
8435 &cimport_scope->buf, block_node, nullptr);8448 &cimport_scope->buf, block_node, nullptr, nullptr);
8436 if (result->type_entry->id == TypeTableEntryIdInvalid)8449 if (result->type_entry->id == TypeTableEntryIdInvalid)
8437 return ira->codegen->builtin_types.entry_invalid;8450 return ira->codegen->builtin_types.entry_invalid;
84388451
src/ir.hpp+2-1
...@@ -15,7 +15,8 @@ IrInstruction *ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);...@@ -15,7 +15,8 @@ IrInstruction *ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);
1515
16IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,16IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
17 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,17 TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
18 FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name);18 FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
19 IrExecutable *parent_exec);
1920
20TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,21TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
21 TypeTableEntry *expected_type, AstNode *expected_type_source_node);22 TypeTableEntry *expected_type, AstNode *expected_type_source_node);
std/test_runner.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const io = @import("std").io;1const io = @import("std").io;
22
3struct TestFn {3const TestFn = struct {
4 name: []u8,4 name: []u8,
5 func: extern fn(),5 func: extern fn(),
6}6};
77
8extern var zig_test_fn_list: []TestFn;8extern var zig_test_fn_list: []TestFn;
99