authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 22:53:51-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 22:53:51-05:00
log8b2622cdd58cec697d9d1f8f49717b6ce7ee3e2e
tree3de817be4757dd1ad0bbdc0c7c3f863deb0f1d43
parent5874cb04bd544ca155d1489bb0bdf9397fa3b41c
signature Commit is signed but in an unrecognized format.

std.fmt.format: tuple parameter instead of var args


48 files changed, 643 insertions(+), 839 deletions(-)

build.zig+5-5
......@@ -154,7 +154,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
154154 const static_bare_name = if (mem.eql(u8, lib, "curses"))
155155 @as([]const u8, "libncurses.a")
156156 else
157 b.fmt("lib{}.a", lib);
157 b.fmt("lib{}.a", .{lib});
158158 const static_lib_name = fs.path.join(
159159 b.allocator,
160160 &[_][]const u8{ lib_dir, static_bare_name },
......@@ -186,7 +186,7 @@ fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_na
186186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
187187 cmake_binary_dir,
188188 "zig_cpp",
189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
189 b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
190190 }) catch unreachable);
191191}
192192
......@@ -343,14 +343,14 @@ fn addCxxKnownPath(
343343) !void {
344344 const path_padded = try b.exec(&[_][]const u8{
345345 ctx.cxx_compiler,
346 b.fmt("-print-file-name={}", objname),
346 b.fmt("-print-file-name={}", .{objname}),
347347 });
348348 const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;
349349 if (mem.eql(u8, path_unpadded, objname)) {
350350 if (errtxt) |msg| {
351 warn("{}", msg);
351 warn("{}", .{msg});
352352 } else {
353 warn("Unable to determine path to {}\n", objname);
353 warn("Unable to determine path to {}\n", .{objname});
354354 }
355355 return error.RequiredLibraryNotFound;
356356 }
lib/std/atomic/queue.zig+9-10
......@@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type {
116116 fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void {
117117 try s.writeByteNTimes(' ', indent);
118118 if (optional_node) |node| {
119 try s.print("0x{x}={}\n", @ptrToInt(node), node.data);
119 try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data });
120120 try dumpRecursive(s, node.next, indent + 1);
121121 } else {
122 try s.print("(null)\n");
122 try s.print("(null)\n", .{});
123123 }
124124 }
125125 };
126126 const held = self.mutex.acquire();
127127 defer held.release();
128128
129 try stream.print("head: ");
129 try stream.print("head: ", .{});
130130 try S.dumpRecursive(stream, self.head, 0);
131 try stream.print("tail: ");
131 try stream.print("tail: ", .{});
132132 try S.dumpRecursive(stream, self.tail, 0);
133133 }
134134 };
......@@ -207,16 +207,15 @@ test "std.atomic.Queue" {
207207 }
208208
209209 if (context.put_sum != context.get_sum) {
210 std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum);
210 std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum });
211211 }
212212
213213 if (context.get_count != puts_per_thread * put_thread_count) {
214 std.debug.panic(
215 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
214 std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{
216215 context.get_count,
217216 @as(u32, puts_per_thread),
218217 @as(u32, put_thread_count),
219 );
218 });
220219 }
221220}
222221
......@@ -351,7 +350,7 @@ test "std.atomic.Queue dump" {
351350 \\tail: 0x{x}=1
352351 \\ (null)
353352 \\
354 , @ptrToInt(queue.head), @ptrToInt(queue.tail));
353 , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
355354 expect(mem.eql(u8, buffer[0..sos.pos], expected));
356355
357356 // Test a stream with two elements
......@@ -372,6 +371,6 @@ test "std.atomic.Queue dump" {
372371 \\tail: 0x{x}=2
373372 \\ (null)
374373 \\
375 , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail));
374 , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
376375 expect(mem.eql(u8, buffer[0..sos.pos], expected));
377376}
lib/std/atomic/stack.zig+3-4
......@@ -134,16 +134,15 @@ test "std.atomic.stack" {
134134 }
135135
136136 if (context.put_sum != context.get_sum) {
137 std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum);
137 std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum });
138138 }
139139
140140 if (context.get_count != puts_per_thread * put_thread_count) {
141 std.debug.panic(
142 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
141 std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{
143142 context.get_count,
144143 @as(u32, puts_per_thread),
145144 @as(u32, put_thread_count),
146 );
145 });
147146 }
148147}
149148
lib/std/buffer.zig+4-4
......@@ -16,7 +16,7 @@ pub const Buffer = struct {
1616 mem.copy(u8, self.list.items, m);
1717 return self;
1818 }
19
19
2020 /// Initialize memory to size bytes of undefined values.
2121 /// Must deinitialize with deinit.
2222 pub fn initSize(allocator: *Allocator, size: usize) !Buffer {
......@@ -24,7 +24,7 @@ pub const Buffer = struct {
2424 try self.resize(size);
2525 return self;
2626 }
27
27
2828 /// Initialize with capacity to hold at least num bytes.
2929 /// Must deinitialize with deinit.
3030 pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer {
......@@ -64,7 +64,7 @@ pub const Buffer = struct {
6464 return result;
6565 }
6666
67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: ...) !Buffer {
67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {
6868 const countSize = struct {
6969 fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
7070 size.* += bytes.len;
......@@ -107,7 +107,7 @@ pub const Buffer = struct {
107107 pub fn len(self: Buffer) usize {
108108 return self.list.len - 1;
109109 }
110
110
111111 pub fn capacity(self: Buffer) usize {
112112 return if (self.list.items.len > 0)
113113 self.list.items.len - 1
lib/std/build.zig+104-82
......@@ -232,7 +232,7 @@ pub const Builder = struct {
232232 /// To run an executable built with zig build, see `LibExeObjStep.run`.
233233 pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep {
234234 assert(argv.len >= 1);
235 const run_step = RunStep.create(self, self.fmt("run {}", argv[0]));
235 const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]}));
236236 run_step.addArgs(argv);
237237 return run_step;
238238 }
......@@ -258,7 +258,7 @@ pub const Builder = struct {
258258 return write_file_step;
259259 }
260260
261 pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {
261 pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep {
262262 const data = self.fmt(format, args);
263263 const log_step = self.allocator.create(LogStep) catch unreachable;
264264 log_step.* = LogStep.init(self, data);
......@@ -330,7 +330,7 @@ pub const Builder = struct {
330330 for (self.installed_files.toSliceConst()) |installed_file| {
331331 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
332332 if (self.verbose) {
333 warn("rm {}\n", full_path);
333 warn("rm {}\n", .{full_path});
334334 }
335335 fs.deleteTree(full_path) catch {};
336336 }
......@@ -340,7 +340,7 @@ pub const Builder = struct {
340340
341341 fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
342342 if (s.loop_flag) {
343 warn("Dependency loop detected:\n {}\n", s.name);
343 warn("Dependency loop detected:\n {}\n", .{s.name});
344344 return error.DependencyLoopDetected;
345345 }
346346 s.loop_flag = true;
......@@ -348,7 +348,7 @@ pub const Builder = struct {
348348 for (s.dependencies.toSlice()) |dep| {
349349 self.makeOneStep(dep) catch |err| {
350350 if (err == error.DependencyLoopDetected) {
351 warn(" {}\n", s.name);
351 warn(" {}\n", .{s.name});
352352 }
353353 return err;
354354 };
......@@ -365,7 +365,7 @@ pub const Builder = struct {
365365 return &top_level_step.step;
366366 }
367367 }
368 warn("Cannot run step '{}' because it does not exist\n", name);
368 warn("Cannot run step '{}' because it does not exist\n", .{name});
369369 return error.InvalidStepName;
370370 }
371371
......@@ -378,12 +378,12 @@ pub const Builder = struct {
378378 const word = it.next() orelse break;
379379 if (mem.eql(u8, word, "-isystem")) {
380380 const include_path = it.next() orelse {
381 warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n");
381 warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n", .{});
382382 break;
383383 };
384384 self.addNativeSystemIncludeDir(include_path);
385385 } else {
386 warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", word);
386 warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", .{word});
387387 break;
388388 }
389389 }
......@@ -397,7 +397,7 @@ pub const Builder = struct {
397397 const word = it.next() orelse break;
398398 if (mem.eql(u8, word, "-rpath")) {
399399 const rpath = it.next() orelse {
400 warn("Expected argument after -rpath in NIX_LDFLAGS\n");
400 warn("Expected argument after -rpath in NIX_LDFLAGS\n", .{});
401401 break;
402402 };
403403 self.addNativeSystemRPath(rpath);
......@@ -405,7 +405,7 @@ pub const Builder = struct {
405405 const lib_path = word[2..];
406406 self.addNativeSystemLibPath(lib_path);
407407 } else {
408 warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", word);
408 warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", .{word});
409409 break;
410410 }
411411 }
......@@ -431,8 +431,8 @@ pub const Builder = struct {
431431 self.addNativeSystemIncludeDir("/usr/local/include");
432432 self.addNativeSystemLibPath("/usr/local/lib");
433433
434 self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", triple));
435 self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", triple));
434 self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", .{triple}));
435 self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", .{triple}));
436436
437437 self.addNativeSystemIncludeDir("/usr/include");
438438 self.addNativeSystemLibPath("/usr/lib");
......@@ -440,7 +440,7 @@ pub const Builder = struct {
440440 // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
441441 // zlib.h is in /usr/include (added above)
442442 // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
443 self.addNativeSystemLibPath(self.fmt("/lib/{}", triple));
443 self.addNativeSystemLibPath(self.fmt("/lib/{}", .{triple}));
444444 },
445445 }
446446 }
......@@ -453,7 +453,7 @@ pub const Builder = struct {
453453 .description = description,
454454 };
455455 if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
456 panic("Option '{}' declared twice", name);
456 panic("Option '{}' declared twice", .{name});
457457 }
458458 self.available_options_list.append(available_option) catch unreachable;
459459
......@@ -468,33 +468,33 @@ pub const Builder = struct {
468468 } else if (mem.eql(u8, s, "false")) {
469469 return false;
470470 } else {
471 warn("Expected -D{} to be a boolean, but received '{}'\n", name, s);
471 warn("Expected -D{} to be a boolean, but received '{}'\n", .{ name, s });
472472 self.markInvalidUserInput();
473473 return null;
474474 }
475475 },
476476 UserValue.List => {
477 warn("Expected -D{} to be a boolean, but received a list.\n", name);
477 warn("Expected -D{} to be a boolean, but received a list.\n", .{name});
478478 self.markInvalidUserInput();
479479 return null;
480480 },
481481 },
482 TypeId.Int => panic("TODO integer options to build script"),
483 TypeId.Float => panic("TODO float options to build script"),
482 TypeId.Int => panic("TODO integer options to build script", .{}),
483 TypeId.Float => panic("TODO float options to build script", .{}),
484484 TypeId.String => switch (entry.value.value) {
485485 UserValue.Flag => {
486 warn("Expected -D{} to be a string, but received a boolean.\n", name);
486 warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
487487 self.markInvalidUserInput();
488488 return null;
489489 },
490490 UserValue.List => {
491 warn("Expected -D{} to be a string, but received a list.\n", name);
491 warn("Expected -D{} to be a string, but received a list.\n", .{name});
492492 self.markInvalidUserInput();
493493 return null;
494494 },
495495 UserValue.Scalar => |s| return s,
496496 },
497 TypeId.List => panic("TODO list options to build script"),
497 TypeId.List => panic("TODO list options to build script", .{}),
498498 }
499499 }
500500
......@@ -513,7 +513,7 @@ pub const Builder = struct {
513513 if (self.release_mode != null) {
514514 @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");
515515 }
516 const description = self.fmt("create a release build ({})", @tagName(mode));
516 const description = self.fmt("create a release build ({})", .{@tagName(mode)});
517517 self.is_release = self.option(bool, "release", description) orelse false;
518518 self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;
519519 }
......@@ -536,7 +536,7 @@ pub const Builder = struct {
536536 else if (!release_fast and !release_safe and !release_small)
537537 builtin.Mode.Debug
538538 else x: {
539 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");
539 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)", .{});
540540 self.markInvalidUserInput();
541541 break :x builtin.Mode.Debug;
542542 };
......@@ -599,7 +599,7 @@ pub const Builder = struct {
599599 }) catch unreachable;
600600 },
601601 UserValue.Flag => {
602 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name);
602 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name });
603603 return true;
604604 },
605605 }
......@@ -620,11 +620,11 @@ pub const Builder = struct {
620620 // option already exists
621621 switch (gop.kv.value.value) {
622622 UserValue.Scalar => |s| {
623 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s);
623 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s });
624624 return true;
625625 },
626626 UserValue.List => {
627 warn("Flag '-D{}' conflicts with multiple options of the same name.\n", name);
627 warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name});
628628 return true;
629629 },
630630 UserValue.Flag => {},
......@@ -665,7 +665,7 @@ pub const Builder = struct {
665665 while (true) {
666666 const entry = it.next() orelse break;
667667 if (!entry.value.used) {
668 warn("Invalid option: -D{}\n\n", entry.key);
668 warn("Invalid option: -D{}\n\n", .{entry.key});
669669 self.markInvalidUserInput();
670670 }
671671 }
......@@ -678,11 +678,11 @@ pub const Builder = struct {
678678 }
679679
680680 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
681 if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd);
681 if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd});
682682 for (argv) |arg| {
683 warn("{} ", arg);
683 warn("{} ", .{arg});
684684 }
685 warn("\n");
685 warn("\n", .{});
686686 }
687687
688688 fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {
......@@ -697,20 +697,20 @@ pub const Builder = struct {
697697 child.env_map = env_map;
698698
699699 const term = child.spawnAndWait() catch |err| {
700 warn("Unable to spawn {}: {}\n", argv[0], @errorName(err));
700 warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
701701 return err;
702702 };
703703
704704 switch (term) {
705705 .Exited => |code| {
706706 if (code != 0) {
707 warn("The following command exited with error code {}:\n", code);
707 warn("The following command exited with error code {}:\n", .{code});
708708 printCmd(cwd, argv);
709709 return error.UncleanExit;
710710 }
711711 },
712712 else => {
713 warn("The following command terminated unexpectedly:\n");
713 warn("The following command terminated unexpectedly:\n", .{});
714714 printCmd(cwd, argv);
715715
716716 return error.UncleanExit;
......@@ -720,7 +720,7 @@ pub const Builder = struct {
720720
721721 pub fn makePath(self: *Builder, path: []const u8) !void {
722722 fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
723 warn("Unable to create path {}: {}\n", path, @errorName(err));
723 warn("Unable to create path {}: {}\n", .{ path, @errorName(err) });
724724 return err;
725725 };
726726 }
......@@ -793,12 +793,12 @@ pub const Builder = struct {
793793
794794 fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
795795 if (self.verbose) {
796 warn("cp {} {} ", source_path, dest_path);
796 warn("cp {} {} ", .{ source_path, dest_path });
797797 }
798798 const prev_status = try fs.updateFile(source_path, dest_path);
799799 if (self.verbose) switch (prev_status) {
800 .stale => warn("# installed\n"),
801 .fresh => warn("# up-to-date\n"),
800 .stale => warn("# installed\n", .{}),
801 .fresh => warn("# up-to-date\n", .{}),
802802 };
803803 }
804804
......@@ -806,7 +806,7 @@ pub const Builder = struct {
806806 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
807807 }
808808
809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
809 pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 {
810810 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
811811 }
812812
......@@ -818,7 +818,11 @@ pub const Builder = struct {
818818 if (fs.path.isAbsolute(name)) {
819819 return name;
820820 }
821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
822 search_prefix,
823 "bin",
824 self.fmt("{}{}", .{ name, exe_extension }),
825 });
822826 return fs.realpathAlloc(self.allocator, full_path) catch continue;
823827 }
824828 }
......@@ -829,7 +833,10 @@ pub const Builder = struct {
829833 }
830834 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
831835 while (it.next()) |path| {
832 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
836 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
837 path,
838 self.fmt("{}{}", .{ name, exe_extension }),
839 });
833840 return fs.realpathAlloc(self.allocator, full_path) catch continue;
834841 }
835842 }
......@@ -839,7 +846,10 @@ pub const Builder = struct {
839846 return name;
840847 }
841848 for (paths) |path| {
842 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
849 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
850 path,
851 self.fmt("{}{}", .{ name, exe_extension }),
852 });
843853 return fs.realpathAlloc(self.allocator, full_path) catch continue;
844854 }
845855 }
......@@ -896,17 +906,17 @@ pub const Builder = struct {
896906 var code: u8 = undefined;
897907 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
898908 error.FileNotFound => {
899 warn("Unable to spawn the following command: file not found\n");
909 warn("Unable to spawn the following command: file not found\n", .{});
900910 printCmd(null, argv);
901911 std.os.exit(@truncate(u8, code));
902912 },
903913 error.ExitCodeFailure => {
904 warn("The following command exited with error code {}:\n", code);
914 warn("The following command exited with error code {}:\n", .{code});
905915 printCmd(null, argv);
906916 std.os.exit(@truncate(u8, code));
907917 },
908918 error.ProcessTerminated => {
909 warn("The following command terminated unexpectedly:\n");
919 warn("The following command terminated unexpectedly:\n", .{});
910920 printCmd(null, argv);
911921 std.os.exit(@truncate(u8, code));
912922 },
......@@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct {
11331143
11341144 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep {
11351145 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
1136 panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name);
1146 panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
11371147 }
11381148 var self = LibExeObjStep{
11391149 .strip = false,
......@@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct {
11501160 .step = Step.init(name, builder.allocator, make),
11511161 .version = ver,
11521162 .out_filename = undefined,
1153 .out_h_filename = builder.fmt("{}.h", name),
1163 .out_h_filename = builder.fmt("{}.h", .{name}),
11541164 .out_lib_filename = undefined,
1155 .out_pdb_filename = builder.fmt("{}.pdb", name),
1165 .out_pdb_filename = builder.fmt("{}.pdb", .{name}),
11561166 .major_only_filename = undefined,
11571167 .name_only_filename = undefined,
11581168 .packages = ArrayList(Pkg).init(builder.allocator),
......@@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct {
11861196 fn computeOutFileNames(self: *LibExeObjStep) void {
11871197 switch (self.kind) {
11881198 .Obj => {
1189 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
1199 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });
11901200 },
11911201 .Exe => {
1192 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
1202 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.exeFileExt() });
11931203 },
11941204 .Test => {
1195 self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());
1205 self.out_filename = self.builder.fmt("test{}", .{self.target.exeFileExt()});
11961206 },
11971207 .Lib => {
11981208 if (!self.is_dynamic) {
1199 self.out_filename = self.builder.fmt(
1200 "{}{}{}",
1209 self.out_filename = self.builder.fmt("{}{}{}", .{
12011210 self.target.libPrefix(),
12021211 self.name,
12031212 self.target.staticLibSuffix(),
1204 );
1213 });
12051214 self.out_lib_filename = self.out_filename;
12061215 } else {
12071216 if (self.target.isDarwin()) {
1208 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);
1209 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);
1210 self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);
1217 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{
1218 self.name,
1219 self.version.major,
1220 self.version.minor,
1221 self.version.patch,
1222 });
1223 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{
1224 self.name,
1225 self.version.major,
1226 });
1227 self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name});
12111228 self.out_lib_filename = self.out_filename;
12121229 } else if (self.target.isWindows()) {
1213 self.out_filename = self.builder.fmt("{}.dll", self.name);
1214 self.out_lib_filename = self.builder.fmt("{}.lib", self.name);
1230 self.out_filename = self.builder.fmt("{}.dll", .{self.name});
1231 self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name});
12151232 } else {
1216 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch);
1217 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major);
1218 self.name_only_filename = self.builder.fmt("lib{}.so", self.name);
1233 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{
1234 self.name,
1235 self.version.major,
1236 self.version.minor,
1237 self.version.patch,
1238 });
1239 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major });
1240 self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name});
12191241 self.out_lib_filename = self.out_filename;
12201242 }
12211243 }
......@@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct {
12681290 // It doesn't have to be native. We catch that if you actually try to run it.
12691291 // Consider that this is declarative; the run step may not be run unless a user
12701292 // option is supplied.
1271 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name));
1293 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name}));
12721294 run_step.addArtifactArg(exe);
12731295
12741296 if (exe.vcpkg_bin_path) |path| {
......@@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct {
14201442 } else if (mem.eql(u8, tok, "-pthread")) {
14211443 self.linkLibC();
14221444 } else if (self.builder.verbose) {
1423 warn("Ignoring pkg-config flag '{}'\n", tok);
1445 warn("Ignoring pkg-config flag '{}'\n", .{tok});
14241446 }
14251447 }
14261448 }
......@@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct {
16531675 const builder = self.builder;
16541676
16551677 if (self.root_src == null and self.link_objects.len == 0) {
1656 warn("{}: linker needs 1 or more objects to link\n", self.step.name);
1678 warn("{}: linker needs 1 or more objects to link\n", .{self.step.name});
16571679 return error.NeedAnObject;
16581680 }
16591681
......@@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct {
17251747 if (self.build_options_contents.len() > 0) {
17261748 const build_options_file = try fs.path.join(
17271749 builder.allocator,
1728 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
1750 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
17291751 );
17301752 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
17311753 try zig_args.append("--pkg-begin");
......@@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct {
17801802
17811803 if (self.kind == Kind.Lib and self.is_dynamic) {
17821804 zig_args.append("--ver-major") catch unreachable;
1783 zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable;
1805 zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable;
17841806
17851807 zig_args.append("--ver-minor") catch unreachable;
1786 zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable;
1808 zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable;
17871809
17881810 zig_args.append("--ver-patch") catch unreachable;
1789 zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
1811 zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable;
17901812 }
17911813 if (self.is_dynamic) {
17921814 try zig_args.append("-dynamic");
......@@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct {
18111833
18121834 if (self.target_glibc) |ver| {
18131835 try zig_args.append("-target-glibc");
1814 try zig_args.append(builder.fmt("{}.{}.{}", ver.major, ver.minor, ver.patch));
1836 try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch }));
18151837 }
18161838
18171839 if (self.linker_script) |linker_script| {
......@@ -2079,7 +2101,7 @@ pub const RunStep = struct {
20792101 }
20802102
20812103 if (prev_path) |pp| {
2082 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", pp, search_path);
2104 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", .{ pp, search_path });
20832105 env_map.set(key, new_path) catch unreachable;
20842106 } else {
20852107 env_map.set(key, search_path) catch unreachable;
......@@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct {
21532175 const self = builder.allocator.create(Self) catch unreachable;
21542176 self.* = Self{
21552177 .builder = builder,
2156 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
2178 .step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
21572179 .artifact = artifact,
21582180 .dest_dir = switch (artifact.kind) {
21592181 .Obj => unreachable,
......@@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct {
22192241 builder.pushInstalledFile(dir, dest_rel_path);
22202242 return InstallFileStep{
22212243 .builder = builder,
2222 .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),
2244 .step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make),
22232245 .src_path = src_path,
22242246 .dir = dir,
22252247 .dest_rel_path = dest_rel_path,
......@@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct {
22532275 builder.pushInstalledFile(options.install_dir, options.install_subdir);
22542276 return InstallDirStep{
22552277 .builder = builder,
2256 .step = Step.init(builder.fmt("install {}/", options.source_dir), builder.allocator, make),
2278 .step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
22572279 .options = options,
22582280 };
22592281 }
......@@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct {
22902312 pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep {
22912313 return WriteFileStep{
22922314 .builder = builder,
2293 .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),
2315 .step = Step.init(builder.fmt("writefile {}", .{file_path}), builder.allocator, make),
22942316 .file_path = file_path,
22952317 .data = data,
22962318 };
......@@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct {
23012323 const full_path = self.builder.pathFromRoot(self.file_path);
23022324 const full_path_dir = fs.path.dirname(full_path) orelse ".";
23032325 fs.makePath(self.builder.allocator, full_path_dir) catch |err| {
2304 warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));
2326 warn("unable to make path {}: {}\n", .{ full_path_dir, @errorName(err) });
23052327 return err;
23062328 };
23072329 io.writeFile(full_path, self.data) catch |err| {
2308 warn("unable to write {}: {}\n", full_path, @errorName(err));
2330 warn("unable to write {}: {}\n", .{ full_path, @errorName(err) });
23092331 return err;
23102332 };
23112333 }
......@@ -2319,14 +2341,14 @@ pub const LogStep = struct {
23192341 pub fn init(builder: *Builder, data: []const u8) LogStep {
23202342 return LogStep{
23212343 .builder = builder,
2322 .step = Step.init(builder.fmt("log {}", data), builder.allocator, make),
2344 .step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make),
23232345 .data = data,
23242346 };
23252347 }
23262348
23272349 fn make(step: *Step) anyerror!void {
23282350 const self = @fieldParentPtr(LogStep, "step", step);
2329 warn("{}", self.data);
2351 warn("{}", .{self.data});
23302352 }
23312353};
23322354
......@@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct {
23382360 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
23392361 return RemoveDirStep{
23402362 .builder = builder,
2341 .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),
2363 .step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
23422364 .dir_path = dir_path,
23432365 };
23442366 }
......@@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct {
23482370
23492371 const full_path = self.builder.pathFromRoot(self.dir_path);
23502372 fs.deleteTree(full_path) catch |err| {
2351 warn("Unable to remove {}: {}\n", full_path, @errorName(err));
2373 warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) });
23522374 return err;
23532375 };
23542376 }
......@@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
23972419 &[_][]const u8{ out_dir, filename_major_only },
23982420 ) catch unreachable;
23992421 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
2400 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
2422 warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename });
24012423 return err;
24022424 };
24032425 // sym link for libfoo.so to libfoo.so.1
......@@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
24062428 &[_][]const u8{ out_dir, filename_name_only },
24072429 ) catch unreachable;
24082430 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2409 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
2431 warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only });
24102432 return err;
24112433 };
24122434}
lib/std/builtin.zig+2-2
......@@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
429429 }
430430 },
431431 .wasi => {
432 std.debug.warn("{}", msg);
432 std.debug.warn("{}", .{msg});
433433 _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT);
434434 unreachable;
435435 },
......@@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
439439 },
440440 else => {
441441 const first_trace_addr = @returnAddress();
442 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);
442 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", .{msg});
443443 },
444444 }
445445}
lib/std/crypto/benchmark.zig+1-1
......@@ -114,7 +114,7 @@ fn usage() void {
114114 \\ --seed [int]
115115 \\ --help
116116 \\
117 );
117 , .{});
118118}
119119
120120fn mode(comptime x: comptime_int) comptime_int {
lib/std/debug.zig+52-39
......@@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined;
4646var stderr_stream: ?*io.OutStream(File.WriteError) = null;
4747var stderr_mutex = std.Mutex.init();
4848
49pub fn warn(comptime fmt: []const u8, args: ...) void {
49pub fn warn(comptime fmt: []const u8, args: var) void {
5050 const held = stderr_mutex.acquire();
5151 defer held.release();
5252 const stderr = getStderrStream();
......@@ -92,15 +92,15 @@ fn wantTtyColor() bool {
9292pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
9393 const stderr = getStderrStream();
9494 if (builtin.strip_debug_info) {
95 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
95 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
9696 return;
9797 }
9898 const debug_info = getSelfDebugInfo() catch |err| {
99 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
99 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
100100 return;
101101 };
102102 writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| {
103 stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;
103 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
104104 return;
105105 };
106106}
......@@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
111111pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
112112 const stderr = getStderrStream();
113113 if (builtin.strip_debug_info) {
114 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
114 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
115115 return;
116116 }
117117 const debug_info = getSelfDebugInfo() catch |err| {
118 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
118 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
119119 return;
120120 };
121121 const tty_color = wantTtyColor();
......@@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
184184pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
185185 const stderr = getStderrStream();
186186 if (builtin.strip_debug_info) {
187 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
187 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
188188 return;
189189 }
190190 const debug_info = getSelfDebugInfo() catch |err| {
191 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
191 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
192192 return;
193193 };
194194 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| {
195 stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;
195 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
196196 return;
197197 };
198198}
......@@ -211,7 +211,7 @@ pub fn assert(ok: bool) void {
211211 if (!ok) unreachable; // assertion failure
212212}
213213
214pub fn panic(comptime format: []const u8, args: ...) noreturn {
214pub fn panic(comptime format: []const u8, args: var) noreturn {
215215 @setCold(true);
216216 // TODO: remove conditional once wasi / LLVM defines __builtin_return_address
217217 const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress();
......@@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn {
221221/// TODO multithreaded awareness
222222var panicking: u8 = 0; // TODO make this a bool
223223
224pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn {
224pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
225225 @setCold(true);
226226
227227 if (enable_segfault_handler) {
......@@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
376376 } else {
377377 // we have no information to add to the address
378378 if (tty_color) {
379 try out_stream.print("???:?:?: ");
379 try out_stream.print("???:?:?: ", .{});
380380 setTtyColor(TtyColor.Dim);
381 try out_stream.print("0x{x} in ??? (???)", relocated_address);
381 try out_stream.print("0x{x} in ??? (???)", .{relocated_address});
382382 setTtyColor(TtyColor.Reset);
383 try out_stream.print("\n\n\n");
383 try out_stream.print("\n\n\n", .{});
384384 } else {
385 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", relocated_address);
385 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address});
386386 }
387387 return;
388388 };
......@@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
509509 if (tty_color) {
510510 setTtyColor(TtyColor.White);
511511 if (opt_line_info) |li| {
512 try out_stream.print("{}:{}:{}", li.file_name, li.line, li.column);
512 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
513513 } else {
514 try out_stream.print("???:?:?");
514 try out_stream.print("???:?:?", .{});
515515 }
516516 setTtyColor(TtyColor.Reset);
517 try out_stream.print(": ");
517 try out_stream.print(": ", .{});
518518 setTtyColor(TtyColor.Dim);
519 try out_stream.print("0x{x} in {} ({})", relocated_address, symbol_name, obj_basename);
519 try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename });
520520 setTtyColor(TtyColor.Reset);
521521
522522 if (opt_line_info) |line_info| {
523 try out_stream.print("\n");
523 try out_stream.print("\n", .{});
524524 if (printLineFromFileAnyOs(out_stream, line_info)) {
525525 if (line_info.column == 0) {
526526 try out_stream.write("\n");
......@@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
546546 else => return err,
547547 }
548548 } else {
549 try out_stream.print("\n\n\n");
549 try out_stream.print("\n\n\n", .{});
550550 }
551551 } else {
552552 if (opt_line_info) |li| {
553 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", li.file_name, li.line, li.column, relocated_address, symbol_name, obj_basename);
553 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{
554 li.file_name,
555 li.line,
556 li.column,
557 relocated_address,
558 symbol_name,
559 obj_basename,
560 });
554561 } else {
555 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", relocated_address, symbol_name, obj_basename);
562 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{
563 relocated_address,
564 symbol_name,
565 obj_basename,
566 });
556567 }
557568 }
558569}
......@@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
697708
698709 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
699710 if (tty_color) {
700 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address);
711 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
701712 } else {
702 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address);
713 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
703714 }
704715 return;
705716 };
......@@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
723734 } else |err| switch (err) {
724735 error.MissingDebugInfo, error.InvalidDebugInfo => {
725736 if (tty_color) {
726 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", address, symbol_name, compile_unit_name);
737 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{
738 address, symbol_name, compile_unit_name,
739 });
727740 } else {
728 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", address, symbol_name, compile_unit_name);
741 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name });
729742 }
730743 },
731744 else => return err,
......@@ -746,15 +759,14 @@ fn printLineInfo(
746759 comptime printLineFromFile: var,
747760) !void {
748761 if (tty_color) {
749 try out_stream.print(
750 WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n",
762 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{
751763 line_info.file_name,
752764 line_info.line,
753765 line_info.column,
754766 address,
755767 symbol_name,
756768 compile_unit_name,
757 );
769 });
758770 if (printLineFromFile(out_stream, line_info)) {
759771 if (line_info.column == 0) {
760772 try out_stream.write("\n");
......@@ -772,15 +784,14 @@ fn printLineInfo(
772784 else => return err,
773785 }
774786 } else {
775 try out_stream.print(
776 "{}:{}:{}: 0x{x} in {} ({})\n",
787 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{
777788 line_info.file_name,
778789 line_info.line,
779790 line_info.column,
780791 address,
781792 symbol_name,
782793 compile_unit_name,
783 );
794 });
784795 }
785796}
786797
......@@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct {
12261237 ) !void {
12271238 const compile_unit = self.findCompileUnit(address) catch {
12281239 if (tty_color) {
1229 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address);
1240 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
12301241 } else {
1231 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address);
1242 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
12321243 }
12331244 return;
12341245 };
......@@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct {
12481259 } else |err| switch (err) {
12491260 error.MissingDebugInfo, error.InvalidDebugInfo => {
12501261 if (tty_color) {
1251 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", address, compile_unit_name);
1262 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{
1263 address, compile_unit_name,
1264 });
12521265 } else {
1253 try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", address, compile_unit_name);
1266 try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name });
12541267 }
12551268 },
12561269 else => return err,
......@@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con
24162429 resetSegfaultHandler();
24172430
24182431 const addr = @ptrToInt(info.fields.sigfault.addr);
2419 std.debug.warn("Segmentation fault at address 0x{x}\n", addr);
2432 std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr});
24202433
24212434 switch (builtin.arch) {
24222435 .i386 => {
......@@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
24682481 const sp = asm (""
24692482 : [argc] "={rsp}" (-> usize)
24702483 );
2471 std.debug.warn("{} sp = 0x{x}\n", prefix, sp);
2484 std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp });
24722485}
24732486
24742487// Reference everything so it gets tested.
lib/std/event/channel.zig+2-2
......@@ -294,14 +294,14 @@ test "std.event.Channel wraparound" {
294294
295295 const channel_size = 2;
296296
297 var buf : [channel_size]i32 = undefined;
297 var buf: [channel_size]i32 = undefined;
298298 var channel: Channel(i32) = undefined;
299299 channel.init(&buf);
300300 defer channel.deinit();
301301
302302 // add items to channel and pull them out until
303303 // the buffer wraps around, make sure it doesn't crash.
304 var result : i32 = undefined;
304 var result: i32 = undefined;
305305 channel.put(5);
306306 testing.expectEqual(@as(i32, 5), channel.get());
307307 channel.put(6);
lib/std/fifo.zig+2-2
......@@ -293,7 +293,7 @@ pub fn LinearFifo(
293293
294294 pub usingnamespace if (T == u8)
295295 struct {
296 pub fn print(self: *Self, comptime format: []const u8, args: ...) !void {
296 pub fn print(self: *Self, comptime format: []const u8, args: var) !void {
297297 return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args);
298298 }
299299 }
......@@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" {
407407 fifo.shrink(0);
408408
409409 {
410 try fifo.print("{}, {}!", "Hello", "World");
410 try fifo.print("{}, {}!", .{ "Hello", "World" });
411411 var result: [30]u8 = undefined;
412412 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
413413 testing.expectEqual(@as(usize, 0), fifo.readableLength());
lib/std/fmt.zig+111-109
......@@ -91,10 +91,12 @@ pub fn format(
9191 comptime Errors: type,
9292 output: fn (@typeOf(context), []const u8) Errors!void,
9393 comptime fmt: []const u8,
94 args: ...,
94 args: var,
9595) Errors!void {
9696 const ArgSetType = @IntType(false, 32);
97 if (args.len > ArgSetType.bit_count) {
97 const args_fields = std.meta.fields(@typeOf(args));
98 const args_len = args_fields.len;
99 if (args_len > ArgSetType.bit_count) {
98100 @compileError("32 arguments max are supported per format call");
99101 }
100102
......@@ -158,14 +160,14 @@ pub fn format(
158160 maybe_pos_arg.? += c - '0';
159161 specifier_start = i + 1;
160162
161 if (maybe_pos_arg.? >= args.len) {
163 if (maybe_pos_arg.? >= args_len) {
162164 @compileError("Positional value refers to non-existent argument");
163165 }
164166 },
165167 '}' => {
166168 const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);
167169
168 if (arg_to_print >= args.len) {
170 if (arg_to_print >= args_len) {
169171 @compileError("Too few arguments");
170172 }
171173
......@@ -302,7 +304,7 @@ pub fn format(
302304 used_pos_args |= 1 << i;
303305 }
304306
305 if (@popCount(ArgSetType, used_pos_args) != args.len) {
307 if (@popCount(ArgSetType, used_pos_args) != args_len) {
306308 @compileError("Unused arguments");
307309 }
308310 if (state != State.Start) {
......@@ -389,7 +391,7 @@ pub fn formatType(
389391 }
390392 try output(context, " }");
391393 } else {
392 try format(context, Errors, output, "@{x}", @ptrToInt(&value));
394 try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});
393395 }
394396 },
395397 .Struct => {
......@@ -421,12 +423,12 @@ pub fn formatType(
421423 if (info.child == u8) {
422424 return formatText(value, fmt, options, context, Errors, output);
423425 }
424 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
426 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
425427 },
426428 builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {
427429 return formatType(value.*, fmt, options, context, Errors, output, max_depth);
428430 },
429 else => return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)),
431 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
430432 },
431433 .Many => {
432434 if (ptr_info.child == u8) {
......@@ -435,7 +437,7 @@ pub fn formatType(
435437 return formatText(value[0..len], fmt, options, context, Errors, output);
436438 }
437439 }
438 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
440 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
439441 },
440442 .Slice => {
441443 if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) {
......@@ -444,10 +446,10 @@ pub fn formatType(
444446 if (ptr_info.child == u8) {
445447 return formatText(value, fmt, options, context, Errors, output);
446448 }
447 return format(context, Errors, output, "{}@{x}", @typeName(ptr_info.child), @ptrToInt(value.ptr));
449 return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });
448450 },
449451 .C => {
450 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
452 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
451453 },
452454 },
453455 .Array => |info| {
......@@ -465,7 +467,7 @@ pub fn formatType(
465467 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
466468 },
467469 .Fn => {
468 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
470 return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
469471 },
470472 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
471473 }
......@@ -1113,7 +1115,7 @@ pub const BufPrintError = error{
11131115 /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.
11141116 BufferTooSmall,
11151117};
1116pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]u8 {
1118pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 {
11171119 var context = BufPrintContext{ .remaining = buf };
11181120 try format(&context, BufPrintError, bufPrintWrite, fmt, args);
11191121 return buf[0 .. buf.len - context.remaining.len];
......@@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]
11211123
11221124pub const AllocPrintError = error{OutOfMemory};
11231125
1124pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) AllocPrintError![]u8 {
1126pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 {
11251127 var size: usize = 0;
11261128 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
11271129 const buf = try allocator.alloc(u8, size);
......@@ -1173,46 +1175,46 @@ test "parse unsigned comptime" {
11731175test "optional" {
11741176 {
11751177 const value: ?i32 = 1234;
1176 try testFmt("optional: 1234\n", "optional: {}\n", value);
1178 try testFmt("optional: 1234\n", "optional: {}\n", .{value});
11771179 }
11781180 {
11791181 const value: ?i32 = null;
1180 try testFmt("optional: null\n", "optional: {}\n", value);
1182 try testFmt("optional: null\n", "optional: {}\n", .{value});
11811183 }
11821184}
11831185
11841186test "error" {
11851187 {
11861188 const value: anyerror!i32 = 1234;
1187 try testFmt("error union: 1234\n", "error union: {}\n", value);
1189 try testFmt("error union: 1234\n", "error union: {}\n", .{value});
11881190 }
11891191 {
11901192 const value: anyerror!i32 = error.InvalidChar;
1191 try testFmt("error union: error.InvalidChar\n", "error union: {}\n", value);
1193 try testFmt("error union: error.InvalidChar\n", "error union: {}\n", .{value});
11921194 }
11931195}
11941196
11951197test "int.small" {
11961198 {
11971199 const value: u3 = 0b101;
1198 try testFmt("u3: 5\n", "u3: {}\n", value);
1200 try testFmt("u3: 5\n", "u3: {}\n", .{value});
11991201 }
12001202}
12011203
12021204test "int.specifier" {
12031205 {
12041206 const value: u8 = 'a';
1205 try testFmt("u8: a\n", "u8: {c}\n", value);
1207 try testFmt("u8: a\n", "u8: {c}\n", .{value});
12061208 }
12071209 {
12081210 const value: u8 = 0b1100;
1209 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", value);
1211 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value});
12101212 }
12111213}
12121214
12131215test "int.padded" {
1214 try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));
1215 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));
1216 try testFmt("u8: ' 1'", "u8: '{:4}'", .{@as(u8, 1)});
1217 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", .{@as(u8, 1)});
12161218}
12171219
12181220test "buffer" {
......@@ -1238,14 +1240,14 @@ test "buffer" {
12381240test "array" {
12391241 {
12401242 const value: [3]u8 = "abc".*;
1241 try testFmt("array: abc\n", "array: {}\n", value);
1242 try testFmt("array: abc\n", "array: {}\n", &value);
1243 try testFmt("array: abc\n", "array: {}\n", .{value});
1244 try testFmt("array: abc\n", "array: {}\n", .{&value});
12431245
12441246 var buf: [100]u8 = undefined;
12451247 try testFmt(
1246 try bufPrint(buf[0..], "array: [3]u8@{x}\n", @ptrToInt(&value)),
1248 try bufPrint(buf[0..], "array: [3]u8@{x}\n", .{@ptrToInt(&value)}),
12471249 "array: {*}\n",
1248 &value,
1250 .{&value},
12491251 );
12501252 }
12511253}
......@@ -1253,36 +1255,36 @@ test "array" {
12531255test "slice" {
12541256 {
12551257 const value: []const u8 = "abc";
1256 try testFmt("slice: abc\n", "slice: {}\n", value);
1258 try testFmt("slice: abc\n", "slice: {}\n", .{value});
12571259 }
12581260 {
12591261 const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0];
1260 try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", value);
1262 try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", .{value});
12611263 }
12621264
1263 try testFmt("buf: Test \n", "buf: {s:5}\n", "Test");
1264 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");
1265 try testFmt("buf: Test \n", "buf: {s:5}\n", .{"Test"});
1266 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"});
12651267}
12661268
12671269test "pointer" {
12681270 {
12691271 const value = @intToPtr(*i32, 0xdeadbeef);
1270 try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", value);
1271 try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", value);
1272 try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value});
1273 try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value});
12721274 }
12731275 {
12741276 const value = @intToPtr(fn () void, 0xdeadbeef);
1275 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
1277 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
12761278 }
12771279 {
12781280 const value = @intToPtr(fn () void, 0xdeadbeef);
1279 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
1281 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
12801282 }
12811283}
12821284
12831285test "cstr" {
1284 try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C");
1285 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C");
1286 try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"});
1287 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"});
12861288}
12871289
12881290test "filesize" {
......@@ -1290,8 +1292,8 @@ test "filesize" {
12901292 // TODO https://github.com/ziglang/zig/issues/3289
12911293 return error.SkipZigTest;
12921294 }
1293 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024));
1294 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024));
1295 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", .{@as(usize, 63 * 1024 * 1024)});
1296 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", .{@as(usize, 63 * 1024 * 1024)});
12951297}
12961298
12971299test "struct" {
......@@ -1300,8 +1302,8 @@ test "struct" {
13001302 field: u8,
13011303 };
13021304 const value = Struct{ .field = 42 };
1303 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value);
1304 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value);
1305 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{value});
1306 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{&value});
13051307 }
13061308 {
13071309 const Struct = struct {
......@@ -1309,7 +1311,7 @@ test "struct" {
13091311 b: u1,
13101312 };
13111313 const value = Struct{ .a = 0, .b = 1 };
1312 try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", value);
1314 try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value});
13131315 }
13141316}
13151317
......@@ -1319,8 +1321,8 @@ test "enum" {
13191321 Two,
13201322 };
13211323 const value = Enum.Two;
1322 try testFmt("enum: Enum.Two\n", "enum: {}\n", value);
1323 try testFmt("enum: Enum.Two\n", "enum: {}\n", &value);
1324 try testFmt("enum: Enum.Two\n", "enum: {}\n", .{value});
1325 try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value});
13241326}
13251327
13261328test "float.scientific" {
......@@ -1328,10 +1330,10 @@ test "float.scientific" {
13281330 // TODO https://github.com/ziglang/zig/issues/3289
13291331 return error.SkipZigTest;
13301332 }
1331 try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));
1332 try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));
1333 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
1334 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
1333 try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)});
1334 try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)});
1335 try testFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)});
1336 try testFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)});
13351337}
13361338
13371339test "float.scientific.precision" {
......@@ -1339,12 +1341,12 @@ test "float.scientific.precision" {
13391341 // TODO https://github.com/ziglang/zig/issues/3289
13401342 return error.SkipZigTest;
13411343 }
1342 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42));
1343 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563))));
1344 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));
1344 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)});
1345 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))});
1346 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))});
13451347 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
13461348 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
1347 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400))));
1349 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1203982400)))});
13481350}
13491351
13501352test "float.special" {
......@@ -1352,14 +1354,14 @@ test "float.special" {
13521354 // TODO https://github.com/ziglang/zig/issues/3289
13531355 return error.SkipZigTest;
13541356 }
1355 try testFmt("f64: nan", "f64: {}", math.nan_f64);
1357 try testFmt("f64: nan", "f64: {}", .{math.nan_f64});
13561358 // negative nan is not defined by IEE 754,
13571359 // and ARM thus normalizes it to positive nan
13581360 if (builtin.arch != builtin.Arch.arm) {
1359 try testFmt("f64: -nan", "f64: {}", -math.nan_f64);
1361 try testFmt("f64: -nan", "f64: {}", .{-math.nan_f64});
13601362 }
1361 try testFmt("f64: inf", "f64: {}", math.inf_f64);
1362 try testFmt("f64: -inf", "f64: {}", -math.inf_f64);
1363 try testFmt("f64: inf", "f64: {}", .{math.inf_f64});
1364 try testFmt("f64: -inf", "f64: {}", .{-math.inf_f64});
13631365}
13641366
13651367test "float.decimal" {
......@@ -1367,21 +1369,21 @@ test "float.decimal" {
13671369 // TODO https://github.com/ziglang/zig/issues/3289
13681370 return error.SkipZigTest;
13691371 }
1370 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
1371 try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));
1372 try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567));
1372 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
1373 try testFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
1374 try testFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});
13731375 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
13741376 // -11.12339... is rounded back up to -11.1234
1375 try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));
1376 try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));
1377 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
1378 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
1379 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
1380 try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));
1381 try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));
1382 try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));
1383 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));
1384 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));
1377 try testFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)});
1378 try testFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)});
1379 try testFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)});
1380 try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)});
1381 try testFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)});
1382 try testFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)});
1383 try testFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)});
1384 try testFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)});
1385 try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)});
1386 try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)});
13851387}
13861388
13871389test "float.libc.sanity" {
......@@ -1389,22 +1391,22 @@ test "float.libc.sanity" {
13891391 // TODO https://github.com/ziglang/zig/issues/3289
13901392 return error.SkipZigTest;
13911393 }
1392 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781))));
1393 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389))));
1394 try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278))));
1395 try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));
1396 try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));
1394 try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))});
1395 try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))});
1396 try testFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))});
1397 try testFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))});
1398 try testFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))});
13971399
13981400 // libc differences
13991401 //
14001402 // This is 0.015625 exactly according to gdb. We thus round down,
14011403 // however glibc rounds up for some reason. This occurs for all
14021404 // floats of the form x.yyyy25 on a precision point.
1403 try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568))));
1405 try testFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1015021568)))});
14041406 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
14051407 // also rounds to 630 so I'm inclined to believe libc is not
14061408 // optimal here.
1407 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049))));
1409 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1518338049)))});
14081410}
14091411
14101412test "custom" {
......@@ -1422,9 +1424,9 @@ test "custom" {
14221424 output: fn (@typeOf(context), []const u8) Errors!void,
14231425 ) Errors!void {
14241426 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
1425 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y);
1427 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
14261428 } else if (comptime std.mem.eql(u8, fmt, "d")) {
1427 return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", self.x, self.y);
1429 return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", .{ self.x, self.y });
14281430 } else {
14291431 @compileError("Unknown format character: '" ++ fmt ++ "'");
14301432 }
......@@ -1436,12 +1438,12 @@ test "custom" {
14361438 .x = 10.2,
14371439 .y = 2.22,
14381440 };
1439 try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value);
1440 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value);
1441 try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{&value});
1442 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{&value});
14411443
14421444 // same thing but not passing a pointer
1443 try testFmt("point: (10.200,2.220)\n", "point: {}\n", value);
1444 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", value);
1445 try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{value});
1446 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value});
14451447}
14461448
14471449test "struct" {
......@@ -1455,7 +1457,7 @@ test "struct" {
14551457 .b = error.Unused,
14561458 };
14571459
1458 try testFmt("S{ .a = 456, .b = error.Unused }", "{}", inst);
1460 try testFmt("S{ .a = 456, .b = error.Unused }", "{}", .{inst});
14591461}
14601462
14611463test "union" {
......@@ -1478,13 +1480,13 @@ test "union" {
14781480 const uu_inst = UU{ .int = 456 };
14791481 const eu_inst = EU{ .float = 321.123 };
14801482
1481 try testFmt("TU{ .int = 123 }", "{}", tu_inst);
1483 try testFmt("TU{ .int = 123 }", "{}", .{tu_inst});
14821484
14831485 var buf: [100]u8 = undefined;
1484 const uu_result = try bufPrint(buf[0..], "{}", uu_inst);
1486 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
14851487 std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
14861488
1487 const eu_result = try bufPrint(buf[0..], "{}", eu_inst);
1489 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
14881490 std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
14891491}
14901492
......@@ -1497,7 +1499,7 @@ test "enum" {
14971499
14981500 const inst = E.Two;
14991501
1500 try testFmt("E.Two", "{}", inst);
1502 try testFmt("E.Two", "{}", .{inst});
15011503}
15021504
15031505test "struct.self-referential" {
......@@ -1511,7 +1513,7 @@ test "struct.self-referential" {
15111513 };
15121514 inst.a = &inst;
15131515
1514 try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", inst);
1516 try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", .{inst});
15151517}
15161518
15171519test "struct.zero-size" {
......@@ -1526,30 +1528,30 @@ test "struct.zero-size" {
15261528 const a = A{};
15271529 const b = B{ .a = a, .c = 0 };
15281530
1529 try testFmt("B{ .a = A{ }, .c = 0 }", "{}", b);
1531 try testFmt("B{ .a = A{ }, .c = 0 }", "{}", .{b});
15301532}
15311533
15321534test "bytes.hex" {
15331535 const some_bytes = "\xCA\xFE\xBA\xBE";
1534 try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes);
1535 try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes);
1536 try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes});
1537 try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes});
15361538 //Test Slices
1537 try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]);
1538 try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]);
1539 try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]});
1540 try testFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]});
15391541 const bytes_with_zeros = "\x00\x0E\xBA\xBE";
1540 try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros);
1542 try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
15411543}
15421544
1543fn testFmt(expected: []const u8, comptime template: []const u8, args: ...) !void {
1545fn testFmt(expected: []const u8, comptime template: []const u8, args: var) !void {
15441546 var buf: [100]u8 = undefined;
15451547 const result = try bufPrint(buf[0..], template, args);
15461548 if (mem.eql(u8, result, expected)) return;
15471549
1548 std.debug.warn("\n====== expected this output: =========\n");
1549 std.debug.warn("{}", expected);
1550 std.debug.warn("\n======== instead found this: =========\n");
1551 std.debug.warn("{}", result);
1552 std.debug.warn("\n======================================\n");
1550 std.debug.warn("\n====== expected this output: =========\n", .{});
1551 std.debug.warn("{}", .{expected});
1552 std.debug.warn("\n======== instead found this: =========\n", .{});
1553 std.debug.warn("{}", .{result});
1554 std.debug.warn("\n======================================\n", .{});
15531555 return error.TestFailed;
15541556}
15551557
......@@ -1602,7 +1604,7 @@ test "hexToBytes" {
16021604 const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706";
16031605 var pb: [32]u8 = undefined;
16041606 try hexToBytes(pb[0..], test_hex_str);
1605 try testFmt(test_hex_str, "{X}", pb);
1607 try testFmt(test_hex_str, "{X}", .{pb});
16061608}
16071609
16081610test "formatIntValue with comptime_int" {
......@@ -1628,7 +1630,7 @@ test "formatType max_depth" {
16281630 output: fn (@typeOf(context), []const u8) Errors!void,
16291631 ) Errors!void {
16301632 if (fmt.len == 0) {
1631 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y);
1633 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
16321634 } else {
16331635 @compileError("Unknown format string: '" ++ fmt ++ "'");
16341636 }
......@@ -1680,17 +1682,17 @@ test "formatType max_depth" {
16801682}
16811683
16821684test "positional" {
1683 try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1684 try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1685 try testFmt("0 0", "{0} {0}", @as(usize, 0));
1686 try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));
1687 try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));
1685 try testFmt("2 1 0", "{2} {1} {0}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) });
1686 try testFmt("2 1 0", "{2} {1} {}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) });
1687 try testFmt("0 0", "{0} {0}", .{@as(usize, 0)});
1688 try testFmt("0 1", "{} {1}", .{ @as(usize, 0), @as(usize, 1) });
1689 try testFmt("1 0 0 1", "{1} {} {0} {}", .{ @as(usize, 0), @as(usize, 1) });
16881690}
16891691
16901692test "positional with specifier" {
1691 try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
1693 try testFmt("10.0", "{0d:.1}", .{@as(f64, 9.999)});
16921694}
16931695
16941696test "positional/alignment/width/precision" {
1695 try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));
1697 try testFmt("10.0", "{0d: >3.1}", .{@as(f64, 9.999)});
16961698}
lib/std/hash/benchmark.zig+1-1
......@@ -164,7 +164,7 @@ fn usage() void {
164164 \\ --iterative-only
165165 \\ --help
166166 \\
167 );
167 , .{});
168168}
169169
170170fn mode(comptime x: comptime_int) comptime_int {
lib/std/http/headers.zig+1-1
......@@ -610,5 +610,5 @@ test "Headers.format" {
610610 \\foo: bar
611611 \\cookie: somevalue
612612 \\
613 , try std.fmt.bufPrint(buf[0..], "{}", h));
613 , try std.fmt.bufPrint(buf[0..], "{}", .{h}));
614614}
lib/std/io.zig+1-1
......@@ -492,7 +492,7 @@ test "io.SliceOutStream" {
492492 var slice_stream = SliceOutStream.init(buf[0..]);
493493 const stream = &slice_stream.stream;
494494
495 try stream.print("{}{}!", "Hello", "World");
495 try stream.print("{}{}!", .{ "Hello", "World" });
496496 testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());
497497}
498498
lib/std/io/out_stream.zig+1-1
......@@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type {
3535 }
3636 }
3737
38 pub fn print(self: *Self, comptime format: []const u8, args: ...) Error!void {
38 pub fn print(self: *Self, comptime format: []const u8, args: var) Error!void {
3939 return std.fmt.format(self, Error, self.writeFn, format, args);
4040 }
4141
lib/std/io/test.zig+4-4
......@@ -27,9 +27,9 @@ test "write a file, read it, then delete it" {
2727 var file_out_stream = file.outStream();
2828 var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream);
2929 const st = &buf_stream.stream;
30 try st.print("begin");
30 try st.print("begin", .{});
3131 try st.write(data[0..]);
32 try st.print("end");
32 try st.print("end", .{});
3333 try buf_stream.flush();
3434 }
3535
......@@ -72,7 +72,7 @@ test "BufferOutStream" {
7272
7373 const x: i32 = 42;
7474 const y: i32 = 1234;
75 try buf_stream.print("x: {}\ny: {}\n", x, y);
75 try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
7676
7777 expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
7878}
......@@ -605,7 +605,7 @@ test "c out stream" {
605605 }
606606
607607 const out_stream = &io.COutStream.init(out_file).stream;
608 try out_stream.print("hi: {}\n", @as(i32, 123));
608 try out_stream.print("hi: {}\n", .{@as(i32, 123)});
609609}
610610
611611test "File seek ops" {
lib/std/json/write_stream.zig+4-4
......@@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
158158 switch (@typeInfo(@typeOf(value))) {
159159 .Int => |info| {
160160 if (info.bits < 53) {
161 try self.stream.print("{}", value);
161 try self.stream.print("{}", .{value});
162162 self.popState();
163163 return;
164164 }
165165 if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) {
166 try self.stream.print("{}", value);
166 try self.stream.print("{}", .{value});
167167 self.popState();
168168 return;
169169 }
170170 },
171171 .Float => if (@floatCast(f64, value) == value) {
172 try self.stream.print("{}", value);
172 try self.stream.print("{}", .{value});
173173 self.popState();
174174 return;
175175 },
176176 else => {},
177177 }
178 try self.stream.print("\"{}\"", value);
178 try self.stream.print("\"{}\"", .{value});
179179 self.popState();
180180 }
181181
lib/std/math/big/int.zig+2-2
......@@ -180,9 +180,9 @@ pub const Int = struct {
180180
181181 pub fn dump(self: Int) void {
182182 for (self.limbs) |limb| {
183 debug.warn("{x} ", limb);
183 debug.warn("{x} ", .{limb});
184184 }
185 debug.warn("\n");
185 debug.warn("\n", .{});
186186 }
187187
188188 /// Negate the sign of an Int.
lib/std/net.zig+7-15
......@@ -277,32 +277,24 @@ pub const Address = extern union {
277277 os.AF_INET => {
278278 const port = mem.bigToNative(u16, self.in.port);
279279 const bytes = @ptrCast(*const [4]u8, &self.in.addr);
280 try std.fmt.format(
281 context,
282 Errors,
283 output,
284 "{}.{}.{}.{}:{}",
280 try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{
285281 bytes[0],
286282 bytes[1],
287283 bytes[2],
288284 bytes[3],
289285 port,
290 );
286 });
291287 },
292288 os.AF_INET6 => {
293289 const port = mem.bigToNative(u16, self.in6.port);
294290 if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
295 try std.fmt.format(
296 context,
297 Errors,
298 output,
299 "[::ffff:{}.{}.{}.{}]:{}",
291 try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{
300292 self.in6.addr[12],
301293 self.in6.addr[13],
302294 self.in6.addr[14],
303295 self.in6.addr[15],
304296 port,
305 );
297 });
306298 return;
307299 }
308300 const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr);
......@@ -327,19 +319,19 @@ pub const Address = extern union {
327319 }
328320 continue;
329321 }
330 try std.fmt.format(context, Errors, output, "{x}", native_endian_parts[i]);
322 try std.fmt.format(context, Errors, output, "{x}", .{native_endian_parts[i]});
331323 if (i != native_endian_parts.len - 1) {
332324 try output(context, ":");
333325 }
334326 }
335 try std.fmt.format(context, Errors, output, "]:{}", port);
327 try std.fmt.format(context, Errors, output, "]:{}", .{port});
336328 },
337329 os.AF_UNIX => {
338330 if (!has_unix_sockets) {
339331 unreachable;
340332 }
341333
342 try std.fmt.format(context, Errors, output, "{}", &self.un.path);
334 try std.fmt.format(context, Errors, output, "{}", .{&self.un.path});
343335 },
344336 else => unreachable,
345337 }
lib/std/net/test.zig+3-3
......@@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" {
2929 };
3030 for (ips) |ip, i| {
3131 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
32 var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
32 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
3333 std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
3434 }
3535
......@@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" {
5151 "127.0.0.1",
5252 }) |ip| {
5353 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
54 var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
54 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
5555 std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
5656 }
5757
......@@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void {
118118 var client = try server.accept();
119119
120120 const stream = &client.file.outStream().stream;
121 try stream.print("hello from server\n");
121 try stream.print("hello from server\n", .{});
122122}
lib/std/os.zig+2-2
......@@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
26032603 defer close(fd);
26042604
26052605 var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;
2606 const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", fd) catch unreachable;
2606 const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable;
26072607
26082608 return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
26092609 }
......@@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{
28322832/// and you get an unexpected error.
28332833pub fn unexpectedErrno(err: usize) UnexpectedError {
28342834 if (unexpected_error_tracing) {
2835 std.debug.warn("unexpected errno: {}\n", err);
2835 std.debug.warn("unexpected errno: {}\n", .{err});
28362836 std.debug.dumpCurrentStackTrace(null);
28372837 }
28382838 return error.Unexpected;
lib/std/os/windows.zig+2-2
......@@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
10391039 var buf_u8: [614]u8 = undefined;
10401040 var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);
10411041 _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
1042 std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]);
1042 std.debug.warn("error.Unexpected: GetLastError({}): {}\n", .{ err, buf_u8[0..len] });
10431043 std.debug.dumpCurrentStackTrace(null);
10441044 }
10451045 return error.Unexpected;
......@@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {
10531053/// and you get an unexpected status.
10541054pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
10551055 if (std.os.unexpected_error_tracing) {
1056 std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", status);
1056 std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{status});
10571057 std.debug.dumpCurrentStackTrace(null);
10581058 }
10591059 return error.Unexpected;
lib/std/os/zen.zig deleted-260
......@@ -1,260 +0,0 @@
1const std = @import("../std.zig");
2const assert = std.debug.assert;
3
4//////////////////////////
5//// IPC structures ////
6//////////////////////////
7
8pub const Message = struct {
9 sender: MailboxId,
10 receiver: MailboxId,
11 code: usize,
12 args: [5]usize,
13 payload: ?[]const u8,
14
15 pub fn from(mailbox_id: MailboxId) Message {
16 return Message{
17 .sender = MailboxId.Undefined,
18 .receiver = mailbox_id,
19 .code = undefined,
20 .args = undefined,
21 .payload = null,
22 };
23 }
24
25 pub fn to(mailbox_id: MailboxId, msg_code: usize, args: ...) Message {
26 var message = Message{
27 .sender = MailboxId.This,
28 .receiver = mailbox_id,
29 .code = msg_code,
30 .args = undefined,
31 .payload = null,
32 };
33
34 assert(args.len <= message.args.len);
35 comptime var i = 0;
36 inline while (i < args.len) : (i += 1) {
37 message.args[i] = args[i];
38 }
39
40 return message;
41 }
42
43 pub fn as(self: Message, sender: MailboxId) Message {
44 var message = self;
45 message.sender = sender;
46 return message;
47 }
48
49 pub fn withPayload(self: Message, payload: []const u8) Message {
50 var message = self;
51 message.payload = payload;
52 return message;
53 }
54};
55
56pub const MailboxId = union(enum) {
57 Undefined,
58 This,
59 Kernel,
60 Port: u16,
61 Thread: u16,
62};
63
64//////////////////////////////////////
65//// Ports reserved for servers ////
66//////////////////////////////////////
67
68pub const Server = struct {
69 pub const Keyboard = MailboxId{ .Port = 0 };
70 pub const Terminal = MailboxId{ .Port = 1 };
71};
72
73////////////////////////
74//// POSIX things ////
75////////////////////////
76
77// Standard streams.
78pub const STDIN_FILENO = 0;
79pub const STDOUT_FILENO = 1;
80pub const STDERR_FILENO = 2;
81
82// FIXME: let's borrow Linux's error numbers for now.
83usingnamespace @import("bits/linux/errno-generic.zig");
84// Get the errno from a syscall return value, or 0 for no error.
85pub fn getErrno(r: usize) usize {
86 const signed_r = @bitCast(isize, r);
87 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
88}
89
90// TODO: implement this correctly.
91pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
92 switch (fd) {
93 STDIN_FILENO => {
94 var i: usize = 0;
95 while (i < count) : (i += 1) {
96 send(&Message.to(Server.Keyboard, 0));
97
98 // FIXME: we should be certain that we are receiving from Keyboard.
99 var message = Message.from(MailboxId.This);
100 receive(&message);
101
102 buf[i] = @intCast(u8, message.args[0]);
103 }
104 },
105 else => unreachable,
106 }
107 return count;
108}
109
110// TODO: implement this correctly.
111pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
112 switch (fd) {
113 STDOUT_FILENO, STDERR_FILENO => {
114 send(&Message.to(Server.Terminal, 1).withPayload(buf[0..count]));
115 },
116 else => unreachable,
117 }
118 return count;
119}
120
121///////////////////////////
122//// Syscall numbers ////
123///////////////////////////
124
125pub const Syscall = enum(usize) {
126 exit = 0,
127 send = 1,
128 receive = 2,
129 subscribeIRQ = 3,
130 inb = 4,
131 outb = 5,
132 map = 6,
133 createThread = 7,
134};
135
136////////////////////
137//// Syscalls ////
138////////////////////
139
140pub fn exit(status: i32) noreturn {
141 _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status)));
142 unreachable;
143}
144
145pub fn send(message: *const Message) void {
146 _ = syscall1(Syscall.send, @ptrToInt(message));
147}
148
149pub fn receive(destination: *Message) void {
150 _ = syscall1(Syscall.receive, @ptrToInt(destination));
151}
152
153pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void {
154 _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id));
155}
156
157pub fn inb(port: u16) u8 {
158 return @intCast(u8, syscall1(Syscall.inb, port));
159}
160
161pub fn outb(port: u16, value: u8) void {
162 _ = syscall2(Syscall.outb, port, value);
163}
164
165pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
166 return syscall4(Syscall.map, v_addr, p_addr, size, @boolToInt(writable)) != 0;
167}
168
169pub fn createThread(function: fn () void) u16 {
170 return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function)));
171}
172
173/////////////////////////
174//// Syscall stubs ////
175/////////////////////////
176
177inline fn syscall0(number: Syscall) usize {
178 return asm volatile ("int $0x80"
179 : [ret] "={eax}" (-> usize)
180 : [number] "{eax}" (number)
181 );
182}
183
184inline fn syscall1(number: Syscall, arg1: usize) usize {
185 return asm volatile ("int $0x80"
186 : [ret] "={eax}" (-> usize)
187 : [number] "{eax}" (number),
188 [arg1] "{ecx}" (arg1)
189 );
190}
191
192inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize {
193 return asm volatile ("int $0x80"
194 : [ret] "={eax}" (-> usize)
195 : [number] "{eax}" (number),
196 [arg1] "{ecx}" (arg1),
197 [arg2] "{edx}" (arg2)
198 );
199}
200
201inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize {
202 return asm volatile ("int $0x80"
203 : [ret] "={eax}" (-> usize)
204 : [number] "{eax}" (number),
205 [arg1] "{ecx}" (arg1),
206 [arg2] "{edx}" (arg2),
207 [arg3] "{ebx}" (arg3)
208 );
209}
210
211inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
212 return asm volatile ("int $0x80"
213 : [ret] "={eax}" (-> usize)
214 : [number] "{eax}" (number),
215 [arg1] "{ecx}" (arg1),
216 [arg2] "{edx}" (arg2),
217 [arg3] "{ebx}" (arg3),
218 [arg4] "{esi}" (arg4)
219 );
220}
221
222inline fn syscall5(
223 number: Syscall,
224 arg1: usize,
225 arg2: usize,
226 arg3: usize,
227 arg4: usize,
228 arg5: usize,
229) usize {
230 return asm volatile ("int $0x80"
231 : [ret] "={eax}" (-> usize)
232 : [number] "{eax}" (number),
233 [arg1] "{ecx}" (arg1),
234 [arg2] "{edx}" (arg2),
235 [arg3] "{ebx}" (arg3),
236 [arg4] "{esi}" (arg4),
237 [arg5] "{edi}" (arg5)
238 );
239}
240
241inline fn syscall6(
242 number: Syscall,
243 arg1: usize,
244 arg2: usize,
245 arg3: usize,
246 arg4: usize,
247 arg5: usize,
248 arg6: usize,
249) usize {
250 return asm volatile ("int $0x80"
251 : [ret] "={eax}" (-> usize)
252 : [number] "{eax}" (number),
253 [arg1] "{ecx}" (arg1),
254 [arg2] "{edx}" (arg2),
255 [arg3] "{ebx}" (arg3),
256 [arg4] "{esi}" (arg4),
257 [arg5] "{edi}" (arg5),
258 [arg6] "{ebp}" (arg6)
259 );
260}
lib/std/priority_queue.zig+8-8
......@@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type {
199199 }
200200
201201 fn dump(self: *Self) void {
202 warn("{{ ");
203 warn("items: ");
202 warn("{{ ", .{});
203 warn("items: ", .{});
204204 for (self.items) |e, i| {
205205 if (i >= self.len) break;
206 warn("{}, ", e);
206 warn("{}, ", .{e});
207207 }
208 warn("array: ");
208 warn("array: ", .{});
209209 for (self.items) |e, i| {
210 warn("{}, ", e);
210 warn("{}, ", .{e});
211211 }
212 warn("len: {} ", self.len);
213 warn("capacity: {}", self.capacity());
214 warn(" }}\n");
212 warn("len: {} ", .{self.len});
213 warn("capacity: {}", .{self.capacity()});
214 warn(" }}\n", .{});
215215 }
216216 };
217217}
lib/std/progress.zig+11-11
......@@ -130,11 +130,11 @@ pub const Progress = struct {
130130 var end: usize = 0;
131131 if (self.columns_written > 0) {
132132 // restore cursor position
133 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", self.columns_written) catch unreachable).len;
133 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len;
134134 self.columns_written = 0;
135135
136136 // clear rest of line
137 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K") catch unreachable).len;
137 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
138138 }
139139
140140 if (!self.done) {
......@@ -142,28 +142,28 @@ pub const Progress = struct {
142142 var maybe_node: ?*Node = &self.root;
143143 while (maybe_node) |node| {
144144 if (need_ellipse) {
145 self.bufWrite(&end, "...");
145 self.bufWrite(&end, "...", .{});
146146 }
147147 need_ellipse = false;
148148 if (node.name.len != 0 or node.estimated_total_items != null) {
149149 if (node.name.len != 0) {
150 self.bufWrite(&end, "{}", node.name);
150 self.bufWrite(&end, "{}", .{node.name});
151151 need_ellipse = true;
152152 }
153153 if (node.estimated_total_items) |total| {
154 if (need_ellipse) self.bufWrite(&end, " ");
155 self.bufWrite(&end, "[{}/{}] ", node.completed_items + 1, total);
154 if (need_ellipse) self.bufWrite(&end, " ", .{});
155 self.bufWrite(&end, "[{}/{}] ", .{ node.completed_items + 1, total });
156156 need_ellipse = false;
157157 } else if (node.completed_items != 0) {
158 if (need_ellipse) self.bufWrite(&end, " ");
159 self.bufWrite(&end, "[{}] ", node.completed_items + 1);
158 if (need_ellipse) self.bufWrite(&end, " ", .{});
159 self.bufWrite(&end, "[{}] ", .{node.completed_items + 1});
160160 need_ellipse = false;
161161 }
162162 }
163163 maybe_node = node.recently_updated_child;
164164 }
165165 if (need_ellipse) {
166 self.bufWrite(&end, "...");
166 self.bufWrite(&end, "...", .{});
167167 }
168168 }
169169
......@@ -174,7 +174,7 @@ pub const Progress = struct {
174174 self.prev_refresh_timestamp = self.timer.read();
175175 }
176176
177 pub fn log(self: *Progress, comptime format: []const u8, args: ...) void {
177 pub fn log(self: *Progress, comptime format: []const u8, args: var) void {
178178 const file = self.terminal orelse return;
179179 self.refresh();
180180 file.outStream().stream.print(format, args) catch {
......@@ -184,7 +184,7 @@ pub const Progress = struct {
184184 self.columns_written = 0;
185185 }
186186
187 fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: ...) void {
187 fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: var) void {
188188 if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| {
189189 const amt = written.len;
190190 end.* += amt;
lib/std/special/build_runner.zig+18-15
......@@ -26,15 +26,15 @@ pub fn main() !void {
2626 _ = arg_it.skip();
2727
2828 const zig_exe = try unwrapArg(arg_it.next(allocator) orelse {
29 warn("Expected first argument to be path to zig compiler\n");
29 warn("Expected first argument to be path to zig compiler\n", .{});
3030 return error.InvalidArgs;
3131 });
3232 const build_root = try unwrapArg(arg_it.next(allocator) orelse {
33 warn("Expected second argument to be build root directory path\n");
33 warn("Expected second argument to be build root directory path\n", .{});
3434 return error.InvalidArgs;
3535 });
3636 const cache_root = try unwrapArg(arg_it.next(allocator) orelse {
37 warn("Expected third argument to be cache root directory path\n");
37 warn("Expected third argument to be cache root directory path\n", .{});
3838 return error.InvalidArgs;
3939 });
4040
......@@ -51,7 +51,7 @@ pub fn main() !void {
5151 if (mem.startsWith(u8, arg, "-D")) {
5252 const option_contents = arg[2..];
5353 if (option_contents.len == 0) {
54 warn("Expected option name after '-D'\n\n");
54 warn("Expected option name after '-D'\n\n", .{});
5555 return usageAndErr(builder, false, stderr_stream);
5656 }
5757 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
......@@ -70,18 +70,18 @@ pub fn main() !void {
7070 return usage(builder, false, stdout_stream);
7171 } else if (mem.eql(u8, arg, "--prefix")) {
7272 builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse {
73 warn("Expected argument after --prefix\n\n");
73 warn("Expected argument after --prefix\n\n", .{});
7474 return usageAndErr(builder, false, stderr_stream);
7575 });
7676 } else if (mem.eql(u8, arg, "--search-prefix")) {
7777 const search_prefix = try unwrapArg(arg_it.next(allocator) orelse {
78 warn("Expected argument after --search-prefix\n\n");
78 warn("Expected argument after --search-prefix\n\n", .{});
7979 return usageAndErr(builder, false, stderr_stream);
8080 });
8181 builder.addSearchPrefix(search_prefix);
8282 } else if (mem.eql(u8, arg, "--override-lib-dir")) {
8383 builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse {
84 warn("Expected argument after --override-lib-dir\n\n");
84 warn("Expected argument after --override-lib-dir\n\n", .{});
8585 return usageAndErr(builder, false, stderr_stream);
8686 });
8787 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
......@@ -99,7 +99,7 @@ pub fn main() !void {
9999 } else if (mem.eql(u8, arg, "--verbose-cc")) {
100100 builder.verbose_cc = true;
101101 } else {
102 warn("Unrecognized argument: {}\n\n", arg);
102 warn("Unrecognized argument: {}\n\n", .{arg});
103103 return usageAndErr(builder, false, stderr_stream);
104104 }
105105 } else {
......@@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
145145 \\
146146 \\Steps:
147147 \\
148 , builder.zig_exe);
148 , .{builder.zig_exe});
149149
150150 const allocator = builder.allocator;
151151 for (builder.top_level_steps.toSliceConst()) |top_level_step| {
152152 const name = if (&top_level_step.step == builder.default_step)
153 try fmt.allocPrint(allocator, "{} (default)", top_level_step.step.name)
153 try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name})
154154 else
155155 top_level_step.step.name;
156 try out_stream.print(" {s:22} {}\n", name, top_level_step.description);
156 try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description });
157157 }
158158
159159 try out_stream.write(
......@@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
169169 );
170170
171171 if (builder.available_options_list.len == 0) {
172 try out_stream.print(" (none)\n");
172 try out_stream.print(" (none)\n", .{});
173173 } else {
174174 for (builder.available_options_list.toSliceConst()) |option| {
175 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id));
175 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{
176 option.name,
177 Builder.typeIdName(option.type_id),
178 });
176179 defer allocator.free(name);
177 try out_stream.print("{s:24} {}\n", name, option.description);
180 try out_stream.print("{s:24} {}\n", .{ name, option.description });
178181 }
179182 }
180183
......@@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory};
204207
205208fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
206209 return arg catch |err| {
207 warn("Unable to parse command line: {}\n", err);
210 warn("Unable to parse command line: {}\n", .{err});
208211 return err;
209212 };
210213}
lib/std/special/init-exe/src/main.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
22
33pub fn main() anyerror!void {
4 std.debug.warn("All your base are belong to us.\n");
4 std.debug.warn("All your base are belong to us.\n", .{});
55}
lib/std/special/start.zig+2-2
......@@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 {
217217 if (std.event.Loop.instance) |loop| {
218218 if (!@hasDecl(root, "event_loop")) {
219219 loop.init() catch |err| {
220 std.debug.warn("error: {}\n", @errorName(err));
220 std.debug.warn("error: {}\n", .{@errorName(err)});
221221 if (@errorReturnTrace()) |trace| {
222222 std.debug.dumpStackTrace(trace.*);
223223 }
......@@ -264,7 +264,7 @@ fn callMain() u8 {
264264 },
265265 .ErrorUnion => {
266266 const result = root.main() catch |err| {
267 std.debug.warn("error: {}\n", @errorName(err));
267 std.debug.warn("error: {}\n", .{@errorName(err)});
268268 if (@errorReturnTrace()) |trace| {
269269 std.debug.dumpStackTrace(trace.*);
270270 }
lib/std/special/test_runner.zig+7-7
......@@ -16,28 +16,28 @@ pub fn main() anyerror!void {
1616 var test_node = root_node.start(test_fn.name, null);
1717 test_node.activate();
1818 progress.refresh();
19 if (progress.terminal == null) std.debug.warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
19 if (progress.terminal == null) std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name });
2020 if (test_fn.func()) |_| {
2121 ok_count += 1;
2222 test_node.end();
23 if (progress.terminal == null) std.debug.warn("OK\n");
23 if (progress.terminal == null) std.debug.warn("OK\n", .{});
2424 } else |err| switch (err) {
2525 error.SkipZigTest => {
2626 skip_count += 1;
2727 test_node.end();
28 progress.log("{}...SKIP\n", test_fn.name);
29 if (progress.terminal == null) std.debug.warn("SKIP\n");
28 progress.log("{}...SKIP\n", .{test_fn.name});
29 if (progress.terminal == null) std.debug.warn("SKIP\n", .{});
3030 },
3131 else => {
32 progress.log("");
32 progress.log("", .{});
3333 return err;
3434 },
3535 }
3636 }
3737 root_node.end();
3838 if (ok_count == test_fn_list.len) {
39 std.debug.warn("All {} tests passed.\n", ok_count);
39 std.debug.warn("All {} tests passed.\n", .{ok_count});
4040 } else {
41 std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count);
41 std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count });
4242 }
4343}
lib/std/target.zig+6-12
......@@ -321,14 +321,12 @@ pub const Target = union(enum) {
321321 pub const stack_align = 16;
322322
323323 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
324 return std.fmt.allocPrint(
325 allocator,
326 "{}{}-{}-{}",
324 return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{
327325 @tagName(self.getArch()),
328326 Target.archSubArchName(self.getArch()),
329327 @tagName(self.getOs()),
330328 @tagName(self.getAbi()),
331 );
329 });
332330 }
333331
334332 /// Returned slice must be freed by the caller.
......@@ -372,23 +370,19 @@ pub const Target = union(enum) {
372370 }
373371
374372 pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 {
375 return std.fmt.allocPrint(
376 allocator,
377 "{}-{}-{}",
373 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
378374 @tagName(self.getArch()),
379375 @tagName(self.getOs()),
380376 @tagName(self.getAbi()),
381 );
377 });
382378 }
383379
384380 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
385 return std.fmt.allocPrint(
386 allocator,
387 "{}-{}-{}",
381 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
388382 @tagName(self.getArch()),
389383 @tagName(self.getOs()),
390384 @tagName(self.getAbi()),
391 );
385 });
392386 }
393387
394388 pub fn parse(text: []const u8) !Target {
lib/std/testing.zig+23-18
......@@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
88 if (actual_error_union) |actual_payload| {
99 // TODO remove workaround here for https://github.com/ziglang/zig/issues/557
1010 if (@sizeOf(@typeOf(actual_payload)) == 0) {
11 std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload)));
11 std.debug.panic("expected error.{}, found {} value", .{
12 @errorName(expected_error),
13 @typeName(@typeOf(actual_payload)),
14 });
1215 } else {
13 std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload);
16 std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload });
1417 }
1518 } else |actual_error| {
1619 if (expected_error != actual_error) {
17 std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error));
20 std.debug.panic("expected error.{}, found error.{}", .{
21 @errorName(expected_error),
22 @errorName(actual_error),
23 });
1824 }
1925 }
2026}
......@@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
5157 .ErrorSet,
5258 => {
5359 if (actual != expected) {
54 std.debug.panic("expected {}, found {}", expected, actual);
60 std.debug.panic("expected {}, found {}", .{ expected, actual });
5561 }
5662 },
5763
......@@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
6268 builtin.TypeInfo.Pointer.Size.C,
6369 => {
6470 if (actual != expected) {
65 std.debug.panic("expected {*}, found {*}", expected, actual);
71 std.debug.panic("expected {*}, found {*}", .{ expected, actual });
6672 }
6773 },
6874
6975 builtin.TypeInfo.Pointer.Size.Slice => {
7076 if (actual.ptr != expected.ptr) {
71 std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr);
77 std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr });
7278 }
7379 if (actual.len != expected.len) {
74 std.debug.panic("expected slice len {}, found {}", expected.len, actual.len);
80 std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len });
7581 }
7682 },
7783 }
......@@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
106112 }
107113
108114 // we iterate over *all* union fields
109 // => we should never get here as the loop above is
115 // => we should never get here as the loop above is
110116 // including all possible values.
111117 unreachable;
112118 },
......@@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
116122 if (actual) |actual_payload| {
117123 expectEqual(expected_payload, actual_payload);
118124 } else {
119 std.debug.panic("expected {}, found null", expected_payload);
125 std.debug.panic("expected {}, found null", .{expected_payload});
120126 }
121127 } else {
122128 if (actual) |actual_payload| {
123 std.debug.panic("expected null, found {}", actual_payload);
129 std.debug.panic("expected null, found {}", .{actual_payload});
124130 }
125131 }
126132 },
......@@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
130136 if (actual) |actual_payload| {
131137 expectEqual(expected_payload, actual_payload);
132138 } else |actual_err| {
133 std.debug.panic("expected {}, found {}", expected_payload, actual_err);
139 std.debug.panic("expected {}, found {}", .{ expected_payload, actual_err });
134140 }
135141 } else |expected_err| {
136142 if (actual) |actual_payload| {
137 std.debug.panic("expected {}, found {}", expected_err, actual_payload);
143 std.debug.panic("expected {}, found {}", .{ expected_err, actual_payload });
138144 } else |actual_err| {
139145 expectEqual(expected_err, actual_err);
140146 }
......@@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
143149 }
144150}
145151
146test "expectEqual.union(enum)"
147{
152test "expectEqual.union(enum)" {
148153 const T = union(enum) {
149154 a: i32,
150155 b: f32,
151156 };
152157
153 const a10 = T { .a = 10 };
154 const a20 = T { .a = 20 };
158 const a10 = T{ .a = 10 };
159 const a20 = T{ .a = 20 };
155160
156161 expectEqual(a10, a10);
157162}
......@@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
165170 // If the child type is u8 and no weird bytes, we could print it as strings
166171 // Even for the length difference, it would be useful to see the values of the slices probably.
167172 if (expected.len != actual.len) {
168 std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len);
173 std.debug.panic("slice lengths differ. expected {}, found {}", .{ expected.len, actual.len });
169174 }
170175 var i: usize = 0;
171176 while (i < expected.len) : (i += 1) {
172177 if (expected[i] != actual[i]) {
173 std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]);
178 std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
174179 }
175180 }
176181}
lib/std/unicode.zig+1-1
......@@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
170170/// ```
171171/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();
172172/// while (utf8.nextCodepointSlice()) |codepoint| {
173/// std.debug.warn("got codepoint {}\n", codepoint);
173/// std.debug.warn("got codepoint {}\n", .{codepoint});
174174/// }
175175/// ```
176176pub const Utf8View = struct {
lib/std/unicode/throughput_test.zig+6-2
......@@ -24,8 +24,12 @@ pub fn main() !void {
2424 const elapsed_ns_better = timer.lap();
2525 @fence(.SeqCst);
2626
27 std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000);
28 std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000);
27 std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{
28 elapsed_ns_orig, elapsed_ns_orig / 1000000,
29 });
30 std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{
31 elapsed_ns_better, elapsed_ns_better / 1000000,
32 });
2933 asm volatile ("nop"
3034 :
3135 : [a] "r" (&buffer1),
lib/std/valgrind.zig-14
......@@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void {
114114 doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0);
115115}
116116
117//pub fn printf(format: [*]const u8, args: ...) usize {
118// return doClientRequestExpr(0,
119// .PrintfValistByRef,
120// @ptrToInt(format), @ptrToInt(args),
121// 0, 0, 0);
122//}
123
124//pub fn printfBacktrace(format: [*]const u8, args: ...) usize {
125// return doClientRequestExpr(0,
126// .PrintfBacktraceValistByRef,
127// @ptrToInt(format), @ptrToInt(args),
128// 0, 0, 0);
129//}
130
131117pub fn nonSIMDCall0(func: fn (usize) usize) usize {
132118 return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0);
133119}
lib/std/zig/ast.zig+15-9
......@@ -301,7 +301,9 @@ pub const Error = union(enum) {
301301 node: *Node,
302302
303303 pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void {
304 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));
304 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", .{
305 @tagName(self.node.id),
306 });
305307 }
306308 };
307309
......@@ -309,7 +311,8 @@ pub const Error = union(enum) {
309311 node: *Node,
310312
311313 pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void {
312 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));
314 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++
315 @tagName(Node.Id.FnProto) ++ ", found {}", .{@tagName(self.node.id)});
313316 }
314317 };
315318
......@@ -321,14 +324,14 @@ pub const Error = union(enum) {
321324 const found_token = tokens.at(self.token);
322325 switch (found_token.id) {
323326 .Invalid_ampersands => {
324 return stream.print("`&&` is invalid. Note that `and` is boolean AND.");
327 return stream.print("`&&` is invalid. Note that `and` is boolean AND.", .{});
325328 },
326329 .Invalid => {
327 return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol());
330 return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
328331 },
329332 else => {
330333 const token_name = found_token.id.symbol();
331 return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name);
334 return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name });
332335 },
333336 }
334337 }
......@@ -340,7 +343,10 @@ pub const Error = union(enum) {
340343
341344 pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void {
342345 const actual_token = tokens.at(self.token);
343 return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol());
346 return stream.print("expected ',' or '{}', found '{}'", .{
347 self.end_id.symbol(),
348 actual_token.id.symbol(),
349 });
344350 }
345351 };
346352
......@@ -352,7 +358,7 @@ pub const Error = union(enum) {
352358
353359 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
354360 const actual_token = tokens.at(self.token);
355 return stream.print(msg, actual_token.id.symbol());
361 return stream.print(msg, .{actual_token.id.symbol()});
356362 }
357363 };
358364 }
......@@ -563,10 +569,10 @@ pub const Node = struct {
563569 {
564570 var i: usize = 0;
565571 while (i < indent) : (i += 1) {
566 std.debug.warn(" ");
572 std.debug.warn(" ", .{});
567573 }
568574 }
569 std.debug.warn("{}\n", @tagName(self.id));
575 std.debug.warn("{}\n", .{@tagName(self.id)});
570576
571577 var child_i: usize = 0;
572578 while (self.iterate(child_i)) |child| : (child_i += 1) {
lib/std/zig/parser_test.zig+16-30
......@@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" {
642642 );
643643}
644644
645test "zig fmt: var_args with trailing comma" {
646 try testCanonical(
647 \\pub fn add(
648 \\ a: ...,
649 \\) void {}
650 \\
651 );
652}
653
654645test "zig fmt: enum decl with no trailing comma" {
655646 try testTransform(
656647 \\const StrLitKind = enum {Normal, C};
......@@ -1750,13 +1741,6 @@ test "zig fmt: call expression" {
17501741 );
17511742}
17521743
1753test "zig fmt: var args" {
1754 try testCanonical(
1755 \\fn print(args: ...) void {}
1756 \\
1757 );
1758}
1759
17601744test "zig fmt: var type" {
17611745 try testCanonical(
17621746 \\fn print(args: var) var {}
......@@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
27052689 while (error_it.next()) |parse_error| {
27062690 const token = tree.tokens.at(parse_error.loc());
27072691 const loc = tree.tokenLocation(0, parse_error.loc());
2708 try stderr.print("(memory buffer):{}:{}: error: ", loc.line + 1, loc.column + 1);
2692 try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 });
27092693 try tree.renderError(parse_error, stderr);
2710 try stderr.print("\n{}\n", source[loc.line_start..loc.line_end]);
2694 try stderr.print("\n{}\n", .{source[loc.line_start..loc.line_end]});
27112695 {
27122696 var i: usize = 0;
27132697 while (i < loc.column) : (i += 1) {
......@@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
27432727 var anything_changed: bool = undefined;
27442728 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
27452729 if (!mem.eql(u8, result_source, expected_source)) {
2746 warn("\n====== expected this output: =========\n");
2747 warn("{}", expected_source);
2748 warn("\n======== instead found this: =========\n");
2749 warn("{}", result_source);
2750 warn("\n======================================\n");
2730 warn("\n====== expected this output: =========\n", .{});
2731 warn("{}", .{expected_source});
2732 warn("\n======== instead found this: =========\n", .{});
2733 warn("{}", .{result_source});
2734 warn("\n======================================\n", .{});
27512735 return error.TestFailed;
27522736 }
27532737 const changes_expected = source.ptr != expected_source.ptr;
27542738 if (anything_changed != changes_expected) {
2755 warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);
2739 warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
27562740 return error.TestFailed;
27572741 }
27582742 std.testing.expect(anything_changed == changes_expected);
......@@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
27722756 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
27732757 warn(
27742758 "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
2775 fail_index,
2776 needed_alloc_count,
2777 failing_allocator.allocated_bytes,
2778 failing_allocator.freed_bytes,
2779 failing_allocator.allocations,
2780 failing_allocator.deallocations,
2759 .{
2760 fail_index,
2761 needed_alloc_count,
2762 failing_allocator.allocated_bytes,
2763 failing_allocator.freed_bytes,
2764 failing_allocator.allocations,
2765 failing_allocator.deallocations,
2766 },
27812767 );
27822768 return error.MemoryLeakDetected;
27832769 }
lib/std/zig/render.zig+3-3
......@@ -76,7 +76,7 @@ fn renderRoot(
7676 // render all the line comments at the beginning of the file
7777 while (tok_it.next()) |token| {
7878 if (token.id != .LineComment) break;
79 try stream.print("{}\n", mem.trimRight(u8, tree.tokenSlicePtr(token), " "));
79 try stream.print("{}\n", .{mem.trimRight(u8, tree.tokenSlicePtr(token), " ")});
8080 if (tok_it.peek()) |next_token| {
8181 const loc = tree.tokenLocationPtr(token.end, next_token);
8282 if (loc.line >= 2) {
......@@ -1226,7 +1226,7 @@ fn renderExpression(
12261226
12271227 var skip_first_indent = true;
12281228 if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) {
1229 try stream.print("\n");
1229 try stream.print("\n", .{});
12301230 skip_first_indent = false;
12311231 }
12321232
......@@ -2129,7 +2129,7 @@ fn renderTokenOffset(
21292129
21302130 var loc = tree.tokenLocationPtr(token.end, next_token);
21312131 if (loc.line == 0) {
2132 try stream.print(" {}", mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
2132 try stream.print(" {}", .{mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")});
21332133 offset = 2;
21342134 token = next_token;
21352135 next_token = tree.tokens.at(token_index + offset);
lib/std/zig/tokenizer.zig+2-2
......@@ -330,7 +330,7 @@ pub const Tokenizer = struct {
330330
331331 /// For debugging purposes
332332 pub fn dump(self: *Tokenizer, token: *const Token) void {
333 std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);
333 std.debug.warn("{} \"{}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] });
334334 }
335335
336336 pub fn init(buffer: []const u8) Tokenizer {
......@@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
15761576 for (expected_tokens) |expected_token_id| {
15771577 const token = tokenizer.next();
15781578 if (token.id != expected_token_id) {
1579 std.debug.panic("expected {}, found {}\n", @tagName(expected_token_id), @tagName(token.id));
1579 std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
15801580 }
15811581 }
15821582 const last_token = tokenizer.next();
src-self-hosted/arg.zig+6-6
......@@ -98,15 +98,15 @@ pub const Args = struct {
9898 const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| {
9999 switch (err) {
100100 error.ArgumentNotInAllowedSet => {
101 std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg);
102 std.debug.warn("allowed options are ");
101 std.debug.warn("argument '{}' is invalid for flag '{}'\n", .{ args[i], arg });
102 std.debug.warn("allowed options are ", .{});
103103 for (flag.allowed_set.?) |possible| {
104 std.debug.warn("'{}' ", possible);
104 std.debug.warn("'{}' ", .{possible});
105105 }
106 std.debug.warn("\n");
106 std.debug.warn("\n", .{});
107107 },
108108 error.MissingFlagArguments => {
109 std.debug.warn("missing argument for flag: {}\n", arg);
109 std.debug.warn("missing argument for flag: {}\n", .{arg});
110110 },
111111 else => {},
112112 }
......@@ -134,7 +134,7 @@ pub const Args = struct {
134134 }
135135
136136 // TODO: Better errors with context, global error state and return is sufficient.
137 std.debug.warn("could not match flag: {}\n", arg);
137 std.debug.warn("could not match flag: {}\n", .{arg});
138138 return error.UnknownFlag;
139139 } else {
140140 try parsed.positionals.append(arg);
src-self-hosted/dep_tokenizer.zig+15-15
......@@ -38,7 +38,7 @@ pub const Tokenizer = struct {
3838 },
3939 .target => |*target| switch (char) {
4040 '\t', '\n', '\r', ' ' => {
41 return self.errorIllegalChar(self.index, char, "invalid target");
41 return self.errorIllegalChar(self.index, char, "invalid target", .{});
4242 },
4343 '$' => {
4444 self.state = State{ .target_dollar_sign = target.* };
......@@ -59,7 +59,7 @@ pub const Tokenizer = struct {
5959 },
6060 .target_reverse_solidus => |*target| switch (char) {
6161 '\t', '\n', '\r' => {
62 return self.errorIllegalChar(self.index, char, "bad target escape");
62 return self.errorIllegalChar(self.index, char, "bad target escape", .{});
6363 },
6464 ' ', '#', '\\' => {
6565 try target.appendByte(char);
......@@ -84,7 +84,7 @@ pub const Tokenizer = struct {
8484 break; // advance
8585 },
8686 else => {
87 return self.errorIllegalChar(self.index, char, "expecting '$'");
87 return self.errorIllegalChar(self.index, char, "expecting '$'", .{});
8888 },
8989 },
9090 .target_colon => |*target| switch (char) {
......@@ -161,7 +161,7 @@ pub const Tokenizer = struct {
161161 break; // advance
162162 },
163163 else => {
164 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");
164 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
165165 },
166166 },
167167 .rhs_continuation_linefeed => switch (char) {
......@@ -170,7 +170,7 @@ pub const Tokenizer = struct {
170170 break; // advance
171171 },
172172 else => {
173 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");
173 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
174174 },
175175 },
176176 .prereq_quote => |*prereq| switch (char) {
......@@ -231,7 +231,7 @@ pub const Tokenizer = struct {
231231 return Token{ .id = .prereq, .bytes = bytes };
232232 },
233233 else => {
234 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");
234 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
235235 },
236236 },
237237 }
......@@ -249,13 +249,13 @@ pub const Tokenizer = struct {
249249 .rhs_continuation_linefeed,
250250 => {},
251251 .target => |target| {
252 return self.errorPosition(idx, target.toSlice(), "incomplete target");
252 return self.errorPosition(idx, target.toSlice(), "incomplete target", .{});
253253 },
254254 .target_reverse_solidus,
255255 .target_dollar_sign,
256256 => {
257257 const index = self.index - 1;
258 return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape");
258 return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{});
259259 },
260260 .target_colon => |target| {
261261 const bytes = target.toSlice();
......@@ -278,7 +278,7 @@ pub const Tokenizer = struct {
278278 self.state = State{ .lhs = {} };
279279 },
280280 .prereq_quote => |prereq| {
281 return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite");
281 return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{});
282282 },
283283 .prereq => |prereq| {
284284 const bytes = prereq.toSlice();
......@@ -299,29 +299,29 @@ pub const Tokenizer = struct {
299299 return null;
300300 }
301301
302 fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: ...) Error {
302 fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error {
303303 self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice();
304304 return Error.InvalidInput;
305305 }
306306
307 fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: ...) Error {
307 fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: var) Error {
308308 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
309309 std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {};
310310 try buffer.append(" '");
311311 var out = makeOutput(std.Buffer.append, &buffer);
312312 try printCharValues(&out, bytes);
313313 try buffer.append("'");
314 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position - (bytes.len - 1)) catch {};
314 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position - (bytes.len - 1)}) catch {};
315315 self.error_text = buffer.toSlice();
316316 return Error.InvalidInput;
317317 }
318318
319 fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: ...) Error {
319 fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: var) Error {
320320 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
321321 try buffer.append("illegal char ");
322322 var out = makeOutput(std.Buffer.append, &buffer);
323323 try printUnderstandableChar(&out, char);
324 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position) catch {};
324 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position}) catch {};
325325 if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {};
326326 self.error_text = buffer.toSlice();
327327 return Error.InvalidInput;
......@@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void {
998998
999999fn printUnderstandableChar(out: var, char: u8) !void {
10001000 if (!std.ascii.isPrint(char) or char == ' ') {
1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", .{char}) catch {};
10021002 } else {
10031003 try out.write("'");
10041004 try out.write(&[_]u8{printable_char_tab[char]});
src-self-hosted/stage1.zig+6-6
......@@ -205,7 +205,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
205205 defer allocator.free(source_code);
206206
207207 const tree = std.zig.parse(allocator, source_code) catch |err| {
208 try stderr.print("error parsing stdin: {}\n", err);
208 try stderr.print("error parsing stdin: {}\n", .{err});
209209 process.exit(1);
210210 };
211211 defer tree.deinit();
......@@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
294294 },
295295 else => {
296296 // TODO lock stderr printing
297 try stderr.print("unable to open '{}': {}\n", file_path, err);
297 try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
298298 fmt.any_error = true;
299299 return;
300300 },
......@@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
302302 defer fmt.allocator.free(source_code);
303303
304304 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
305 try stderr.print("error parsing file '{}': {}\n", file_path, err);
305 try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
306306 fmt.any_error = true;
307307 return;
308308 };
......@@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
320320 if (check_mode) {
321321 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
322322 if (anything_changed) {
323 try stderr.print("{}\n", file_path);
323 try stderr.print("{}\n", .{file_path});
324324 fmt.any_error = true;
325325 }
326326 } else {
......@@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
329329
330330 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
331331 if (anything_changed) {
332 try stderr.print("{}\n", file_path);
332 try stderr.print("{}\n", .{file_path});
333333 try baf.finish();
334334 }
335335 }
......@@ -374,7 +374,7 @@ fn printErrMsgToFile(
374374 const text = text_buf.toOwnedSlice();
375375
376376 const stream = &file.outStream().stream;
377 try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
377 try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
378378
379379 if (!color_on) return;
380380
src-self-hosted/translate_c.zig+49-30
......@@ -125,7 +125,7 @@ const Context = struct {
125125
126126 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
127127 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
128 return std.fmt.allocPrint(c.a(), "{}:{}:{}", filename, line, column);
128 return std.fmt.allocPrint(c.a(), "{}:{}:{}", .{ filename, line, column });
129129 }
130130};
131131
......@@ -228,20 +228,20 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void {
228228 return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl));
229229 },
230230 .Typedef => {
231 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs");
231 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs", .{});
232232 },
233233 .Enum => {
234 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums");
234 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums", .{});
235235 },
236236 .Record => {
237 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs");
237 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs", .{});
238238 },
239239 .Var => {
240 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables");
240 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables", .{});
241241 },
242242 else => {
243243 const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl));
244 try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", decl_name);
244 try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", .{decl_name});
245245 },
246246 }
247247}
......@@ -264,7 +264,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
264264 .is_export = switch (storage_class) {
265265 .None => has_body and c.mode != .import,
266266 .Extern, .Static => false,
267 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern"),
267 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),
268268 .Auto => unreachable, // Not legal on functions
269269 .Register => unreachable, // Not legal on functions
270270 },
......@@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
274274 const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type);
275275 break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
276276 error.UnsupportedType => {
277 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");
277 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
278278 },
279279 error.OutOfMemory => |e| return e,
280280 };
......@@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
283283 const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type);
284284 break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
285285 error.UnsupportedType => {
286 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");
286 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
287287 },
288288 error.OutOfMemory => |e| return e,
289289 };
......@@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
302302 error.OutOfMemory => |e| return e,
303303 error.UnsupportedTranslation,
304304 error.UnsupportedType,
305 => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function"),
305 => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function", .{}),
306306 };
307307 assert(result.node.id == ast.Node.Id.Block);
308308 proto_node.body_node = result.node;
......@@ -344,7 +344,7 @@ fn transStmt(
344344 error.UnsupportedTranslation,
345345 ZigClangStmt_getBeginLoc(stmt),
346346 "TODO implement translation of stmt class {}",
347 @tagName(sc),
347 .{@tagName(sc)},
348348 );
349349 },
350350 }
......@@ -364,7 +364,7 @@ fn transBinaryOperator(
364364 error.UnsupportedTranslation,
365365 ZigClangBinaryOperator_getBeginLoc(stmt),
366366 "TODO: handle more C binary operators: {}",
367 op,
367 .{op},
368368 ),
369369 .Assign => return TransResult{
370370 .node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base,
......@@ -415,7 +415,7 @@ fn transBinaryOperator(
415415 error.UnsupportedTranslation,
416416 ZigClangBinaryOperator_getBeginLoc(stmt),
417417 "TODO: handle more C binary operators: {}",
418 op,
418 .{op},
419419 ),
420420 .MulAssign,
421421 .DivAssign,
......@@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe
567567 error.UnsupportedTranslation,
568568 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),
569569 "TODO implement translation of DeclStmt kind {}",
570 @tagName(kind),
570 .{@tagName(kind)},
571571 ),
572572 }
573573 }
......@@ -636,7 +636,7 @@ fn transImplicitCastExpr(
636636 error.UnsupportedTranslation,
637637 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)),
638638 "TODO implement translation of CastKind {}",
639 @tagName(kind),
639 .{@tagName(kind)},
640640 ),
641641 }
642642}
......@@ -650,7 +650,7 @@ fn transIntegerLiteral(
650650 var eval_result: ZigClangExprEvalResult = undefined;
651651 if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) {
652652 const loc = ZigClangIntegerLiteral_getBeginLoc(expr);
653 return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal");
653 return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal", .{});
654654 }
655655 const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val));
656656 const res = TransResult{
......@@ -719,7 +719,7 @@ fn transStringLiteral(
719719 error.UnsupportedTranslation,
720720 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),
721721 "TODO: support string literal kind {}",
722 kind,
722 .{kind},
723723 ),
724724 }
725725}
......@@ -751,7 +751,7 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 {
751751 '\n' => return "\\n"[0..],
752752 '\r' => return "\\r"[0..],
753753 '\t' => return "\\t"[0..],
754 else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", c) catch unreachable,
754 else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", .{c}) catch unreachable,
755755 };
756756 std.mem.copy(u8, char_buf, escaped);
757757 return char_buf[0..escaped.len];
......@@ -1016,7 +1016,13 @@ fn transCreateNodeAssign(
10161016 // zig: lhs = _tmp;
10171017 // zig: break :x _tmp
10181018 // zig: })
1019 return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(lhs), "TODO: worst case assign op expr");
1019 return revertAndWarn(
1020 rp,
1021 error.UnsupportedTranslation,
1022 ZigClangExpr_getBeginLoc(lhs),
1023 "TODO: worst case assign op expr",
1024 .{},
1025 );
10201026}
10211027
10221028fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.BuiltinCall {
......@@ -1211,7 +1217,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour
12111217 .Float128 => return appendIdentifier(rp.c, "f128"),
12121218 .Float16 => return appendIdentifier(rp.c, "f16"),
12131219 .LongDouble => return appendIdentifier(rp.c, "c_longdouble"),
1214 else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type"),
1220 else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type", .{}),
12151221 }
12161222 },
12171223 .FunctionProto => {
......@@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour
12531259 },
12541260 else => {
12551261 const type_name = rp.c.str(ZigClangType_getTypeClassName(ty));
1256 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", type_name);
1262 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name});
12571263 },
12581264 }
12591265}
......@@ -1275,7 +1281,13 @@ fn transCC(
12751281 switch (clang_cc) {
12761282 .C => return CallingConvention.C,
12771283 .X86StdCall => return CallingConvention.Stdcall,
1278 else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported calling convention: {}", @tagName(clang_cc)),
1284 else => return revertAndWarn(
1285 rp,
1286 error.UnsupportedType,
1287 source_loc,
1288 "unsupported calling convention: {}",
1289 .{@tagName(clang_cc)},
1290 ),
12791291 }
12801292}
12811293
......@@ -1292,7 +1304,13 @@ fn transFnProto(
12921304 const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty);
12931305 var i: usize = 0;
12941306 while (i < param_count) : (i += 1) {
1295 return revertAndWarn(rp, error.UnsupportedType, source_loc, "TODO: implement parameters for FunctionProto in transType");
1307 return revertAndWarn(
1308 rp,
1309 error.UnsupportedType,
1310 source_loc,
1311 "TODO: implement parameters for FunctionProto in transType",
1312 .{},
1313 );
12961314 }
12971315
12981316 return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);
......@@ -1350,7 +1368,7 @@ fn finishTransFnProto(
13501368 } else {
13511369 break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) {
13521370 error.UnsupportedType => {
1353 try emitWarning(rp.c, source_loc, "unsupported function proto return type");
1371 try emitWarning(rp.c, source_loc, "unsupported function proto return type", .{});
13541372 return err;
13551373 },
13561374 error.OutOfMemory => |e| return e,
......@@ -1397,18 +1415,19 @@ fn revertAndWarn(
13971415 err: var,
13981416 source_loc: ZigClangSourceLocation,
13991417 comptime format: []const u8,
1400 args: ...,
1418 args: var,
14011419) (@typeOf(err) || error{OutOfMemory}) {
14021420 rp.activate();
14031421 try emitWarning(rp.c, source_loc, format, args);
14041422 return err;
14051423}
14061424
1407fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: ...) !void {
1408 _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, c.locStr(loc), args);
1425fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: var) !void {
1426 const args_prefix = .{c.locStr(loc)};
1427 _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args);
14091428}
14101429
1411fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: ...) !void {
1430fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: var) !void {
14121431 // const name = @compileError(msg);
14131432 const const_tok = try appendToken(c, .Keyword_const, "const");
14141433 const name_tok = try appendToken(c, .Identifier, name);
......@@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime
14561475}
14571476
14581477fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex {
1459 return appendTokenFmt(c, token_id, "{}", bytes);
1478 return appendTokenFmt(c, token_id, "{}", .{bytes});
14601479}
14611480
1462fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: ...) !ast.TokenIndex {
1481fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {
14631482 const S = struct {
14641483 fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void {
14651484 return context.source_buffer.append(bytes);
src/ir.cpp+12-4
......@@ -17025,7 +17025,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1702517025 {
1702617026 result_loc_pass1 = no_result_loc();
1702717027 }
17028 bool was_written = result_loc_pass1->written;
17028 bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;
1702917029 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
1703017030 value, force_runtime, non_null_comptime, allow_discard);
1703117031 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
......@@ -17038,7 +17038,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1703817038 }
1703917039
1704017040 InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field;
17041 if (!was_written && isf != nullptr) {
17041 if (!was_already_resolved && isf != nullptr) {
1704217042 // Now it's time to add the field to the struct type.
1704317043 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;
1704417044 uint32_t new_field_count = old_field_count + 1;
......@@ -18077,7 +18077,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1807718077 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
1807818078 return result_loc;
1807918079 }
18080 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
18080 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
18081 if (res_child_type == ira->codegen->builtin_types.entry_var) {
18082 res_child_type = impl_fn_type_id->return_type;
18083 }
18084 if (!handle_is_ptr(res_child_type)) {
1808118085 ir_reset_result(call_result_loc);
1808218086 result_loc = nullptr;
1808318087 }
......@@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1824018244 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
1824118245 return result_loc;
1824218246 }
18243 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
18247 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
18248 if (res_child_type == ira->codegen->builtin_types.entry_var) {
18249 res_child_type = return_type;
18250 }
18251 if (!handle_is_ptr(res_child_type)) {
1824418252 ir_reset_result(call_result_loc);
1824518253 result_loc = nullptr;
1824618254 }
test/cli.zig+11-11
......@@ -19,11 +19,11 @@ pub fn main() !void {
1919 a = &arena.allocator;
2020
2121 const zig_exe_rel = try (arg_it.next(a) orelse {
22 std.debug.warn("Expected first argument to be path to zig compiler\n");
22 std.debug.warn("Expected first argument to be path to zig compiler\n", .{});
2323 return error.InvalidArgs;
2424 });
2525 const cache_root = try (arg_it.next(a) orelse {
26 std.debug.warn("Expected second argument to be cache root directory path\n");
26 std.debug.warn("Expected second argument to be cache root directory path\n", .{});
2727 return error.InvalidArgs;
2828 });
2929 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
......@@ -45,39 +45,39 @@ pub fn main() !void {
4545
4646fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
4747 return arg catch |err| {
48 warn("Unable to parse command line: {}\n", err);
48 warn("Unable to parse command line: {}\n", .{err});
4949 return err;
5050 };
5151}
5252
5353fn printCmd(cwd: []const u8, argv: []const []const u8) void {
54 std.debug.warn("cd {} && ", cwd);
54 std.debug.warn("cd {} && ", .{cwd});
5555 for (argv) |arg| {
56 std.debug.warn("{} ", arg);
56 std.debug.warn("{} ", .{arg});
5757 }
58 std.debug.warn("\n");
58 std.debug.warn("\n", .{});
5959}
6060
6161fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
6262 const max_output_size = 100 * 1024;
6363 const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
64 std.debug.warn("The following command failed:\n");
64 std.debug.warn("The following command failed:\n", .{});
6565 printCmd(cwd, argv);
6666 return err;
6767 };
6868 switch (result.term) {
6969 .Exited => |code| {
7070 if (code != 0) {
71 std.debug.warn("The following command exited with error code {}:\n", code);
71 std.debug.warn("The following command exited with error code {}:\n", .{code});
7272 printCmd(cwd, argv);
73 std.debug.warn("stderr:\n{}\n", result.stderr);
73 std.debug.warn("stderr:\n{}\n", .{result.stderr});
7474 return error.CommandFailed;
7575 }
7676 },
7777 else => {
78 std.debug.warn("The following command terminated unexpectedly:\n");
78 std.debug.warn("The following command terminated unexpectedly:\n", .{});
7979 printCmd(cwd, argv);
80 std.debug.warn("stderr:\n{}\n", result.stderr);
80 std.debug.warn("stderr:\n{}\n", .{result.stderr});
8181 return error.CommandFailed;
8282 },
8383 }
test/compile_errors.zig+2-4
......@@ -2598,14 +2598,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
25982598 \\fn a(b: fn (*const u8) void) void {
25992599 \\ b('a');
26002600 \\}
2601 \\fn c(d: u8) void {
2602 \\ @import("std").debug.warn("{c}\n", d);
2603 \\}
2601 \\fn c(d: u8) void {}
26042602 \\export fn entry() void {
26052603 \\ a(c);
26062604 \\}
26072605 ,
2608 "tmp.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
2606 "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
26092607 );
26102608
26112609 cases.add(
test/standalone/cat/main.zig+5-5
......@@ -23,7 +23,7 @@ pub fn main() !void {
2323 return usage(exe);
2424 } else {
2525 const file = cwd.openFile(arg, .{}) catch |err| {
26 warn("Unable to open file: {}\n", @errorName(err));
26 warn("Unable to open file: {}\n", .{@errorName(err)});
2727 return err;
2828 };
2929 defer file.close();
......@@ -38,7 +38,7 @@ pub fn main() !void {
3838}
3939
4040fn usage(exe: []const u8) !void {
41 warn("Usage: {} [FILE]...\n", exe);
41 warn("Usage: {} [FILE]...\n", .{exe});
4242 return error.Invalid;
4343}
4444
......@@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
4747
4848 while (true) {
4949 const bytes_read = file.read(buf[0..]) catch |err| {
50 warn("Unable to read from stream: {}\n", @errorName(err));
50 warn("Unable to read from stream: {}\n", .{@errorName(err)});
5151 return err;
5252 };
5353
......@@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
5656 }
5757
5858 stdout.write(buf[0..bytes_read]) catch |err| {
59 warn("Unable to write to stdout: {}\n", @errorName(err));
59 warn("Unable to write to stdout: {}\n", .{@errorName(err)});
6060 return err;
6161 };
6262 }
......@@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
6464
6565fn unwrapArg(arg: anyerror![]u8) ![]u8 {
6666 return arg catch |err| {
67 warn("Unable to parse command line: {}\n", err);
67 warn("Unable to parse command line: {}\n", .{err});
6868 return err;
6969 };
7070}
test/standalone/guess_number/main.zig+1-1
......@@ -10,7 +10,7 @@ pub fn main() !void {
1010
1111 var seed_bytes: [@sizeOf(u64)]u8 = undefined;
1212 std.crypto.randomBytes(seed_bytes[0..]) catch |err| {
13 std.debug.warn("unable to seed random number generator: {}", err);
13 std.debug.warn("unable to seed random number generator: {}", .{err});
1414 return err;
1515 };
1616 const seed = std.mem.readIntNative(u64, &seed_bytes);
test/tests.zig+94-66
......@@ -411,7 +411,7 @@ pub fn addPkgTests(
411411 is_qemu_enabled: bool,
412412 glibc_dir: ?[]const u8,
413413) *build.Step {
414 const step = b.step(b.fmt("test-{}", name), desc);
414 const step = b.step(b.fmt("test-{}", .{name}), desc);
415415
416416 for (test_targets) |test_target| {
417417 if (skip_non_native and test_target.target != .Native)
......@@ -454,14 +454,14 @@ pub fn addPkgTests(
454454 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
455455
456456 const these_tests = b.addTest(root_src);
457 these_tests.setNamePrefix(b.fmt(
458 "{}-{}-{}-{}-{} ",
457 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
458 these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", .{
459459 name,
460460 triple_prefix,
461461 @tagName(test_target.mode),
462462 libc_prefix,
463 if (test_target.single_threaded) "single" else "multi",
464 ));
463 single_threaded_txt,
464 }));
465465 these_tests.single_threaded = test_target.single_threaded;
466466 these_tests.setFilter(test_filter);
467467 these_tests.setBuildMode(test_target.mode);
......@@ -562,7 +562,7 @@ pub const CompareOutputContext = struct {
562562 args.append(arg) catch unreachable;
563563 }
564564
565 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
565 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
566566
567567 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
568568 defer child.deinit();
......@@ -572,7 +572,7 @@ pub const CompareOutputContext = struct {
572572 child.stderr_behavior = .Pipe;
573573 child.env_map = b.env_map;
574574
575 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
575 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
576576
577577 var stdout = Buffer.initNull(b.allocator);
578578 var stderr = Buffer.initNull(b.allocator);
......@@ -584,18 +584,18 @@ pub const CompareOutputContext = struct {
584584 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
585585
586586 const term = child.wait() catch |err| {
587 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
587 debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
588588 };
589589 switch (term) {
590590 .Exited => |code| {
591591 if (code != 0) {
592 warn("Process {} exited with error code {}\n", full_exe_path, code);
592 warn("Process {} exited with error code {}\n", .{ full_exe_path, code });
593593 printInvocation(args.toSliceConst());
594594 return error.TestFailed;
595595 }
596596 },
597597 else => {
598 warn("Process {} terminated unexpectedly\n", full_exe_path);
598 warn("Process {} terminated unexpectedly\n", .{full_exe_path});
599599 printInvocation(args.toSliceConst());
600600 return error.TestFailed;
601601 },
......@@ -609,10 +609,10 @@ pub const CompareOutputContext = struct {
609609 \\========= But found: ====================
610610 \\{}
611611 \\
612 , self.expected_output, stdout.toSliceConst());
612 , .{ self.expected_output, stdout.toSliceConst() });
613613 return error.TestFailed;
614614 }
615 warn("OK\n");
615 warn("OK\n", .{});
616616 }
617617 };
618618
......@@ -644,7 +644,7 @@ pub const CompareOutputContext = struct {
644644
645645 const full_exe_path = self.exe.getOutputPath();
646646
647 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
647 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
648648
649649 const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
650650 defer child.deinit();
......@@ -655,28 +655,34 @@ pub const CompareOutputContext = struct {
655655 child.stderr_behavior = .Ignore;
656656
657657 const term = child.spawnAndWait() catch |err| {
658 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
658 debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
659659 };
660660
661661 const expected_exit_code: u32 = 126;
662662 switch (term) {
663663 .Exited => |code| {
664664 if (code != expected_exit_code) {
665 warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code);
665 warn("\nProgram expected to exit with code {} but exited with code {}\n", .{
666 expected_exit_code, code,
667 });
666668 return error.TestFailed;
667669 }
668670 },
669671 .Signal => |sig| {
670 warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig);
672 warn("\nProgram expected to exit with code {} but instead signaled {}\n", .{
673 expected_exit_code, sig,
674 });
671675 return error.TestFailed;
672676 },
673677 else => {
674 warn("\nProgram expected to exit with code {}" ++ " but exited in an unexpected way\n", expected_exit_code);
678 warn("\nProgram expected to exit with code {} but exited in an unexpected way\n", .{
679 expected_exit_code,
680 });
675681 return error.TestFailed;
676682 },
677683 }
678684
679 warn("OK\n");
685 warn("OK\n", .{});
680686 }
681687 };
682688
......@@ -729,7 +735,9 @@ pub const CompareOutputContext = struct {
729735
730736 switch (case.special) {
731737 Special.Asm => {
732 const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable;
738 const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", .{
739 case.name,
740 }) catch unreachable;
733741 if (self.test_filter) |filter| {
734742 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
735743 }
......@@ -758,7 +766,11 @@ pub const CompareOutputContext = struct {
758766 },
759767 Special.None => {
760768 for (self.modes) |mode| {
761 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-output", case.name, @tagName(mode)) catch unreachable;
769 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
770 "compare-output",
771 case.name,
772 @tagName(mode),
773 }) catch unreachable;
762774 if (self.test_filter) |filter| {
763775 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
764776 }
......@@ -790,7 +802,7 @@ pub const CompareOutputContext = struct {
790802 }
791803 },
792804 Special.RuntimeSafety => {
793 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;
805 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", .{case.name}) catch unreachable;
794806 if (self.test_filter) |filter| {
795807 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
796808 }
......@@ -843,7 +855,11 @@ pub const StackTracesContext = struct {
843855 const expect_for_mode = expect[@enumToInt(mode)];
844856 if (expect_for_mode.len == 0) continue;
845857
846 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "stack-trace", name, @tagName(mode)) catch unreachable;
858 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
859 "stack-trace",
860 name,
861 @tagName(mode),
862 }) catch unreachable;
847863 if (self.test_filter) |filter| {
848864 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
849865 }
......@@ -907,7 +923,7 @@ pub const StackTracesContext = struct {
907923 defer args.deinit();
908924 args.append(full_exe_path) catch unreachable;
909925
910 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
926 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
911927
912928 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
913929 defer child.deinit();
......@@ -917,7 +933,7 @@ pub const StackTracesContext = struct {
917933 child.stderr_behavior = .Pipe;
918934 child.env_map = b.env_map;
919935
920 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
936 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
921937
922938 var stdout = Buffer.initNull(b.allocator);
923939 var stderr = Buffer.initNull(b.allocator);
......@@ -929,30 +945,34 @@ pub const StackTracesContext = struct {
929945 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
930946
931947 const term = child.wait() catch |err| {
932 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
948 debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
933949 };
934950
935951 switch (term) {
936952 .Exited => |code| {
937953 const expect_code: u32 = 1;
938954 if (code != expect_code) {
939 warn("Process {} exited with error code {} but expected code {}\n", full_exe_path, code, expect_code);
955 warn("Process {} exited with error code {} but expected code {}\n", .{
956 full_exe_path,
957 code,
958 expect_code,
959 });
940960 printInvocation(args.toSliceConst());
941961 return error.TestFailed;
942962 }
943963 },
944964 .Signal => |signum| {
945 warn("Process {} terminated on signal {}\n", full_exe_path, signum);
965 warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum });
946966 printInvocation(args.toSliceConst());
947967 return error.TestFailed;
948968 },
949969 .Stopped => |signum| {
950 warn("Process {} stopped on signal {}\n", full_exe_path, signum);
970 warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum });
951971 printInvocation(args.toSliceConst());
952972 return error.TestFailed;
953973 },
954974 .Unknown => |code| {
955 warn("Process {} terminated unexpectedly with error code {}\n", full_exe_path, code);
975 warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code });
956976 printInvocation(args.toSliceConst());
957977 return error.TestFailed;
958978 },
......@@ -1003,10 +1023,10 @@ pub const StackTracesContext = struct {
10031023 \\================================================
10041024 \\{}
10051025 \\
1006 , self.expect_output, got);
1026 , .{ self.expect_output, got });
10071027 return error.TestFailed;
10081028 }
1009 warn("OK\n");
1029 warn("OK\n", .{});
10101030 }
10111031 };
10121032};
......@@ -1129,7 +1149,7 @@ pub const CompileErrorContext = struct {
11291149 Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
11301150 }
11311151
1132 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
1152 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
11331153
11341154 if (b.verbose) {
11351155 printInvocation(zig_args.toSliceConst());
......@@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct {
11431163 child.stdout_behavior = .Pipe;
11441164 child.stderr_behavior = .Pipe;
11451165
1146 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
1166 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
11471167
11481168 var stdout_buf = Buffer.initNull(b.allocator);
11491169 var stderr_buf = Buffer.initNull(b.allocator);
......@@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct {
11551175 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
11561176
11571177 const term = child.wait() catch |err| {
1158 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
1178 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
11591179 };
11601180 switch (term) {
11611181 .Exited => |code| {
......@@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct {
11651185 }
11661186 },
11671187 else => {
1168 warn("Process {} terminated unexpectedly\n", b.zig_exe);
1188 warn("Process {} terminated unexpectedly\n", .{b.zig_exe});
11691189 printInvocation(zig_args.toSliceConst());
11701190 return error.TestFailed;
11711191 },
......@@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct {
11821202 \\{}
11831203 \\================================================
11841204 \\
1185 , stdout);
1205 , .{stdout});
11861206 return error.TestFailed;
11871207 }
11881208
......@@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct {
12001220 ok = ok and i == self.case.expected_errors.len;
12011221
12021222 if (!ok) {
1203 warn("\n======== Expected these compile errors: ========\n");
1223 warn("\n======== Expected these compile errors: ========\n", .{});
12041224 for (self.case.expected_errors.toSliceConst()) |expected| {
1205 warn("{}\n", expected);
1225 warn("{}\n", .{expected});
12061226 }
12071227 }
12081228 } else {
......@@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct {
12131233 \\=========== Expected compile error: ============
12141234 \\{}
12151235 \\
1216 , expected);
1236 , .{expected});
12171237 ok = false;
12181238 break;
12191239 }
......@@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct {
12251245 \\================= Full output: =================
12261246 \\{}
12271247 \\
1228 , stderr);
1248 , .{stderr});
12291249 return error.TestFailed;
12301250 }
12311251
1232 warn("OK\n");
1252 warn("OK\n", .{});
12331253 }
12341254 };
12351255
......@@ -1279,7 +1299,9 @@ pub const CompileErrorContext = struct {
12791299 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
12801300 const b = self.b;
12811301
1282 const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", case.name) catch unreachable;
1302 const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", .{
1303 case.name,
1304 }) catch unreachable;
12831305 if (self.test_filter) |filter| {
12841306 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
12851307 }
......@@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct {
13161338 pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {
13171339 const b = self.b;
13181340
1319 const annotated_case_name = b.fmt("build {} (Debug)", build_file);
1341 const annotated_case_name = b.fmt("build {} (Debug)", .{build_file});
13201342 if (self.test_filter) |filter| {
13211343 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
13221344 }
......@@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct {
13371359
13381360 const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
13391361
1340 const log_step = b.addLog("PASS {}\n", annotated_case_name);
1362 const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
13411363 log_step.step.dependOn(&run_cmd.step);
13421364
13431365 self.step.dependOn(&log_step.step);
......@@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct {
13471369 const b = self.b;
13481370
13491371 for (self.modes) |mode| {
1350 const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", root_src, @tagName(mode)) catch unreachable;
1372 const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", .{
1373 root_src,
1374 @tagName(mode),
1375 }) catch unreachable;
13511376 if (self.test_filter) |filter| {
13521377 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
13531378 }
......@@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct {
13581383 exe.linkSystemLibrary("c");
13591384 }
13601385
1361 const log_step = b.addLog("PASS {}\n", annotated_case_name);
1386 const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
13621387 log_step.step.dependOn(&exe.step);
13631388
13641389 self.step.dependOn(&log_step.step);
......@@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct {
14341459 zig_args.append(translate_c_cmd) catch unreachable;
14351460 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
14361461
1437 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
1462 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
14381463
14391464 if (b.verbose) {
14401465 printInvocation(zig_args.toSliceConst());
......@@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct {
14481473 child.stdout_behavior = .Pipe;
14491474 child.stderr_behavior = .Pipe;
14501475
1451 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
1476 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{
1477 zig_args.toSliceConst()[0],
1478 @errorName(err),
1479 });
14521480
14531481 var stdout_buf = Buffer.initNull(b.allocator);
14541482 var stderr_buf = Buffer.initNull(b.allocator);
......@@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct {
14601488 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
14611489
14621490 const term = child.wait() catch |err| {
1463 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
1491 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.toSliceConst()[0], @errorName(err) });
14641492 };
14651493 switch (term) {
14661494 .Exited => |code| {
14671495 if (code != 0) {
1468 warn("Compilation failed with exit code {}\n", code);
1496 warn("Compilation failed with exit code {}\n", .{code});
14691497 printInvocation(zig_args.toSliceConst());
14701498 return error.TestFailed;
14711499 }
14721500 },
14731501 .Signal => |code| {
1474 warn("Compilation failed with signal {}\n", code);
1502 warn("Compilation failed with signal {}\n", .{code});
14751503 printInvocation(zig_args.toSliceConst());
14761504 return error.TestFailed;
14771505 },
14781506 else => {
1479 warn("Compilation terminated unexpectedly\n");
1507 warn("Compilation terminated unexpectedly\n", .{});
14801508 printInvocation(zig_args.toSliceConst());
14811509 return error.TestFailed;
14821510 },
......@@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct {
14911519 \\{}
14921520 \\============================================
14931521 \\
1494 , stderr);
1522 , .{stderr});
14951523 printInvocation(zig_args.toSliceConst());
14961524 return error.TestFailed;
14971525 }
......@@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct {
15051533 \\========= But found: ===========================
15061534 \\{}
15071535 \\
1508 , expected_line, stdout);
1536 , .{ expected_line, stdout });
15091537 printInvocation(zig_args.toSliceConst());
15101538 return error.TestFailed;
15111539 }
15121540 }
1513 warn("OK\n");
1541 warn("OK\n", .{});
15141542 }
15151543 };
15161544
15171545 fn printInvocation(args: []const []const u8) void {
15181546 for (args) |arg| {
1519 warn("{} ", arg);
1547 warn("{} ", .{arg});
15201548 }
1521 warn("\n");
1549 warn("\n", .{});
15221550 }
15231551
15241552 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
......@@ -1586,7 +1614,7 @@ pub const TranslateCContext = struct {
15861614 const b = self.b;
15871615
15881616 const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c";
1589 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", translate_c_cmd, case.name) catch unreachable;
1617 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", .{ translate_c_cmd, case.name }) catch unreachable;
15901618 if (self.test_filter) |filter| {
15911619 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
15921620 }
......@@ -1666,7 +1694,7 @@ pub const GenHContext = struct {
16661694 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
16671695 const b = self.context.b;
16681696
1669 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
1697 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
16701698
16711699 const full_h_path = self.obj.getOutputHPath();
16721700 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
......@@ -1680,19 +1708,19 @@ pub const GenHContext = struct {
16801708 \\========= But found: ===========================
16811709 \\{}
16821710 \\
1683 , expected_line, actual_h);
1711 , .{ expected_line, actual_h });
16841712 return error.TestFailed;
16851713 }
16861714 }
1687 warn("OK\n");
1715 warn("OK\n", .{});
16881716 }
16891717 };
16901718
16911719 fn printInvocation(args: []const []const u8) void {
16921720 for (args) |arg| {
1693 warn("{} ", arg);
1721 warn("{} ", .{arg});
16941722 }
1695 warn("\n");
1723 warn("\n", .{});
16961724 }
16971725
16981726 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
......@@ -1724,7 +1752,7 @@ pub const GenHContext = struct {
17241752 ) catch unreachable;
17251753
17261754 const mode = builtin.Mode.Debug;
1727 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable;
1755 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable;
17281756 if (self.test_filter) |filter| {
17291757 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
17301758 }
......@@ -1749,7 +1777,7 @@ pub const GenHContext = struct {
17491777
17501778fn printInvocation(args: []const []const u8) void {
17511779 for (args) |arg| {
1752 warn("{} ", arg);
1780 warn("{} ", .{arg});
17531781 }
1754 warn("\n");
1782 warn("\n", .{});
17551783}