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 {...@@ -1696,17 +1696,15 @@ pub fn totalErrorCount(self: *Compilation) usize {
1696 // the previous parse success, including compile errors, but we cannot1696 // the previous parse success, including compile errors, but we cannot
1697 // emit them until the file succeeds parsing.1697 // emit them until the file succeeds parsing.
1698 for (module.failed_decls.items()) |entry| {1698 for (module.failed_decls.items()) |entry| {
1699 if (entry.key.namespace.file_scope.status == .parse_failure) {1699 if (entry.key.namespace.file_scope.okToReportErrors()) {
1700 continue;1700 total += 1;
1701 }1701 }
1702 total += 1;
1703 }1702 }
1704 if (module.emit_h) |emit_h| {1703 if (module.emit_h) |emit_h| {
1705 for (emit_h.failed_decls.items()) |entry| {1704 for (emit_h.failed_decls.items()) |entry| {
1706 if (entry.key.namespace.file_scope.status == .parse_failure) {1705 if (entry.key.namespace.file_scope.okToReportErrors()) {
1707 continue;1706 total += 1;
1708 }1707 }
1709 total += 1;
1710 }1708 }
1711 }1709 }
1712 }1710 }
...@@ -1767,21 +1765,19 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors {...@@ -1767,21 +1765,19 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors {
1767 }1765 }
1768 }1766 }
1769 for (module.failed_decls.items()) |entry| {1767 for (module.failed_decls.items()) |entry| {
1770 if (entry.key.namespace.file_scope.status == .parse_failure) {1768 // Skip errors for Decls within files that had a parse failure.
1771 // Skip errors for Decls within files that had a parse failure.1769 // We'll try again once parsing succeeds.
1772 // We'll try again once parsing succeeds.1770 if (entry.key.namespace.file_scope.okToReportErrors()) {
1773 continue;1771 try AllErrors.add(module, &arena, &errors, entry.value.*);
1774 }1772 }
1775 try AllErrors.add(module, &arena, &errors, entry.value.*);
1776 }1773 }
1777 if (module.emit_h) |emit_h| {1774 if (module.emit_h) |emit_h| {
1778 for (emit_h.failed_decls.items()) |entry| {1775 for (emit_h.failed_decls.items()) |entry| {
1779 if (entry.key.namespace.file_scope.status == .parse_failure) {1776 // Skip errors for Decls within files that had a parse failure.
1780 // Skip errors for Decls within files that had a parse failure.1777 // We'll try again once parsing succeeds.
1781 // We'll try again once parsing succeeds.1778 if (entry.key.namespace.file_scope.okToReportErrors()) {
1782 continue;1779 try AllErrors.add(module, &arena, &errors, entry.value.*);
1783 }1780 }
1784 try AllErrors.add(module, &arena, &errors, entry.value.*);
1785 }1781 }
1786 }1782 }
1787 for (module.failed_exports.items()) |entry| {1783 for (module.failed_exports.items()) |entry| {
src/Module.zig+7
...@@ -1138,6 +1138,13 @@ pub const Scope = struct {...@@ -1138,6 +1138,13 @@ pub const Scope = struct {
1138 const loc = std.zig.findLineColumn(file.source.bytes, src);1138 const loc = std.zig.findLineColumn(file.source.bytes, src);
1139 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });1139 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });
1140 }1140 }
1141
1142 pub fn okToReportErrors(file: File) bool {
1143 return switch (file.status) {
1144 .parse_failure, .astgen_failure => false,
1145 else => true,
1146 };
1147 }
1141 };1148 };
11421149
1143 /// This is the context needed to semantically analyze ZIR instructions and1150 /// 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 {...@@ -1225,7 +1225,7 @@ pub fn addCases(ctx: *TestContext) !void {
1225 {1225 {
1226 var case = ctx.obj("variable shadowing", linux_x64);1226 var case = ctx.obj("variable shadowing", linux_x64);
1227 case.addError(1227 case.addError(
1228 \\pub export fn _start() noreturn {1228 \\export fn _start() noreturn {
1229 \\ var i: u32 = 10;1229 \\ var i: u32 = 10;
1230 \\ var i: u32 = 10;1230 \\ var i: u32 = 10;
1231 \\ unreachable;1231 \\ unreachable;
...@@ -1251,7 +1251,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1251,7 +1251,7 @@ pub fn addCases(ctx: *TestContext) !void {
1251 var case = ctx.obj("@compileLog", linux_x64);1251 var case = ctx.obj("@compileLog", linux_x64);
1252 // The other compile error prevents emission of a "found compile log" statement.1252 // The other compile error prevents emission of a "found compile log" statement.
1253 case.addError(1253 case.addError(
1254 \\pub export fn _start() noreturn {1254 \\export fn _start() noreturn {
1255 \\ const b = true;1255 \\ const b = true;
1256 \\ var f: u32 = 1;1256 \\ var f: u32 = 1;
1257 \\ @compileLog(b, 20, f, x);1257 \\ @compileLog(b, 20, f, x);
...@@ -1293,10 +1293,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1293,10 +1293,9 @@ pub fn addCases(ctx: *TestContext) !void {
1293 \\ _ = foo;1293 \\ _ = foo;
1294 \\}1294 \\}
1295 \\extern var foo: i32;1295 \\extern var foo: i32;
1296 \\pub export fn _start() void {}
1297 , &[_][]const u8{":2:9: error: unable to resolve comptime value"});1296 , &[_][]const u8{":2:9: error: unable to resolve comptime value"});
1298 case.addError(1297 case.addError(
1299 \\pub export fn _start() void {1298 \\export fn entry() void {
1300 \\ _ = foo;1299 \\ _ = foo;
1301 \\}1300 \\}
1302 \\extern var foo;1301 \\extern var foo;