authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-31 17:38:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:58-07:00
logc82a04d35f529c7dc8301059a0fe0b204f111145
tree047f10197cb3915ffc37d0ba700d6e87cac37d83
parentbb526426e75ed456a7db6afa32447e5a76ac7ca1

InternPool: debug dump all the data


1 files changed, 105 insertions(+), 13 deletions(-)

src/InternPool.zig+105-13
......@@ -1453,7 +1453,7 @@ pub const Index = enum(u32) {
14531453 float_comptime_float: struct { data: *Float128 },
14541454 variable: struct { data: *Tag.Variable },
14551455 extern_func: struct { data: *Key.ExternFunc },
1456 func: struct { data: *Key.Func },
1456 func: struct { data: *Tag.Func },
14571457 only_possible_value: DataIsIndex,
14581458 union_value: struct { data: *Key.Union },
14591459 bytes: struct { data: *Bytes },
......@@ -1949,7 +1949,7 @@ pub const Tag = enum(u8) {
19491949 /// data is extra index to Key.ExternFunc.
19501950 extern_func,
19511951 /// A regular function.
1952 /// data is extra index to Key.Func.
1952 /// data is extra index to Func.
19531953 func,
19541954 /// This represents the only possible value for *some* types which have
19551955 /// only one possible value. Not all only-possible-values are encoded this way;
......@@ -2893,8 +2893,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
28932893 .is_weak_linkage = extra.flags.is_weak_linkage,
28942894 } };
28952895 },
2896 .extern_func => .{ .extern_func = ip.extraData(Key.ExternFunc, data) },
2897 .func => .{ .func = ip.extraData(Key.Func, data) },
2896 .extern_func => .{ .extern_func = ip.extraData(Tag.ExternFunc, data) },
2897 .func => .{ .func = ip.extraData(Tag.Func, data) },
28982898 .only_possible_value => {
28992899 const ty = @intToEnum(Index, data);
29002900 const ty_item = ip.items.get(@enumToInt(ty));
......@@ -3349,12 +3349,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
33493349
33503350 .extern_func => |extern_func| ip.items.appendAssumeCapacity(.{
33513351 .tag = .extern_func,
3352 .data = try ip.addExtra(gpa, extern_func),
3352 .data = try ip.addExtra(gpa, @as(Tag.ExternFunc, extern_func)),
33533353 }),
33543354
33553355 .func => |func| ip.items.appendAssumeCapacity(.{
33563356 .tag = .func,
3357 .data = try ip.addExtra(gpa, func),
3357 .data = try ip.addExtra(gpa, @as(Tag.Func, func)),
33583358 }),
33593359
33603360 .ptr => |ptr| {
......@@ -4715,7 +4715,7 @@ pub fn indexToFunc(ip: *const InternPool, val: Index) Module.Fn.OptionalIndex {
47154715 const tags = ip.items.items(.tag);
47164716 if (tags[@enumToInt(val)] != .func) return .none;
47174717 const datas = ip.items.items(.data);
4718 return ip.extraData(Key.Func, datas[@enumToInt(val)]).index.toOptional();
4718 return ip.extraData(Tag.Func, datas[@enumToInt(val)]).index.toOptional();
47194719}
47204720
47214721pub fn indexToInferredErrorSetType(ip: *const InternPool, val: Index) Module.Fn.InferredErrorSet.OptionalIndex {
......@@ -4807,10 +4807,11 @@ pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {
48074807}
48084808
48094809pub fn dump(ip: *const InternPool) void {
4810 dumpFallible(ip, std.heap.page_allocator) catch return;
4810 dumpStatsFallible(ip, std.heap.page_allocator) catch return;
4811 dumpAllFallible(ip) catch return;
48114812}
48124813
4813fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
4814fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
48144815 const items_size = (1 + 4) * ip.items.len;
48154816 const extra_size = 4 * ip.extra.items.len;
48164817 const limbs_size = 8 * ip.limbs.items.len;
......@@ -4969,8 +4970,8 @@ fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
49694970 .float_c_longdouble_f128 => @sizeOf(Float128),
49704971 .float_comptime_float => @sizeOf(Float128),
49714972 .variable => @sizeOf(Tag.Variable) + @sizeOf(Module.Decl),
4972 .extern_func => @sizeOf(Key.ExternFunc) + @sizeOf(Module.Decl),
4973 .func => @sizeOf(Key.Func) + @sizeOf(Module.Fn) + @sizeOf(Module.Decl),
4973 .extern_func => @sizeOf(Tag.ExternFunc) + @sizeOf(Module.Decl),
4974 .func => @sizeOf(Tag.Func) + @sizeOf(Module.Fn) + @sizeOf(Module.Decl),
49744975 .only_possible_value => 0,
49754976 .union_value => @sizeOf(Key.Union),
49764977
......@@ -4989,8 +4990,8 @@ fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
49894990 }
49904991 };
49914992 counts.sort(SortContext{ .map = &counts });
4992 const len = @min(25, counts.count());
4993 std.debug.print(" top 25 tags:\n", .{});
4993 const len = @min(50, counts.count());
4994 std.debug.print(" top 50 tags:\n", .{});
49944995 for (counts.keys()[0..len], counts.values()[0..len]) |tag, stats| {
49954996 std.debug.print(" {s}: {d} occurrences, {d} total bytes\n", .{
49964997 @tagName(tag), stats.count, stats.bytes,
......@@ -4998,6 +4999,97 @@ fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
49984999 }
49995000}
50005001
5002fn dumpAllFallible(ip: *const InternPool) anyerror!void {
5003 const tags = ip.items.items(.tag);
5004 const datas = ip.items.items(.data);
5005 var bw = std.io.bufferedWriter(std.io.getStdErr().writer());
5006 const w = bw.writer();
5007 for (tags, datas, 0..) |tag, data, i| {
5008 try w.print("${d} = {s}(", .{ i, @tagName(tag) });
5009 switch (tag) {
5010 .simple_type => try w.print("{s}", .{@tagName(@intToEnum(SimpleType, data))}),
5011 .simple_value => try w.print("{s}", .{@tagName(@intToEnum(SimpleValue, data))}),
5012
5013 .type_int_signed,
5014 .type_int_unsigned,
5015 .type_array_small,
5016 .type_array_big,
5017 .type_vector,
5018 .type_pointer,
5019 .type_optional,
5020 .type_anyframe,
5021 .type_error_union,
5022 .type_error_set,
5023 .type_inferred_error_set,
5024 .type_enum_explicit,
5025 .type_enum_nonexhaustive,
5026 .type_enum_auto,
5027 .type_opaque,
5028 .type_struct,
5029 .type_struct_ns,
5030 .type_struct_anon,
5031 .type_tuple_anon,
5032 .type_union_tagged,
5033 .type_union_untagged,
5034 .type_union_safety,
5035 .type_function,
5036 .undef,
5037 .runtime_value,
5038 .ptr_decl,
5039 .ptr_mut_decl,
5040 .ptr_comptime_field,
5041 .ptr_int,
5042 .ptr_eu_payload,
5043 .ptr_opt_payload,
5044 .ptr_elem,
5045 .ptr_field,
5046 .ptr_slice,
5047 .opt_payload,
5048 .int_u8,
5049 .int_u16,
5050 .int_u32,
5051 .int_i32,
5052 .int_usize,
5053 .int_comptime_int_u32,
5054 .int_comptime_int_i32,
5055 .int_small,
5056 .int_positive,
5057 .int_negative,
5058 .int_lazy_align,
5059 .int_lazy_size,
5060 .error_set_error,
5061 .error_union_error,
5062 .error_union_payload,
5063 .enum_literal,
5064 .enum_tag,
5065 .bytes,
5066 .aggregate,
5067 .repeated,
5068 .float_f16,
5069 .float_f32,
5070 .float_f64,
5071 .float_f80,
5072 .float_f128,
5073 .float_c_longdouble_f80,
5074 .float_c_longdouble_f128,
5075 .float_comptime_float,
5076 .variable,
5077 .extern_func,
5078 .func,
5079 .union_value,
5080 .memoized_call,
5081 => try w.print("{d}", .{data}),
5082
5083 .opt_null,
5084 .type_slice,
5085 .only_possible_value,
5086 => try w.print("${d}", .{data}),
5087 }
5088 try w.writeAll(")\n");
5089 }
5090 try bw.flush();
5091}
5092
50015093pub fn structPtr(ip: *InternPool, index: Module.Struct.Index) *Module.Struct {
50025094 return ip.allocated_structs.at(@enumToInt(index));
50035095}