zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 483b3a334487a60320296b876c12ccfc05d4a9fb (tree)
parent b65f3d8826a71cf9e0603561ae9dfdbd501e05a9
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 19 Sep 2023 19:16:17 -0700

InternPool: implement only_possible_value prong of indexToKey

for the new struct and packed struct encodings.

Diffstat:
Msrc/InternPool.zig | 40++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/InternPool.zig b/src/InternPool.zig @@ -3859,7 +3859,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { .func_decl => .{ .func = ip.extraFuncDecl(data) }, .func_coerced => .{ .func = ip.extraFuncCoerced(data) }, .only_possible_value => { - const ty = @as(Index, @enumFromInt(data)); + const ty: Index = @enumFromInt(data); const ty_item = ip.items.get(@intFromEnum(ty)); return switch (ty_item.tag) { .type_array_big => { @@ -3872,22 +3872,35 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { .storage = .{ .elems = sentinel[0..@intFromBool(sentinel[0] != .none)] }, } }; }, - .type_array_small, .type_vector => .{ .aggregate = .{ - .ty = ty, - .storage = .{ .elems = &.{} }, - } }, - // TODO: migrate structs to properly use the InternPool rather - // than using the SegmentedList trick, then the struct type will - // have a slice of comptime values that can be used here for when - // the struct has one possible value due to all fields comptime (same - // as the tuple case below). - .type_struct, .type_struct_ns => .{ .aggregate = .{ + .type_array_small, + .type_vector, + .type_struct_ns, + .type_struct_packed, + => .{ .aggregate = .{ .ty = ty, .storage = .{ .elems = &.{} }, } }, // There is only one possible value precisely due to the // fact that this values slice is fully populated! + .type_struct => { + const info = extraStructType(ip, ty_item.data); + return .{ .aggregate = .{ + .ty = ty, + .storage = .{ .elems = @ptrCast(info.field_inits.get(ip)) }, + } }; + }, + + .type_struct_packed_inits => { + const info = extraPackedStructType(ip, ty_item.data, true); + return .{ .aggregate = .{ + .ty = ty, + .storage = .{ .elems = @ptrCast(info.field_inits.get(ip)) }, + } }; + }, + + // There is only one possible value precisely due to the + // fact that this values slice is fully populated! .type_struct_anon, .type_tuple_anon => { const type_struct_anon = ip.extraDataTrail(TypeStructAnon, ty_item.data); const fields_len = type_struct_anon.data.fields_len; @@ -3898,11 +3911,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { } }; }, - .type_struct_packed, .type_struct_packed_inits => { - // a packed struct has a 0-bit backing type - @panic("TODO"); - }, - .type_enum_auto, .type_enum_explicit, .type_union,