authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-26 13:19:30+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-02 17:12:57-07:00
log1c13ca5a05978011283ff55a586443b10b69fc85
tree30a411c8e359467ba520d3f8e68ebf8500aceffa
parentdd973fb365dbbe11ce5beac8b4889bfab3fddc4d

stage2: Use {s} instead of {} when formatting strings


27 files changed, 503 insertions(+), 360 deletions(-)

lib/std/meta/trait.zig+14
...@@ -298,6 +298,20 @@ pub fn isNumber(comptime T: type) bool {...@@ -298,6 +298,20 @@ pub fn isNumber(comptime T: type) bool {
298 };298 };
299}299}
300300
301pub fn isIntegerNumber(comptime T: type) bool {
302 return switch (@typeInfo(T)) {
303 .Int, .ComptimeInt => true,
304 else => false,
305 };
306}
307
308pub fn isFloatingNumber(comptime T: type) bool {
309 return switch (@typeInfo(T)) {
310 .Float, .ComptimeFloat => true,
311 else => false,
312 };
313}
314
301test "std.meta.trait.isNumber" {315test "std.meta.trait.isNumber" {
302 const NotANumber = struct {316 const NotANumber = struct {
303 number: u8,317 number: u8,
src/Cache.zig+2-2
...@@ -549,7 +549,7 @@ pub const Manifest = struct {...@@ -549,7 +549,7 @@ pub const Manifest = struct {
549 .target, .target_must_resolve, .prereq => {},549 .target, .target_must_resolve, .prereq => {},
550 else => |err| {550 else => |err| {
551 try err.printError(error_buf.writer());551 try err.printError(error_buf.writer());
552 std.log.err("failed parsing {}: {}", .{ dep_file_basename, error_buf.items });552 std.log.err("failed parsing {s}: {s}", .{ dep_file_basename, error_buf.items });
553 return error.InvalidDepFile;553 return error.InvalidDepFile;
554 },554 },
555 }555 }
...@@ -561,7 +561,7 @@ pub const Manifest = struct {...@@ -561,7 +561,7 @@ pub const Manifest = struct {
561 .prereq => |bytes| try self.addFilePost(bytes),561 .prereq => |bytes| try self.addFilePost(bytes),
562 else => |err| {562 else => |err| {
563 try err.printError(error_buf.writer());563 try err.printError(error_buf.writer());
564 std.log.err("failed parsing {}: {}", .{ dep_file_basename, error_buf.items });564 std.log.err("failed parsing {s}: {s}", .{ dep_file_basename, error_buf.items });
565 return error.InvalidDepFile;565 return error.InvalidDepFile;
566 },566 },
567 }567 }
src/Compilation.zig+47-47
...@@ -1475,7 +1475,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1475,7 +1475,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1475 // lifetime annotations in the ZIR.1475 // lifetime annotations in the ZIR.
1476 var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa);1476 var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa);
1477 defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;1477 defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;
1478 log.debug("analyze liveness of {}\n", .{decl.name});1478 log.debug("analyze liveness of {s}\n", .{decl.name});
1479 try liveness.analyze(module.gpa, &decl_arena.allocator, func.analysis.success);1479 try liveness.analyze(module.gpa, &decl_arena.allocator, func.analysis.success);
1480 }1480 }
14811481
...@@ -1492,7 +1492,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1492,7 +1492,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1492 module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(1492 module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(
1493 module.gpa,1493 module.gpa,
1494 decl.src(),1494 decl.src(),
1495 "unable to codegen: {}",1495 "unable to codegen: {s}",
1496 .{@errorName(err)},1496 .{@errorName(err)},
1497 ));1497 ));
1498 decl.analysis = .codegen_failure_retryable;1498 decl.analysis = .codegen_failure_retryable;
...@@ -1535,7 +1535,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1535,7 +1535,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1535 module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(1535 module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(
1536 module.gpa,1536 module.gpa,
1537 decl.src(),1537 decl.src(),
1538 "unable to update line number: {}",1538 "unable to update line number: {s}",
1539 .{@errorName(err)},1539 .{@errorName(err)},
1540 ));1540 ));
1541 decl.analysis = .codegen_failure_retryable;1541 decl.analysis = .codegen_failure_retryable;
...@@ -1544,50 +1544,50 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1544,50 +1544,50 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1544 .glibc_crt_file => |crt_file| {1544 .glibc_crt_file => |crt_file| {
1545 glibc.buildCRTFile(self, crt_file) catch |err| {1545 glibc.buildCRTFile(self, crt_file) catch |err| {
1546 // TODO Expose this as a normal compile error rather than crashing here.1546 // TODO Expose this as a normal compile error rather than crashing here.
1547 fatal("unable to build glibc CRT file: {}", .{@errorName(err)});1547 fatal("unable to build glibc CRT file: {s}", .{@errorName(err)});
1548 };1548 };
1549 },1549 },
1550 .glibc_shared_objects => {1550 .glibc_shared_objects => {
1551 glibc.buildSharedObjects(self) catch |err| {1551 glibc.buildSharedObjects(self) catch |err| {
1552 // TODO Expose this as a normal compile error rather than crashing here.1552 // TODO Expose this as a normal compile error rather than crashing here.
1553 fatal("unable to build glibc shared objects: {}", .{@errorName(err)});1553 fatal("unable to build glibc shared objects: {s}", .{@errorName(err)});
1554 };1554 };
1555 },1555 },
1556 .musl_crt_file => |crt_file| {1556 .musl_crt_file => |crt_file| {
1557 musl.buildCRTFile(self, crt_file) catch |err| {1557 musl.buildCRTFile(self, crt_file) catch |err| {
1558 // TODO Expose this as a normal compile error rather than crashing here.1558 // TODO Expose this as a normal compile error rather than crashing here.
1559 fatal("unable to build musl CRT file: {}", .{@errorName(err)});1559 fatal("unable to build musl CRT file: {s}", .{@errorName(err)});
1560 };1560 };
1561 },1561 },
1562 .mingw_crt_file => |crt_file| {1562 .mingw_crt_file => |crt_file| {
1563 mingw.buildCRTFile(self, crt_file) catch |err| {1563 mingw.buildCRTFile(self, crt_file) catch |err| {
1564 // TODO Expose this as a normal compile error rather than crashing here.1564 // TODO Expose this as a normal compile error rather than crashing here.
1565 fatal("unable to build mingw-w64 CRT file: {}", .{@errorName(err)});1565 fatal("unable to build mingw-w64 CRT file: {s}", .{@errorName(err)});
1566 };1566 };
1567 },1567 },
1568 .windows_import_lib => |index| {1568 .windows_import_lib => |index| {
1569 const link_lib = self.bin_file.options.system_libs.items()[index].key;1569 const link_lib = self.bin_file.options.system_libs.items()[index].key;
1570 mingw.buildImportLib(self, link_lib) catch |err| {1570 mingw.buildImportLib(self, link_lib) catch |err| {
1571 // TODO Expose this as a normal compile error rather than crashing here.1571 // TODO Expose this as a normal compile error rather than crashing here.
1572 fatal("unable to generate DLL import .lib file: {}", .{@errorName(err)});1572 fatal("unable to generate DLL import .lib file: {s}", .{@errorName(err)});
1573 };1573 };
1574 },1574 },
1575 .libunwind => {1575 .libunwind => {
1576 libunwind.buildStaticLib(self) catch |err| {1576 libunwind.buildStaticLib(self) catch |err| {
1577 // TODO Expose this as a normal compile error rather than crashing here.1577 // TODO Expose this as a normal compile error rather than crashing here.
1578 fatal("unable to build libunwind: {}", .{@errorName(err)});1578 fatal("unable to build libunwind: {s}", .{@errorName(err)});
1579 };1579 };
1580 },1580 },
1581 .libcxx => {1581 .libcxx => {
1582 libcxx.buildLibCXX(self) catch |err| {1582 libcxx.buildLibCXX(self) catch |err| {
1583 // TODO Expose this as a normal compile error rather than crashing here.1583 // TODO Expose this as a normal compile error rather than crashing here.
1584 fatal("unable to build libcxx: {}", .{@errorName(err)});1584 fatal("unable to build libcxx: {s}", .{@errorName(err)});
1585 };1585 };
1586 },1586 },
1587 .libcxxabi => {1587 .libcxxabi => {
1588 libcxx.buildLibCXXABI(self) catch |err| {1588 libcxx.buildLibCXXABI(self) catch |err| {
1589 // TODO Expose this as a normal compile error rather than crashing here.1589 // TODO Expose this as a normal compile error rather than crashing here.
1590 fatal("unable to build libcxxabi: {}", .{@errorName(err)});1590 fatal("unable to build libcxxabi: {s}", .{@errorName(err)});
1591 };1591 };
1592 },1592 },
1593 .libtsan => {1593 .libtsan => {
...@@ -1611,20 +1611,20 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1611,20 +1611,20 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1611 .libssp => {1611 .libssp => {
1612 self.buildOutputFromZig("ssp.zig", .Lib, &self.libssp_static_lib) catch |err| {1612 self.buildOutputFromZig("ssp.zig", .Lib, &self.libssp_static_lib) catch |err| {
1613 // TODO Expose this as a normal compile error rather than crashing here.1613 // TODO Expose this as a normal compile error rather than crashing here.
1614 fatal("unable to build libssp: {}", .{@errorName(err)});1614 fatal("unable to build libssp: {s}", .{@errorName(err)});
1615 };1615 };
1616 },1616 },
1617 .zig_libc => {1617 .zig_libc => {
1618 self.buildOutputFromZig("c.zig", .Lib, &self.libc_static_lib) catch |err| {1618 self.buildOutputFromZig("c.zig", .Lib, &self.libc_static_lib) catch |err| {
1619 // TODO Expose this as a normal compile error rather than crashing here.1619 // TODO Expose this as a normal compile error rather than crashing here.
1620 fatal("unable to build zig's multitarget libc: {}", .{@errorName(err)});1620 fatal("unable to build zig's multitarget libc: {s}", .{@errorName(err)});
1621 };1621 };
1622 },1622 },
1623 .generate_builtin_zig => {1623 .generate_builtin_zig => {
1624 // This Job is only queued up if there is a zig module.1624 // This Job is only queued up if there is a zig module.
1625 self.updateBuiltinZigFile(self.bin_file.options.module.?) catch |err| {1625 self.updateBuiltinZigFile(self.bin_file.options.module.?) catch |err| {
1626 // TODO Expose this as a normal compile error rather than crashing here.1626 // TODO Expose this as a normal compile error rather than crashing here.
1627 fatal("unable to update builtin.zig file: {}", .{@errorName(err)});1627 fatal("unable to update builtin.zig file: {s}", .{@errorName(err)});
1628 };1628 };
1629 },1629 },
1630 .stage1_module => {1630 .stage1_module => {
...@@ -1704,11 +1704,11 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -1704,11 +1704,11 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
1704 const out_h_path = try comp.local_cache_directory.join(arena, &[_][]const u8{1704 const out_h_path = try comp.local_cache_directory.join(arena, &[_][]const u8{
1705 tmp_dir_sub_path, cimport_basename,1705 tmp_dir_sub_path, cimport_basename,
1706 });1706 });
1707 const out_dep_path = try std.fmt.allocPrint(arena, "{}.d", .{out_h_path});1707 const out_dep_path = try std.fmt.allocPrint(arena, "{s}.d", .{out_h_path});
17081708
1709 try zig_cache_tmp_dir.writeFile(cimport_basename, c_src);1709 try zig_cache_tmp_dir.writeFile(cimport_basename, c_src);
1710 if (comp.verbose_cimport) {1710 if (comp.verbose_cimport) {
1711 log.info("C import source: {}", .{out_h_path});1711 log.info("C import source: {s}", .{out_h_path});
1712 }1712 }
17131713
1714 var argv = std.ArrayList([]const u8).init(comp.gpa);1714 var argv = std.ArrayList([]const u8).init(comp.gpa);
...@@ -1755,7 +1755,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -1755,7 +1755,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
1755 defer tree.deinit();1755 defer tree.deinit();
17561756
1757 if (comp.verbose_cimport) {1757 if (comp.verbose_cimport) {
1758 log.info("C import .d file: {}", .{out_dep_path});1758 log.info("C import .d file: {s}", .{out_dep_path});
1759 }1759 }
17601760
1761 const dep_basename = std.fs.path.basename(out_dep_path);1761 const dep_basename = std.fs.path.basename(out_dep_path);
...@@ -1775,7 +1775,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -1775,7 +1775,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
1775 try bos.flush();1775 try bos.flush();
17761776
1777 man.writeManifest() catch |err| {1777 man.writeManifest() catch |err| {
1778 log.warn("failed to write cache manifest for C import: {}", .{@errorName(err)});1778 log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)});
1779 };1779 };
17801780
1781 break :digest digest;1781 break :digest digest;
...@@ -1785,7 +1785,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -1785,7 +1785,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
1785 "o", &digest, cimport_zig_basename,1785 "o", &digest, cimport_zig_basename,
1786 });1786 });
1787 if (comp.verbose_cimport) {1787 if (comp.verbose_cimport) {
1788 log.info("C import output: {}\n", .{out_zig_path});1788 log.info("C import output: {s}\n", .{out_zig_path});
1789 }1789 }
1790 return CImportResult{1790 return CImportResult{
1791 .out_zig_path = out_zig_path,1791 .out_zig_path = out_zig_path,
...@@ -1946,7 +1946,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *...@@ -1946,7 +1946,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
1946 child.stderr_behavior = .Inherit;1946 child.stderr_behavior = .Inherit;
19471947
1948 const term = child.spawnAndWait() catch |err| {1948 const term = child.spawnAndWait() catch |err| {
1949 return comp.failCObj(c_object, "unable to spawn {}: {}", .{ argv.items[0], @errorName(err) });1949 return comp.failCObj(c_object, "unable to spawn {s}: {s}", .{ argv.items[0], @errorName(err) });
1950 };1950 };
1951 switch (term) {1951 switch (term) {
1952 .Exited => |code| {1952 .Exited => |code| {
...@@ -1974,7 +1974,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *...@@ -1974,7 +1974,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
1974 const stderr = try stderr_reader.readAllAlloc(arena, 10 * 1024 * 1024);1974 const stderr = try stderr_reader.readAllAlloc(arena, 10 * 1024 * 1024);
19751975
1976 const term = child.wait() catch |err| {1976 const term = child.wait() catch |err| {
1977 return comp.failCObj(c_object, "unable to spawn {}: {}", .{ argv.items[0], @errorName(err) });1977 return comp.failCObj(c_object, "unable to spawn {s}: {s}", .{ argv.items[0], @errorName(err) });
1978 };1978 };
19791979
1980 switch (term) {1980 switch (term) {
...@@ -1982,12 +1982,12 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *...@@ -1982,12 +1982,12 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
1982 if (code != 0) {1982 if (code != 0) {
1983 // TODO parse clang stderr and turn it into an error message1983 // TODO parse clang stderr and turn it into an error message
1984 // and then call failCObjWithOwnedErrorMsg1984 // and then call failCObjWithOwnedErrorMsg
1985 log.err("clang failed with stderr: {}", .{stderr});1985 log.err("clang failed with stderr: {s}", .{stderr});
1986 return comp.failCObj(c_object, "clang exited with code {}", .{code});1986 return comp.failCObj(c_object, "clang exited with code {}", .{code});
1987 }1987 }
1988 },1988 },
1989 else => {1989 else => {
1990 log.err("clang terminated with stderr: {}", .{stderr});1990 log.err("clang terminated with stderr: {s}", .{stderr});
1991 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});1991 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});
1992 },1992 },
1993 }1993 }
...@@ -1999,7 +1999,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *...@@ -1999,7 +1999,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
1999 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);1999 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
2000 // Just to save disk space, we delete the file because it is never needed again.2000 // Just to save disk space, we delete the file because it is never needed again.
2001 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {2001 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
2002 log.warn("failed to delete '{}': {}", .{ dep_file_path, @errorName(err) });2002 log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
2003 };2003 };
2004 }2004 }
20052005
...@@ -2015,7 +2015,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *...@@ -2015,7 +2015,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
2015 try std.fs.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename);2015 try std.fs.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename);
20162016
2017 man.writeManifest() catch |err| {2017 man.writeManifest() catch |err| {
2018 log.warn("failed to write cache manifest when compiling '{}': {}", .{ c_object.src.src_path, @errorName(err) });2018 log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) });
2019 };2019 };
2020 break :blk digest;2020 break :blk digest;
2021 };2021 };
...@@ -2034,7 +2034,7 @@ pub fn tmpFilePath(comp: *Compilation, arena: *Allocator, suffix: []const u8) er...@@ -2034,7 +2034,7 @@ pub fn tmpFilePath(comp: *Compilation, arena: *Allocator, suffix: []const u8) er
2034 const s = std.fs.path.sep_str;2034 const s = std.fs.path.sep_str;
2035 const rand_int = std.crypto.random.int(u64);2035 const rand_int = std.crypto.random.int(u64);
2036 if (comp.local_cache_directory.path) |p| {2036 if (comp.local_cache_directory.path) |p| {
2037 return std.fmt.allocPrint(arena, "{}" ++ s ++ "tmp" ++ s ++ "{x}-{s}", .{ p, rand_int, suffix });2037 return std.fmt.allocPrint(arena, "{s}" ++ s ++ "tmp" ++ s ++ "{x}-{s}", .{ p, rand_int, suffix });
2038 } else {2038 } else {
2039 return std.fmt.allocPrint(arena, "tmp" ++ s ++ "{x}-{s}", .{ rand_int, suffix });2039 return std.fmt.allocPrint(arena, "tmp" ++ s ++ "{x}-{s}", .{ rand_int, suffix });
2040 }2040 }
...@@ -2144,7 +2144,7 @@ pub fn addCCArgs(...@@ -2144,7 +2144,7 @@ pub fn addCCArgs(
2144 }2144 }
2145 const mcmodel = comp.bin_file.options.machine_code_model;2145 const mcmodel = comp.bin_file.options.machine_code_model;
2146 if (mcmodel != .default) {2146 if (mcmodel != .default) {
2147 try argv.append(try std.fmt.allocPrint(arena, "-mcmodel={}", .{@tagName(mcmodel)}));2147 try argv.append(try std.fmt.allocPrint(arena, "-mcmodel={s}", .{@tagName(mcmodel)}));
2148 }2148 }
21492149
2150 switch (target.os.tag) {2150 switch (target.os.tag) {
...@@ -2497,22 +2497,22 @@ fn detectLibCIncludeDirs(...@@ -2497,22 +2497,22 @@ fn detectLibCIncludeDirs(
2497 const s = std.fs.path.sep_str;2497 const s = std.fs.path.sep_str;
2498 const arch_include_dir = try std.fmt.allocPrint(2498 const arch_include_dir = try std.fmt.allocPrint(
2499 arena,2499 arena,
2500 "{}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{}-{}-{}",2500 "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}",
2501 .{ zig_lib_dir, arch_name, os_name, abi_name },2501 .{ zig_lib_dir, arch_name, os_name, abi_name },
2502 );2502 );
2503 const generic_include_dir = try std.fmt.allocPrint(2503 const generic_include_dir = try std.fmt.allocPrint(
2504 arena,2504 arena,
2505 "{}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{}",2505 "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}",
2506 .{ zig_lib_dir, generic_name },2506 .{ zig_lib_dir, generic_name },
2507 );2507 );
2508 const arch_os_include_dir = try std.fmt.allocPrint(2508 const arch_os_include_dir = try std.fmt.allocPrint(
2509 arena,2509 arena,
2510 "{}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{}-{}-any",2510 "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any",
2511 .{ zig_lib_dir, @tagName(target.cpu.arch), os_name },2511 .{ zig_lib_dir, @tagName(target.cpu.arch), os_name },
2512 );2512 );
2513 const generic_os_include_dir = try std.fmt.allocPrint(2513 const generic_os_include_dir = try std.fmt.allocPrint(
2514 arena,2514 arena,
2515 "{}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{}-any",2515 "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any",
2516 .{ zig_lib_dir, os_name },2516 .{ zig_lib_dir, os_name },
2517 );2517 );
25182518
...@@ -2631,9 +2631,9 @@ fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) !void {...@@ -2631,9 +2631,9 @@ fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) !void {
26312631
2632pub fn dump_argv(argv: []const []const u8) void {2632pub fn dump_argv(argv: []const []const u8) void {
2633 for (argv[0 .. argv.len - 1]) |arg| {2633 for (argv[0 .. argv.len - 1]) |arg| {
2634 std.debug.print("{} ", .{arg});2634 std.debug.print("{s} ", .{arg});
2635 }2635 }
2636 std.debug.print("{}\n", .{argv[argv.len - 1]});2636 std.debug.print("{s}\n", .{argv[argv.len - 1]});
2637}2637}
26382638
2639pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 {2639pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 {
...@@ -2653,15 +2653,15 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8...@@ -2653,15 +2653,15 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
2653 \\pub const arch = Target.current.cpu.arch;2653 \\pub const arch = Target.current.cpu.arch;
2654 \\/// Deprecated2654 \\/// Deprecated
2655 \\pub const endian = Target.current.cpu.arch.endian();2655 \\pub const endian = Target.current.cpu.arch.endian();
2656 \\pub const output_mode = OutputMode.{};2656 \\pub const output_mode = OutputMode.{s};
2657 \\pub const link_mode = LinkMode.{};2657 \\pub const link_mode = LinkMode.{s};
2658 \\pub const is_test = {};2658 \\pub const is_test = {};
2659 \\pub const single_threaded = {};2659 \\pub const single_threaded = {};
2660 \\pub const abi = Abi.{};2660 \\pub const abi = Abi.{s};
2661 \\pub const cpu: Cpu = Cpu{{2661 \\pub const cpu: Cpu = Cpu{{
2662 \\ .arch = .{},2662 \\ .arch = .{s},
2663 \\ .model = &Target.{}.cpu.{},2663 \\ .model = &Target.{s}.cpu.{s},
2664 \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{2664 \\ .features = Target.{s}.featureSet(&[_]Target.{s}.Feature{{
2665 \\2665 \\
2666 , .{2666 , .{
2667 @tagName(comp.bin_file.options.output_mode),2667 @tagName(comp.bin_file.options.output_mode),
...@@ -2692,7 +2692,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8...@@ -2692,7 +2692,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
2692 \\ }}),2692 \\ }}),
2693 \\}};2693 \\}};
2694 \\pub const os = Os{{2694 \\pub const os = Os{{
2695 \\ .tag = .{},2695 \\ .tag = .{s},
2696 \\ .version_range = .{{2696 \\ .version_range = .{{
2697 ,2697 ,
2698 .{@tagName(target.os.tag)},2698 .{@tagName(target.os.tag)},
...@@ -2778,8 +2778,8 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8...@@ -2778,8 +2778,8 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
2778 (comp.bin_file.options.skip_linker_dependencies and comp.bin_file.options.parent_compilation_link_libc);2778 (comp.bin_file.options.skip_linker_dependencies and comp.bin_file.options.parent_compilation_link_libc);
27792779
2780 try buffer.writer().print(2780 try buffer.writer().print(
2781 \\pub const object_format = ObjectFormat.{};2781 \\pub const object_format = ObjectFormat.{s};
2782 \\pub const mode = Mode.{};2782 \\pub const mode = Mode.{s};
2783 \\pub const link_libc = {};2783 \\pub const link_libc = {};
2784 \\pub const link_libcpp = {};2784 \\pub const link_libcpp = {};
2785 \\pub const have_error_return_tracing = {};2785 \\pub const have_error_return_tracing = {};
...@@ -2787,7 +2787,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8...@@ -2787,7 +2787,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
2787 \\pub const position_independent_code = {};2787 \\pub const position_independent_code = {};
2788 \\pub const position_independent_executable = {};2788 \\pub const position_independent_executable = {};
2789 \\pub const strip_debug_info = {};2789 \\pub const strip_debug_info = {};
2790 \\pub const code_model = CodeModel.{};2790 \\pub const code_model = CodeModel.{s};
2791 \\2791 \\
2792 , .{2792 , .{
2793 @tagName(comp.bin_file.options.object_format),2793 @tagName(comp.bin_file.options.object_format),
...@@ -3013,7 +3013,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -3013,7 +3013,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3013 id_symlink_basename,3013 id_symlink_basename,
3014 &prev_digest_buf,3014 &prev_digest_buf,
3015 ) catch |err| blk: {3015 ) catch |err| blk: {
3016 log.debug("stage1 {} new_digest={} error: {}", .{ mod.root_pkg.root_src_path, digest, @errorName(err) });3016 log.debug("stage1 {} new_digest={} error: {s}", .{ mod.root_pkg.root_src_path, digest, @errorName(err) });
3017 // Handle this as a cache miss.3017 // Handle this as a cache miss.
3018 break :blk prev_digest_buf[0..0];3018 break :blk prev_digest_buf[0..0];
3019 };3019 };
...@@ -3189,7 +3189,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -3189,7 +3189,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3189 // Update the small file with the digest. If it fails we can continue; it only3189 // Update the small file with the digest. If it fails we can continue; it only
3190 // means that the next invocation will have an unnecessary cache miss.3190 // means that the next invocation will have an unnecessary cache miss.
3191 const stage1_flags_byte = @bitCast(u8, mod.stage1_flags);3191 const stage1_flags_byte = @bitCast(u8, mod.stage1_flags);
3192 log.debug("stage1 {} final digest={} flags={x}", .{3192 log.debug("stage1 {s} final digest={} flags={x}", .{
3193 mod.root_pkg.root_src_path, digest, stage1_flags_byte,3193 mod.root_pkg.root_src_path, digest, stage1_flags_byte,
3194 });3194 });
3195 var digest_plus_flags: [digest.len + 2]u8 = undefined;3195 var digest_plus_flags: [digest.len + 2]u8 = undefined;
...@@ -3202,11 +3202,11 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -3202,11 +3202,11 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3202 digest_plus_flags, stage1_flags_byte, mod.stage1_flags.have_winmain_crt_startup,3202 digest_plus_flags, stage1_flags_byte, mod.stage1_flags.have_winmain_crt_startup,
3203 });3203 });
3204 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest_plus_flags) catch |err| {3204 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest_plus_flags) catch |err| {
3205 log.warn("failed to save stage1 hash digest file: {}", .{@errorName(err)});3205 log.warn("failed to save stage1 hash digest file: {s}", .{@errorName(err)});
3206 };3206 };
3207 // Failure here only means an unnecessary cache miss.3207 // Failure here only means an unnecessary cache miss.
3208 man.writeManifest() catch |err| {3208 man.writeManifest() catch |err| {
3209 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});3209 log.warn("failed to write cache manifest when linking: {s}", .{@errorName(err)});
3210 };3210 };
3211 // We hang on to this lock so that the output file path can be used without3211 // We hang on to this lock so that the output file path can be used without
3212 // other processes clobbering it.3212 // other processes clobbering it.
src/DepTokenizer.zig+3-3
...@@ -366,7 +366,7 @@ pub const Token = union(enum) {...@@ -366,7 +366,7 @@ pub const Token = union(enum) {
366 .incomplete_quoted_prerequisite,366 .incomplete_quoted_prerequisite,
367 .incomplete_target,367 .incomplete_target,
368 => |index_and_bytes| {368 => |index_and_bytes| {
369 try writer.print("{} '", .{self.errStr()});369 try writer.print("{s} '", .{self.errStr()});
370 if (self == .incomplete_target) {370 if (self == .incomplete_target) {
371 const tmp = Token{ .target_must_resolve = index_and_bytes.bytes };371 const tmp = Token{ .target_must_resolve = index_and_bytes.bytes };
372 try tmp.resolve(writer);372 try tmp.resolve(writer);
...@@ -383,7 +383,7 @@ pub const Token = union(enum) {...@@ -383,7 +383,7 @@ pub const Token = union(enum) {
383 => |index_and_char| {383 => |index_and_char| {
384 try writer.writeAll("illegal char ");384 try writer.writeAll("illegal char ");
385 try printUnderstandableChar(writer, index_and_char.char);385 try printUnderstandableChar(writer, index_and_char.char);
386 try writer.print(" at position {}: {}", .{ index_and_char.index, self.errStr() });386 try writer.print(" at position {}: {s}", .{ index_and_char.index, self.errStr() });
387 },387 },
388 }388 }
389 }389 }
...@@ -943,7 +943,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {...@@ -943,7 +943,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
943943
944fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {944fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
945 var buf: [80]u8 = undefined;945 var buf: [80]u8 = undefined;
946 var text = try std.fmt.bufPrint(buf[0..], "{} {} bytes ", .{ label, bytes.len });946 var text = try std.fmt.bufPrint(buf[0..], "{s} {} bytes ", .{ label, bytes.len });
947 try out.writeAll(text);947 try out.writeAll(text);
948 var i: usize = text.len;948 var i: usize = text.len;
949 const end = 79;949 const end = 79;
src/Module.zig+8-8
...@@ -953,7 +953,7 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {...@@ -953,7 +953,7 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {
953 self.failed_decls.putAssumeCapacityNoClobber(decl, try Compilation.ErrorMsg.create(953 self.failed_decls.putAssumeCapacityNoClobber(decl, try Compilation.ErrorMsg.create(
954 self.gpa,954 self.gpa,
955 decl.src(),955 decl.src(),
956 "unable to analyze: {}",956 "unable to analyze: {s}",
957 .{@errorName(err)},957 .{@errorName(err)},
958 ));958 ));
959 decl.analysis = .sema_failure_retryable;959 decl.analysis = .sema_failure_retryable;
...@@ -1475,7 +1475,7 @@ fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module {...@@ -1475,7 +1475,7 @@ fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module {
1475 if (zir_module.error_msg) |src_err_msg| {1475 if (zir_module.error_msg) |src_err_msg| {
1476 self.failed_files.putAssumeCapacityNoClobber(1476 self.failed_files.putAssumeCapacityNoClobber(
1477 &root_scope.base,1477 &root_scope.base,
1478 try Compilation.ErrorMsg.create(self.gpa, src_err_msg.byte_offset, "{}", .{src_err_msg.msg}),1478 try Compilation.ErrorMsg.create(self.gpa, src_err_msg.byte_offset, "{s}", .{src_err_msg.msg}),
1479 );1479 );
1480 root_scope.status = .unloaded_parse_failure;1480 root_scope.status = .unloaded_parse_failure;
1481 return error.AnalysisFail;1481 return error.AnalysisFail;
...@@ -1581,7 +1581,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void...@@ -1581,7 +1581,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void
1581 decl.src_index = decl_i;1581 decl.src_index = decl_i;
1582 if (deleted_decls.remove(decl) == null) {1582 if (deleted_decls.remove(decl) == null) {
1583 decl.analysis = .sema_failure;1583 decl.analysis = .sema_failure;
1584 const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name});1584 const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{s}'", .{decl.name});
1585 errdefer err_msg.destroy(self.gpa);1585 errdefer err_msg.destroy(self.gpa);
1586 try self.failed_decls.putNoClobber(self.gpa, decl, err_msg);1586 try self.failed_decls.putNoClobber(self.gpa, decl, err_msg);
1587 } else {1587 } else {
...@@ -1623,7 +1623,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void...@@ -1623,7 +1623,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void
1623 decl.src_index = decl_i;1623 decl.src_index = decl_i;
1624 if (deleted_decls.remove(decl) == null) {1624 if (deleted_decls.remove(decl) == null) {
1625 decl.analysis = .sema_failure;1625 decl.analysis = .sema_failure;
1626 const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{}'", .{decl.name});1626 const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{s}'", .{decl.name});
1627 errdefer err_msg.destroy(self.gpa);1627 errdefer err_msg.destroy(self.gpa);
1628 try self.failed_decls.putNoClobber(self.gpa, decl, err_msg);1628 try self.failed_decls.putNoClobber(self.gpa, decl, err_msg);
1629 } else if (!srcHashEql(decl.contents_hash, contents_hash)) {1629 } else if (!srcHashEql(decl.contents_hash, contents_hash)) {
...@@ -1991,7 +1991,7 @@ pub fn analyzeExport(...@@ -1991,7 +1991,7 @@ pub fn analyzeExport(
1991 self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(1991 self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(
1992 self.gpa,1992 self.gpa,
1993 src,1993 src,
1994 "exported symbol collision: {}",1994 "exported symbol collision: {s}",
1995 .{symbol_name},1995 .{symbol_name},
1996 ));1996 ));
1997 // TODO: add a note1997 // TODO: add a note
...@@ -2007,7 +2007,7 @@ pub fn analyzeExport(...@@ -2007,7 +2007,7 @@ pub fn analyzeExport(
2007 self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(2007 self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(
2008 self.gpa,2008 self.gpa,
2009 src,2009 src,
2010 "unable to export: {}",2010 "unable to export: {s}",
2011 .{@errorName(err)},2011 .{@errorName(err)},
2012 ));2012 ));
2013 new_export.status = .failed_retryable;2013 new_export.status = .failed_retryable;
...@@ -2277,7 +2277,7 @@ pub fn createAnonymousDecl(...@@ -2277,7 +2277,7 @@ pub fn createAnonymousDecl(
2277) !*Decl {2277) !*Decl {
2278 const name_index = self.getNextAnonNameIndex();2278 const name_index = self.getNextAnonNameIndex();
2279 const scope_decl = scope.decl().?;2279 const scope_decl = scope.decl().?;
2280 const name = try std.fmt.allocPrint(self.gpa, "{}__anon_{}", .{ scope_decl.name, name_index });2280 const name = try std.fmt.allocPrint(self.gpa, "{s}__anon_{}", .{ scope_decl.name, name_index });
2281 defer self.gpa.free(name);2281 defer self.gpa.free(name);
2282 const name_hash = scope.namespace().fullyQualifiedNameHash(name);2282 const name_hash = scope.namespace().fullyQualifiedNameHash(name);
2283 const src_hash: std.zig.SrcHash = undefined;2283 const src_hash: std.zig.SrcHash = undefined;
...@@ -2384,7 +2384,7 @@ pub fn analyzeDeref(self: *Module, scope: *Scope, src: usize, ptr: *Inst, ptr_sr...@@ -2384,7 +2384,7 @@ pub fn analyzeDeref(self: *Module, scope: *Scope, src: usize, ptr: *Inst, ptr_sr
23842384
2385pub fn analyzeDeclRefByName(self: *Module, scope: *Scope, src: usize, decl_name: []const u8) InnerError!*Inst {2385pub fn analyzeDeclRefByName(self: *Module, scope: *Scope, src: usize, decl_name: []const u8) InnerError!*Inst {
2386 const decl = self.lookupDeclName(scope, decl_name) orelse2386 const decl = self.lookupDeclName(scope, decl_name) orelse
2387 return self.fail(scope, src, "decl '{}' not found", .{decl_name});2387 return self.fail(scope, src, "decl '{s}' not found", .{decl_name});
2388 return self.analyzeDeclRef(scope, src, decl);2388 return self.analyzeDeclRef(scope, src, decl);
2389}2389}
23902390
src/astgen.zig+4-4
...@@ -1955,7 +1955,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -1955,7 +1955,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
1955 error.Overflow => return mod.failNode(1955 error.Overflow => return mod.failNode(
1956 scope,1956 scope,
1957 &ident.base,1957 &ident.base,
1958 "primitive integer type '{}' exceeds maximum bit width of 65535",1958 "primitive integer type '{s}' exceeds maximum bit width of 65535",
1959 .{ident_name},1959 .{ident_name},
1960 ),1960 ),
1961 error.InvalidCharacter => break :integer,1961 error.InvalidCharacter => break :integer,
...@@ -2010,7 +2010,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2010,7 +2010,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
2010 return rlWrapPtr(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclValInModule, .{ .decl = decl }, .{}));2010 return rlWrapPtr(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclValInModule, .{ .decl = decl }, .{}));
2011 }2011 }
20122012
2013 return mod.failNode(scope, &ident.base, "use of undeclared identifier '{}'", .{ident_name});2013 return mod.failNode(scope, &ident.base, "use of undeclared identifier '{s}'", .{ident_name});
2014}2014}
20152015
2016fn stringLiteral(mod: *Module, scope: *Scope, str_lit: *ast.Node.OneToken) InnerError!*zir.Inst {2016fn stringLiteral(mod: *Module, scope: *Scope, str_lit: *ast.Node.OneToken) InnerError!*zir.Inst {
...@@ -2204,7 +2204,7 @@ fn ensureBuiltinParamCount(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinC...@@ -2204,7 +2204,7 @@ fn ensureBuiltinParamCount(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinC
2204 return;2204 return;
22052205
2206 const s = if (count == 1) "" else "s";2206 const s = if (count == 1) "" else "s";
2207 return mod.failTok(scope, call.builtin_token, "expected {} parameter{}, found {}", .{ count, s, call.params_len });2207 return mod.failTok(scope, call.builtin_token, "expected {} parameter{s}, found {}", .{ count, s, call.params_len });
2208}2208}
22092209
2210fn simpleCast(2210fn simpleCast(
...@@ -2383,7 +2383,7 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built...@@ -2383,7 +2383,7 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built
2383 } else if (mem.eql(u8, builtin_name, "@compileError")) {2383 } else if (mem.eql(u8, builtin_name, "@compileError")) {
2384 return compileError(mod, scope, call);2384 return compileError(mod, scope, call);
2385 } else {2385 } else {
2386 return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{}'", .{builtin_name});2386 return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{s}'", .{builtin_name});
2387 }2387 }
2388}2388}
23892389
src/codegen.zig+19-19
...@@ -228,7 +228,7 @@ pub fn generateSymbol(...@@ -228,7 +228,7 @@ pub fn generateSymbol(
228 .fail = try ErrorMsg.create(228 .fail = try ErrorMsg.create(
229 bin_file.allocator,229 bin_file.allocator,
230 src,230 src,
231 "TODO implement generateSymbol for type '{}'",231 "TODO implement generateSymbol for type '{s}'",
232 .{@tagName(t)},232 .{@tagName(t)},
233 ),233 ),
234 };234 };
...@@ -2029,7 +2029,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2029,7 +2029,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2029 });2029 });
2030 break :blk 0x84;2030 break :blk 0x84;
2031 },2031 },
2032 else => return self.fail(inst.base.src, "TODO implement condbr {} when condition is {}", .{ self.target.cpu.arch, @tagName(cond) }),2032 else => return self.fail(inst.base.src, "TODO implement condbr {s} when condition is {s}", .{ self.target.cpu.arch, @tagName(cond) }),
2033 };2033 };
2034 self.code.appendSliceAssumeCapacity(&[_]u8{ 0x0f, opcode });2034 self.code.appendSliceAssumeCapacity(&[_]u8{ 0x0f, opcode });
2035 const reloc = Reloc{ .rel32 = self.code.items.len };2035 const reloc = Reloc{ .rel32 = self.code.items.len };
...@@ -2376,11 +2376,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2376,11 +2376,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2376 .arm, .armeb => {2376 .arm, .armeb => {
2377 for (inst.inputs) |input, i| {2377 for (inst.inputs) |input, i| {
2378 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {2378 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2379 return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});2379 return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
2380 }2380 }
2381 const reg_name = input[1 .. input.len - 1];2381 const reg_name = input[1 .. input.len - 1];
2382 const reg = parseRegName(reg_name) orelse2382 const reg = parseRegName(reg_name) orelse
2383 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2383 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2384 const arg = try self.resolveInst(inst.args[i]);2384 const arg = try self.resolveInst(inst.args[i]);
2385 try self.genSetReg(inst.base.src, reg, arg);2385 try self.genSetReg(inst.base.src, reg, arg);
2386 }2386 }
...@@ -2393,11 +2393,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2393,11 +2393,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
23932393
2394 if (inst.output) |output| {2394 if (inst.output) |output| {
2395 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {2395 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2396 return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});2396 return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
2397 }2397 }
2398 const reg_name = output[2 .. output.len - 1];2398 const reg_name = output[2 .. output.len - 1];
2399 const reg = parseRegName(reg_name) orelse2399 const reg = parseRegName(reg_name) orelse
2400 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2400 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2401 return MCValue{ .register = reg };2401 return MCValue{ .register = reg };
2402 } else {2402 } else {
2403 return MCValue.none;2403 return MCValue.none;
...@@ -2406,11 +2406,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2406,11 +2406,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2406 .aarch64 => {2406 .aarch64 => {
2407 for (inst.inputs) |input, i| {2407 for (inst.inputs) |input, i| {
2408 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {2408 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2409 return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});2409 return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
2410 }2410 }
2411 const reg_name = input[1 .. input.len - 1];2411 const reg_name = input[1 .. input.len - 1];
2412 const reg = parseRegName(reg_name) orelse2412 const reg = parseRegName(reg_name) orelse
2413 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2413 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2414 const arg = try self.resolveInst(inst.args[i]);2414 const arg = try self.resolveInst(inst.args[i]);
2415 try self.genSetReg(inst.base.src, reg, arg);2415 try self.genSetReg(inst.base.src, reg, arg);
2416 }2416 }
...@@ -2425,11 +2425,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2425,11 +2425,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24252425
2426 if (inst.output) |output| {2426 if (inst.output) |output| {
2427 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {2427 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2428 return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});2428 return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
2429 }2429 }
2430 const reg_name = output[2 .. output.len - 1];2430 const reg_name = output[2 .. output.len - 1];
2431 const reg = parseRegName(reg_name) orelse2431 const reg = parseRegName(reg_name) orelse
2432 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2432 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2433 return MCValue{ .register = reg };2433 return MCValue{ .register = reg };
2434 } else {2434 } else {
2435 return MCValue.none;2435 return MCValue.none;
...@@ -2438,11 +2438,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2438,11 +2438,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2438 .riscv64 => {2438 .riscv64 => {
2439 for (inst.inputs) |input, i| {2439 for (inst.inputs) |input, i| {
2440 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {2440 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2441 return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});2441 return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
2442 }2442 }
2443 const reg_name = input[1 .. input.len - 1];2443 const reg_name = input[1 .. input.len - 1];
2444 const reg = parseRegName(reg_name) orelse2444 const reg = parseRegName(reg_name) orelse
2445 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2445 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2446 const arg = try self.resolveInst(inst.args[i]);2446 const arg = try self.resolveInst(inst.args[i]);
2447 try self.genSetReg(inst.base.src, reg, arg);2447 try self.genSetReg(inst.base.src, reg, arg);
2448 }2448 }
...@@ -2455,11 +2455,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2455,11 +2455,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24552455
2456 if (inst.output) |output| {2456 if (inst.output) |output| {
2457 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {2457 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2458 return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});2458 return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
2459 }2459 }
2460 const reg_name = output[2 .. output.len - 1];2460 const reg_name = output[2 .. output.len - 1];
2461 const reg = parseRegName(reg_name) orelse2461 const reg = parseRegName(reg_name) orelse
2462 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2462 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2463 return MCValue{ .register = reg };2463 return MCValue{ .register = reg };
2464 } else {2464 } else {
2465 return MCValue.none;2465 return MCValue.none;
...@@ -2468,11 +2468,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2468,11 +2468,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2468 .x86_64, .i386 => {2468 .x86_64, .i386 => {
2469 for (inst.inputs) |input, i| {2469 for (inst.inputs) |input, i| {
2470 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {2470 if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2471 return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});2471 return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
2472 }2472 }
2473 const reg_name = input[1 .. input.len - 1];2473 const reg_name = input[1 .. input.len - 1];
2474 const reg = parseRegName(reg_name) orelse2474 const reg = parseRegName(reg_name) orelse
2475 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2475 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2476 const arg = try self.resolveInst(inst.args[i]);2476 const arg = try self.resolveInst(inst.args[i]);
2477 try self.genSetReg(inst.base.src, reg, arg);2477 try self.genSetReg(inst.base.src, reg, arg);
2478 }2478 }
...@@ -2485,11 +2485,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2485,11 +2485,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24852485
2486 if (inst.output) |output| {2486 if (inst.output) |output| {
2487 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {2487 if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2488 return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});2488 return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
2489 }2489 }
2490 const reg_name = output[2 .. output.len - 1];2490 const reg_name = output[2 .. output.len - 1];
2491 const reg = parseRegName(reg_name) orelse2491 const reg = parseRegName(reg_name) orelse
2492 return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});2492 return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
2493 return MCValue{ .register = reg };2493 return MCValue{ .register = reg };
2494 } else {2494 } else {
2495 return MCValue.none;2495 return MCValue.none;
...@@ -3417,7 +3417,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3417,7 +3417,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3417 next_int_reg += 1;3417 next_int_reg += 1;
3418 }3418 }
3419 },3419 },
3420 else => return self.fail(src, "TODO implement function parameters of type {}", .{@tagName(ty.zigTypeTag())}),3420 else => return self.fail(src, "TODO implement function parameters of type {s}", .{@tagName(ty.zigTypeTag())}),
3421 }3421 }
3422 }3422 }
3423 result.stack_byte_count = next_stack_offset;3423 result.stack_byte_count = next_stack_offset;
src/codegen/c.zig+8-7
...@@ -235,7 +235,7 @@ fn renderFunctionSignature(...@@ -235,7 +235,7 @@ fn renderFunctionSignature(
235 try writer.writeAll(", ");235 try writer.writeAll(", ");
236 }236 }
237 try renderType(ctx, writer, tv.ty.fnParamType(index));237 try renderType(ctx, writer, tv.ty.fnParamType(index));
238 try writer.print(" arg{}", .{index});238 try writer.print(" arg{d}", .{index});
239 }239 }
240 }240 }
241 try writer.writeByte(')');241 try writer.writeByte(')');
...@@ -481,8 +481,9 @@ fn genBinOp(ctx: *Context, file: *C, inst: *Inst.BinOp, operator: []const u8) !?...@@ -481,8 +481,9 @@ fn genBinOp(ctx: *Context, file: *C, inst: *Inst.BinOp, operator: []const u8) !?
481 const rhs = try ctx.resolveInst(inst.rhs);481 const rhs = try ctx.resolveInst(inst.rhs);
482 const writer = file.main.writer();482 const writer = file.main.writer();
483 const name = try ctx.name();483 const name = try ctx.name();
484 try renderTypeAndName(ctx, writer, inst.base.ty, name, .Const);484 try writer.writeAll(indentation ++ "const ");
485 try writer.print(" = {s} {s} {s};\n", .{ lhs, operator, rhs });485 try renderType(ctx, writer, inst.base.ty);
486 try writer.print(" {s} = {s} " ++ operator ++ " {s};\n", .{ name, lhs, rhs });
486 return name;487 return name;
487}488}
488489
...@@ -587,7 +588,7 @@ fn genAsm(ctx: *Context, file: *C, as: *Inst.Assembly) !?[]u8 {...@@ -587,7 +588,7 @@ fn genAsm(ctx: *Context, file: *C, as: *Inst.Assembly) !?[]u8 {
587 const arg = as.args[index];588 const arg = as.args[index];
588 try writer.writeAll("register ");589 try writer.writeAll("register ");
589 try renderType(ctx, writer, arg.ty);590 try renderType(ctx, writer, arg.ty);
590 try writer.print(" {}_constant __asm__(\"{}\") = ", .{ reg, reg });591 try writer.print(" {s}_constant __asm__(\"{s}\") = ", .{ reg, reg });
591 // TODO merge constant handling into inst_map as well592 // TODO merge constant handling into inst_map as well
592 if (arg.castTag(.constant)) |c| {593 if (arg.castTag(.constant)) |c| {
593 try renderValue(ctx, writer, arg.ty, c.val);594 try renderValue(ctx, writer, arg.ty, c.val);
...@@ -597,13 +598,13 @@ fn genAsm(ctx: *Context, file: *C, as: *Inst.Assembly) !?[]u8 {...@@ -597,13 +598,13 @@ fn genAsm(ctx: *Context, file: *C, as: *Inst.Assembly) !?[]u8 {
597 if (!gop.found_existing) {598 if (!gop.found_existing) {
598 return ctx.fail(ctx.decl.src(), "Internal error in C backend: asm argument not found in inst_map", .{});599 return ctx.fail(ctx.decl.src(), "Internal error in C backend: asm argument not found in inst_map", .{});
599 }600 }
600 try writer.print("{};\n ", .{gop.entry.value});601 try writer.print("{s};\n ", .{gop.entry.value});
601 }602 }
602 } else {603 } else {
603 return ctx.fail(ctx.decl.src(), "TODO non-explicit inline asm regs", .{});604 return ctx.fail(ctx.decl.src(), "TODO non-explicit inline asm regs", .{});
604 }605 }
605 }606 }
606 try writer.print("__asm {} (\"{}\"", .{ if (as.is_volatile) @as([]const u8, "volatile") else "", as.asm_source });607 try writer.print("__asm {s} (\"{s}\"", .{ if (as.is_volatile) @as([]const u8, "volatile") else "", as.asm_source });
607 if (as.output) |o| {608 if (as.output) |o| {
608 return ctx.fail(ctx.decl.src(), "TODO inline asm output", .{});609 return ctx.fail(ctx.decl.src(), "TODO inline asm output", .{});
609 }610 }
...@@ -619,7 +620,7 @@ fn genAsm(ctx: *Context, file: *C, as: *Inst.Assembly) !?[]u8 {...@@ -619,7 +620,7 @@ fn genAsm(ctx: *Context, file: *C, as: *Inst.Assembly) !?[]u8 {
619 if (index > 0) {620 if (index > 0) {
620 try writer.writeAll(", ");621 try writer.writeAll(", ");
621 }622 }
622 try writer.print("\"\"({}_constant)", .{reg});623 try writer.print("\"\"({s}_constant)", .{reg});
623 } else {624 } else {
624 // This is blocked by the earlier test625 // This is blocked by the earlier test
625 unreachable;626 unreachable;
src/codegen/llvm.zig created+125
...@@ -0,0 +1,125 @@
1const std = @import("std");
2const Allocator = std.mem.Allocator;
3
4pub fn targetTriple(allocator: *Allocator, target: std.Target) ![]u8 {
5 const llvm_arch = switch (target.cpu.arch) {
6 .arm => "arm",
7 .armeb => "armeb",
8 .aarch64 => "aarch64",
9 .aarch64_be => "aarch64_be",
10 .aarch64_32 => "aarch64_32",
11 .arc => "arc",
12 .avr => "avr",
13 .bpfel => "bpfel",
14 .bpfeb => "bpfeb",
15 .hexagon => "hexagon",
16 .mips => "mips",
17 .mipsel => "mipsel",
18 .mips64 => "mips64",
19 .mips64el => "mips64el",
20 .msp430 => "msp430",
21 .powerpc => "powerpc",
22 .powerpc64 => "powerpc64",
23 .powerpc64le => "powerpc64le",
24 .r600 => "r600",
25 .amdgcn => "amdgcn",
26 .riscv32 => "riscv32",
27 .riscv64 => "riscv64",
28 .sparc => "sparc",
29 .sparcv9 => "sparcv9",
30 .sparcel => "sparcel",
31 .s390x => "s390x",
32 .tce => "tce",
33 .tcele => "tcele",
34 .thumb => "thumb",
35 .thumbeb => "thumbeb",
36 .i386 => "i386",
37 .x86_64 => "x86_64",
38 .xcore => "xcore",
39 .nvptx => "nvptx",
40 .nvptx64 => "nvptx64",
41 .le32 => "le32",
42 .le64 => "le64",
43 .amdil => "amdil",
44 .amdil64 => "amdil64",
45 .hsail => "hsail",
46 .hsail64 => "hsail64",
47 .spir => "spir",
48 .spir64 => "spir64",
49 .kalimba => "kalimba",
50 .shave => "shave",
51 .lanai => "lanai",
52 .wasm32 => "wasm32",
53 .wasm64 => "wasm64",
54 .renderscript32 => "renderscript32",
55 .renderscript64 => "renderscript64",
56 .ve => "ve",
57 .spu_2 => return error.LLVMBackendDoesNotSupportSPUMarkII,
58 };
59 // TODO Add a sub-arch for some architectures depending on CPU features.
60
61 const llvm_os = switch (target.os.tag) {
62 .freestanding => "unknown",
63 .ananas => "ananas",
64 .cloudabi => "cloudabi",
65 .dragonfly => "dragonfly",
66 .freebsd => "freebsd",
67 .fuchsia => "fuchsia",
68 .ios => "ios",
69 .kfreebsd => "kfreebsd",
70 .linux => "linux",
71 .lv2 => "lv2",
72 .macos => "macosx",
73 .netbsd => "netbsd",
74 .openbsd => "openbsd",
75 .solaris => "solaris",
76 .windows => "windows",
77 .haiku => "haiku",
78 .minix => "minix",
79 .rtems => "rtems",
80 .nacl => "nacl",
81 .cnk => "cnk",
82 .aix => "aix",
83 .cuda => "cuda",
84 .nvcl => "nvcl",
85 .amdhsa => "amdhsa",
86 .ps4 => "ps4",
87 .elfiamcu => "elfiamcu",
88 .tvos => "tvos",
89 .watchos => "watchos",
90 .mesa3d => "mesa3d",
91 .contiki => "contiki",
92 .amdpal => "amdpal",
93 .hermit => "hermit",
94 .hurd => "hurd",
95 .wasi => "wasi",
96 .emscripten => "emscripten",
97 .uefi => "windows",
98 .other => "unknown",
99 };
100
101 const llvm_abi = switch (target.abi) {
102 .none => "unknown",
103 .gnu => "gnu",
104 .gnuabin32 => "gnuabin32",
105 .gnuabi64 => "gnuabi64",
106 .gnueabi => "gnueabi",
107 .gnueabihf => "gnueabihf",
108 .gnux32 => "gnux32",
109 .code16 => "code16",
110 .eabi => "eabi",
111 .eabihf => "eabihf",
112 .android => "android",
113 .musl => "musl",
114 .musleabi => "musleabi",
115 .musleabihf => "musleabihf",
116 .msvc => "msvc",
117 .itanium => "itanium",
118 .cygnus => "cygnus",
119 .coreclr => "coreclr",
120 .simulator => "simulator",
121 .macabi => "macabi",
122 };
123
124 return std.fmt.allocPrint(allocator, "{s}-unknown-{s}-{s}", .{ llvm_arch, llvm_os, llvm_abi });
125}
src/glibc.zig+13-13
...@@ -72,7 +72,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -72,7 +72,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
72 errdefer version_table.deinit(gpa);72 errdefer version_table.deinit(gpa);
7373
74 var glibc_dir = zig_lib_dir.openDir("libc" ++ path.sep_str ++ "glibc", .{}) catch |err| {74 var glibc_dir = zig_lib_dir.openDir("libc" ++ path.sep_str ++ "glibc", .{}) catch |err| {
75 std.log.err("unable to open glibc dir: {}", .{@errorName(err)});75 std.log.err("unable to open glibc dir: {s}", .{@errorName(err)});
76 return error.ZigInstallationCorrupt;76 return error.ZigInstallationCorrupt;
77 };77 };
78 defer glibc_dir.close();78 defer glibc_dir.close();
...@@ -81,7 +81,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -81,7 +81,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
81 const vers_txt_contents = glibc_dir.readFileAlloc(gpa, "vers.txt", max_txt_size) catch |err| switch (err) {81 const vers_txt_contents = glibc_dir.readFileAlloc(gpa, "vers.txt", max_txt_size) catch |err| switch (err) {
82 error.OutOfMemory => return error.OutOfMemory,82 error.OutOfMemory => return error.OutOfMemory,
83 else => {83 else => {
84 std.log.err("unable to read vers.txt: {}", .{@errorName(err)});84 std.log.err("unable to read vers.txt: {s}", .{@errorName(err)});
85 return error.ZigInstallationCorrupt;85 return error.ZigInstallationCorrupt;
86 },86 },
87 };87 };
...@@ -91,7 +91,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -91,7 +91,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
91 const fns_txt_contents = glibc_dir.readFileAlloc(arena, "fns.txt", max_txt_size) catch |err| switch (err) {91 const fns_txt_contents = glibc_dir.readFileAlloc(arena, "fns.txt", max_txt_size) catch |err| switch (err) {
92 error.OutOfMemory => return error.OutOfMemory,92 error.OutOfMemory => return error.OutOfMemory,
93 else => {93 else => {
94 std.log.err("unable to read fns.txt: {}", .{@errorName(err)});94 std.log.err("unable to read fns.txt: {s}", .{@errorName(err)});
95 return error.ZigInstallationCorrupt;95 return error.ZigInstallationCorrupt;
96 },96 },
97 };97 };
...@@ -99,7 +99,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -99,7 +99,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
99 const abi_txt_contents = glibc_dir.readFileAlloc(gpa, "abi.txt", max_txt_size) catch |err| switch (err) {99 const abi_txt_contents = glibc_dir.readFileAlloc(gpa, "abi.txt", max_txt_size) catch |err| switch (err) {
100 error.OutOfMemory => return error.OutOfMemory,100 error.OutOfMemory => return error.OutOfMemory,
101 else => {101 else => {
102 std.log.err("unable to read abi.txt: {}", .{@errorName(err)});102 std.log.err("unable to read abi.txt: {s}", .{@errorName(err)});
103 return error.ZigInstallationCorrupt;103 return error.ZigInstallationCorrupt;
104 },104 },
105 };105 };
...@@ -116,7 +116,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -116,7 +116,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
116 }116 }
117 const adjusted_line = line[prefix.len..];117 const adjusted_line = line[prefix.len..];
118 const ver = std.builtin.Version.parse(adjusted_line) catch |err| {118 const ver = std.builtin.Version.parse(adjusted_line) catch |err| {
119 std.log.err("vers.txt:{}: unable to parse glibc version '{}': {}", .{ line_i, line, @errorName(err) });119 std.log.err("vers.txt:{}: unable to parse glibc version '{s}': {s}", .{ line_i, line, @errorName(err) });
120 return error.ZigInstallationCorrupt;120 return error.ZigInstallationCorrupt;
121 };121 };
122 try all_versions.append(arena, ver);122 try all_versions.append(arena, ver);
...@@ -136,7 +136,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -136,7 +136,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
136 return error.ZigInstallationCorrupt;136 return error.ZigInstallationCorrupt;
137 };137 };
138 const lib = findLib(lib_name) orelse {138 const lib = findLib(lib_name) orelse {
139 std.log.err("fns.txt:{}: unknown library name: {}", .{ line_i, lib_name });139 std.log.err("fns.txt:{}: unknown library name: {s}", .{ line_i, lib_name });
140 return error.ZigInstallationCorrupt;140 return error.ZigInstallationCorrupt;
141 };141 };
142 try all_functions.append(arena, .{142 try all_functions.append(arena, .{
...@@ -170,15 +170,15 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -170,15 +170,15 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
170 return error.ZigInstallationCorrupt;170 return error.ZigInstallationCorrupt;
171 };171 };
172 const arch_tag = std.meta.stringToEnum(std.Target.Cpu.Arch, arch_name) orelse {172 const arch_tag = std.meta.stringToEnum(std.Target.Cpu.Arch, arch_name) orelse {
173 std.log.err("abi.txt:{}: unrecognized arch: '{}'", .{ line_i, arch_name });173 std.log.err("abi.txt:{}: unrecognized arch: '{s}'", .{ line_i, arch_name });
174 return error.ZigInstallationCorrupt;174 return error.ZigInstallationCorrupt;
175 };175 };
176 if (!mem.eql(u8, os_name, "linux")) {176 if (!mem.eql(u8, os_name, "linux")) {
177 std.log.err("abi.txt:{}: expected OS 'linux', found '{}'", .{ line_i, os_name });177 std.log.err("abi.txt:{}: expected OS 'linux', found '{s}'", .{ line_i, os_name });
178 return error.ZigInstallationCorrupt;178 return error.ZigInstallationCorrupt;
179 }179 }
180 const abi_tag = std.meta.stringToEnum(std.Target.Abi, abi_name) orelse {180 const abi_tag = std.meta.stringToEnum(std.Target.Abi, abi_name) orelse {
181 std.log.err("abi.txt:{}: unrecognized ABI: '{}'", .{ line_i, abi_name });181 std.log.err("abi.txt:{}: unrecognized ABI: '{s}'", .{ line_i, abi_name });
182 return error.ZigInstallationCorrupt;182 return error.ZigInstallationCorrupt;
183 };183 };
184184
...@@ -211,7 +211,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!...@@ -211,7 +211,7 @@ pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!
211 }211 }
212 const version_index = std.fmt.parseInt(u8, version_index_string, 10) catch |err| {212 const version_index = std.fmt.parseInt(u8, version_index_string, 10) catch |err| {
213 // If this happens with legit data, increase the size of the integer type in the struct.213 // If this happens with legit data, increase the size of the integer type in the struct.
214 std.log.err("abi.txt:{}: unable to parse version: {}", .{ line_i, @errorName(err) });214 std.log.err("abi.txt:{}: unable to parse version: {s}", .{ line_i, @errorName(err) });
215 return error.ZigInstallationCorrupt;215 return error.ZigInstallationCorrupt;
216 };216 };
217217
...@@ -531,7 +531,7 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(...@@ -531,7 +531,7 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(
531 try args.append(try path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, lib_libc ++ "glibc" }));531 try args.append(try path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, lib_libc ++ "glibc" }));
532532
533 try args.append("-I");533 try args.append("-I");
534 try args.append(try std.fmt.allocPrint(arena, "{}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{}-{}-{}", .{534 try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", .{
535 comp.zig_lib_directory.path.?, @tagName(arch), @tagName(target.os.tag), @tagName(target.abi),535 comp.zig_lib_directory.path.?, @tagName(arch), @tagName(target.os.tag), @tagName(target.abi),
536 }));536 }));
537537
...@@ -539,7 +539,7 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(...@@ -539,7 +539,7 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(
539 try args.append(try lib_path(comp, arena, lib_libc ++ "include" ++ s ++ "generic-glibc"));539 try args.append(try lib_path(comp, arena, lib_libc ++ "include" ++ s ++ "generic-glibc"));
540540
541 try args.append("-I");541 try args.append("-I");
542 try args.append(try std.fmt.allocPrint(arena, "{}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{}-linux-any", .{542 try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-linux-any", .{
543 comp.zig_lib_directory.path.?, @tagName(arch),543 comp.zig_lib_directory.path.?, @tagName(arch),
544 }));544 }));
545545
...@@ -881,7 +881,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -881,7 +881,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
881 if (o_directory.handle.createFile(ok_basename, .{})) |file| {881 if (o_directory.handle.createFile(ok_basename, .{})) |file| {
882 file.close();882 file.close();
883 } else |err| {883 } else |err| {
884 std.log.warn("glibc shared objects: failed to mark completion: {}", .{@errorName(err)});884 std.log.warn("glibc shared objects: failed to mark completion: {s}", .{@errorName(err)});
885 }885 }
886 }886 }
887887
src/libc_installation.zig+16-16
...@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {...@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {
83 }83 }
84 inline for (fields) |field, i| {84 inline for (fields) |field, i| {
85 if (!found_keys[i].found) {85 if (!found_keys[i].found) {
86 log.err("missing field: {}\n", .{field.name});86 log.err("missing field: {s}\n", .{field.name});
87 return error.ParseError;87 return error.ParseError;
88 }88 }
89 }89 }
...@@ -96,18 +96,18 @@ pub const LibCInstallation = struct {...@@ -96,18 +96,18 @@ pub const LibCInstallation = struct {
96 return error.ParseError;96 return error.ParseError;
97 }97 }
98 if (self.crt_dir == null and !is_darwin) {98 if (self.crt_dir == null and !is_darwin) {
99 log.err("crt_dir may not be empty for {}\n", .{@tagName(Target.current.os.tag)});99 log.err("crt_dir may not be empty for {s}\n", .{@tagName(Target.current.os.tag)});
100 return error.ParseError;100 return error.ParseError;
101 }101 }
102 if (self.msvc_lib_dir == null and is_windows and !is_gnu) {102 if (self.msvc_lib_dir == null and is_windows and !is_gnu) {
103 log.err("msvc_lib_dir may not be empty for {}-{}\n", .{103 log.err("msvc_lib_dir may not be empty for {s}-{s}\n", .{
104 @tagName(Target.current.os.tag),104 @tagName(Target.current.os.tag),
105 @tagName(Target.current.abi),105 @tagName(Target.current.abi),
106 });106 });
107 return error.ParseError;107 return error.ParseError;
108 }108 }
109 if (self.kernel32_lib_dir == null and is_windows and !is_gnu) {109 if (self.kernel32_lib_dir == null and is_windows and !is_gnu) {
110 log.err("kernel32_lib_dir may not be empty for {}-{}\n", .{110 log.err("kernel32_lib_dir may not be empty for {s}-{s}\n", .{
111 @tagName(Target.current.os.tag),111 @tagName(Target.current.os.tag),
112 @tagName(Target.current.abi),112 @tagName(Target.current.abi),
113 });113 });
...@@ -128,25 +128,25 @@ pub const LibCInstallation = struct {...@@ -128,25 +128,25 @@ pub const LibCInstallation = struct {
128 try out.print(128 try out.print(
129 \\# The directory that contains `stdlib.h`.129 \\# The directory that contains `stdlib.h`.
130 \\# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`130 \\# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
131 \\include_dir={}131 \\include_dir={s}
132 \\132 \\
133 \\# The system-specific include directory. May be the same as `include_dir`.133 \\# The system-specific include directory. May be the same as `include_dir`.
134 \\# On Windows it's the directory that includes `vcruntime.h`.134 \\# On Windows it's the directory that includes `vcruntime.h`.
135 \\# On POSIX it's the directory that includes `sys/errno.h`.135 \\# On POSIX it's the directory that includes `sys/errno.h`.
136 \\sys_include_dir={}136 \\sys_include_dir={s}
137 \\137 \\
138 \\# The directory that contains `crt1.o` or `crt2.o`.138 \\# The directory that contains `crt1.o` or `crt2.o`.
139 \\# On POSIX, can be found with `cc -print-file-name=crt1.o`.139 \\# On POSIX, can be found with `cc -print-file-name=crt1.o`.
140 \\# Not needed when targeting MacOS.140 \\# Not needed when targeting MacOS.
141 \\crt_dir={}141 \\crt_dir={s}
142 \\142 \\
143 \\# The directory that contains `vcruntime.lib`.143 \\# The directory that contains `vcruntime.lib`.
144 \\# Only needed when targeting MSVC on Windows.144 \\# Only needed when targeting MSVC on Windows.
145 \\msvc_lib_dir={}145 \\msvc_lib_dir={s}
146 \\146 \\
147 \\# The directory that contains `kernel32.lib`.147 \\# The directory that contains `kernel32.lib`.
148 \\# Only needed when targeting MSVC on Windows.148 \\# Only needed when targeting MSVC on Windows.
149 \\kernel32_lib_dir={}149 \\kernel32_lib_dir={s}
150 \\150 \\
151 , .{151 , .{
152 include_dir,152 include_dir,
...@@ -338,7 +338,7 @@ pub const LibCInstallation = struct {...@@ -338,7 +338,7 @@ pub const LibCInstallation = struct {
338338
339 for (searches) |search| {339 for (searches) |search| {
340 result_buf.shrink(0);340 result_buf.shrink(0);
341 try result_buf.outStream().print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });341 try result_buf.outStream().print("{s}\\Include\\{s}\\ucrt", .{ search.path, search.version });
342342
343 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {343 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
344 error.FileNotFound,344 error.FileNotFound,
...@@ -384,7 +384,7 @@ pub const LibCInstallation = struct {...@@ -384,7 +384,7 @@ pub const LibCInstallation = struct {
384384
385 for (searches) |search| {385 for (searches) |search| {
386 result_buf.shrink(0);386 result_buf.shrink(0);
387 try result_buf.outStream().print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir });387 try result_buf.outStream().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ search.path, search.version, arch_sub_dir });
388388
389 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {389 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
390 error.FileNotFound,390 error.FileNotFound,
...@@ -439,7 +439,7 @@ pub const LibCInstallation = struct {...@@ -439,7 +439,7 @@ pub const LibCInstallation = struct {
439 for (searches) |search| {439 for (searches) |search| {
440 result_buf.shrink(0);440 result_buf.shrink(0);
441 const stream = result_buf.outStream();441 const stream = result_buf.outStream();
442 try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir });442 try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ search.path, search.version, arch_sub_dir });
443443
444 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {444 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
445 error.FileNotFound,445 error.FileNotFound,
...@@ -520,7 +520,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {...@@ -520,7 +520,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
520 const allocator = args.allocator;520 const allocator = args.allocator;
521521
522 const cc_exe = std.os.getenvZ("CC") orelse default_cc_exe;522 const cc_exe = std.os.getenvZ("CC") orelse default_cc_exe;
523 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", .{args.search_basename});523 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={s}", .{args.search_basename});
524 defer allocator.free(arg1);524 defer allocator.free(arg1);
525 const argv = [_][]const u8{ cc_exe, arg1 };525 const argv = [_][]const u8{ cc_exe, arg1 };
526526
...@@ -584,17 +584,17 @@ fn printVerboseInvocation(...@@ -584,17 +584,17 @@ fn printVerboseInvocation(
584 if (!verbose) return;584 if (!verbose) return;
585585
586 if (search_basename) |s| {586 if (search_basename) |s| {
587 std.debug.warn("Zig attempted to find the file '{}' by executing this command:\n", .{s});587 std.debug.warn("Zig attempted to find the file '{s}' by executing this command:\n", .{s});
588 } else {588 } else {
589 std.debug.warn("Zig attempted to find the path to native system libc headers by executing this command:\n", .{});589 std.debug.warn("Zig attempted to find the path to native system libc headers by executing this command:\n", .{});
590 }590 }
591 for (argv) |arg, i| {591 for (argv) |arg, i| {
592 if (i != 0) std.debug.warn(" ", .{});592 if (i != 0) std.debug.warn(" ", .{});
593 std.debug.warn("{}", .{arg});593 std.debug.warn("{s}", .{arg});
594 }594 }
595 std.debug.warn("\n", .{});595 std.debug.warn("\n", .{});
596 if (stderr) |s| {596 if (stderr) |s| {
597 std.debug.warn("Output:\n==========\n{}\n==========\n", .{s});597 std.debug.warn("Output:\n==========\n{s}\n==========\n", .{s});
598 }598 }
599}599}
600600
src/link.zig+4-4
...@@ -560,9 +560,9 @@ pub const File = struct {...@@ -560,9 +560,9 @@ pub const File = struct {
560 const full_out_path_z = try arena.dupeZ(u8, full_out_path);560 const full_out_path_z = try arena.dupeZ(u8, full_out_path);
561561
562 if (base.options.verbose_link) {562 if (base.options.verbose_link) {
563 std.debug.print("ar rcs {}", .{full_out_path_z});563 std.debug.print("ar rcs {s}", .{full_out_path_z});
564 for (object_files.items) |arg| {564 for (object_files.items) |arg| {
565 std.debug.print(" {}", .{arg});565 std.debug.print(" {s}", .{arg});
566 }566 }
567 std.debug.print("\n", .{});567 std.debug.print("\n", .{});
568 }568 }
...@@ -574,11 +574,11 @@ pub const File = struct {...@@ -574,11 +574,11 @@ pub const File = struct {
574574
575 if (!base.options.disable_lld_caching) {575 if (!base.options.disable_lld_caching) {
576 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {576 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
577 log.warn("failed to save archive hash digest file: {}", .{@errorName(err)});577 log.warn("failed to save archive hash digest file: {s}", .{@errorName(err)});
578 };578 };
579579
580 man.writeManifest() catch |err| {580 man.writeManifest() catch |err| {
581 log.warn("failed to write cache manifest when archiving: {}", .{@errorName(err)});581 log.warn("failed to write cache manifest when archiving: {s}", .{@errorName(err)});
582 };582 };
583583
584 base.lock = man.toOwnedLock();584 base.lock = man.toOwnedLock();
src/link/C.zig+4-1
...@@ -111,8 +111,11 @@ pub fn flushModule(self: *C, comp: *Compilation) !void {...@@ -111,8 +111,11 @@ pub fn flushModule(self: *C, comp: *Compilation) !void {
111 if (self.header.buf.items.len > 0) {111 if (self.header.buf.items.len > 0) {
112 try writer.writeByte('\n');112 try writer.writeByte('\n');
113 }113 }
114 if (self.header.items.len > 0) {
115 try writer.print("{s}\n", .{self.header.items});
116 }
114 if (self.constants.items.len > 0) {117 if (self.constants.items.len > 0) {
115 try writer.print("{}\n", .{self.constants.items});118 try writer.print("{s}\n", .{self.constants.items});
116 }119 }
117 if (self.main.items.len > 1) {120 if (self.main.items.len > 1) {
118 const last_two = self.main.items[self.main.items.len - 2 ..];121 const last_two = self.main.items[self.main.items.len - 2 ..];
src/link/Coff.zig+5-5
...@@ -686,7 +686,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {...@@ -686,7 +686,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
686 if (need_realloc) {686 if (need_realloc) {
687 const curr_vaddr = self.getDeclVAddr(decl);687 const curr_vaddr = self.getDeclVAddr(decl);
688 const vaddr = try self.growTextBlock(&decl.link.coff, code.len, required_alignment);688 const vaddr = try self.growTextBlock(&decl.link.coff, code.len, required_alignment);
689 log.debug("growing {} from 0x{x} to 0x{x}\n", .{ decl.name, curr_vaddr, vaddr });689 log.debug("growing {s} from 0x{x} to 0x{x}\n", .{ decl.name, curr_vaddr, vaddr });
690 if (vaddr != curr_vaddr) {690 if (vaddr != curr_vaddr) {
691 log.debug(" (writing new offset table entry)\n", .{});691 log.debug(" (writing new offset table entry)\n", .{});
692 self.offset_table.items[decl.link.coff.offset_table_index] = vaddr;692 self.offset_table.items[decl.link.coff.offset_table_index] = vaddr;
...@@ -697,7 +697,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {...@@ -697,7 +697,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
697 }697 }
698 } else {698 } else {
699 const vaddr = try self.allocateTextBlock(&decl.link.coff, code.len, required_alignment);699 const vaddr = try self.allocateTextBlock(&decl.link.coff, code.len, required_alignment);
700 log.debug("allocated text block for {} at 0x{x} (size: {Bi})\n", .{ mem.spanZ(decl.name), vaddr, code.len });700 log.debug("allocated text block for {s} at 0x{x} (size: {Bi})\n", .{ mem.spanZ(decl.name), vaddr, code.len });
701 errdefer self.freeTextBlock(&decl.link.coff);701 errdefer self.freeTextBlock(&decl.link.coff);
702 self.offset_table.items[decl.link.coff.offset_table_index] = vaddr;702 self.offset_table.items[decl.link.coff.offset_table_index] = vaddr;
703 try self.writeOffsetTableEntry(decl.link.coff.offset_table_index);703 try self.writeOffsetTableEntry(decl.link.coff.offset_table_index);
...@@ -880,7 +880,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {...@@ -880,7 +880,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
880 id_symlink_basename,880 id_symlink_basename,
881 &prev_digest_buf,881 &prev_digest_buf,
882 ) catch |err| blk: {882 ) catch |err| blk: {
883 log.debug("COFF LLD new_digest={} error: {}", .{ digest, @errorName(err) });883 log.debug("COFF LLD new_digest={} error: {s}", .{ digest, @errorName(err) });
884 // Handle this as a cache miss.884 // Handle this as a cache miss.
885 break :blk prev_digest_buf[0..0];885 break :blk prev_digest_buf[0..0];
886 };886 };
...@@ -1236,11 +1236,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {...@@ -1236,11 +1236,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1236 // Update the file with the digest. If it fails we can continue; it only1236 // Update the file with the digest. If it fails we can continue; it only
1237 // means that the next invocation will have an unnecessary cache miss.1237 // means that the next invocation will have an unnecessary cache miss.
1238 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {1238 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
1239 log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});1239 log.warn("failed to save linking hash digest file: {s}", .{@errorName(err)});
1240 };1240 };
1241 // Again failure here only means an unnecessary cache miss.1241 // Again failure here only means an unnecessary cache miss.
1242 man.writeManifest() catch |err| {1242 man.writeManifest() catch |err| {
1243 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});1243 log.warn("failed to write cache manifest when linking: {s}", .{@errorName(err)});
1244 };1244 };
1245 // We hang on to this lock so that the output file path can be used without1245 // We hang on to this lock so that the output file path can be used without
1246 // other processes clobbering it.1246 // other processes clobbering it.
src/link/Elf.zig+9-9
...@@ -1362,7 +1362,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1362,7 +1362,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1362 id_symlink_basename,1362 id_symlink_basename,
1363 &prev_digest_buf,1363 &prev_digest_buf,
1364 ) catch |err| blk: {1364 ) catch |err| blk: {
1365 log.debug("ELF LLD new_digest={} error: {}", .{ digest, @errorName(err) });1365 log.debug("ELF LLD new_digest={} error: {s}", .{ digest, @errorName(err) });
1366 // Handle this as a cache miss.1366 // Handle this as a cache miss.
1367 break :blk prev_digest_buf[0..0];1367 break :blk prev_digest_buf[0..0];
1368 };1368 };
...@@ -1396,7 +1396,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1396,7 +1396,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13961396
1397 if (self.base.options.output_mode == .Exe) {1397 if (self.base.options.output_mode == .Exe) {
1398 try argv.append("-z");1398 try argv.append("-z");
1399 try argv.append(try std.fmt.allocPrint(arena, "stack-size={}", .{stack_size}));1399 try argv.append(try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size}));
1400 }1400 }
14011401
1402 if (self.base.options.image_base_override) |image_base| {1402 if (self.base.options.image_base_override) |image_base| {
...@@ -1438,7 +1438,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1438,7 +1438,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1438 if (getLDMOption(target)) |ldm| {1438 if (getLDMOption(target)) |ldm| {
1439 // Any target ELF will use the freebsd osabi if suffixed with "_fbsd".1439 // Any target ELF will use the freebsd osabi if suffixed with "_fbsd".
1440 const arg = if (target.os.tag == .freebsd)1440 const arg = if (target.os.tag == .freebsd)
1441 try std.fmt.allocPrint(arena, "{}_fbsd", .{ldm})1441 try std.fmt.allocPrint(arena, "{s}_fbsd", .{ldm})
1442 else1442 else
1443 ldm;1443 ldm;
1444 try argv.append("-m");1444 try argv.append("-m");
...@@ -1599,7 +1599,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1599,7 +1599,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1599 // (the check for that needs to be earlier), but they could be full paths to .so files, in which1599 // (the check for that needs to be earlier), but they could be full paths to .so files, in which
1600 // case we want to avoid prepending "-l".1600 // case we want to avoid prepending "-l".
1601 const ext = Compilation.classifyFileExt(link_lib);1601 const ext = Compilation.classifyFileExt(link_lib);
1602 const arg = if (ext == .shared_library) link_lib else try std.fmt.allocPrint(arena, "-l{}", .{link_lib});1602 const arg = if (ext == .shared_library) link_lib else try std.fmt.allocPrint(arena, "-l{s}", .{link_lib});
1603 argv.appendAssumeCapacity(arg);1603 argv.appendAssumeCapacity(arg);
1604 }1604 }
16051605
...@@ -1733,11 +1733,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1733,11 +1733,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1733 // Update the file with the digest. If it fails we can continue; it only1733 // Update the file with the digest. If it fails we can continue; it only
1734 // means that the next invocation will have an unnecessary cache miss.1734 // means that the next invocation will have an unnecessary cache miss.
1735 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {1735 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
1736 log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});1736 log.warn("failed to save linking hash digest file: {s}", .{@errorName(err)});
1737 };1737 };
1738 // Again failure here only means an unnecessary cache miss.1738 // Again failure here only means an unnecessary cache miss.
1739 man.writeManifest() catch |err| {1739 man.writeManifest() catch |err| {
1740 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});1740 log.warn("failed to write cache manifest when linking: {s}", .{@errorName(err)});
1741 };1741 };
1742 // We hang on to this lock so that the output file path can be used without1742 // We hang on to this lock so that the output file path can be used without
1743 // other processes clobbering it.1743 // other processes clobbering it.
...@@ -2082,10 +2082,10 @@ pub fn allocateDeclIndexes(self: *Elf, decl: *Module.Decl) !void {...@@ -2082,10 +2082,10 @@ pub fn allocateDeclIndexes(self: *Elf, decl: *Module.Decl) !void {
2082 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);2082 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
20832083
2084 if (self.local_symbol_free_list.popOrNull()) |i| {2084 if (self.local_symbol_free_list.popOrNull()) |i| {
2085 log.debug("reusing symbol index {} for {}\n", .{ i, decl.name });2085 log.debug("reusing symbol index {} for {s}\n", .{ i, decl.name });
2086 decl.link.elf.local_sym_index = i;2086 decl.link.elf.local_sym_index = i;
2087 } else {2087 } else {
2088 log.debug("allocating symbol index {} for {}\n", .{ self.local_symbols.items.len, decl.name });2088 log.debug("allocating symbol index {} for {s}\n", .{ self.local_symbols.items.len, decl.name });
2089 decl.link.elf.local_sym_index = @intCast(u32, self.local_symbols.items.len);2089 decl.link.elf.local_sym_index = @intCast(u32, self.local_symbols.items.len);
2090 _ = self.local_symbols.addOneAssumeCapacity();2090 _ = self.local_symbols.addOneAssumeCapacity();
2091 }2091 }
...@@ -2182,7 +2182,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {...@@ -2182,7 +2182,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
2182 if (zir_dumps.len != 0) {2182 if (zir_dumps.len != 0) {
2183 for (zir_dumps) |fn_name| {2183 for (zir_dumps) |fn_name| {
2184 if (mem.eql(u8, mem.spanZ(decl.name), fn_name)) {2184 if (mem.eql(u8, mem.spanZ(decl.name), fn_name)) {
2185 std.debug.print("\n{}\n", .{decl.name});2185 std.debug.print("\n{s}\n", .{decl.name});
2186 typed_value.val.castTag(.function).?.data.dump(module.*);2186 typed_value.val.castTag(.function).?.data.dump(module.*);
2187 }2187 }
2188 }2188 }
src/link/MachO.zig+11-11
...@@ -520,7 +520,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -520,7 +520,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
520 id_symlink_basename,520 id_symlink_basename,
521 &prev_digest_buf,521 &prev_digest_buf,
522 ) catch |err| blk: {522 ) catch |err| blk: {
523 log.debug("MachO LLD new_digest={} error: {}", .{ digest, @errorName(err) });523 log.debug("MachO LLD new_digest={} error: {s}", .{ digest, @errorName(err) });
524 // Handle this as a cache miss.524 // Handle this as a cache miss.
525 break :blk prev_digest_buf[0..0];525 break :blk prev_digest_buf[0..0];
526 };526 };
...@@ -706,7 +706,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -706,7 +706,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
706 // (the check for that needs to be earlier), but they could be full paths to .dylib files, in which706 // (the check for that needs to be earlier), but they could be full paths to .dylib files, in which
707 // case we want to avoid prepending "-l".707 // case we want to avoid prepending "-l".
708 const ext = Compilation.classifyFileExt(link_lib);708 const ext = Compilation.classifyFileExt(link_lib);
709 const arg = if (ext == .shared_library) link_lib else try std.fmt.allocPrint(arena, "-l{}", .{link_lib});709 const arg = if (ext == .shared_library) link_lib else try std.fmt.allocPrint(arena, "-l{s}", .{link_lib});
710 argv.appendAssumeCapacity(arg);710 argv.appendAssumeCapacity(arg);
711 }711 }
712712
...@@ -759,15 +759,15 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -759,15 +759,15 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
759 self.base.allocator.free(result.stderr);759 self.base.allocator.free(result.stderr);
760 }760 }
761 if (result.stdout.len != 0) {761 if (result.stdout.len != 0) {
762 log.warn("unexpected LD stdout: {}", .{result.stdout});762 log.warn("unexpected LD stdout: {s}", .{result.stdout});
763 }763 }
764 if (result.stderr.len != 0) {764 if (result.stderr.len != 0) {
765 log.warn("unexpected LD stderr: {}", .{result.stderr});765 log.warn("unexpected LD stderr: {s}", .{result.stderr});
766 }766 }
767 if (result.term != .Exited or result.term.Exited != 0) {767 if (result.term != .Exited or result.term.Exited != 0) {
768 // TODO parse this output and surface with the Compilation API rather than768 // TODO parse this output and surface with the Compilation API rather than
769 // directly outputting to stderr here.769 // directly outputting to stderr here.
770 log.err("{}", .{result.stderr});770 log.err("{s}", .{result.stderr});
771 return error.LDReportedFailure;771 return error.LDReportedFailure;
772 }772 }
773 } else {773 } else {
...@@ -980,11 +980,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -980,11 +980,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
980 // Update the file with the digest. If it fails we can continue; it only980 // Update the file with the digest. If it fails we can continue; it only
981 // means that the next invocation will have an unnecessary cache miss.981 // means that the next invocation will have an unnecessary cache miss.
982 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {982 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
983 log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});983 log.warn("failed to save linking hash digest file: {s}", .{@errorName(err)});
984 };984 };
985 // Again failure here only means an unnecessary cache miss.985 // Again failure here only means an unnecessary cache miss.
986 man.writeManifest() catch |err| {986 man.writeManifest() catch |err| {
987 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});987 log.warn("failed to write cache manifest when linking: {s}", .{@errorName(err)});
988 };988 };
989 // We hang on to this lock so that the output file path can be used without989 // We hang on to this lock so that the output file path can be used without
990 // other processes clobbering it.990 // other processes clobbering it.
...@@ -1088,10 +1088,10 @@ pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void {...@@ -1088,10 +1088,10 @@ pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void {
1088 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);1088 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
10891089
1090 if (self.local_symbol_free_list.popOrNull()) |i| {1090 if (self.local_symbol_free_list.popOrNull()) |i| {
1091 log.debug("reusing symbol index {} for {}", .{ i, decl.name });1091 log.debug("reusing symbol index {d} for {s}", .{ i, decl.name });
1092 decl.link.macho.local_sym_index = i;1092 decl.link.macho.local_sym_index = i;
1093 } else {1093 } else {
1094 log.debug("allocating symbol index {} for {}", .{ self.local_symbols.items.len, decl.name });1094 log.debug("allocating symbol index {d} for {s}", .{ self.local_symbols.items.len, decl.name });
1095 decl.link.macho.local_sym_index = @intCast(u32, self.local_symbols.items.len);1095 decl.link.macho.local_sym_index = @intCast(u32, self.local_symbols.items.len);
1096 _ = self.local_symbols.addOneAssumeCapacity();1096 _ = self.local_symbols.addOneAssumeCapacity();
1097 }1097 }
...@@ -1165,7 +1165,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {...@@ -1165,7 +1165,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1165 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, symbol.n_value, required_alignment);1165 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, symbol.n_value, required_alignment);
1166 if (need_realloc) {1166 if (need_realloc) {
1167 const vaddr = try self.growTextBlock(&decl.link.macho, code.len, required_alignment);1167 const vaddr = try self.growTextBlock(&decl.link.macho, code.len, required_alignment);
1168 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl.name, symbol.n_value, vaddr });1168 log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl.name, symbol.n_value, vaddr });
1169 if (vaddr != symbol.n_value) {1169 if (vaddr != symbol.n_value) {
1170 symbol.n_value = vaddr;1170 symbol.n_value = vaddr;
1171 log.debug(" (writing new offset table entry)", .{});1171 log.debug(" (writing new offset table entry)", .{});
...@@ -1188,7 +1188,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {...@@ -1188,7 +1188,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1188 const decl_name = mem.spanZ(decl.name);1188 const decl_name = mem.spanZ(decl.name);
1189 const name_str_index = try self.makeString(decl_name);1189 const name_str_index = try self.makeString(decl_name);
1190 const addr = try self.allocateTextBlock(&decl.link.macho, code.len, required_alignment);1190 const addr = try self.allocateTextBlock(&decl.link.macho, code.len, required_alignment);
1191 log.debug("allocated text block for {} at 0x{x}", .{ decl_name, addr });1191 log.debug("allocated text block for {s} at 0x{x}", .{ decl_name, addr });
1192 errdefer self.freeTextBlock(&decl.link.macho);1192 errdefer self.freeTextBlock(&decl.link.macho);
11931193
1194 symbol.* = .{1194 symbol.* = .{
src/link/Wasm.zig+3-3
...@@ -321,7 +321,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -321,7 +321,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
321 id_symlink_basename,321 id_symlink_basename,
322 &prev_digest_buf,322 &prev_digest_buf,
323 ) catch |err| blk: {323 ) catch |err| blk: {
324 log.debug("WASM LLD new_digest={} error: {}", .{ digest, @errorName(err) });324 log.debug("WASM LLD new_digest={} error: {s}", .{ digest, @errorName(err) });
325 // Handle this as a cache miss.325 // Handle this as a cache miss.
326 break :blk prev_digest_buf[0..0];326 break :blk prev_digest_buf[0..0];
327 };327 };
...@@ -463,11 +463,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -463,11 +463,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
463 // Update the file with the digest. If it fails we can continue; it only463 // Update the file with the digest. If it fails we can continue; it only
464 // means that the next invocation will have an unnecessary cache miss.464 // means that the next invocation will have an unnecessary cache miss.
465 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {465 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
466 log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});466 log.warn("failed to save linking hash digest symlink: {s}", .{@errorName(err)});
467 };467 };
468 // Again failure here only means an unnecessary cache miss.468 // Again failure here only means an unnecessary cache miss.
469 man.writeManifest() catch |err| {469 man.writeManifest() catch |err| {
470 log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});470 log.warn("failed to write cache manifest when linking: {s}", .{@errorName(err)});
471 };471 };
472 // We hang on to this lock so that the output file path can be used without472 // We hang on to this lock so that the output file path can be used without
473 // other processes clobbering it.473 // other processes clobbering it.
src/main.zig+118-118
...@@ -118,7 +118,7 @@ pub fn main() anyerror!void {...@@ -118,7 +118,7 @@ pub fn main() anyerror!void {
118118
119pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void {119pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void {
120 if (args.len <= 1) {120 if (args.len <= 1) {
121 std.log.info("{}", .{usage});121 std.log.info("{s}", .{usage});
122 fatal("expected command argument", .{});122 fatal("expected command argument", .{});
123 }123 }
124124
...@@ -204,8 +204,8 @@ pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -204,8 +204,8 @@ pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
204 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {204 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
205 try io.getStdOut().writeAll(usage);205 try io.getStdOut().writeAll(usage);
206 } else {206 } else {
207 std.log.info("{}", .{usage});207 std.log.info("{s}", .{usage});
208 fatal("unknown command: {}", .{args[1]});208 fatal("unknown command: {s}", .{args[1]});
209 }209 }
210}210}
211211
...@@ -615,7 +615,7 @@ fn buildOutputType(...@@ -615,7 +615,7 @@ fn buildOutputType(
615 fatal("unexpected end-of-parameter mark: --", .{});615 fatal("unexpected end-of-parameter mark: --", .{});
616 }616 }
617 } else if (mem.eql(u8, arg, "--pkg-begin")) {617 } else if (mem.eql(u8, arg, "--pkg-begin")) {
618 if (i + 2 >= args.len) fatal("Expected 2 arguments after {}", .{arg});618 if (i + 2 >= args.len) fatal("Expected 2 arguments after {s}", .{arg});
619 i += 1;619 i += 1;
620 const pkg_name = args[i];620 const pkg_name = args[i];
621 i += 1;621 i += 1;
...@@ -635,7 +635,7 @@ fn buildOutputType(...@@ -635,7 +635,7 @@ fn buildOutputType(
635 cur_pkg = cur_pkg.parent orelse635 cur_pkg = cur_pkg.parent orelse
636 fatal("encountered --pkg-end with no matching --pkg-begin", .{});636 fatal("encountered --pkg-end with no matching --pkg-begin", .{});
637 } else if (mem.eql(u8, arg, "--main-pkg-path")) {637 } else if (mem.eql(u8, arg, "--main-pkg-path")) {
638 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});638 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
639 i += 1;639 i += 1;
640 main_pkg_path = args[i];640 main_pkg_path = args[i];
641 } else if (mem.eql(u8, arg, "-cflags")) {641 } else if (mem.eql(u8, arg, "-cflags")) {
...@@ -653,10 +653,10 @@ fn buildOutputType(...@@ -653,10 +653,10 @@ fn buildOutputType(
653 i += 1;653 i += 1;
654 const next_arg = args[i];654 const next_arg = args[i];
655 color = std.meta.stringToEnum(Color, next_arg) orelse {655 color = std.meta.stringToEnum(Color, next_arg) orelse {
656 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});656 fatal("expected [auto|on|off] after --color, found '{s}'", .{next_arg});
657 };657 };
658 } else if (mem.eql(u8, arg, "--subsystem")) {658 } else if (mem.eql(u8, arg, "--subsystem")) {
659 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});659 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
660 i += 1;660 i += 1;
661 if (mem.eql(u8, args[i], "console")) {661 if (mem.eql(u8, args[i], "console")) {
662 subsystem = .Console;662 subsystem = .Console;
...@@ -689,51 +689,51 @@ fn buildOutputType(...@@ -689,51 +689,51 @@ fn buildOutputType(
689 });689 });
690 }690 }
691 } else if (mem.eql(u8, arg, "-O")) {691 } else if (mem.eql(u8, arg, "-O")) {
692 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});692 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
693 i += 1;693 i += 1;
694 optimize_mode_string = args[i];694 optimize_mode_string = args[i];
695 } else if (mem.eql(u8, arg, "--stack")) {695 } else if (mem.eql(u8, arg, "--stack")) {
696 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});696 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
697 i += 1;697 i += 1;
698 stack_size_override = std.fmt.parseUnsigned(u64, args[i], 0) catch |err| {698 stack_size_override = std.fmt.parseUnsigned(u64, args[i], 0) catch |err| {
699 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });699 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });
700 };700 };
701 } else if (mem.eql(u8, arg, "--image-base")) {701 } else if (mem.eql(u8, arg, "--image-base")) {
702 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});702 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
703 i += 1;703 i += 1;
704 image_base_override = std.fmt.parseUnsigned(u64, args[i], 0) catch |err| {704 image_base_override = std.fmt.parseUnsigned(u64, args[i], 0) catch |err| {
705 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });705 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });
706 };706 };
707 } else if (mem.eql(u8, arg, "--name")) {707 } else if (mem.eql(u8, arg, "--name")) {
708 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});708 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
709 i += 1;709 i += 1;
710 provided_name = args[i];710 provided_name = args[i];
711 } else if (mem.eql(u8, arg, "-rpath")) {711 } else if (mem.eql(u8, arg, "-rpath")) {
712 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});712 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
713 i += 1;713 i += 1;
714 try rpath_list.append(args[i]);714 try rpath_list.append(args[i]);
715 } else if (mem.eql(u8, arg, "--library-directory") or mem.eql(u8, arg, "-L")) {715 } else if (mem.eql(u8, arg, "--library-directory") or mem.eql(u8, arg, "-L")) {
716 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});716 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
717 i += 1;717 i += 1;
718 try lib_dirs.append(args[i]);718 try lib_dirs.append(args[i]);
719 } else if (mem.eql(u8, arg, "-F")) {719 } else if (mem.eql(u8, arg, "-F")) {
720 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});720 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
721 i += 1;721 i += 1;
722 try framework_dirs.append(args[i]);722 try framework_dirs.append(args[i]);
723 } else if (mem.eql(u8, arg, "-framework")) {723 } else if (mem.eql(u8, arg, "-framework")) {
724 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});724 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
725 i += 1;725 i += 1;
726 try frameworks.append(args[i]);726 try frameworks.append(args[i]);
727 } else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {727 } else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {
728 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});728 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
729 i += 1;729 i += 1;
730 linker_script = args[i];730 linker_script = args[i];
731 } else if (mem.eql(u8, arg, "--version-script")) {731 } else if (mem.eql(u8, arg, "--version-script")) {
732 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});732 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
733 i += 1;733 i += 1;
734 version_script = args[i];734 version_script = args[i];
735 } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) {735 } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) {
736 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});736 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
737 // We don't know whether this library is part of libc or libc++ until we resolve the target.737 // We don't know whether this library is part of libc or libc++ until we resolve the target.
738 // So we simply append to the list for now.738 // So we simply append to the list for now.
739 i += 1;739 i += 1;
...@@ -743,7 +743,7 @@ fn buildOutputType(...@@ -743,7 +743,7 @@ fn buildOutputType(
743 mem.eql(u8, arg, "-I") or743 mem.eql(u8, arg, "-I") or
744 mem.eql(u8, arg, "-dirafter"))744 mem.eql(u8, arg, "-dirafter"))
745 {745 {
746 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});746 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
747 i += 1;747 i += 1;
748 try clang_argv.append(arg);748 try clang_argv.append(arg);
749 try clang_argv.append(args[i]);749 try clang_argv.append(args[i]);
...@@ -753,19 +753,19 @@ fn buildOutputType(...@@ -753,19 +753,19 @@ fn buildOutputType(
753 }753 }
754 i += 1;754 i += 1;
755 version = std.builtin.Version.parse(args[i]) catch |err| {755 version = std.builtin.Version.parse(args[i]) catch |err| {
756 fatal("unable to parse --version '{}': {}", .{ args[i], @errorName(err) });756 fatal("unable to parse --version '{s}': {s}", .{ args[i], @errorName(err) });
757 };757 };
758 have_version = true;758 have_version = true;
759 } else if (mem.eql(u8, arg, "-target")) {759 } else if (mem.eql(u8, arg, "-target")) {
760 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});760 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
761 i += 1;761 i += 1;
762 target_arch_os_abi = args[i];762 target_arch_os_abi = args[i];
763 } else if (mem.eql(u8, arg, "-mcpu")) {763 } else if (mem.eql(u8, arg, "-mcpu")) {
764 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});764 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
765 i += 1;765 i += 1;
766 target_mcpu = args[i];766 target_mcpu = args[i];
767 } else if (mem.eql(u8, arg, "-mcmodel")) {767 } else if (mem.eql(u8, arg, "-mcmodel")) {
768 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});768 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
769 i += 1;769 i += 1;
770 machine_code_model = parseCodeModel(args[i]);770 machine_code_model = parseCodeModel(args[i]);
771 } else if (mem.startsWith(u8, arg, "-ofmt=")) {771 } else if (mem.startsWith(u8, arg, "-ofmt=")) {
...@@ -777,35 +777,35 @@ fn buildOutputType(...@@ -777,35 +777,35 @@ fn buildOutputType(
777 } else if (mem.startsWith(u8, arg, "-O")) {777 } else if (mem.startsWith(u8, arg, "-O")) {
778 optimize_mode_string = arg["-O".len..];778 optimize_mode_string = arg["-O".len..];
779 } else if (mem.eql(u8, arg, "--dynamic-linker")) {779 } else if (mem.eql(u8, arg, "--dynamic-linker")) {
780 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});780 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
781 i += 1;781 i += 1;
782 target_dynamic_linker = args[i];782 target_dynamic_linker = args[i];
783 } else if (mem.eql(u8, arg, "--libc")) {783 } else if (mem.eql(u8, arg, "--libc")) {
784 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});784 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
785 i += 1;785 i += 1;
786 libc_paths_file = args[i];786 libc_paths_file = args[i];
787 } else if (mem.eql(u8, arg, "--test-filter")) {787 } else if (mem.eql(u8, arg, "--test-filter")) {
788 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});788 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
789 i += 1;789 i += 1;
790 test_filter = args[i];790 test_filter = args[i];
791 } else if (mem.eql(u8, arg, "--test-name-prefix")) {791 } else if (mem.eql(u8, arg, "--test-name-prefix")) {
792 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});792 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
793 i += 1;793 i += 1;
794 test_name_prefix = args[i];794 test_name_prefix = args[i];
795 } else if (mem.eql(u8, arg, "--test-cmd")) {795 } else if (mem.eql(u8, arg, "--test-cmd")) {
796 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});796 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
797 i += 1;797 i += 1;
798 try test_exec_args.append(args[i]);798 try test_exec_args.append(args[i]);
799 } else if (mem.eql(u8, arg, "--cache-dir")) {799 } else if (mem.eql(u8, arg, "--cache-dir")) {
800 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});800 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
801 i += 1;801 i += 1;
802 override_local_cache_dir = args[i];802 override_local_cache_dir = args[i];
803 } else if (mem.eql(u8, arg, "--global-cache-dir")) {803 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
804 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});804 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
805 i += 1;805 i += 1;
806 override_global_cache_dir = args[i];806 override_global_cache_dir = args[i];
807 } else if (mem.eql(u8, arg, "--override-lib-dir")) {807 } else if (mem.eql(u8, arg, "--override-lib-dir")) {
808 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});808 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
809 i += 1;809 i += 1;
810 override_lib_dir = args[i];810 override_lib_dir = args[i];
811 } else if (mem.eql(u8, arg, "-fcompiler-rt")) {811 } else if (mem.eql(u8, arg, "-fcompiler-rt")) {
...@@ -968,7 +968,7 @@ fn buildOutputType(...@@ -968,7 +968,7 @@ fn buildOutputType(
968 {968 {
969 try clang_argv.append(arg);969 try clang_argv.append(arg);
970 } else {970 } else {
971 fatal("unrecognized parameter: '{}'", .{arg});971 fatal("unrecognized parameter: '{s}'", .{arg});
972 }972 }
973 } else switch (Compilation.classifyFileExt(arg)) {973 } else switch (Compilation.classifyFileExt(arg)) {
974 .object, .static_library, .shared_library => {974 .object, .static_library, .shared_library => {
...@@ -982,19 +982,19 @@ fn buildOutputType(...@@ -982,19 +982,19 @@ fn buildOutputType(
982 },982 },
983 .zig, .zir => {983 .zig, .zir => {
984 if (root_src_file) |other| {984 if (root_src_file) |other| {
985 fatal("found another zig file '{}' after root source file '{}'", .{ arg, other });985 fatal("found another zig file '{s}' after root source file '{s}'", .{ arg, other });
986 } else {986 } else {
987 root_src_file = arg;987 root_src_file = arg;
988 }988 }
989 },989 },
990 .unknown => {990 .unknown => {
991 fatal("unrecognized file extension of parameter '{}'", .{arg});991 fatal("unrecognized file extension of parameter '{s}'", .{arg});
992 },992 },
993 }993 }
994 }994 }
995 if (optimize_mode_string) |s| {995 if (optimize_mode_string) |s| {
996 optimize_mode = std.meta.stringToEnum(std.builtin.Mode, s) orelse996 optimize_mode = std.meta.stringToEnum(std.builtin.Mode, s) orelse
997 fatal("unrecognized optimization mode: '{}'", .{s});997 fatal("unrecognized optimization mode: '{s}'", .{s});
998 }998 }
999 },999 },
1000 .cc, .cpp => {1000 .cc, .cpp => {
...@@ -1018,7 +1018,7 @@ fn buildOutputType(...@@ -1018,7 +1018,7 @@ fn buildOutputType(
1018 var it = ClangArgIterator.init(arena, all_args);1018 var it = ClangArgIterator.init(arena, all_args);
1019 while (it.has_next) {1019 while (it.has_next) {
1020 it.next() catch |err| {1020 it.next() catch |err| {
1021 fatal("unable to parse command line parameters: {}", .{@errorName(err)});1021 fatal("unable to parse command line parameters: {s}", .{@errorName(err)});
1022 };1022 };
1023 switch (it.zig_equivalent) {1023 switch (it.zig_equivalent) {
1024 .target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown1024 .target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown
...@@ -1038,7 +1038,7 @@ fn buildOutputType(...@@ -1038,7 +1038,7 @@ fn buildOutputType(
1038 },1038 },
1039 .zig, .zir => {1039 .zig, .zir => {
1040 if (root_src_file) |other| {1040 if (root_src_file) |other| {
1041 fatal("found another zig file '{}' after root source file '{}'", .{ it.only_arg, other });1041 fatal("found another zig file '{s}' after root source file '{s}'", .{ it.only_arg, other });
1042 } else {1042 } else {
1043 root_src_file = it.only_arg;1043 root_src_file = it.only_arg;
1044 }1044 }
...@@ -1153,7 +1153,7 @@ fn buildOutputType(...@@ -1153,7 +1153,7 @@ fn buildOutputType(
1153 if (mem.eql(u8, arg, "-soname")) {1153 if (mem.eql(u8, arg, "-soname")) {
1154 i += 1;1154 i += 1;
1155 if (i >= linker_args.items.len) {1155 if (i >= linker_args.items.len) {
1156 fatal("expected linker arg after '{}'", .{arg});1156 fatal("expected linker arg after '{s}'", .{arg});
1157 }1157 }
1158 const name = linker_args.items[i];1158 const name = linker_args.items[i];
1159 soname = .{ .yes = name };1159 soname = .{ .yes = name };
...@@ -1185,7 +1185,7 @@ fn buildOutputType(...@@ -1185,7 +1185,7 @@ fn buildOutputType(
1185 } else if (mem.eql(u8, arg, "-rpath")) {1185 } else if (mem.eql(u8, arg, "-rpath")) {
1186 i += 1;1186 i += 1;
1187 if (i >= linker_args.items.len) {1187 if (i >= linker_args.items.len) {
1188 fatal("expected linker arg after '{}'", .{arg});1188 fatal("expected linker arg after '{s}'", .{arg});
1189 }1189 }
1190 try rpath_list.append(linker_args.items[i]);1190 try rpath_list.append(linker_args.items[i]);
1191 } else if (mem.eql(u8, arg, "-I") or1191 } else if (mem.eql(u8, arg, "-I") or
...@@ -1194,7 +1194,7 @@ fn buildOutputType(...@@ -1194,7 +1194,7 @@ fn buildOutputType(
1194 {1194 {
1195 i += 1;1195 i += 1;
1196 if (i >= linker_args.items.len) {1196 if (i >= linker_args.items.len) {
1197 fatal("expected linker arg after '{}'", .{arg});1197 fatal("expected linker arg after '{s}'", .{arg});
1198 }1198 }
1199 target_dynamic_linker = linker_args.items[i];1199 target_dynamic_linker = linker_args.items[i];
1200 } else if (mem.eql(u8, arg, "-E") or1200 } else if (mem.eql(u8, arg, "-E") or
...@@ -1205,7 +1205,7 @@ fn buildOutputType(...@@ -1205,7 +1205,7 @@ fn buildOutputType(
1205 } else if (mem.eql(u8, arg, "--version-script")) {1205 } else if (mem.eql(u8, arg, "--version-script")) {
1206 i += 1;1206 i += 1;
1207 if (i >= linker_args.items.len) {1207 if (i >= linker_args.items.len) {
1208 fatal("expected linker arg after '{}'", .{arg});1208 fatal("expected linker arg after '{s}'", .{arg});
1209 }1209 }
1210 version_script = linker_args.items[i];1210 version_script = linker_args.items[i];
1211 } else if (mem.startsWith(u8, arg, "-O")) {1211 } else if (mem.startsWith(u8, arg, "-O")) {
...@@ -1227,7 +1227,7 @@ fn buildOutputType(...@@ -1227,7 +1227,7 @@ fn buildOutputType(
1227 } else if (mem.eql(u8, arg, "-z")) {1227 } else if (mem.eql(u8, arg, "-z")) {
1228 i += 1;1228 i += 1;
1229 if (i >= linker_args.items.len) {1229 if (i >= linker_args.items.len) {
1230 fatal("expected linker arg after '{}'", .{arg});1230 fatal("expected linker arg after '{s}'", .{arg});
1231 }1231 }
1232 const z_arg = linker_args.items[i];1232 const z_arg = linker_args.items[i];
1233 if (mem.eql(u8, z_arg, "nodelete")) {1233 if (mem.eql(u8, z_arg, "nodelete")) {
...@@ -1235,44 +1235,44 @@ fn buildOutputType(...@@ -1235,44 +1235,44 @@ fn buildOutputType(
1235 } else if (mem.eql(u8, z_arg, "defs")) {1235 } else if (mem.eql(u8, z_arg, "defs")) {
1236 linker_z_defs = true;1236 linker_z_defs = true;
1237 } else {1237 } else {
1238 warn("unsupported linker arg: -z {}", .{z_arg});1238 warn("unsupported linker arg: -z {s}", .{z_arg});
1239 }1239 }
1240 } else if (mem.eql(u8, arg, "--major-image-version")) {1240 } else if (mem.eql(u8, arg, "--major-image-version")) {
1241 i += 1;1241 i += 1;
1242 if (i >= linker_args.items.len) {1242 if (i >= linker_args.items.len) {
1243 fatal("expected linker arg after '{}'", .{arg});1243 fatal("expected linker arg after '{s}'", .{arg});
1244 }1244 }
1245 version.major = std.fmt.parseUnsigned(u32, linker_args.items[i], 10) catch |err| {1245 version.major = std.fmt.parseUnsigned(u32, linker_args.items[i], 10) catch |err| {
1246 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });1246 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1247 };1247 };
1248 have_version = true;1248 have_version = true;
1249 } else if (mem.eql(u8, arg, "--minor-image-version")) {1249 } else if (mem.eql(u8, arg, "--minor-image-version")) {
1250 i += 1;1250 i += 1;
1251 if (i >= linker_args.items.len) {1251 if (i >= linker_args.items.len) {
1252 fatal("expected linker arg after '{}'", .{arg});1252 fatal("expected linker arg after '{s}'", .{arg});
1253 }1253 }
1254 version.minor = std.fmt.parseUnsigned(u32, linker_args.items[i], 10) catch |err| {1254 version.minor = std.fmt.parseUnsigned(u32, linker_args.items[i], 10) catch |err| {
1255 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });1255 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1256 };1256 };
1257 have_version = true;1257 have_version = true;
1258 } else if (mem.eql(u8, arg, "--stack")) {1258 } else if (mem.eql(u8, arg, "--stack")) {
1259 i += 1;1259 i += 1;
1260 if (i >= linker_args.items.len) {1260 if (i >= linker_args.items.len) {
1261 fatal("expected linker arg after '{}'", .{arg});1261 fatal("expected linker arg after '{s}'", .{arg});
1262 }1262 }
1263 stack_size_override = std.fmt.parseUnsigned(u64, linker_args.items[i], 0) catch |err| {1263 stack_size_override = std.fmt.parseUnsigned(u64, linker_args.items[i], 0) catch |err| {
1264 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });1264 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1265 };1265 };
1266 } else if (mem.eql(u8, arg, "--image-base")) {1266 } else if (mem.eql(u8, arg, "--image-base")) {
1267 i += 1;1267 i += 1;
1268 if (i >= linker_args.items.len) {1268 if (i >= linker_args.items.len) {
1269 fatal("expected linker arg after '{}'", .{arg});1269 fatal("expected linker arg after '{s}'", .{arg});
1270 }1270 }
1271 image_base_override = std.fmt.parseUnsigned(u64, linker_args.items[i], 0) catch |err| {1271 image_base_override = std.fmt.parseUnsigned(u64, linker_args.items[i], 0) catch |err| {
1272 fatal("unable to parse '{}': {}", .{ arg, @errorName(err) });1272 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1273 };1273 };
1274 } else {1274 } else {
1275 warn("unsupported linker arg: {}", .{arg});1275 warn("unsupported linker arg: {s}", .{arg});
1276 }1276 }
1277 }1277 }
12781278
...@@ -1328,7 +1328,7 @@ fn buildOutputType(...@@ -1328,7 +1328,7 @@ fn buildOutputType(
1328 }1328 }
13291329
1330 if (arg_mode == .translate_c and c_source_files.items.len != 1) {1330 if (arg_mode == .translate_c and c_source_files.items.len != 1) {
1331 fatal("translate-c expects exactly 1 source file (found {})", .{c_source_files.items.len});1331 fatal("translate-c expects exactly 1 source file (found {d})", .{c_source_files.items.len});
1332 }1332 }
13331333
1334 if (root_src_file == null and arg_mode == .zig_test) {1334 if (root_src_file == null and arg_mode == .zig_test) {
...@@ -1373,25 +1373,25 @@ fn buildOutputType(...@@ -1373,25 +1373,25 @@ fn buildOutputType(
1373 help: {1373 help: {
1374 var help_text = std.ArrayList(u8).init(arena);1374 var help_text = std.ArrayList(u8).init(arena);
1375 for (diags.arch.?.allCpuModels()) |cpu| {1375 for (diags.arch.?.allCpuModels()) |cpu| {
1376 help_text.writer().print(" {}\n", .{cpu.name}) catch break :help;1376 help_text.writer().print(" {s}\n", .{cpu.name}) catch break :help;
1377 }1377 }
1378 std.log.info("Available CPUs for architecture '{}': {}", .{1378 std.log.info("Available CPUs for architecture '{s}': {s}", .{
1379 @tagName(diags.arch.?), help_text.items,1379 @tagName(diags.arch.?), help_text.items,
1380 });1380 });
1381 }1381 }
1382 fatal("Unknown CPU: '{}'", .{diags.cpu_name.?});1382 fatal("Unknown CPU: '{s}'", .{diags.cpu_name.?});
1383 },1383 },
1384 error.UnknownCpuFeature => {1384 error.UnknownCpuFeature => {
1385 help: {1385 help: {
1386 var help_text = std.ArrayList(u8).init(arena);1386 var help_text = std.ArrayList(u8).init(arena);
1387 for (diags.arch.?.allFeaturesList()) |feature| {1387 for (diags.arch.?.allFeaturesList()) |feature| {
1388 help_text.writer().print(" {}: {}\n", .{ feature.name, feature.description }) catch break :help;1388 help_text.writer().print(" {s}: {s}\n", .{ feature.name, feature.description }) catch break :help;
1389 }1389 }
1390 std.log.info("Available CPU features for architecture '{}': {}", .{1390 std.log.info("Available CPU features for architecture '{s}': {s}", .{
1391 @tagName(diags.arch.?), help_text.items,1391 @tagName(diags.arch.?), help_text.items,
1392 });1392 });
1393 }1393 }
1394 fatal("Unknown CPU feature: '{}'", .{diags.unknown_feature_name});1394 fatal("Unknown CPU feature: '{s}'", .{diags.unknown_feature_name});
1395 },1395 },
1396 else => |e| return e,1396 else => |e| return e,
1397 };1397 };
...@@ -1431,10 +1431,10 @@ fn buildOutputType(...@@ -1431,10 +1431,10 @@ fn buildOutputType(
14311431
1432 if (cross_target.isNativeOs() and (system_libs.items.len != 0 or want_native_include_dirs)) {1432 if (cross_target.isNativeOs() and (system_libs.items.len != 0 or want_native_include_dirs)) {
1433 const paths = std.zig.system.NativePaths.detect(arena) catch |err| {1433 const paths = std.zig.system.NativePaths.detect(arena) catch |err| {
1434 fatal("unable to detect native system paths: {}", .{@errorName(err)});1434 fatal("unable to detect native system paths: {s}", .{@errorName(err)});
1435 };1435 };
1436 for (paths.warnings.items) |warning| {1436 for (paths.warnings.items) |warning| {
1437 warn("{}", .{warning});1437 warn("{s}", .{warning});
1438 }1438 }
14391439
1440 const has_sysroot = if (comptime std.Target.current.isDarwin()) outer: {1440 const has_sysroot = if (comptime std.Target.current.isDarwin()) outer: {
...@@ -1492,7 +1492,7 @@ fn buildOutputType(...@@ -1492,7 +1492,7 @@ fn buildOutputType(
1492 } else if (mem.eql(u8, ofmt, "raw")) {1492 } else if (mem.eql(u8, ofmt, "raw")) {
1493 break :blk .raw;1493 break :blk .raw;
1494 } else {1494 } else {
1495 fatal("unsupported object format: {}", .{ofmt});1495 fatal("unsupported object format: {s}", .{ofmt});
1496 }1496 }
1497 };1497 };
14981498
...@@ -1562,7 +1562,7 @@ fn buildOutputType(...@@ -1562,7 +1562,7 @@ fn buildOutputType(
1562 }1562 }
1563 if (fs.path.dirname(full_path)) |dirname| {1563 if (fs.path.dirname(full_path)) |dirname| {
1564 const handle = fs.cwd().openDir(dirname, .{}) catch |err| {1564 const handle = fs.cwd().openDir(dirname, .{}) catch |err| {
1565 fatal("unable to open output directory '{}': {}", .{ dirname, @errorName(err) });1565 fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) });
1566 };1566 };
1567 cleanup_emit_bin_dir = handle;1567 cleanup_emit_bin_dir = handle;
1568 break :b Compilation.EmitLoc{1568 break :b Compilation.EmitLoc{
...@@ -1585,19 +1585,19 @@ fn buildOutputType(...@@ -1585,19 +1585,19 @@ fn buildOutputType(
1585 },1585 },
1586 };1586 };
15871587
1588 const default_h_basename = try std.fmt.allocPrint(arena, "{}.h", .{root_name});1588 const default_h_basename = try std.fmt.allocPrint(arena, "{s}.h", .{root_name});
1589 var emit_h_resolved = try emit_h.resolve(default_h_basename);1589 var emit_h_resolved = try emit_h.resolve(default_h_basename);
1590 defer emit_h_resolved.deinit();1590 defer emit_h_resolved.deinit();
15911591
1592 const default_asm_basename = try std.fmt.allocPrint(arena, "{}.s", .{root_name});1592 const default_asm_basename = try std.fmt.allocPrint(arena, "{s}.s", .{root_name});
1593 var emit_asm_resolved = try emit_asm.resolve(default_asm_basename);1593 var emit_asm_resolved = try emit_asm.resolve(default_asm_basename);
1594 defer emit_asm_resolved.deinit();1594 defer emit_asm_resolved.deinit();
15951595
1596 const default_llvm_ir_basename = try std.fmt.allocPrint(arena, "{}.ll", .{root_name});1596 const default_llvm_ir_basename = try std.fmt.allocPrint(arena, "{s}.ll", .{root_name});
1597 var emit_llvm_ir_resolved = try emit_llvm_ir.resolve(default_llvm_ir_basename);1597 var emit_llvm_ir_resolved = try emit_llvm_ir.resolve(default_llvm_ir_basename);
1598 defer emit_llvm_ir_resolved.deinit();1598 defer emit_llvm_ir_resolved.deinit();
15991599
1600 const default_analysis_basename = try std.fmt.allocPrint(arena, "{}-analysis.json", .{root_name});1600 const default_analysis_basename = try std.fmt.allocPrint(arena, "{s}-analysis.json", .{root_name});
1601 var emit_analysis_resolved = try emit_analysis.resolve(default_analysis_basename);1601 var emit_analysis_resolved = try emit_analysis.resolve(default_analysis_basename);
1602 defer emit_analysis_resolved.deinit();1602 defer emit_analysis_resolved.deinit();
16031603
...@@ -1609,10 +1609,10 @@ fn buildOutputType(...@@ -1609,10 +1609,10 @@ fn buildOutputType(
1609 .yes_default_path => blk: {1609 .yes_default_path => blk: {
1610 if (root_src_file) |rsf| {1610 if (root_src_file) |rsf| {
1611 if (mem.endsWith(u8, rsf, ".zir")) {1611 if (mem.endsWith(u8, rsf, ".zir")) {
1612 break :blk try std.fmt.allocPrint(arena, "{}.out.zir", .{root_name});1612 break :blk try std.fmt.allocPrint(arena, "{s}.out.zir", .{root_name});
1613 }1613 }
1614 }1614 }
1615 break :blk try std.fmt.allocPrint(arena, "{}.zir", .{root_name});1615 break :blk try std.fmt.allocPrint(arena, "{s}.zir", .{root_name});
1616 },1616 },
1617 .yes => |p| p,1617 .yes => |p| p,
1618 };1618 };
...@@ -1642,7 +1642,7 @@ fn buildOutputType(...@@ -1642,7 +1642,7 @@ fn buildOutputType(
1642 }1642 }
1643 else1643 else
1644 introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {1644 introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
1645 fatal("unable to find zig installation directory: {}", .{@errorName(err)});1645 fatal("unable to find zig installation directory: {s}", .{@errorName(err)});
1646 };1646 };
1647 defer zig_lib_directory.handle.close();1647 defer zig_lib_directory.handle.close();
16481648
...@@ -1655,7 +1655,7 @@ fn buildOutputType(...@@ -1655,7 +1655,7 @@ fn buildOutputType(
16551655
1656 if (libc_paths_file) |paths_file| {1656 if (libc_paths_file) |paths_file| {
1657 libc_installation = LibCInstallation.parse(gpa, paths_file) catch |err| {1657 libc_installation = LibCInstallation.parse(gpa, paths_file) catch |err| {
1658 fatal("unable to parse libc paths file: {}", .{@errorName(err)});1658 fatal("unable to parse libc paths file: {s}", .{@errorName(err)});
1659 };1659 };
1660 }1660 }
16611661
...@@ -1791,7 +1791,7 @@ fn buildOutputType(...@@ -1791,7 +1791,7 @@ fn buildOutputType(
1791 .disable_lld_caching = !have_enable_cache,1791 .disable_lld_caching = !have_enable_cache,
1792 .subsystem = subsystem,1792 .subsystem = subsystem,
1793 }) catch |err| {1793 }) catch |err| {
1794 fatal("unable to create compilation: {}", .{@errorName(err)});1794 fatal("unable to create compilation: {s}", .{@errorName(err)});
1795 };1795 };
1796 var comp_destroyed = false;1796 var comp_destroyed = false;
1797 defer if (!comp_destroyed) comp.destroy();1797 defer if (!comp_destroyed) comp.destroy();
...@@ -1914,12 +1914,12 @@ fn buildOutputType(...@@ -1914,12 +1914,12 @@ fn buildOutputType(
1914 if (!watch) return cleanExit();1914 if (!watch) return cleanExit();
1915 } else {1915 } else {
1916 const cmd = try argvCmd(arena, argv.items);1916 const cmd = try argvCmd(arena, argv.items);
1917 fatal("the following test command failed with exit code {}:\n{}", .{ code, cmd });1917 fatal("the following test command failed with exit code {}:\n{s}", .{ code, cmd });
1918 }1918 }
1919 },1919 },
1920 else => {1920 else => {
1921 const cmd = try argvCmd(arena, argv.items);1921 const cmd = try argvCmd(arena, argv.items);
1922 fatal("the following test command crashed:\n{}", .{cmd});1922 fatal("the following test command crashed:\n{s}", .{cmd});
1923 },1923 },
1924 }1924 }
1925 },1925 },
...@@ -1936,7 +1936,7 @@ fn buildOutputType(...@@ -1936,7 +1936,7 @@ fn buildOutputType(
1936 try stderr.print("(zig) ", .{});1936 try stderr.print("(zig) ", .{});
1937 try comp.makeBinFileExecutable();1937 try comp.makeBinFileExecutable();
1938 if (stdin.readUntilDelimiterOrEof(&repl_buf, '\n') catch |err| {1938 if (stdin.readUntilDelimiterOrEof(&repl_buf, '\n') catch |err| {
1939 try stderr.print("\nUnable to parse command: {}\n", .{@errorName(err)});1939 try stderr.print("\nUnable to parse command: {s}\n", .{@errorName(err)});
1940 continue;1940 continue;
1941 }) |line| {1941 }) |line| {
1942 const actual_line = mem.trimRight(u8, line, "\r\n ");1942 const actual_line = mem.trimRight(u8, line, "\r\n ");
...@@ -1954,7 +1954,7 @@ fn buildOutputType(...@@ -1954,7 +1954,7 @@ fn buildOutputType(
1954 } else if (mem.eql(u8, actual_line, "help")) {1954 } else if (mem.eql(u8, actual_line, "help")) {
1955 try stderr.writeAll(repl_help);1955 try stderr.writeAll(repl_help);
1956 } else {1956 } else {
1957 try stderr.print("unknown command: {}\n", .{actual_line});1957 try stderr.print("unknown command: {s}\n", .{actual_line});
1958 }1958 }
1959 } else {1959 } else {
1960 break;1960 break;
...@@ -2012,14 +2012,14 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi...@@ -2012,14 +2012,14 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
2012 assert(comp.c_source_files.len == 1);2012 assert(comp.c_source_files.len == 1);
2013 const c_source_file = comp.c_source_files[0];2013 const c_source_file = comp.c_source_files[0];
20142014
2015 const translated_zig_basename = try std.fmt.allocPrint(arena, "{}.zig", .{comp.bin_file.options.root_name});2015 const translated_zig_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{comp.bin_file.options.root_name});
20162016
2017 var man: Cache.Manifest = comp.obtainCObjectCacheManifest();2017 var man: Cache.Manifest = comp.obtainCObjectCacheManifest();
2018 defer if (enable_cache) man.deinit();2018 defer if (enable_cache) man.deinit();
20192019
2020 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects2020 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
2021 _ = man.addFile(c_source_file.src_path, null) catch |err| {2021 _ = man.addFile(c_source_file.src_path, null) catch |err| {
2022 fatal("unable to process '{}': {}", .{ c_source_file.src_path, @errorName(err) });2022 fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });
2023 };2023 };
20242024
2025 const digest = if (try man.hit()) man.final() else digest: {2025 const digest = if (try man.hit()) man.final() else digest: {
...@@ -2034,7 +2034,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi...@@ -2034,7 +2034,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
2034 break :blk null;2034 break :blk null;
20352035
2036 const c_src_basename = fs.path.basename(c_source_file.src_path);2036 const c_src_basename = fs.path.basename(c_source_file.src_path);
2037 const dep_basename = try std.fmt.allocPrint(arena, "{}.d", .{c_src_basename});2037 const dep_basename = try std.fmt.allocPrint(arena, "{s}.d", .{c_src_basename});
2038 const out_dep_path = try comp.tmpFilePath(arena, dep_basename);2038 const out_dep_path = try comp.tmpFilePath(arena, dep_basename);
2039 break :blk out_dep_path;2039 break :blk out_dep_path;
2040 };2040 };
...@@ -2069,7 +2069,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi...@@ -2069,7 +2069,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
2069 error.ASTUnitFailure => fatal("clang API returned errors but due to a clang bug, it is not exposing the errors for zig to see. For more details: https://github.com/ziglang/zig/issues/4455", .{}),2069 error.ASTUnitFailure => fatal("clang API returned errors but due to a clang bug, it is not exposing the errors for zig to see. For more details: https://github.com/ziglang/zig/issues/4455", .{}),
2070 error.SemanticAnalyzeFail => {2070 error.SemanticAnalyzeFail => {
2071 for (clang_errors) |clang_err| {2071 for (clang_errors) |clang_err| {
2072 std.debug.print("{}:{}:{}: {}\n", .{2072 std.debug.print("{s}:{}:{}: {s}\n", .{
2073 if (clang_err.filename_ptr) |p| p[0..clang_err.filename_len] else "(no file)",2073 if (clang_err.filename_ptr) |p| p[0..clang_err.filename_len] else "(no file)",
2074 clang_err.line + 1,2074 clang_err.line + 1,
2075 clang_err.column + 1,2075 clang_err.column + 1,
...@@ -2087,7 +2087,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi...@@ -2087,7 +2087,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
2087 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);2087 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
2088 // Just to save disk space, we delete the file because it is never needed again.2088 // Just to save disk space, we delete the file because it is never needed again.
2089 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {2089 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
2090 warn("failed to delete '{}': {}", .{ dep_file_path, @errorName(err) });2090 warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
2091 };2091 };
2092 }2092 }
20932093
...@@ -2102,7 +2102,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi...@@ -2102,7 +2102,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
2102 _ = try std.zig.render(comp.gpa, bos.writer(), tree);2102 _ = try std.zig.render(comp.gpa, bos.writer(), tree);
2103 try bos.flush();2103 try bos.flush();
21042104
2105 man.writeManifest() catch |err| warn("failed to write cache manifest: {}", .{@errorName(err)});2105 man.writeManifest() catch |err| warn("failed to write cache manifest: {s}", .{@errorName(err)});
21062106
2107 break :digest digest;2107 break :digest digest;
2108 };2108 };
...@@ -2111,7 +2111,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi...@@ -2111,7 +2111,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi
2111 const full_zig_path = try comp.local_cache_directory.join(arena, &[_][]const u8{2111 const full_zig_path = try comp.local_cache_directory.join(arena, &[_][]const u8{
2112 "o", &digest, translated_zig_basename,2112 "o", &digest, translated_zig_basename,
2113 });2113 });
2114 try io.getStdOut().writer().print("{}\n", .{full_zig_path});2114 try io.getStdOut().writer().print("{s}\n", .{full_zig_path});
2115 return cleanExit();2115 return cleanExit();
2116 } else {2116 } else {
2117 const out_zig_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest, translated_zig_basename });2117 const out_zig_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest, translated_zig_basename });
...@@ -2148,10 +2148,10 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {...@@ -2148,10 +2148,10 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {
2148 try stdout.writeAll(usage_libc);2148 try stdout.writeAll(usage_libc);
2149 return cleanExit();2149 return cleanExit();
2150 } else {2150 } else {
2151 fatal("unrecognized parameter: '{}'", .{arg});2151 fatal("unrecognized parameter: '{s}'", .{arg});
2152 }2152 }
2153 } else if (input_file != null) {2153 } else if (input_file != null) {
2154 fatal("unexpected extra parameter: '{}'", .{arg});2154 fatal("unexpected extra parameter: '{s}'", .{arg});
2155 } else {2155 } else {
2156 input_file = arg;2156 input_file = arg;
2157 }2157 }
...@@ -2159,7 +2159,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {...@@ -2159,7 +2159,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {
2159 }2159 }
2160 if (input_file) |libc_file| {2160 if (input_file) |libc_file| {
2161 var libc = LibCInstallation.parse(gpa, libc_file) catch |err| {2161 var libc = LibCInstallation.parse(gpa, libc_file) catch |err| {
2162 fatal("unable to parse libc file: {}", .{@errorName(err)});2162 fatal("unable to parse libc file: {s}", .{@errorName(err)});
2163 };2163 };
2164 defer libc.deinit(gpa);2164 defer libc.deinit(gpa);
2165 } else {2165 } else {
...@@ -2167,7 +2167,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {...@@ -2167,7 +2167,7 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void {
2167 .allocator = gpa,2167 .allocator = gpa,
2168 .verbose = true,2168 .verbose = true,
2169 }) catch |err| {2169 }) catch |err| {
2170 fatal("unable to detect native libc: {}", .{@errorName(err)});2170 fatal("unable to detect native libc: {s}", .{@errorName(err)});
2171 };2171 };
2172 defer libc.deinit(gpa);2172 defer libc.deinit(gpa);
21732173
...@@ -2205,16 +2205,16 @@ pub fn cmdInit(...@@ -2205,16 +2205,16 @@ pub fn cmdInit(
2205 try io.getStdOut().writeAll(usage_init);2205 try io.getStdOut().writeAll(usage_init);
2206 return cleanExit();2206 return cleanExit();
2207 } else {2207 } else {
2208 fatal("unrecognized parameter: '{}'", .{arg});2208 fatal("unrecognized parameter: '{s}'", .{arg});
2209 }2209 }
2210 } else {2210 } else {
2211 fatal("unexpected extra parameter: '{}'", .{arg});2211 fatal("unexpected extra parameter: '{s}'", .{arg});
2212 }2212 }
2213 }2213 }
2214 }2214 }
2215 const self_exe_path = try fs.selfExePathAlloc(arena);2215 const self_exe_path = try fs.selfExePathAlloc(arena);
2216 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {2216 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
2217 fatal("unable to find zig installation directory: {}\n", .{@errorName(err)});2217 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
2218 };2218 };
2219 defer zig_lib_directory.handle.close();2219 defer zig_lib_directory.handle.close();
22202220
...@@ -2232,7 +2232,7 @@ pub fn cmdInit(...@@ -2232,7 +2232,7 @@ pub fn cmdInit(
22322232
2233 const max_bytes = 10 * 1024 * 1024;2233 const max_bytes = 10 * 1024 * 1024;
2234 const build_zig_contents = template_dir.readFileAlloc(arena, "build.zig", max_bytes) catch |err| {2234 const build_zig_contents = template_dir.readFileAlloc(arena, "build.zig", max_bytes) catch |err| {
2235 fatal("unable to read template file 'build.zig': {}", .{@errorName(err)});2235 fatal("unable to read template file 'build.zig': {s}", .{@errorName(err)});
2236 };2236 };
2237 var modified_build_zig_contents = std.ArrayList(u8).init(arena);2237 var modified_build_zig_contents = std.ArrayList(u8).init(arena);
2238 try modified_build_zig_contents.ensureCapacity(build_zig_contents.len);2238 try modified_build_zig_contents.ensureCapacity(build_zig_contents.len);
...@@ -2244,13 +2244,13 @@ pub fn cmdInit(...@@ -2244,13 +2244,13 @@ pub fn cmdInit(
2244 }2244 }
2245 }2245 }
2246 const main_zig_contents = template_dir.readFileAlloc(arena, "src" ++ s ++ "main.zig", max_bytes) catch |err| {2246 const main_zig_contents = template_dir.readFileAlloc(arena, "src" ++ s ++ "main.zig", max_bytes) catch |err| {
2247 fatal("unable to read template file 'main.zig': {}", .{@errorName(err)});2247 fatal("unable to read template file 'main.zig': {s}", .{@errorName(err)});
2248 };2248 };
2249 if (fs.cwd().access("build.zig", .{})) |_| {2249 if (fs.cwd().access("build.zig", .{})) |_| {
2250 fatal("existing build.zig file would be overwritten", .{});2250 fatal("existing build.zig file would be overwritten", .{});
2251 } else |err| switch (err) {2251 } else |err| switch (err) {
2252 error.FileNotFound => {},2252 error.FileNotFound => {},
2253 else => fatal("unable to test existence of build.zig: {}\n", .{@errorName(err)}),2253 else => fatal("unable to test existence of build.zig: {s}\n", .{@errorName(err)}),
2254 }2254 }
2255 var src_dir = try fs.cwd().makeOpenPath("src", .{});2255 var src_dir = try fs.cwd().makeOpenPath("src", .{});
2256 defer src_dir.close();2256 defer src_dir.close();
...@@ -2311,23 +2311,23 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2311,23 +2311,23 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2311 const arg = args[i];2311 const arg = args[i];
2312 if (mem.startsWith(u8, arg, "-")) {2312 if (mem.startsWith(u8, arg, "-")) {
2313 if (mem.eql(u8, arg, "--build-file")) {2313 if (mem.eql(u8, arg, "--build-file")) {
2314 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});2314 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
2315 i += 1;2315 i += 1;
2316 build_file = args[i];2316 build_file = args[i];
2317 continue;2317 continue;
2318 } else if (mem.eql(u8, arg, "--override-lib-dir")) {2318 } else if (mem.eql(u8, arg, "--override-lib-dir")) {
2319 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});2319 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
2320 i += 1;2320 i += 1;
2321 override_lib_dir = args[i];2321 override_lib_dir = args[i];
2322 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });2322 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
2323 continue;2323 continue;
2324 } else if (mem.eql(u8, arg, "--cache-dir")) {2324 } else if (mem.eql(u8, arg, "--cache-dir")) {
2325 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});2325 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
2326 i += 1;2326 i += 1;
2327 override_local_cache_dir = args[i];2327 override_local_cache_dir = args[i];
2328 continue;2328 continue;
2329 } else if (mem.eql(u8, arg, "--global-cache-dir")) {2329 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
2330 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});2330 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
2331 i += 1;2331 i += 1;
2332 override_global_cache_dir = args[i];2332 override_global_cache_dir = args[i];
2333 continue;2333 continue;
...@@ -2344,7 +2344,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2344,7 +2344,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2344 }2344 }
2345 else2345 else
2346 introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {2346 introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
2347 fatal("unable to find zig installation directory: {}", .{@errorName(err)});2347 fatal("unable to find zig installation directory: {s}", .{@errorName(err)});
2348 };2348 };
2349 defer zig_lib_directory.handle.close();2349 defer zig_lib_directory.handle.close();
23502350
...@@ -2385,7 +2385,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2385,7 +2385,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2385 } else |err| switch (err) {2385 } else |err| switch (err) {
2386 error.FileNotFound => {2386 error.FileNotFound => {
2387 dirname = fs.path.dirname(dirname) orelse {2387 dirname = fs.path.dirname(dirname) orelse {
2388 std.log.info("{}", .{2388 std.log.info("{s}", .{
2389 \\Initialize a 'build.zig' template file with `zig init-lib` or `zig init-exe`,2389 \\Initialize a 'build.zig' template file with `zig init-lib` or `zig init-exe`,
2390 \\or see `zig --help` for more options.2390 \\or see `zig --help` for more options.
2391 });2391 });
...@@ -2467,7 +2467,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2467,7 +2467,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2467 .self_exe_path = self_exe_path,2467 .self_exe_path = self_exe_path,
2468 .thread_pool = &thread_pool,2468 .thread_pool = &thread_pool,
2469 }) catch |err| {2469 }) catch |err| {
2470 fatal("unable to create compilation: {}", .{@errorName(err)});2470 fatal("unable to create compilation: {s}", .{@errorName(err)});
2471 };2471 };
2472 defer comp.destroy();2472 defer comp.destroy();
24732473
...@@ -2493,11 +2493,11 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2493,11 +2493,11 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2493 .Exited => |code| {2493 .Exited => |code| {
2494 if (code == 0) return cleanExit();2494 if (code == 0) return cleanExit();
2495 const cmd = try argvCmd(arena, child_argv);2495 const cmd = try argvCmd(arena, child_argv);
2496 fatal("the following build command failed with exit code {}:\n{}", .{ code, cmd });2496 fatal("the following build command failed with exit code {}:\n{s}", .{ code, cmd });
2497 },2497 },
2498 else => {2498 else => {
2499 const cmd = try argvCmd(arena, child_argv);2499 const cmd = try argvCmd(arena, child_argv);
2500 fatal("the following build command crashed:\n{}", .{cmd});2500 fatal("the following build command crashed:\n{s}", .{cmd});
2501 },2501 },
2502 }2502 }
2503}2503}
...@@ -2564,14 +2564,14 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {...@@ -2564,14 +2564,14 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
2564 i += 1;2564 i += 1;
2565 const next_arg = args[i];2565 const next_arg = args[i];
2566 color = std.meta.stringToEnum(Color, next_arg) orelse {2566 color = std.meta.stringToEnum(Color, next_arg) orelse {
2567 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});2567 fatal("expected [auto|on|off] after --color, found '{s}'", .{next_arg});
2568 };2568 };
2569 } else if (mem.eql(u8, arg, "--stdin")) {2569 } else if (mem.eql(u8, arg, "--stdin")) {
2570 stdin_flag = true;2570 stdin_flag = true;
2571 } else if (mem.eql(u8, arg, "--check")) {2571 } else if (mem.eql(u8, arg, "--check")) {
2572 check_flag = true;2572 check_flag = true;
2573 } else {2573 } else {
2574 fatal("unrecognized parameter: '{}'", .{arg});2574 fatal("unrecognized parameter: '{s}'", .{arg});
2575 }2575 }
2576 } else {2576 } else {
2577 try input_files.append(arg);2577 try input_files.append(arg);
...@@ -2590,7 +2590,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {...@@ -2590,7 +2590,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
2590 defer gpa.free(source_code);2590 defer gpa.free(source_code);
25912591
2592 const tree = std.zig.parse(gpa, source_code) catch |err| {2592 const tree = std.zig.parse(gpa, source_code) catch |err| {
2593 fatal("error parsing stdin: {}", .{err});2593 fatal("error parsing stdin: {s}", .{err});
2594 };2594 };
2595 defer tree.deinit();2595 defer tree.deinit();
25962596
...@@ -2629,7 +2629,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {...@@ -2629,7 +2629,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
2629 for (input_files.items) |file_path| {2629 for (input_files.items) |file_path| {
2630 // Get the real path here to avoid Windows failing on relative file paths with . or .. in them.2630 // Get the real path here to avoid Windows failing on relative file paths with . or .. in them.
2631 const real_path = fs.realpathAlloc(gpa, file_path) catch |err| {2631 const real_path = fs.realpathAlloc(gpa, file_path) catch |err| {
2632 fatal("unable to open '{}': {}", .{ file_path, err });2632 fatal("unable to open '{s}': {s}", .{ file_path, @errorName(err) });
2633 };2633 };
2634 defer gpa.free(real_path);2634 defer gpa.free(real_path);
26352635
...@@ -2668,7 +2668,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_...@@ -2668,7 +2668,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_
2668 fmtPathFile(fmt, file_path, check_mode, dir, sub_path) catch |err| switch (err) {2668 fmtPathFile(fmt, file_path, check_mode, dir, sub_path) catch |err| switch (err) {
2669 error.IsDir, error.AccessDenied => return fmtPathDir(fmt, file_path, check_mode, dir, sub_path),2669 error.IsDir, error.AccessDenied => return fmtPathDir(fmt, file_path, check_mode, dir, sub_path),
2670 else => {2670 else => {
2671 warn("unable to format '{}': {}", .{ file_path, err });2671 warn("unable to format '{s}': {s}", .{ file_path, @errorName(err) });
2672 fmt.any_error = true;2672 fmt.any_error = true;
2673 return;2673 return;
2674 },2674 },
...@@ -2702,7 +2702,7 @@ fn fmtPathDir(...@@ -2702,7 +2702,7 @@ fn fmtPathDir(
2702 try fmtPathDir(fmt, full_path, check_mode, dir, entry.name);2702 try fmtPathDir(fmt, full_path, check_mode, dir, entry.name);
2703 } else {2703 } else {
2704 fmtPathFile(fmt, full_path, check_mode, dir, entry.name) catch |err| {2704 fmtPathFile(fmt, full_path, check_mode, dir, entry.name) catch |err| {
2705 warn("unable to format '{}': {}", .{ full_path, err });2705 warn("unable to format '{s}': {s}", .{ full_path, @errorName(err) });
2706 fmt.any_error = true;2706 fmt.any_error = true;
2707 return;2707 return;
2708 };2708 };
...@@ -2761,7 +2761,7 @@ fn fmtPathFile(...@@ -2761,7 +2761,7 @@ fn fmtPathFile(
2761 const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree);2761 const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree);
2762 if (anything_changed) {2762 if (anything_changed) {
2763 const stdout = io.getStdOut().writer();2763 const stdout = io.getStdOut().writer();
2764 try stdout.print("{}\n", .{file_path});2764 try stdout.print("{s}\n", .{file_path});
2765 fmt.any_error = true;2765 fmt.any_error = true;
2766 }2766 }
2767 } else {2767 } else {
...@@ -2779,7 +2779,7 @@ fn fmtPathFile(...@@ -2779,7 +2779,7 @@ fn fmtPathFile(
2779 try af.file.writeAll(fmt.out_buffer.items);2779 try af.file.writeAll(fmt.out_buffer.items);
2780 try af.finish();2780 try af.finish();
2781 const stdout = io.getStdOut().writer();2781 const stdout = io.getStdOut().writer();
2782 try stdout.print("{}\n", .{file_path});2782 try stdout.print("{s}\n", .{file_path});
2783 }2783 }
2784}2784}
27852785
...@@ -2812,7 +2812,7 @@ fn printErrMsgToFile(...@@ -2812,7 +2812,7 @@ fn printErrMsgToFile(
2812 const text = text_buf.items;2812 const text = text_buf.items;
28132813
2814 const stream = file.outStream();2814 const stream = file.outStream();
2815 try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });2815 try stream.print("{s}:{}:{}: error: {s}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
28162816
2817 if (!color_on) return;2817 if (!color_on) return;
28182818
...@@ -2984,7 +2984,7 @@ pub const ClangArgIterator = struct {...@@ -2984,7 +2984,7 @@ pub const ClangArgIterator = struct {
2984 const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit2984 const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit
2985 const resp_file_path = arg[1..];2985 const resp_file_path = arg[1..];
2986 const resp_contents = fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes) catch |err| {2986 const resp_contents = fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes) catch |err| {
2987 fatal("unable to read response file '{}': {}", .{ resp_file_path, @errorName(err) });2987 fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) });
2988 };2988 };
2989 defer allocator.free(resp_contents);2989 defer allocator.free(resp_contents);
2990 // TODO is there a specification for this file format? Let's find it and make this parsing more robust2990 // TODO is there a specification for this file format? Let's find it and make this parsing more robust
...@@ -3057,7 +3057,7 @@ pub const ClangArgIterator = struct {...@@ -3057,7 +3057,7 @@ pub const ClangArgIterator = struct {
3057 const prefix_len = clang_arg.matchStartsWith(arg);3057 const prefix_len = clang_arg.matchStartsWith(arg);
3058 if (prefix_len == arg.len) {3058 if (prefix_len == arg.len) {
3059 if (self.next_index >= self.argv.len) {3059 if (self.next_index >= self.argv.len) {
3060 fatal("Expected parameter after '{}'", .{arg});3060 fatal("Expected parameter after '{s}'", .{arg});
3061 }3061 }
3062 self.only_arg = self.argv[self.next_index];3062 self.only_arg = self.argv[self.next_index];
3063 self.incrementArgIndex();3063 self.incrementArgIndex();
...@@ -3078,7 +3078,7 @@ pub const ClangArgIterator = struct {...@@ -3078,7 +3078,7 @@ pub const ClangArgIterator = struct {
3078 if (prefix_len != 0) {3078 if (prefix_len != 0) {
3079 self.only_arg = arg[prefix_len..];3079 self.only_arg = arg[prefix_len..];
3080 if (self.next_index >= self.argv.len) {3080 if (self.next_index >= self.argv.len) {
3081 fatal("Expected parameter after '{}'", .{arg});3081 fatal("Expected parameter after '{s}'", .{arg});
3082 }3082 }
3083 self.second_arg = self.argv[self.next_index];3083 self.second_arg = self.argv[self.next_index];
3084 self.incrementArgIndex();3084 self.incrementArgIndex();
...@@ -3089,7 +3089,7 @@ pub const ClangArgIterator = struct {...@@ -3089,7 +3089,7 @@ pub const ClangArgIterator = struct {
3089 },3089 },
3090 .separate => if (clang_arg.matchEql(arg) > 0) {3090 .separate => if (clang_arg.matchEql(arg) > 0) {
3091 if (self.next_index >= self.argv.len) {3091 if (self.next_index >= self.argv.len) {
3092 fatal("Expected parameter after '{}'", .{arg});3092 fatal("Expected parameter after '{s}'", .{arg});
3093 }3093 }
3094 self.only_arg = self.argv[self.next_index];3094 self.only_arg = self.argv[self.next_index];
3095 self.incrementArgIndex();3095 self.incrementArgIndex();
...@@ -3115,7 +3115,7 @@ pub const ClangArgIterator = struct {...@@ -3115,7 +3115,7 @@ pub const ClangArgIterator = struct {
3115 },3115 },
3116 }3116 }
3117 else {3117 else {
3118 fatal("Unknown Clang option: '{}'", .{arg});3118 fatal("Unknown Clang option: '{s}'", .{arg});
3119 }3119 }
3120 }3120 }
31213121
...@@ -3143,7 +3143,7 @@ pub const ClangArgIterator = struct {...@@ -3143,7 +3143,7 @@ pub const ClangArgIterator = struct {
31433143
3144fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {3144fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
3145 return std.meta.stringToEnum(std.builtin.CodeModel, arg) orelse3145 return std.meta.stringToEnum(std.builtin.CodeModel, arg) orelse
3146 fatal("unsupported machine code model: '{}'", .{arg});3146 fatal("unsupported machine code model: '{s}'", .{arg});
3147}3147}
31483148
3149/// Raise the open file descriptor limit. Ask and ye shall receive.3149/// Raise the open file descriptor limit. Ask and ye shall receive.
...@@ -3263,7 +3263,7 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s...@@ -3263,7 +3263,7 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s
3263 // CPU model & feature detection is todo so here we rely on LLVM.3263 // CPU model & feature detection is todo so here we rely on LLVM.
3264 // https://github.com/ziglang/zig/issues/45913264 // https://github.com/ziglang/zig/issues/4591
3265 if (!build_options.have_llvm)3265 if (!build_options.have_llvm)
3266 fatal("CPU features detection is not yet available for {} without LLVM extensions", .{@tagName(arch)});3266 fatal("CPU features detection is not yet available for {s} without LLVM extensions", .{@tagName(arch)});
32673267
3268 const llvm = @import("llvm_bindings.zig");3268 const llvm = @import("llvm_bindings.zig");
3269 const llvm_cpu_name = llvm.GetHostCPUName();3269 const llvm_cpu_name = llvm.GetHostCPUName();
src/mingw.zig+2-2
...@@ -381,7 +381,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -381,7 +381,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
381381
382 const term = child.wait() catch |err| {382 const term = child.wait() catch |err| {
383 // TODO surface a proper error here383 // TODO surface a proper error here
384 log.err("unable to spawn {}: {}", .{ args[0], @errorName(err) });384 log.err("unable to spawn {s}: {s}", .{ args[0], @errorName(err) });
385 return error.ClangPreprocessorFailed;385 return error.ClangPreprocessorFailed;
386 };386 };
387387
...@@ -395,7 +395,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -395,7 +395,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
395 },395 },
396 else => {396 else => {
397 // TODO surface a proper error here397 // TODO surface a proper error here
398 log.err("clang terminated unexpectedly with stderr: {}", .{stderr});398 log.err("clang terminated unexpectedly with stderr: {s}", .{stderr});
399 return error.ClangPreprocessorFailed;399 return error.ClangPreprocessorFailed;
400 },400 },
401 }401 }
src/musl.zig+4-4
...@@ -155,21 +155,21 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -155,21 +155,21 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
155 if (!is_arch_specific) {155 if (!is_arch_specific) {
156 // Look for an arch specific override.156 // Look for an arch specific override.
157 override_path.shrinkRetainingCapacity(0);157 override_path.shrinkRetainingCapacity(0);
158 try override_path.writer().print("{}" ++ s ++ "{}" ++ s ++ "{}.s", .{158 try override_path.writer().print("{s}" ++ s ++ "{s}" ++ s ++ "{s}.s", .{
159 dirname, arch_name, noextbasename,159 dirname, arch_name, noextbasename,
160 });160 });
161 if (source_table.contains(override_path.items))161 if (source_table.contains(override_path.items))
162 continue;162 continue;
163163
164 override_path.shrinkRetainingCapacity(0);164 override_path.shrinkRetainingCapacity(0);
165 try override_path.writer().print("{}" ++ s ++ "{}" ++ s ++ "{}.S", .{165 try override_path.writer().print("{s}" ++ s ++ "{s}" ++ s ++ "{s}.S", .{
166 dirname, arch_name, noextbasename,166 dirname, arch_name, noextbasename,
167 });167 });
168 if (source_table.contains(override_path.items))168 if (source_table.contains(override_path.items))
169 continue;169 continue;
170170
171 override_path.shrinkRetainingCapacity(0);171 override_path.shrinkRetainingCapacity(0);
172 try override_path.writer().print("{}" ++ s ++ "{}" ++ s ++ "{}.c", .{172 try override_path.writer().print("{s}" ++ s ++ "{s}" ++ s ++ "{s}.c", .{
173 dirname, arch_name, noextbasename,173 dirname, arch_name, noextbasename,
174 });174 });
175 if (source_table.contains(override_path.items))175 if (source_table.contains(override_path.items))
...@@ -322,7 +322,7 @@ fn add_cc_args(...@@ -322,7 +322,7 @@ fn add_cc_args(
322 const target = comp.getTarget();322 const target = comp.getTarget();
323 const arch_name = target_util.archMuslName(target.cpu.arch);323 const arch_name = target_util.archMuslName(target.cpu.arch);
324 const os_name = @tagName(target.os.tag);324 const os_name = @tagName(target.os.tag);
325 const triple = try std.fmt.allocPrint(arena, "{}-{}-musl", .{ arch_name, os_name });325 const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name });
326 const o_arg = if (want_O3) "-O3" else "-Os";326 const o_arg = if (want_O3) "-O3" else "-Os";
327327
328 try args.appendSlice(&[_][]const u8{328 try args.appendSlice(&[_][]const u8{
src/print_env.zig+1-1
...@@ -9,7 +9,7 @@ pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Wri...@@ -9,7 +9,7 @@ pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Wri
9 defer gpa.free(self_exe_path);9 defer gpa.free(self_exe_path);
1010
11 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(gpa, self_exe_path) catch |err| {11 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(gpa, self_exe_path) catch |err| {
12 fatal("unable to find zig installation directory: {}\n", .{@errorName(err)});12 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
13 };13 };
14 defer gpa.free(zig_lib_directory.path.?);14 defer gpa.free(zig_lib_directory.path.?);
15 defer zig_lib_directory.handle.close();15 defer zig_lib_directory.handle.close();
src/print_targets.zig+2-2
...@@ -18,7 +18,7 @@ pub fn cmdTargets(...@@ -18,7 +18,7 @@ pub fn cmdTargets(
18 native_target: Target,18 native_target: Target,
19) !void {19) !void {
20 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {20 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
21 fatal("unable to find zig installation directory: {}\n", .{@errorName(err)});21 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
22 };22 };
23 defer zig_lib_directory.handle.close();23 defer zig_lib_directory.handle.close();
24 defer allocator.free(zig_lib_directory.path.?);24 defer allocator.free(zig_lib_directory.path.?);
...@@ -61,7 +61,7 @@ pub fn cmdTargets(...@@ -61,7 +61,7 @@ pub fn cmdTargets(
61 try jws.objectField("libc");61 try jws.objectField("libc");
62 try jws.beginArray();62 try jws.beginArray();
63 for (target.available_libcs) |libc| {63 for (target.available_libcs) |libc| {
64 const tmp = try std.fmt.allocPrint(allocator, "{}-{}-{}", .{64 const tmp = try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{
65 @tagName(libc.arch), @tagName(libc.os), @tagName(libc.abi),65 @tagName(libc.arch), @tagName(libc.os), @tagName(libc.abi),
66 });66 });
67 defer allocator.free(tmp);67 defer allocator.free(tmp);
src/stage1.zig+2-2
...@@ -37,14 +37,14 @@ pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {...@@ -37,14 +37,14 @@ pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {
37 defer arena_instance.deinit();37 defer arena_instance.deinit();
38 const arena = &arena_instance.allocator;38 const arena = &arena_instance.allocator;
3939
40 const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("{}", .{"OutOfMemory"});40 const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("{s}", .{"OutOfMemory"});
41 for (args) |*arg, i| {41 for (args) |*arg, i| {
42 arg.* = mem.spanZ(argv[i]);42 arg.* = mem.spanZ(argv[i]);
43 }43 }
44 if (std.builtin.mode == .Debug) {44 if (std.builtin.mode == .Debug) {
45 stage2.mainArgs(gpa, arena, args) catch unreachable;45 stage2.mainArgs(gpa, arena, args) catch unreachable;
46 } else {46 } else {
47 stage2.mainArgs(gpa, arena, args) catch |err| fatal("{}", .{@errorName(err)});47 stage2.mainArgs(gpa, arena, args) catch |err| fatal("{s}", .{@errorName(err)});
48 }48 }
49 return 0;49 return 0;
50}50}
src/translate_c.zig+38-38
...@@ -136,7 +136,7 @@ const Scope = struct {...@@ -136,7 +136,7 @@ const Scope = struct {
136 var proposed_name = name_copy;136 var proposed_name = name_copy;
137 while (scope.contains(proposed_name)) {137 while (scope.contains(proposed_name)) {
138 scope.mangle_count += 1;138 scope.mangle_count += 1;
139 proposed_name = try std.fmt.allocPrint(c.arena, "{}_{}", .{ name, scope.mangle_count });139 proposed_name = try std.fmt.allocPrint(c.arena, "{s}_{}", .{ name, scope.mangle_count });
140 }140 }
141 try scope.variables.append(.{ .name = name_copy, .alias = proposed_name });141 try scope.variables.append(.{ .name = name_copy, .alias = proposed_name });
142 return proposed_name;142 return proposed_name;
...@@ -290,7 +290,7 @@ pub const Context = struct {...@@ -290,7 +290,7 @@ pub const Context = struct {
290290
291 const line = c.source_manager.getSpellingLineNumber(spelling_loc);291 const line = c.source_manager.getSpellingLineNumber(spelling_loc);
292 const column = c.source_manager.getSpellingColumnNumber(spelling_loc);292 const column = c.source_manager.getSpellingColumnNumber(spelling_loc);
293 return std.fmt.allocPrint(c.arena, "{}:{}:{}", .{ filename, line, column });293 return std.fmt.allocPrint(c.arena, "{s}:{d}:{d}", .{ filename, line, column });
294 }294 }
295295
296 fn createCall(c: *Context, fn_expr: *ast.Node, params_len: ast.NodeIndex) !*ast.Node.Call {296 fn createCall(c: *Context, fn_expr: *ast.Node, params_len: ast.NodeIndex) !*ast.Node.Call {
...@@ -530,7 +530,7 @@ fn declVisitor(c: *Context, decl: *const clang.Decl) Error!void {...@@ -530,7 +530,7 @@ fn declVisitor(c: *Context, decl: *const clang.Decl) Error!void {
530 },530 },
531 else => {531 else => {
532 const decl_name = try c.str(decl.getDeclKindName());532 const decl_name = try c.str(decl.getDeclKindName());
533 try emitWarning(c, decl.getLocation(), "ignoring {} declaration", .{decl_name});533 try emitWarning(c, decl.getLocation(), "ignoring {s} declaration", .{decl_name});
534 },534 },
535 }535 }
536}536}
...@@ -625,7 +625,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {...@@ -625,7 +625,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
625 const param_name = if (param.name_token) |name_tok|625 const param_name = if (param.name_token) |name_tok|
626 tokenSlice(c, name_tok)626 tokenSlice(c, name_tok)
627 else627 else
628 return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name});628 return failDecl(c, fn_decl_loc, fn_name, "function {s} parameter has no name", .{fn_name});
629629
630 const c_param = fn_decl.getParamDecl(param_id);630 const c_param = fn_decl.getParamDecl(param_id);
631 const qual_type = c_param.getOriginalType();631 const qual_type = c_param.getOriginalType();
...@@ -634,7 +634,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {...@@ -634,7 +634,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
634 const mangled_param_name = try block_scope.makeMangledName(c, param_name);634 const mangled_param_name = try block_scope.makeMangledName(c, param_name);
635635
636 if (!is_const) {636 if (!is_const) {
637 const bare_arg_name = try std.fmt.allocPrint(c.arena, "arg_{}", .{mangled_param_name});637 const bare_arg_name = try std.fmt.allocPrint(c.arena, "arg_{s}", .{mangled_param_name});
638 const arg_name = try block_scope.makeMangledName(c, bare_arg_name);638 const arg_name = try block_scope.makeMangledName(c, bare_arg_name);
639639
640 const mut_tok = try appendToken(c, .Keyword_var, "var");640 const mut_tok = try appendToken(c, .Keyword_var, "var");
...@@ -727,7 +727,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co...@@ -727,7 +727,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
727727
728 // TODO https://github.com/ziglang/zig/issues/3756728 // TODO https://github.com/ziglang/zig/issues/3756
729 // TODO https://github.com/ziglang/zig/issues/1802729 // TODO https://github.com/ziglang/zig/issues/1802
730 const checked_name = if (isZigPrimitiveType(var_name)) try std.fmt.allocPrint(c.arena, "{}_{}", .{ var_name, c.getMangle() }) else var_name;730 const checked_name = if (isZigPrimitiveType(var_name)) try std.fmt.allocPrint(c.arena, "{s}_{d}", .{ var_name, c.getMangle() }) else var_name;
731 const var_decl_loc = var_decl.getLocation();731 const var_decl_loc = var_decl.getLocation();
732732
733 const qual_type = var_decl.getTypeSourceInfo_getType();733 const qual_type = var_decl.getTypeSourceInfo_getType();
...@@ -808,7 +808,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co...@@ -808,7 +808,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
808 _ = try appendToken(rp.c, .LParen, "(");808 _ = try appendToken(rp.c, .LParen, "(");
809 const expr = try transCreateNodeStringLiteral(809 const expr = try transCreateNodeStringLiteral(
810 rp.c,810 rp.c,
811 try std.fmt.allocPrint(rp.c.arena, "\"{}\"", .{str_ptr[0..str_len]}),811 try std.fmt.allocPrint(rp.c.arena, "\"{s}\"", .{str_ptr[0..str_len]}),
812 );812 );
813 _ = try appendToken(rp.c, .RParen, ")");813 _ = try appendToken(rp.c, .RParen, ")");
814814
...@@ -887,7 +887,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const clang.TypedefNameDecl, top_lev...@@ -887,7 +887,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const clang.TypedefNameDecl, top_lev
887887
888 // TODO https://github.com/ziglang/zig/issues/3756888 // TODO https://github.com/ziglang/zig/issues/3756
889 // TODO https://github.com/ziglang/zig/issues/1802889 // TODO https://github.com/ziglang/zig/issues/1802
890 const checked_name = if (isZigPrimitiveType(typedef_name)) try std.fmt.allocPrint(c.arena, "{}_{}", .{ typedef_name, c.getMangle() }) else typedef_name;890 const checked_name = if (isZigPrimitiveType(typedef_name)) try std.fmt.allocPrint(c.arena, "{s}_{d}", .{ typedef_name, c.getMangle() }) else typedef_name;
891 if (checkForBuiltinTypedef(checked_name)) |builtin| {891 if (checkForBuiltinTypedef(checked_name)) |builtin| {
892 return transTypeDefAsBuiltin(c, typedef_decl, builtin);892 return transTypeDefAsBuiltin(c, typedef_decl, builtin);
893 }893 }
...@@ -958,11 +958,11 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as...@@ -958,11 +958,11 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as
958 container_kind_name = "struct";958 container_kind_name = "struct";
959 container_kind = .Keyword_struct;959 container_kind = .Keyword_struct;
960 } else {960 } else {
961 try emitWarning(c, record_loc, "record {} is not a struct or union", .{bare_name});961 try emitWarning(c, record_loc, "record {s} is not a struct or union", .{bare_name});
962 return null;962 return null;
963 }963 }
964964
965 const name = try std.fmt.allocPrint(c.arena, "{}_{}", .{ container_kind_name, bare_name });965 const name = try std.fmt.allocPrint(c.arena, "{s}_{s}", .{ container_kind_name, bare_name });
966 _ = try c.decl_table.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), name);966 _ = try c.decl_table.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), name);
967967
968 const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null;968 const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null;
...@@ -1003,7 +1003,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as...@@ -1003,7 +1003,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as
1003 _ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});1003 _ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
1004 const opaque_type = try transCreateNodeOpaqueType(c);1004 const opaque_type = try transCreateNodeOpaqueType(c);
1005 semicolon = try appendToken(c, .Semicolon, ";");1005 semicolon = try appendToken(c, .Semicolon, ";");
1006 try emitWarning(c, field_loc, "{} demoted to opaque type - has bitfield", .{container_kind_name});1006 try emitWarning(c, field_loc, "{s} demoted to opaque type - has bitfield", .{container_kind_name});
1007 break :blk opaque_type;1007 break :blk opaque_type;
1008 }1008 }
10091009
...@@ -1011,7 +1011,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as...@@ -1011,7 +1011,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as
1011 _ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});1011 _ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
1012 const opaque_type = try transCreateNodeOpaqueType(c);1012 const opaque_type = try transCreateNodeOpaqueType(c);
1013 semicolon = try appendToken(c, .Semicolon, ";");1013 semicolon = try appendToken(c, .Semicolon, ";");
1014 try emitWarning(c, field_loc, "{} demoted to opaque type - has variable length array", .{container_kind_name});1014 try emitWarning(c, field_loc, "{s} demoted to opaque type - has variable length array", .{container_kind_name});
1015 break :blk opaque_type;1015 break :blk opaque_type;
1016 }1016 }
10171017
...@@ -1030,7 +1030,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as...@@ -1030,7 +1030,7 @@ fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*as
1030 _ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});1030 _ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
1031 const opaque_type = try transCreateNodeOpaqueType(c);1031 const opaque_type = try transCreateNodeOpaqueType(c);
1032 semicolon = try appendToken(c, .Semicolon, ";");1032 semicolon = try appendToken(c, .Semicolon, ";");
1033 try emitWarning(c, record_loc, "{} demoted to opaque type - unable to translate type of field {}", .{ container_kind_name, raw_name });1033 try emitWarning(c, record_loc, "{s} demoted to opaque type - unable to translate type of field {s}", .{ container_kind_name, raw_name });
1034 break :blk opaque_type;1034 break :blk opaque_type;
1035 },1035 },
1036 else => |e| return e,1036 else => |e| return e,
...@@ -1114,7 +1114,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const clang.EnumDecl) Error!?*ast.Node...@@ -1114,7 +1114,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const clang.EnumDecl) Error!?*ast.Node
1114 is_unnamed = true;1114 is_unnamed = true;
1115 }1115 }
11161116
1117 const name = try std.fmt.allocPrint(c.arena, "enum_{}", .{bare_name});1117 const name = try std.fmt.allocPrint(c.arena, "enum_{s}", .{bare_name});
1118 _ = try c.decl_table.put(c.gpa, @ptrToInt(enum_decl.getCanonicalDecl()), name);1118 _ = try c.decl_table.put(c.gpa, @ptrToInt(enum_decl.getCanonicalDecl()), name);
11191119
1120 const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null;1120 const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null;
...@@ -1385,7 +1385,7 @@ fn transStmt(...@@ -1385,7 +1385,7 @@ fn transStmt(
1385 rp,1385 rp,
1386 error.UnsupportedTranslation,1386 error.UnsupportedTranslation,
1387 stmt.getBeginLoc(),1387 stmt.getBeginLoc(),
1388 "TODO implement translation of stmt class {}",1388 "TODO implement translation of stmt class {s}",
1389 .{@tagName(sc)},1389 .{@tagName(sc)},
1390 );1390 );
1391 },1391 },
...@@ -1684,7 +1684,7 @@ fn transDeclStmtOne(...@@ -1684,7 +1684,7 @@ fn transDeclStmtOne(
1684 rp,1684 rp,
1685 error.UnsupportedTranslation,1685 error.UnsupportedTranslation,
1686 decl.getLocation(),1686 decl.getLocation(),
1687 "TODO implement translation of DeclStmt kind {}",1687 "TODO implement translation of DeclStmt kind {s}",
1688 .{@tagName(kind)},1688 .{@tagName(kind)},
1689 ),1689 ),
1690 }1690 }
...@@ -1782,7 +1782,7 @@ fn transImplicitCastExpr(...@@ -1782,7 +1782,7 @@ fn transImplicitCastExpr(
1782 rp,1782 rp,
1783 error.UnsupportedTranslation,1783 error.UnsupportedTranslation,
1784 @ptrCast(*const clang.Stmt, expr).getBeginLoc(),1784 @ptrCast(*const clang.Stmt, expr).getBeginLoc(),
1785 "TODO implement translation of CastKind {}",1785 "TODO implement translation of CastKind {s}",
1786 .{@tagName(kind)},1786 .{@tagName(kind)},
1787 ),1787 ),
1788 }1788 }
...@@ -2043,7 +2043,7 @@ fn transStringLiteral(...@@ -2043,7 +2043,7 @@ fn transStringLiteral(
2043 rp,2043 rp,
2044 error.UnsupportedTranslation,2044 error.UnsupportedTranslation,
2045 @ptrCast(*const clang.Stmt, stmt).getBeginLoc(),2045 @ptrCast(*const clang.Stmt, stmt).getBeginLoc(),
2046 "TODO: support string literal kind {}",2046 "TODO: support string literal kind {s}",
2047 .{kind},2047 .{kind},
2048 ),2048 ),
2049 }2049 }
...@@ -2168,7 +2168,6 @@ fn transCCast(...@@ -2168,7 +2168,6 @@ fn transCCast(
2168 // @boolToInt returns either a comptime_int or a u12168 // @boolToInt returns either a comptime_int or a u1
2169 // TODO: if dst_type is 1 bit & signed (bitfield) we need @bitCast2169 // TODO: if dst_type is 1 bit & signed (bitfield) we need @bitCast
2170 // instead of @as2170 // instead of @as
2171
2172 const builtin_node = try rp.c.createBuiltinCall("@boolToInt", 1);2171 const builtin_node = try rp.c.createBuiltinCall("@boolToInt", 1);
2173 builtin_node.params()[0] = expr;2172 builtin_node.params()[0] = expr;
2174 builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")");2173 builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")");
...@@ -2455,7 +2454,7 @@ fn transInitListExpr(...@@ -2455,7 +2454,7 @@ fn transInitListExpr(
2455 );2454 );
2456 } else {2455 } else {
2457 const type_name = rp.c.str(qual_type.getTypeClassName());2456 const type_name = rp.c.str(qual_type.getTypeClassName());
2458 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported initlist type: '{}'", .{type_name});2457 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported initlist type: '{s}'", .{type_name});
2459 }2458 }
2460}2459}
24612460
...@@ -4433,7 +4432,8 @@ fn transCreateNodeBoolLiteral(c: *Context, value: bool) !*ast.Node {...@@ -4433,7 +4432,8 @@ fn transCreateNodeBoolLiteral(c: *Context, value: bool) !*ast.Node {
4433}4432}
44344433
4435fn transCreateNodeInt(c: *Context, int: anytype) !*ast.Node {4434fn transCreateNodeInt(c: *Context, int: anytype) !*ast.Node {
4436 const token = try appendTokenFmt(c, .IntegerLiteral, "{}", .{int});4435 const fmt_s = if (comptime std.meta.trait.isIntegerNumber(@TypeOf(int))) "{d}" else "{s}";
4436 const token = try appendTokenFmt(c, .IntegerLiteral, fmt_s, .{int});
4437 const node = try c.arena.create(ast.Node.OneToken);4437 const node = try c.arena.create(ast.Node.OneToken);
4438 node.* = .{4438 node.* = .{
4439 .base = .{ .tag = .IntegerLiteral },4439 .base = .{ .tag = .IntegerLiteral },
...@@ -4442,8 +4442,8 @@ fn transCreateNodeInt(c: *Context, int: anytype) !*ast.Node {...@@ -4442,8 +4442,8 @@ fn transCreateNodeInt(c: *Context, int: anytype) !*ast.Node {
4442 return &node.base;4442 return &node.base;
4443}4443}
44444444
4445fn transCreateNodeFloat(c: *Context, int: anytype) !*ast.Node {4445fn transCreateNodeFloat(c: *Context, str: []const u8) !*ast.Node {
4446 const token = try appendTokenFmt(c, .FloatLiteral, "{}", .{int});4446 const token = try appendTokenFmt(c, .FloatLiteral, "{s}", .{str});
4447 const node = try c.arena.create(ast.Node.OneToken);4447 const node = try c.arena.create(ast.Node.OneToken);
4448 node.* = .{4448 node.* = .{
4449 .base = .{ .tag = .FloatLiteral },4449 .base = .{ .tag = .FloatLiteral },
...@@ -4916,7 +4916,7 @@ fn transType(rp: RestorePoint, ty: *const clang.Type, source_loc: clang.SourceLo...@@ -4916,7 +4916,7 @@ fn transType(rp: RestorePoint, ty: *const clang.Type, source_loc: clang.SourceLo
4916 },4916 },
4917 else => {4917 else => {
4918 const type_name = rp.c.str(ty.getTypeClassName());4918 const type_name = rp.c.str(ty.getTypeClassName());
4919 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name});4919 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{s}'", .{type_name});
4920 },4920 },
4921 }4921 }
4922}4922}
...@@ -4999,7 +4999,7 @@ fn transCC(...@@ -4999,7 +4999,7 @@ fn transCC(
4999 rp,4999 rp,
5000 error.UnsupportedType,5000 error.UnsupportedType,
5001 source_loc,5001 source_loc,
5002 "unsupported calling convention: {}",5002 "unsupported calling convention: {s}",
5003 .{@tagName(clang_cc)},5003 .{@tagName(clang_cc)},
5004 ),5004 ),
5005 }5005 }
...@@ -5117,7 +5117,7 @@ fn finishTransFnProto(...@@ -5117,7 +5117,7 @@ fn finishTransFnProto(
5117 _ = try appendToken(rp.c, .LParen, "(");5117 _ = try appendToken(rp.c, .LParen, "(");
5118 const expr = try transCreateNodeStringLiteral(5118 const expr = try transCreateNodeStringLiteral(
5119 rp.c,5119 rp.c,
5120 try std.fmt.allocPrint(rp.c.arena, "\"{}\"", .{str_ptr[0..str_len]}),5120 try std.fmt.allocPrint(rp.c.arena, "\"{s}\"", .{str_ptr[0..str_len]}),
5121 );5121 );
5122 _ = try appendToken(rp.c, .RParen, ")");5122 _ = try appendToken(rp.c, .RParen, ")");
51235123
...@@ -5214,7 +5214,7 @@ fn revertAndWarn(...@@ -5214,7 +5214,7 @@ fn revertAndWarn(
52145214
5215fn emitWarning(c: *Context, loc: clang.SourceLocation, comptime format: []const u8, args: anytype) !void {5215fn emitWarning(c: *Context, loc: clang.SourceLocation, comptime format: []const u8, args: anytype) !void {
5216 const args_prefix = .{c.locStr(loc)};5216 const args_prefix = .{c.locStr(loc)};
5217 _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args);5217 _ = try appendTokenFmt(c, .LineComment, "// {s}: warning: " ++ format, args_prefix ++ args);
5218}5218}
52195219
5220pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, comptime format: []const u8, args: anytype) !void {5220pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, comptime format: []const u8, args: anytype) !void {
...@@ -5228,7 +5228,7 @@ pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, compti...@@ -5228,7 +5228,7 @@ pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, compti
5228 const msg_tok = try appendTokenFmt(c, .StringLiteral, "\"" ++ format ++ "\"", args);5228 const msg_tok = try appendTokenFmt(c, .StringLiteral, "\"" ++ format ++ "\"", args);
5229 const rparen_tok = try appendToken(c, .RParen, ")");5229 const rparen_tok = try appendToken(c, .RParen, ")");
5230 const semi_tok = try appendToken(c, .Semicolon, ";");5230 const semi_tok = try appendToken(c, .Semicolon, ";");
5231 _ = try appendTokenFmt(c, .LineComment, "// {}", .{c.locStr(loc)});5231 _ = try appendTokenFmt(c, .LineComment, "// {s}", .{c.locStr(loc)});
52325232
5233 const msg_node = try c.arena.create(ast.Node.OneToken);5233 const msg_node = try c.arena.create(ast.Node.OneToken);
5234 msg_node.* = .{5234 msg_node.* = .{
...@@ -5258,7 +5258,7 @@ pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, compti...@@ -5258,7 +5258,7 @@ pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, compti
52585258
5259fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex {5259fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex {
5260 std.debug.assert(token_id != .Identifier); // use appendIdentifier5260 std.debug.assert(token_id != .Identifier); // use appendIdentifier
5261 return appendTokenFmt(c, token_id, "{}", .{bytes});5261 return appendTokenFmt(c, token_id, "{s}", .{bytes});
5262}5262}
52635263
5264fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: anytype) !ast.TokenIndex {5264fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: anytype) !ast.TokenIndex {
...@@ -5329,7 +5329,7 @@ fn transCreateNodeIdentifier(c: *Context, name: []const u8) !*ast.Node {...@@ -5329,7 +5329,7 @@ fn transCreateNodeIdentifier(c: *Context, name: []const u8) !*ast.Node {
5329}5329}
53305330
5331fn transCreateNodeIdentifierUnchecked(c: *Context, name: []const u8) !*ast.Node {5331fn transCreateNodeIdentifierUnchecked(c: *Context, name: []const u8) !*ast.Node {
5332 const token_index = try appendTokenFmt(c, .Identifier, "{}", .{name});5332 const token_index = try appendTokenFmt(c, .Identifier, "{s}", .{name});
5333 const identifier = try c.arena.create(ast.Node.OneToken);5333 const identifier = try c.arena.create(ast.Node.OneToken);
5334 identifier.* = .{5334 identifier.* = .{
5335 .base = .{ .tag = .Identifier },5335 .base = .{ .tag = .Identifier },
...@@ -5390,7 +5390,7 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void {...@@ -5390,7 +5390,7 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void {
5390 const name = try c.str(raw_name);5390 const name = try c.str(raw_name);
5391 // TODO https://github.com/ziglang/zig/issues/37565391 // TODO https://github.com/ziglang/zig/issues/3756
5392 // TODO https://github.com/ziglang/zig/issues/18025392 // TODO https://github.com/ziglang/zig/issues/1802
5393 const mangled_name = if (isZigPrimitiveType(name)) try std.fmt.allocPrint(c.arena, "{}_{}", .{ name, c.getMangle() }) else name;5393 const mangled_name = if (isZigPrimitiveType(name)) try std.fmt.allocPrint(c.arena, "{s}_{d}", .{ name, c.getMangle() }) else name;
5394 if (scope.containsNow(mangled_name)) {5394 if (scope.containsNow(mangled_name)) {
5395 continue;5395 continue;
5396 }5396 }
...@@ -5468,7 +5468,7 @@ fn transMacroDefine(c: *Context, m: *MacroCtx) ParseError!void {...@@ -5468,7 +5468,7 @@ fn transMacroDefine(c: *Context, m: *MacroCtx) ParseError!void {
5468 const init_node = try parseCExpr(c, m, scope);5468 const init_node = try parseCExpr(c, m, scope);
5469 const last = m.next().?;5469 const last = m.next().?;
5470 if (last != .Eof and last != .Nl)5470 if (last != .Eof and last != .Nl)
5471 return m.fail(c, "unable to translate C expr: unexpected token .{}", .{@tagName(last)});5471 return m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(last)});
54725472
5473 const semicolon_token = try appendToken(c, .Semicolon, ";");5473 const semicolon_token = try appendToken(c, .Semicolon, ";");
5474 const node = try ast.Node.VarDecl.create(c.arena, .{5474 const node = try ast.Node.VarDecl.create(c.arena, .{
...@@ -5540,7 +5540,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {...@@ -5540,7 +5540,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {
5540 const expr = try parseCExpr(c, m, scope);5540 const expr = try parseCExpr(c, m, scope);
5541 const last = m.next().?;5541 const last = m.next().?;
5542 if (last != .Eof and last != .Nl)5542 if (last != .Eof and last != .Nl)
5543 return m.fail(c, "unable to translate C expr: unexpected token .{}", .{@tagName(last)});5543 return m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(last)});
5544 _ = try appendToken(c, .Semicolon, ";");5544 _ = try appendToken(c, .Semicolon, ";");
5545 const type_of_arg = if (!expr.tag.isBlock()) expr else blk: {5545 const type_of_arg = if (!expr.tag.isBlock()) expr else blk: {
5546 const stmts = expr.blockStatements();5546 const stmts = expr.blockStatements();
...@@ -5623,11 +5623,11 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!*ast.Node {...@@ -5623,11 +5623,11 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!*ast.Node {
5623 switch (lit_bytes[1]) {5623 switch (lit_bytes[1]) {
5624 '0'...'7' => {5624 '0'...'7' => {
5625 // Octal5625 // Octal
5626 lit_bytes = try std.fmt.allocPrint(c.arena, "0o{}", .{lit_bytes});5626 lit_bytes = try std.fmt.allocPrint(c.arena, "0o{s}", .{lit_bytes});
5627 },5627 },
5628 'X' => {5628 'X' => {
5629 // Hexadecimal with capital X, valid in C but not in Zig5629 // Hexadecimal with capital X, valid in C but not in Zig
5630 lit_bytes = try std.fmt.allocPrint(c.arena, "0x{}", .{lit_bytes[2..]});5630 lit_bytes = try std.fmt.allocPrint(c.arena, "0x{s}", .{lit_bytes[2..]});
5631 },5631 },
5632 else => {},5632 else => {},
5633 }5633 }
...@@ -5659,7 +5659,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!*ast.Node {...@@ -5659,7 +5659,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!*ast.Node {
5659 },5659 },
5660 .FloatLiteral => |suffix| {5660 .FloatLiteral => |suffix| {
5661 if (lit_bytes[0] == '.')5661 if (lit_bytes[0] == '.')
5662 lit_bytes = try std.fmt.allocPrint(c.arena, "0{}", .{lit_bytes});5662 lit_bytes = try std.fmt.allocPrint(c.arena, "0{s}", .{lit_bytes});
5663 if (suffix == .none) {5663 if (suffix == .none) {
5664 return transCreateNodeFloat(c, lit_bytes);5664 return transCreateNodeFloat(c, lit_bytes);
5665 }5665 }
...@@ -5937,7 +5937,7 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*...@@ -5937,7 +5937,7 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*
59375937
5938 const next_id = m.next().?;5938 const next_id = m.next().?;
5939 if (next_id != .RParen) {5939 if (next_id != .RParen) {
5940 try m.fail(c, "unable to translate C expr: expected ')' instead got: {}", .{@tagName(next_id)});5940 try m.fail(c, "unable to translate C expr: expected ')' instead got: {s}", .{@tagName(next_id)});
5941 return error.ParseError;5941 return error.ParseError;
5942 }5942 }
5943 var saw_l_paren = false;5943 var saw_l_paren = false;
...@@ -5995,7 +5995,7 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*...@@ -5995,7 +5995,7 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*
5995 return &group_node.base;5995 return &group_node.base;
5996 },5996 },
5997 else => {5997 else => {
5998 try m.fail(c, "unable to translate C expr: unexpected token .{}", .{@tagName(tok)});5998 try m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(tok)});
5999 return error.ParseError;5999 return error.ParseError;
6000 },6000 },
6001 }6001 }
src/value.zig+2-2
...@@ -464,7 +464,7 @@ pub const Value = extern union {...@@ -464,7 +464,7 @@ pub const Value = extern union {
464 .ty => return val.castTag(.ty).?.data.format("", options, out_stream),464 .ty => return val.castTag(.ty).?.data.format("", options, out_stream),
465 .int_type => {465 .int_type => {
466 const int_type = val.castTag(.int_type).?.data;466 const int_type = val.castTag(.int_type).?.data;
467 return out_stream.print("{}{}", .{467 return out_stream.print("{s}{d}", .{
468 if (int_type.signed) "s" else "u",468 if (int_type.signed) "s" else "u",
469 int_type.bits,469 int_type.bits,
470 });470 });
...@@ -507,7 +507,7 @@ pub const Value = extern union {...@@ -507,7 +507,7 @@ pub const Value = extern union {
507 }507 }
508 return out_stream.writeAll("}");508 return out_stream.writeAll("}");
509 },509 },
510 .@"error" => return out_stream.print("error.{}", .{val.castTag(.@"error").?.data.name}),510 .@"error" => return out_stream.print("error.{s}", .{val.castTag(.@"error").?.data.name}),
511 .inferred_alloc => return out_stream.writeAll("(inferred allocation value)"),511 .inferred_alloc => return out_stream.writeAll("(inferred allocation value)"),
512 };512 };
513 }513 }
src/zir.zig+22-22
...@@ -1150,7 +1150,7 @@ pub const Module = struct {...@@ -1150,7 +1150,7 @@ pub const Module = struct {
11501150
1151 for (self.decls) |decl, i| {1151 for (self.decls) |decl, i| {
1152 write.next_instr_index = 0;1152 write.next_instr_index = 0;
1153 try stream.print("@{} ", .{decl.name});1153 try stream.print("@{s} ", .{decl.name});
1154 try write.writeInstToStream(stream, decl.inst);1154 try write.writeInstToStream(stream, decl.inst);
1155 try stream.writeByte('\n');1155 try stream.writeByte('\n');
1156 }1156 }
...@@ -1206,13 +1206,13 @@ const Writer = struct {...@@ -1206,13 +1206,13 @@ const Writer = struct {
1206 if (@typeInfo(arg_field.field_type) == .Optional) {1206 if (@typeInfo(arg_field.field_type) == .Optional) {
1207 if (@field(inst.kw_args, arg_field.name)) |non_optional| {1207 if (@field(inst.kw_args, arg_field.name)) |non_optional| {
1208 if (need_comma) try stream.writeAll(", ");1208 if (need_comma) try stream.writeAll(", ");
1209 try stream.print("{}=", .{arg_field.name});1209 try stream.print("{s}=", .{arg_field.name});
1210 try self.writeParamToStream(stream, &non_optional);1210 try self.writeParamToStream(stream, &non_optional);
1211 need_comma = true;1211 need_comma = true;
1212 }1212 }
1213 } else {1213 } else {
1214 if (need_comma) try stream.writeAll(", ");1214 if (need_comma) try stream.writeAll(", ");
1215 try stream.print("{}=", .{arg_field.name});1215 try stream.print("{s}=", .{arg_field.name});
1216 try self.writeParamToStream(stream, &@field(inst.kw_args, arg_field.name));1216 try self.writeParamToStream(stream, &@field(inst.kw_args, arg_field.name));
1217 need_comma = true;1217 need_comma = true;
1218 }1218 }
...@@ -1334,16 +1334,16 @@ const Writer = struct {...@@ -1334,16 +1334,16 @@ const Writer = struct {
1334 if (info.index) |i| {1334 if (info.index) |i| {
1335 try stream.print("%{}", .{info.index});1335 try stream.print("%{}", .{info.index});
1336 } else {1336 } else {
1337 try stream.print("@{}", .{info.name});1337 try stream.print("@{s}", .{info.name});
1338 }1338 }
1339 } else if (inst.cast(Inst.DeclVal)) |decl_val| {1339 } else if (inst.cast(Inst.DeclVal)) |decl_val| {
1340 try stream.print("@{}", .{decl_val.positionals.name});1340 try stream.print("@{s}", .{decl_val.positionals.name});
1341 } else if (inst.cast(Inst.DeclValInModule)) |decl_val| {1341 } else if (inst.cast(Inst.DeclValInModule)) |decl_val| {
1342 try stream.print("@{}", .{decl_val.positionals.decl.name});1342 try stream.print("@{s}", .{decl_val.positionals.decl.name});
1343 } else {1343 } else {
1344 // This should be unreachable in theory, but since ZIR is used for debugging the compiler1344 // This should be unreachable in theory, but since ZIR is used for debugging the compiler
1345 // we output some debug text instead.1345 // we output some debug text instead.
1346 try stream.print("?{}?", .{@tagName(inst.tag)});1346 try stream.print("?{s}?", .{@tagName(inst.tag)});
1347 }1347 }
1348 }1348 }
1349};1349};
...@@ -1424,7 +1424,7 @@ const Parser = struct {...@@ -1424,7 +1424,7 @@ const Parser = struct {
1424 const decl = try parseInstruction(self, &body_context, ident);1424 const decl = try parseInstruction(self, &body_context, ident);
1425 const ident_index = body_context.instructions.items.len;1425 const ident_index = body_context.instructions.items.len;
1426 if (try body_context.name_map.fetchPut(ident, decl.inst)) |_| {1426 if (try body_context.name_map.fetchPut(ident, decl.inst)) |_| {
1427 return self.fail("redefinition of identifier '{}'", .{ident});1427 return self.fail("redefinition of identifier '{s}'", .{ident});
1428 }1428 }
1429 try body_context.instructions.append(decl.inst);1429 try body_context.instructions.append(decl.inst);
1430 continue;1430 continue;
...@@ -1510,7 +1510,7 @@ const Parser = struct {...@@ -1510,7 +1510,7 @@ const Parser = struct {
1510 const decl = try parseInstruction(self, null, ident);1510 const decl = try parseInstruction(self, null, ident);
1511 const ident_index = self.decls.items.len;1511 const ident_index = self.decls.items.len;
1512 if (try self.global_name_map.fetchPut(ident, decl.inst)) |_| {1512 if (try self.global_name_map.fetchPut(ident, decl.inst)) |_| {
1513 return self.fail("redefinition of identifier '{}'", .{ident});1513 return self.fail("redefinition of identifier '{s}'", .{ident});
1514 }1514 }
1515 try self.decls.append(self.allocator, decl);1515 try self.decls.append(self.allocator, decl);
1516 },1516 },
...@@ -1538,7 +1538,7 @@ const Parser = struct {...@@ -1538,7 +1538,7 @@ const Parser = struct {
1538 for (bytes) |byte| {1538 for (bytes) |byte| {
1539 if (self.source[self.i] != byte) {1539 if (self.source[self.i] != byte) {
1540 self.i = start;1540 self.i = start;
1541 return self.fail("expected '{}'", .{bytes});1541 return self.fail("expected '{s}'", .{bytes});
1542 }1542 }
1543 self.i += 1;1543 self.i += 1;
1544 }1544 }
...@@ -1585,7 +1585,7 @@ const Parser = struct {...@@ -1585,7 +1585,7 @@ const Parser = struct {
1585 return parseInstructionGeneric(self, field.name, tag.Type(), tag, body_ctx, name, contents_start);1585 return parseInstructionGeneric(self, field.name, tag.Type(), tag, body_ctx, name, contents_start);
1586 }1586 }
1587 }1587 }
1588 return self.fail("unknown instruction '{}'", .{fn_name});1588 return self.fail("unknown instruction '{s}'", .{fn_name});
1589 }1589 }
15901590
1591 fn parseInstructionGeneric(1591 fn parseInstructionGeneric(
...@@ -1621,7 +1621,7 @@ const Parser = struct {...@@ -1621,7 +1621,7 @@ const Parser = struct {
1621 self.i += 1;1621 self.i += 1;
1622 skipSpace(self);1622 skipSpace(self);
1623 } else if (self.source[self.i] == ')') {1623 } else if (self.source[self.i] == ')') {
1624 return self.fail("expected positional parameter '{}'", .{arg_field.name});1624 return self.fail("expected positional parameter '{s}'", .{arg_field.name});
1625 }1625 }
1626 @field(inst_specific.positionals, arg_field.name) = try parseParameterGeneric(1626 @field(inst_specific.positionals, arg_field.name) = try parseParameterGeneric(
1627 self,1627 self,
...@@ -1648,7 +1648,7 @@ const Parser = struct {...@@ -1648,7 +1648,7 @@ const Parser = struct {
1648 break;1648 break;
1649 }1649 }
1650 } else {1650 } else {
1651 return self.fail("unrecognized keyword parameter: '{}'", .{name});1651 return self.fail("unrecognized keyword parameter: '{s}'", .{name});
1652 }1652 }
1653 skipSpace(self);1653 skipSpace(self);
1654 }1654 }
...@@ -1672,7 +1672,7 @@ const Parser = struct {...@@ -1672,7 +1672,7 @@ const Parser = struct {
1672 ' ', '\n', ',', ')' => {1672 ' ', '\n', ',', ')' => {
1673 const enum_name = self.source[start..self.i];1673 const enum_name = self.source[start..self.i];
1674 return std.meta.stringToEnum(T, enum_name) orelse {1674 return std.meta.stringToEnum(T, enum_name) orelse {
1675 return self.fail("tag '{}' not a member of enum '{}'", .{ enum_name, @typeName(T) });1675 return self.fail("tag '{s}' not a member of enum '{s}'", .{ enum_name, @typeName(T) });
1676 };1676 };
1677 },1677 },
1678 0 => return self.failByte(0),1678 0 => return self.failByte(0),
...@@ -1710,7 +1710,7 @@ const Parser = struct {...@@ -1710,7 +1710,7 @@ const Parser = struct {
1710 BigIntConst => return self.parseIntegerLiteral(),1710 BigIntConst => return self.parseIntegerLiteral(),
1711 usize => {1711 usize => {
1712 const big_int = try self.parseIntegerLiteral();1712 const big_int = try self.parseIntegerLiteral();
1713 return big_int.to(usize) catch |err| return self.fail("integer literal: {}", .{@errorName(err)});1713 return big_int.to(usize) catch |err| return self.fail("integer literal: {s}", .{@errorName(err)});
1714 },1714 },
1715 TypedValue => return self.fail("'const' is a special instruction; not legal in ZIR text", .{}),1715 TypedValue => return self.fail("'const' is a special instruction; not legal in ZIR text", .{}),
1716 *IrModule.Decl => return self.fail("'declval_in_module' is a special instruction; not legal in ZIR text", .{}),1716 *IrModule.Decl => return self.fail("'declval_in_module' is a special instruction; not legal in ZIR text", .{}),
...@@ -1759,7 +1759,7 @@ const Parser = struct {...@@ -1759,7 +1759,7 @@ const Parser = struct {
1759 },1759 },
1760 else => @compileError("Unimplemented: ir parseParameterGeneric for type " ++ @typeName(T)),1760 else => @compileError("Unimplemented: ir parseParameterGeneric for type " ++ @typeName(T)),
1761 }1761 }
1762 return self.fail("TODO parse parameter {}", .{@typeName(T)});1762 return self.fail("TODO parse parameter {s}", .{@typeName(T)});
1763 }1763 }
17641764
1765 fn parseParameterInst(self: *Parser, body_ctx: ?*Body) !*Inst {1765 fn parseParameterInst(self: *Parser, body_ctx: ?*Body) !*Inst {
...@@ -1788,7 +1788,7 @@ const Parser = struct {...@@ -1788,7 +1788,7 @@ const Parser = struct {
1788 const src = name_start - 1;1788 const src = name_start - 1;
1789 if (local_ref) {1789 if (local_ref) {
1790 self.i = src;1790 self.i = src;
1791 return self.fail("unrecognized identifier: {}", .{bad_name});1791 return self.fail("unrecognized identifier: {s}", .{bad_name});
1792 } else {1792 } else {
1793 const declval = try self.arena.allocator.create(Inst.DeclVal);1793 const declval = try self.arena.allocator.create(Inst.DeclVal);
1794 declval.* = .{1794 declval.* = .{
...@@ -1873,7 +1873,7 @@ pub fn dumpFn(old_module: IrModule, module_fn: *IrModule.Fn) void {...@@ -1873,7 +1873,7 @@ pub fn dumpFn(old_module: IrModule, module_fn: *IrModule.Fn) void {
18731873
1874 const fn_ty = module_fn.owner_decl.typed_value.most_recent.typed_value.ty;1874 const fn_ty = module_fn.owner_decl.typed_value.most_recent.typed_value.ty;
1875 _ = ctx.emitFn(module_fn, 0, fn_ty) catch |err| {1875 _ = ctx.emitFn(module_fn, 0, fn_ty) catch |err| {
1876 std.debug.print("unable to dump function: {}\n", .{err});1876 std.debug.print("unable to dump function: {s}\n", .{@errorName(err)});
1877 return;1877 return;
1878 };1878 };
1879 var module = Module{1879 var module = Module{
...@@ -2203,7 +2203,7 @@ const EmitZIR = struct {...@@ -2203,7 +2203,7 @@ const EmitZIR = struct {
2203 };2203 };
2204 return self.emitStringLiteral(src, bytes);2204 return self.emitStringLiteral(src, bytes);
2205 },2205 },
2206 else => |t| std.debug.panic("TODO implement emitTypedValue for pointer to {}", .{@tagName(t)}),2206 else => |t| std.debug.panic("TODO implement emitTypedValue for pointer to {s}", .{@tagName(t)}),
2207 }2207 }
2208 },2208 },
2209 .ComptimeInt => return self.emitComptimeIntVal(src, typed_value.val),2209 .ComptimeInt => return self.emitComptimeIntVal(src, typed_value.val),
...@@ -2274,7 +2274,7 @@ const EmitZIR = struct {...@@ -2274,7 +2274,7 @@ const EmitZIR = struct {
2274 };2274 };
2275 return self.emitUnnamedDecl(&inst.base);2275 return self.emitUnnamedDecl(&inst.base);
2276 },2276 },
2277 else => |t| std.debug.panic("TODO implement emitTypedValue for {}", .{@tagName(t)}),2277 else => |t| std.debug.panic("TODO implement emitTypedValue for {s}", .{@tagName(t)}),
2278 }2278 }
2279 }2279 }
22802280
...@@ -2947,7 +2947,7 @@ pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8...@@ -2947,7 +2947,7 @@ pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8
2947 try write.inst_table.ensureCapacity(@intCast(u32, instructions.len));2947 try write.inst_table.ensureCapacity(@intCast(u32, instructions.len));
29482948
2949 const stderr = std.io.getStdErr().outStream();2949 const stderr = std.io.getStdErr().outStream();
2950 try stderr.print("{} {s} {{ // unanalyzed\n", .{ kind, decl_name });2950 try stderr.print("{s} {s} {{ // unanalyzed\n", .{ kind, decl_name });
29512951
2952 for (instructions) |inst| {2952 for (instructions) |inst| {
2953 const my_i = write.next_instr_index;2953 const my_i = write.next_instr_index;
...@@ -2967,5 +2967,5 @@ pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8...@@ -2967,5 +2967,5 @@ pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8
2967 try stderr.writeByte('\n');2967 try stderr.writeByte('\n');
2968 }2968 }
29692969
2970 try stderr.print("}} // {} {s}\n\n", .{ kind, decl_name });2970 try stderr.print("}} // {s} {s}\n\n", .{ kind, decl_name });
2971}2971}
src/zir_sema.zig+17-17
...@@ -274,7 +274,7 @@ pub fn resolveInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!...@@ -274,7 +274,7 @@ pub fn resolveInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!
274 const entry = if (old_inst.cast(zir.Inst.DeclVal)) |declval| blk: {274 const entry = if (old_inst.cast(zir.Inst.DeclVal)) |declval| blk: {
275 const decl_name = declval.positionals.name;275 const decl_name = declval.positionals.name;
276 const entry = zir_module.contents.module.findDecl(decl_name) orelse276 const entry = zir_module.contents.module.findDecl(decl_name) orelse
277 return mod.fail(scope, old_inst.src, "decl '{}' not found", .{decl_name});277 return mod.fail(scope, old_inst.src, "decl '{s}' not found", .{decl_name});
278 break :blk entry;278 break :blk entry;
279 } else blk: {279 } else blk: {
280 // If this assert trips, the instruction that was referenced did not get280 // If this assert trips, the instruction that was referenced did not get
...@@ -564,14 +564,14 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr...@@ -564,14 +564,14 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr
564fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {564fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {
565 const symbol_name = try resolveConstString(mod, scope, export_inst.positionals.symbol_name);565 const symbol_name = try resolveConstString(mod, scope, export_inst.positionals.symbol_name);
566 const exported_decl = mod.lookupDeclName(scope, export_inst.positionals.decl_name) orelse566 const exported_decl = mod.lookupDeclName(scope, export_inst.positionals.decl_name) orelse
567 return mod.fail(scope, export_inst.base.src, "decl '{}' not found", .{export_inst.positionals.decl_name});567 return mod.fail(scope, export_inst.base.src, "decl '{s}' not found", .{export_inst.positionals.decl_name});
568 try mod.analyzeExport(scope, export_inst.base.src, symbol_name, exported_decl);568 try mod.analyzeExport(scope, export_inst.base.src, symbol_name, exported_decl);
569 return mod.constVoid(scope, export_inst.base.src);569 return mod.constVoid(scope, export_inst.base.src);
570}570}
571571
572fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {572fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
573 const msg = try resolveConstString(mod, scope, inst.positionals.operand);573 const msg = try resolveConstString(mod, scope, inst.positionals.operand);
574 return mod.fail(scope, inst.base.src, "{}", .{msg});574 return mod.fail(scope, inst.base.src, "{s}", .{msg});
575}575}
576576
577fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst {577fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst {
...@@ -918,7 +918,7 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In...@@ -918,7 +918,7 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In
918 for (inst.positionals.fields) |field_name| {918 for (inst.positionals.fields) |field_name| {
919 const entry = try mod.getErrorValue(field_name);919 const entry = try mod.getErrorValue(field_name);
920 if (payload.data.fields.fetchPutAssumeCapacity(entry.key, entry.value)) |prev| {920 if (payload.data.fields.fetchPutAssumeCapacity(entry.key, entry.value)) |prev| {
921 return mod.fail(scope, inst.base.src, "duplicate error: '{}'", .{field_name});921 return mod.fail(scope, inst.base.src, "duplicate error: '{s}'", .{field_name});
922 }922 }
923 }923 }
924 // TODO create name in format "error:line:column"924 // TODO create name in format "error:line:column"
...@@ -1068,7 +1068,7 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr...@@ -1068,7 +1068,7 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr
1068 return mod.fail(1068 return mod.fail(
1069 scope,1069 scope,
1070 fieldptr.positionals.field_name.src,1070 fieldptr.positionals.field_name.src,
1071 "no member named '{}' in '{}'",1071 "no member named '{s}' in '{}'",
1072 .{ field_name, elem_ty },1072 .{ field_name, elem_ty },
1073 );1073 );
1074 }1074 }
...@@ -1089,7 +1089,7 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr...@@ -1089,7 +1089,7 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr
1089 return mod.fail(1089 return mod.fail(
1090 scope,1090 scope,
1091 fieldptr.positionals.field_name.src,1091 fieldptr.positionals.field_name.src,
1092 "no member named '{}' in '{}'",1092 "no member named '{s}' in '{}'",
1093 .{ field_name, elem_ty },1093 .{ field_name, elem_ty },
1094 );1094 );
1095 }1095 }
...@@ -1107,7 +1107,7 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr...@@ -1107,7 +1107,7 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr
1107 // TODO resolve inferred error sets1107 // TODO resolve inferred error sets
1108 const entry = if (val.castTag(.error_set)) |payload|1108 const entry = if (val.castTag(.error_set)) |payload|
1109 (payload.data.fields.getEntry(field_name) orelse1109 (payload.data.fields.getEntry(field_name) orelse
1110 return mod.fail(scope, fieldptr.base.src, "no error named '{}' in '{}'", .{ field_name, child_type })).*1110 return mod.fail(scope, fieldptr.base.src, "no error named '{s}' in '{}'", .{ field_name, child_type })).*
1111 else1111 else
1112 try mod.getErrorValue(field_name);1112 try mod.getErrorValue(field_name);
11131113
...@@ -1135,9 +1135,9 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr...@@ -1135,9 +1135,9 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr
1135 }1135 }
11361136
1137 if (&container_scope.file_scope.base == mod.root_scope) {1137 if (&container_scope.file_scope.base == mod.root_scope) {
1138 return mod.fail(scope, fieldptr.base.src, "root source file has no member called '{}'", .{field_name});1138 return mod.fail(scope, fieldptr.base.src, "root source file has no member called '{s}'", .{field_name});
1139 } else {1139 } else {
1140 return mod.fail(scope, fieldptr.base.src, "container '{}' has no member called '{}'", .{ child_type, field_name });1140 return mod.fail(scope, fieldptr.base.src, "container '{}' has no member called '{s}'", .{ child_type, field_name });
1141 }1141 }
1142 },1142 },
1143 else => return mod.fail(scope, fieldptr.base.src, "type '{}' does not support field access", .{child_type}),1143 else => return mod.fail(scope, fieldptr.base.src, "type '{}' does not support field access", .{child_type}),
...@@ -1503,14 +1503,14 @@ fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErr...@@ -1503,14 +1503,14 @@ fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErr
15031503
1504 const file_scope = mod.analyzeImport(scope, inst.base.src, operand) catch |err| switch (err) {1504 const file_scope = mod.analyzeImport(scope, inst.base.src, operand) catch |err| switch (err) {
1505 error.ImportOutsidePkgPath => {1505 error.ImportOutsidePkgPath => {
1506 return mod.fail(scope, inst.base.src, "import of file outside package path: '{}'", .{operand});1506 return mod.fail(scope, inst.base.src, "import of file outside package path: '{s}'", .{operand});
1507 },1507 },
1508 error.FileNotFound => {1508 error.FileNotFound => {
1509 return mod.fail(scope, inst.base.src, "unable to find '{}'", .{operand});1509 return mod.fail(scope, inst.base.src, "unable to find '{s}'", .{operand});
1510 },1510 },
1511 else => {1511 else => {
1512 // TODO user friendly error to string1512 // TODO user friendly error to string
1513 return mod.fail(scope, inst.base.src, "unable to open '{}': {}", .{ operand, @errorName(err) });1513 return mod.fail(scope, inst.base.src, "unable to open '{s}': {s}", .{ operand, @errorName(err) });
1514 },1514 },
1515 };1515 };
1516 return mod.constType(scope, inst.base.src, file_scope.root_container.ty);1516 return mod.constType(scope, inst.base.src, file_scope.root_container.ty);
...@@ -1637,7 +1637,7 @@ fn analyzeInstArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn...@@ -1637,7 +1637,7 @@ fn analyzeInstArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn
1637 const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat;1637 const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat;
16381638
1639 if (!is_int and !(is_float and floatOpAllowed(inst.base.tag))) {1639 if (!is_int and !(is_float and floatOpAllowed(inst.base.tag))) {
1640 return mod.fail(scope, inst.base.src, "invalid operands to binary expression: '{}' and '{}'", .{ @tagName(lhs.ty.zigTypeTag()), @tagName(rhs.ty.zigTypeTag()) });1640 return mod.fail(scope, inst.base.src, "invalid operands to binary expression: '{s}' and '{s}'", .{ @tagName(lhs.ty.zigTypeTag()), @tagName(rhs.ty.zigTypeTag()) });
1641 }1641 }
16421642
1643 if (casted_lhs.value()) |lhs_val| {1643 if (casted_lhs.value()) |lhs_val| {
...@@ -1656,7 +1656,7 @@ fn analyzeInstArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn...@@ -1656,7 +1656,7 @@ fn analyzeInstArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn
1656 const ir_tag = switch (inst.base.tag) {1656 const ir_tag = switch (inst.base.tag) {
1657 .add => Inst.Tag.add,1657 .add => Inst.Tag.add,
1658 .sub => Inst.Tag.sub,1658 .sub => Inst.Tag.sub,
1659 else => return mod.fail(scope, inst.base.src, "TODO implement arithmetic for operand '{}''", .{@tagName(inst.base.tag)}),1659 else => return mod.fail(scope, inst.base.src, "TODO implement arithmetic for operand '{s}''", .{@tagName(inst.base.tag)}),
1660 };1660 };
16611661
1662 return mod.addBinOp(b, inst.base.src, scalar_type, ir_tag, casted_lhs, casted_rhs);1662 return mod.addBinOp(b, inst.base.src, scalar_type, ir_tag, casted_lhs, casted_rhs);
...@@ -1689,7 +1689,7 @@ fn analyzeInstComptimeOp(mod: *Module, scope: *Scope, res_type: Type, inst: *zir...@@ -1689,7 +1689,7 @@ fn analyzeInstComptimeOp(mod: *Module, scope: *Scope, res_type: Type, inst: *zir
1689 mod.floatSub(scope, res_type, inst.base.src, lhs_val, rhs_val);1689 mod.floatSub(scope, res_type, inst.base.src, lhs_val, rhs_val);
1690 break :blk val;1690 break :blk val;
1691 },1691 },
1692 else => return mod.fail(scope, inst.base.src, "TODO Implement arithmetic operand '{}'", .{@tagName(inst.base.tag)}),1692 else => return mod.fail(scope, inst.base.src, "TODO Implement arithmetic operand '{s}'", .{@tagName(inst.base.tag)}),
1693 };1693 };
16941694
1695 return mod.constInst(scope, inst.base.src, .{1695 return mod.constInst(scope, inst.base.src, .{
...@@ -1781,7 +1781,7 @@ fn analyzeInstCmp(...@@ -1781,7 +1781,7 @@ fn analyzeInstCmp(
1781 return mod.fail(scope, inst.base.src, "TODO implement equality comparison between a union's tag value and an enum literal", .{});1781 return mod.fail(scope, inst.base.src, "TODO implement equality comparison between a union's tag value and an enum literal", .{});
1782 } else if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) {1782 } else if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) {
1783 if (!is_equality_cmp) {1783 if (!is_equality_cmp) {
1784 return mod.fail(scope, inst.base.src, "{} operator not allowed for errors", .{@tagName(op)});1784 return mod.fail(scope, inst.base.src, "{s} operator not allowed for errors", .{@tagName(op)});
1785 }1785 }
1786 return mod.fail(scope, inst.base.src, "TODO implement equality comparison between errors", .{});1786 return mod.fail(scope, inst.base.src, "TODO implement equality comparison between errors", .{});
1787 } else if (lhs.ty.isNumeric() and rhs.ty.isNumeric()) {1787 } else if (lhs.ty.isNumeric() and rhs.ty.isNumeric()) {
...@@ -1962,7 +1962,7 @@ fn analyzeDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerErr...@@ -1962,7 +1962,7 @@ fn analyzeDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerErr
1962 const decl_name = inst.positionals.name;1962 const decl_name = inst.positionals.name;
1963 const zir_module = scope.namespace().cast(Scope.ZIRModule).?;1963 const zir_module = scope.namespace().cast(Scope.ZIRModule).?;
1964 const src_decl = zir_module.contents.module.findDecl(decl_name) orelse1964 const src_decl = zir_module.contents.module.findDecl(decl_name) orelse
1965 return mod.fail(scope, inst.base.src, "use of undeclared identifier '{}'", .{decl_name});1965 return mod.fail(scope, inst.base.src, "use of undeclared identifier '{s}'", .{decl_name});
19661966
1967 const decl = try resolveCompleteZirDecl(mod, scope, src_decl.decl);1967 const decl = try resolveCompleteZirDecl(mod, scope, src_decl.decl);
19681968