authorgravatar for mason@anthropicstudios.comMason Remaley <mason@anthropicstudios.com> 2025-02-26 14:53:14-08:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-04-02 05:54:04+01:00
log87209954a74bbf9b82b7ab24c0389a4a133edd31
tree6f940ec8607aa8a0ab9569b4c805ebacaf3d3801
parent06ee383da9a23016dcb25ff7cb6811e3dc2c387e
signature Commit is signed but in an unrecognized format.

Zcu: fix ZOIR cache bugs

* When saving bigint limbs, we gave the iovec the wrong length, meaning bigint data (and the following string and compile error data) was corrupted. * When updating a stale ZOIR cache, we failed to truncate the file, so just wrote more bytes onto the end of the stale cache.

2 files changed, 2 insertions(+), 1 deletions(-)

src/Zcu.zig+1-1
...@@ -2753,7 +2753,7 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir...@@ -2753,7 +2753,7 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir
2753 },2753 },
2754 .{2754 .{
2755 .base = @ptrCast(zoir.limbs),2755 .base = @ptrCast(zoir.limbs),
2756 .len = zoir.limbs.len * 4,2756 .len = zoir.limbs.len * @sizeOf(std.math.big.Limb),
2757 },2757 },
2758 .{2758 .{
2759 .base = zoir.string_bytes.ptr,2759 .base = zoir.string_bytes.ptr,
src/Zcu/PerThread.zig+1
...@@ -234,6 +234,7 @@ pub fn updateFile(...@@ -234,6 +234,7 @@ pub fn updateFile(
234 error.FileTooBig => unreachable, // 0 is not too big234 error.FileTooBig => unreachable, // 0 is not too big
235 else => |e| return e,235 else => |e| return e,
236 };236 };
237 try cache_file.seekTo(0);
237238
238 if (stat.size > std.math.maxInt(u32))239 if (stat.size > std.math.maxInt(u32))
239 return error.FileTooBig;240 return error.FileTooBig;