authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-06-03 15:09:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-06-03 15:09:40-04:00
loge5b90651ba118cb0d3293c83bdfbc62c40f4c266
tree35b7af7aeef87a6bbd8f621c0c4f763156945555
parente64f0971fc788cefb348e9516cd3b284df7ea0df

compileError builtin includes "referenced by" notes

to help track down the cause closes #278

6 files changed, 54 insertions(+), 18 deletions(-)

src/all_types.hpp+1-2
......@@ -1453,8 +1453,6 @@ struct CodeGen {
14531453 FnTableEntry *extern_panic_fn;
14541454 LLVMValueRef cur_ret_ptr;
14551455 LLVMValueRef cur_fn_val;
1456 ZigList<LLVMBasicBlockRef> break_block_stack;
1457 ZigList<LLVMBasicBlockRef> continue_block_stack;
14581456 bool c_want_stdint;
14591457 bool c_want_stdbool;
14601458 AstNode *root_export_decl;
......@@ -1510,6 +1508,7 @@ struct CodeGen {
15101508 Buf *out_h_path;
15111509
15121510 ZigList<FnTableEntry *> inline_fns;
1511 ZigList<AstNode *> tld_ref_source_node_stack;
15131512};
15141513
15151514enum VarLinkage {
src/analyze.cpp+7-5
......@@ -2086,7 +2086,7 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source
20862086
20872087void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {
20882088 Tld *tld = g->compile_var_import->decls_scope->decl_table.get(name);
2089 resolve_top_level_decl(g, tld, false);
2089 resolve_top_level_decl(g, tld, false, tld->source_node);
20902090 assert(tld->id == TldIdVar);
20912091 TldVar *tld_var = (TldVar *)tld;
20922092 tld_var->var->value = value;
......@@ -2399,7 +2399,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
23992399 g->global_vars.append(tld_var);
24002400}
24012401
2402void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) {
2402void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node) {
24032403 if (tld->resolution != TldResolutionUnresolved)
24042404 return;
24052405
......@@ -2407,10 +2407,11 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) {
24072407 add_node_error(g, tld->source_node, buf_sprintf("'%s' depends on itself", buf_ptr(tld->name)));
24082408 tld->resolution = TldResolutionInvalid;
24092409 return;
2410 } else {
2411 tld->dep_loop_flag = true;
24122410 }
24132411
2412 tld->dep_loop_flag = true;
2413 g->tld_ref_source_node_stack.append(source_node);
2414
24142415 switch (tld->id) {
24152416 case TldIdVar:
24162417 {
......@@ -2440,6 +2441,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) {
24402441
24412442 tld->resolution = TldResolutionOk;
24422443 tld->dep_loop_flag = false;
2444 g->tld_ref_source_node_stack.pop();
24432445}
24442446
24452447bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type) {
......@@ -3056,7 +3058,7 @@ void semantic_analyze(CodeGen *g) {
30563058 for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) {
30573059 Tld *tld = g->resolve_queue.at(g->resolve_queue_index);
30583060 bool pointer_only = false;
3059 resolve_top_level_decl(g, tld, pointer_only);
3061 resolve_top_level_decl(g, tld, pointer_only, nullptr);
30603062 }
30613063
30623064 for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) {
src/analyze.hpp+1-1
......@@ -50,7 +50,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
5050bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);
5151VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
5252Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only);
53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
5454bool type_is_codegen_pointer(TypeTableEntry *type);
5555TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);
5656TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
src/ir.cpp+19-7
......@@ -7909,7 +7909,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
79097909
79107910static ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
79117911 Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name));
7912 resolve_top_level_decl(codegen, tld, false);
7912 resolve_top_level_decl(codegen, tld, false, nullptr);
79137913 assert(tld->id == TldIdVar);
79147914 TldVar *tld_var = (TldVar *)tld;
79157915 ConstExprValue *var_value = tld_var->var->value;
......@@ -10032,7 +10032,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1003210032 auto entry = container_scope->decl_table.maybe_get(field_name);
1003310033 Tld *tld = entry ? entry->value : nullptr;
1003410034 if (tld && tld->id == TldIdFn) {
10035 resolve_top_level_decl(ira->codegen, tld, false);
10035 resolve_top_level_decl(ira->codegen, tld, false, field_ptr_instruction->base.source_node);
1003610036 if (tld->resolution == TldResolutionInvalid)
1003710037 return ira->codegen->builtin_types.entry_invalid;
1003810038 TldFn *tld_fn = (TldFn *)tld;
......@@ -10117,7 +10117,7 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field
1011710117
1011810118static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
1011910119 bool pointer_only = false;
10120 resolve_top_level_decl(ira->codegen, tld, pointer_only);
10120 resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);
1012110121 if (tld->resolution == TldResolutionInvalid)
1012210122 return ira->codegen->builtin_types.entry_invalid;
1012310123
......@@ -10539,7 +10539,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira,
1053910539 Tld *tld = instruction->tld;
1054010540 IrInstruction *align_value = instruction->value->other;
1054110541
10542 resolve_top_level_decl(ira->codegen, tld, true);
10542 resolve_top_level_decl(ira->codegen, tld, true, instruction->base.source_node);
1054310543 if (tld->resolution == TldResolutionInvalid)
1054410544 return ira->codegen->builtin_types.entry_invalid;
1054510545
......@@ -10602,7 +10602,7 @@ static TypeTableEntry *ir_analyze_instruction_set_global_section(IrAnalyze *ira,
1060210602 Tld *tld = instruction->tld;
1060310603 IrInstruction *section_value = instruction->value->other;
1060410604
10605 resolve_top_level_decl(ira->codegen, tld, true);
10605 resolve_top_level_decl(ira->codegen, tld, true, instruction->base.source_node);
1060610606 if (tld->resolution == TldResolutionInvalid)
1060710607 return ira->codegen->builtin_types.entry_invalid;
1060810608
......@@ -11932,7 +11932,19 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
1193211932 if (!msg_buf)
1193311933 return ira->codegen->builtin_types.entry_invalid;
1193411934
11935 ir_add_error(ira, &instruction->base, msg_buf);
11935 ErrorMsg *msg = ir_add_error(ira, &instruction->base, msg_buf);
11936 size_t i = ira->codegen->tld_ref_source_node_stack.length;
11937 for (;;) {
11938 if (i == 0)
11939 break;
11940 i -= 1;
11941 AstNode *source_node = ira->codegen->tld_ref_source_node_stack.at(i);
11942 if (source_node) {
11943 add_error_note(ira->codegen, msg, source_node,
11944 buf_sprintf("referenced here"));
11945 }
11946 }
11947
1193611948 return ira->codegen->builtin_types.entry_invalid;
1193711949}
1193811950
......@@ -13454,7 +13466,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
1345413466 Tld *tld = instruction->tld;
1345513467 LVal lval = instruction->lval;
1345613468
13457 resolve_top_level_decl(ira->codegen, tld, lval.is_ptr);
13469 resolve_top_level_decl(ira->codegen, tld, lval.is_ptr, instruction->base.source_node);
1345813470 if (tld->resolution == TldResolutionInvalid)
1345913471 return ira->codegen->builtin_types.entry_invalid;
1346013472
std/special/bootstrap.zig+12-3
......@@ -8,7 +8,8 @@ const builtin = @import("builtin");
88const want_main_symbol = std.target.linking_libc;
99const want_start_symbol = !want_main_symbol;
1010
11const exit = std.os.posix.exit;
11const posix_exit = std.os.posix.exit;
12extern fn ExitProcess(exit_code: c_uint) -> noreturn;
1213
1314var argc_ptr: &usize = undefined;
1415
......@@ -34,8 +35,16 @@ fn callMainAndExit() -> noreturn {
3435 const argc = *argc_ptr;
3536 const argv = @ptrCast(&&u8, &argc_ptr[1]);
3637 const envp = @ptrCast(&?&u8, &argv[argc + 1]);
37 callMain(argc, argv, envp) %% exit(1);
38 exit(0);
38 callMain(argc, argv, envp) %% exit(true);
39 exit(false);
40}
41
42fn exit(failure: bool) -> noreturn {
43 if (builtin.os == builtin.Os.windows) {
44 ExitProcess(c_uint(failure));
45 } else {
46 posix_exit(i32(failure));
47 }
3948}
4049
4150fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void {
test/compile_errors.zig+14
......@@ -1916,4 +1916,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
19161916 \\}
19171917 ,
19181918 ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value");
1919
1920 cases.add("@compileError shows traceback of references that caused it",
1921 \\const foo = @compileError("aoeu");
1922 \\
1923 \\const bar = baz + foo;
1924 \\const baz = 1;
1925 \\
1926 \\export fn entry() -> i32 {
1927 \\ return bar;
1928 \\}
1929 ,
1930 ".tmp_source.zig:1:13: error: aoeu",
1931 ".tmp_source.zig:3:19: note: referenced here",
1932 ".tmp_source.zig:7:12: note: referenced here");
19191933}