convert more {} to {d} and {s}

This commit is contained in:
Andrew Kelley 2021-01-02 19:03:14 -07:00
parent 5b981b1be7
commit 974c008a0e
23 changed files with 97 additions and 97 deletions

View File

@ -163,7 +163,7 @@ pub fn format(
out_stream: anytype,
) !void {
if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");
try std.fmt.format(out_stream, "{}.{}.{}", .{ self.major, self.minor, self.patch });
try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});
}

View File

@ -115,10 +115,10 @@ pub const Error = union(enum) {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
const found_token = tree.tokens.at(self.token);
if (found_token.id == .Invalid) {
return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
return stream.print("expected '{s}', found invalid bytes", .{self.expected_id.symbol()});
} else {
const token_name = found_token.id.symbol();
return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name });
return stream.print("expected '{s}', found '{s}'", .{ self.expected_id.symbol(), token_name });
}
}
};
@ -131,7 +131,7 @@ pub const Error = union(enum) {
try stream.write("invalid type specifier '");
try type_spec.spec.print(tree, stream);
const token_name = tree.tokens.at(self.token).id.symbol();
return stream.print("{}'", .{token_name});
return stream.print("{s}'", .{token_name});
}
};
@ -140,7 +140,7 @@ pub const Error = union(enum) {
name: TokenIndex,
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
return stream.print("must use '{}' tag to refer to type '{}'", .{ tree.slice(kw), tree.slice(name) });
return stream.print("must use '{s}' tag to refer to type '{s}'", .{ tree.slice(kw), tree.slice(name) });
}
};

View File

@ -38,7 +38,7 @@ pub const PreopenType = union(PreopenTypeTag) {
pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
try out_stream.print("PreopenType{{ ", .{});
switch (self) {
PreopenType.Dir => |path| try out_stream.print(".Dir = '{}'", .{path}),
PreopenType.Dir => |path| try out_stream.print(".Dir = '{z}'", .{path}),
}
return out_stream.print(" }}", .{});
}

View File

