aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-06-30 03:00:07 +0100
committermlugg <mlugg@mlugg.co.uk>2024-07-04 21:01:41 +0100
commitded5c759f83a4da355a128dd4d7f5e22cbd3cabe (patch)
treeb862bbdf36b892e9c39f472c6759f084c87d64b2 /src/Sema.zig
parent089bbd6588d82ccda0646e756006cf5787eadef2 (diff)
downloadzig-ded5c759f83a4da355a128dd4d7f5e22cbd3cabe.tar.gz
zig-ded5c759f83a4da355a128dd4d7f5e22cbd3cabe.zip
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`.
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig10
1 files changed, 4 insertions, 6 deletions
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});
},