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 {...@@ -2765,8 +2765,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2765 .func => .{ .func = ip.extraData(Key.Func, data) },2765 .func => .{ .func = ip.extraData(Key.Func, data) },
2766 .only_possible_value => {2766 .only_possible_value => {
2767 const ty = @intToEnum(Index, data);2767 const ty = @intToEnum(Index, data);
2768 return switch (ip.indexToKey(ty)) {2768 const ty_item = ip.items.get(@enumToInt(ty));
2769 .array_type, .vector_type => .{ .aggregate = .{2769 return switch (ty_item.tag) {
2770 .type_array_big, .type_array_small, .type_vector => .{ .aggregate = .{
2770 .ty = ty,2771 .ty = ty,
2771 .storage = .{ .elems = &.{} },2772 .storage = .{ .elems = &.{} },
2772 } },2773 } },
...@@ -2775,16 +2776,23 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -2775,16 +2776,23 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
2775 // have a slice of comptime values that can be used here for when2776 // have a slice of comptime values that can be used here for when
2776 // the struct has one possible value due to all fields comptime (same2777 // the struct has one possible value due to all fields comptime (same
2777 // as the tuple case below).2778 // as the tuple case below).
2778 .struct_type => .{ .aggregate = .{2779 .type_struct, .type_struct_ns => .{ .aggregate = .{
2779 .ty = ty,2780 .ty = ty,
2780 .storage = .{ .elems = &.{} },2781 .storage = .{ .elems = &.{} },
2781 } },2782 } },
2783
2782 // There is only one possible value precisely due to the2784 // There is only one possible value precisely due to the
2783 // fact that this values slice is fully populated!2785 // fact that this values slice is fully populated!
2784 .anon_struct_type => |anon_struct_type| .{ .aggregate = .{2786 .type_struct_anon, .type_tuple_anon => {
2785 .ty = ty,2787 const type_struct_anon = ip.extraDataTrail(TypeStructAnon, ty_item.data);
2786 .storage = .{ .elems = anon_struct_type.values },2788 const fields_len = type_struct_anon.data.fields_len;
2787 } },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
2788 else => unreachable,2796 else => unreachable,
2789 };2797 };
2790 },2798 },