aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-01-07 00:42:30 +0000
committermlugg <mlugg@mlugg.co.uk>2024-01-23 21:19:53 +0000
commit06d8bb32e3edfb4a26c6d3ecdf198574f4bd3f87 (patch)
treec71cc2ab5af1f24f224031f947c9ac0396df2562 /src/Compilation.zig
parentae845a33c04fb287ae5a7445743c2b570e40ca1f (diff)
downloadzig-06d8bb32e3edfb4a26c6d3ecdf198574f4bd3f87.tar.gz
zig-06d8bb32e3edfb4a26c6d3ecdf198574f4bd3f87.zip
InternPool: introduce TrackedInst
It is problematic for the cached `InternPool` state to directly reference ZIR instruction indices, as these are not stable across incremental updates. The existing ZIR mapping logic attempts to handle this by iterating the existing Decl graph for a file after `AstGen` and update ZIR indices on `Decl`s, struct types, etc. However, this is unreliable due to generic instantiations, and relies on specialized logic for everything which may refer to a ZIR instruction (e.g. a struct's owner decl). I therefore determined that a prerequisite change for incremental compilation would be to rework how we store these indices. This commit introduces a `TrackedInst` type which provides a stable index (`TrackedInst.Index`) for a single ZIR instruction in the compilation. The `InternPool` now stores these values in place of ZIR instruction indices. This makes the ZIR mapping logic relatively trivial: after `AstGen` completes, we simply iterate all `TrackedInst` values and update those indices which have changed. In future, if the corresponding ZIR instruction has been removed, we must also invalidate any dependencies on this instruction to trigger any required re-analysis, however the dependency system does not yet exist.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 58f56517c3..f5d63c3676 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -2795,6 +2795,7 @@ const Header = extern struct {
extra_len: u32,
limbs_len: u32,
string_bytes_len: u32,
+ tracked_insts_len: u32,
},
};
@@ -2802,7 +2803,7 @@ const Header = extern struct {
/// saved, such as the target and most CLI flags. A cache hit will only occur
/// when subsequent compiler invocations use the same set of flags.
pub fn saveState(comp: *Compilation) !void {
- var bufs_list: [6]std.os.iovec_const = undefined;
+ var bufs_list: [7]std.os.iovec_const = undefined;
var bufs_len: usize = 0;
const lf = comp.bin_file orelse return;
@@ -2815,6 +2816,7 @@ pub fn saveState(comp: *Compilation) !void {
.extra_len = @intCast(ip.extra.items.len),
.limbs_len = @intCast(ip.limbs.items.len),
.string_bytes_len = @intCast(ip.string_bytes.items.len),
+ .tracked_insts_len = @intCast(ip.tracked_insts.count()),
},
};
addBuf(&bufs_list, &bufs_len, mem.asBytes(&header));
@@ -2823,6 +2825,7 @@ pub fn saveState(comp: *Compilation) !void {
addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.items.items(.data)));
addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.items.items(.tag)));
addBuf(&bufs_list, &bufs_len, ip.string_bytes.items);
+ addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.tracked_insts.keys()));
// TODO: compilation errors
// TODO: files