authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2024-09-11 22:44:02+01:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2024-09-12 16:01:23+01:00
log9271a89c65967ff0fed7011b4195abdd0f9195eb
tree8b7a7559f0c8ff6dbde8f347b7c5870336a82063
parent8588964972acc473c09e21958a7e52247c978603

InternPool: Replace default values with a .empty declaration


2 files changed, 35 insertions(+), 17 deletions(-)

src/InternPool.zig+34-16
...@@ -2,20 +2,20 @@...@@ -2,20 +2,20 @@
2//! This data structure is self-contained.2//! This data structure is self-contained.
33
4/// One item per thread, indexed by `tid`, which is dense and unique per thread.4/// One item per thread, indexed by `tid`, which is dense and unique per thread.
5locals: []Local = &.{},5locals: []Local,
6/// Length must be a power of two and represents the number of simultaneous6/// Length must be a power of two and represents the number of simultaneous
7/// writers that can mutate any single sharded data structure.7/// writers that can mutate any single sharded data structure.
8shards: []Shard = &.{},8shards: []Shard,
9/// Key is the error name, index is the error tag value. Index 0 has a length-0 string.9/// Key is the error name, index is the error tag value. Index 0 has a length-0 string.
10global_error_set: GlobalErrorSet = GlobalErrorSet.empty,10global_error_set: GlobalErrorSet,
11/// Cached number of active bits in a `tid`.11/// Cached number of active bits in a `tid`.
12tid_width: if (single_threaded) u0 else std.math.Log2Int(u32) = 0,12tid_width: if (single_threaded) u0 else std.math.Log2Int(u32),
13/// Cached shift amount to put a `tid` in the top bits of a 30-bit value.13/// Cached shift amount to put a `tid` in the top bits of a 30-bit value.
14tid_shift_30: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,14tid_shift_30: if (single_threaded) u0 else std.math.Log2Int(u32),
15/// Cached shift amount to put a `tid` in the top bits of a 31-bit value.15/// Cached shift amount to put a `tid` in the top bits of a 31-bit value.
16tid_shift_31: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,16tid_shift_31: if (single_threaded) u0 else std.math.Log2Int(u32),
17/// Cached shift amount to put a `tid` in the top bits of a 32-bit value.17/// Cached shift amount to put a `tid` in the top bits of a 32-bit value.
18tid_shift_32: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,18tid_shift_32: if (single_threaded) u0 else std.math.Log2Int(u32),
1919
20/// Dependencies on the source code hash associated with a ZIR instruction.20/// Dependencies on the source code hash associated with a ZIR instruction.
21/// * For a `declaration`, this is the entire declaration body.21/// * For a `declaration`, this is the entire declaration body.
...@@ -23,36 +23,36 @@ tid_shift_32: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_th...@@ -23,36 +23,36 @@ tid_shift_32: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_th
23/// * For a `func`, this is the source of the full function signature.23/// * For a `func`, this is the source of the full function signature.
24/// These are also invalidated if tracking fails for this instruction.24/// These are also invalidated if tracking fails for this instruction.
25/// Value is index into `dep_entries` of the first dependency on this hash.25/// Value is index into `dep_entries` of the first dependency on this hash.
26src_hash_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index) = .empty,26src_hash_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index),
27/// Dependencies on the value of a Nav.27/// Dependencies on the value of a Nav.
28/// Value is index into `dep_entries` of the first dependency on this Nav value.28/// Value is index into `dep_entries` of the first dependency on this Nav value.
29nav_val_deps: std.AutoArrayHashMapUnmanaged(Nav.Index, DepEntry.Index) = .empty,29nav_val_deps: std.AutoArrayHashMapUnmanaged(Nav.Index, DepEntry.Index),
30/// Dependencies on an interned value, either:30/// Dependencies on an interned value, either:
31/// * a runtime function (invalidated when its IES changes)31/// * a runtime function (invalidated when its IES changes)
32/// * a container type requiring resolution (invalidated when the type must be recreated at a new index)32/// * a container type requiring resolution (invalidated when the type must be recreated at a new index)
33/// Value is index into `dep_entries` of the first dependency on this interned value.33/// Value is index into `dep_entries` of the first dependency on this interned value.
34interned_deps: std.AutoArrayHashMapUnmanaged(Index, DepEntry.Index) = .empty,34interned_deps: std.AutoArrayHashMapUnmanaged(Index, DepEntry.Index),
35/// Dependencies on the full set of names in a ZIR namespace.35/// Dependencies on the full set of names in a ZIR namespace.
36/// Key refers to a `struct_decl`, `union_decl`, etc.36/// Key refers to a `struct_decl`, `union_decl`, etc.
37/// Value is index into `dep_entries` of the first dependency on this namespace.37/// Value is index into `dep_entries` of the first dependency on this namespace.
38namespace_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index) = .empty,38namespace_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index),
39/// Dependencies on the (non-)existence of some name in a namespace.39/// Dependencies on the (non-)existence of some name in a namespace.
40/// Value is index into `dep_entries` of the first dependency on this name.40/// Value is index into `dep_entries` of the first dependency on this name.
41namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.Index) = .empty,41namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.Index),
4242
43/// Given a `Depender`, points to an entry in `dep_entries` whose `depender`43/// Given a `Depender`, points to an entry in `dep_entries` whose `depender`
44/// matches. The `next_dependee` field can be used to iterate all such entries44/// matches. The `next_dependee` field can be used to iterate all such entries
45/// and remove them from the corresponding lists.45/// and remove them from the corresponding lists.
46first_dependency: std.AutoArrayHashMapUnmanaged(AnalUnit, DepEntry.Index) = .empty,46first_dependency: std.AutoArrayHashMapUnmanaged(AnalUnit, DepEntry.Index),
4747
48/// Stores dependency information. The hashmaps declared above are used to look48/// Stores dependency information. The hashmaps declared above are used to look
49/// up entries in this list as required. This is not stored in `extra` so that49/// up entries in this list as required. This is not stored in `extra` so that
50/// we can use `free_dep_entries` to track free indices, since dependencies are50/// we can use `free_dep_entries` to track free indices, since dependencies are
51/// removed frequently.51/// removed frequently.
52dep_entries: std.ArrayListUnmanaged(DepEntry) = .empty,52dep_entries: std.ArrayListUnmanaged(DepEntry),
53/// Stores unused indices in `dep_entries` which can be reused without a full53/// Stores unused indices in `dep_entries` which can be reused without a full
54/// garbage collection pass.54/// garbage collection pass.
55free_dep_entries: std.ArrayListUnmanaged(DepEntry.Index) = .empty,55free_dep_entries: std.ArrayListUnmanaged(DepEntry.Index),
5656
57/// Whether a multi-threaded intern pool is useful.57/// Whether a multi-threaded intern pool is useful.
58/// Currently `false` until the intern pool is actually accessed58/// Currently `false` until the intern pool is actually accessed
...@@ -62,6 +62,24 @@ const want_multi_threaded = true;...@@ -62,6 +62,24 @@ const want_multi_threaded = true;
62/// Whether a single-threaded intern pool impl is in use.62/// Whether a single-threaded intern pool impl is in use.
63pub const single_threaded = builtin.single_threaded or !want_multi_threaded;63pub const single_threaded = builtin.single_threaded or !want_multi_threaded;
6464
65pub const empty: InternPool = .{
66 .locals = &.{},
67 .shards = &.{},
68 .global_error_set = .empty,
69 .tid_width = 0,
70 .tid_shift_30 = if (single_threaded) 0 else 31,
71 .tid_shift_31 = if (single_threaded) 0 else 31,
72 .tid_shift_32 = if (single_threaded) 0 else 31,
73 .src_hash_deps = .empty,
74 .nav_val_deps = .empty,
75 .interned_deps = .empty,
76 .namespace_deps = .empty,
77 .namespace_name_deps = .empty,
78 .first_dependency = .empty,
79 .dep_entries = .empty,
80 .free_dep_entries = .empty,
81};
82
65/// A `TrackedInst.Index` provides a single, unchanging reference to a ZIR instruction across a whole83/// A `TrackedInst.Index` provides a single, unchanging reference to a ZIR instruction across a whole
66/// compilation. From this index, you can acquire a `TrackedInst`, which containss a reference to both84/// compilation. From this index, you can acquire a `TrackedInst`, which containss a reference to both
67/// the file which the instruction lives in, and the instruction index itself, which is updated on85/// the file which the instruction lives in, and the instruction index itself, which is updated on
...@@ -9858,7 +9876,7 @@ fn extraData(extra: Local.Extra, comptime T: type, index: u32) T {...@@ -9858,7 +9876,7 @@ fn extraData(extra: Local.Extra, comptime T: type, index: u32) T {
9858test "basic usage" {9876test "basic usage" {
9859 const gpa = std.testing.allocator;9877 const gpa = std.testing.allocator;
98609878
9861 var ip: InternPool = .{};9879 var ip: InternPool = .empty;
9862 defer ip.deinit(gpa);9880 defer ip.deinit(gpa);
98639881
9864 const i32_type = try ip.get(gpa, .main, .{ .int_type = .{9882 const i32_type = try ip.get(gpa, .main, .{ .int_type = .{
src/Zcu.zig+1-1
...@@ -116,7 +116,7 @@ embed_table: std.StringArrayHashMapUnmanaged(*EmbedFile) = .empty,...@@ -116,7 +116,7 @@ embed_table: std.StringArrayHashMapUnmanaged(*EmbedFile) = .empty,
116/// Stores all Type and Value objects.116/// Stores all Type and Value objects.
117/// The idea is that this will be periodically garbage-collected, but such logic117/// The idea is that this will be periodically garbage-collected, but such logic
118/// is not yet implemented.118/// is not yet implemented.
119intern_pool: InternPool = .{},119intern_pool: InternPool = .empty,
120120
121analysis_in_progress: std.AutoArrayHashMapUnmanaged(AnalUnit, void) = .empty,121analysis_in_progress: std.AutoArrayHashMapUnmanaged(AnalUnit, void) = .empty,
122/// The ErrorMsg memory is owned by the `AnalUnit`, using Module's general purpose allocator.122/// The ErrorMsg memory is owned by the `AnalUnit`, using Module's general purpose allocator.