aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-02-01 16:58:52 +0000
committerMatthew Lugg <mlugg@mlugg.co.uk>2024-02-02 11:02:03 +0000
commit9eda6ccefce370c76209ea50dd57fe65bfe25536 (patch)
treed5b4af496b8a6d1811788557d85e340ce26ef2bc /src/Module.zig
parent5a3ae38f3b79a69cb6f4ad28934a51165cae2ef1 (diff)
downloadzig-9eda6ccefce370c76209ea50dd57fe65bfe25536.tar.gz
zig-9eda6ccefce370c76209ea50dd57fe65bfe25536.zip
InternPool: use separate key for slices
This change eliminates some problematic recursive logic in InternPool, and provides a safer API.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 499eb02f1e..1b3342f775 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -5278,9 +5278,12 @@ pub fn populateTestFunctions(
const test_fn_fields = .{
// name
- try mod.intern(.{ .ptr = .{
+ try mod.intern(.{ .slice = .{
.ty = .slice_const_u8_type,
- .addr = .{ .decl = test_name_decl_index },
+ .ptr = try mod.intern(.{ .ptr = .{
+ .ty = .manyptr_const_u8_type,
+ .addr = .{ .decl = test_name_decl_index },
+ } }),
.len = try mod.intern(.{ .int = .{
.ty = .usize_type,
.storage = .{ .u64 = test_decl_name.len },
@@ -5331,9 +5334,12 @@ pub fn populateTestFunctions(
},
});
const new_val = decl.val;
- const new_init = try mod.intern(.{ .ptr = .{
+ const new_init = try mod.intern(.{ .slice = .{
.ty = new_ty.toIntern(),
- .addr = .{ .decl = array_decl_index },
+ .ptr = try mod.intern(.{ .ptr = .{
+ .ty = new_ty.slicePtrFieldType(mod).toIntern(),
+ .addr = .{ .decl = array_decl_index },
+ } }),
.len = (try mod.intValue(Type.usize, mod.test_functions.count())).toIntern(),
} });
ip.mutateVarInit(decl.val.toIntern(), new_init);
@@ -5423,16 +5429,17 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
.err_name => {},
.payload => |payload| try mod.markReferencedDeclsAlive(Value.fromInterned(payload)),
},
- .ptr => |ptr| {
- switch (ptr.addr) {
- .decl => |decl| try mod.markDeclIndexAlive(decl),
- .anon_decl => {},
- .mut_decl => |mut_decl| try mod.markDeclIndexAlive(mut_decl.decl),
- .int, .comptime_field => {},
- .eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(Value.fromInterned(parent)),
- .elem, .field => |base_index| try mod.markReferencedDeclsAlive(Value.fromInterned(base_index.base)),
- }
- if (ptr.len != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(ptr.len));
+ .slice => |slice| {
+ try mod.markReferencedDeclsAlive(Value.fromInterned(slice.ptr));
+ try mod.markReferencedDeclsAlive(Value.fromInterned(slice.len));
+ },
+ .ptr => |ptr| switch (ptr.addr) {
+ .decl => |decl| try mod.markDeclIndexAlive(decl),
+ .anon_decl => {},
+ .mut_decl => |mut_decl| try mod.markDeclIndexAlive(mut_decl.decl),
+ .int, .comptime_field => {},
+ .eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(Value.fromInterned(parent)),
+ .elem, .field => |base_index| try mod.markReferencedDeclsAlive(Value.fromInterned(base_index.base)),
},
.opt => |opt| if (opt.val != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(opt.val)),
.aggregate => |aggregate| for (aggregate.storage.values()) |elem|