authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-09 17:14:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-09 17:14:42-04:00
log3f4d0ecd7e5a57b425b1cd99139145e7e509c3c6
tree76d1d16a397e44c04167456116d6d3cc91f0b994
parent9462852433a815496e0edf5d5b2e00726f5ea072
parent0ac1b83885c7f2a97a8ac25657afcb5c9b80afb4

Merge remote-tracking branch 'origin/master' into m-n-threading


10 files changed, 202 insertions(+), 63 deletions(-)

doc/docgen.zig+16-13
......@@ -689,7 +689,10 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
689689fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
690690 var code_progress_index: usize = 0;
691691
692 const builtin_code = try escapeHtml(allocator, try getBuiltinCode(allocator, zig_exe));
692 var env_map = try os.getEnvMap(allocator);
693 try env_map.set("ZIG_DEBUG_COLOR", "1");
694
695 const builtin_code = try escapeHtml(allocator, try getBuiltinCode(allocator, &env_map, zig_exe));
693696
694697 for (toc.nodes) |node| {
695698 switch (node) {
......@@ -778,12 +781,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
778781 try build_args.append("c");
779782 try out.print(" --library c");
780783 }
781 _ = exec(allocator, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
784 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
782785
783786 const run_args = [][]const u8{tmp_bin_file_name};
784787
785788 const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {
786 const result = try os.ChildProcess.exec(allocator, run_args, null, null, max_doc_file_size);
789 const result = try os.ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
787790 switch (result.term) {
788791 os.ChildProcess.Term.Exited => |exit_code| {
789792 if (exit_code == 0) {
......@@ -799,7 +802,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
799802 }
800803 break :blk result;
801804 } else blk: {
802 break :blk exec(allocator, run_args) catch return parseError(tokenizer, code.source_token, "example crashed");
805 break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed");
803806 };
804807
805808 const escaped_stderr = try escapeHtml(allocator, result.stderr);
......@@ -845,7 +848,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
845848 "msvc",
846849 });
847850 }
848 const result = exec(allocator, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
851 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
849852 const escaped_stderr = try escapeHtml(allocator, result.stderr);
850853 const escaped_stdout = try escapeHtml(allocator, result.stdout);
851854 try out.print("\n{}{}</code></pre>\n", escaped_stderr, escaped_stdout);
......@@ -877,7 +880,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
877880 try out.print(" --release-small");
878881 },
879882 }
880 const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, null, max_doc_file_size);
883 const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
881884 switch (result.term) {
882885 os.ChildProcess.Term.Exited => |exit_code| {
883886 if (exit_code == 0) {
......@@ -923,7 +926,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
923926 builtin.Mode.ReleaseSmall => try test_args.append("--release-small"),
924927 }
925928
926 const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, null, max_doc_file_size);
929 const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
927930 switch (result.term) {
928931 os.ChildProcess.Term.Exited => |exit_code| {
929932 if (exit_code == 0) {
......@@ -1000,7 +1003,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10001003 }
10011004
10021005 if (maybe_error_match) |error_match| {
1003 const result = try os.ChildProcess.exec(allocator, build_args.toSliceConst(), null, null, max_doc_file_size);
1006 const result = try os.ChildProcess.exec(allocator, build_args.toSliceConst(), null, &env_map, max_doc_file_size);
10041007 switch (result.term) {
10051008 os.ChildProcess.Term.Exited => |exit_code| {
10061009 if (exit_code == 0) {
......@@ -1032,7 +1035,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10321035 try out.print("</code></pre>\n");
10331036 }
10341037 } else {
1035 _ = exec(allocator, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
1038 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
10361039 }
10371040 if (!code.is_inline) {
10381041 try out.print("</code></pre>\n");
......@@ -1045,8 +1048,8 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10451048 }
10461049}
10471050
1048fn exec(allocator: *mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult {
1049 const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size);
1051fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !os.ChildProcess.ExecResult {
1052 const result = try os.ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);
10501053 switch (result.term) {
10511054 os.ChildProcess.Term.Exited => |exit_code| {
10521055 if (exit_code != 0) {
......@@ -1070,8 +1073,8 @@ fn exec(allocator: *mem.Allocator, args: []const []const u8) !os.ChildProcess.Ex
10701073 return result;
10711074}
10721075
1073fn getBuiltinCode(allocator: *mem.Allocator, zig_exe: []const u8) ![]const u8 {
1074 const result = try exec(allocator, []const []const u8{
1076fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
1077 const result = try exec(allocator, env_map, []const []const u8{
10751078 zig_exe,
10761079 "builtin",
10771080 });
doc/langref.html.in+51-3
......@@ -6649,12 +6649,60 @@ pub fn main() void {
66496649 {#header_close#}
66506650
66516651 {#header_open|Invalid Error Set Cast#}
6652 <p>TODO</p>
6652 <p>At compile-time:</p>
6653 {#code_begin|test_err|error.B not a member of error set 'Set2'#}
6654const Set1 = error{
6655 A,
6656 B,
6657};
6658const Set2 = error{
6659 A,
6660 C,
6661};
6662comptime {
6663 _ = @errSetCast(Set2, Set1.B);
6664}
6665 {#code_end#}
6666 <p>At runtime:</p>
6667 {#code_begin|exe_err#}
6668const Set1 = error{
6669 A,
6670 B,
6671};
6672const Set2 = error{
6673 A,
6674 C,
6675};
6676pub fn main() void {
6677 _ = foo(Set1.B);
6678}
6679fn foo(set1: Set1) Set2 {
6680 return @errSetCast(Set2, set1);
6681}
6682 {#code_end#}
66536683 {#header_close#}
66546684
66556685 {#header_open|Incorrect Pointer Alignment#}
6656 <p>TODO</p>
6657
6686 <p>At compile-time:</p>
6687 {#code_begin|test_err|pointer address 0x1 is not aligned to 4 bytes#}
6688comptime {
6689 const ptr = @intToPtr(*i32, 0x1);
6690 const aligned = @alignCast(4, ptr);
6691}
6692 {#code_end#}
6693 <p>At runtime:</p>
6694 {#code_begin|exe_err#}
6695pub fn main() !void {
6696 var array align(4) = []u32{ 0x11111111, 0x11111111 };
6697 const bytes = @sliceToBytes(array[0..]);
6698 if (foo(bytes) != 0x11111111) return error.Wrong;
6699}
6700fn foo(bytes: []u8) u32 {
6701 const slice4 = bytes[1..5];
6702 const int_slice = @bytesToSlice(u32, @alignCast(4, slice4));
6703 return int_slice[0];
6704}
6705 {#code_end#}
66586706 {#header_close#}
66596707 {#header_open|Wrong Union Field Access#}
66606708 <p>TODO</p>
src/ir.cpp+15
......@@ -19370,6 +19370,15 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
1937019370 if (!val)
1937119371 return ira->codegen->invalid_instruction;
1937219372
19373 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
19374 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
19375 {
19376 ir_add_error(ira, target,
19377 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
19378 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
19379 return ira->codegen->invalid_instruction;
19380 }
19381
1937319382 IrInstruction *result = ir_create_const(&ira->new_irb, target->scope, target->source_node, result_type);
1937419383 copy_const_val(&result->value, val, false);
1937519384 result->value.type = result_type;
......@@ -19796,6 +19805,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
1979619805 return ira->codegen->builtin_types.entry_invalid;
1979719806 }
1979819807
19808 if (!type_has_bits(target->value.type)) {
19809 ir_add_error(ira, target,
19810 buf_sprintf("pointer to size 0 type has no address"));
19811 return ira->codegen->builtin_types.entry_invalid;
19812 }
19813
1979919814 if (instr_is_comptime(target)) {
1980019815 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
1980119816 if (!val)
std/build.zig+18
......@@ -814,6 +814,7 @@ pub const LibExeObjStep = struct {
814814 out_h_filename: []const u8,
815815 assembly_files: ArrayList([]const u8),
816816 packages: ArrayList(Pkg),
817 build_options_contents: std.Buffer,
817818
818819 // C only stuff
819820 source_files: ArrayList([]const u8),
......@@ -905,6 +906,7 @@ pub const LibExeObjStep = struct {
905906 .lib_paths = ArrayList([]const u8).init(builder.allocator),
906907 .object_src = undefined,
907908 .disable_libc = true,
909 .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,
908910 };
909911 self.computeOutFileNames();
910912 return self;
......@@ -945,6 +947,7 @@ pub const LibExeObjStep = struct {
945947 .out_h_filename = undefined,
946948 .assembly_files = undefined,
947949 .packages = undefined,
950 .build_options_contents = undefined,
948951 };
949952 self.computeOutFileNames();
950953 return self;
......@@ -1096,6 +1099,12 @@ pub const LibExeObjStep = struct {
10961099 self.include_dirs.append(self.builder.cache_root) catch unreachable;
10971100 }
10981101
1102 pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
1103 assert(self.is_zig);
1104 const out = &std.io.BufferOutStream.init(&self.build_options_contents).stream;
1105 out.print("pub const {} = {};\n", name, value) catch unreachable;
1106 }
1107
10991108 pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {
11001109 self.include_dirs.append(path) catch unreachable;
11011110 }
......@@ -1155,6 +1164,15 @@ pub const LibExeObjStep = struct {
11551164 zig_args.append(builder.pathFromRoot(root_src)) catch unreachable;
11561165 }
11571166
1167 if (self.build_options_contents.len() > 0) {
1168 const build_options_file = try os.path.join(builder.allocator, builder.cache_root, builder.fmt("{}_build_options.zig", self.name));
1169 try std.io.writeFile(builder.allocator, build_options_file, self.build_options_contents.toSliceConst());
1170 try zig_args.append("--pkg-begin");
1171 try zig_args.append("build_options");
1172 try zig_args.append(builder.pathFromRoot(build_options_file));
1173 try zig_args.append("--pkg-end");
1174 }
1175
11581176 for (self.object_files.toSliceConst()) |object_file| {
11591177 zig_args.append("--object") catch unreachable;
11601178 zig_args.append(builder.pathFromRoot(object_file)) catch unreachable;
std/debug/index.zig+50-23
......@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;
1010const builtin = @import("builtin");
1111
1212pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;
13pub const failing_allocator = FailingAllocator.init(global_allocator, 0);
1314
1415pub const runtime_safety = switch (builtin.mode) {
1516 builtin.Mode.Debug, builtin.Mode.ReleaseSafe => true,
......@@ -49,6 +50,12 @@ pub fn getSelfDebugInfo() !*ElfStackTrace {
4950 }
5051}
5152
53fn wantTtyColor() bool {
54 var bytes: [128]u8 = undefined;
55 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
56 return if (std.os.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| true else |_| stderr_file.isTty();
57}
58
5259/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
5360pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
5461 const stderr = getStderrStream() catch return;
......@@ -56,7 +63,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
5663 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
5764 return;
5865 };
59 writeCurrentStackTrace(stderr, getDebugInfoAllocator(), debug_info, stderr_file.isTty(), start_addr) catch |err| {
66 writeCurrentStackTrace(stderr, getDebugInfoAllocator(), debug_info, wantTtyColor(), start_addr) catch |err| {
6067 stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;
6168 return;
6269 };
......@@ -69,7 +76,7 @@ pub fn dumpStackTrace(stack_trace: *const builtin.StackTrace) void {
6976 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
7077 return;
7178 };
72 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, stderr_file.isTty()) catch |err| {
79 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| {
7380 stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;
7481 return;
7582 };
......@@ -161,7 +168,7 @@ pub fn writeStackTrace(stack_trace: *const builtin.StackTrace, out_stream: var,
161168 frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;
162169 }) {
163170 const return_address = stack_trace.instruction_addresses[frame_index];
164 try printSourceAtAddress(debug_info, out_stream, return_address);
171 try printSourceAtAddress(debug_info, out_stream, return_address, tty_color);
165172 }
166173}
167174
......@@ -194,13 +201,11 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: *mem.Allocator, debug_
194201 }
195202 },
196203 }
197 try printSourceAtAddress(debug_info, out_stream, return_address);
204 try printSourceAtAddress(debug_info, out_stream, return_address, tty_color);
198205 }
199206}
200207
201fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: usize) !void {
202 const ptr_hex = "0x{x}";
203
208fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: usize, tty_color: bool) !void {
204209 switch (builtin.os) {
205210 builtin.Os.windows => return error.UnsupportedDebugInfo,
206211 builtin.Os.macosx => {
......@@ -214,36 +219,58 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us
214219 .address = address,
215220 };
216221 const symbol = debug_info.symbol_table.search(address) orelse &unknown;
217 try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address);
222 try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ "0x{x}" ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address);
218223 },
219224 else => {
220225 const compile_unit = findCompileUnit(debug_info, address) catch {
221 try out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n", address);
226 if (tty_color) {
227 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n ???\n\n", address);
228 } else {
229 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n ???\n\n", address);
230 }
222231 return;
223232 };
224233 const compile_unit_name = try compile_unit.die.getAttrString(debug_info, DW.AT_name);
225234 if (getLineNumberInfo(debug_info, compile_unit, address - 1)) |line_info| {
226235 defer line_info.deinit();
227 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? ({})" ++ RESET ++ "\n", line_info.file_name, line_info.line, line_info.column, address, compile_unit_name);
228 if (printLineFromFile(debug_info.allocator(), out_stream, line_info)) {
229 if (line_info.column == 0) {
230 try out_stream.write("\n");
231 } else {
232 {
233 var col_i: usize = 1;
234 while (col_i < line_info.column) : (col_i += 1) {
235 try out_stream.writeByte(' ');
236 if (tty_color) {
237 try out_stream.print(
238 WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n",
239 line_info.file_name,
240 line_info.line,
241 line_info.column,
242 address,
243 compile_unit_name,
244 );
245 if (printLineFromFile(debug_info.allocator(), out_stream, line_info)) {
246 if (line_info.column == 0) {
247 try out_stream.write("\n");
248 } else {
249 {
250 var col_i: usize = 1;
251 while (col_i < line_info.column) : (col_i += 1) {
252 try out_stream.writeByte(' ');
253 }
236254 }
255 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
237256 }
238 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
257 } else |err| switch (err) {
258 error.EndOfFile => {},
259 else => return err,
239260 }
240 } else |err| switch (err) {
241 error.EndOfFile => {},
242 else => return err,
261 } else {
262 try out_stream.print(
263 "{}:{}:{}: 0x{x} in ??? ({})\n",
264 line_info.file_name,
265 line_info.line,
266 line_info.column,
267 address,
268 compile_unit_name,
269 );
243270 }
244271 } else |err| switch (err) {
245272 error.MissingDebugInfo, error.InvalidDebugInfo => {
246 try out_stream.print(ptr_hex ++ " in ??? ({})\n", address, compile_unit_name);
273 try out_stream.print("0x{x} in ??? ({})\n", address, compile_unit_name);
247274 },
248275 else => return err,
249276 }
std/hash_map.zig+10-10
......@@ -259,14 +259,14 @@ test "basic hash map usage" {
259259 var map = HashMap(i32, i32, hash_i32, eql_i32).init(&direct_allocator.allocator);
260260 defer map.deinit();
261261
262 assert((map.put(1, 11) catch unreachable) == null);
263 assert((map.put(2, 22) catch unreachable) == null);
264 assert((map.put(3, 33) catch unreachable) == null);
265 assert((map.put(4, 44) catch unreachable) == null);
266 assert((map.put(5, 55) catch unreachable) == null);
262 assert((try map.put(1, 11)) == null);
263 assert((try map.put(2, 22)) == null);
264 assert((try map.put(3, 33)) == null);
265 assert((try map.put(4, 44)) == null);
266 assert((try map.put(5, 55)) == null);
267267
268 assert((map.put(5, 66) catch unreachable).? == 55);
269 assert((map.put(5, 55) catch unreachable).? == 66);
268 assert((try map.put(5, 66)).? == 55);
269 assert((try map.put(5, 55)).? == 66);
270270
271271 assert(map.contains(2));
272272 assert(map.get(2).?.value == 22);
......@@ -282,9 +282,9 @@ test "iterator hash map" {
282282 var reset_map = HashMap(i32, i32, hash_i32, eql_i32).init(&direct_allocator.allocator);
283283 defer reset_map.deinit();
284284
285 assert((reset_map.put(1, 11) catch unreachable) == null);
286 assert((reset_map.put(2, 22) catch unreachable) == null);
287 assert((reset_map.put(3, 33) catch unreachable) == null);
285 assert((try reset_map.put(1, 11)) == null);
286 assert((try reset_map.put(2, 22)) == null);
287 assert((try reset_map.put(3, 33)) == null);
288288
289289 var keys = []i32{
290290 1,
std/os/index.zig+11-3
......@@ -553,8 +553,13 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {
553553 return null;
554554}
555555
556pub const GetEnvVarOwnedError = error{
557 OutOfMemory,
558 EnvironmentVariableNotFound,
559};
560
556561/// Caller must free returned memory.
557pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 {
562pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 {
558563 if (is_windows) {
559564 const key_with_null = try cstr.addNullByte(allocator, key);
560565 defer allocator.free(key_with_null);
......@@ -563,14 +568,17 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 {
563568 errdefer allocator.free(buf);
564569
565570 while (true) {
566 const windows_buf_len = try math.cast(windows.DWORD, buf.len);
571 const windows_buf_len = math.cast(windows.DWORD, buf.len) catch return error.OutOfMemory;
567572 const result = windows.GetEnvironmentVariableA(key_with_null.ptr, buf.ptr, windows_buf_len);
568573
569574 if (result == 0) {
570575 const err = windows.GetLastError();
571576 return switch (err) {
572577 windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound,
573 else => unexpectedErrorWindows(err),
578 else => {
579 _ = unexpectedErrorWindows(err);
580 return error.EnvironmentVariableNotFound;
581 },
574582 };
575583 }
576584
std/special/build_runner.zig+6-3
......@@ -122,10 +122,13 @@ pub fn main() !void {
122122 return usageAndErr(&builder, true, try stderr_stream);
123123
124124 builder.make(targets.toSliceConst()) catch |err| {
125 if (err == error.InvalidStepName) {
126 return usageAndErr(&builder, true, try stderr_stream);
125 switch (err) {
126 error.InvalidStepName => {
127 return usageAndErr(&builder, true, try stderr_stream);
128 },
129 error.UncleanExit => os.exit(1),
130 else => return err,
127131 }
128 return err;
129132 };
130133}
131134
std/zig/bench.zig+6-8
......@@ -19,20 +19,18 @@ pub fn main() !void {
1919 }
2020 const end = timer.read();
2121 memory_used /= iterations;
22 const elapsed_s = f64(end - start) / std.os.time.ns_per_s;
23 const bytes_per_sec = f64(source.len * iterations) / elapsed_s;
22 const elapsed_s = @intToFloat(f64, end - start) / std.os.time.ns_per_s;
23 const bytes_per_sec = @intToFloat(f64, source.len * iterations) / elapsed_s;
2424 const mb_per_sec = bytes_per_sec / (1024 * 1024);
2525
2626 var stdout_file = try std.io.getStdOut();
27 const stdout = *std.io.FileOutStream.init(*stdout_file).stream;
28 try stdout.print("{.3} MB/s, {} KB used \n", mb_per_sec, memory_used / 1024);
27 const stdout = &std.io.FileOutStream.init(&stdout_file).stream;
28 try stdout.print("{.3} MiB/s, {} KiB used \n", mb_per_sec, memory_used / 1024);
2929}
3030
3131fn testOnce() usize {
3232 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
33 var allocator = *fixed_buf_alloc.allocator;
34 var tokenizer = Tokenizer.init(source);
35 var parser = Parser.init(*tokenizer, allocator, "(memory buffer)");
36 _ = parser.parse() catch @panic("parse failure");
33 var allocator = &fixed_buf_alloc.allocator;
34 _ = std.zig.parse(allocator, source) catch @panic("parse failure");
3735 return fixed_buf_alloc.end_index;
3836}
test/compile_errors.zig+19
......@@ -1,6 +1,25 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "bad @alignCast at comptime",
6 \\comptime {
7 \\ const ptr = @intToPtr(*i32, 0x1);
8 \\ const aligned = @alignCast(4, ptr);
9 \\}
10 ,
11 ".tmp_source.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes",
12 );
13
14 cases.add(
15 "@ptrToInt on *void",
16 \\export fn entry() bool {
17 \\ return @ptrToInt(&{}) == @ptrToInt(&{});
18 \\}
19 ,
20 ".tmp_source.zig:2:23: error: pointer to size 0 type has no address",
21 );
22
423 cases.add(
524 "@popCount - non-integer",
625 \\export fn entry(x: f32) u32 {