@ -4256,7 +4256,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
},
.linux => {
var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;
const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable;
const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{d}\x00", .{fd}) catch unreachable;
const target = readlinkZ(std.meta.assumeSentinel(proc_path.ptr, 0), out_buffer) catch |err| {
switch (err) {
@ -4487,7 +4487,7 @@ pub const UnexpectedError = error{
/// and you get an unexpected error.
pub fn unexpectedErrno(err: usize) UnexpectedError {
if (unexpected_error_tracing) {
std.debug.warn("unexpected errno: {}\n", .{err});
std.debug.warn("unexpected errno: {d}\n", .{err});
std.debug.dumpCurrentStackTrace(null);
}
return error.Unexpected;

View File

@ -172,7 +172,7 @@ test "strncmp" {
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
if (builtin.is_test) {
@setCold(true);
std.debug.panic("{}", .{msg});
std.debug.panic("{s}", .{msg});
}
if (builtin.os.tag != .freestanding and builtin.os.tag != .other) {
std.os.abort();

View File

@ -324,7 +324,7 @@ pub usingnamespace @import("compiler_rt/atomics.zig");
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
@setCold(true);
if (is_test) {
std.debug.panic("{}", .{msg});
std.debug.panic("{s}", .{msg});
} else {
unreachable;
}

View File

@ -258,7 +258,7 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
// If the child type is u8 and no weird bytes, we could print it as strings
// Even for the length difference, it would be useful to see the values of the slices probably.
if (expected.len != actual.len) {
std.debug.panic("slice lengths differ. expected {}, found {}", .{ expected.len, actual.len });
std.debug.panic("slice lengths differ. expected {d}, found {d}", .{ expected.len, actual.len });
}
var i: usize = 0;
while (i < expected.len) : (i += 1) {

View File

@ -3742,7 +3742,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
for (tree.errors) |*parse_error| {
const token = tree.token_locs[parse_error.loc()];
const loc = tree.tokenLocation(0, parse_error.loc());
try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 });
try stderr.print("(memory buffer):{d}:{d}: error: ", .{ loc.line + 1, loc.column + 1 });
try tree.renderError(parse_error, stderr);
try stderr.print("\n{s}\n", .{source[loc.line_start..loc.line_end]});
{
@ -3800,7 +3800,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
error.OutOfMemory => {
if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
warn(
"\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
"\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
.{
fail_index,
needed_alloc_count,

View File

@ -450,7 +450,7 @@ test "version_from_build" {
for (known) |pair| {
var buf: [32]u8 = undefined;
const ver = try version_from_build(pair[0]);
const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ ver.major, ver.minor, ver.patch });
const sver = try std.fmt.bufPrint(buf[0..], "{d}.{d}.{d}", .{ ver.major, ver.minor, ver.patch });
std.testing.expect(std.mem.eql(u8, sver, pair[1]));
}
}
@ -468,7 +468,7 @@ pub fn getSDKPath(allocator: *mem.Allocator) ![]u8 {
allocator.free(result.stdout);
}
if (result.stderr.len != 0) {
std.log.err("unexpected 'xcrun --show-sdk-path' stderr: {}", .{result.stderr});
std.log.err("unexpected 'xcrun --show-sdk-path' stderr: {s}", .{result.stderr});
}
if (result.term.Exited != 0) {
return error.ProcessTerminated;

View File

@ -1512,7 +1512,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(
module.gpa,
decl.src(),
"unable to generate C header: {}",
"unable to generate C header: {s}",
.{@errorName(err)},
));
decl.analysis = .codegen_failure_retryable;
@ -1593,7 +1593,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
.libtsan => {
libtsan.buildTsan(self) catch |err| {
// TODO Expose this as a normal compile error rather than crashing here.
fatal("unable to build TSAN library: {}", .{@errorName(err)});
fatal("unable to build TSAN library: {s}", .{@errorName(err)});
};
},
.compiler_rt_lib => {
@ -1983,7 +1983,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
// TODO parse clang stderr and turn it into an error message
// and then call failCObjWithOwnedErrorMsg
log.err("clang failed with stderr: {s}", .{stderr});
return comp.failCObj(c_object, "clang exited with code {}", .{code});
return comp.failCObj(c_object, "clang exited with code {d}", .{code});
}
},
else => {
@ -3013,7 +3013,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
id_symlink_basename,
&prev_digest_buf,
) catch |err| blk: {
log.debug("stage1 {} new_digest={} error: {s}", .{ mod.root_pkg.root_src_path, digest, @errorName(err) });
log.debug("stage1 {s} new_digest={} error: {s}", .{ mod.root_pkg.root_src_path, digest, @errorName(err) });
// Handle this as a cache miss.
break :blk prev_digest_buf[0..0];
};
@ -3021,7 +3021,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
if (!mem.eql(u8, prev_digest[0..digest.len], &digest))
break :hit;
log.debug("stage1 {} digest={} match - skipping invocation", .{ mod.root_pkg.root_src_path, digest });
log.debug("stage1 {s} digest={} match - skipping invocation", .{ mod.root_pkg.root_src_path, digest });
var flags_bytes: [1]u8 = undefined;
_ = std.fmt.hexToBytes(&flags_bytes, prev_digest[digest.len..]) catch {
log.warn("bad cache stage1 digest: '{s}'", .{prev_digest});
@ -3044,7 +3044,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
mod.stage1_flags = @bitCast(@TypeOf(mod.stage1_flags), flags_bytes[0]);
return;
}
log.debug("stage1 {} prev_digest={} new_digest={}", .{ mod.root_pkg.root_src_path, prev_digest, digest });
log.debug("stage1 {s} prev_digest={} new_digest={}", .{ mod.root_pkg.root_src_path, prev_digest, digest });
man.unhit(prev_hash_state, input_file_count);
}

View File

@ -373,7 +373,7 @@ pub const Token = union(enum) {
} else {
try printCharValues(writer, index_and_bytes.bytes);
}
try writer.print("' at position {}", .{index_and_bytes.index});
try writer.print("' at position {d}", .{index_and_bytes.index});
},
.invalid_target,
.bad_target_escape,
@ -383,7 +383,7 @@ pub const Token = union(enum) {
=> |index_and_char| {
try writer.writeAll("illegal char ");
try printUnderstandableChar(writer, index_and_char.char);
try writer.print(" at position {}: {s}", .{ index_and_char.index, self.errStr() });
try writer.print(" at position {d}: {s}", .{ index_and_char.index, self.errStr() });
},
}
}
@ -943,7 +943,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
var buf: [80]u8 = undefined;
var text = try std.fmt.bufPrint(buf[0..], "{s} {} bytes ", .{ label, bytes.len });
var text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });
try out.writeAll(text);
var i: usize = text.len;
const end = 79;

View File

@ -248,7 +248,7 @@ pub const Decl = struct {
pub fn dump(self: *Decl) void {
const loc = std.zig.findLineColumn(self.scope.source.bytes, self.src);
std.debug.print("{}:{}:{} name={} status={}", .{
std.debug.print("{s}:{d}:{d} name={s} status={s}", .{
self.scope.sub_file_path,
loc.line + 1,
loc.column + 1,
@ -308,7 +308,7 @@ pub const Fn = struct {
/// For debugging purposes.
pub fn dump(self: *Fn, mod: Module) void {
std.debug.print("Module.Function(name={}) ", .{self.owner_decl.name});
std.debug.print("Module.Function(name={s}) ", .{self.owner_decl.name});
switch (self.analysis) {
.queued => {
std.debug.print("queued\n", .{});
@ -632,7 +632,7 @@ pub const Scope = struct {
pub fn dumpSrc(self: *File, src: usize) void {
const loc = std.zig.findLineColumn(self.source.bytes, src);
std.debug.print("{}:{}:{}\n", .{ self.sub_file_path, loc.line + 1, loc.column + 1 });
std.debug.print("{s}:{d}:{d}\n", .{ self.sub_file_path, loc.line + 1, loc.column + 1 });
}
pub fn getSource(self: *File, module: *Module) ![:0]const u8 {
@ -730,7 +730,7 @@ pub const Scope = struct {
pub fn dumpSrc(self: *ZIRModule, src: usize) void {
const loc = std.zig.findLineColumn(self.source.bytes, src);
std.debug.print("{}:{}:{}\n", .{ self.sub_file_path, loc.line + 1, loc.column + 1 });
std.debug.print("{s}:{d}:{d}\n", .{ self.sub_file_path, loc.line + 1, loc.column + 1 });
}
pub fn getSource(self: *ZIRModule, module: *Module) ![:0]const u8 {
@ -1641,7 +1641,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void
}
} else if (src_decl.castTag(.Comptime)) |comptime_node| {
const name_index = self.getNextAnonNameIndex();
const name = try std.fmt.allocPrint(self.gpa, "__comptime_{}", .{name_index});
const name = try std.fmt.allocPrint(self.gpa, "__comptime_{d}", .{name_index});
defer self.gpa.free(name);
const name_hash = container_scope.fullyQualifiedNameHash(name);
@ -2277,7 +2277,7 @@ pub fn createAnonymousDecl(
) !*Decl {
const name_index = self.getNextAnonNameIndex();
const scope_decl = scope.decl().?;
const name = try std.fmt.allocPrint(self.gpa, "{s}__anon_{}", .{ scope_decl.name, name_index });
const name = try std.fmt.allocPrint(self.gpa, "{s}__anon_{d}", .{ scope_decl.name, name_index });
defer self.gpa.free(name);
const name_hash = scope.namespace().fullyQualifiedNameHash(name);
const src_hash: std.zig.SrcHash = undefined;
@ -2555,7 +2555,7 @@ pub fn cmpNumeric(
if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) {
if (lhs.ty.arrayLen() != rhs.ty.arrayLen()) {
return self.fail(scope, src, "vector length mismatch: {} and {}", .{
return self.fail(scope, src, "vector length mismatch: {d} and {d}", .{
lhs.ty.arrayLen(),
rhs.ty.arrayLen(),
});
@ -2700,7 +2700,7 @@ pub fn cmpNumeric(
const dest_type = if (dest_float_type) |ft| ft else blk: {
const max_bits = std.math.max(lhs_bits, rhs_bits);
const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) {
error.Overflow => return self.fail(scope, src, "{} exceeds maximum integer bit count", .{max_bits}),
error.Overflow => return self.fail(scope, src, "{d} exceeds maximum integer bit count", .{max_bits}),
};
break :blk try self.makeIntType(scope, dest_int_is_signed, casted_bits);
};
@ -3319,7 +3319,7 @@ pub fn dumpInst(self: *Module, scope: *Scope, inst: *Inst) void {
const source = zir_module.getSource(self) catch @panic("dumpInst failed to get source");
const loc = std.zig.findLineColumn(source, inst.src);
if (inst.tag == .constant) {
std.debug.print("constant ty={} val={} src={}:{}:{}\n", .{
std.debug.print("constant ty={} val={} src={s}:{d}:{d}\n", .{
inst.ty,
inst.castTag(.constant).?.val,
zir_module.subFilePath(),
@ -3327,7 +3327,7 @@ pub fn dumpInst(self: *Module, scope: *Scope, inst: *Inst) void {
loc.column + 1,
});
} else if (inst.deaths == 0) {
std.debug.print("{} ty={} src={}:{}:{}\n", .{
std.debug.print("{s} ty={} src={s}:{d}:{d}\n", .{
@tagName(inst.tag),
inst.ty,
zir_module.subFilePath(),
@ -3335,7 +3335,7 @@ pub fn dumpInst(self: *Module, scope: *Scope, inst: *Inst) void {
loc.column + 1,
});
} else {
std.debug.print("{} ty={} deaths={b} src={}:{}:{}\n", .{
std.debug.print("{s} ty={} deaths={b} src={s}:{d}:{d}\n", .{
@tagName(inst.tag),
inst.ty,
inst.deaths,

View File

@ -385,7 +385,7 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: *ast.Node.ControlFlowExpr
.local_ptr => scope = scope.cast(Scope.LocalPtr).?.parent,
else => if (node.getLabel()) |break_label| {
const label_name = try identifierTokenString(mod, parent_scope, break_label);
return mod.failTok(parent_scope, break_label, "label not found: '{}'", .{label_name});
return mod.failTok(parent_scope, break_label, "label not found: '{s}'", .{label_name});
} else {
return mod.failTok(parent_scope, src, "break expression outside loop", .{});
},
@ -427,7 +427,7 @@ fn continueExpr(mod: *Module, parent_scope: *Scope, node: *ast.Node.ControlFlowE
.local_ptr => scope = scope.cast(Scope.LocalPtr).?.parent,
else => if (node.getLabel()) |break_label| {
const label_name = try identifierTokenString(mod, parent_scope, break_label);
return mod.failTok(parent_scope, break_label, "label not found: '{}'", .{label_name});
return mod.failTok(parent_scope, break_label, "label not found: '{s}'", .{label_name});
} else {
return mod.failTok(parent_scope, src, "continue expression outside loop", .{});
},
@ -2204,7 +2204,7 @@ fn ensureBuiltinParamCount(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinC
return;
const s = if (count == 1) "" else "s";
return mod.failTok(scope, call.builtin_token, "expected {} parameter{s}, found {}", .{ count, s, call.params_len });
return mod.failTok(scope, call.builtin_token, "expected {d} parameter{s}, found {d}", .{ count, s, call.params_len });
}
fn simpleCast(

View File

@ -383,7 +383,7 @@ const Context = struct {
}
fn name(self: *Context) ![]u8 {
const val = try std.fmt.allocPrint(&self.arena.allocator, "__temp_{}", .{self.unnamed_index});
const val = try std.fmt.allocPrint(&self.arena.allocator, "__temp_{d}", .{self.unnamed_index});
self.unnamed_index += 1;
return val;
}
@ -420,7 +420,7 @@ fn genAlloc(ctx: *Context, file: *C, alloc: *Inst.NoOp) !?[]u8 {
}
fn genArg(ctx: *Context) !?[]u8 {
const name = try std.fmt.allocPrint(&ctx.arena.allocator, "arg{}", .{ctx.argdex});
const name = try std.fmt.allocPrint(&ctx.arena.allocator, "arg{d}", .{ctx.argdex});
ctx.argdex += 1;
return name;
}
@ -528,7 +528,7 @@ fn genCall(ctx: *Context, file: *C, inst: *Inst.Call) !?[]u8 {
try renderValue(ctx, writer, arg.ty, val);
} else {
const val = try ctx.resolveInst(arg);
try writer.print("{}", .{val});
try writer.print("{s}", .{val});
}
}
}

View File

@ -111,12 +111,12 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
while (it.next()) |line| : (line_i += 1) {
const prefix = "GLIBC_";
if (!mem.startsWith(u8, line, prefix)) {
std.log.err("vers.txt:{}: expected 'GLIBC_' prefix", .{line_i});
std.log.err("vers.txt:{d}: expected 'GLIBC_' prefix", .{line_i});
return error.ZigInstallationCorrupt;
}
const adjusted_line = line[prefix.len..];
const ver = std.builtin.Version.parse(adjusted_line) catch |err| {
std.log.err("vers.txt:{}: unable to parse glibc version '{s}': {s}", .{ line_i, line, @errorName(err) });
std.log.err("vers.txt:{d}: unable to parse glibc version '{s}': {s}", .{ line_i, line, @errorName(err) });
return error.ZigInstallationCorrupt;
};
try all_versions.append(arena, ver);
@ -128,15 +128,15 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
while (file_it.next()) |line| : (line_i += 1) {
var line_it = mem.tokenize(line, " ");
const fn_name = line_it.next() orelse {
std.log.err("fns.txt:{}: expected function name", .{line_i});
std.log.err("fns.txt:{d}: expected function name", .{line_i});
return error.ZigInstallationCorrupt;
};
const lib_name = line_it.next() orelse {
std.log.err("fns.txt:{}: expected library name", .{line_i});
std.log.err("fns.txt:{d}: expected library name", .{line_i});
return error.ZigInstallationCorrupt;
};
const lib = findLib(lib_name) orelse {
std.log.err("fns.txt:{}: unknown library name: {s}", .{ line_i, lib_name });
std.log.err("fns.txt:{d}: unknown library name: {s}", .{ line_i, lib_name });
return error.ZigInstallationCorrupt;
};
try all_functions.append(arena, .{
@ -158,27 +158,27 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
while (line_it.next()) |target_string| {
var component_it = mem.tokenize(target_string, "-");
const arch_name = component_it.next() orelse {
std.log.err("abi.txt:{}: expected arch name", .{line_i});
std.log.err("abi.txt:{d}: expected arch name", .{line_i});
return error.ZigInstallationCorrupt;
};
const os_name = component_it.next() orelse {
std.log.err("abi.txt:{}: expected OS name", .{line_i});
std.log.err("abi.txt:{d}: expected OS name", .{line_i});
return error.ZigInstallationCorrupt;
};
const abi_name = component_it.next() orelse {
std.log.err("abi.txt:{}: expected ABI name", .{line_i});
std.log.err("abi.txt:{d}: expected ABI name", .{line_i});
return error.ZigInstallationCorrupt;
};
const arch_tag = std.meta.stringToEnum(std.Target.Cpu.Arch, arch_name) orelse {
std.log.err("abi.txt:{}: unrecognized arch: '{s}'", .{ line_i, arch_name });
std.log.err("abi.txt:{d}: unrecognized arch: '{s}'", .{ line_i, arch_name });
return error.ZigInstallationCorrupt;
};
if (!mem.eql(u8, os_name, "linux")) {
std.log.err("abi.txt:{}: expected OS 'linux', found '{s}'", .{ line_i, os_name });
std.log.err("abi.txt:{d}: expected OS 'linux', found '{s}'", .{ line_i, os_name });
return error.ZigInstallationCorrupt;
}
const abi_tag = std.meta.stringToEnum(std.Target.Abi, abi_name) orelse {
std.log.err("abi.txt:{}: unrecognized ABI: '{s}'", .{ line_i, abi_name });
std.log.err("abi.txt:{d}: unrecognized ABI: '{s}'", .{ line_i, abi_name });
return error.ZigInstallationCorrupt;
};
@ -193,7 +193,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
};
for (ver_list_base) |*ver_list| {
const line = file_it.next() orelse {
std.log.err("abi.txt:{}: missing version number line", .{line_i});
std.log.err("abi.txt:{d}: missing version number line", .{line_i});
return error.ZigInstallationCorrupt;
};
line_i += 1;
@ -206,12 +206,12 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
while (line_it.next()) |version_index_string| {
if (ver_list.len >= ver_list.versions.len) {
// If this happens with legit data, increase the array len in the type.
std.log.err("abi.txt:{}: too many versions", .{line_i});
std.log.err("abi.txt:{d}: too many versions", .{line_i});
return error.ZigInstallationCorrupt;
}
const version_index = std.fmt.parseInt(u8, version_index_string, 10) catch |err| {
// If this happens with legit data, increase the size of the integer type in the struct.
std.log.err("abi.txt:{}: unable to parse version: {s}", .{ line_i, @errorName(err) });
std.log.err("abi.txt:{d}: unable to parse version: {s}", .{ line_i, @errorName(err) });
return error.ZigInstallationCorrupt;
};

View File

@ -523,7 +523,7 @@ pub const File = struct {
id_symlink_basename,
&prev_digest_buf,
) catch |err| b: {
log.debug("archive new_digest={} readFile error: {}", .{ digest, @errorName(err) });
log.debug("archive new_digest={} readFile error: {s}", .{ digest, @errorName(err) });
break :b prev_digest_buf[0..0];
};
if (mem.eql(u8, prev_digest, &digest)) {

View File

@ -2082,10 +2082,10 @@ pub fn allocateDeclIndexes(self: *Elf, decl: *Module.Decl) !void {
try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
if (self.local_symbol_free_list.popOrNull()) |i| {
log.debug("reusing symbol index {} for {s}\n", .{ i, decl.name });
log.debug("reusing symbol index {d} for {s}\n", .{ i, decl.name });
decl.link.elf.local_sym_index = i;
} else {
log.debug("allocating symbol index {} for {s}\n", .{ self.local_symbols.items.len, decl.name });
log.debug("allocating symbol index {d} for {s}\n", .{ self.local_symbols.items.len, decl.name });
decl.link.elf.local_sym_index = @intCast(u32, self.local_symbols.items.len);
_ = self.local_symbols.addOneAssumeCapacity();
}
@ -2432,7 +2432,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
if (needed_size > self.allocatedSize(debug_line_sect.sh_offset)) {
const new_offset = self.findFreeSpace(needed_size, 1);
const existing_size = last_src_fn.off;
log.debug("moving .debug_line section: {} bytes from 0x{x} to 0x{x}\n", .{
log.debug("moving .debug_line section: {d} bytes from 0x{x} to 0x{x}\n", .{
existing_size,
debug_line_sect.sh_offset,
new_offset,

View File

@ -1,6 +1,7 @@
const std = @import("std");
const ir = @import("ir.zig");
const trace = @import("tracy.zig").trace;
const log = std.log.scoped(.liveness);
/// Perform Liveness Analysis over the `Body`. Each `Inst` will have its `deaths` field populated.
pub fn analyze(
@ -248,5 +249,5 @@ fn analyzeInst(
@panic("Handle liveness analysis for instructions with many parameters");
}
std.log.scoped(.liveness).debug("analyze {}: 0b{b}\n", .{ base.tag, base.deaths });
log.debug("analyze {}: 0b{b}\n", .{ base.tag, base.deaths });
}

View File

@ -626,7 +626,7 @@ fn buildOutputType(
fs.path.dirname(pkg_path),
fs.path.basename(pkg_path),
) catch |err| {
fatal("Failed to add package at path {}: {}", .{ pkg_path, @errorName(err) });
fatal("Failed to add package at path {s}: {s}", .{ pkg_path, @errorName(err) });
};
new_cur_pkg.parent = cur_pkg;
try cur_pkg.add(gpa, pkg_name, new_cur_pkg);
@ -696,13 +696,13 @@ fn buildOutputType(
if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
i += 1;
stack_size_override = std.fmt.parseUnsigned(u64, args[i], 0) catch |err| {
fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });
fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
};
} else if (mem.eql(u8, arg, "--image-base")) {
if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
i += 1;
image_base_override = std.fmt.parseUnsigned(u64, args[i], 0) catch |err| {
fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });
fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
};
} else if (mem.eql(u8, arg, "--name")) {
if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
@ -1914,7 +1914,7 @@ fn buildOutputType(
if (!watch) return cleanExit();
} else {
const cmd = try argvCmd(arena, argv.items);
fatal("the following test command failed with exit code {}:\n{s}", .{ code, cmd });
fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });
}
},
else => {
@ -2069,7 +2069,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
error.ASTUnitFailure => fatal("clang API returned errors but due to a clang bug, it is not exposing the errors for zig to see. For more details: https://github.com/ziglang/zig/issues/4455", .{}),
error.SemanticAnalyzeFail => {
for (clang_errors) |clang_err| {
std.debug.print("{s}:{}:{}: {s}\n", .{
std.debug.print("{s}:{d}:{d}: {s}\n", .{
if (clang_err.filename_ptr) |p| p[0..clang_err.filename_len] else "(no file)",
clang_err.line + 1,
clang_err.column + 1,
@ -2493,7 +2493,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
.Exited => |code| {
if (code == 0) return cleanExit();
const cmd = try argvCmd(arena, child_argv);
fatal("the following build command failed with exit code {}:\n{s}", .{ code, cmd });
fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
},
else => {
const cmd = try argvCmd(arena, child_argv);
@ -2812,7 +2812,7 @@ fn printErrMsgToFile(
const text = text_buf.items;
const stream = file.outStream();
try stream.print("{s}:{}:{}: error: {s}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
try stream.print("{s}:{d}:{d}: error: {s}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
if (!color_on) return;

View File

@ -136,7 +136,7 @@ const Scope = struct {
var proposed_name = name_copy;
while (scope.contains(proposed_name)) {
scope.mangle_count += 1;
proposed_name = try std.fmt.allocPrint(c.arena, "{s}_{}", .{ name, scope.mangle_count });
proposed_name = try std.fmt.allocPrint(c.arena, "{s}_{d}", .{ name, scope.mangle_count });
}
try scope.variables.append(.{ .name = name_copy, .alias = proposed_name });
return proposed_name;
@ -440,7 +440,7 @@ pub fn translate(
mem.copy(*ast.Node, root_node.decls(), context.root_decls.items);
if (false) {
std.debug.warn("debug source:\n{}\n==EOF==\ntokens:\n", .{source_buffer.items});
std.debug.warn("debug source:\n{s}\n==EOF==\ntokens:\n", .{source_buffer.items});
for (context.token_ids.items) |token| {
std.debug.warn("{}\n", .{token});
}
@ -945,7 +945,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as
// Record declarations such as `struct {...} x` have no name but they're not
// anonymous hence here isAnonymousStructOrUnion is not needed
if (bare_name.len == 0) {
bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{c.getMangle()});
bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{c.getMangle()});
is_unnamed = true;
}
@ -1019,7 +1019,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as
var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());
if (field_decl.isAnonymousStructOrUnion() or raw_name.len == 0) {
// Context.getMangle() is not used here because doing so causes unpredictable field names for anonymous fields.
raw_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{unnamed_field_count});
raw_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{unnamed_field_count});
unnamed_field_count += 1;
is_anon = true;
}
@ -1110,7 +1110,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const clang.EnumDecl) Error!?*ast.Node
var bare_name = try c.str(@ptrCast(*const clang.NamedDecl, enum_decl).getName_bytes_begin());
var is_unnamed = false;
if (bare_name.len == 0) {
bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{c.getMangle()});
bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{c.getMangle()});
is_unnamed = true;
}
@ -3956,7 +3956,7 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: clang.QualType, source_loc: clang.
const node = try rp.c.arena.create(ast.Node.OneToken);
node.* = .{
.base = .{ .tag = .IntegerLiteral },
.token = try appendTokenFmt(rp.c, .Identifier, "u{}", .{cast_bit_width}),
.token = try appendTokenFmt(rp.c, .Identifier, "u{d}", .{cast_bit_width}),
};
return &node.base;
}
@ -4484,7 +4484,7 @@ fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: *ast.Node, proto_a
_ = try appendToken(c, .Comma, ",");
}
const param_name_tok = param.name_token orelse
try appendTokenFmt(c, .Identifier, "arg_{}", .{c.getMangle()});
try appendTokenFmt(c, .Identifier, "arg_{d}", .{c.getMangle()});
_ = try appendToken(c, .Colon, ":");
@ -5916,11 +5916,11 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*
// struct Foo will be declared as struct_Foo by transRecordDecl
const next_id = m.next().?;
if (next_id != .Identifier) {
try m.fail(c, "unable to translate C expr: expected Identifier instead got: {}", .{@tagName(next_id)});
try m.fail(c, "unable to translate C expr: expected Identifier instead got: {s}", .{@tagName(next_id)});
return error.ParseError;
}
const ident_token = try appendTokenFmt(c, .Identifier, "{}_{}", .{ slice, m.slice() });
const ident_token = try appendTokenFmt(c, .Identifier, "{s}_{s}", .{ slice, m.slice() });
const identifier = try c.arena.create(ast.Node.OneToken);
identifier.* = .{
.base = .{ .tag = .Identifier },

View File

@ -558,21 +558,21 @@ pub const Type = extern union {
},
.array_u8 => {
const len = ty.castTag(.array_u8).?.data;
return out_stream.print("[{}]u8", .{len});
return out_stream.print("[{d}]u8", .{len});
},
.array_u8_sentinel_0 => {
const len = ty.castTag(.array_u8_sentinel_0).?.data;
return out_stream.print("[{}:0]u8", .{len});
return out_stream.print("[{d}:0]u8", .{len});
},
.array => {
const payload = ty.castTag(.array).?.data;
try out_stream.print("[{}]", .{payload.len});
try out_stream.print("[{d}]", .{payload.len});
ty = payload.elem_type;
continue;
},
.array_sentinel => {
const payload = ty.castTag(.array_sentinel).?.data;
try out_stream.print("[{}:{}]", .{ payload.len, payload.sentinel });
try out_stream.print("[{d}:{}]", .{ payload.len, payload.sentinel });
ty = payload.elem_type;
continue;
},

View File

@ -1257,12 +1257,12 @@ const Writer = struct {
self.next_instr_index += 1;
try self.inst_table.putNoClobber(inst, .{ .inst = inst, .index = my_i, .name = undefined });
try stream.writeByteNTimes(' ', self.indent);
try stream.print("%{} ", .{my_i});
try stream.print("%{d} ", .{my_i});
if (inst.cast(Inst.Block)) |block| {
const name = try std.fmt.allocPrint(&self.arena.allocator, "label_{}", .{my_i});
const name = try std.fmt.allocPrint(&self.arena.allocator, "label_{d}", .{my_i});
try self.block_table.put(block, name);
} else if (inst.cast(Inst.Loop)) |loop| {
const name = try std.fmt.allocPrint(&self.arena.allocator, "loop_{}", .{my_i});
const name = try std.fmt.allocPrint(&self.arena.allocator, "loop_{d}", .{my_i});
try self.loop_table.put(loop, name);
}
self.indent += 2;
@ -1332,7 +1332,7 @@ const Writer = struct {
fn writeInstParamToStream(self: *Writer, stream: anytype, inst: *Inst) !void {
if (self.inst_table.get(inst)) |info| {
if (info.index) |i| {
try stream.print("%{}", .{info.index});
try stream.print("%{d}", .{info.index});
} else {
try stream.print("@{s}", .{info.name});
}
@ -1660,7 +1660,6 @@ const Parser = struct {
.contents_hash = std.zig.hashSrc(self.source[contents_start..self.i]),
.inst = &inst_specific.base,
};
//std.debug.warn("parsed {} = '{}'\n", .{ inst_specific.base.name, inst_specific.base.contents });
return decl;
}
@ -1805,7 +1804,7 @@ const Parser = struct {
}
fn generateName(self: *Parser) ![]u8 {
const result = try std.fmt.allocPrint(&self.arena.allocator, "unnamed${}", .{self.unnamed_index});
const result = try std.fmt.allocPrint(&self.arena.allocator, "unnamed${d}", .{self.unnamed_index});
self.unnamed_index += 1;
return result;
}
@ -2865,7 +2864,7 @@ const EmitZIR = struct {
fn autoName(self: *EmitZIR) ![]u8 {
while (true) {
const proposed_name = try std.fmt.allocPrint(&self.arena.allocator, "unnamed${}", .{self.next_auto_name});
const proposed_name = try std.fmt.allocPrint(&self.arena.allocator, "unnamed${d}", .{self.next_auto_name});
self.next_auto_name += 1;
const gop = try self.names.getOrPut(proposed_name);
if (!gop.found_existing) {
@ -2954,15 +2953,15 @@ pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8
write.next_instr_index += 1;
if (inst.cast(Inst.Block)) |block| {
const name = try std.fmt.allocPrint(&write.arena.allocator, "label_{}", .{my_i});
const name = try std.fmt.allocPrint(&write.arena.allocator, "label_{d}", .{my_i});
try write.block_table.put(block, name);
} else if (inst.cast(Inst.Loop)) |loop| {
const name = try std.fmt.allocPrint(&write.arena.allocator, "loop_{}", .{my_i});
const name = try std.fmt.allocPrint(&write.arena.allocator, "loop_{d}", .{my_i});
try write.loop_table.put(loop, name);
}
try write.inst_table.putNoClobber(inst, .{ .inst = inst, .index = my_i, .name = "inst" });
try stderr.print(" %{} ", .{my_i});
try stderr.print(" %{d} ", .{my_i});
try write.writeInstToStream(stderr, inst);
try stderr.writeByte('\n');
}

View File

@ -535,7 +535,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)
// TODO support C-style var args
const param_count = fn_ty.fnParamLen();
if (arg_index >= param_count) {
return mod.fail(scope, inst.base.src, "arg index {} out of bounds; '{}' has {} argument(s)", .{
return mod.fail(scope, inst.base.src, "arg index {d} out of bounds; '{}' has {d} argument(s)", .{
arg_index,
fn_ty,
param_count,
@ -580,7 +580,7 @@ fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*
const param_index = b.instructions.items.len;
const param_count = fn_ty.fnParamLen();
if (param_index >= param_count) {
return mod.fail(scope, inst.base.src, "parameter index {} outside list of length {}", .{
return mod.fail(scope, inst.base.src, "parameter index {d} outside list of length {d}", .{
param_index,
param_count,
});
@ -790,7 +790,7 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError
return mod.fail(
scope,
inst.positionals.func.src,
"expected at least {} argument(s), found {}",
"expected at least {d} argument(s), found {d}",
.{ fn_params_len, call_params_len },
);
}
@ -800,7 +800,7 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError
return mod.fail(
scope,
inst.positionals.func.src,
"expected {} argument(s), found {}",
"expected {d} argument(s), found {d}",
.{ fn_params_len, call_params_len },
);
}
@ -1545,7 +1545,7 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
if (lhs.ty.zigTypeTag() == .Vector and rhs.ty.zigTypeTag() == .Vector) {
if (lhs.ty.arrayLen() != rhs.ty.arrayLen()) {
return mod.fail(scope, inst.base.src, "vector length mismatch: {} and {}", .{
return mod.fail(scope, inst.base.src, "vector length mismatch: {d} and {d}", .{
lhs.ty.arrayLen(),
rhs.ty.arrayLen(),
});
@ -1620,7 +1620,7 @@ fn analyzeInstArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn
if (lhs.ty.zigTypeTag() == .Vector and rhs.ty.zigTypeTag() == .Vector) {
if (lhs.ty.arrayLen() != rhs.ty.arrayLen()) {
return mod.fail(scope, inst.base.src, "vector length mismatch: {} and {}", .{
return mod.fail(scope, inst.base.src, "vector length mismatch: {d} and {d}", .{
lhs.ty.arrayLen(),
rhs.ty.arrayLen(),
});
@ -1791,7 +1791,7 @@ fn analyzeInstCmp(
return mod.cmpNumeric(scope, inst.base.src, lhs, rhs, op);
} else if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
if (!is_equality_cmp) {
return mod.fail(scope, inst.base.src, "{} operator not allowed for types", .{@tagName(op)});
return mod.fail(scope, inst.base.src, "{s} operator not allowed for types", .{@tagName(op)});
}
return mod.constBool(scope, inst.base.src, lhs.value().?.eql(rhs.value().?) == (op == .eq));
}