| ... | ... | @@ -1453,7 +1453,7 @@ pub const Index = enum(u32) { |
| 1453 | 1453 | float_comptime_float: struct { data: *Float128 }, |
| 1454 | 1454 | variable: struct { data: *Tag.Variable }, |
| 1455 | 1455 | extern_func: struct { data: *Key.ExternFunc }, |
| 1456 | | func: struct { data: *Key.Func }, |
| 1456 | func: struct { data: *Tag.Func }, |
| 1457 | 1457 | only_possible_value: DataIsIndex, |
| 1458 | 1458 | union_value: struct { data: *Key.Union }, |
| 1459 | 1459 | bytes: struct { data: *Bytes }, |
| ... | ... | @@ -1949,7 +1949,7 @@ pub const Tag = enum(u8) { |
| 1949 | 1949 | /// data is extra index to Key.ExternFunc. |
| 1950 | 1950 | extern_func, |
| 1951 | 1951 | /// A regular function. |
| 1952 | | /// data is extra index to Key.Func. |
| 1952 | /// data is extra index to Func. |
| 1953 | 1953 | func, |
| 1954 | 1954 | /// This represents the only possible value for *some* types which have |
| 1955 | 1955 | /// 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 { |
| 2893 | 2893 | .is_weak_linkage = extra.flags.is_weak_linkage, |
| 2894 | 2894 | } }; |
| 2895 | 2895 | }, |
| 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) }, |
| 2898 | 2898 | .only_possible_value => { |
| 2899 | 2899 | const ty = @intToEnum(Index, data); |
| 2900 | 2900 | const ty_item = ip.items.get(@enumToInt(ty)); |
| ... | ... | @@ -3349,12 +3349,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3349 | 3349 | |
| 3350 | 3350 | .extern_func => |extern_func| ip.items.appendAssumeCapacity(.{ |
| 3351 | 3351 | .tag = .extern_func, |
| 3352 | | .data = try ip.addExtra(gpa, extern_func), |
| 3352 | .data = try ip.addExtra(gpa, @as(Tag.ExternFunc, extern_func)), |
| 3353 | 3353 | }), |
| 3354 | 3354 | |
| 3355 | 3355 | .func => |func| ip.items.appendAssumeCapacity(.{ |
| 3356 | 3356 | .tag = .func, |
| 3357 | | .data = try ip.addExtra(gpa, func), |
| 3357 | .data = try ip.addExtra(gpa, @as(Tag.Func, func)), |
| 3358 | 3358 | }), |
| 3359 | 3359 | |
| 3360 | 3360 | .ptr => |ptr| { |
| ... | ... | @@ -4715,7 +4715,7 @@ pub fn indexToFunc(ip: *const InternPool, val: Index) Module.Fn.OptionalIndex { |
| 4715 | 4715 | const tags = ip.items.items(.tag); |
| 4716 | 4716 | if (tags[@enumToInt(val)] != .func) return .none; |
| 4717 | 4717 | 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(); |
| 4719 | 4719 | } |
| 4720 | 4720 | |
| 4721 | 4721 | pub 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 { |
| 4807 | 4807 | } |
| 4808 | 4808 | |
| 4809 | 4809 | pub 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; |
| 4811 | 4812 | } |
| 4812 | 4813 | |
| 4813 | | fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 4814 | fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 4814 | 4815 | const items_size = (1 + 4) * ip.items.len; |
| 4815 | 4816 | const extra_size = 4 * ip.extra.items.len; |
| 4816 | 4817 | const limbs_size = 8 * ip.limbs.items.len; |
| ... | ... | @@ -4969,8 +4970,8 @@ fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 4969 | 4970 | .float_c_longdouble_f128 => @sizeOf(Float128), |
| 4970 | 4971 | .float_comptime_float => @sizeOf(Float128), |
| 4971 | 4972 | .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), |
| 4974 | 4975 | .only_possible_value => 0, |
| 4975 | 4976 | .union_value => @sizeOf(Key.Union), |
| 4976 | 4977 | |
| ... | ... | @@ -4989,8 +4990,8 @@ fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 4989 | 4990 | } |
| 4990 | 4991 | }; |
| 4991 | 4992 | 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", .{}); |
| 4994 | 4995 | for (counts.keys()[0..len], counts.values()[0..len]) |tag, stats| { |
| 4995 | 4996 | std.debug.print(" {s}: {d} occurrences, {d} total bytes\n", .{ |
| 4996 | 4997 | @tagName(tag), stats.count, stats.bytes, |
| ... | ... | @@ -4998,6 +4999,97 @@ fn dumpFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 4998 | 4999 | } |
| 4999 | 5000 | } |
| 5000 | 5001 | |
| 5002 | fn 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 | |
| 5001 | 5093 | pub fn structPtr(ip: *InternPool, index: Module.Struct.Index) *Module.Struct { |
| 5002 | 5094 | return ip.allocated_structs.at(@enumToInt(index)); |
| 5003 | 5095 | } |