From ded5c759f83a4da355a128dd4d7f5e22cbd3cabe Mon Sep 17 00:00:00 2001 From: mlugg Date: Sun, 30 Jun 2024 03:00:07 +0100 Subject: Zcu: store `LazySrcLoc` in error messages This change modifies `Zcu.ErrorMsg` to store a `Zcu.LazySrcLoc` rather than a `Zcu.SrcLoc`. Everything else is dominoes. The reason for this change is incremental compilation. If a failed `AnalUnit` is up-to-date on an update, we want to re-use the old error messages. However, the file containing the error location may have been modified, and `SrcLoc` cannot survive such a modification. `LazySrcLoc` is designed to be correct across incremental updates. Therefore, we defer source location resolution until `Compilation` gathers the compile errors into the `ErrorBundle`. --- src/Sema.zig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/Sema.zig') diff --git a/src/Sema.zig b/src/Sema.zig index 105fedbec7..9254cf3b8e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2425,8 +2425,7 @@ pub fn errNote( comptime format: []const u8, args: anytype, ) error{OutOfMemory}!void { - const zcu = sema.mod; - return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args); + return sema.mod.errNote(src, parent, format, args); } fn addFieldErrNote( @@ -2454,7 +2453,7 @@ pub fn errMsg( args: anytype, ) Allocator.Error!*Module.ErrorMsg { assert(src.offset != .unneeded); - return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args); + return Module.ErrorMsg.create(sema.gpa, src, format, args); } pub fn fail( @@ -2542,7 +2541,6 @@ fn reparentOwnedErrorMsg( args: anytype, ) !void { const mod = sema.mod; - const resolved_src = src.upgrade(mod); const msg_str = try std.fmt.allocPrint(mod.gpa, format, args); const orig_notes = msg.notes.len; @@ -2553,7 +2551,7 @@ fn reparentOwnedErrorMsg( .msg = msg.msg, }; - msg.src_loc = resolved_src; + msg.src_loc = src; msg.msg = msg_str; } @@ -13883,7 +13881,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A return sema.fail(block, operand_src, "file path name cannot be empty", .{}); } - const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) { + const val = mod.embedFile(block.getFileScope(mod), name, operand_src) catch |err| switch (err) { error.ImportOutsideModulePath => { return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); }, -- cgit v1.2.3