authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-29 16:52:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:56-07:00
logf2778f7ca07cdfd599c65185dbcc6a648740fd5d
treedb62e2ecc46ae0f927ec1243bc722ab4b45b42b9
parentb336866fbc1edd4c999d3cd5d62ae7230d176fa7

InternPool: avoid indexToKey recursion for only_possible_value

This is a hot function, and recursion makes it more difficult to profile, as well as likely making it more difficult to optimize.

1 files changed, 15 insertions(+), 7 deletions(-)

src/InternPool.zig+15-7
......@@ -2765,8 +2765,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
27652765 .func => .{ .func = ip.extraData(Key.Func, data) },
27662766 .only_possible_value => {
27672767 const ty = @intToEnum(Index, data);
2768 return switch (ip.indexToKey(ty)) {
2769 .array_type, .vector_type => .{ .aggregate = .{
2768 const ty_item = ip.items.get(@enumToInt(ty));
2769 return switch (ty_item.tag) {
2770 .type_array_big, .type_array_small, .type_vector => .{ .aggregate = .{
27702771 .ty = ty,
27712772 .storage = .{ .elems = &.{} },
27722773 } },
......@@ -2775,16 +2776,23 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
27752776 // have a slice of comptime values that can be used here for when
27762777 // the struct has one possible value due to all fields comptime (same
27772778 // as the tuple case below).
2778 .struct_type => .{ .aggregate = .{
2779 .type_struct, .type_struct_ns => .{ .aggregate = .{
27792780 .ty = ty,
27802781 .storage = .{ .elems = &.{} },
27812782 } },
2783
27822784 // There is only one possible value precisely due to the
27832785 // fact that this values slice is fully populated!
2784 .anon_struct_type => |anon_struct_type| .{ .aggregate = .{
2785 .ty = ty,
2786 .storage = .{ .elems = anon_struct_type.values },
2787 } },
2786 .type_struct_anon, .type_tuple_anon => {
2787 const type_struct_anon = ip.extraDataTrail(TypeStructAnon, ty_item.data);
2788 const fields_len = type_struct_anon.data.fields_len;
2789 const values = ip.extra.items[type_struct_anon.end + fields_len ..][0..fields_len];
2790 return .{ .aggregate = .{
2791 .ty = ty,
2792 .storage = .{ .elems = @ptrCast([]const Index, values) },
2793 } };
2794 },
2795
27882796 else => unreachable,
27892797 };
27902798 },