authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 19:16:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 14:48:40-07:00
log483b3a334487a60320296b876c12ccfc05d4a9fb
tree622373a5845872dff7df53e8258305ca4c5f86ae
parentb65f3d8826a71cf9e0603561ae9dfdbd501e05a9

InternPool: implement only_possible_value prong of indexToKey

for the new struct and packed struct encodings.

1 files changed, 24 insertions(+), 16 deletions(-)

src/InternPool.zig+24-16
...@@ -3859,7 +3859,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3859,7 +3859,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
3859 .func_decl => .{ .func = ip.extraFuncDecl(data) },3859 .func_decl => .{ .func = ip.extraFuncDecl(data) },
3860 .func_coerced => .{ .func = ip.extraFuncCoerced(data) },3860 .func_coerced => .{ .func = ip.extraFuncCoerced(data) },
3861 .only_possible_value => {3861 .only_possible_value => {
3862 const ty = @as(Index, @enumFromInt(data));3862 const ty: Index = @enumFromInt(data);
3863 const ty_item = ip.items.get(@intFromEnum(ty));3863 const ty_item = ip.items.get(@intFromEnum(ty));
3864 return switch (ty_item.tag) {3864 return switch (ty_item.tag) {
3865 .type_array_big => {3865 .type_array_big => {
...@@ -3872,20 +3872,33 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3872,20 +3872,33 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
3872 .storage = .{ .elems = sentinel[0..@intFromBool(sentinel[0] != .none)] },3872 .storage = .{ .elems = sentinel[0..@intFromBool(sentinel[0] != .none)] },
3873 } };3873 } };
3874 },3874 },
3875 .type_array_small, .type_vector => .{ .aggregate = .{3875 .type_array_small,
3876 .ty = ty,3876 .type_vector,
3877 .storage = .{ .elems = &.{} },3877 .type_struct_ns,
3878 } },3878 .type_struct_packed,
3879 // TODO: migrate structs to properly use the InternPool rather3879 => .{ .aggregate = .{
3880 // than using the SegmentedList trick, then the struct type will
3881 // have a slice of comptime values that can be used here for when
3882 // the struct has one possible value due to all fields comptime (same
3883 // as the tuple case below).
3884 .type_struct, .type_struct_ns => .{ .aggregate = .{
3885 .ty = ty,3880 .ty = ty,
3886 .storage = .{ .elems = &.{} },3881 .storage = .{ .elems = &.{} },
3887 } },3882 } },
38883883
3884 // There is only one possible value precisely due to the
3885 // fact that this values slice is fully populated!
3886 .type_struct => {
3887 const info = extraStructType(ip, ty_item.data);
3888 return .{ .aggregate = .{
3889 .ty = ty,
3890 .storage = .{ .elems = @ptrCast(info.field_inits.get(ip)) },
3891 } };
3892 },
3893
3894 .type_struct_packed_inits => {
3895 const info = extraPackedStructType(ip, ty_item.data, true);
3896 return .{ .aggregate = .{
3897 .ty = ty,
3898 .storage = .{ .elems = @ptrCast(info.field_inits.get(ip)) },
3899 } };
3900 },
3901
3889 // There is only one possible value precisely due to the3902 // There is only one possible value precisely due to the
3890 // fact that this values slice is fully populated!3903 // fact that this values slice is fully populated!
3891 .type_struct_anon, .type_tuple_anon => {3904 .type_struct_anon, .type_tuple_anon => {
...@@ -3898,11 +3911,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -3898,11 +3911,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
3898 } };3911 } };
3899 },3912 },
39003913
3901 .type_struct_packed, .type_struct_packed_inits => {
3902 // a packed struct has a 0-bit backing type
3903 @panic("TODO");
3904 },
3905
3906 .type_enum_auto,3914 .type_enum_auto,
3907 .type_enum_explicit,3915 .type_enum_explicit,
3908 .type_union,3916 .type_union,