Skip to content

Commit

Permalink
convert more {} to {d} and {s}
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jan 3, 2021
1 parent 5b981b1 commit 974c008
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 97 deletions.
2 changes: 1 addition & 1 deletion lib/std/SemanticVersion.zig
Expand Up @@ -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});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/std/c/ast.zig
Expand Up @@ -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 });
}
}
};
Expand All @@ -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});
}
};

Expand All @@ -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) });
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/std/fs/wasi.zig
Expand Up @@ -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(" }}", .{});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/std/os.zig
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/special/c.zig
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/std/special/compiler_rt.zig
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/testing.zig
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/std/zig/parser_test.zig
Expand Up @@ -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]});
{
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/std/zig/system/macos.zig
Expand Up @@ -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]));
}
}
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/Compilation.zig
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -3013,15 +3013,15 @@ 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];
};
if (prev_digest.len >= digest.len + 2) hit: {
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});
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/DepTokenizer.zig
Expand Up @@ -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,
Expand All @@ -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() });
},
}
}
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/Module.zig
Expand Up @@ -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,
Expand Down Expand Up @@ -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", .{});
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
});
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -3319,23 +3319,23 @@ 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(),
loc.line + 1,
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(),
loc.line + 1,
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,
Expand Down
6 changes: 3 additions & 3 deletions src/astgen.zig
Expand Up @@ -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", .{});
},
Expand Down Expand Up @@ -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", .{});
},
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/c.zig
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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});
}
}
}
Expand Down

0 comments on commit 974c008

Please sign in to comment.