From 73a7747a9cfb180a92fa0d98f9387d5ad1f47fd2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Aug 2019 12:43:36 -0400 Subject: [PATCH] fix some compile error regressions --- src/all_types.hpp | 7 +++++++ src/analyze.cpp | 29 ++++++++++++++++++----------- src/ir.cpp | 13 +++++-------- src/tokenizer.cpp | 2 +- test/compile_errors.zig | 12 ++++++------ 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index e860b87857..61e71c236c 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -53,6 +53,13 @@ enum PtrLen { PtrLenC, }; +enum UndefAllowed { + UndefOk, + UndefBad, + LazyOkNoUndef, + LazyOk, +}; + enum X64CABIClass { X64CABIClass_Unknown, X64CABIClass_MEMORY, diff --git a/src/analyze.cpp b/src/analyze.cpp index 06212bf48b..bba26b29ae 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -59,6 +59,7 @@ ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) { root_struct->source_code, root_struct->line_offsets, msg); g->errors.append(err); + g->trace_err = err; return err; } @@ -1793,7 +1794,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { if (struct_type->data.structure.resolve_loop_flag_other) { if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { struct_type->data.structure.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("struct '%s' depends on its own size", buf_ptr(&struct_type->name))); } return ErrorSemanticAnalyzeFail; @@ -1947,7 +1948,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { if (union_type->data.unionation.resolve_loop_flag_other) { if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { union_type->data.unionation.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("union '%s' depends on its own alignment", buf_ptr(&union_type->name))); } return ErrorSemanticAnalyzeFail; @@ -2058,7 +2059,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { if (union_type->data.unionation.resolve_loop_flag_other) { if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { union_type->data.unionation.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("union '%s' depends on its own size", buf_ptr(&union_type->name))); } return ErrorSemanticAnalyzeFail; @@ -2160,7 +2161,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { if (enum_type->data.enumeration.resolve_loop_flag) { if (enum_type->data.enumeration.resolve_status != ResolveStatusInvalid) { enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("enum '%s' depends on itself", buf_ptr(&enum_type->name))); } @@ -2337,7 +2338,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { if (struct_type->data.structure.resolve_loop_flag_zero_bits) { if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { struct_type->data.structure.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("struct '%s' depends on itself", buf_ptr(&struct_type->name))); } @@ -2462,7 +2463,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { if (struct_type->data.structure.resolve_loop_flag_other) { if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { struct_type->data.structure.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("struct '%s' depends on its own alignment", buf_ptr(&struct_type->name))); } return ErrorSemanticAnalyzeFail; @@ -2530,7 +2531,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { if (union_type->data.unionation.resolve_loop_flag_zero_bits) { if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { union_type->data.unionation.resolve_status = ResolveStatusInvalid; - g->trace_err = add_node_error(g, decl_node, + add_node_error(g, decl_node, buf_sprintf("union '%s' depends on itself", buf_ptr(&union_type->name))); } @@ -3423,7 +3424,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { ZigType *explicit_type = nullptr; if (var_decl->type) { if (tld_var->analyzing_type) { - g->trace_err = add_node_error(g, var_decl->type, + add_node_error(g, var_decl->type, buf_sprintf("type of '%s' depends on itself", buf_ptr(tld_var->base.name))); explicit_type = g->builtin_types.entry_invalid; } else { @@ -4001,6 +4002,13 @@ static void resolve_async_fn_frame(CodeGen *g, ZigFn *fn) { ZigType *frame_type = get_fn_frame_type(g, fn); Error err; if ((err = type_resolve(g, frame_type, ResolveStatusSizeKnown))) { + if (g->trace_err != nullptr && frame_type->data.frame.resolve_loop_src_node != nullptr && + !frame_type->data.frame.reported_loop_err) + { + frame_type->data.frame.reported_loop_err = true; + g->trace_err = add_error_note(g, g->trace_err, frame_type->data.frame.resolve_loop_src_node, + buf_sprintf("when analyzing type '%s' here", buf_ptr(&frame_type->name))); + } fn->anal_state = FnAnalStateInvalid; return; } @@ -5406,8 +5414,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { if (frame_type->data.frame.resolve_loop_type != nullptr) { if (!frame_type->data.frame.reported_loop_err) { - frame_type->data.frame.reported_loop_err = true; - g->trace_err = add_node_error(g, fn->proto_node, + add_node_error(g, fn->proto_node, buf_sprintf("'%s' depends on itself", buf_ptr(&frame_type->name))); } return ErrorSemanticAnalyzeFail; @@ -5424,7 +5431,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { return ErrorSemanticAnalyzeFail; break; case FnAnalStateProbing: { - g->trace_err = add_node_error(g, fn->proto_node, + add_node_error(g, fn->proto_node, buf_sprintf("cannot resolve '%s': function not fully analyzed yet", buf_ptr(&frame_type->name))); return ErrorSemanticAnalyzeFail; diff --git a/src/ir.cpp b/src/ir.cpp index bd782b4fdc..a6c14885ef 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -152,12 +152,6 @@ struct ConstCastBadAllowsZero { }; -enum UndefAllowed { - UndefOk, - UndefBad, - LazyOk, -}; - static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, ResultLoc *result_loc); @@ -6836,7 +6830,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod const char modifier = *buf_ptr(asm_output->constraint); if (modifier != '=') { add_node_error(irb->codegen, node, - buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported." + buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported" " Compiler TODO: see https://github.com/ziglang/zig/issues/215", buf_ptr(asm_output->asm_symbolic_name), modifier)); return irb->codegen->invalid_instruction; @@ -6860,7 +6854,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod uint32_t len = asm_token.end - asm_token.start - 2; add_node_error(irb->codegen, node, - buf_sprintf("could not find '%.*s' in the inputs or outputs.", + buf_sprintf("could not find '%.*s' in the inputs or outputs", len, ptr)); return irb->codegen->invalid_instruction; } @@ -8114,6 +8108,9 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc } IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval, result_loc); if (result == irb->codegen->invalid_instruction) { + if (irb->exec->first_err_trace_msg == nullptr) { + irb->exec->first_err_trace_msg = irb->codegen->trace_err; + } src_assert(irb->exec->first_err_trace_msg != nullptr, node); } return result; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 84f3f2c0ec..9c9effcb10 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -841,7 +841,7 @@ void tokenize(Buf *buf, Tokenization *out) { case TokenizeStateSawAmpersand: switch (c) { case '&': - tokenize_error(&t, "`&&` is invalid. Note that `and` is boolean AND."); + tokenize_error(&t, "`&&` is invalid. Note that `and` is boolean AND"); break; case '=': set_token_id(&t, t.cur_tok, TokenIdBitAndEq); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index a6a1d0219b..7ae722366a 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -10,7 +10,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ : [bar] "=r" (-> usize) \\ ); \\} - , "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs."); + , "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs"); tc.target = tests.Target{ .Cross = tests.CrossTarget{ .arch = .x86_64, @@ -53,8 +53,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} , "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself", - "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSumIndirect)' here", - "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSum)' here", + "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here", + "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", ); cases.add( @@ -245,7 +245,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { , "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", "tmp.zig:5:10: note: analysis of function 'other' depends on the frame", - "tmp.zig:8:13: note: depends on the frame here", + "tmp.zig:8:13: note: referenced here", ); cases.add( @@ -258,7 +258,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} , "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", - "tmp.zig:5:13: note: depends on its own frame here", + "tmp.zig:5:13: note: referenced here", ); cases.add( @@ -1091,7 +1091,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return 5678; \\} , - "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND.", + "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", ); cases.add(