aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-07-04 15:47:47 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-07-04 17:56:01 -0700
commit74346b0f79ca4bf67d61008030c7cc3565bff3f9 (patch)
tree69bdcb7800608daed4a8908406623f3bab38f0e4 /src/InternPool.zig
parent30ec43a6c78d9c8803becbea5a02edb8fae08af6 (diff)
downloadzig-74346b0f79ca4bf67d61008030c7cc3565bff3f9.tar.gz
zig-74346b0f79ca4bf67d61008030c7cc3565bff3f9.zip
frontend: TrackedInst stores FileIndex instead of path digest
The purpose of using path digest was to reference a file in a serializable manner. Now that there is a stable index associated with files, it is a superior way to accomplish that goal, since removes one layer of indirection, and makes TrackedInst 8 bytes instead of 20. The saved Zig Compiler State file for "hello world" goes from 1.3M to 1.2M with this change.
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index e79de26516..18cd21d08d 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -92,12 +92,27 @@ dep_entries: std.ArrayListUnmanaged(DepEntry) = .{},
/// garbage collection pass.
free_dep_entries: std.ArrayListUnmanaged(DepEntry.Index) = .{},
+/// Elements are ordered identically to the `import_table` field of `Zcu`.
+///
+/// Unlike `import_table`, this data is serialized as part of incremental
+/// compilation state.
+///
+/// Key is the hash of the path to this file, used to store
+/// `InternPool.TrackedInst`.
+///
+/// Value is the `Decl` of the struct that represents this `File`.
+files: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, OptionalDeclIndex) = .{},
+
+pub const FileIndex = enum(u32) {
+ _,
+};
+
pub const TrackedInst = extern struct {
- path_digest: Cache.BinDigest,
+ file: FileIndex,
inst: Zir.Inst.Index,
comptime {
// The fields should be tightly packed. See also serialiation logic in `Compilation.saveState`.
- assert(@sizeOf(@This()) == Cache.bin_digest_len + @sizeOf(Zir.Inst.Index));
+ assert(@sizeOf(@This()) == @sizeOf(FileIndex) + @sizeOf(Zir.Inst.Index));
}
pub const Index = enum(u32) {
_,
@@ -126,11 +141,11 @@ pub const TrackedInst = extern struct {
pub fn trackZir(
ip: *InternPool,
gpa: Allocator,
- path_digest: Cache.BinDigest,
+ file: FileIndex,
inst: Zir.Inst.Index,
) Allocator.Error!TrackedInst.Index {
const key: TrackedInst = .{
- .path_digest = path_digest,
+ .file = file,
.inst = inst,
};
const gop = try ip.tracked_insts.getOrPut(gpa, key);
@@ -4597,6 +4612,8 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void {
ip.dep_entries.deinit(gpa);
ip.free_dep_entries.deinit(gpa);
+ ip.files.deinit(gpa);
+
ip.* = undefined;
}