From 74346b0f79ca4bf67d61008030c7cc3565bff3f9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 4 Jul 2024 15:47:47 -0700 Subject: 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. --- src/InternPool.zig | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/InternPool.zig') 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; } -- cgit v1.2.3