authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-31 22:48:40-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-31 22:48:40-05:00
log5f518dbeb952186b7c11777b2454256c8c4fb9ac
tree31adf1939ed1173c29199e98dfbab9d8b9f6056f
parent5161d70620342749b1995fdaabb39220654cc941

*WIP* error sets converting std lib


62 files changed, 389 insertions(+), 510 deletions(-)

TODO created+5
......@@ -0,0 +1,5 @@
1sed -i 's/\(\bfn .*) \)%\(.*{\)$/\1!\2/g' $(find .. -name "*.zig")
2
3comptime assert(error{} ! i32 == i32);
4
5
build.zig+2-2
......@@ -10,7 +10,7 @@ const ArrayList = std.ArrayList;
1010const Buffer = std.Buffer;
1111const io = std.io;
1212
13pub fn build(b: &Builder) %void {
13pub fn build(b: &Builder) !void {
1414 const mode = b.standardReleaseOptions();
1515
1616 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
......@@ -149,7 +149,7 @@ const LibraryDep = struct {
149149 includes: ArrayList([]const u8),
150150};
151151
152fn findLLVM(b: &Builder, llvm_config_exe: []const u8) %LibraryDep {
152fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {
153153 const libs_output = try b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
154154 const includes_output = try b.exec([][]const u8{llvm_config_exe, "--includedir"});
155155 const libdir_output = try b.exec([][]const u8{llvm_config_exe, "--libdir"});
doc/docgen.zig+9-9
......@@ -12,7 +12,7 @@ const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
1212const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
1313const tmp_dir_name = "docgen_tmp";
1414
15pub fn main() %void {
15pub fn main() !void {
1616 // TODO use a more general purpose allocator here
1717 var inc_allocator = try std.heap.IncrementingAllocator.init(max_doc_file_size);
1818 defer inc_allocator.deinit();
......@@ -243,13 +243,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const
243243 return error.ParseError;
244244}
245245
246fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) %void {
246fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) !void {
247247 if (token.id != id) {
248248 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));
249249 }
250250}
251251
252fn eatToken(tokenizer: &Tokenizer, id: Token.Id) %Token {
252fn eatToken(tokenizer: &Tokenizer, id: Token.Id) !Token {
253253 const token = tokenizer.next();
254254 try assertToken(tokenizer, token, id);
255255 return token;
......@@ -316,7 +316,7 @@ const Action = enum {
316316 Close,
317317};
318318
319fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc {
319fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
320320 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
321321 errdefer urls.deinit();
322322
......@@ -540,7 +540,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc {
540540 };
541541}
542542
543fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 {
543fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {
544544 var buf = try std.Buffer.initSize(allocator, 0);
545545 defer buf.deinit();
546546
......@@ -560,7 +560,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 {
560560 return buf.toOwnedSlice();
561561}
562562
563fn escapeHtml(allocator: &mem.Allocator, input: []const u8) %[]u8 {
563fn escapeHtml(allocator: &mem.Allocator, input: []const u8) ![]u8 {
564564 var buf = try std.Buffer.initSize(allocator, 0);
565565 defer buf.deinit();
566566
......@@ -604,7 +604,7 @@ test "term color" {
604604 assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B"));
605605}
606606
607fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 {
607fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {
608608 var buf = try std.Buffer.initSize(allocator, 0);
609609 defer buf.deinit();
610610
......@@ -686,7 +686,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 {
686686
687687error ExampleFailedToCompile;
688688
689fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) %void {
689fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) !void {
690690 var code_progress_index: usize = 0;
691691 for (toc.nodes) |node| {
692692 switch (node) {
......@@ -977,7 +977,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io
977977error ChildCrashed;
978978error ChildExitError;
979979
980fn exec(allocator: &mem.Allocator, args: []const []const u8) %os.ChildProcess.ExecResult {
980fn exec(allocator: &mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult {
981981 const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size);
982982 switch (result.term) {
983983 os.ChildProcess.Term.Exited => |exit_code| {
doc/langref.html.in+4-2
......@@ -5598,7 +5598,9 @@ Block = option(Symbol ":") "{" many(Statement) "}"
55985598
55995599Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"
56005600
5601TypeExpr = PrefixOpExpression | "var"
5601TypeExpr = ErrorSetExpr | "var"
5602
5603ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression
56025604
56035605BlockOrExpression = Block | Expression
56045606
......@@ -5680,7 +5682,7 @@ MultiplyExpression = CurlySuffixExpression MultiplyOperator MultiplyExpression |
56805682
56815683CurlySuffixExpression = TypeExpr option(ContainerInitExpression)
56825684
5683MultiplyOperator = "!" | "*" | "/" | "%" | "**" | "*%"
5685MultiplyOperator = "*" | "/" | "%" | "**" | "*%"
56845686
56855687PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression
56865688
example/cat/main.zig+4-4
......@@ -5,7 +5,7 @@ const os = std.os;
55const warn = std.debug.warn;
66const allocator = std.debug.global_allocator;
77
8pub fn main() %void {
8pub fn main() !void {
99 var args_it = os.args();
1010 const exe = try unwrapArg(??args_it.next(allocator));
1111 var catted_anything = false;
......@@ -36,12 +36,12 @@ pub fn main() %void {
3636 }
3737}
3838
39fn usage(exe: []const u8) %void {
39fn usage(exe: []const u8) !void {
4040 warn("Usage: {} [FILE]...\n", exe);
4141 return error.Invalid;
4242}
4343
44fn cat_file(stdout: &io.File, file: &io.File) %void {
44fn cat_file(stdout: &io.File, file: &io.File) !void {
4545 var buf: [1024 * 4]u8 = undefined;
4646
4747 while (true) {
......@@ -61,7 +61,7 @@ fn cat_file(stdout: &io.File, file: &io.File) %void {
6161 }
6262}
6363
64fn unwrapArg(arg: %[]u8) %[]u8 {
64fn unwrapArg(arg: %[]u8) ![]u8 {
6565 return arg catch |err| {
6666 warn("Unable to parse command line: {}\n", err);
6767 return err;
example/guess_number/main.zig+1-1
......@@ -5,7 +5,7 @@ const fmt = std.fmt;
55const Rand = std.rand.Rand;
66const os = std.os;
77
8pub fn main() %void {
8pub fn main() !void {
99 var stdout_file = try io.getStdOut();
1010 var stdout_file_stream = io.FileOutStream.init(&stdout_file);
1111 const stdout = &stdout_file_stream.stream;
example/hello_world/hello.zig+1-1
......@@ -1,6 +1,6 @@
11const std = @import("std");
22
3pub fn main() %void {
3pub fn main() !void {
44 // If this program is run without stdout attached, exit with an error.
55 var stdout_file = try std.io.getStdOut();
66 // If this program encounters pipe failure when printing to stdout, exit
example/mix_o_files/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 const obj = b.addObject("base64", "base64.zig");
55
66 const exe = b.addCExecutable("test");
example/shared_library/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
55
66 const exe = b.addCExecutable("test");
src-self-hosted/main.zig+7-7
......@@ -20,7 +20,7 @@ error ZigInstallationNotFound;
2020
2121const default_zig_cache_name = "zig-cache";
2222
23pub fn main() %void {
23pub fn main() !void {
2424 main2() catch |err| {
2525 if (err != error.InvalidCommandLineArguments) {
2626 warn("{}\n", @errorName(err));
......@@ -48,7 +48,7 @@ fn badArgs(comptime format: []const u8, args: ...) error {
4848 return error.InvalidCommandLineArguments;
4949}
5050
51pub fn main2() %void {
51pub fn main2() !void {
5252 const allocator = std.heap.c_allocator;
5353
5454 const args = try os.argsAlloc(allocator);
......@@ -472,7 +472,7 @@ pub fn main2() %void {
472472 }
473473}
474474
475fn printUsage(stream: &io.OutStream) %void {
475fn printUsage(stream: &io.OutStream) !void {
476476 try stream.write(
477477 \\Usage: zig [command] [options]
478478 \\
......@@ -548,7 +548,7 @@ fn printUsage(stream: &io.OutStream) %void {
548548 );
549549}
550550
551fn printZen() %void {
551fn printZen() !void {
552552 var stdout_file = try io.getStdErr();
553553 try stdout_file.write(
554554 \\
......@@ -569,7 +569,7 @@ fn printZen() %void {
569569}
570570
571571/// Caller must free result
572fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) %[]u8 {
572fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) ![]u8 {
573573 if (zig_install_prefix_arg) |zig_install_prefix| {
574574 return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| {
575575 warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err));
......@@ -585,7 +585,7 @@ fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const
585585}
586586
587587/// Caller must free result
588fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) %[]u8 {
588fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) ![]u8 {
589589 const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig");
590590 errdefer allocator.free(test_zig_dir);
591591
......@@ -599,7 +599,7 @@ fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) %[]u8
599599}
600600
601601/// Caller must free result
602fn findZigLibDir(allocator: &mem.Allocator) %[]u8 {
602fn findZigLibDir(allocator: &mem.Allocator) ![]u8 {
603603 const self_exe_path = try os.selfExeDirPath(allocator);
604604 defer allocator.free(self_exe_path);
605605
src-self-hosted/module.zig+4-4
......@@ -198,7 +198,7 @@ pub const Module = struct {
198198 self.allocator.destroy(self);
199199 }
200200
201 pub fn build(self: &Module) %void {
201 pub fn build(self: &Module) !void {
202202 if (self.llvm_argv.len != 0) {
203203 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator,
204204 [][]const []const u8 { [][]const u8{"zig (LLVM option parsing)"}, self.llvm_argv, });
......@@ -263,11 +263,11 @@ pub const Module = struct {
263263
264264 }
265265
266 pub fn link(self: &Module, out_file: ?[]const u8) %void {
266 pub fn link(self: &Module, out_file: ?[]const u8) !void {
267267 warn("TODO link");
268268 }
269269
270 pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) %&LinkLib {
270 pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) !&LinkLib {
271271 const is_libc = mem.eql(u8, name, "c");
272272
273273 if (is_libc) {
......@@ -297,7 +297,7 @@ pub const Module = struct {
297297 }
298298};
299299
300fn printError(comptime format: []const u8, args: ...) %void {
300fn printError(comptime format: []const u8, args: ...) !void {
301301 var stderr_file = try std.io.getStdErr();
302302 var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file);
303303 const out_stream = &stderr_file_out_stream.stream;
src-self-hosted/parser.zig+18-18
......@@ -63,7 +63,7 @@ pub const Parser = struct {
6363 NullableField: &?&ast.Node,
6464 List: &ArrayList(&ast.Node),
6565
66 pub fn store(self: &const DestPtr, value: &ast.Node) %void {
66 pub fn store(self: &const DestPtr, value: &ast.Node) !void {
6767 switch (*self) {
6868 DestPtr.Field => |ptr| *ptr = value,
6969 DestPtr.NullableField => |ptr| *ptr = value,
......@@ -99,7 +99,7 @@ pub const Parser = struct {
9999
100100 /// Returns an AST tree, allocated with the parser's allocator.
101101 /// Result should be freed with `freeAst` when done.
102 pub fn parse(self: &Parser) %Tree {
102 pub fn parse(self: &Parser) !Tree {
103103 var stack = self.initUtilityArrayList(State);
104104 defer self.deinitUtilityArrayList(stack);
105105
......@@ -544,7 +544,7 @@ pub const Parser = struct {
544544 }
545545 }
546546
547 fn createRoot(self: &Parser) %&ast.NodeRoot {
547 fn createRoot(self: &Parser) !&ast.NodeRoot {
548548 const node = try self.allocator.create(ast.NodeRoot);
549549
550550 *node = ast.NodeRoot {
......@@ -599,7 +599,7 @@ pub const Parser = struct {
599599 return node;
600600 }
601601
602 fn createParamDecl(self: &Parser) %&ast.NodeParamDecl {
602 fn createParamDecl(self: &Parser) !&ast.NodeParamDecl {
603603 const node = try self.allocator.create(ast.NodeParamDecl);
604604
605605 *node = ast.NodeParamDecl {
......@@ -613,7 +613,7 @@ pub const Parser = struct {
613613 return node;
614614 }
615615
616 fn createBlock(self: &Parser, begin_token: &const Token) %&ast.NodeBlock {
616 fn createBlock(self: &Parser, begin_token: &const Token) !&ast.NodeBlock {
617617 const node = try self.allocator.create(ast.NodeBlock);
618618
619619 *node = ast.NodeBlock {
......@@ -625,7 +625,7 @@ pub const Parser = struct {
625625 return node;
626626 }
627627
628 fn createInfixOp(self: &Parser, op_token: &const Token, op: &const ast.NodeInfixOp.InfixOp) %&ast.NodeInfixOp {
628 fn createInfixOp(self: &Parser, op_token: &const Token, op: &const ast.NodeInfixOp.InfixOp) !&ast.NodeInfixOp {
629629 const node = try self.allocator.create(ast.NodeInfixOp);
630630
631631 *node = ast.NodeInfixOp {
......@@ -638,7 +638,7 @@ pub const Parser = struct {
638638 return node;
639639 }
640640
641 fn createPrefixOp(self: &Parser, op_token: &const Token, op: &const ast.NodePrefixOp.PrefixOp) %&ast.NodePrefixOp {
641 fn createPrefixOp(self: &Parser, op_token: &const Token, op: &const ast.NodePrefixOp.PrefixOp) !&ast.NodePrefixOp {
642642 const node = try self.allocator.create(ast.NodePrefixOp);
643643
644644 *node = ast.NodePrefixOp {
......@@ -650,7 +650,7 @@ pub const Parser = struct {
650650 return node;
651651 }
652652
653 fn createIdentifier(self: &Parser, name_token: &const Token) %&ast.NodeIdentifier {
653 fn createIdentifier(self: &Parser, name_token: &const Token) !&ast.NodeIdentifier {
654654 const node = try self.allocator.create(ast.NodeIdentifier);
655655
656656 *node = ast.NodeIdentifier {
......@@ -660,7 +660,7 @@ pub const Parser = struct {
660660 return node;
661661 }
662662
663 fn createIntegerLiteral(self: &Parser, token: &const Token) %&ast.NodeIntegerLiteral {
663 fn createIntegerLiteral(self: &Parser, token: &const Token) !&ast.NodeIntegerLiteral {
664664 const node = try self.allocator.create(ast.NodeIntegerLiteral);
665665
666666 *node = ast.NodeIntegerLiteral {
......@@ -670,7 +670,7 @@ pub const Parser = struct {
670670 return node;
671671 }
672672
673 fn createFloatLiteral(self: &Parser, token: &const Token) %&ast.NodeFloatLiteral {
673 fn createFloatLiteral(self: &Parser, token: &const Token) !&ast.NodeFloatLiteral {
674674 const node = try self.allocator.create(ast.NodeFloatLiteral);
675675
676676 *node = ast.NodeFloatLiteral {
......@@ -680,13 +680,13 @@ pub const Parser = struct {
680680 return node;
681681 }
682682
683 fn createAttachIdentifier(self: &Parser, dest_ptr: &const DestPtr, name_token: &const Token) %&ast.NodeIdentifier {
683 fn createAttachIdentifier(self: &Parser, dest_ptr: &const DestPtr, name_token: &const Token) !&ast.NodeIdentifier {
684684 const node = try self.createIdentifier(name_token);
685685 try dest_ptr.store(&node.base);
686686 return node;
687687 }
688688
689 fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) %&ast.NodeParamDecl {
689 fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) !&ast.NodeParamDecl {
690690 const node = try self.createParamDecl();
691691 try list.append(&node.base);
692692 return node;
......@@ -730,13 +730,13 @@ pub const Parser = struct {
730730 return error.ParseError;
731731 }
732732
733 fn expectToken(self: &Parser, token: &const Token, id: @TagType(Token.Id)) %void {
733 fn expectToken(self: &Parser, token: &const Token, id: @TagType(Token.Id)) !void {
734734 if (token.id != id) {
735735 return self.parseError(token, "expected {}, found {}", @tagName(id), @tagName(token.id));
736736 }
737737 }
738738
739 fn eatToken(self: &Parser, id: @TagType(Token.Id)) %Token {
739 fn eatToken(self: &Parser, id: @TagType(Token.Id)) !Token {
740740 const token = self.getNextToken();
741741 try self.expectToken(token, id);
742742 return token;
......@@ -763,7 +763,7 @@ pub const Parser = struct {
763763 indent: usize,
764764 };
765765
766 pub fn renderAst(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) %void {
766 pub fn renderAst(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) !void {
767767 var stack = self.initUtilityArrayList(RenderAstFrame);
768768 defer self.deinitUtilityArrayList(stack);
769769
......@@ -802,7 +802,7 @@ pub const Parser = struct {
802802 Indent: usize,
803803 };
804804
805 pub fn renderSource(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) %void {
805 pub fn renderSource(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) !void {
806806 var stack = self.initUtilityArrayList(RenderState);
807807 defer self.deinitUtilityArrayList(stack);
808808
......@@ -1038,7 +1038,7 @@ pub const Parser = struct {
10381038
10391039var fixed_buffer_mem: [100 * 1024]u8 = undefined;
10401040
1041fn testParse(source: []const u8, allocator: &mem.Allocator) %[]u8 {
1041fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 {
10421042 var padded_source: [0x100]u8 = undefined;
10431043 std.mem.copy(u8, padded_source[0..source.len], source);
10441044 padded_source[source.len + 0] = '\n';
......@@ -1064,7 +1064,7 @@ error MemoryLeakDetected;
10641064
10651065// TODO test for memory leaks
10661066// TODO test for valid frees
1067fn testCanonical(source: []const u8) %void {
1067fn testCanonical(source: []const u8) !void {
10681068 const needed_alloc_count = x: {
10691069 // Try it once with unlimited memory, make sure it works
10701070 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
src/analyze.cpp+6-4
......@@ -516,6 +516,7 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
516516
517517TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type) {
518518 assert(err_set_type->id == TypeTableEntryIdErrorSet);
519 assert(!type_is_invalid(payload_type));
519520
520521 TypeId type_id = {};
521522 type_id.id = TypeTableEntryIdErrorUnion;
......@@ -1409,6 +1410,11 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14091410 }
14101411
14111412 TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
1413 if (type_is_invalid(specified_return_type)) {
1414 fn_type_id.return_type = g->builtin_types.entry_invalid;
1415 return g->builtin_types.entry_invalid;
1416 }
1417
14121418 if (fn_proto->auto_err_set) {
14131419 TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(g, fn_entry);
14141420 fn_type_id.return_type = get_error_union_type(g, inferred_err_set_type, specified_return_type);
......@@ -1416,10 +1422,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14161422 fn_type_id.return_type = specified_return_type;
14171423 }
14181424
1419 if (type_is_invalid(fn_type_id.return_type)) {
1420 return g->builtin_types.entry_invalid;
1421 }
1422
14231425 if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) {
14241426 add_node_error(g, fn_proto->return_type,
14251427 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",
src/parser.cpp+24-6
......@@ -241,7 +241,28 @@ static Token *ast_eat_token(ParseContext *pc, size_t *token_index, TokenId token
241241}
242242
243243/*
244TypeExpr = PrefixOpExpression | "var"
244ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression
245*/
246static AstNode *ast_parse_error_set_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
247 AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory);
248 if (!prefix_op_expr) {
249 return nullptr;
250 }
251 Token *token = &pc->tokens->at(*token_index);
252 if (token->id == TokenIdBang) {
253 *token_index += 1;
254 AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token);
255 node->data.bin_op_expr.op1 = prefix_op_expr;
256 node->data.bin_op_expr.bin_op = BinOpTypeErrorUnion;
257 node->data.bin_op_expr.op2 = ast_parse_prefix_op_expr(pc, token_index, true);
258 return node;
259 } else {
260 return prefix_op_expr;
261 }
262}
263
264/*
265TypeExpr = ErrorSetExpr | "var"
245266*/
246267static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
247268 Token *token = &pc->tokens->at(*token_index);
......@@ -250,7 +271,7 @@ static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool
250271 *token_index += 1;
251272 return node;
252273 } else {
253 return ast_parse_prefix_op_expr(pc, token_index, mandatory);
274 return ast_parse_error_set_expr(pc, token_index, mandatory);
254275 }
255276}
256277
......@@ -2346,10 +2367,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
23462367 node->data.fn_proto.return_type = ast_create_node(pc, NodeTypeErrorType, next_token);
23472368 return node;
23482369 }
2349
2350 return node;
2351 }
2352 if (next_token->id == TokenIdBang) {
2370 } else if (next_token->id == TokenIdBang) {
23532371 *token_index += 1;
23542372 node->data.fn_proto.auto_err_set = true;
23552373 next_token = &pc->tokens->at(*token_index);
std/array_list.zig+5-5
......@@ -59,18 +59,18 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
5959 return result;
6060 }
6161
62 pub fn append(l: &Self, item: &const T) %void {
62 pub fn append(l: &Self, item: &const T) !void {
6363 const new_item_ptr = try l.addOne();
6464 *new_item_ptr = *item;
6565 }
6666
67 pub fn appendSlice(l: &Self, items: []align(A) const T) %void {
67 pub fn appendSlice(l: &Self, items: []align(A) const T) !void {
6868 try l.ensureCapacity(l.len + items.len);
6969 mem.copy(T, l.items[l.len..], items);
7070 l.len += items.len;
7171 }
7272
73 pub fn resize(l: &Self, new_len: usize) %void {
73 pub fn resize(l: &Self, new_len: usize) !void {
7474 try l.ensureCapacity(new_len);
7575 l.len = new_len;
7676 }
......@@ -80,7 +80,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
8080 l.len = new_len;
8181 }
8282
83 pub fn ensureCapacity(l: &Self, new_capacity: usize) %void {
83 pub fn ensureCapacity(l: &Self, new_capacity: usize) !void {
8484 var better_capacity = l.items.len;
8585 if (better_capacity >= new_capacity) return;
8686 while (true) {
......@@ -90,7 +90,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
9090 l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity);
9191 }
9292
93 pub fn addOne(l: &Self) %&T {
93 pub fn addOne(l: &Self) !&T {
9494 const new_length = l.len + 1;
9595 try l.ensureCapacity(new_length);
9696 const result = &l.items[l.len];
std/base64.zig+9-14
......@@ -79,8 +79,6 @@ pub const Base64Encoder = struct {
7979};
8080
8181pub const standard_decoder = Base64Decoder.init(standard_alphabet_chars, standard_pad_char);
82error InvalidPadding;
83error InvalidCharacter;
8482
8583pub const Base64Decoder = struct {
8684 /// e.g. 'A' => 0.
......@@ -111,7 +109,7 @@ pub const Base64Decoder = struct {
111109 }
112110
113111 /// If the encoded buffer is detected to be invalid, returns error.InvalidPadding.
114 pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) %usize {
112 pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) !usize {
115113 if (source.len % 4 != 0) return error.InvalidPadding;
116114 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
117115 }
......@@ -119,7 +117,7 @@ pub const Base64Decoder = struct {
119117 /// dest.len must be what you get from ::calcSize.
120118 /// invalid characters result in error.InvalidCharacter.
121119 /// invalid padding results in error.InvalidPadding.
122 pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) %void {
120 pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) !void {
123121 assert(dest.len == (decoder.calcSize(source) catch unreachable));
124122 assert(source.len % 4 == 0);
125123
......@@ -163,8 +161,6 @@ pub const Base64Decoder = struct {
163161 }
164162};
165163
166error OutputTooSmall;
167
168164pub const Base64DecoderWithIgnore = struct {
169165 decoder: Base64Decoder,
170166 char_is_ignored: [256]bool,
......@@ -185,7 +181,7 @@ pub const Base64DecoderWithIgnore = struct {
185181 }
186182
187183 /// If no characters end up being ignored or padding, this will be the exact decoded size.
188 pub fn calcSizeUpperBound(encoded_len: usize) %usize {
184 pub fn calcSizeUpperBound(encoded_len: usize) !usize {
189185 return @divTrunc(encoded_len, 4) * 3;
190186 }
191187
......@@ -193,7 +189,7 @@ pub const Base64DecoderWithIgnore = struct {
193189 /// Invalid padding results in error.InvalidPadding.
194190 /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound.
195191 /// Returns the number of bytes writen to dest.
196 pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) %usize {
192 pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) !usize {
197193 const decoder = &decoder_with_ignore.decoder;
198194
199195 var src_cursor: usize = 0;
......@@ -378,7 +374,7 @@ test "base64" {
378374 comptime (testBase64() catch unreachable);
379375}
380376
381fn testBase64() %void {
377fn testBase64() !void {
382378 try testAllApis("", "");
383379 try testAllApis("f", "Zg==");
384380 try testAllApis("fo", "Zm8=");
......@@ -412,7 +408,7 @@ fn testBase64() %void {
412408 try testOutputTooSmallError("AAAAAA==");
413409}
414410
415fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) %void {
411fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void {
416412 // Base64Encoder
417413 {
418414 var buffer: [0x100]u8 = undefined;
......@@ -449,7 +445,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) %void
449445 }
450446}
451447
452fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) %void {
448fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !void {
453449 const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
454450 standard_alphabet_chars, standard_pad_char, " ");
455451 var buffer: [0x100]u8 = undefined;
......@@ -458,8 +454,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) %voi
458454 assert(mem.eql(u8, decoded[0..written], expected_decoded));
459455}
460456
461error ExpectedError;
462fn testError(encoded: []const u8, expected_err: error) %void {
457fn testError(encoded: []const u8, expected_err: error) !void {
463458 const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
464459 standard_alphabet_chars, standard_pad_char, " ");
465460 var buffer: [0x100]u8 = undefined;
......@@ -475,7 +470,7 @@ fn testError(encoded: []const u8, expected_err: error) %void {
475470 } else |err| if (err != expected_err) return err;
476471}
477472
478fn testOutputTooSmallError(encoded: []const u8) %void {
473fn testOutputTooSmallError(encoded: []const u8) !void {
479474 const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
480475 standard_alphabet_chars, standard_pad_char, " ");
481476 var buffer: [0x100]u8 = undefined;
std/buf_map.zig+2-2
......@@ -27,7 +27,7 @@ pub const BufMap = struct {
2727 self.hash_map.deinit();
2828 }
2929
30 pub fn set(self: &BufMap, key: []const u8, value: []const u8) %void {
30 pub fn set(self: &BufMap, key: []const u8, value: []const u8) !void {
3131 if (self.hash_map.get(key)) |entry| {
3232 const value_copy = try self.copy(value);
3333 errdefer self.free(value_copy);
......@@ -67,7 +67,7 @@ pub const BufMap = struct {
6767 self.hash_map.allocator.free(mut_value);
6868 }
6969
70 fn copy(self: &BufMap, value: []const u8) %[]const u8 {
70 fn copy(self: &BufMap, value: []const u8) ![]const u8 {
7171 const result = try self.hash_map.allocator.alloc(u8, value.len);
7272 mem.copy(u8, result, value);
7373 return result;
std/buf_set.zig+2-2
......@@ -24,7 +24,7 @@ pub const BufSet = struct {
2424 self.hash_map.deinit();
2525 }
2626
27 pub fn put(self: &BufSet, key: []const u8) %void {
27 pub fn put(self: &BufSet, key: []const u8) !void {
2828 if (self.hash_map.get(key) == null) {
2929 const key_copy = try self.copy(key);
3030 errdefer self.free(key_copy);
......@@ -55,7 +55,7 @@ pub const BufSet = struct {
5555 self.hash_map.allocator.free(mut_value);
5656 }
5757
58 fn copy(self: &BufSet, value: []const u8) %[]const u8 {
58 fn copy(self: &BufSet, value: []const u8) ![]const u8 {
5959 const result = try self.hash_map.allocator.alloc(u8, value.len);
6060 mem.copy(u8, result, value);
6161 return result;
std/buffer.zig+9-9
......@@ -12,14 +12,14 @@ pub const Buffer = struct {
1212 list: ArrayList(u8),
1313
1414 /// Must deinitialize with deinit.
15 pub fn init(allocator: &Allocator, m: []const u8) %Buffer {
15 pub fn init(allocator: &Allocator, m: []const u8) !Buffer {
1616 var self = try initSize(allocator, m.len);
1717 mem.copy(u8, self.list.items, m);
1818 return self;
1919 }
2020
2121 /// Must deinitialize with deinit.
22 pub fn initSize(allocator: &Allocator, size: usize) %Buffer {
22 pub fn initSize(allocator: &Allocator, size: usize) !Buffer {
2323 var self = initNull(allocator);
2424 try self.resize(size);
2525 return self;
......@@ -37,7 +37,7 @@ pub const Buffer = struct {
3737 }
3838
3939 /// Must deinitialize with deinit.
40 pub fn initFromBuffer(buffer: &const Buffer) %Buffer {
40 pub fn initFromBuffer(buffer: &const Buffer) !Buffer {
4141 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
4242 }
4343
......@@ -80,7 +80,7 @@ pub const Buffer = struct {
8080 self.list.items[self.len()] = 0;
8181 }
8282
83 pub fn resize(self: &Buffer, new_len: usize) %void {
83 pub fn resize(self: &Buffer, new_len: usize) !void {
8484 try self.list.resize(new_len + 1);
8585 self.list.items[self.len()] = 0;
8686 }
......@@ -93,24 +93,24 @@ pub const Buffer = struct {
9393 return self.list.len - 1;
9494 }
9595
96 pub fn append(self: &Buffer, m: []const u8) %void {
96 pub fn append(self: &Buffer, m: []const u8) !void {
9797 const old_len = self.len();
9898 try self.resize(old_len + m.len);
9999 mem.copy(u8, self.list.toSlice()[old_len..], m);
100100 }
101101
102102 // TODO: remove, use OutStream for this
103 pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) %void {
103 pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) !void {
104104 return fmt.format(self, append, format, args);
105105 }
106106
107107 // TODO: remove, use OutStream for this
108 pub fn appendByte(self: &Buffer, byte: u8) %void {
108 pub fn appendByte(self: &Buffer, byte: u8) !void {
109109 return self.appendByteNTimes(byte, 1);
110110 }
111111
112112 // TODO: remove, use OutStream for this
113 pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) %void {
113 pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) !void {
114114 var prev_size: usize = self.len();
115115 const new_size = prev_size + count;
116116 try self.resize(new_size);
......@@ -137,7 +137,7 @@ pub const Buffer = struct {
137137 return mem.eql(u8, self.list.items[start..l], m);
138138 }
139139
140 pub fn replaceContents(self: &const Buffer, m: []const u8) %void {
140 pub fn replaceContents(self: &const Buffer, m: []const u8) !void {
141141 try self.resize(m.len);
142142 mem.copy(u8, self.list.toSlice(), m);
143143 }
std/build.zig+21-28
......@@ -15,13 +15,6 @@ const BufSet = std.BufSet;
1515const BufMap = std.BufMap;
1616const fmt_lib = std.fmt;
1717
18error ExtraArg;
19error UncleanExit;
20error InvalidStepName;
21error DependencyLoopDetected;
22error NoCompilerFound;
23error NeedAnObject;
24
2518pub const Builder = struct {
2619 uninstall_tls: TopLevelStep,
2720 install_tls: TopLevelStep,
......@@ -242,7 +235,7 @@ pub const Builder = struct {
242235 self.lib_paths.append(path) catch unreachable;
243236 }
244237
245 pub fn make(self: &Builder, step_names: []const []const u8) %void {
238 pub fn make(self: &Builder, step_names: []const []const u8) !void {
246239 var wanted_steps = ArrayList(&Step).init(self.allocator);
247240 defer wanted_steps.deinit();
248241
......@@ -278,7 +271,7 @@ pub const Builder = struct {
278271 return &self.uninstall_tls.step;
279272 }
280273
281 fn makeUninstall(uninstall_step: &Step) %void {
274 fn makeUninstall(uninstall_step: &Step) !void {
282275 const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
283276 const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
284277
......@@ -292,7 +285,7 @@ pub const Builder = struct {
292285 // TODO remove empty directories
293286 }
294287
295 fn makeOneStep(self: &Builder, s: &Step) %void {
288 fn makeOneStep(self: &Builder, s: &Step) !void {
296289 if (s.loop_flag) {
297290 warn("Dependency loop detected:\n {}\n", s.name);
298291 return error.DependencyLoopDetected;
......@@ -313,7 +306,7 @@ pub const Builder = struct {
313306 try s.make();
314307 }
315308
316 fn getTopLevelStepByName(self: &Builder, name: []const u8) %&Step {
309 fn getTopLevelStepByName(self: &Builder, name: []const u8) !&Step {
317310 for (self.top_level_steps.toSliceConst()) |top_level_step| {
318311 if (mem.eql(u8, top_level_step.step.name, name)) {
319312 return &top_level_step.step;
......@@ -548,7 +541,7 @@ pub const Builder = struct {
548541 return self.invalid_user_input;
549542 }
550543
551 fn spawnChild(self: &Builder, argv: []const []const u8) %void {
544 fn spawnChild(self: &Builder, argv: []const []const u8) !void {
552545 return self.spawnChildEnvMap(null, &self.env_map, argv);
553546 }
554547
......@@ -595,7 +588,7 @@ pub const Builder = struct {
595588 }
596589 }
597590
598 pub fn makePath(self: &Builder, path: []const u8) %void {
591 pub fn makePath(self: &Builder, path: []const u8) !void {
599592 os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
600593 warn("Unable to create path {}: {}\n", path, @errorName(err));
601594 return err;
......@@ -630,11 +623,11 @@ pub const Builder = struct {
630623 self.installed_files.append(full_path) catch unreachable;
631624 }
632625
633 fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) %void {
626 fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) !void {
634627 return self.copyFileMode(source_path, dest_path, 0o666);
635628 }
636629
637 fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: usize) %void {
630 fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: usize) !void {
638631 if (self.verbose) {
639632 warn("cp {} {}\n", source_path, dest_path);
640633 }
......@@ -672,7 +665,7 @@ pub const Builder = struct {
672665 }
673666 }
674667
675 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) %[]const u8 {
668 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 {
676669 // TODO report error for ambiguous situations
677670 const exe_extension = (Target { .Native = {}}).exeFileExt();
678671 for (self.search_prefixes.toSliceConst()) |search_prefix| {
......@@ -721,7 +714,7 @@ pub const Builder = struct {
721714 return error.FileNotFound;
722715 }
723716
724 pub fn exec(self: &Builder, argv: []const []const u8) %[]u8 {
717 pub fn exec(self: &Builder, argv: []const []const u8) ![]u8 {
725718 const max_output_size = 100 * 1024;
726719 const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size);
727720 switch (result.term) {
......@@ -1180,12 +1173,12 @@ pub const LibExeObjStep = struct {
11801173 self.disable_libc = disable;
11811174 }
11821175
1183 fn make(step: &Step) %void {
1176 fn make(step: &Step) !void {
11841177 const self = @fieldParentPtr(LibExeObjStep, "step", step);
11851178 return if (self.is_zig) self.makeZig() else self.makeC();
11861179 }
11871180
1188 fn makeZig(self: &LibExeObjStep) %void {
1181 fn makeZig(self: &LibExeObjStep) !void {
11891182 const builder = self.builder;
11901183
11911184 assert(self.is_zig);
......@@ -1396,7 +1389,7 @@ pub const LibExeObjStep = struct {
13961389 }
13971390 }
13981391
1399 fn makeC(self: &LibExeObjStep) %void {
1392 fn makeC(self: &LibExeObjStep) !void {
14001393 const builder = self.builder;
14011394
14021395 const cc = builder.getCCExe();
......@@ -1687,7 +1680,7 @@ pub const TestStep = struct {
16871680 self.exec_cmd_args = args;
16881681 }
16891682
1690 fn make(step: &Step) %void {
1683 fn make(step: &Step) !void {
16911684 const self = @fieldParentPtr(TestStep, "step", step);
16921685 const builder = self.builder;
16931686
......@@ -1796,7 +1789,7 @@ pub const CommandStep = struct {
17961789 return self;
17971790 }
17981791
1799 fn make(step: &Step) %void {
1792 fn make(step: &Step) !void {
18001793 const self = @fieldParentPtr(CommandStep, "step", step);
18011794
18021795 const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;
......@@ -1836,7 +1829,7 @@ const InstallArtifactStep = struct {
18361829 return self;
18371830 }
18381831
1839 fn make(step: &Step) %void {
1832 fn make(step: &Step) !void {
18401833 const self = @fieldParentPtr(Self, "step", step);
18411834 const builder = self.builder;
18421835
......@@ -1868,7 +1861,7 @@ pub const InstallFileStep = struct {
18681861 };
18691862 }
18701863
1871 fn make(step: &Step) %void {
1864 fn make(step: &Step) !void {
18721865 const self = @fieldParentPtr(InstallFileStep, "step", step);
18731866 try self.builder.copyFile(self.src_path, self.dest_path);
18741867 }
......@@ -1889,7 +1882,7 @@ pub const WriteFileStep = struct {
18891882 };
18901883 }
18911884
1892 fn make(step: &Step) %void {
1885 fn make(step: &Step) !void {
18931886 const self = @fieldParentPtr(WriteFileStep, "step", step);
18941887 const full_path = self.builder.pathFromRoot(self.file_path);
18951888 const full_path_dir = os.path.dirname(full_path);
......@@ -1917,7 +1910,7 @@ pub const LogStep = struct {
19171910 };
19181911 }
19191912
1920 fn make(step: &Step) %void {
1913 fn make(step: &Step) !void {
19211914 const self = @fieldParentPtr(LogStep, "step", step);
19221915 warn("{}", self.data);
19231916 }
......@@ -1936,7 +1929,7 @@ pub const RemoveDirStep = struct {
19361929 };
19371930 }
19381931
1939 fn make(step: &Step) %void {
1932 fn make(step: &Step) !void {
19401933 const self = @fieldParentPtr(RemoveDirStep, "step", step);
19411934
19421935 const full_path = self.builder.pathFromRoot(self.dir_path);
......@@ -1967,7 +1960,7 @@ pub const Step = struct {
19671960 return init(name, allocator, makeNoOp);
19681961 }
19691962
1970 pub fn make(self: &Step) %void {
1963 pub fn make(self: &Step) !void {
19711964 if (self.done_flag)
19721965 return;
19731966
std/crypto/throughput_test.zig+1-1
......@@ -18,7 +18,7 @@ const c = @cImport({
1818
1919const Mb = 1024 * 1024;
2020
21pub fn main() %void {
21pub fn main() !void {
2222 var stdout_file = try std.io.getStdOut();
2323 var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
2424 const stdout = &stdout_out_stream.stream;
std/cstr.zig+2-2
......@@ -42,7 +42,7 @@ fn testCStrFnsImpl() void {
4242/// Returns a mutable slice with exactly the same size which is guaranteed to
4343/// have a null byte after it.
4444/// Caller owns the returned memory.
45pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) %[]u8 {
45pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) ![]u8 {
4646 const result = try allocator.alloc(u8, slice.len + 1);
4747 mem.copy(u8, result, slice);
4848 result[slice.len] = 0;
......@@ -56,7 +56,7 @@ pub const NullTerminated2DArray = struct {
5656
5757 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator
5858 /// Caller must deinit result
59 pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) %NullTerminated2DArray {
59 pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) !NullTerminated2DArray {
6060 var new_len: usize = 1; // 1 for the list null
6161 var byte_count: usize = 0;
6262 for (slices) |slice| {
std/debug/failing_allocator.zig+2-2
......@@ -28,7 +28,7 @@ pub const FailingAllocator = struct {
2828 };
2929 }
3030
31 fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) %[]u8 {
31 fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) ![]u8 {
3232 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
3333 if (self.index == self.fail_index) {
3434 return error.OutOfMemory;
......@@ -39,7 +39,7 @@ pub const FailingAllocator = struct {
3939 return result;
4040 }
4141
42 fn realloc(allocator: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
42 fn realloc(allocator: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
4343 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
4444 if (new_size <= old_mem.len) {
4545 self.freed_bytes += old_mem.len - new_size;
std/elf.zig+4-6
......@@ -6,8 +6,6 @@ const mem = std.mem;
66const debug = std.debug;
77const InStream = std.stream.InStream;
88
9error InvalidFormat;
10
119pub const SHT_NULL = 0;
1210pub const SHT_PROGBITS = 1;
1311pub const SHT_SYMTAB = 2;
......@@ -81,14 +79,14 @@ pub const Elf = struct {
8179 prealloc_file: io.File,
8280
8381 /// Call close when done.
84 pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) %void {
82 pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) !void {
8583 try elf.prealloc_file.open(path);
8684 try elf.openFile(allocator, &elf.prealloc_file);
8785 elf.auto_close_stream = true;
8886 }
8987
9088 /// Call close when done.
91 pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &io.File) %void {
89 pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &io.File) !void {
9290 elf.allocator = allocator;
9391 elf.in_file = file;
9492 elf.auto_close_stream = false;
......@@ -239,7 +237,7 @@ pub const Elf = struct {
239237 elf.in_file.close();
240238 }
241239
242 pub fn findSection(elf: &Elf, name: []const u8) %?&SectionHeader {
240 pub fn findSection(elf: &Elf, name: []const u8) !?&SectionHeader {
243241 var file_stream = io.FileInStream.init(elf.in_file);
244242 const in = &file_stream.stream;
245243
......@@ -263,7 +261,7 @@ pub const Elf = struct {
263261 return null;
264262 }
265263
266 pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) %void {
264 pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) !void {
267265 try elf.in_file.seekTo(elf_section.offset);
268266 }
269267};
std/fmt/index.zig+31-34
......@@ -24,8 +24,8 @@ const State = enum { // TODO put inside format function and make sure the name a
2424/// Renders fmt string with args, calling output with slices of bytes.
2525/// If `output` returns an error, the error is returned from `format` and
2626/// `output` is not called again.
27pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
28 comptime fmt: []const u8, args: ...) %void
27pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void,
28 comptime fmt: []const u8, args: ...) Errors!void
2929{
3030 comptime var start_index = 0;
3131 comptime var state = State.Start;
......@@ -58,7 +58,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
5858 start_index = i;
5959 },
6060 '}' => {
61 try formatValue(args[next_arg], context, output);
61 try formatValue(args[next_arg], context, Errors, output);
6262 next_arg += 1;
6363 state = State.Start;
6464 start_index = i + 1;
......@@ -110,7 +110,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
110110 },
111111 State.Integer => switch (c) {
112112 '}' => {
113 try formatInt(args[next_arg], radix, uppercase, width, context, output);
113 try formatInt(args[next_arg], radix, uppercase, width, context, Errors, output);
114114 next_arg += 1;
115115 state = State.Start;
116116 start_index = i + 1;
......@@ -124,7 +124,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
124124 State.IntegerWidth => switch (c) {
125125 '}' => {
126126 width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
127 try formatInt(args[next_arg], radix, uppercase, width, context, output);
127 try formatInt(args[next_arg], radix, uppercase, width, context, Errors, output);
128128 next_arg += 1;
129129 state = State.Start;
130130 start_index = i + 1;
......@@ -134,7 +134,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
134134 },
135135 State.Float => switch (c) {
136136 '}' => {
137 try formatFloatDecimal(args[next_arg], 0, context, output);
137 try formatFloatDecimal(args[next_arg], 0, context, Errors, output);
138138 next_arg += 1;
139139 state = State.Start;
140140 start_index = i + 1;
......@@ -148,7 +148,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
148148 State.FloatWidth => switch (c) {
149149 '}' => {
150150 width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
151 try formatFloatDecimal(args[next_arg], width, context, output);
151 try formatFloatDecimal(args[next_arg], width, context, Errors, output);
152152 next_arg += 1;
153153 state = State.Start;
154154 start_index = i + 1;
......@@ -159,7 +159,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
159159 State.BufWidth => switch (c) {
160160 '}' => {
161161 width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
162 try formatBuf(args[next_arg], width, context, output);
162 try formatBuf(args[next_arg], width, context, Errors, output);
163163 next_arg += 1;
164164 state = State.Start;
165165 start_index = i + 1;
......@@ -169,7 +169,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
169169 },
170170 State.Character => switch (c) {
171171 '}' => {
172 try formatAsciiChar(args[next_arg], context, output);
172 try formatAsciiChar(args[next_arg], context, Errors, output);
173173 next_arg += 1;
174174 state = State.Start;
175175 start_index = i + 1;
......@@ -191,7 +191,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
191191 }
192192}
193193
194pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
194pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
195195 const T = @typeOf(value);
196196 switch (@typeId(T)) {
197197 builtin.TypeId.Int => {
......@@ -208,16 +208,16 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
208208 },
209209 builtin.TypeId.Nullable => {
210210 if (value) |payload| {
211 return formatValue(payload, context, output);
211 return formatValue(payload, context, Errors, output);
212212 } else {
213213 return output(context, "null");
214214 }
215215 },
216216 builtin.TypeId.ErrorUnion => {
217217 if (value) |payload| {
218 return formatValue(payload, context, output);
218 return formatValue(payload, context, Errors, output);
219219 } else |err| {
220 return formatValue(err, context, output);
220 return formatValue(err, context, Errors, output);
221221 }
222222 },
223223 builtin.TypeId.Error => {
......@@ -240,12 +240,12 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
240240 }
241241}
242242
243pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
243pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
244244 return output(context, (&c)[0..1]);
245245}
246246
247247pub fn formatBuf(buf: []const u8, width: usize,
248 context: var, output: fn(@typeOf(context), []const u8)%void) %void
248 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
249249{
250250 try output(context, buf);
251251
......@@ -256,7 +256,7 @@ pub fn formatBuf(buf: []const u8, width: usize,
256256 }
257257}
258258
259pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
259pub fn formatFloat(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
260260 var x = f64(value);
261261
262262 // Errol doesn't handle these special cases.
......@@ -294,7 +294,7 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons
294294 }
295295}
296296
297pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
297pub fn formatFloatDecimal(value: var, precision: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
298298 var x = f64(value);
299299
300300 // Errol doesn't handle these special cases.
......@@ -336,7 +336,7 @@ pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn
336336
337337
338338pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
339 context: var, output: fn(@typeOf(context), []const u8)%void) %void
339 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)errors!void) errors!void
340340{
341341 if (@typeOf(value).is_signed) {
342342 return formatIntSigned(value, base, uppercase, width, context, output);
......@@ -346,7 +346,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
346346}
347347
348348fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
349 context: var, output: fn(@typeOf(context), []const u8)%void) %void
349 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
350350{
351351 const uint = @IntType(false, @typeOf(value).bit_count);
352352 if (value < 0) {
......@@ -367,7 +367,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
367367}
368368
369369fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
370 context: var, output: fn(@typeOf(context), []const u8)%void) %void
370 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
371371{
372372 // max_int_digits accounts for the minus sign. when printing an unsigned
373373 // number we don't need to do that.
......@@ -417,12 +417,12 @@ const FormatIntBuf = struct {
417417 out_buf: []u8,
418418 index: usize,
419419};
420fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) %void {
420fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) !void {
421421 mem.copy(u8, context.out_buf[context.index..], bytes);
422422 context.index += bytes.len;
423423}
424424
425pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) %T {
425pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
426426 if (!T.is_signed)
427427 return parseUnsigned(T, buf, radix);
428428 if (buf.len == 0)
......@@ -446,7 +446,7 @@ test "fmt.parseInt" {
446446 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
447447}
448448
449pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) %T {
449pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) !T {
450450 var x: T = 0;
451451
452452 for (buf) |c| {
......@@ -458,8 +458,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) %T {
458458 return x;
459459}
460460
461error InvalidChar;
462fn charToDigit(c: u8, radix: u8) %u8 {
461fn charToDigit(c: u8, radix: u8) !u8 {
463462 const value = switch (c) {
464463 '0' ... '9' => c - '0',
465464 'A' ... 'Z' => c - 'A' + 10,
......@@ -485,28 +484,26 @@ const BufPrintContext = struct {
485484 remaining: []u8,
486485};
487486
488error BufferTooSmall;
489fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) %void {
487fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
490488 if (context.remaining.len < bytes.len) return error.BufferTooSmall;
491489 mem.copy(u8, context.remaining, bytes);
492490 context.remaining = context.remaining[bytes.len..];
493491}
494492
495pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) %[]u8 {
493pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
496494 var context = BufPrintContext { .remaining = buf, };
497495 try format(&context, bufPrintWrite, fmt, args);
498496 return buf[0..buf.len - context.remaining.len];
499497}
500498
501pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) %[]u8 {
499pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
502500 var size: usize = 0;
503 // Cannot fail because `countSize` cannot fail.
504 format(&size, countSize, fmt, args) catch unreachable;
501 format(&size, error{}, countSize, fmt, args);
505502 const buf = try allocator.alloc(u8, size);
506503 return bufPrint(buf, fmt, args);
507504}
508505
509fn countSize(size: &usize, bytes: []const u8) %void {
506fn countSize(size: &usize, bytes: []const u8) void {
510507 *size += bytes.len;
511508}
512509
......@@ -561,13 +558,13 @@ test "fmt.format" {
561558 }
562559 {
563560 var buf1: [32]u8 = undefined;
564 const value: %i32 = 1234;
561 const value: error!i32 = 1234;
565562 const result = try bufPrint(buf1[0..], "error union: {}\n", value);
566563 assert(mem.eql(u8, result, "error union: 1234\n"));
567564 }
568565 {
569566 var buf1: [32]u8 = undefined;
570 const value: %i32 = error.InvalidChar;
567 const value: error!i32 = error.InvalidChar;
571568 const result = try bufPrint(buf1[0..], "error union: {}\n", value);
572569 assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));
573570 }
std/hash_map.zig+2-2
......@@ -80,7 +80,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
8080 }
8181
8282 /// Returns the value that was already there.
83 pub fn put(hm: &Self, key: K, value: &const V) %?V {
83 pub fn put(hm: &Self, key: K, value: &const V) !?V {
8484 if (hm.entries.len == 0) {
8585 try hm.initCapacity(16);
8686 }
......@@ -151,7 +151,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
151151 };
152152 }
153153
154 fn initCapacity(hm: &Self, capacity: usize) %void {
154 fn initCapacity(hm: &Self, capacity: usize) !void {
155155 hm.entries = try hm.allocator.alloc(Entry, capacity);
156156 hm.size = 0;
157157 hm.max_distance_from_start_index = 0;
std/heap.zig+5-7
......@@ -9,8 +9,6 @@ const c = std.c;
99
1010const Allocator = mem.Allocator;
1111
12error OutOfMemory;
13
1412pub const c_allocator = &c_allocator_state;
1513var c_allocator_state = Allocator {
1614 .allocFn = cAlloc,
......@@ -18,14 +16,14 @@ var c_allocator_state = Allocator {
1816 .freeFn = cFree,
1917};
2018
21fn cAlloc(self: &Allocator, n: usize, alignment: u29) %[]u8 {
19fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {
2220 return if (c.malloc(usize(n))) |buf|
2321 @ptrCast(&u8, buf)[0..n]
2422 else
2523 error.OutOfMemory;
2624}
2725
28fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
26fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
2927 const old_ptr = @ptrCast(&c_void, old_mem.ptr);
3028 if (c.realloc(old_ptr, new_size)) |buf| {
3129 return @ptrCast(&u8, buf)[0..new_size];
......@@ -47,7 +45,7 @@ pub const IncrementingAllocator = struct {
4745 end_index: usize,
4846 heap_handle: if (builtin.os == Os.windows) os.windows.HANDLE else void,
4947
50 fn init(capacity: usize) %IncrementingAllocator {
48 fn init(capacity: usize) !IncrementingAllocator {
5149 switch (builtin.os) {
5250 Os.linux, Os.macosx, Os.ios => {
5351 const p = os.posix;
......@@ -105,7 +103,7 @@ pub const IncrementingAllocator = struct {
105103 return self.bytes.len - self.end_index;
106104 }
107105
108 fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 {
106 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {
109107 const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator);
110108 const addr = @ptrToInt(&self.bytes[self.end_index]);
111109 const rem = @rem(addr, alignment);
......@@ -120,7 +118,7 @@ pub const IncrementingAllocator = struct {
120118 return result;
121119 }
122120
123 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
121 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
124122 if (new_size <= old_mem.len) {
125123 return old_mem[0..new_size];
126124 } else {
std/io.zig+41-67
......@@ -26,31 +26,7 @@ test "import io tests" {
2626 }
2727}
2828
29/// The function received invalid input at runtime. An Invalid error means a
30/// bug in the program that called the function.
31error Invalid;
32
33error DiskQuota;
34error FileTooBig;
35error Io;
36error NoSpaceLeft;
37error BadPerm;
38error BrokenPipe;
39error BadFd;
40error IsDir;
41error NotDir;
42error SymLinkLoop;
43error ProcessFdQuotaExceeded;
44error SystemFdQuotaExceeded;
45error NameTooLong;
46error NoDevice;
47error PathNotFound;
48error OutOfMemory;
49error Unseekable;
50error EndOfFile;
51error FilePosLargerThanPointerRange;
52
53pub fn getStdErr() %File {
29pub fn getStdErr() !File {
5430 const handle = if (is_windows)
5531 try os.windowsGetStdHandle(system.STD_ERROR_HANDLE)
5632 else if (is_posix)
......@@ -60,7 +36,7 @@ pub fn getStdErr() %File {
6036 return File.openHandle(handle);
6137}
6238
63pub fn getStdOut() %File {
39pub fn getStdOut() !File {
6440 const handle = if (is_windows)
6541 try os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE)
6642 else if (is_posix)
......@@ -70,7 +46,7 @@ pub fn getStdOut() %File {
7046 return File.openHandle(handle);
7147}
7248
73pub fn getStdIn() %File {
49pub fn getStdIn() !File {
7450 const handle = if (is_windows)
7551 try os.windowsGetStdHandle(system.STD_INPUT_HANDLE)
7652 else if (is_posix)
......@@ -94,7 +70,7 @@ pub const FileInStream = struct {
9470 };
9571 }
9672
97 fn readFn(in_stream: &InStream, buffer: []u8) %usize {
73 fn readFn(in_stream: &InStream, buffer: []u8) !usize {
9874 const self = @fieldParentPtr(FileInStream, "stream", in_stream);
9975 return self.file.read(buffer);
10076 }
......@@ -114,7 +90,7 @@ pub const FileOutStream = struct {
11490 };
11591 }
11692
117 fn writeFn(out_stream: &OutStream, bytes: []const u8) %void {
93 fn writeFn(out_stream: &OutStream, bytes: []const u8) !void {
11894 const self = @fieldParentPtr(FileOutStream, "stream", out_stream);
11995 return self.file.write(bytes);
12096 }
......@@ -129,7 +105,7 @@ pub const File = struct {
129105 /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned.
130106 /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
131107 /// Call close to clean up.
132 pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) %File {
108 pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) !File {
133109 if (is_posix) {
134110 const flags = system.O_LARGEFILE|system.O_RDONLY;
135111 const fd = try os.posixOpen(path, flags, 0, allocator);
......@@ -144,7 +120,7 @@ pub const File = struct {
144120 }
145121
146122 /// Calls `openWriteMode` with 0o666 for the mode.
147 pub fn openWrite(path: []const u8, allocator: ?&mem.Allocator) %File {
123 pub fn openWrite(path: []const u8, allocator: ?&mem.Allocator) !File {
148124 return openWriteMode(path, 0o666, allocator);
149125
150126 }
......@@ -154,7 +130,7 @@ pub const File = struct {
154130 /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned.
155131 /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
156132 /// Call close to clean up.
157 pub fn openWriteMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) %File {
133 pub fn openWriteMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) !File {
158134 if (is_posix) {
159135 const flags = system.O_LARGEFILE|system.O_WRONLY|system.O_CREAT|system.O_CLOEXEC|system.O_TRUNC;
160136 const fd = try os.posixOpen(path, flags, mode, allocator);
......@@ -189,7 +165,7 @@ pub const File = struct {
189165 return os.isTty(self.handle);
190166 }
191167
192 pub fn seekForward(self: &File, amount: isize) %void {
168 pub fn seekForward(self: &File, amount: isize) !void {
193169 switch (builtin.os) {
194170 Os.linux, Os.macosx, Os.ios => {
195171 const result = system.lseek(self.handle, amount, system.SEEK_CUR);
......@@ -218,7 +194,7 @@ pub const File = struct {
218194 }
219195 }
220196
221 pub fn seekTo(self: &File, pos: usize) %void {
197 pub fn seekTo(self: &File, pos: usize) !void {
222198 switch (builtin.os) {
223199 Os.linux, Os.macosx, Os.ios => {
224200 const ipos = try math.cast(isize, pos);
......@@ -249,7 +225,7 @@ pub const File = struct {
249225 }
250226 }
251227
252 pub fn getPos(self: &File) %usize {
228 pub fn getPos(self: &File) !usize {
253229 switch (builtin.os) {
254230 Os.linux, Os.macosx, Os.ios => {
255231 const result = system.lseek(self.handle, 0, system.SEEK_CUR);
......@@ -289,7 +265,7 @@ pub const File = struct {
289265 }
290266 }
291267
292 pub fn getEndPos(self: &File) %usize {
268 pub fn getEndPos(self: &File) !usize {
293269 if (is_posix) {
294270 var stat: system.Stat = undefined;
295271 const err = system.getErrno(system.fstat(self.handle, &stat));
......@@ -318,7 +294,7 @@ pub const File = struct {
318294 }
319295 }
320296
321 pub fn read(self: &File, buffer: []u8) %usize {
297 pub fn read(self: &File, buffer: []u8) !usize {
322298 if (is_posix) {
323299 var index: usize = 0;
324300 while (index < buffer.len) {
......@@ -360,7 +336,7 @@ pub const File = struct {
360336 }
361337 }
362338
363 fn write(self: &File, bytes: []const u8) %void {
339 fn write(self: &File, bytes: []const u8) !void {
364340 if (is_posix) {
365341 try os.posixWrite(self.handle, bytes);
366342 } else if (is_windows) {
......@@ -371,19 +347,16 @@ pub const File = struct {
371347 }
372348};
373349
374error StreamTooLong;
375error EndOfStream;
376
377350pub const InStream = struct {
378351 /// Return the number of bytes read. If the number read is smaller than buf.len, it
379352 /// means the stream reached the end. Reaching the end of a stream is not an error
380353 /// condition.
381 readFn: fn(self: &InStream, buffer: []u8) %usize,
354 readFn: fn(self: &InStream, buffer: []u8) !usize,
382355
383356 /// Replaces `buffer` contents by reading from the stream until it is finished.
384357 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
385358 /// the contents read from the stream are lost.
386 pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) %void {
359 pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) !void {
387360 try buffer.resize(0);
388361
389362 var actual_buf_len: usize = 0;
......@@ -408,7 +381,7 @@ pub const InStream = struct {
408381 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
409382 /// Caller owns returned memory.
410383 /// If this function returns an error, the contents from the stream read so far are lost.
411 pub fn readAllAlloc(self: &InStream, allocator: &mem.Allocator, max_size: usize) %[]u8 {
384 pub fn readAllAlloc(self: &InStream, allocator: &mem.Allocator, max_size: usize) ![]u8 {
412385 var buf = Buffer.initNull(allocator);
413386 defer buf.deinit();
414387
......@@ -420,7 +393,7 @@ pub const InStream = struct {
420393 /// Does not include the delimiter in the result.
421394 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents
422395 /// read from the stream so far are lost.
423 pub fn readUntilDelimiterBuffer(self: &InStream, buffer: &Buffer, delimiter: u8, max_size: usize) %void {
396 pub fn readUntilDelimiterBuffer(self: &InStream, buffer: &Buffer, delimiter: u8, max_size: usize) !void {
424397 try buf.resize(0);
425398
426399 while (true) {
......@@ -443,7 +416,7 @@ pub const InStream = struct {
443416 /// Caller owns returned memory.
444417 /// If this function returns an error, the contents from the stream read so far are lost.
445418 pub fn readUntilDelimiterAlloc(self: &InStream, allocator: &mem.Allocator,
446 delimiter: u8, max_size: usize) %[]u8
419 delimiter: u8, max_size: usize) ![]u8
447420 {
448421 var buf = Buffer.initNull(allocator);
449422 defer buf.deinit();
......@@ -455,43 +428,43 @@ pub const InStream = struct {
455428 /// Returns the number of bytes read. If the number read is smaller than buf.len, it
456429 /// means the stream reached the end. Reaching the end of a stream is not an error
457430 /// condition.
458 pub fn read(self: &InStream, buffer: []u8) %usize {
431 pub fn read(self: &InStream, buffer: []u8) !usize {
459432 return self.readFn(self, buffer);
460433 }
461434
462435 /// Same as `read` but end of stream returns `error.EndOfStream`.
463 pub fn readNoEof(self: &InStream, buf: []u8) %void {
436 pub fn readNoEof(self: &InStream, buf: []u8) !void {
464437 const amt_read = try self.read(buf);
465438 if (amt_read < buf.len) return error.EndOfStream;
466439 }
467440
468441 /// Reads 1 byte from the stream or returns `error.EndOfStream`.
469 pub fn readByte(self: &InStream) %u8 {
442 pub fn readByte(self: &InStream) !u8 {
470443 var result: [1]u8 = undefined;
471444 try self.readNoEof(result[0..]);
472445 return result[0];
473446 }
474447
475448 /// Same as `readByte` except the returned byte is signed.
476 pub fn readByteSigned(self: &InStream) %i8 {
449 pub fn readByteSigned(self: &InStream) !i8 {
477450 return @bitCast(i8, try self.readByte());
478451 }
479452
480 pub fn readIntLe(self: &InStream, comptime T: type) %T {
453 pub fn readIntLe(self: &InStream, comptime T: type) !T {
481454 return self.readInt(builtin.Endian.Little, T);
482455 }
483456
484 pub fn readIntBe(self: &InStream, comptime T: type) %T {
457 pub fn readIntBe(self: &InStream, comptime T: type) !T {
485458 return self.readInt(builtin.Endian.Big, T);
486459 }
487460
488 pub fn readInt(self: &InStream, endian: builtin.Endian, comptime T: type) %T {
461 pub fn readInt(self: &InStream, endian: builtin.Endian, comptime T: type) !T {
489462 var bytes: [@sizeOf(T)]u8 = undefined;
490463 try self.readNoEof(bytes[0..]);
491464 return mem.readInt(bytes, T, endian);
492465 }
493466
494 pub fn readVarInt(self: &InStream, endian: builtin.Endian, comptime T: type, size: usize) %T {
467 pub fn readVarInt(self: &InStream, endian: builtin.Endian, comptime T: type, size: usize) !T {
495468 assert(size <= @sizeOf(T));
496469 assert(size <= 8);
497470 var input_buf: [8]u8 = undefined;
......@@ -504,22 +477,23 @@ pub const InStream = struct {
504477};
505478
506479pub const OutStream = struct {
507 writeFn: fn(self: &OutStream, bytes: []const u8) %void,
480 // TODO allow specifying the error set
481 writeFn: fn(self: &OutStream, bytes: []const u8) error!void,
508482
509 pub fn print(self: &OutStream, comptime format: []const u8, args: ...) %void {
510 return std.fmt.format(self, self.writeFn, format, args);
483 pub fn print(self: &OutStream, comptime format: []const u8, args: ...) !void {
484 return std.fmt.format(self, error, self.writeFn, format, args);
511485 }
512486
513 pub fn write(self: &OutStream, bytes: []const u8) %void {
487 pub fn write(self: &OutStream, bytes: []const u8) !void {
514488 return self.writeFn(self, bytes);
515489 }
516490
517 pub fn writeByte(self: &OutStream, byte: u8) %void {
491 pub fn writeByte(self: &OutStream, byte: u8) !void {
518492 const slice = (&byte)[0..1];
519493 return self.writeFn(self, slice);
520494 }
521495
522 pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) %void {
496 pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) !void {
523497 const slice = (&byte)[0..1];
524498 var i: usize = 0;
525499 while (i < n) : (i += 1) {
......@@ -532,19 +506,19 @@ pub const OutStream = struct {
532506/// a fixed size buffer of size `std.os.max_noalloc_path_len` is an attempted solution. If the fixed
533507/// size buffer is too small, and the provided allocator is null, `error.NameTooLong` is returned.
534508/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
535pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) %void {
509pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) !void {
536510 var file = try File.openWrite(path, allocator);
537511 defer file.close();
538512 try file.write(data);
539513}
540514
541515/// On success, caller owns returned buffer.
542pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) %[]u8 {
516pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) ![]u8 {
543517 return readFileAllocExtra(path, allocator, 0);
544518}
545519/// On success, caller owns returned buffer.
546520/// Allocates extra_len extra bytes at the end of the file buffer, which are uninitialized.
547pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) %[]u8 {
521pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) ![]u8 {
548522 var file = try File.openRead(path, allocator);
549523 defer file.close();
550524
......@@ -589,7 +563,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) type {
589563 };
590564 }
591565
592 fn readFn(in_stream: &InStream, dest: []u8) %usize {
566 fn readFn(in_stream: &InStream, dest: []u8) !usize {
593567 const self = @fieldParentPtr(Self, "stream", in_stream);
594568
595569 var dest_index: usize = 0;
......@@ -652,7 +626,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type {
652626 };
653627 }
654628
655 pub fn flush(self: &Self) %void {
629 pub fn flush(self: &Self) !void {
656630 if (self.index == 0)
657631 return;
658632
......@@ -660,7 +634,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type {
660634 self.index = 0;
661635 }
662636
663 fn writeFn(out_stream: &OutStream, bytes: []const u8) %void {
637 fn writeFn(out_stream: &OutStream, bytes: []const u8) !void {
664638 const self = @fieldParentPtr(Self, "stream", out_stream);
665639
666640 if (bytes.len >= self.buffer.len) {
......@@ -698,7 +672,7 @@ pub const BufferOutStream = struct {
698672 };
699673 }
700674
701 fn writeFn(out_stream: &OutStream, bytes: []const u8) %void {
675 fn writeFn(out_stream: &OutStream, bytes: []const u8) !void {
702676 const self = @fieldParentPtr(BufferOutStream, "stream", out_stream);
703677 return self.buffer.append(bytes);
704678 }
std/linked_list.zig+2-2
......@@ -190,7 +190,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
190190 ///
191191 /// Returns:
192192 /// A pointer to the new node.
193 pub fn allocateNode(list: &Self, allocator: &Allocator) %&Node {
193 pub fn allocateNode(list: &Self, allocator: &Allocator) !&Node {
194194 comptime assert(!isIntrusive());
195195 return allocator.create(Node);
196196 }
......@@ -213,7 +213,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
213213 ///
214214 /// Returns:
215215 /// A pointer to the new node.
216 pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) %&Node {
216 pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node {
217217 comptime assert(!isIntrusive());
218218 var node = try list.allocateNode(allocator);
219219 *node = Node.init(data);
std/math/index.zig+13-31
......@@ -191,30 +191,26 @@ test "math.max" {
191191 assert(max(i32(-1), i32(2)) == 2);
192192}
193193
194error Overflow;
195pub fn mul(comptime T: type, a: T, b: T) %T {
194pub fn mul(comptime T: type, a: T, b: T) !T {
196195 var answer: T = undefined;
197196 return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer;
198197}
199198
200error Overflow;
201pub fn add(comptime T: type, a: T, b: T) %T {
199pub fn add(comptime T: type, a: T, b: T) !T {
202200 var answer: T = undefined;
203201 return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer;
204202}
205203
206error Overflow;
207pub fn sub(comptime T: type, a: T, b: T) %T {
204pub fn sub(comptime T: type, a: T, b: T) !T {
208205 var answer: T = undefined;
209206 return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
210207}
211208
212pub fn negate(x: var) %@typeOf(x) {
209pub fn negate(x: var) !@typeOf(x) {
213210 return sub(@typeOf(x), 0, x);
214211}
215212
216error Overflow;
217pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) %T {
213pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {
218214 var answer: T = undefined;
219215 return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer;
220216}
......@@ -323,8 +319,7 @@ fn testOverflow() void {
323319}
324320
325321
326error Overflow;
327pub fn absInt(x: var) %@typeOf(x) {
322pub fn absInt(x: var) !@typeOf(x) {
328323 const T = @typeOf(x);
329324 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
330325 comptime assert(T.is_signed); // must pass a signed integer to absInt
......@@ -347,9 +342,7 @@ fn testAbsInt() void {
347342
348343pub const absFloat = @import("fabs.zig").fabs;
349344
350error DivisionByZero;
351error Overflow;
352pub fn divTrunc(comptime T: type, numerator: T, denominator: T) %T {
345pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
353346 @setRuntimeSafety(false);
354347 if (denominator == 0)
355348 return error.DivisionByZero;
......@@ -372,9 +365,7 @@ fn testDivTrunc() void {
372365 assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
373366}
374367
375error DivisionByZero;
376error Overflow;
377pub fn divFloor(comptime T: type, numerator: T, denominator: T) %T {
368pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
378369 @setRuntimeSafety(false);
379370 if (denominator == 0)
380371 return error.DivisionByZero;
......@@ -397,10 +388,7 @@ fn testDivFloor() void {
397388 assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
398389}
399390
400error DivisionByZero;
401error Overflow;
402error UnexpectedRemainder;
403pub fn divExact(comptime T: type, numerator: T, denominator: T) %T {
391pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
404392 @setRuntimeSafety(false);
405393 if (denominator == 0)
406394 return error.DivisionByZero;
......@@ -428,9 +416,7 @@ fn testDivExact() void {
428416 if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
429417}
430418
431error DivisionByZero;
432error NegativeDenominator;
433pub fn mod(comptime T: type, numerator: T, denominator: T) %T {
419pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
434420 @setRuntimeSafety(false);
435421 if (denominator == 0)
436422 return error.DivisionByZero;
......@@ -455,9 +441,7 @@ fn testMod() void {
455441 if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
456442}
457443
458error DivisionByZero;
459error NegativeDenominator;
460pub fn rem(comptime T: type, numerator: T, denominator: T) %T {
444pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
461445 @setRuntimeSafety(false);
462446 if (denominator == 0)
463447 return error.DivisionByZero;
......@@ -505,8 +489,7 @@ test "math.absCast" {
505489
506490/// Returns the negation of the integer parameter.
507491/// Result is a signed integer.
508error Overflow;
509pub fn negateCast(x: var) %@IntType(true, @typeOf(x).bit_count) {
492pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
510493 if (@typeOf(x).is_signed)
511494 return negate(x);
512495
......@@ -532,8 +515,7 @@ test "math.negateCast" {
532515
533516/// Cast an integer to a different integer type. If the value doesn't fit,
534517/// return an error.
535error Overflow;
536pub fn cast(comptime T: type, x: var) %T {
518pub fn cast(comptime T: type, x: var) !T {
537519 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
538520 if (x > @maxValue(T)) {
539521 return error.Overflow;
std/mem.zig+11-11
......@@ -4,13 +4,13 @@ const assert = debug.assert;
44const math = std.math;
55const builtin = @import("builtin");
66
7error OutOfMemory;
8
97pub const Allocator = struct {
8 const Errors = error {OutOfMemory};
9
1010 /// Allocate byte_count bytes and return them in a slice, with the
1111 /// slice's pointer aligned at least to alignment bytes.
1212 /// The returned newly allocated memory is undefined.
13 allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) %[]u8,
13 allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) Errors![]u8,
1414
1515 /// If `new_byte_count > old_mem.len`:
1616 /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.
......@@ -21,12 +21,12 @@ pub const Allocator = struct {
2121 /// * alignment <= alignment of old_mem.ptr
2222 ///
2323 /// The returned newly allocated memory is undefined.
24 reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) %[]u8,
24 reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) Errors![]u8,
2525
2626 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
2727 freeFn: fn (self: &Allocator, old_mem: []u8) void,
2828
29 fn create(self: &Allocator, comptime T: type) %&T {
29 fn create(self: &Allocator, comptime T: type) !&T {
3030 const slice = try self.alloc(T, 1);
3131 return &slice[0];
3232 }
......@@ -35,7 +35,7 @@ pub const Allocator = struct {
3535 self.free(ptr[0..1]);
3636 }
3737
38 fn alloc(self: &Allocator, comptime T: type, n: usize) %[]T {
38 fn alloc(self: &Allocator, comptime T: type, n: usize) ![]T {
3939 return self.alignedAlloc(T, @alignOf(T), n);
4040 }
4141
......@@ -51,7 +51,7 @@ pub const Allocator = struct {
5151 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
5252 }
5353
54 fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) %[]T {
54 fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) ![]T {
5555 return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
5656 }
5757
......@@ -123,7 +123,7 @@ pub const FixedBufferAllocator = struct {
123123 };
124124 }
125125
126 fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 {
126 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {
127127 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
128128 const addr = @ptrToInt(&self.buffer[self.end_index]);
129129 const rem = @rem(addr, alignment);
......@@ -138,7 +138,7 @@ pub const FixedBufferAllocator = struct {
138138 return result;
139139 }
140140
141 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
141 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
142142 if (new_size <= old_mem.len) {
143143 return old_mem[0..new_size];
144144 } else {
......@@ -197,7 +197,7 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
197197}
198198
199199/// Copies ::m to newly allocated memory. Caller is responsible to free it.
200pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) %[]T {
200pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) ![]T {
201201 const new_buf = try allocator.alloc(T, m.len);
202202 copy(T, new_buf, m);
203203 return new_buf;
......@@ -428,7 +428,7 @@ const SplitIterator = struct {
428428
429429/// Naively combines a series of strings with a separator.
430430/// Allocates memory for the result, which must be freed by the caller.
431pub fn join(allocator: &Allocator, sep: u8, strings: ...) %[]u8 {
431pub fn join(allocator: &Allocator, sep: u8, strings: ...) ![]u8 {
432432 comptime assert(strings.len >= 1);
433433 var total_strings_len: usize = strings.len; // 1 sep per string
434434 {
std/net.zig+9-25
......@@ -5,19 +5,10 @@ const endian = std.endian;
55
66// TODO don't trust this file, it bit rotted. start over
77
8error SigInterrupt;
9error Io;
10error TimedOut;
11error ConnectionReset;
12error ConnectionRefused;
13error OutOfMemory;
14error NotSocket;
15error BadFd;
16
178const Connection = struct {
189 socket_fd: i32,
1910
20 pub fn send(c: Connection, buf: []const u8) %usize {
11 pub fn send(c: Connection, buf: []const u8) !usize {
2112 const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0);
2213 const send_err = linux.getErrno(send_ret);
2314 switch (send_err) {
......@@ -31,7 +22,7 @@ const Connection = struct {
3122 }
3223 }
3324
34 pub fn recv(c: Connection, buf: []u8) %[]u8 {
25 pub fn recv(c: Connection, buf: []u8) ![]u8 {
3526 const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null);
3627 const recv_err = linux.getErrno(recv_ret);
3728 switch (recv_err) {
......@@ -48,7 +39,7 @@ const Connection = struct {
4839 }
4940 }
5041
51 pub fn close(c: Connection) %void {
42 pub fn close(c: Connection) !void {
5243 switch (linux.getErrno(linux.close(c.socket_fd))) {
5344 0 => return,
5445 linux.EBADF => unreachable,
......@@ -66,7 +57,7 @@ const Address = struct {
6657 sort_key: i32,
6758};
6859
69pub fn lookup(hostname: []const u8, out_addrs: []Address) %[]Address {
60pub fn lookup(hostname: []const u8, out_addrs: []Address) ![]Address {
7061 if (hostname.len == 0) {
7162
7263 unreachable; // TODO
......@@ -75,7 +66,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) %[]Address {
7566 unreachable; // TODO
7667}
7768
78pub fn connectAddr(addr: &Address, port: u16) %Connection {
69pub fn connectAddr(addr: &Address, port: u16) !Connection {
7970 const socket_ret = linux.socket(addr.family, linux.SOCK_STREAM, linux.PROTO_tcp);
8071 const socket_err = linux.getErrno(socket_ret);
8172 if (socket_err > 0) {
......@@ -118,7 +109,7 @@ pub fn connectAddr(addr: &Address, port: u16) %Connection {
118109 };
119110}
120111
121pub fn connect(hostname: []const u8, port: u16) %Connection {
112pub fn connect(hostname: []const u8, port: u16) !Connection {
122113 var addrs_buf: [1]Address = undefined;
123114 const addrs_slice = try lookup(hostname, addrs_buf[0..]);
124115 const main_addr = &addrs_slice[0];
......@@ -126,9 +117,7 @@ pub fn connect(hostname: []const u8, port: u16) %Connection {
126117 return connectAddr(main_addr, port);
127118}
128119
129error InvalidIpLiteral;
130
131pub fn parseIpLiteral(buf: []const u8) %Address {
120pub fn parseIpLiteral(buf: []const u8) !Address {
132121
133122 return error.InvalidIpLiteral;
134123}
......@@ -146,12 +135,7 @@ fn hexDigit(c: u8) u8 {
146135 }
147136}
148137
149error InvalidChar;
150error Overflow;
151error JunkAtEnd;
152error Incomplete;
153
154fn parseIp6(buf: []const u8) %Address {
138fn parseIp6(buf: []const u8) !Address {
155139 var result: Address = undefined;
156140 result.family = linux.AF_INET6;
157141 result.scope_id = 0;
......@@ -232,7 +216,7 @@ fn parseIp6(buf: []const u8) %Address {
232216 return error.Incomplete;
233217}
234218
235fn parseIp4(buf: []const u8) %u32 {
219fn parseIp4(buf: []const u8) !u32 {
236220 var result: u32 = undefined;
237221 const out_ptr = ([]u8)((&result)[0..1]);
238222
std/os/child_process.zig+23-27
......@@ -13,10 +13,6 @@ const builtin = @import("builtin");
1313const Os = builtin.Os;
1414const LinkedList = std.LinkedList;
1515
16error PermissionDenied;
17error ProcessNotFound;
18error InvalidName;
19
2016var children_nodes = LinkedList(&ChildProcess).init();
2117
2218const is_windows = builtin.os == Os.windows;
......@@ -74,7 +70,7 @@ pub const ChildProcess = struct {
7470
7571 /// First argument in argv is the executable.
7672 /// On success must call deinit.
77 pub fn init(argv: []const []const u8, allocator: &mem.Allocator) %&ChildProcess {
73 pub fn init(argv: []const []const u8, allocator: &mem.Allocator) !&ChildProcess {
7874 const child = try allocator.create(ChildProcess);
7975 errdefer allocator.destroy(child);
8076
......@@ -103,7 +99,7 @@ pub const ChildProcess = struct {
10399 return child;
104100 }
105101
106 pub fn setUserName(self: &ChildProcess, name: []const u8) %void {
102 pub fn setUserName(self: &ChildProcess, name: []const u8) !void {
107103 const user_info = try os.getUserInfo(name);
108104 self.uid = user_info.uid;
109105 self.gid = user_info.gid;
......@@ -111,7 +107,7 @@ pub const ChildProcess = struct {
111107
112108 /// onTerm can be called before `spawn` returns.
113109 /// On success must call `kill` or `wait`.
114 pub fn spawn(self: &ChildProcess) %void {
110 pub fn spawn(self: &ChildProcess) !void {
115111 if (is_windows) {
116112 return self.spawnWindows();
117113 } else {
......@@ -119,13 +115,13 @@ pub const ChildProcess = struct {
119115 }
120116 }
121117
122 pub fn spawnAndWait(self: &ChildProcess) %Term {
118 pub fn spawnAndWait(self: &ChildProcess) !Term {
123119 try self.spawn();
124120 return self.wait();
125121 }
126122
127123 /// Forcibly terminates child process and then cleans up all resources.
128 pub fn kill(self: &ChildProcess) %Term {
124 pub fn kill(self: &ChildProcess) !Term {
129125 if (is_windows) {
130126 return self.killWindows(1);
131127 } else {
......@@ -133,7 +129,7 @@ pub const ChildProcess = struct {
133129 }
134130 }
135131
136 pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) %Term {
132 pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) !Term {
137133 if (self.term) |term| {
138134 self.cleanupStreams();
139135 return term;
......@@ -149,7 +145,7 @@ pub const ChildProcess = struct {
149145 return ??self.term;
150146 }
151147
152 pub fn killPosix(self: &ChildProcess) %Term {
148 pub fn killPosix(self: &ChildProcess) !Term {
153149 block_SIGCHLD();
154150 defer restore_SIGCHLD();
155151
......@@ -172,7 +168,7 @@ pub const ChildProcess = struct {
172168 }
173169
174170 /// Blocks until child process terminates and then cleans up all resources.
175 pub fn wait(self: &ChildProcess) %Term {
171 pub fn wait(self: &ChildProcess) !Term {
176172 if (is_windows) {
177173 return self.waitWindows();
178174 } else {
......@@ -220,7 +216,7 @@ pub const ChildProcess = struct {
220216 };
221217 }
222218
223 fn waitWindows(self: &ChildProcess) %Term {
219 fn waitWindows(self: &ChildProcess) !Term {
224220 if (self.term) |term| {
225221 self.cleanupStreams();
226222 return term;
......@@ -230,7 +226,7 @@ pub const ChildProcess = struct {
230226 return ??self.term;
231227 }
232228
233 fn waitPosix(self: &ChildProcess) %Term {
229 fn waitPosix(self: &ChildProcess) !Term {
234230 block_SIGCHLD();
235231 defer restore_SIGCHLD();
236232
......@@ -247,7 +243,7 @@ pub const ChildProcess = struct {
247243 self.allocator.destroy(self);
248244 }
249245
250 fn waitUnwrappedWindows(self: &ChildProcess) %void {
246 fn waitUnwrappedWindows(self: &ChildProcess) !void {
251247 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);
252248
253249 self.term = (%Term)(x: {
......@@ -295,7 +291,7 @@ pub const ChildProcess = struct {
295291 if (self.stderr) |*stderr| { stderr.close(); self.stderr = null; }
296292 }
297293
298 fn cleanupAfterWait(self: &ChildProcess, status: i32) %Term {
294 fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term {
299295 children_nodes.remove(&self.llnode);
300296
301297 defer {
......@@ -331,7 +327,7 @@ pub const ChildProcess = struct {
331327 ;
332328 }
333329
334 fn spawnPosix(self: &ChildProcess) %void {
330 fn spawnPosix(self: &ChildProcess) !void {
335331 // TODO atomically set a flag saying that we already did this
336332 install_SIGCHLD_handler();
337333
......@@ -440,7 +436,7 @@ pub const ChildProcess = struct {
440436 if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); }
441437 }
442438
443 fn spawnWindows(self: &ChildProcess) %void {
439 fn spawnWindows(self: &ChildProcess) !void {
444440 const saAttr = windows.SECURITY_ATTRIBUTES {
445441 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
446442 .bInheritHandle = windows.TRUE,
......@@ -623,7 +619,7 @@ pub const ChildProcess = struct {
623619 if (self.stdout_behavior == StdIo.Pipe) { os.close(??g_hChildStd_OUT_Wr); }
624620 }
625621
626 fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) %void {
622 fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) !void {
627623 switch (stdio) {
628624 StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno),
629625 StdIo.Close => os.close(std_fileno),
......@@ -655,7 +651,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
655651
656652/// Caller must dealloc.
657653/// Guarantees a null byte at result[result.len].
658fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) %[]u8 {
654fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) ![]u8 {
659655 var buf = try Buffer.initSize(allocator, 0);
660656 defer buf.deinit();
661657
......@@ -700,7 +696,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void {
700696// a namespace field lookup
701697const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;
702698
703fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void {
699fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void {
704700 if (windows.CreatePipe(rd, wr, sattr, 0) == 0) {
705701 const err = windows.GetLastError();
706702 return switch (err) {
......@@ -709,7 +705,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECUR
709705 }
710706}
711707
712fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) %void {
708fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) !void {
713709 if (windows.SetHandleInformation(h, mask, flags) == 0) {
714710 const err = windows.GetLastError();
715711 return switch (err) {
......@@ -718,7 +714,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D
718714 }
719715}
720716
721fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void {
717fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void {
722718 var rd_h: windows.HANDLE = undefined;
723719 var wr_h: windows.HANDLE = undefined;
724720 try windowsMakePipe(&rd_h, &wr_h, sattr);
......@@ -728,7 +724,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S
728724 *wr = wr_h;
729725}
730726
731fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void {
727fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void {
732728 var rd_h: windows.HANDLE = undefined;
733729 var wr_h: windows.HANDLE = undefined;
734730 try windowsMakePipe(&rd_h, &wr_h, sattr);
......@@ -738,7 +734,7 @@ fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const
738734 *wr = wr_h;
739735}
740736
741fn makePipe() %[2]i32 {
737fn makePipe() ![2]i32 {
742738 var fds: [2]i32 = undefined;
743739 const err = posix.getErrno(posix.pipe(&fds));
744740 if (err > 0) {
......@@ -764,13 +760,13 @@ fn forkChildErrReport(fd: i32, err: error) noreturn {
764760
765761const ErrInt = @IntType(false, @sizeOf(error) * 8);
766762
767fn writeIntFd(fd: i32, value: ErrInt) %void {
763fn writeIntFd(fd: i32, value: ErrInt) !void {
768764 var bytes: [@sizeOf(ErrInt)]u8 = undefined;
769765 mem.writeInt(bytes[0..], value, builtin.endian);
770766 os.posixWrite(fd, bytes[0..]) catch return error.SystemResources;
771767}
772768
773fn readIntFd(fd: i32) %ErrInt {
769fn readIntFd(fd: i32) !ErrInt {
774770 var bytes: [@sizeOf(ErrInt)]u8 = undefined;
775771 os.posixRead(fd, bytes[0..]) catch return error.SystemResources;
776772 return mem.readInt(bytes[0..], ErrInt, builtin.endian);
std/os/get_user_id.zig+2-5
......@@ -9,7 +9,7 @@ pub const UserInfo = struct {
99};
1010
1111/// POSIX function which gets a uid from username.
12pub fn getUserInfo(name: []const u8) %UserInfo {
12pub fn getUserInfo(name: []const u8) !UserInfo {
1313 return switch (builtin.os) {
1414 Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),
1515 else => @compileError("Unsupported OS"),
......@@ -24,13 +24,10 @@ const State = enum {
2424 ReadGroupId,
2525};
2626
27error UserNotFound;
28error CorruptPasswordFile;
29
3027// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else
3128// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.
3229
33pub fn posixGetUserInfo(name: []const u8) %UserInfo {
30pub fn posixGetUserInfo(name: []const u8) !UserInfo {
3431 var in_stream = try io.InStream.open("/etc/passwd", null);
3532 defer in_stream.close();
3633
std/os/index.zig-2
......@@ -1470,8 +1470,6 @@ test "std.os" {
14701470}
14711471
14721472
1473error Unexpected;
1474
14751473// TODO make this a build variable that you can set
14761474const unexpected_error_tracing = false;
14771475
std/os/linux.zig+1-1
......@@ -720,7 +720,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags:
720720// error SystemResources;
721721// error Io;
722722//
723// pub fn if_nametoindex(name: []u8) %u32 {
723// pub fn if_nametoindex(name: []u8) !u32 {
724724// var ifr: ifreq = undefined;
725725//
726726// if (name.len >= ifr.ifr_name.len) {
std/os/path.zig+11-18
......@@ -32,7 +32,7 @@ pub fn isSep(byte: u8) bool {
3232
3333/// Naively combines a series of paths with the native path seperator.
3434/// Allocates memory for the result, which must be freed by the caller.
35pub fn join(allocator: &Allocator, paths: ...) %[]u8 {
35pub fn join(allocator: &Allocator, paths: ...) ![]u8 {
3636 if (is_windows) {
3737 return joinWindows(allocator, paths);
3838 } else {
......@@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) %[]u8 {
4040 }
4141}
4242
43pub fn joinWindows(allocator: &Allocator, paths: ...) %[]u8 {
43pub fn joinWindows(allocator: &Allocator, paths: ...) ![]u8 {
4444 return mem.join(allocator, sep_windows, paths);
4545}
4646
47pub fn joinPosix(allocator: &Allocator, paths: ...) %[]u8 {
47pub fn joinPosix(allocator: &Allocator, paths: ...) ![]u8 {
4848 return mem.join(allocator, sep_posix, paths);
4949}
5050
......@@ -313,7 +313,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
313313}
314314
315315/// Converts the command line arguments into a slice and calls `resolveSlice`.
316pub fn resolve(allocator: &Allocator, args: ...) %[]u8 {
316pub fn resolve(allocator: &Allocator, args: ...) ![]u8 {
317317 var paths: [args.len][]const u8 = undefined;
318318 comptime var arg_i = 0;
319319 inline while (arg_i < args.len) : (arg_i += 1) {
......@@ -323,7 +323,7 @@ pub fn resolve(allocator: &Allocator, args: ...) %[]u8 {
323323}
324324
325325/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
326pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 {
326pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 {
327327 if (is_windows) {
328328 return resolveWindows(allocator, paths);
329329 } else {
......@@ -337,7 +337,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 {
337337/// If all paths are relative it uses the current working directory as a starting point.
338338/// Each drive has its own current working directory.
339339/// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters.
340pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 {
340pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
341341 if (paths.len == 0) {
342342 assert(is_windows); // resolveWindows called on non windows can't use getCwd
343343 return os.getCwd(allocator);
......@@ -520,7 +520,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 {
520520/// It resolves "." and "..".
521521/// The result does not have a trailing path separator.
522522/// If all paths are relative it uses the current working directory as a starting point.
523pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) %[]u8 {
523pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) ![]u8 {
524524 if (paths.len == 0) {
525525 assert(!is_windows); // resolvePosix called on windows can't use getCwd
526526 return os.getCwd(allocator);
......@@ -890,7 +890,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
890890/// resolve to the same path (after calling `resolve` on each), a zero-length
891891/// string is returned.
892892/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
893pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
893pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
894894 if (is_windows) {
895895 return relativeWindows(allocator, from, to);
896896 } else {
......@@ -898,7 +898,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
898898 }
899899}
900900
901pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
901pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
902902 const resolved_from = try resolveWindows(allocator, [][]const u8{from});
903903 defer allocator.free(resolved_from);
904904
......@@ -971,7 +971,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)
971971 return []u8{};
972972}
973973
974pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
974pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
975975 const resolved_from = try resolvePosix(allocator, [][]const u8{from});
976976 defer allocator.free(resolved_from);
977977
......@@ -1066,18 +1066,11 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons
10661066 assert(mem.eql(u8, result, expected_output));
10671067}
10681068
1069error AccessDenied;
1070error FileNotFound;
1071error NotSupported;
1072error NotDir;
1073error NameTooLong;
1074error SymLinkLoop;
1075error InputOutput;
10761069/// Return the canonicalized absolute pathname.
10771070/// Expands all symbolic links and resolves references to `.`, `..`, and
10781071/// extra `/` characters in ::pathname.
10791072/// Caller must deallocate result.
1080pub fn real(allocator: &Allocator, pathname: []const u8) %[]u8 {
1073pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {
10811074 switch (builtin.os) {
10821075 Os.windows => {
10831076 const pathname_buf = try allocator.alloc(u8, pathname.len + 1);
std/os/windows/util.zig+4-17
......@@ -6,11 +6,7 @@ const mem = std.mem;
66const BufMap = std.BufMap;
77const cstr = std.cstr;
88
9error WaitAbandoned;
10error WaitTimeOut;
11error Unexpected;
12
13pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) %void {
9pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) !void {
1410 const result = windows.WaitForSingleObject(handle, milliseconds);
1511 return switch (result) {
1612 windows.WAIT_ABANDONED => error.WaitAbandoned,
......@@ -30,12 +26,7 @@ pub fn windowsClose(handle: windows.HANDLE) void {
3026 assert(windows.CloseHandle(handle) != 0);
3127}
3228
33error SystemResources;
34error OperationAborted;
35error IoPending;
36error BrokenPipe;
37
38pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) %void {
29pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) !void {
3930 if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
4031 const err = windows.GetLastError();
4132 return switch (err) {
......@@ -75,9 +66,6 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
7566 mem.indexOf(u16, name_wide, []u16{'-','p','t','y'}) != null;
7667}
7768
78error SharingViolation;
79error PipeBusy;
80
8169/// `file_path` may need to be copied in memory to add a null terminating byte. In this case
8270/// a fixed size buffer of size ::max_noalloc_path_len is an attempted solution. If the fixed
8371/// size buffer is too small, and the provided allocator is null, ::error.NameTooLong is returned.
......@@ -120,7 +108,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m
120108}
121109
122110/// Caller must free result.
123pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) %[]u8 {
111pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) ![]u8 {
124112 // count bytes needed
125113 const bytes_needed = x: {
126114 var bytes_needed: usize = 1; // 1 for the final null byte
......@@ -151,8 +139,7 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)
151139 return result;
152140}
153141
154error DllNotFound;
155pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) %windows.HMODULE {
142pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) !windows.HMODULE {
156143 const padded_buff = try cstr.addNullByte(allocator, dll_path);
157144 defer allocator.free(padded_buff);
158145 return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound;
std/special/build_file_template.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 const mode = b.standardReleaseOptions();
55 const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig");
66 exe.setBuildMode(mode);
std/special/build_runner.zig+3-5
......@@ -8,9 +8,7 @@ const mem = std.mem;
88const ArrayList = std.ArrayList;
99const warn = std.debug.warn;
1010
11error InvalidArgs;
12
13pub fn main() %void {
11pub fn main() !void {
1412 var arg_it = os.args();
1513
1614 // TODO use a more general purpose allocator here
......@@ -125,7 +123,7 @@ pub fn main() %void {
125123 };
126124}
127125
128fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) %void {
126fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) !void {
129127 // run the build script to collect the options
130128 if (!already_ran_build) {
131129 builder.setInstallPrefix(null);
......@@ -188,7 +186,7 @@ fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutSt
188186 return error.InvalidArgs;
189187}
190188
191fn unwrapArg(arg: %[]u8) %[]u8 {
189fn unwrapArg(arg: %[]u8) ![]u8 {
192190 return arg catch |err| {
193191 warn("Unable to parse command line: {}\n", err);
194192 return err;
std/unicode.zig+6-14
......@@ -1,11 +1,9 @@
11const std = @import("./index.zig");
22
3error Utf8InvalidStartByte;
4
53/// Given the first byte of a UTF-8 codepoint,
64/// returns a number 1-4 indicating the total length of the codepoint in bytes.
75/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
8pub fn utf8ByteSequenceLength(first_byte: u8) %u3 {
6pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
97 if (first_byte < 0b10000000) return u3(1);
108 if (first_byte & 0b11100000 == 0b11000000) return u3(2);
119 if (first_byte & 0b11110000 == 0b11100000) return u3(3);
......@@ -13,16 +11,11 @@ pub fn utf8ByteSequenceLength(first_byte: u8) %u3 {
1311 return error.Utf8InvalidStartByte;
1412}
1513
16error Utf8OverlongEncoding;
17error Utf8ExpectedContinuation;
18error Utf8EncodesSurrogateHalf;
19error Utf8CodepointTooLarge;
20
2114/// Decodes the UTF-8 codepoint encoded in the given slice of bytes.
2215/// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable.
2316/// If you already know the length at comptime, you can call one of
2417/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
25pub fn utf8Decode(bytes: []const u8) %u32 {
18pub fn utf8Decode(bytes: []const u8) !u32 {
2619 return switch (bytes.len) {
2720 1 => u32(bytes[0]),
2821 2 => utf8Decode2(bytes),
......@@ -31,7 +24,7 @@ pub fn utf8Decode(bytes: []const u8) %u32 {
3124 else => unreachable,
3225 };
3326}
34pub fn utf8Decode2(bytes: []const u8) %u32 {
27pub fn utf8Decode2(bytes: []const u8) !u32 {
3528 std.debug.assert(bytes.len == 2);
3629 std.debug.assert(bytes[0] & 0b11100000 == 0b11000000);
3730 var value: u32 = bytes[0] & 0b00011111;
......@@ -44,7 +37,7 @@ pub fn utf8Decode2(bytes: []const u8) %u32 {
4437
4538 return value;
4639}
47pub fn utf8Decode3(bytes: []const u8) %u32 {
40pub fn utf8Decode3(bytes: []const u8) !u32 {
4841 std.debug.assert(bytes.len == 3);
4942 std.debug.assert(bytes[0] & 0b11110000 == 0b11100000);
5043 var value: u32 = bytes[0] & 0b00001111;
......@@ -62,7 +55,7 @@ pub fn utf8Decode3(bytes: []const u8) %u32 {
6255
6356 return value;
6457}
65pub fn utf8Decode4(bytes: []const u8) %u32 {
58pub fn utf8Decode4(bytes: []const u8) !u32 {
6659 std.debug.assert(bytes.len == 4);
6760 std.debug.assert(bytes[0] & 0b11111000 == 0b11110000);
6861 var value: u32 = bytes[0] & 0b00000111;
......@@ -85,7 +78,6 @@ pub fn utf8Decode4(bytes: []const u8) %u32 {
8578 return value;
8679}
8780
88error UnexpectedEof;
8981test "valid utf8" {
9082 testValid("\x00", 0x0);
9183 testValid("\x20", 0x20);
......@@ -161,7 +153,7 @@ fn testValid(bytes: []const u8, expected_codepoint: u32) void {
161153 std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint);
162154}
163155
164fn testDecode(bytes: []const u8) %u32 {
156fn testDecode(bytes: []const u8) !u32 {
165157 const length = try utf8ByteSequenceLength(bytes[0]);
166158 if (bytes.len < length) return error.UnexpectedEof;
167159 std.debug.assert(bytes.len == length);
test/cases/cast.zig+6-8
......@@ -32,7 +32,6 @@ fn funcWithConstPtrPtr(x: &const &i32) void {
3232 **x += 1;
3333}
3434
35error ItBroke;
3635test "explicit cast from integer to error type" {
3736 testCastIntToErr(error.ItBroke);
3837 comptime testCastIntToErr(error.ItBroke);
......@@ -110,11 +109,11 @@ test "return null from fn() %?&T" {
110109 const b = returnNullLitFromMaybeTypeErrorRef();
111110 assert((try a) == null and (try b) == null);
112111}
113fn returnNullFromMaybeTypeErrorRef() %?&A {
112fn returnNullFromMaybeTypeErrorRef() !?&A {
114113 const a: ?&A = null;
115114 return a;
116115}
117fn returnNullLitFromMaybeTypeErrorRef() %?&A {
116fn returnNullLitFromMaybeTypeErrorRef() !?&A {
118117 return null;
119118}
120119
......@@ -170,7 +169,7 @@ fn testCastZeroArrayToErrSliceMut() void {
170169 assert((gimmeErrOrSlice() catch unreachable).len == 0);
171170}
172171
173fn gimmeErrOrSlice() %[]u8 {
172fn gimmeErrOrSlice() ![]u8 {
174173 return []u8{};
175174}
176175
......@@ -188,7 +187,7 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" {
188187 assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
189188 }
190189}
191fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) %[]u8 {
190fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) ![]u8 {
192191 if (a) {
193192 return []u8{};
194193 }
......@@ -238,14 +237,13 @@ test "peer type resolution: error and [N]T" {
238237 comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
239238}
240239
241error BadValue;
242//fn testPeerErrorAndArray(x: u8) %[]const u8 {
240//fn testPeerErrorAndArray(x: u8) ![]const u8 {
243241// return switch (x) {
244242// 0x00 => "OK",
245243// else => error.BadValue,
246244// };
247245//}
248fn testPeerErrorAndArray2(x: u8) %[]const u8 {
246fn testPeerErrorAndArray2(x: u8) ![]const u8 {
249247 return switch (x) {
250248 0x00 => "OK",
251249 0x01 => "OKK",
test/cases/defer.zig+1-3
......@@ -3,9 +3,7 @@ const assert = @import("std").debug.assert;
33var result: [3]u8 = undefined;
44var index: usize = undefined;
55
6error FalseNotAllowed;
7
8fn runSomeErrorDefers(x: bool) %bool {
6fn runSomeErrorDefers(x: bool) !bool {
97 index = 0;
108 defer {result[index] = 'a'; index += 1;}
119 errdefer {result[index] = 'b'; index += 1;}
test/cases/enum_with_members.zig+1-1
......@@ -6,7 +6,7 @@ const ET = union(enum) {
66 SINT: i32,
77 UINT: u32,
88
9 pub fn print(a: &const ET, buf: []u8) %usize {
9 pub fn print(a: &const ET, buf: []u8) !usize {
1010 return switch (*a) {
1111 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
1212 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
test/cases/error.zig+6-15
......@@ -1,16 +1,16 @@
11const assert = @import("std").debug.assert;
22const mem = @import("std").mem;
33
4pub fn foo() %i32 {
4pub fn foo() !i32 {
55 const x = try bar();
66 return x + 1;
77}
88
9pub fn bar() %i32 {
9pub fn bar() !i32 {
1010 return 13;
1111}
1212
13pub fn baz() %i32 {
13pub fn baz() !i32 {
1414 const y = foo() catch 1234;
1515 return y + 1;
1616}
......@@ -19,7 +19,6 @@ test "error wrapping" {
1919 assert((baz() catch unreachable) == 15);
2020}
2121
22error ItBroke;
2322fn gimmeItBroke() []const u8 {
2423 return @errorName(error.ItBroke);
2524}
......@@ -28,8 +27,6 @@ test "@errorName" {
2827 assert(mem.eql(u8, @errorName(error.AnError), "AnError"));
2928 assert(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
3029}
31error AnError;
32error ALongerErrorName;
3330
3431
3532test "error values" {
......@@ -37,16 +34,11 @@ test "error values" {
3734 const b = i32(error.err2);
3835 assert(a != b);
3936}
40error err1;
41error err2;
4237
4338
4439test "redefinition of error values allowed" {
4540 shouldBeNotEqual(error.AnError, error.SecondError);
4641}
47error AnError;
48error AnError;
49error SecondError;
5042fn shouldBeNotEqual(a: error, b: error) void {
5143 if (a == b) unreachable;
5244}
......@@ -58,8 +50,7 @@ test "error binary operator" {
5850 assert(a == 3);
5951 assert(b == 10);
6052}
61error ItBroke;
62fn errBinaryOperatorG(x: bool) %isize {
53fn errBinaryOperatorG(x: bool) !isize {
6354 return if (x) error.ItBroke else isize(10);
6455}
6556
......@@ -75,11 +66,11 @@ test "error return in assignment" {
7566 doErrReturnInAssignment() catch unreachable;
7667}
7768
78fn doErrReturnInAssignment() %void {
69fn doErrReturnInAssignment() !void {
7970 var x : i32 = undefined;
8071 x = try makeANonErr();
8172}
8273
83fn makeANonErr() %i32 {
74fn makeANonErr() !i32 {
8475 return 1;
8576}
test/cases/ir_block_deps.zig+1-3
......@@ -1,6 +1,6 @@
11const assert = @import("std").debug.assert;
22
3fn foo(id: u64) %i32 {
3fn foo(id: u64) !i32 {
44 return switch (id) {
55 1 => getErrInt(),
66 2 => {
......@@ -13,8 +13,6 @@ fn foo(id: u64) %i32 {
1313
1414fn getErrInt() %i32 { return 0; }
1515
16error ItBroke;
17
1816test "ir block deps" {
1917 assert((foo(1) catch unreachable) == 0);
2018 assert((foo(2) catch unreachable) == 0);
test/cases/misc.zig+2-2
......@@ -262,7 +262,7 @@ test "generic malloc free" {
262262 memFree(u8, a);
263263}
264264const some_mem : [100]u8 = undefined;
265fn memAlloc(comptime T: type, n: usize) %[]T {
265fn memAlloc(comptime T: type, n: usize) ![]T {
266266 return @ptrCast(&T, &some_mem[0])[0..n];
267267}
268268fn memFree(comptime T: type, memory: []T) void { }
......@@ -419,7 +419,7 @@ test "cast slice to u8 slice" {
419419test "pointer to void return type" {
420420 testPointerToVoidReturnType() catch unreachable;
421421}
422fn testPointerToVoidReturnType() %void {
422fn testPointerToVoidReturnType() !void {
423423 const a = testPointerToVoidReturnType2();
424424 return *a;
425425}
test/cases/switch.zig+1-1
......@@ -225,7 +225,7 @@ fn switchWithUnreachable(x: i32) i32 {
225225 return 10;
226226}
227227
228fn return_a_number() %i32 {
228fn return_a_number() !i32 {
229229 return 1;
230230}
231231
test/cases/switch_prong_err_enum.zig+2-4
......@@ -2,19 +2,17 @@ const assert = @import("std").debug.assert;
22
33var read_count: u64 = 0;
44
5fn readOnce() %u64 {
5fn readOnce() !u64 {
66 read_count += 1;
77 return read_count;
88}
99
10error InvalidDebugInfo;
11
1210const FormValue = union(enum) {
1311 Address: u64,
1412 Other: bool,
1513};
1614
17fn doThing(form_id: u64) %FormValue {
15fn doThing(form_id: u64) !FormValue {
1816 return switch (form_id) {
1917 17 => FormValue { .Address = try readOnce() },
2018 else => error.InvalidDebugInfo,
test/cases/switch_prong_implicit_cast.zig+1-3
......@@ -5,9 +5,7 @@ const FormValue = union(enum) {
55 Two: bool,
66};
77
8error Whatever;
9
10fn foo(id: u64) %FormValue {
8fn foo(id: u64) !FormValue {
119 return switch (id) {
1210 2 => FormValue { .Two = true },
1311 1 => FormValue { .One = {} },
test/cases/try.zig+2-5
......@@ -17,10 +17,7 @@ fn tryOnErrorUnionImpl() void {
1717 assert(x == 11);
1818}
1919
20error ItBroke;
21error NoMem;
22error CrappedOut;
23fn returnsTen() %i32 {
20fn returnsTen() !i32 {
2421 return 10;
2522}
2623
......@@ -32,7 +29,7 @@ test "try without vars" {
3229 assert(result2 == 1);
3330}
3431
35fn failIfTrue(ok: bool) %void {
32fn failIfTrue(ok: bool) !void {
3633 if (ok) {
3734 return error.ItBroke;
3835 } else {
test/cases/while.zig+2-4
......@@ -50,7 +50,7 @@ fn runContinueAndBreakTest() void {
5050test "return with implicit cast from while loop" {
5151 returnWithImplicitCastFromWhileLoopTest() catch unreachable;
5252}
53fn returnWithImplicitCastFromWhileLoopTest() %void {
53fn returnWithImplicitCastFromWhileLoopTest() !void {
5454 while (true) {
5555 return;
5656 }
......@@ -116,8 +116,7 @@ test "while with error union condition" {
116116}
117117
118118var numbers_left: i32 = undefined;
119error OutOfNumbers;
120fn getNumberOrErr() %i32 {
119fn getNumberOrErr() !i32 {
121120 return if (numbers_left == 0)
122121 error.OutOfNumbers
123122 else x: {
......@@ -205,7 +204,6 @@ fn testContinueOuter() void {
205204
206205fn returnNull() ?i32 { return null; }
207206fn returnMaybe(x: i32) ?i32 { return x; }
208error YouWantedAnError;
209207fn returnError() %i32 { return error.YouWantedAnError; }
210208fn returnSuccess(x: i32) %i32 { return x; }
211209fn returnFalse() bool { return false; }
test/compare_output.zig+16-16
......@@ -15,7 +15,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
1515 \\use @import("std").io;
1616 \\use @import("foo.zig");
1717 \\
18 \\pub fn main() %void {
18 \\pub fn main() !void {
1919 \\ privateFunction();
2020 \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
2121 \\ stdout.print("OK 2\n") catch unreachable;
......@@ -49,7 +49,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
4949 \\use @import("foo.zig");
5050 \\use @import("bar.zig");
5151 \\
52 \\pub fn main() %void {
52 \\pub fn main() !void {
5353 \\ foo_function();
5454 \\ bar_function();
5555 \\}
......@@ -89,7 +89,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
8989 var tc = cases.create("two files use import each other",
9090 \\use @import("a.zig");
9191 \\
92 \\pub fn main() %void {
92 \\pub fn main() !void {
9393 \\ ok();
9494 \\}
9595 , "OK\n");
......@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
118118 cases.add("hello world without libc",
119119 \\const io = @import("std").io;
120120 \\
121 \\pub fn main() %void {
121 \\pub fn main() !void {
122122 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
123123 \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
124124 \\}
......@@ -268,7 +268,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
268268 \\const z = io.stdin_fileno;
269269 \\const x : @typeOf(y) = 1234;
270270 \\const y : u16 = 5678;
271 \\pub fn main() %void {
271 \\pub fn main() !void {
272272 \\ var x_local : i32 = print_ok(x);
273273 \\}
274274 \\fn print_ok(val: @typeOf(x)) @typeOf(foo) {
......@@ -351,7 +351,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
351351 \\ fn method(b: &const Bar) bool { return true; }
352352 \\};
353353 \\
354 \\pub fn main() %void {
354 \\pub fn main() !void {
355355 \\ const bar = Bar {.field2 = 13,};
356356 \\ const foo = Foo {.field1 = bar,};
357357 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
......@@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
367367
368368 cases.add("defer with only fallthrough",
369369 \\const io = @import("std").io;
370 \\pub fn main() %void {
370 \\pub fn main() !void {
371371 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
372372 \\ stdout.print("before\n") catch unreachable;
373373 \\ defer stdout.print("defer1\n") catch unreachable;
......@@ -380,7 +380,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
380380 cases.add("defer with return",
381381 \\const io = @import("std").io;
382382 \\const os = @import("std").os;
383 \\pub fn main() %void {
383 \\pub fn main() !void {
384384 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
385385 \\ stdout.print("before\n") catch unreachable;
386386 \\ defer stdout.print("defer1\n") catch unreachable;
......@@ -394,10 +394,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
394394
395395 cases.add("errdefer and it fails",
396396 \\const io = @import("std").io;
397 \\pub fn main() %void {
397 \\pub fn main() !void {
398398 \\ do_test() catch return;
399399 \\}
400 \\fn do_test() %void {
400 \\fn do_test() !void {
401401 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
402402 \\ stdout.print("before\n") catch unreachable;
403403 \\ defer stdout.print("defer1\n") catch unreachable;
......@@ -407,17 +407,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
407407 \\ stdout.print("after\n") catch unreachable;
408408 \\}
409409 \\error IToldYouItWouldFail;
410 \\fn its_gonna_fail() %void {
410 \\fn its_gonna_fail() !void {
411411 \\ return error.IToldYouItWouldFail;
412412 \\}
413413 , "before\ndeferErr\ndefer1\n");
414414
415415 cases.add("errdefer and it passes",
416416 \\const io = @import("std").io;
417 \\pub fn main() %void {
417 \\pub fn main() !void {
418418 \\ do_test() catch return;
419419 \\}
420 \\fn do_test() %void {
420 \\fn do_test() !void {
421421 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
422422 \\ stdout.print("before\n") catch unreachable;
423423 \\ defer stdout.print("defer1\n") catch unreachable;
......@@ -434,7 +434,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
434434 \\const foo_txt = @embedFile("foo.txt");
435435 \\const io = @import("std").io;
436436 \\
437 \\pub fn main() %void {
437 \\pub fn main() !void {
438438 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
439439 \\ stdout.print(foo_txt) catch unreachable;
440440 \\}
......@@ -452,7 +452,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
452452 \\const os = std.os;
453453 \\const allocator = std.debug.global_allocator;
454454 \\
455 \\pub fn main() %void {
455 \\pub fn main() !void {
456456 \\ var args_it = os.args();
457457 \\ var stdout_file = try io.getStdOut();
458458 \\ var stdout_adapter = io.FileOutStream.init(&stdout_file);
......@@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
493493 \\const os = std.os;
494494 \\const allocator = std.debug.global_allocator;
495495 \\
496 \\pub fn main() %void {
496 \\pub fn main() !void {
497497 \\ var args_it = os.args();
498498 \\ var stdout_file = try io.getStdOut();
499499 \\ var stdout_adapter = io.FileOutStream.init(&stdout_file);
test/compile_errors.zig+3-3
......@@ -1383,7 +1383,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
13831383 , ".tmp_source.zig:6:13: error: cannot assign to constant");
13841384
13851385 cases.add("return from defer expression",
1386 \\pub fn testTrickyDefer() %void {
1386 \\pub fn testTrickyDefer() !void {
13871387 \\ defer canFail() catch {};
13881388 \\
13891389 \\ defer try canFail();
......@@ -1970,7 +1970,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
19701970 \\fn foo1(args: ...) void {}
19711971 \\fn foo2(args: ...) void {}
19721972 \\
1973 \\pub fn main() %void {
1973 \\pub fn main() !void {
19741974 \\ foos[0]();
19751975 \\}
19761976 ,
......@@ -1982,7 +1982,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
19821982 \\fn foo1(arg: var) void {}
19831983 \\fn foo2(arg: var) void {}
19841984 \\
1985 \\pub fn main() %void {
1985 \\pub fn main() !void {
19861986 \\ foos[0](true);
19871987 \\}
19881988 ,
test/runtime_safety.zig+21-21
......@@ -5,7 +5,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
55 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
66 \\ @import("std").os.exit(126);
77 \\}
8 \\pub fn main() %void {
8 \\pub fn main() !void {
99 \\ @panic("oh no");
1010 \\}
1111 );
......@@ -14,7 +14,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
1414 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
1515 \\ @import("std").os.exit(126);
1616 \\}
17 \\pub fn main() %void {
17 \\pub fn main() !void {
1818 \\ const a = []i32{1, 2, 3, 4};
1919 \\ baz(bar(a));
2020 \\}
......@@ -29,7 +29,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
2929 \\ @import("std").os.exit(126);
3030 \\}
3131 \\error Whatever;
32 \\pub fn main() %void {
32 \\pub fn main() !void {
3333 \\ const x = add(65530, 10);
3434 \\ if (x == 0) return error.Whatever;
3535 \\}
......@@ -43,7 +43,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
4343 \\ @import("std").os.exit(126);
4444 \\}
4545 \\error Whatever;
46 \\pub fn main() %void {
46 \\pub fn main() !void {
4747 \\ const x = sub(10, 20);
4848 \\ if (x == 0) return error.Whatever;
4949 \\}
......@@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
5757 \\ @import("std").os.exit(126);
5858 \\}
5959 \\error Whatever;
60 \\pub fn main() %void {
60 \\pub fn main() !void {
6161 \\ const x = mul(300, 6000);
6262 \\ if (x == 0) return error.Whatever;
6363 \\}
......@@ -71,7 +71,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
7171 \\ @import("std").os.exit(126);
7272 \\}
7373 \\error Whatever;
74 \\pub fn main() %void {
74 \\pub fn main() !void {
7575 \\ const x = neg(-32768);
7676 \\ if (x == 32767) return error.Whatever;
7777 \\}
......@@ -85,7 +85,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
8585 \\ @import("std").os.exit(126);
8686 \\}
8787 \\error Whatever;
88 \\pub fn main() %void {
88 \\pub fn main() !void {
8989 \\ const x = div(-32768, -1);
9090 \\ if (x == 32767) return error.Whatever;
9191 \\}
......@@ -99,7 +99,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
9999 \\ @import("std").os.exit(126);
100100 \\}
101101 \\error Whatever;
102 \\pub fn main() %void {
102 \\pub fn main() !void {
103103 \\ const x = shl(-16385, 1);
104104 \\ if (x == 0) return error.Whatever;
105105 \\}
......@@ -113,7 +113,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
113113 \\ @import("std").os.exit(126);
114114 \\}
115115 \\error Whatever;
116 \\pub fn main() %void {
116 \\pub fn main() !void {
117117 \\ const x = shl(0b0010111111111111, 3);
118118 \\ if (x == 0) return error.Whatever;
119119 \\}
......@@ -127,7 +127,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
127127 \\ @import("std").os.exit(126);
128128 \\}
129129 \\error Whatever;
130 \\pub fn main() %void {
130 \\pub fn main() !void {
131131 \\ const x = shr(-16385, 1);
132132 \\ if (x == 0) return error.Whatever;
133133 \\}
......@@ -141,7 +141,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
141141 \\ @import("std").os.exit(126);
142142 \\}
143143 \\error Whatever;
144 \\pub fn main() %void {
144 \\pub fn main() !void {
145145 \\ const x = shr(0b0010111111111111, 3);
146146 \\ if (x == 0) return error.Whatever;
147147 \\}
......@@ -155,7 +155,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
155155 \\ @import("std").os.exit(126);
156156 \\}
157157 \\error Whatever;
158 \\pub fn main() %void {
158 \\pub fn main() !void {
159159 \\ const x = div0(999, 0);
160160 \\}
161161 \\fn div0(a: i32, b: i32) i32 {
......@@ -168,7 +168,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
168168 \\ @import("std").os.exit(126);
169169 \\}
170170 \\error Whatever;
171 \\pub fn main() %void {
171 \\pub fn main() !void {
172172 \\ const x = divExact(10, 3);
173173 \\ if (x == 0) return error.Whatever;
174174 \\}
......@@ -182,7 +182,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
182182 \\ @import("std").os.exit(126);
183183 \\}
184184 \\error Whatever;
185 \\pub fn main() %void {
185 \\pub fn main() !void {
186186 \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
187187 \\ if (x.len == 0) return error.Whatever;
188188 \\}
......@@ -196,7 +196,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
196196 \\ @import("std").os.exit(126);
197197 \\}
198198 \\error Whatever;
199 \\pub fn main() %void {
199 \\pub fn main() !void {
200200 \\ const x = shorten_cast(200);
201201 \\ if (x == 0) return error.Whatever;
202202 \\}
......@@ -210,7 +210,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
210210 \\ @import("std").os.exit(126);
211211 \\}
212212 \\error Whatever;
213 \\pub fn main() %void {
213 \\pub fn main() !void {
214214 \\ const x = unsigned_cast(-10);
215215 \\ if (x == 0) return error.Whatever;
216216 \\}
......@@ -227,10 +227,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
227227 \\ @import("std").os.exit(0); // test failed
228228 \\}
229229 \\error Whatever;
230 \\pub fn main() %void {
230 \\pub fn main() !void {
231231 \\ bar() catch unreachable;
232232 \\}
233 \\fn bar() %void {
233 \\fn bar() !void {
234234 \\ return error.Whatever;
235235 \\}
236236 );
......@@ -239,7 +239,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
239239 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
240240 \\ @import("std").os.exit(126);
241241 \\}
242 \\pub fn main() %void {
242 \\pub fn main() !void {
243243 \\ _ = bar(9999);
244244 \\}
245245 \\fn bar(x: u32) error {
......@@ -252,7 +252,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
252252 \\ @import("std").os.exit(126);
253253 \\}
254254 \\error Wrong;
255 \\pub fn main() %void {
255 \\pub fn main() !void {
256256 \\ var array align(4) = []u32{0x11111111, 0x11111111};
257257 \\ const bytes = ([]u8)(array[0..]);
258258 \\ if (foo(bytes) != 0x11111111) return error.Wrong;
......@@ -274,7 +274,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
274274 \\ int: u32,
275275 \\};
276276 \\
277 \\pub fn main() %void {
277 \\pub fn main() !void {
278278 \\ var f = Foo { .int = 42 };
279279 \\ bar(&f);
280280 \\}
test/standalone/brace_expansion/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 const main = b.addTest("main.zig");
55 main.setBuildMode(b.standardReleaseOptions());
66
test/standalone/brace_expansion/main.zig+5-8
......@@ -6,9 +6,6 @@ const assert = debug.assert;
66const Buffer = std.Buffer;
77const ArrayList = std.ArrayList;
88
9error InvalidInput;
10error OutOfMem;
11
129const Token = union(enum) {
1310 Word: []const u8,
1411 OpenBrace,
......@@ -19,7 +16,7 @@ const Token = union(enum) {
1916
2017var global_allocator: &mem.Allocator = undefined;
2118
22fn tokenize(input:[] const u8) %ArrayList(Token) {
19fn tokenize(input:[] const u8) !ArrayList(Token) {
2320 const State = enum {
2421 Start,
2522 Word,
......@@ -71,7 +68,7 @@ const Node = union(enum) {
7168 Combine: []Node,
7269};
7370
74fn parse(tokens: &const ArrayList(Token), token_index: &usize) %Node {
71fn parse(tokens: &const ArrayList(Token), token_index: &usize) !Node {
7572 const first_token = tokens.items[*token_index];
7673 *token_index += 1;
7774
......@@ -107,7 +104,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) %Node {
107104 }
108105}
109106
110fn expandString(input: []const u8, output: &Buffer) %void {
107fn expandString(input: []const u8, output: &Buffer) !void {
111108 const tokens = try tokenize(input);
112109 if (tokens.len == 1) {
113110 return output.resize(0);
......@@ -135,7 +132,7 @@ fn expandString(input: []const u8, output: &Buffer) %void {
135132 }
136133}
137134
138fn expandNode(node: &const Node, output: &ArrayList(Buffer)) %void {
135fn expandNode(node: &const Node, output: &ArrayList(Buffer)) !void {
139136 assert(output.len == 0);
140137 switch (*node) {
141138 Node.Scalar => |scalar| {
......@@ -172,7 +169,7 @@ fn expandNode(node: &const Node, output: &ArrayList(Buffer)) %void {
172169 }
173170}
174171
175pub fn main() %void {
172pub fn main() !void {
176173 var stdin_file = try io.getStdIn();
177174 var stdout_file = try io.getStdOut();
178175
test/standalone/issue_339/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 const obj = b.addObject("test", "test.zig");
55
66 const test_step = b.step("test", "Test the program");
test/standalone/pkg_import/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 const exe = b.addExecutable("test", "test.zig");
55 exe.addPackagePath("my_pkg", "pkg.zig");
66
test/standalone/pkg_import/test.zig+1-1
......@@ -1,6 +1,6 @@
11const my_pkg = @import("my_pkg");
22const assert = @import("std").debug.assert;
33
4pub fn main() %void {
4pub fn main() !void {
55 assert(my_pkg.add(10, 20) == 30);
66}
test/standalone/use_alias/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) %void {
3pub fn build(b: &Builder) !void {
44 b.addCIncludePath(".");
55
66 const main = b.addTest("main.zig");
test/tests.zig+5-8
......@@ -45,9 +45,6 @@ const test_targets = []TestTarget {
4545 },
4646};
4747
48error TestFailed;
49error CompilationIncorrectlySucceeded;
50
5148const max_stdout_size = 1 * 1024 * 1024; // 1 MB
5249
5350pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
......@@ -248,7 +245,7 @@ pub const CompareOutputContext = struct {
248245 return ptr;
249246 }
250247
251 fn make(step: &build.Step) %void {
248 fn make(step: &build.Step) !void {
252249 const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
253250 const b = self.context.b;
254251
......@@ -337,7 +334,7 @@ pub const CompareOutputContext = struct {
337334 return ptr;
338335 }
339336
340 fn make(step: &build.Step) %void {
337 fn make(step: &build.Step) !void {
341338 const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
342339 const b = self.context.b;
343340
......@@ -563,7 +560,7 @@ pub const CompileErrorContext = struct {
563560 return ptr;
564561 }
565562
566 fn make(step: &build.Step) %void {
563 fn make(step: &build.Step) !void {
567564 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
568565 const b = self.context.b;
569566
......@@ -847,7 +844,7 @@ pub const TranslateCContext = struct {
847844 return ptr;
848845 }
849846
850 fn make(step: &build.Step) %void {
847 fn make(step: &build.Step) !void {
851848 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
852849 const b = self.context.b;
853850
......@@ -1045,7 +1042,7 @@ pub const GenHContext = struct {
10451042 return ptr;
10461043 }
10471044
1048 fn make(step: &build.Step) %void {
1045 fn make(step: &build.Step) !void {
10491046 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
10501047 const b = self.context.b;
10511048