From 483b3a334487a60320296b876c12ccfc05d4a9fb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Sep 2023 19:16:17 -0700 Subject: [PATCH] InternPool: implement only_possible_value prong of indexToKey for the new struct and packed struct encodings. --- src/InternPool.zig | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/InternPool.zig b/src/InternPool.zig index c5eaa41ead..2fb0b11088 100644 --- 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,20 +3872,33 @@ 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 => { @@ -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,