authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-02 14:25:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:52-07:00
log6314e6f238758ce84a288e9ed990540232d04656
treeb31d2a11b6527374a0e73800a23ae8a8cc773f4c
parentd5c97fded5d31114f8fc684938a2de22af929949

compiler: fix a bunch of format strings


5 files changed, 86 insertions(+), 96 deletions(-)

src/Package/Fetch.zig+1-1
......@@ -227,7 +227,7 @@ pub const JobQueue = struct {
227227 }
228228
229229 try buf.writer().print(
230 \\ pub const build_root = "{q}";
230 \\ pub const build_root = "{fq}";
231231 \\
232232 , .{fetch.package_root});
233233
src/arch/riscv64/CodeGen.zig+24-24
......@@ -435,7 +435,7 @@ const InstTracking = struct {
435435 fn trackSpill(inst_tracking: *InstTracking, function: *Func, inst: Air.Inst.Index) !void {
436436 try function.freeValue(inst_tracking.short);
437437 inst_tracking.reuseFrame();
438 tracking_log.debug("%{d} => {} (spilled)", .{ inst, inst_tracking.* });
438 tracking_log.debug("%{d} => {f} (spilled)", .{ inst, inst_tracking.* });
439439 }
440440
441441 fn verifyMaterialize(inst_tracking: InstTracking, target: InstTracking) void {
......@@ -1015,7 +1015,7 @@ const FormatTrackingData = struct {
10151015};
10161016fn formatTracking(data: FormatTrackingData, writer: *std.io.Writer) std.io.Writer.Error!void {
10171017 var it = data.func.inst_tracking.iterator();
1018 while (it.next()) |entry| try writer.print("\n%{d} = {}", .{ entry.key_ptr.*, entry.value_ptr.* });
1018 while (it.next()) |entry| try writer.print("\n%{d} = {f}", .{ entry.key_ptr.*, entry.value_ptr.* });
10191019}
10201020fn fmtTracking(func: *Func) std.fmt.Formatter(FormatTrackingData, formatTracking) {
10211021 return .{ .data = .{ .func = func } };
......@@ -1033,7 +1033,7 @@ fn addInst(func: *Func, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
10331033 .pseudo_dbg_epilogue_begin,
10341034 .pseudo_dead,
10351035 => false,
1036 }) wip_mir_log.debug("{}", .{func.fmtWipMir(result_index)});
1036 }) wip_mir_log.debug("{f}", .{func.fmtWipMir(result_index)});
10371037 return result_index;
10381038}
10391039
......@@ -1287,7 +1287,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
12871287 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
12881288 .@"enum" => {
12891289 const enum_ty = Type.fromInterned(lazy_sym.ty);
1290 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});
1290 wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(pt)});
12911291
12921292 const param_regs = abi.Registers.Integer.function_arg_regs;
12931293 const ret_reg = param_regs[0];
......@@ -1369,7 +1369,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
13691369 });
13701370 },
13711371 else => return func.fail(
1372 "TODO implement {s} for {}",
1372 "TODO implement {s} for {f}",
13731373 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) },
13741374 ),
13751375 }
......@@ -1383,8 +1383,8 @@ fn genBody(func: *Func, body: []const Air.Inst.Index) InnerError!void {
13831383
13841384 for (body) |inst| {
13851385 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst, ip)) continue;
1386 wip_mir_log.debug("{}", .{func.fmtAir(inst)});
1387 verbose_tracking_log.debug("{}", .{func.fmtTracking()});
1386 wip_mir_log.debug("{f}", .{func.fmtAir(inst)});
1387 verbose_tracking_log.debug("{f}", .{func.fmtTracking()});
13881388
13891389 const old_air_bookkeeping = func.air_bookkeeping;
13901390 try func.ensureProcessDeathCapacity(Air.Liveness.bpi);
......@@ -1674,7 +1674,7 @@ fn genBody(func: *Func, body: []const Air.Inst.Index) InnerError!void {
16741674 }
16751675 }
16761676 }
1677 verbose_tracking_log.debug("{}", .{func.fmtTracking()});
1677 verbose_tracking_log.debug("{f}", .{func.fmtTracking()});
16781678}
16791679
16801680fn getValue(func: *Func, value: MCValue, inst: ?Air.Inst.Index) !void {
......@@ -1891,7 +1891,7 @@ fn splitType(func: *Func, ty: Type) ![2]Type {
18911891 else => return func.fail("TODO: splitType class {}", .{class}),
18921892 };
18931893 } else if (parts[0].abiSize(zcu) + parts[1].abiSize(zcu) == ty.abiSize(zcu)) return parts;
1894 return func.fail("TODO implement splitType for {}", .{ty.fmt(func.pt)});
1894 return func.fail("TODO implement splitType for {f}", .{ty.fmt(func.pt)});
18951895}
18961896
18971897/// Truncates the value in the register in place.
......@@ -2004,7 +2004,7 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {
20042004 const val_ty = ptr_ty.childType(zcu);
20052005 return func.allocFrameIndex(FrameAlloc.init(.{
20062006 .size = math.cast(u32, val_ty.abiSize(zcu)) orelse {
2007 return func.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});
2007 return func.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(pt)});
20082008 },
20092009 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
20102010 }));
......@@ -2144,7 +2144,7 @@ pub fn spillRegisters(func: *Func, comptime registers: []const Register) !void {
21442144/// allocated. A second call to `copyToTmpRegister` may return the same register.
21452145/// This can have a side effect of spilling instructions to the stack to free up a register.
21462146fn copyToTmpRegister(func: *Func, ty: Type, mcv: MCValue) !Register {
2147 log.debug("copyToTmpRegister ty: {}", .{ty.fmt(func.pt)});
2147 log.debug("copyToTmpRegister ty: {f}", .{ty.fmt(func.pt)});
21482148 const reg = try func.register_manager.allocReg(null, func.regTempClassForType(ty));
21492149 try func.genSetReg(ty, reg, mcv);
21502150 return reg;
......@@ -2229,7 +2229,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void {
22292229 break :result null; // TODO
22302230
22312231 break :result dst_mcv;
2232 } orelse return func.fail("TODO: implement airIntCast from {} to {}", .{
2232 } orelse return func.fail("TODO: implement airIntCast from {f} to {f}", .{
22332233 src_ty.fmt(pt), dst_ty.fmt(pt),
22342234 });
22352235
......@@ -2617,7 +2617,7 @@ fn genBinOp(
26172617 .add_sat,
26182618 => {
26192619 if (bit_size != 64 or !is_unsigned)
2620 return func.fail("TODO: genBinOp ty: {}", .{lhs_ty.fmt(pt)});
2620 return func.fail("TODO: genBinOp ty: {f}", .{lhs_ty.fmt(pt)});
26212621
26222622 const tmp_reg = try func.copyToTmpRegister(rhs_ty, .{ .register = rhs_reg });
26232623 const tmp_lock = func.register_manager.lockRegAssumeUnused(tmp_reg);
......@@ -4049,7 +4049,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
40494049 );
40504050 } else {
40514051 return func.fail(
4052 "TODO implement get_union_tag for ABI larger than 8 bytes and operand {}, tag {}",
4052 "TODO implement get_union_tag for ABI larger than 8 bytes and operand {}, tag {f}",
40534053 .{ frame_mcv, tag_ty.fmt(pt) },
40544054 );
40554055 }
......@@ -4170,7 +4170,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {
41704170
41714171 switch (scalar_ty.zigTypeTag(zcu)) {
41724172 .int => if (ty.zigTypeTag(zcu) == .vector) {
4173 return func.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
4173 return func.fail("TODO implement airAbs for {f}", .{ty.fmt(pt)});
41744174 } else {
41754175 const int_info = scalar_ty.intInfo(zcu);
41764176 const int_bits = int_info.bits;
......@@ -4251,7 +4251,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {
42514251
42524252 break :result return_mcv;
42534253 },
4254 else => return func.fail("TODO: implement airAbs {}", .{scalar_ty.fmt(pt)}),
4254 else => return func.fail("TODO: implement airAbs {f}", .{scalar_ty.fmt(pt)}),
42554255 }
42564256
42574257 break :result .unreach;
......@@ -4315,7 +4315,7 @@ fn airByteSwap(func: *Func, inst: Air.Inst.Index) !void {
43154315
43164316 break :result dest_mcv;
43174317 },
4318 else => return func.fail("TODO: airByteSwap {}", .{ty.fmt(pt)}),
4318 else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(pt)}),
43194319 }
43204320 };
43214321 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -4381,7 +4381,7 @@ fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
43814381 else => return func.fail("TODO: airUnaryMath Float {s}", .{@tagName(tag)}),
43824382 }
43834383 },
4384 else => return func.fail("TODO: airUnaryMath ty: {}", .{ty.fmt(pt)}),
4384 else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(pt)}),
43854385 }
43864386
43874387 break :result MCValue{ .register = dst_reg };
......@@ -4481,7 +4481,7 @@ fn load(func: *Func, dst_mcv: MCValue, ptr_mcv: MCValue, ptr_ty: Type) InnerErro
44814481 const zcu = pt.zcu;
44824482 const dst_ty = ptr_ty.childType(zcu);
44834483
4484 log.debug("loading {}:{} into {}", .{ ptr_mcv, ptr_ty.fmt(pt), dst_mcv });
4484 log.debug("loading {}:{f} into {}", .{ ptr_mcv, ptr_ty.fmt(pt), dst_mcv });
44854485
44864486 switch (ptr_mcv) {
44874487 .none,
......@@ -4534,7 +4534,7 @@ fn airStore(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
45344534fn store(func: *Func, ptr_mcv: MCValue, src_mcv: MCValue, ptr_ty: Type) !void {
45354535 const zcu = func.pt.zcu;
45364536 const src_ty = ptr_ty.childType(zcu);
4537 log.debug("storing {}:{} in {}:{}", .{ src_mcv, src_ty.fmt(func.pt), ptr_mcv, ptr_ty.fmt(func.pt) });
4537 log.debug("storing {}:{f} in {}:{f}", .{ src_mcv, src_ty.fmt(func.pt), ptr_mcv, ptr_ty.fmt(func.pt) });
45384538
45394539 switch (ptr_mcv) {
45404540 .none => unreachable,
......@@ -7289,7 +7289,7 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
72897289 const bit_size = dst_ty.bitSize(zcu);
72907290 if (abi_size * 8 <= bit_size) break :result dst_mcv;
72917291
7292 return func.fail("TODO: airBitCast {} to {}", .{ src_ty.fmt(pt), dst_ty.fmt(pt) });
7292 return func.fail("TODO: airBitCast {f} to {f}", .{ src_ty.fmt(pt), dst_ty.fmt(pt) });
72937293 };
72947294 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
72957295}
......@@ -8105,7 +8105,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
81058105 );
81068106 break :result .{ .load_frame = .{ .index = frame_index } };
81078107 },
8108 else => return func.fail("TODO: airAggregate {}", .{result_ty.fmt(pt)}),
8108 else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(pt)}),
81098109 }
81108110 };
81118111
......@@ -8306,7 +8306,7 @@ fn resolveCallingConventionValues(
83068306 };
83078307
83088308 result.return_value = switch (ret_tracking_i) {
8309 else => return func.fail("ty {} took {} tracking return indices", .{ ret_ty.fmt(pt), ret_tracking_i }),
8309 else => return func.fail("ty {f} took {} tracking return indices", .{ ret_ty.fmt(pt), ret_tracking_i }),
83108310 1 => ret_tracking[0],
83118311 2 => InstTracking.init(.{ .register_pair = .{
83128312 ret_tracking[0].short.register, ret_tracking[1].short.register,
......@@ -8361,7 +8361,7 @@ fn resolveCallingConventionValues(
83618361 else => return func.fail("TODO: C calling convention arg class {}", .{class}),
83628362 } else {
83638363 arg.* = switch (arg_mcv_i) {
8364 else => return func.fail("ty {} took {} tracking arg indices", .{ ty.fmt(pt), arg_mcv_i }),
8364 else => return func.fail("ty {f} took {} tracking arg indices", .{ ty.fmt(pt), arg_mcv_i }),
83658365 1 => arg_mcv[0],
83668366 2 => .{ .register_pair = .{ arg_mcv[0].register, arg_mcv[1].register } },
83678367 };
src/arch/riscv64/Emit.zig+1-1
......@@ -172,7 +172,7 @@ const Reloc = struct {
172172
173173fn fixupRelocs(emit: *Emit) Error!void {
174174 for (emit.relocs.items) |reloc| {
175 log.debug("target inst: {}", .{emit.lower.mir.instructions.get(reloc.target)});
175 log.debug("target inst: {f}", .{emit.lower.mir.instructions.get(reloc.target)});
176176 const target = emit.code_offset_mapping.get(reloc.target) orelse
177177 return emit.fail("relocation target not found!", .{});
178178
src/arch/riscv64/Lower.zig+1-1
......@@ -61,7 +61,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {
6161 defer lower.result_relocs_len = undefined;
6262
6363 const inst = lower.mir.instructions.get(index);
64 log.debug("lowerMir {}", .{inst});
64 log.debug("lowerMir {f}", .{inst});
6565 switch (inst.tag) {
6666 else => try lower.generic(inst),
6767 .pseudo_dbg_line_column,
src/codegen/c.zig+59-69
......@@ -1282,7 +1282,7 @@ pub const DeclGen = struct {
12821282 }
12831283 const ai = ty.arrayInfo(zcu);
12841284 if (ai.elem_type.eql(.u8, zcu)) {
1285 var literal = stringLiteral(writer, ty.arrayLenIncludingSentinel(zcu));
1285 var literal: StringLiteral = .init(writer, ty.arrayLenIncludingSentinel(zcu));
12861286 try literal.start();
12871287 var index: usize = 0;
12881288 while (index < ai.len) : (index += 1) {
......@@ -1841,7 +1841,7 @@ pub const DeclGen = struct {
18411841 const ai = ty.arrayInfo(zcu);
18421842 if (ai.elem_type.eql(.u8, zcu)) {
18431843 const c_len = ty.arrayLenIncludingSentinel(zcu);
1844 var literal = stringLiteral(writer, c_len);
1844 var literal: StringLiteral = .init(writer, c_len);
18451845 try literal.start();
18461846 var index: u64 = 0;
18471847 while (index < c_len) : (index += 1)
......@@ -8143,7 +8143,12 @@ fn compareOperatorC(operator: std.math.CompareOperator) []const u8 {
81438143 };
81448144}
81458145
8146fn StringLiteral(comptime WriterType: type) type {
8146const StringLiteral = struct {
8147 len: usize,
8148 cur_len: usize,
8149 start_count: usize,
8150 writer: *std.io.Writer,
8151
81478152 // MSVC throws C2078 if an array of size 65536 or greater is initialized with a string literal,
81488153 // regardless of the length of the string literal initializing it. Array initializer syntax is
81498154 // used instead.
......@@ -8155,81 +8160,66 @@ fn StringLiteral(comptime WriterType: type) type {
81558160 const max_char_len = 4;
81568161 const max_literal_len = @min(16380 - max_char_len, 4095);
81578162
8158 return struct {
8159 len: u64,
8160 cur_len: u64 = 0,
8161 counting_writer: std.io.CountingWriter(WriterType),
8162
8163 pub const Error = if (WriterType == *std.io.Writer) error{WriteFailed} else WriterType.Error;
8164
8165 const Self = @This();
8163 fn init(writer: *std.io.Writer, len: usize) StringLiteral {
8164 return .{
8165 .cur_len = 0,
8166 .len = len,
8167 .start_count = writer.count,
8168 .writer = writer,
8169 };
8170 }
81668171
8167 pub fn start(self: *Self) Error!void {
8168 const writer = self.counting_writer.writer();
8169 if (self.len <= max_string_initializer_len) {
8170 try writer.writeByte('\"');
8171 } else {
8172 try writer.writeByte('{');
8173 }
8172 pub fn start(sl: *StringLiteral) std.io.Writer.Error!void {
8173 if (sl.len <= max_string_initializer_len) {
8174 try sl.writer.writeByte('\"');
8175 } else {
8176 try sl.writer.writeByte('{');
81748177 }
8178 }
81758179
8176 pub fn end(self: *Self) Error!void {
8177 const writer = self.counting_writer.writer();
8178 if (self.len <= max_string_initializer_len) {
8179 try writer.writeByte('\"');
8180 } else {
8181 try writer.writeByte('}');
8182 }
8180 pub fn end(sl: *StringLiteral) std.io.Writer.Error!void {
8181 if (sl.len <= max_string_initializer_len) {
8182 try sl.writer.writeByte('\"');
8183 } else {
8184 try sl.writer.writeByte('}');
81838185 }
8186 }
81848187
8185 fn writeStringLiteralChar(writer: anytype, c: u8) !void {
8186 switch (c) {
8187 7 => try writer.writeAll("\\a"),
8188 8 => try writer.writeAll("\\b"),
8189 '\t' => try writer.writeAll("\\t"),
8190 '\n' => try writer.writeAll("\\n"),
8191 11 => try writer.writeAll("\\v"),
8192 12 => try writer.writeAll("\\f"),
8193 '\r' => try writer.writeAll("\\r"),
8194 '"', '\'', '?', '\\' => try writer.print("\\{c}", .{c}),
8195 else => switch (c) {
8196 ' '...'~' => try writer.writeByte(c),
8197 else => try writer.print("\\{o:0>3}", .{c}),
8198 },
8199 }
8188 fn writeStringLiteralChar(sl: *StringLiteral, c: u8) std.io.Writer.Error!void {
8189 switch (c) {
8190 7 => try sl.writer.writeAll("\\a"),
8191 8 => try sl.writer.writeAll("\\b"),
8192 '\t' => try sl.writer.writeAll("\\t"),
8193 '\n' => try sl.writer.writeAll("\\n"),
8194 11 => try sl.writer.writeAll("\\v"),
8195 12 => try sl.writer.writeAll("\\f"),
8196 '\r' => try sl.writer.writeAll("\\r"),
8197 '"', '\'', '?', '\\' => try sl.writer.print("\\{c}", .{c}),
8198 else => switch (c) {
8199 ' '...'~' => try sl.writer.writeByte(c),
8200 else => try sl.writer.print("\\{o:0>3}", .{c}),
8201 },
82008202 }
8203 }
82018204
8202 pub fn writeChar(self: *Self, c: u8) Error!void {
8203 const writer = self.counting_writer.writer();
8204 if (self.len <= max_string_initializer_len) {
8205 if (self.cur_len == 0 and self.counting_writer.bytes_written > 1)
8206 try writer.writeAll("\"\"");
8207
8208 const len = self.counting_writer.bytes_written;
8209 try writeStringLiteralChar(writer, c);
8205 pub fn writeChar(sl: *StringLiteral, c: u8) std.io.Writer.Error!void {
8206 if (sl.len <= max_string_initializer_len) {
8207 if (sl.cur_len == 0 and sl.writer.count - sl.start_count > 1)
8208 try sl.writer.writeAll("\"\"");
82108209
8211 const char_length = self.counting_writer.bytes_written - len;
8212 assert(char_length <= max_char_len);
8213 self.cur_len += char_length;
8210 const count = sl.writer.count;
8211 try sl.writeStringLiteralChar(c);
8212 const char_len = sl.writer.count - count;
8213 assert(char_len <= max_char_len);
8214 sl.cur_len += char_len;
82148215
8215 if (self.cur_len >= max_literal_len) self.cur_len = 0;
8216 } else {
8217 if (self.counting_writer.bytes_written > 1) try writer.writeByte(',');
8218 try writer.print("'\\x{x}'", .{c});
8219 }
8216 if (sl.cur_len >= max_literal_len) sl.cur_len = 0;
8217 } else {
8218 if (sl.writer.count - sl.start_count > 1) try sl.writer.writeByte(',');
8219 try sl.writer.print("'\\x{x}'", .{c});
82208220 }
8221 };
8222}
8223
8224fn stringLiteral(
8225 child_stream: anytype,
8226 len: u64,
8227) StringLiteral(@TypeOf(child_stream)) {
8228 return .{
8229 .len = len,
8230 .counting_writer = std.io.countingWriter(child_stream),
8231 };
8232}
8221 }
8222};
82338223
82348224const FormatStringContext = struct {
82358225 str: []const u8,
......@@ -8237,7 +8227,7 @@ const FormatStringContext = struct {
82378227};
82388228
82398229fn formatStringLiteral(data: FormatStringContext, writer: *std.io.Writer) std.io.Writer.Error!void {
8240 var literal = stringLiteral(writer, data.str.len + @intFromBool(data.sentinel != null));
8230 var literal: StringLiteral = .init(writer, data.str.len + @intFromBool(data.sentinel != null));
82418231 try literal.start();
82428232 for (data.str) |c| try literal.writeChar(c);
82438233 if (data.sentinel) |sentinel| if (sentinel != 0) try literal.writeChar(sentinel);