authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-15 21:20:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-15 21:20:06-07:00
log7cd94d212361bc5662e8cc6959cd32edca1df03a
tree7a5fe6aa6a2da5c6f160659c8b8894a93662d953
parentdc036f5b6fde67c4a74701c75c5947a956abaec1

stage2: omit Decl compile errors from failed AstGen files

Just like when new parse errors occur during an update, when new AstGen errors occur during an update, we do not reveal compile errors for Decl objects which are inside of a newly failed File. Once the File passes AstGen successfully, it will be compared with the previously succeeded ZIR and the saved Decl compile errors will be handled properly.

3 files changed, 22 insertions(+), 20 deletions(-)

src/Compilation.zig+12-16
......@@ -1696,17 +1696,15 @@ pub fn totalErrorCount(self: *Compilation) usize {
16961696 // the previous parse success, including compile errors, but we cannot
16971697 // emit them until the file succeeds parsing.
16981698 for (module.failed_decls.items()) |entry| {
1699 if (entry.key.namespace.file_scope.status == .parse_failure) {
1700 continue;
1699 if (entry.key.namespace.file_scope.okToReportErrors()) {
1700 total += 1;
17011701 }
1702 total += 1;
17031702 }
17041703 if (module.emit_h) |emit_h| {
17051704 for (emit_h.failed_decls.items()) |entry| {
1706 if (entry.key.namespace.file_scope.status == .parse_failure) {
1707 continue;
1705 if (entry.key.namespace.file_scope.okToReportErrors()) {
1706 total += 1;
17081707 }
1709 total += 1;
17101708 }
17111709 }
17121710 }
......@@ -1767,21 +1765,19 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors {
17671765 }
17681766 }
17691767 for (module.failed_decls.items()) |entry| {
1770 if (entry.key.namespace.file_scope.status == .parse_failure) {
1771 // Skip errors for Decls within files that had a parse failure.
1772 // We'll try again once parsing succeeds.
1773 continue;
1768 // Skip errors for Decls within files that had a parse failure.
1769 // We'll try again once parsing succeeds.
1770 if (entry.key.namespace.file_scope.okToReportErrors()) {
1771 try AllErrors.add(module, &arena, &errors, entry.value.*);
17741772 }
1775 try AllErrors.add(module, &arena, &errors, entry.value.*);
17761773 }
17771774 if (module.emit_h) |emit_h| {
17781775 for (emit_h.failed_decls.items()) |entry| {
1779 if (entry.key.namespace.file_scope.status == .parse_failure) {
1780 // Skip errors for Decls within files that had a parse failure.
1781 // We'll try again once parsing succeeds.
1782 continue;
1776 // Skip errors for Decls within files that had a parse failure.
1777 // We'll try again once parsing succeeds.
1778 if (entry.key.namespace.file_scope.okToReportErrors()) {
1779 try AllErrors.add(module, &arena, &errors, entry.value.*);
17831780 }
1784 try AllErrors.add(module, &arena, &errors, entry.value.*);
17851781 }
17861782 }
17871783 for (module.failed_exports.items()) |entry| {
src/Module.zig+7
......@@ -1138,6 +1138,13 @@ pub const Scope = struct {
11381138 const loc = std.zig.findLineColumn(file.source.bytes, src);
11391139 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });
11401140 }
1141
1142 pub fn okToReportErrors(file: File) bool {
1143 return switch (file.status) {
1144 .parse_failure, .astgen_failure => false,
1145 else => true,
1146 };
1147 }
11411148 };
11421149
11431150 /// This is the context needed to semantically analyze ZIR instructions and
test/stage2/test.zig+3-4
......@@ -1225,7 +1225,7 @@ pub fn addCases(ctx: *TestContext) !void {
12251225 {
12261226 var case = ctx.obj("variable shadowing", linux_x64);
12271227 case.addError(
1228 \\pub export fn _start() noreturn {
1228 \\export fn _start() noreturn {
12291229 \\ var i: u32 = 10;
12301230 \\ var i: u32 = 10;
12311231 \\ unreachable;
......@@ -1251,7 +1251,7 @@ pub fn addCases(ctx: *TestContext) !void {
12511251 var case = ctx.obj("@compileLog", linux_x64);
12521252 // The other compile error prevents emission of a "found compile log" statement.
12531253 case.addError(
1254 \\pub export fn _start() noreturn {
1254 \\export fn _start() noreturn {
12551255 \\ const b = true;
12561256 \\ var f: u32 = 1;
12571257 \\ @compileLog(b, 20, f, x);
......@@ -1293,10 +1293,9 @@ pub fn addCases(ctx: *TestContext) !void {
12931293 \\ _ = foo;
12941294 \\}
12951295 \\extern var foo: i32;
1296 \\pub export fn _start() void {}
12971296 , &[_][]const u8{":2:9: error: unable to resolve comptime value"});
12981297 case.addError(
1299 \\pub export fn _start() void {
1298 \\export fn entry() void {
13001299 \\ _ = foo;
13011300 \\}
13021301 \\extern var foo;