From 015cd79f89aefd26fb1df91f3d07f7dcade21c4a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 25 Apr 2021 00:02:58 -0700 Subject: stage2: implement caching for ZIR code Notably this exposed an issue with the language having to do with the secret safety tag on untagged unions. How can we have our cake and eat it too? Not solved in this commit. I will file a language proposal to tackle this issue soon. Fixes a compile error in `std.fs.File.readvAll`. --- src/Compilation.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index be488a20d6..684eef47e8 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -434,10 +434,10 @@ pub const AllErrors = struct { arena: *Allocator, errors: *std.ArrayList(Message), file: *Module.Scope.File, - source: []const u8, ) !void { assert(file.zir_loaded); assert(file.tree_loaded); + assert(file.source_loaded); const payload_index = file.zir.extra[@enumToInt(Zir.ExtraIndex.compile_errors)]; assert(payload_index != 0); @@ -466,7 +466,7 @@ pub const AllErrors = struct { } break :blk token_starts[note_item.data.token] + note_item.data.byte_offset; }; - const loc = std.zig.findLineColumn(source, byte_offset); + const loc = std.zig.findLineColumn(file.source, byte_offset); note.* = .{ .src = .{ @@ -492,7 +492,7 @@ pub const AllErrors = struct { } break :blk token_starts[item.data.token] + item.data.byte_offset; }; - const loc = std.zig.findLineColumn(source, byte_offset); + const loc = std.zig.findLineColumn(file.source, byte_offset); try errors.append(.{ .src = .{ @@ -1709,9 +1709,11 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { if (entry.value) |msg| { try AllErrors.add(module, &arena, &errors, msg.*); } else { - // Must be ZIR errors. - const source = try entry.key.getSource(module.gpa); - try AllErrors.addZir(&arena.allocator, &errors, entry.key, source); + // Must be ZIR errors. In order for ZIR errors to exist, the parsing + // must have completed successfully. + const tree = try entry.key.getTree(module.gpa); + assert(tree.errors.len == 0); + try AllErrors.addZir(&arena.allocator, &errors, entry.key); } } for (module.failed_decls.items()) |entry| { -- cgit v1.2.3