authorgravatar for matthew.mcallister.0@gmail.comMatthew McAllister <matthew.mcallister.0@gmail.com> 2019-02-14 15:54:37-08:00
committergravatar for matthew.mcallister.0@gmail.comMatthew McAllister <matthew.mcallister.0@gmail.com> 2019-02-17 14:02:37-08:00
log51783510b9b972fab52d429ff3311b0fe8402e42
treee01041cba524688af54615406fb108247000d067
parentde18ece29436290cae3608d2c942e7e0a69f1a44

Deduplicate compile log statement warnings


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

src/all_types.hpp+1
......@@ -648,6 +648,7 @@ struct AstNodeFnCallExpr {
648648 ZigList<AstNode *> params;
649649 bool is_builtin;
650650 bool is_async;
651 bool seen; // used by @compileLog
651652 AstNode *async_allocator;
652653};
653654
src/ir.cpp+7-3
......@@ -17194,9 +17194,13 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
1719417194 }
1719517195 fprintf(stderr, "\n");
1719617196
17197 // Here we bypass higher level functions such as ir_add_error because we do not want
17198 // invalidate_exec to be called.
17199 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
17197 auto *expr = &instruction->base.source_node->data.fn_call_expr;
17198 if (!expr->seen) {
17199 // Here we bypass higher level functions such as ir_add_error because we do not want
17200 // invalidate_exec to be called.
17201 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
17202 }
17203 expr->seen = true;
1720017204
1720117205 return ir_const_void(ira, &instruction->base);
1720217206}
src/parser.cpp+2
......@@ -2739,6 +2739,7 @@ static AstNode *ast_parse_async_prefix(ParseContext *pc) {
27392739
27402740 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async);
27412741 res->data.fn_call_expr.is_async = true;
2742 res->data.fn_call_expr.seen = false;
27422743 if (eat_token_if(pc, TokenIdCmpLessThan) != nullptr) {
27432744 AstNode *prefix_expr = ast_expect(pc, ast_parse_prefix_expr);
27442745 expect_token(pc, TokenIdCmpGreaterThan);
......@@ -2759,6 +2760,7 @@ static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc) {
27592760
27602761 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, paren);
27612762 res->data.fn_call_expr.params = params;
2763 res->data.fn_call_expr.seen = false;
27622764 return res;
27632765}
27642766
test/compile_errors.zig+16-2
......@@ -137,6 +137,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
137137 ".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
138138 );
139139
140 cases.addTest(
141 "compile log statement warning deduplication in generic fn",
142 \\export fn entry() void {
143 \\ inner(1);
144 \\ inner(2);
145 \\}
146 \\fn inner(comptime n: usize) void {
147 \\ comptime var i = 0;
148 \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
149 \\}
150 ,
151 ".tmp_source.zig:7:39: error: found compile log statement",
152 );
153
140154 cases.addTest(
141155 "@truncate undefined value",
142156 \\export fn entry() void {
......@@ -4920,7 +4934,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49204934
49214935 cases.add(
49224936 "non-printable invalid character",
4923 "\xff\xfe" ++
4937 "\xff\xfe" ++
49244938 \\fn test() bool {\r
49254939 \\ true\r
49264940 \\}
......@@ -5480,7 +5494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
54805494 \\ Baz: void,
54815495 \\};
54825496 \\comptime {
5483 \\ var foo = Foo {.Baz = {}};
5497 \\ var foo = Foo {.Baz = {}};
54845498 \\ const bar_val = foo.Bar;
54855499 \\}
54865500 ,