authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 23:17:03-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 23:17:03-05:00
logfe4963412f939d4f72eb5f0153a253116206749b
tree1ff6242dfa3dccb082e825466202d5289f31f172
parent8b2622cdd58cec697d9d1f8f49717b6ce7ee3e2e
signature Commit is signed but in an unrecognized format.

update self-hosted compiler to new format API


11 files changed, 133 insertions(+), 142 deletions(-)

src-self-hosted/codegen.zig+6-8
......@@ -45,13 +45,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
4545
4646 // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes
4747 // the git revision.
48 const producer = try std.Buffer.allocPrint(
49 &code.arena.allocator,
50 "zig {}.{}.{}",
48 const producer = try std.Buffer.allocPrint(&code.arena.allocator, "zig {}.{}.{}", .{
5149 @as(u32, c.ZIG_VERSION_MAJOR),
5250 @as(u32, c.ZIG_VERSION_MINOR),
5351 @as(u32, c.ZIG_VERSION_PATCH),
54 );
52 });
5553 const flags = "";
5654 const runtime_version = 0;
5755 const compile_unit_file = llvm.CreateFile(
......@@ -93,7 +91,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
9391 llvm.DIBuilderFinalize(dibuilder);
9492
9593 if (comp.verbose_llvm_ir) {
96 std.debug.warn("raw module:\n");
94 std.debug.warn("raw module:\n", .{});
9795 llvm.DumpModule(ofile.module);
9896 }
9997
......@@ -120,18 +118,18 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
120118 is_small,
121119 )) {
122120 if (std.debug.runtime_safety) {
123 std.debug.panic("unable to write object file {}: {s}\n", output_path.toSliceConst(), err_msg);
121 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg });
124122 }
125123 return error.WritingObjectFileFailed;
126124 }
127125 //validate_inline_fns(g); TODO
128126 fn_val.containing_object = output_path;
129127 if (comp.verbose_llvm_ir) {
130 std.debug.warn("optimized module:\n");
128 std.debug.warn("optimized module:\n", .{});
131129 llvm.DumpModule(ofile.module);
132130 }
133131 if (comp.verbose_link) {
134 std.debug.warn("created {}\n", output_path.toSliceConst());
132 std.debug.warn("created {}\n", .{output_path.toSliceConst()});
135133 }
136134}
137135
src-self-hosted/compilation.zig+12-15
......@@ -807,7 +807,7 @@ pub const Compilation = struct {
807807 root_scope.realpath,
808808 max_src_size,
809809 ) catch |err| {
810 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));
810 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", .{@errorName(err)});
811811 return;
812812 };
813813 errdefer self.gpa().free(source_code);
......@@ -878,7 +878,7 @@ pub const Compilation = struct {
878878 try self.addCompileError(tree_scope, Span{
879879 .first = fn_proto.fn_token,
880880 .last = fn_proto.fn_token + 1,
881 }, "missing function name");
881 }, "missing function name", .{});
882882 continue;
883883 };
884884
......@@ -942,7 +942,7 @@ pub const Compilation = struct {
942942 const root_scope = blk: {
943943 // TODO async/await std.fs.realpath
944944 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
945 try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));
945 try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});
946946 return;
947947 };
948948 errdefer self.gpa().free(root_src_real_path);
......@@ -991,7 +991,7 @@ pub const Compilation = struct {
991991 defer unanalyzed_code.destroy(comp.gpa());
992992
993993 if (comp.verbose_ir) {
994 std.debug.warn("unanalyzed:\n");
994 std.debug.warn("unanalyzed:\n", .{});
995995 unanalyzed_code.dump();
996996 }
997997
......@@ -1003,7 +1003,7 @@ pub const Compilation = struct {
10031003 errdefer analyzed_code.destroy(comp.gpa());
10041004
10051005 if (comp.verbose_ir) {
1006 std.debug.warn("analyzed:\n");
1006 std.debug.warn("analyzed:\n", .{});
10071007 analyzed_code.dump();
10081008 }
10091009
......@@ -1048,14 +1048,14 @@ pub const Compilation = struct {
10481048
10491049 const gop = try locked_table.getOrPut(decl.name);
10501050 if (gop.found_existing) {
1051 try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", decl.name);
1051 try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", .{decl.name});
10521052 // TODO note: other definition here
10531053 } else {
10541054 gop.kv.value = decl;
10551055 }
10561056 }
10571057
1058 fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: ...) !void {
1058 fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: var) !void {
10591059 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
10601060 errdefer self.gpa().free(text);
10611061
......@@ -1065,7 +1065,7 @@ pub const Compilation = struct {
10651065 try self.prelink_group.call(addCompileErrorAsync, self, msg);
10661066 }
10671067
1068 fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: ...) !void {
1068 fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: var) !void {
10691069 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
10701070 errdefer self.gpa().free(text);
10711071
......@@ -1092,12 +1092,9 @@ pub const Compilation = struct {
10921092 defer exported_symbol_names.release();
10931093
10941094 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {
1095 try self.addCompileError(
1096 decl.tree_scope,
1097 decl.getSpan(),
1098 "exported symbol collision: '{}'",
1095 try self.addCompileError(decl.tree_scope, decl.getSpan(), "exported symbol collision: '{}'", .{
10991096 decl.name,
1100 );
1097 });
11011098 // TODO add error note showing location of other symbol
11021099 }
11031100 }
......@@ -1162,7 +1159,7 @@ pub const Compilation = struct {
11621159 const tmp_dir = try self.getTmpDir();
11631160 const file_prefix = self.getRandomFileName();
11641161
1165 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
1162 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });
11661163 defer self.gpa().free(file_name);
11671164
11681165 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
......@@ -1303,7 +1300,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
13031300 try comp.addCompileError(tree_scope, Span{
13041301 .first = param_decl.firstToken(),
13051302 .last = param_decl.type_node.firstToken(),
1306 }, "missing parameter name");
1303 }, "missing parameter name", .{});
13071304 return error.SemanticAnalysisFailed;
13081305 };
13091306 const param_name = tree_scope.tree.tokenSlice(name_token);
src-self-hosted/errmsg.zig+5-7
......@@ -231,7 +231,7 @@ pub const Msg = struct {
231231 pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void {
232232 switch (msg.data) {
233233 .Cli => {
234 try stream.print("{}:-:-: error: {}\n", msg.realpath, msg.text);
234 try stream.print("{}:-:-: error: {}\n", .{ msg.realpath, msg.text });
235235 return;
236236 },
237237 else => {},
......@@ -254,24 +254,22 @@ pub const Msg = struct {
254254 const start_loc = tree.tokenLocationPtr(0, first_token);
255255 const end_loc = tree.tokenLocationPtr(first_token.end, last_token);
256256 if (!color_on) {
257 try stream.print(
258 "{}:{}:{}: error: {}\n",
257 try stream.print("{}:{}:{}: error: {}\n", .{
259258 path,
260259 start_loc.line + 1,
261260 start_loc.column + 1,
262261 msg.text,
263 );
262 });
264263 return;
265264 }
266265
267 try stream.print(
268 "{}:{}:{}: error: {}\n{}\n",
266 try stream.print("{}:{}:{}: error: {}\n{}\n", .{
269267 path,
270268 start_loc.line + 1,
271269 start_loc.column + 1,
272270 msg.text,
273271 tree.source[start_loc.line_start..start_loc.line_end],
274 );
272 });
275273 try stream.writeByteNTimes(' ', start_loc.column);
276274 try stream.writeByteNTimes('~', last_token.end - first_token.start);
277275 try stream.write("\n");
src-self-hosted/introspect.zig+1-1
......@@ -48,7 +48,7 @@ pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
4848 \\Unable to find zig lib directory: {}.
4949 \\Reinstall Zig or use --zig-install-prefix.
5050 \\
51 , @errorName(err));
51 , .{@errorName(err)});
5252
5353 return error.ZigLibDirNotFound;
5454 };
src-self-hosted/ir.zig+38-40
......@@ -32,16 +32,16 @@ pub const IrVal = union(enum) {
3232
3333 pub fn dump(self: IrVal) void {
3434 switch (self) {
35 .Unknown => std.debug.warn("Unknown"),
35 .Unknown => std.debug.warn("Unknown", .{}),
3636 .KnownType => |typ| {
37 std.debug.warn("KnownType(");
37 std.debug.warn("KnownType(", .{});
3838 typ.dump();
39 std.debug.warn(")");
39 std.debug.warn(")", .{});
4040 },
4141 .KnownValue => |value| {
42 std.debug.warn("KnownValue(");
42 std.debug.warn("KnownValue(", .{});
4343 value.dump();
44 std.debug.warn(")");
44 std.debug.warn(")", .{});
4545 },
4646 }
4747 }
......@@ -90,9 +90,9 @@ pub const Inst = struct {
9090 inline while (i < @memberCount(Id)) : (i += 1) {
9191 if (base.id == @field(Id, @memberName(Id, i))) {
9292 const T = @field(Inst, @memberName(Id, i));
93 std.debug.warn("#{} = {}(", base.debug_id, @tagName(base.id));
93 std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
9494 @fieldParentPtr(T, "base", base).dump();
95 std.debug.warn(")");
95 std.debug.warn(")", .{});
9696 return;
9797 }
9898 }
......@@ -173,7 +173,7 @@ pub const Inst = struct {
173173 if (self.isCompTime()) {
174174 return self.val.KnownValue;
175175 } else {
176 try ira.addCompileError(self.span, "unable to evaluate constant expression");
176 try ira.addCompileError(self.span, "unable to evaluate constant expression", .{});
177177 return error.SemanticAnalysisFailed;
178178 }
179179 }
......@@ -269,11 +269,11 @@ pub const Inst = struct {
269269 const ir_val_init = IrVal.Init.Unknown;
270270
271271 pub fn dump(self: *const Call) void {
272 std.debug.warn("#{}(", self.params.fn_ref.debug_id);
272 std.debug.warn("#{}(", .{self.params.fn_ref.debug_id});
273273 for (self.params.args) |arg| {
274 std.debug.warn("#{},", arg.debug_id);
274 std.debug.warn("#{},", .{arg.debug_id});
275275 }
276 std.debug.warn(")");
276 std.debug.warn(")", .{});
277277 }
278278
279279 pub fn hasSideEffects(self: *const Call) bool {
......@@ -284,19 +284,17 @@ pub const Inst = struct {
284284 const fn_ref = try self.params.fn_ref.getAsParam();
285285 const fn_ref_type = fn_ref.getKnownType();
286286 const fn_type = fn_ref_type.cast(Type.Fn) orelse {
287 try ira.addCompileError(fn_ref.span, "type '{}' not a function", fn_ref_type.name);
287 try ira.addCompileError(fn_ref.span, "type '{}' not a function", .{fn_ref_type.name});
288288 return error.SemanticAnalysisFailed;
289289 };
290290
291291 const fn_type_param_count = fn_type.paramCount();
292292
293293 if (fn_type_param_count != self.params.args.len) {
294 try ira.addCompileError(
295 self.base.span,
296 "expected {} arguments, found {}",
294 try ira.addCompileError(self.base.span, "expected {} arguments, found {}", .{
297295 fn_type_param_count,
298296 self.params.args.len,
299 );
297 });
300298 return error.SemanticAnalysisFailed;
301299 }
302300
......@@ -375,7 +373,7 @@ pub const Inst = struct {
375373 const ir_val_init = IrVal.Init.NoReturn;
376374
377375 pub fn dump(self: *const Return) void {
378 std.debug.warn("#{}", self.params.return_value.debug_id);
376 std.debug.warn("#{}", .{self.params.return_value.debug_id});
379377 }
380378
381379 pub fn hasSideEffects(self: *const Return) bool {
......@@ -509,7 +507,7 @@ pub const Inst = struct {
509507 const ir_val_init = IrVal.Init.Unknown;
510508
511509 pub fn dump(inst: *const VarPtr) void {
512 std.debug.warn("{}", inst.params.var_scope.name);
510 std.debug.warn("{}", .{inst.params.var_scope.name});
513511 }
514512
515513 pub fn hasSideEffects(inst: *const VarPtr) bool {
......@@ -567,7 +565,7 @@ pub const Inst = struct {
567565 const target = try self.params.target.getAsParam();
568566 const target_type = target.getKnownType();
569567 if (target_type.id != .Pointer) {
570 try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", target_type.name);
568 try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", .{target_type.name});
571569 return error.SemanticAnalysisFailed;
572570 }
573571 const ptr_type = @fieldParentPtr(Type.Pointer, "base", target_type);
......@@ -705,7 +703,7 @@ pub const Inst = struct {
705703 const ir_val_init = IrVal.Init.Unknown;
706704
707705 pub fn dump(self: *const CheckVoidStmt) void {
708 std.debug.warn("#{}", self.params.target.debug_id);
706 std.debug.warn("#{}", .{self.params.target.debug_id});
709707 }
710708
711709 pub fn hasSideEffects(inst: *const CheckVoidStmt) bool {
......@@ -715,7 +713,7 @@ pub const Inst = struct {
715713 pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst {
716714 const target = try self.params.target.getAsParam();
717715 if (target.getKnownType().id != .Void) {
718 try ira.addCompileError(self.base.span, "expression value is ignored");
716 try ira.addCompileError(self.base.span, "expression value is ignored", .{});
719717 return error.SemanticAnalysisFailed;
720718 }
721719 return ira.irb.buildConstVoid(self.base.scope, self.base.span, true);
......@@ -801,7 +799,7 @@ pub const Inst = struct {
801799 const ir_val_init = IrVal.Init.Unknown;
802800
803801 pub fn dump(inst: *const AddImplicitReturnType) void {
804 std.debug.warn("#{}", inst.params.target.debug_id);
802 std.debug.warn("#{}", .{inst.params.target.debug_id});
805803 }
806804
807805 pub fn hasSideEffects(inst: *const AddImplicitReturnType) bool {
......@@ -826,7 +824,7 @@ pub const Inst = struct {
826824 const ir_val_init = IrVal.Init.Unknown;
827825
828826 pub fn dump(inst: *const TestErr) void {
829 std.debug.warn("#{}", inst.params.target.debug_id);
827 std.debug.warn("#{}", .{inst.params.target.debug_id});
830828 }
831829
832830 pub fn hasSideEffects(inst: *const TestErr) bool {
......@@ -888,7 +886,7 @@ pub const Inst = struct {
888886 const ir_val_init = IrVal.Init.Unknown;
889887
890888 pub fn dump(inst: *const TestCompTime) void {
891 std.debug.warn("#{}", inst.params.target.debug_id);
889 std.debug.warn("#{}", .{inst.params.target.debug_id});
892890 }
893891
894892 pub fn hasSideEffects(inst: *const TestCompTime) bool {
......@@ -971,11 +969,11 @@ pub const Code = struct {
971969 pub fn dump(self: *Code) void {
972970 var bb_i: usize = 0;
973971 for (self.basic_block_list.toSliceConst()) |bb| {
974 std.debug.warn("{s}_{}:\n", bb.name_hint, bb.debug_id);
972 std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id });
975973 for (bb.instruction_list.toSliceConst()) |instr| {
976 std.debug.warn(" ");
974 std.debug.warn(" ", .{});
977975 instr.dump();
978 std.debug.warn("\n");
976 std.debug.warn("\n", .{});
979977 }
980978 }
981979 }
......@@ -993,6 +991,7 @@ pub const Code = struct {
993991 self.tree_scope,
994992 ret_value.span,
995993 "unable to evaluate constant expression",
994 .{},
996995 );
997996 return error.SemanticAnalysisFailed;
998997 } else if (inst.hasSideEffects()) {
......@@ -1000,6 +999,7 @@ pub const Code = struct {
1000999 self.tree_scope,
10011000 inst.span,
10021001 "unable to evaluate constant expression",
1002 .{},
10031003 );
10041004 return error.SemanticAnalysisFailed;
10051005 }
......@@ -1359,7 +1359,7 @@ pub const Builder = struct {
13591359 irb.code.tree_scope,
13601360 src_span,
13611361 "invalid character in string literal: '{c}'",
1362 str_token[bad_index],
1362 .{str_token[bad_index]},
13631363 );
13641364 return error.SemanticAnalysisFailed;
13651365 },
......@@ -1523,6 +1523,7 @@ pub const Builder = struct {
15231523 irb.code.tree_scope,
15241524 src_span,
15251525 "return expression outside function definition",
1526 .{},
15261527 );
15271528 return error.SemanticAnalysisFailed;
15281529 }
......@@ -1533,6 +1534,7 @@ pub const Builder = struct {
15331534 irb.code.tree_scope,
15341535 src_span,
15351536 "cannot return from defer expression",
1537 .{},
15361538 );
15371539 scope_defer_expr.reported_err = true;
15381540 }
......@@ -1629,7 +1631,7 @@ pub const Builder = struct {
16291631 }
16301632 } else |err| switch (err) {
16311633 error.Overflow => {
1632 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large");
1634 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large", .{});
16331635 return error.SemanticAnalysisFailed;
16341636 },
16351637 error.OutOfMemory => return error.OutOfMemory,
......@@ -1663,7 +1665,7 @@ pub const Builder = struct {
16631665 // TODO put a variable of same name with invalid type in global scope
16641666 // so that future references to this same name will find a variable with an invalid type
16651667
1666 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", name);
1668 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", .{name});
16671669 return error.SemanticAnalysisFailed;
16681670 }
16691671
......@@ -2008,7 +2010,7 @@ const Analyze = struct {
20082010 const next_instruction = ira.parent_basic_block.instruction_list.at(ira.instruction_index);
20092011
20102012 if (!next_instruction.is_generated) {
2011 try ira.addCompileError(next_instruction.span, "unreachable code");
2013 try ira.addCompileError(next_instruction.span, "unreachable code", .{});
20122014 break;
20132015 }
20142016 ira.instruction_index += 1;
......@@ -2041,7 +2043,7 @@ const Analyze = struct {
20412043 }
20422044 }
20432045
2044 fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: ...) !void {
2046 fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: var) !void {
20452047 return self.irb.comp.addCompileError(self.irb.code.tree_scope, span, fmt, args);
20462048 }
20472049
......@@ -2330,12 +2332,10 @@ const Analyze = struct {
23302332 break :cast;
23312333 };
23322334 if (!fits) {
2333 try ira.addCompileError(
2334 source_instr.span,
2335 "integer value '{}' cannot be stored in type '{}'",
2335 try ira.addCompileError(source_instr.span, "integer value '{}' cannot be stored in type '{}'", .{
23362336 from_int,
23372337 dest_type.name,
2338 );
2338 });
23392339 return error.SemanticAnalysisFailed;
23402340 }
23412341
......@@ -2498,12 +2498,10 @@ const Analyze = struct {
24982498 // }
24992499 //}
25002500
2501 try ira.addCompileError(
2502 source_instr.span,
2503 "expected type '{}', found '{}'",
2501 try ira.addCompileError(source_instr.span, "expected type '{}', found '{}'", .{
25042502 dest_type.name,
25052503 from_type.name,
2506 );
2504 });
25072505 //ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
25082506 // buf_sprintf("expected type '%s', found '%s'",
25092507 // buf_ptr(&wanted_type->name),
src-self-hosted/libc_installation.zig+13-15
......@@ -65,7 +65,7 @@ pub const LibCInstallation = struct {
6565 if (line.len == 0 or line[0] == '#') continue;
6666 var line_it = std.mem.separate(line, "=");
6767 const name = line_it.next() orelse {
68 try stderr.print("missing equal sign after field name\n");
68 try stderr.print("missing equal sign after field name\n", .{});
6969 return error.ParseError;
7070 };
7171 const value = line_it.rest();
......@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {
8383 },
8484 else => {
8585 if (value.len == 0) {
86 try stderr.print("field cannot be empty: {}\n", key);
86 try stderr.print("field cannot be empty: {}\n", .{key});
8787 return error.ParseError;
8888 }
8989 const dupe = try std.mem.dupe(allocator, u8, value);
......@@ -97,7 +97,7 @@ pub const LibCInstallation = struct {
9797 }
9898 for (found_keys) |found_key, i| {
9999 if (!found_key.found) {
100 try stderr.print("missing field: {}\n", keys[i]);
100 try stderr.print("missing field: {}\n", .{keys[i]});
101101 return error.ParseError;
102102 }
103103 }
......@@ -105,6 +105,11 @@ pub const LibCInstallation = struct {
105105
106106 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {
107107 @setEvalBranchQuota(4000);
108 const lib_dir = self.lib_dir orelse "";
109 const static_lib_dir = self.static_lib_dir orelse "";
110 const msvc_lib_dir = self.msvc_lib_dir orelse "";
111 const kernel32_lib_dir = self.kernel32_lib_dir orelse "";
112 const dynamic_linker_path = self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} });
108113 try out.print(
109114 \\# The directory that contains `stdlib.h`.
110115 \\# On Linux, can be found with: `cc -E -Wp,-v -xc /dev/null`
......@@ -132,14 +137,7 @@ pub const LibCInstallation = struct {
132137 \\# Only needed when targeting Linux.
133138 \\dynamic_linker_path={}
134139 \\
135 ,
136 self.include_dir,
137 self.lib_dir orelse "",
138 self.static_lib_dir orelse "",
139 self.msvc_lib_dir orelse "",
140 self.kernel32_lib_dir orelse "",
141 self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} }),
142 );
140 , .{ self.include_dir, lib_dir, static_lib_dir, msvc_lib_dir, kernel32_lib_dir, dynamic_linker_path });
143141 }
144142
145143 /// Finds the default, native libc.
......@@ -255,7 +253,7 @@ pub const LibCInstallation = struct {
255253 for (searches) |search| {
256254 result_buf.shrink(0);
257255 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
258 try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);
256 try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
259257
260258 const stdlib_path = try fs.path.join(
261259 allocator,
......@@ -282,7 +280,7 @@ pub const LibCInstallation = struct {
282280 for (searches) |search| {
283281 result_buf.shrink(0);
284282 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
285 try stream.print("{}\\Lib\\{}\\ucrt\\", search.path, search.version);
283 try stream.print("{}\\Lib\\{}\\ucrt\\", .{ search.path, search.version });
286284 switch (builtin.arch) {
287285 .i386 => try stream.write("x86"),
288286 .x86_64 => try stream.write("x64"),
......@@ -360,7 +358,7 @@ pub const LibCInstallation = struct {
360358 for (searches) |search| {
361359 result_buf.shrink(0);
362360 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
363 try stream.print("{}\\Lib\\{}\\um\\", search.path, search.version);
361 try stream.print("{}\\Lib\\{}\\um\\", .{ search.path, search.version });
364362 switch (builtin.arch) {
365363 .i386 => try stream.write("x86\\"),
366364 .x86_64 => try stream.write("x64\\"),
......@@ -395,7 +393,7 @@ pub const LibCInstallation = struct {
395393/// caller owns returned memory
396394fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 {
397395 const cc_exe = std.os.getenv("CC") orelse "cc";
398 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", o_file);
396 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", .{o_file});
399397 defer allocator.free(arg1);
400398 const argv = [_][]const u8{ cc_exe, arg1 };
401399
src-self-hosted/link.zig+20-13
......@@ -75,9 +75,9 @@ pub fn link(comp: *Compilation) !void {
7575 if (comp.verbose_link) {
7676 for (ctx.args.toSliceConst()) |arg, i| {
7777 const space = if (i == 0) "" else " ";
78 std.debug.warn("{}{s}", space, arg);
78 std.debug.warn("{}{s}", .{ space, arg });
7979 }
80 std.debug.warn("\n");
80 std.debug.warn("\n", .{});
8181 }
8282
8383 const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));
......@@ -94,7 +94,7 @@ pub fn link(comp: *Compilation) !void {
9494 // TODO capture these messages and pass them through the system, reporting them through the
9595 // event system instead of printing them directly here.
9696 // perhaps try to parse and understand them.
97 std.debug.warn("{}\n", ctx.link_msg.toSliceConst());
97 std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()});
9898 }
9999 return error.LinkFailed;
100100 }
......@@ -334,13 +334,13 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
334334
335335 const is_library = ctx.comp.kind == .Lib;
336336
337 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", ctx.out_file_path.toSliceConst());
337 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()});
338338 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));
339339
340340 if (ctx.comp.haveLibC()) {
341 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.msvc_lib_dir.?)).ptr));
342 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.kernel32_lib_dir.?)).ptr));
343 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.lib_dir.?)).ptr));
341 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.msvc_lib_dir.?})).ptr));
342 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.kernel32_lib_dir.?})).ptr));
343 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.lib_dir.?})).ptr));
344344 }
345345
346346 if (ctx.link_in_crt) {
......@@ -348,17 +348,20 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
348348 const d_str = if (ctx.comp.build_mode == .Debug) "d" else "";
349349
350350 if (ctx.comp.is_static) {
351 const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", d_str);
351 const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", .{d_str});
352352 try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr));
353353 } else {
354 const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", d_str);
354 const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", .{d_str});
355355 try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr));
356356 }
357357
358 const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", lib_str, d_str);
358 const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", .{
359 lib_str,
360 d_str,
361 });
359362 try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr));
360363
361 const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", lib_str, d_str);
364 const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", .{ lib_str, d_str });
362365 try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr));
363366
364367 // Visual C++ 2015 Conformance Changes
......@@ -508,7 +511,11 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
508511 .IPhoneOS => try ctx.args.append("-iphoneos_version_min"),
509512 .IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),
510513 }
511 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);
514 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", .{
515 platform.major,
516 platform.minor,
517 platform.micro,
518 });
512519 try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr));
513520
514521 if (ctx.comp.kind == .Exe) {
......@@ -584,7 +591,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
584591 try ctx.args.append("-lSystem");
585592 } else {
586593 if (mem.indexOfScalar(u8, lib.name, '/') == null) {
587 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);
594 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", .{lib.name});
588595 try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr));
589596 } else {
590597 const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name);
src-self-hosted/main.zig+24-25
......@@ -128,7 +128,7 @@ pub fn main() !void {
128128 }
129129 }
130130
131 try stderr.print("unknown command: {}\n\n", args[1]);
131 try stderr.print("unknown command: {}\n\n", .{args[1]});
132132 try stderr.write(usage);
133133 process.argsFree(allocator, args);
134134 process.exit(1);
......@@ -329,14 +329,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
329329 if (cur_pkg.parent) |parent| {
330330 cur_pkg = parent;
331331 } else {
332 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");
332 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n", .{});
333333 process.exit(1);
334334 }
335335 }
336336 }
337337
338338 if (cur_pkg.parent != null) {
339 try stderr.print("unmatched --pkg-begin\n");
339 try stderr.print("unmatched --pkg-begin\n", .{});
340340 process.exit(1);
341341 }
342342
......@@ -345,7 +345,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
345345 0 => null,
346346 1 => flags.positionals.at(0),
347347 else => {
348 try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));
348 try stderr.print("unexpected extra parameter: {}\n", .{flags.positionals.at(1)});
349349 process.exit(1);
350350 },
351351 };
......@@ -477,13 +477,13 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
477477
478478 switch (build_event) {
479479 .Ok => {
480 stderr.print("Build {} succeeded\n", count) catch process.exit(1);
480 stderr.print("Build {} succeeded\n", .{count}) catch process.exit(1);
481481 },
482482 .Error => |err| {
483 stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch process.exit(1);
483 stderr.print("Build {} failed: {}\n", .{ count, @errorName(err) }) catch process.exit(1);
484484 },
485485 .Fail => |msgs| {
486 stderr.print("Build {} compile errors:\n", count) catch process.exit(1);
486 stderr.print("Build {} compile errors:\n", .{count}) catch process.exit(1);
487487 for (msgs) |msg| {
488488 defer msg.destroy();
489489 msg.printToFile(stderr_file, color) catch process.exit(1);
......@@ -544,12 +544,11 @@ const Fmt = struct {
544544
545545fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
546546 libc.parse(allocator, libc_paths_file, stderr) catch |err| {
547 stderr.print(
548 "Unable to parse libc path file '{}': {}.\n" ++
549 "Try running `zig libc` to see an example for the native target.\n",
547 stderr.print("Unable to parse libc path file '{}': {}.\n" ++
548 "Try running `zig libc` to see an example for the native target.\n", .{
550549 libc_paths_file,
551550 @errorName(err),
552 ) catch {};
551 }) catch {};
553552 process.exit(1);
554553 };
555554}
......@@ -563,7 +562,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
563562 return;
564563 },
565564 else => {
566 try stderr.print("unexpected extra parameter: {}\n", args[1]);
565 try stderr.print("unexpected extra parameter: {}\n", .{args[1]});
567566 process.exit(1);
568567 },
569568 }
......@@ -572,7 +571,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
572571 defer zig_compiler.deinit();
573572
574573 const libc = zig_compiler.getNativeLibC() catch |err| {
575 stderr.print("unable to find libc: {}\n", @errorName(err)) catch {};
574 stderr.print("unable to find libc: {}\n", .{@errorName(err)}) catch {};
576575 process.exit(1);
577576 };
578577 libc.render(stdout) catch process.exit(1);
......@@ -614,7 +613,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
614613 defer allocator.free(source_code);
615614
616615 const tree = std.zig.parse(allocator, source_code) catch |err| {
617 try stderr.print("error parsing stdin: {}\n", err);
616 try stderr.print("error parsing stdin: {}\n", .{err});
618617 process.exit(1);
619618 };
620619 defer tree.deinit();
......@@ -718,7 +717,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
718717 },
719718 else => {
720719 // TODO lock stderr printing
721 try stderr.print("unable to open '{}': {}\n", file_path, err);
720 try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
722721 fmt.any_error = true;
723722 return;
724723 },
......@@ -726,7 +725,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
726725 defer fmt.allocator.free(source_code);
727726
728727 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
729 try stderr.print("error parsing file '{}': {}\n", file_path, err);
728 try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
730729 fmt.any_error = true;
731730 return;
732731 };
......@@ -747,7 +746,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
747746 if (check_mode) {
748747 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
749748 if (anything_changed) {
750 try stderr.print("{}\n", file_path);
749 try stderr.print("{}\n", .{file_path});
751750 fmt.any_error = true;
752751 }
753752 } else {
......@@ -757,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
757756
758757 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
759758 if (anything_changed) {
760 try stderr.print("{}\n", file_path);
759 try stderr.print("{}\n", .{file_path});
761760 try baf.finish();
762761 }
763762 }
......@@ -774,7 +773,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
774773 // NOTE: Cannot use empty string, see #918.
775774 comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
776775
777 try stdout.print(" {}{}", arch_tag, native_str);
776 try stdout.print(" {}{}", .{ arch_tag, native_str });
778777 }
779778 }
780779 try stdout.write("\n");
......@@ -787,7 +786,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
787786 // NOTE: Cannot use empty string, see #918.
788787 comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
789788
790 try stdout.print(" {}{}", os_tag, native_str);
789 try stdout.print(" {}{}", .{ os_tag, native_str });
791790 }
792791 }
793792 try stdout.write("\n");
......@@ -800,13 +799,13 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
800799 // NOTE: Cannot use empty string, see #918.
801800 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";
802801
803 try stdout.print(" {}{}", abi_tag, native_str);
802 try stdout.print(" {}{}", .{ abi_tag, native_str });
804803 }
805804 }
806805}
807806
808807fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
809 try stdout.print("{}\n", std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING));
808 try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)});
810809}
811810
812811const args_test_spec = [_]Flag{Flag.Bool("--help")};
......@@ -865,7 +864,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
865864 }
866865 }
867866
868 try stderr.print("unknown sub command: {}\n\n", args[0]);
867 try stderr.print("unknown sub command: {}\n\n", .{args[0]});
869868 try stderr.write(usage_internal);
870869}
871870
......@@ -878,14 +877,14 @@ fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
878877 \\ZIG_LLVM_CONFIG_EXE {}
879878 \\ZIG_DIA_GUIDS_LIB {}
880879 \\
881 ,
880 , .{
882881 std.mem.toSliceConst(u8, c.ZIG_CMAKE_BINARY_DIR),
883882 std.mem.toSliceConst(u8, c.ZIG_CXX_COMPILER),
884883 std.mem.toSliceConst(u8, c.ZIG_LLD_INCLUDE_PATH),
885884 std.mem.toSliceConst(u8, c.ZIG_LLD_LIBRARIES),
886885 std.mem.toSliceConst(u8, c.ZIG_LLVM_CONFIG_EXE),
887886 std.mem.toSliceConst(u8, c.ZIG_DIA_GUIDS_LIB),
888 );
887 });
889888}
890889
891890const CliPkg = struct {
src-self-hosted/type.zig+11-15
......@@ -399,7 +399,7 @@ pub const Type = struct {
399399 .Generic => |generic| {
400400 self.non_key = NonKey{ .Generic = {} };
401401 const cc_str = ccFnTypeStr(generic.cc);
402 try name_stream.print("{}fn(", cc_str);
402 try name_stream.print("{}fn(", .{cc_str});
403403 var param_i: usize = 0;
404404 while (param_i < generic.param_count) : (param_i += 1) {
405405 const arg = if (param_i == 0) "var" else ", var";
......@@ -407,7 +407,7 @@ pub const Type = struct {
407407 }
408408 try name_stream.write(")");
409409 if (key.alignment) |alignment| {
410 try name_stream.print(" align({})", alignment);
410 try name_stream.print(" align({})", .{alignment});
411411 }
412412 try name_stream.write(" var");
413413 },
......@@ -416,7 +416,7 @@ pub const Type = struct {
416416 .Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) },
417417 };
418418 const cc_str = ccFnTypeStr(normal.cc);
419 try name_stream.print("{}fn(", cc_str);
419 try name_stream.print("{}fn(", .{cc_str});
420420 for (normal.params) |param, i| {
421421 if (i != 0) try name_stream.write(", ");
422422 if (param.is_noalias) try name_stream.write("noalias ");
......@@ -428,9 +428,9 @@ pub const Type = struct {
428428 }
429429 try name_stream.write(")");
430430 if (key.alignment) |alignment| {
431 try name_stream.print(" align({})", alignment);
431 try name_stream.print(" align({})", .{alignment});
432432 }
433 try name_stream.print(" {}", normal.return_type.name);
433 try name_stream.print(" {}", .{normal.return_type.name});
434434 },
435435 }
436436
......@@ -584,7 +584,7 @@ pub const Type = struct {
584584 errdefer comp.gpa().destroy(self);
585585
586586 const u_or_i = "ui"[@boolToInt(key.is_signed)];
587 const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", u_or_i, key.bit_count);
587 const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", .{ u_or_i, key.bit_count });
588588 errdefer comp.gpa().free(name);
589589
590590 self.base.init(comp, .Int, name);
......@@ -767,23 +767,19 @@ pub const Type = struct {
767767 .Non => "",
768768 };
769769 const name = switch (self.key.alignment) {
770 .Abi => try std.fmt.allocPrint(
771 comp.gpa(),
772 "{}{}{}{}",
770 .Abi => try std.fmt.allocPrint(comp.gpa(), "{}{}{}{}", .{
773771 size_str,
774772 mut_str,
775773 vol_str,
776774 self.key.child_type.name,
777 ),
778 .Override => |alignment| try std.fmt.allocPrint(
779 comp.gpa(),
780 "{}align<{}> {}{}{}",
775 }),
776 .Override => |alignment| try std.fmt.allocPrint(comp.gpa(), "{}align<{}> {}{}{}", .{
781777 size_str,
782778 alignment,
783779 mut_str,
784780 vol_str,
785781 self.key.child_type.name,
786 ),
782 }),
787783 };
788784 errdefer comp.gpa().free(name);
789785
......@@ -852,7 +848,7 @@ pub const Type = struct {
852848 };
853849 errdefer comp.gpa().destroy(self);
854850
855 const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", key.len, key.elem_type.name);
851 const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", .{ key.len, key.elem_type.name });
856852 errdefer comp.gpa().free(name);
857853
858854 self.base.init(comp, .Array, name);
src-self-hosted/util.zig+2-2
......@@ -175,7 +175,7 @@ pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
175175 var result: *llvm.Target = undefined;
176176 var err_msg: [*:0]u8 = undefined;
177177 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
178 std.debug.warn("triple: {s} error: {s}\n", triple.toSlice(), err_msg);
178 std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg });
179179 return error.UnsupportedTarget;
180180 }
181181 return result;
......@@ -206,7 +206,7 @@ pub fn getTriple(allocator: *std.mem.Allocator, self: std.Target) !std.Buffer {
206206 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
207207
208208 var out = &std.io.BufferOutStream.init(&result).stream;
209 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);
209 try out.print("{}-unknown-{}-{}", .{ @tagName(self.getArch()), @tagName(self.getOs()), env_name });
210210
211211 return result;
212212}
src-self-hosted/value.zig+1-1
......@@ -53,7 +53,7 @@ pub const Value = struct {
5353 }
5454
5555 pub fn dump(base: *const Value) void {
56 std.debug.warn("{}", @tagName(base.id));
56 std.debug.warn("{}", .{@tagName(base.id)});
5757 }
5858
5959 pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) {