aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-08-17 14:25:18 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-08-17 18:16:03 -0700
commit7ef1eb1c27754cb0349fdc10db1f02ff2dddd99b (patch)
tree6a76839d8be347648741e17f50d6c70d8313adc3 /src/link
parent8c1329b222ab620d7388d766e9e558baa502ce93 (diff)
downloadzig-7ef1eb1c27754cb0349fdc10db1f02ff2dddd99b.tar.gz
zig-7ef1eb1c27754cb0349fdc10db1f02ff2dddd99b.zip
InternPool: safer enum API
The key changes in this commit are: ```diff - names: []const NullTerminatedString, + names: NullTerminatedString.Slice, - values: []const Index, + values: Index.Slice, ``` Which eliminates the slices from `InternPool.Key.EnumType` and replaces them with structs that contain `start` and `len` indexes. This makes the lifetime of `EnumType` change from expiring with updates to InternPool, to expiring when the InternPool is garbage-collected, which is currently never. This is gearing up for a larger change I started working on locally which moves union types into InternPool. As a bonus, I fixed some unnecessary instances of `@as`.
Diffstat (limited to 'src/link')
-rw-r--r--src/link/Dwarf.zig9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig
index 6b7744644e..b2ca85467c 100644
--- a/src/link/Dwarf.zig
+++ b/src/link/Dwarf.zig
@@ -388,9 +388,10 @@ pub const DeclState = struct {
try ty.print(dbg_info_buffer.writer(), mod);
try dbg_info_buffer.append(0);
- const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type;
- for (enum_type.names, 0..) |field_name_index, field_i| {
- const field_name = mod.intern_pool.stringToSlice(field_name_index);
+ const ip = &mod.intern_pool;
+ const enum_type = ip.indexToKey(ty.ip_index).enum_type;
+ for (enum_type.names.get(ip), 0..) |field_name_index, field_i| {
+ const field_name = ip.stringToSlice(field_name_index);
// DW.AT.enumerator
try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2 + @sizeOf(u64));
dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevKind.enum_variant));
@@ -400,7 +401,7 @@ pub const DeclState = struct {
// DW.AT.const_value, DW.FORM.data8
const value: u64 = value: {
if (enum_type.values.len == 0) break :value field_i; // auto-numbered
- const value = enum_type.values[field_i];
+ const value = enum_type.values.get(ip)[field_i];
// TODO do not assume a 64bit enum value - could be bigger.
// See https://github.com/ziglang/zig/issues/645
const field_int_val = try value.toValue().intFromEnum(ty, mod);