Skip to content

Commit 16c2c0e

Browse files
committed
InternPool: Replace default values with a .empty declaration
1 parent addaacc commit 16c2c0e

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/InternPool.zig

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,57 @@
22
//! This data structure is self-contained.
33

44
/// One item per thread, indexed by `tid`, which is dense and unique per thread.
5-
locals: []Local = &.{},
5+
locals: []Local,
66
/// Length must be a power of two and represents the number of simultaneous
77
/// writers that can mutate any single sharded data structure.
8-
shards: []Shard = &.{},
8+
shards: []Shard,
99
/// Key is the error name, index is the error tag value. Index 0 has a length-0 string.
10-
global_error_set: GlobalErrorSet = GlobalErrorSet.empty,
10+
global_error_set: GlobalErrorSet,
1111
/// Cached number of active bits in a `tid`.
12-
tid_width: if (single_threaded) u0 else std.math.Log2Int(u32) = 0,
12+
tid_width: if (single_threaded) u0 else std.math.Log2Int(u32),
1313
/// Cached shift amount to put a `tid` in the top bits of a 30-bit value.
14-
tid_shift_30: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,
14+
tid_shift_30: if (single_threaded) u0 else std.math.Log2Int(u32),
1515
/// Cached shift amount to put a `tid` in the top bits of a 31-bit value.
16-
tid_shift_31: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,
16+
tid_shift_31: if (single_threaded) u0 else std.math.Log2Int(u32),
1717
/// Cached shift amount to put a `tid` in the top bits of a 32-bit value.
18-
tid_shift_32: if (single_threaded) u0 else std.math.Log2Int(u32) = if (single_threaded) 0 else 31,
18+
tid_shift_32: if (single_threaded) u0 else std.math.Log2Int(u32),
1919

2020
/// Dependencies on the source code hash associated with a ZIR instruction.
2121
/// * For a `declaration`, this is the entire declaration body.
2222
/// * For a `struct_decl`, `union_decl`, etc, this is the source of the fields (but not declarations).
2323
/// * For a `func`, this is the source of the full function signature.
2424
/// These are also invalidated if tracking fails for this instruction.
2525
/// Value is index into `dep_entries` of the first dependency on this hash.
26-
src_hash_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index) = .empty,
26+
src_hash_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index),
2727
/// Dependencies on the value of a Nav.
2828
/// Value is index into `dep_entries` of the first dependency on this Nav value.
29-
nav_val_deps: std.AutoArrayHashMapUnmanaged(Nav.Index, DepEntry.Index) = .empty,
29+
nav_val_deps: std.AutoArrayHashMapUnmanaged(Nav.Index, DepEntry.Index),
3030
/// Dependencies on an interned value, either:
3131
/// * a runtime function (invalidated when its IES changes)
3232
/// * a container type requiring resolution (invalidated when the type must be recreated at a new index)
3333
/// Value is index into `dep_entries` of the first dependency on this interned value.
34-
interned_deps: std.AutoArrayHashMapUnmanaged(Index, DepEntry.Index) = .empty,
34+
interned_deps: std.AutoArrayHashMapUnmanaged(Index, DepEntry.Index),
3535
/// Dependencies on the full set of names in a ZIR namespace.
3636
/// Key refers to a `struct_decl`, `union_decl`, etc.
3737
/// Value is index into `dep_entries` of the first dependency on this namespace.
38-
namespace_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index) = .empty,
38+
namespace_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index),
3939
/// Dependencies on the (non-)existence of some name in a namespace.
4040
/// Value is index into `dep_entries` of the first dependency on this name.
41-
namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.Index) = .empty,
41+
namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.Index),
4242

4343
/// Given a `Depender`, points to an entry in `dep_entries` whose `depender`
4444
/// matches. The `next_dependee` field can be used to iterate all such entries
4545
/// and remove them from the corresponding lists.
46-
first_dependency: std.AutoArrayHashMapUnmanaged(AnalUnit, DepEntry.Index) = .empty,
46+
first_dependency: std.AutoArrayHashMapUnmanaged(AnalUnit, DepEntry.Index),
4747

4848
/// Stores dependency information. The hashmaps declared above are used to look
4949
/// up entries in this list as required. This is not stored in `extra` so that
5050
/// we can use `free_dep_entries` to track free indices, since dependencies are
5151
/// removed frequently.
52-
dep_entries: std.ArrayListUnmanaged(DepEntry) = .empty,
52+
dep_entries: std.ArrayListUnmanaged(DepEntry),
5353
/// Stores unused indices in `dep_entries` which can be reused without a full
5454
/// garbage collection pass.
55-
free_dep_entries: std.ArrayListUnmanaged(DepEntry.Index) = .empty,
55+
free_dep_entries: std.ArrayListUnmanaged(DepEntry.Index),
5656

5757
/// Whether a multi-threaded intern pool is useful.
5858
/// Currently `false` until the intern pool is actually accessed
@@ -62,6 +62,24 @@ const want_multi_threaded = true;
6262
/// Whether a single-threaded intern pool impl is in use.
6363
pub const single_threaded = builtin.single_threaded or !want_multi_threaded;
6464

65+
pub 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+
6583
/// A `TrackedInst.Index` provides a single, unchanging reference to a ZIR instruction across a whole
6684
/// compilation. From this index, you can acquire a `TrackedInst`, which containss a reference to both
6785
/// 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 {
98589876
test "basic usage" {
98599877
const gpa = std.testing.allocator;
98609878

9861-
var ip: InternPool = .{};
9879+
var ip: InternPool = .empty;
98629880
defer ip.deinit(gpa);
98639881

98649882
const i32_type = try ip.get(gpa, .main, .{ .int_type = .{

src/Zcu.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ embed_table: std.StringArrayHashMapUnmanaged(*EmbedFile) = .empty,
116116
/// Stores all Type and Value objects.
117117
/// The idea is that this will be periodically garbage-collected, but such logic
118118
/// is not yet implemented.
119-
intern_pool: InternPool = .{},
119+
intern_pool: InternPool = .empty,
120120

121121
analysis_in_progress: std.AutoArrayHashMapUnmanaged(AnalUnit, void) = .empty,
122122
/// The ErrorMsg memory is owned by the `AnalUnit`, using Module's general purpose allocator.

0 commit comments

Comments
 (0)