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 {...@@ -648,6 +648,7 @@ struct AstNodeFnCallExpr {
648 ZigList<AstNode *> params;648 ZigList<AstNode *> params;
649 bool is_builtin;649 bool is_builtin;
650 bool is_async;650 bool is_async;
651 bool seen; // used by @compileLog
651 AstNode *async_allocator;652 AstNode *async_allocator;
652};653};
653654
src/ir.cpp+7-3
...@@ -17194,9 +17194,13 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr...@@ -17194,9 +17194,13 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
17194 }17194 }
17195 fprintf(stderr, "\n");17195 fprintf(stderr, "\n");
1719617196
17197 // Here we bypass higher level functions such as ir_add_error because we do not want17197 auto *expr = &instruction->base.source_node->data.fn_call_expr;
17198 // invalidate_exec to be called.17198 if (!expr->seen) {
17199 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));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
17201 return ir_const_void(ira, &instruction->base);17205 return ir_const_void(ira, &instruction->base);
17202}17206}
src/parser.cpp+2
...@@ -2739,6 +2739,7 @@ static AstNode *ast_parse_async_prefix(ParseContext *pc) {...@@ -2739,6 +2739,7 @@ static AstNode *ast_parse_async_prefix(ParseContext *pc) {
27392739
2740 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async);2740 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async);
2741 res->data.fn_call_expr.is_async = true;2741 res->data.fn_call_expr.is_async = true;
2742 res->data.fn_call_expr.seen = false;
2742 if (eat_token_if(pc, TokenIdCmpLessThan) != nullptr) {2743 if (eat_token_if(pc, TokenIdCmpLessThan) != nullptr) {
2743 AstNode *prefix_expr = ast_expect(pc, ast_parse_prefix_expr);2744 AstNode *prefix_expr = ast_expect(pc, ast_parse_prefix_expr);
2744 expect_token(pc, TokenIdCmpGreaterThan);2745 expect_token(pc, TokenIdCmpGreaterThan);
...@@ -2759,6 +2760,7 @@ static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc) {...@@ -2759,6 +2760,7 @@ static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc) {
27592760
2760 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, paren);2761 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, paren);
2761 res->data.fn_call_expr.params = params;2762 res->data.fn_call_expr.params = params;
2763 res->data.fn_call_expr.seen = false;
2762 return res;2764 return res;
2763}2765}
27642766
test/compile_errors.zig+16-2
...@@ -137,6 +137,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -137,6 +137,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
137 ".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",137 ".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
138 );138 );
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
140 cases.addTest(154 cases.addTest(
141 "@truncate undefined value",155 "@truncate undefined value",
142 \\export fn entry() void {156 \\export fn entry() void {
...@@ -4920,7 +4934,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4920,7 +4934,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49204934
4921 cases.add(4935 cases.add(
4922 "non-printable invalid character",4936 "non-printable invalid character",
4923 "\xff\xfe" ++ 4937 "\xff\xfe" ++
4924 \\fn test() bool {\r4938 \\fn test() bool {\r
4925 \\ true\r4939 \\ true\r
4926 \\}4940 \\}
...@@ -5480,7 +5494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5480,7 +5494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5480 \\ Baz: void,5494 \\ Baz: void,
5481 \\};5495 \\};
5482 \\comptime {5496 \\comptime {
5483 \\ var foo = Foo {.Baz = {}}; 5497 \\ var foo = Foo {.Baz = {}};
5484 \\ const bar_val = foo.Bar;5498 \\ const bar_val = foo.Bar;
5485 \\}5499 \\}
5486 ,5500 ,