aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-07-01 10:52:53 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-07 22:43:52 -0700
commitf71d97e4cbb0e56213cb76657ad6c9edf6134868 (patch)
treed920c6526826ab214b8c653e9a4a39dd6f3fb5a3 /src/InternPool.zig
parentfac5fe57beb3ee34d5687da4258be22f0ed2f2f3 (diff)
downloadzig-f71d97e4cbb0e56213cb76657ad6c9edf6134868.tar.gz
zig-f71d97e4cbb0e56213cb76657ad6c9edf6134868.zip
update compiler source to new APIs
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig59
1 files changed, 29 insertions, 30 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index bfa838b5d6..5ebc1cd578 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -1881,23 +1881,23 @@ pub const NullTerminatedString = enum(u32) {
const FormatData = struct {
string: NullTerminatedString,
ip: *const InternPool,
+ id: bool,
};
- fn format(
- data: FormatData,
- comptime specifier: []const u8,
- _: std.fmt.FormatOptions,
- writer: anytype,
- ) @TypeOf(writer).Error!void {
+ fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
const slice = data.string.toSlice(data.ip);
- if (comptime std.mem.eql(u8, specifier, "")) {
+ if (!data.id) {
try writer.writeAll(slice);
- } else if (comptime std.mem.eql(u8, specifier, "i")) {
+ } else {
try writer.print("{f}", .{std.zig.fmtIdP(slice)});
- } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");
+ }
+ }
+
+ pub fn fmt(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(FormatData, format) {
+ return .{ .data = .{ .string = string, .ip = ip, .id = false } };
}
- pub fn fmt(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(format) {
- return .{ .data = .{ .string = string, .ip = ip } };
+ pub fn fmtId(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(FormatData, format) {
+ return .{ .data = .{ .string = string, .ip = ip, .id = true } };
}
const debug_state = InternPool.debug_state;
@@ -9750,7 +9750,7 @@ fn finishFuncInstance(
const fn_namespace = fn_owner_nav.analysis.?.namespace;
// TODO: improve this name
- const nav_name = try ip.getOrPutStringFmt(gpa, tid, "{}__anon_{d}", .{
+ const nav_name = try ip.getOrPutStringFmt(gpa, tid, "{f}__anon_{d}", .{
fn_owner_nav.name.fmt(ip), @intFromEnum(func_index),
}, .no_embedded_nulls);
const nav_index = try ip.createNav(gpa, tid, .{
@@ -11259,8 +11259,9 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
}
fn dumpAllFallible(ip: *const InternPool) anyerror!void {
- var bw = std.io.bufferedWriter(std.fs.File.stderr().deprecatedWriter());
- const w = bw.writer();
+ var buffer: [4096]u8 = undefined;
+ const stderr_bw = std.debug.lockStderrWriter(&buffer);
+ defer std.debug.unlockStderrWriter();
for (ip.locals, 0..) |*local, tid| {
const items = local.shared.items.view();
for (
@@ -11269,12 +11270,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
0..,
) |tag, data, index| {
const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip);
- try w.print("${d} = {s}(", .{ i, @tagName(tag) });
+ try stderr_bw.print("${d} = {s}(", .{ i, @tagName(tag) });
switch (tag) {
.removed => {},
- .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
- .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
+ .simple_type => try stderr_bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
+ .simple_value => try stderr_bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
.type_int_signed,
.type_int_unsigned,
@@ -11347,17 +11348,16 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
.func_coerced,
.union_value,
.memoized_call,
- => try w.print("{d}", .{data}),
+ => try stderr_bw.print("{d}", .{data}),
.opt_null,
.type_slice,
.only_possible_value,
- => try w.print("${d}", .{data}),
+ => try stderr_bw.print("${d}", .{data}),
}
- try w.writeAll(")\n");
+ try stderr_bw.writeAll(")\n");
}
}
- try bw.flush();
}
pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void {
@@ -11369,9 +11369,6 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
defer arena_allocator.deinit();
const arena = arena_allocator.allocator();
- var bw = std.io.bufferedWriter(std.fs.File.stderr().deprecatedWriter());
- const w = bw.writer();
-
var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .empty;
for (ip.locals, 0..) |*local, tid| {
const items = local.shared.items.view().slice();
@@ -11394,6 +11391,10 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
}
}
+ var buffer: [4096]u8 = undefined;
+ const stderr_bw = std.debug.lockStderrWriter(&buffer);
+ defer std.debug.unlockStderrWriter();
+
const SortContext = struct {
values: []std.ArrayListUnmanaged(Index),
pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {
@@ -11405,23 +11406,21 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
var it = instances.iterator();
while (it.next()) |entry| {
const generic_fn_owner_nav = ip.getNav(ip.funcDeclInfo(entry.key_ptr.*).owner_nav);
- try w.print("{} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len });
+ try stderr_bw.print("{f} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len });
for (entry.value_ptr.items) |index| {
const unwrapped_index = index.unwrap(ip);
const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip));
const owner_nav = ip.getNav(func.owner_nav);
- try w.print(" {}: (", .{owner_nav.name.fmt(ip)});
+ try stderr_bw.print(" {f}: (", .{owner_nav.name.fmt(ip)});
for (func.comptime_args.get(ip)) |arg| {
if (arg != .none) {
const key = ip.indexToKey(arg);
- try w.print(" {} ", .{key});
+ try stderr_bw.print(" {} ", .{key});
}
}
- try w.writeAll(")\n");
+ try stderr_bw.writeAll(")\n");
}
}
-
- try bw.flush();
}
pub fn getNav(ip: *const InternPool, index: Nav.Index) Nav {