| author | |
| committer | |
| log | 5f518dbeb952186b7c11777b2454256c8c4fb9ac |
| tree | 31adf1939ed1173c29199e98dfbab9d8b9f6056f |
| parent | 5161d70620342749b1995fdaabb39220654cc941 |
62 files changed, 389 insertions(+), 510 deletions(-)
TODO created+5| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | sed -i 's/\(\bfn .*) \)%\(.*{\)$/\1!\2/g' $(find .. -name "*.zig") | |
| 2 | ||
| 3 | comptime assert(error{} ! i32 == i32); | |
| 4 | ||
| 5 |
build.zig+2-2| ... | ... | @@ -10,7 +10,7 @@ const ArrayList = std.ArrayList; |
| 10 | 10 | const Buffer = std.Buffer; |
| 11 | 11 | const io = std.io; |
| 12 | 12 | |
| 13 | pub fn build(b: &Builder) %void { | |
| 13 | pub fn build(b: &Builder) !void { | |
| 14 | 14 | const mode = b.standardReleaseOptions(); |
| 15 | 15 | |
| 16 | 16 | var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); |
| ... | ... | @@ -149,7 +149,7 @@ const LibraryDep = struct { |
| 149 | 149 | includes: ArrayList([]const u8), |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) %LibraryDep { | |
| 152 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep { | |
| 153 | 153 | const libs_output = try b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); |
| 154 | 154 | const includes_output = try b.exec([][]const u8{llvm_config_exe, "--includedir"}); |
| 155 | 155 | 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(); |
| 12 | 12 | const obj_ext = std.build.Target(std.build.Target.Native).oFileExt(); |
| 13 | 13 | const tmp_dir_name = "docgen_tmp"; |
| 14 | 14 | |
| 15 | pub fn main() %void { | |
| 15 | pub fn main() !void { | |
| 16 | 16 | // TODO use a more general purpose allocator here |
| 17 | 17 | var inc_allocator = try std.heap.IncrementingAllocator.init(max_doc_file_size); |
| 18 | 18 | defer inc_allocator.deinit(); |
| ... | ... | @@ -243,13 +243,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const |
| 243 | 243 | return error.ParseError; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) %void { | |
| 246 | fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) !void { | |
| 247 | 247 | if (token.id != id) { |
| 248 | 248 | return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id)); |
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | fn eatToken(tokenizer: &Tokenizer, id: Token.Id) %Token { | |
| 252 | fn eatToken(tokenizer: &Tokenizer, id: Token.Id) !Token { | |
| 253 | 253 | const token = tokenizer.next(); |
| 254 | 254 | try assertToken(tokenizer, token, id); |
| 255 | 255 | return token; |
| ... | ... | @@ -316,7 +316,7 @@ const Action = enum { |
| 316 | 316 | Close, |
| 317 | 317 | }; |
| 318 | 318 | |
| 319 | fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc { | |
| 319 | fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc { | |
| 320 | 320 | var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator); |
| 321 | 321 | errdefer urls.deinit(); |
| 322 | 322 | |
| ... | ... | @@ -540,7 +540,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc { |
| 540 | 540 | }; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 { | |
| 543 | fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 { | |
| 544 | 544 | var buf = try std.Buffer.initSize(allocator, 0); |
| 545 | 545 | defer buf.deinit(); |
| 546 | 546 | |
| ... | ... | @@ -560,7 +560,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 { |
| 560 | 560 | return buf.toOwnedSlice(); |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | fn escapeHtml(allocator: &mem.Allocator, input: []const u8) %[]u8 { | |
| 563 | fn escapeHtml(allocator: &mem.Allocator, input: []const u8) ![]u8 { | |
| 564 | 564 | var buf = try std.Buffer.initSize(allocator, 0); |
| 565 | 565 | defer buf.deinit(); |
| 566 | 566 | |
| ... | ... | @@ -604,7 +604,7 @@ test "term color" { |
| 604 | 604 | assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B")); |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 { | |
| 607 | fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 { | |
| 608 | 608 | var buf = try std.Buffer.initSize(allocator, 0); |
| 609 | 609 | defer buf.deinit(); |
| 610 | 610 | |
| ... | ... | @@ -686,7 +686,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 { |
| 686 | 686 | |
| 687 | 687 | error ExampleFailedToCompile; |
| 688 | 688 | |
| 689 | fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) %void { | |
| 689 | fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) !void { | |
| 690 | 690 | var code_progress_index: usize = 0; |
| 691 | 691 | for (toc.nodes) |node| { |
| 692 | 692 | switch (node) { |
| ... | ... | @@ -977,7 +977,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io |
| 977 | 977 | error ChildCrashed; |
| 978 | 978 | error ChildExitError; |
| 979 | 979 | |
| 980 | fn exec(allocator: &mem.Allocator, args: []const []const u8) %os.ChildProcess.ExecResult { | |
| 980 | fn exec(allocator: &mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult { | |
| 981 | 981 | const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size); |
| 982 | 982 | switch (result.term) { |
| 983 | 983 | os.ChildProcess.Term.Exited => |exit_code| { |
doc/langref.html.in+4-2| ... | ... | @@ -5598,7 +5598,9 @@ Block = option(Symbol ":") "{" many(Statement) "}" |
| 5598 | 5598 | |
| 5599 | 5599 | Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" |
| 5600 | 5600 | |
| 5601 | TypeExpr = PrefixOpExpression | "var" | |
| 5601 | TypeExpr = ErrorSetExpr | "var" | |
| 5602 | ||
| 5603 | ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression | |
| 5602 | 5604 | |
| 5603 | 5605 | BlockOrExpression = Block | Expression |
| 5604 | 5606 | |
| ... | ... | @@ -5680,7 +5682,7 @@ MultiplyExpression = CurlySuffixExpression MultiplyOperator MultiplyExpression | |
| 5680 | 5682 | |
| 5681 | 5683 | CurlySuffixExpression = TypeExpr option(ContainerInitExpression) |
| 5682 | 5684 | |
| 5683 | MultiplyOperator = "!" | "*" | "/" | "%" | "**" | "*%" | |
| 5685 | MultiplyOperator = "*" | "/" | "%" | "**" | "*%" | |
| 5684 | 5686 | |
| 5685 | 5687 | PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression |
| 5686 | 5688 |
example/cat/main.zig+4-4| ... | ... | @@ -5,7 +5,7 @@ const os = std.os; |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | const allocator = std.debug.global_allocator; |
| 7 | 7 | |
| 8 | pub fn main() %void { | |
| 8 | pub fn main() !void { | |
| 9 | 9 | var args_it = os.args(); |
| 10 | 10 | const exe = try unwrapArg(??args_it.next(allocator)); |
| 11 | 11 | var catted_anything = false; |
| ... | ... | @@ -36,12 +36,12 @@ pub fn main() %void { |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | fn usage(exe: []const u8) %void { | |
| 39 | fn usage(exe: []const u8) !void { | |
| 40 | 40 | warn("Usage: {} [FILE]...\n", exe); |
| 41 | 41 | return error.Invalid; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | fn cat_file(stdout: &io.File, file: &io.File) %void { | |
| 44 | fn cat_file(stdout: &io.File, file: &io.File) !void { | |
| 45 | 45 | var buf: [1024 * 4]u8 = undefined; |
| 46 | 46 | |
| 47 | 47 | while (true) { |
| ... | ... | @@ -61,7 +61,7 @@ fn cat_file(stdout: &io.File, file: &io.File) %void { |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | fn unwrapArg(arg: %[]u8) %[]u8 { | |
| 64 | fn unwrapArg(arg: %[]u8) ![]u8 { | |
| 65 | 65 | return arg catch |err| { |
| 66 | 66 | warn("Unable to parse command line: {}\n", err); |
| 67 | 67 | return err; |
example/guess_number/main.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ const fmt = std.fmt; |
| 5 | 5 | const Rand = std.rand.Rand; |
| 6 | 6 | const os = std.os; |
| 7 | 7 | |
| 8 | pub fn main() %void { | |
| 8 | pub fn main() !void { | |
| 9 | 9 | var stdout_file = try io.getStdOut(); |
| 10 | 10 | var stdout_file_stream = io.FileOutStream.init(&stdout_file); |
| 11 | 11 | const stdout = &stdout_file_stream.stream; |
example/hello_world/hello.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn main() %void { | |
| 3 | pub fn main() !void { | |
| 4 | 4 | // If this program is run without stdout attached, exit with an error. |
| 5 | 5 | var stdout_file = try std.io.getStdOut(); |
| 6 | 6 | // If this program encounters pipe failure when printing to stdout, exit |
example/mix_o_files/build.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | const obj = b.addObject("base64", "base64.zig"); |
| 5 | 5 | |
| 6 | 6 | const exe = b.addCExecutable("test"); |
example/shared_library/build.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0)); |
| 5 | 5 | |
| 6 | 6 | const exe = b.addCExecutable("test"); |
src-self-hosted/main.zig+7-7| ... | ... | @@ -20,7 +20,7 @@ error ZigInstallationNotFound; |
| 20 | 20 | |
| 21 | 21 | const default_zig_cache_name = "zig-cache"; |
| 22 | 22 | |
| 23 | pub fn main() %void { | |
| 23 | pub fn main() !void { | |
| 24 | 24 | main2() catch |err| { |
| 25 | 25 | if (err != error.InvalidCommandLineArguments) { |
| 26 | 26 | warn("{}\n", @errorName(err)); |
| ... | ... | @@ -48,7 +48,7 @@ fn badArgs(comptime format: []const u8, args: ...) error { |
| 48 | 48 | return error.InvalidCommandLineArguments; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | pub fn main2() %void { | |
| 51 | pub fn main2() !void { | |
| 52 | 52 | const allocator = std.heap.c_allocator; |
| 53 | 53 | |
| 54 | 54 | const args = try os.argsAlloc(allocator); |
| ... | ... | @@ -472,7 +472,7 @@ pub fn main2() %void { |
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | fn printUsage(stream: &io.OutStream) %void { | |
| 475 | fn printUsage(stream: &io.OutStream) !void { | |
| 476 | 476 | try stream.write( |
| 477 | 477 | \\Usage: zig [command] [options] |
| 478 | 478 | \\ |
| ... | ... | @@ -548,7 +548,7 @@ fn printUsage(stream: &io.OutStream) %void { |
| 548 | 548 | ); |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | fn printZen() %void { | |
| 551 | fn printZen() !void { | |
| 552 | 552 | var stdout_file = try io.getStdErr(); |
| 553 | 553 | try stdout_file.write( |
| 554 | 554 | \\ |
| ... | ... | @@ -569,7 +569,7 @@ fn printZen() %void { |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /// Caller must free result |
| 572 | fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) %[]u8 { | |
| 572 | fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) ![]u8 { | |
| 573 | 573 | if (zig_install_prefix_arg) |zig_install_prefix| { |
| 574 | 574 | return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| { |
| 575 | 575 | 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 |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /// Caller must free result |
| 588 | fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) %[]u8 { | |
| 588 | fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) ![]u8 { | |
| 589 | 589 | const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig"); |
| 590 | 590 | errdefer allocator.free(test_zig_dir); |
| 591 | 591 | |
| ... | ... | @@ -599,7 +599,7 @@ fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) %[]u8 |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /// Caller must free result |
| 602 | fn findZigLibDir(allocator: &mem.Allocator) %[]u8 { | |
| 602 | fn findZigLibDir(allocator: &mem.Allocator) ![]u8 { | |
| 603 | 603 | const self_exe_path = try os.selfExeDirPath(allocator); |
| 604 | 604 | defer allocator.free(self_exe_path); |
| 605 | 605 |
src-self-hosted/module.zig+4-4| ... | ... | @@ -198,7 +198,7 @@ pub const Module = struct { |
| 198 | 198 | self.allocator.destroy(self); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | pub fn build(self: &Module) %void { | |
| 201 | pub fn build(self: &Module) !void { | |
| 202 | 202 | if (self.llvm_argv.len != 0) { |
| 203 | 203 | var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator, |
| 204 | 204 | [][]const []const u8 { [][]const u8{"zig (LLVM option parsing)"}, self.llvm_argv, }); |
| ... | ... | @@ -263,11 +263,11 @@ pub const Module = struct { |
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | pub fn link(self: &Module, out_file: ?[]const u8) %void { | |
| 266 | pub fn link(self: &Module, out_file: ?[]const u8) !void { | |
| 267 | 267 | warn("TODO link"); |
| 268 | 268 | } |
| 269 | 269 | |
| 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 { | |
| 271 | 271 | const is_libc = mem.eql(u8, name, "c"); |
| 272 | 272 | |
| 273 | 273 | if (is_libc) { |
| ... | ... | @@ -297,7 +297,7 @@ pub const Module = struct { |
| 297 | 297 | } |
| 298 | 298 | }; |
| 299 | 299 | |
| 300 | fn printError(comptime format: []const u8, args: ...) %void { | |
| 300 | fn printError(comptime format: []const u8, args: ...) !void { | |
| 301 | 301 | var stderr_file = try std.io.getStdErr(); |
| 302 | 302 | var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file); |
| 303 | 303 | const out_stream = &stderr_file_out_stream.stream; |
src-self-hosted/parser.zig+18-18| ... | ... | @@ -63,7 +63,7 @@ pub const Parser = struct { |
| 63 | 63 | NullableField: &?&ast.Node, |
| 64 | 64 | List: &ArrayList(&ast.Node), |
| 65 | 65 | |
| 66 | pub fn store(self: &const DestPtr, value: &ast.Node) %void { | |
| 66 | pub fn store(self: &const DestPtr, value: &ast.Node) !void { | |
| 67 | 67 | switch (*self) { |
| 68 | 68 | DestPtr.Field => |ptr| *ptr = value, |
| 69 | 69 | DestPtr.NullableField => |ptr| *ptr = value, |
| ... | ... | @@ -99,7 +99,7 @@ pub const Parser = struct { |
| 99 | 99 | |
| 100 | 100 | /// Returns an AST tree, allocated with the parser's allocator. |
| 101 | 101 | /// Result should be freed with `freeAst` when done. |
| 102 | pub fn parse(self: &Parser) %Tree { | |
| 102 | pub fn parse(self: &Parser) !Tree { | |
| 103 | 103 | var stack = self.initUtilityArrayList(State); |
| 104 | 104 | defer self.deinitUtilityArrayList(stack); |
| 105 | 105 | |
| ... | ... | @@ -544,7 +544,7 @@ pub const Parser = struct { |
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | fn createRoot(self: &Parser) %&ast.NodeRoot { | |
| 547 | fn createRoot(self: &Parser) !&ast.NodeRoot { | |
| 548 | 548 | const node = try self.allocator.create(ast.NodeRoot); |
| 549 | 549 | |
| 550 | 550 | *node = ast.NodeRoot { |
| ... | ... | @@ -599,7 +599,7 @@ pub const Parser = struct { |
| 599 | 599 | return node; |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | fn createParamDecl(self: &Parser) %&ast.NodeParamDecl { | |
| 602 | fn createParamDecl(self: &Parser) !&ast.NodeParamDecl { | |
| 603 | 603 | const node = try self.allocator.create(ast.NodeParamDecl); |
| 604 | 604 | |
| 605 | 605 | *node = ast.NodeParamDecl { |
| ... | ... | @@ -613,7 +613,7 @@ pub const Parser = struct { |
| 613 | 613 | return node; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | fn createBlock(self: &Parser, begin_token: &const Token) %&ast.NodeBlock { | |
| 616 | fn createBlock(self: &Parser, begin_token: &const Token) !&ast.NodeBlock { | |
| 617 | 617 | const node = try self.allocator.create(ast.NodeBlock); |
| 618 | 618 | |
| 619 | 619 | *node = ast.NodeBlock { |
| ... | ... | @@ -625,7 +625,7 @@ pub const Parser = struct { |
| 625 | 625 | return node; |
| 626 | 626 | } |
| 627 | 627 | |
| 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 { | |
| 629 | 629 | const node = try self.allocator.create(ast.NodeInfixOp); |
| 630 | 630 | |
| 631 | 631 | *node = ast.NodeInfixOp { |
| ... | ... | @@ -638,7 +638,7 @@ pub const Parser = struct { |
| 638 | 638 | return node; |
| 639 | 639 | } |
| 640 | 640 | |
| 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 { | |
| 642 | 642 | const node = try self.allocator.create(ast.NodePrefixOp); |
| 643 | 643 | |
| 644 | 644 | *node = ast.NodePrefixOp { |
| ... | ... | @@ -650,7 +650,7 @@ pub const Parser = struct { |
| 650 | 650 | return node; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | fn createIdentifier(self: &Parser, name_token: &const Token) %&ast.NodeIdentifier { | |
| 653 | fn createIdentifier(self: &Parser, name_token: &const Token) !&ast.NodeIdentifier { | |
| 654 | 654 | const node = try self.allocator.create(ast.NodeIdentifier); |
| 655 | 655 | |
| 656 | 656 | *node = ast.NodeIdentifier { |
| ... | ... | @@ -660,7 +660,7 @@ pub const Parser = struct { |
| 660 | 660 | return node; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | fn createIntegerLiteral(self: &Parser, token: &const Token) %&ast.NodeIntegerLiteral { | |
| 663 | fn createIntegerLiteral(self: &Parser, token: &const Token) !&ast.NodeIntegerLiteral { | |
| 664 | 664 | const node = try self.allocator.create(ast.NodeIntegerLiteral); |
| 665 | 665 | |
| 666 | 666 | *node = ast.NodeIntegerLiteral { |
| ... | ... | @@ -670,7 +670,7 @@ pub const Parser = struct { |
| 670 | 670 | return node; |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | fn createFloatLiteral(self: &Parser, token: &const Token) %&ast.NodeFloatLiteral { | |
| 673 | fn createFloatLiteral(self: &Parser, token: &const Token) !&ast.NodeFloatLiteral { | |
| 674 | 674 | const node = try self.allocator.create(ast.NodeFloatLiteral); |
| 675 | 675 | |
| 676 | 676 | *node = ast.NodeFloatLiteral { |
| ... | ... | @@ -680,13 +680,13 @@ pub const Parser = struct { |
| 680 | 680 | return node; |
| 681 | 681 | } |
| 682 | 682 | |
| 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 { | |
| 684 | 684 | const node = try self.createIdentifier(name_token); |
| 685 | 685 | try dest_ptr.store(&node.base); |
| 686 | 686 | return node; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) %&ast.NodeParamDecl { | |
| 689 | fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) !&ast.NodeParamDecl { | |
| 690 | 690 | const node = try self.createParamDecl(); |
| 691 | 691 | try list.append(&node.base); |
| 692 | 692 | return node; |
| ... | ... | @@ -730,13 +730,13 @@ pub const Parser = struct { |
| 730 | 730 | return error.ParseError; |
| 731 | 731 | } |
| 732 | 732 | |
| 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 { | |
| 734 | 734 | if (token.id != id) { |
| 735 | 735 | return self.parseError(token, "expected {}, found {}", @tagName(id), @tagName(token.id)); |
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | fn eatToken(self: &Parser, id: @TagType(Token.Id)) %Token { | |
| 739 | fn eatToken(self: &Parser, id: @TagType(Token.Id)) !Token { | |
| 740 | 740 | const token = self.getNextToken(); |
| 741 | 741 | try self.expectToken(token, id); |
| 742 | 742 | return token; |
| ... | ... | @@ -763,7 +763,7 @@ pub const Parser = struct { |
| 763 | 763 | indent: usize, |
| 764 | 764 | }; |
| 765 | 765 | |
| 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 { | |
| 767 | 767 | var stack = self.initUtilityArrayList(RenderAstFrame); |
| 768 | 768 | defer self.deinitUtilityArrayList(stack); |
| 769 | 769 | |
| ... | ... | @@ -802,7 +802,7 @@ pub const Parser = struct { |
| 802 | 802 | Indent: usize, |
| 803 | 803 | }; |
| 804 | 804 | |
| 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 { | |
| 806 | 806 | var stack = self.initUtilityArrayList(RenderState); |
| 807 | 807 | defer self.deinitUtilityArrayList(stack); |
| 808 | 808 | |
| ... | ... | @@ -1038,7 +1038,7 @@ pub const Parser = struct { |
| 1038 | 1038 | |
| 1039 | 1039 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1040 | 1040 | |
| 1041 | fn testParse(source: []const u8, allocator: &mem.Allocator) %[]u8 { | |
| 1041 | fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 { | |
| 1042 | 1042 | var padded_source: [0x100]u8 = undefined; |
| 1043 | 1043 | std.mem.copy(u8, padded_source[0..source.len], source); |
| 1044 | 1044 | padded_source[source.len + 0] = '\n'; |
| ... | ... | @@ -1064,7 +1064,7 @@ error MemoryLeakDetected; |
| 1064 | 1064 | |
| 1065 | 1065 | // TODO test for memory leaks |
| 1066 | 1066 | // TODO test for valid frees |
| 1067 | fn testCanonical(source: []const u8) %void { | |
| 1067 | fn testCanonical(source: []const u8) !void { | |
| 1068 | 1068 | const needed_alloc_count = x: { |
| 1069 | 1069 | // Try it once with unlimited memory, make sure it works |
| 1070 | 1070 | 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) { |
| 516 | 516 | |
| 517 | 517 | TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type) { |
| 518 | 518 | assert(err_set_type->id == TypeTableEntryIdErrorSet); |
| 519 | assert(!type_is_invalid(payload_type)); | |
| 519 | 520 | |
| 520 | 521 | TypeId type_id = {}; |
| 521 | 522 | type_id.id = TypeTableEntryIdErrorUnion; |
| ... | ... | @@ -1409,6 +1410,11 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1409 | 1410 | } |
| 1410 | 1411 | |
| 1411 | 1412 | 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 | ||
| 1412 | 1418 | if (fn_proto->auto_err_set) { |
| 1413 | 1419 | TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(g, fn_entry); |
| 1414 | 1420 | 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 |
| 1416 | 1422 | fn_type_id.return_type = specified_return_type; |
| 1417 | 1423 | } |
| 1418 | 1424 | |
| 1419 | if (type_is_invalid(fn_type_id.return_type)) { | |
| 1420 | return g->builtin_types.entry_invalid; | |
| 1421 | } | |
| 1422 | ||
| 1423 | 1425 | if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) { |
| 1424 | 1426 | add_node_error(g, fn_proto->return_type, |
| 1425 | 1427 | 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 |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /* |
| 244 | TypeExpr = PrefixOpExpression | "var" | |
| 244 | ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression | |
| 245 | */ | |
| 246 | static 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 | /* | |
| 265 | TypeExpr = ErrorSetExpr | "var" | |
| 245 | 266 | */ |
| 246 | 267 | static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 247 | 268 | Token *token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -250,7 +271,7 @@ static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool |
| 250 | 271 | *token_index += 1; |
| 251 | 272 | return node; |
| 252 | 273 | } else { |
| 253 | return ast_parse_prefix_op_expr(pc, token_index, mandatory); | |
| 274 | return ast_parse_error_set_expr(pc, token_index, mandatory); | |
| 254 | 275 | } |
| 255 | 276 | } |
| 256 | 277 | |
| ... | ... | @@ -2346,10 +2367,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m |
| 2346 | 2367 | node->data.fn_proto.return_type = ast_create_node(pc, NodeTypeErrorType, next_token); |
| 2347 | 2368 | return node; |
| 2348 | 2369 | } |
| 2349 | ||
| 2350 | return node; | |
| 2351 | } | |
| 2352 | if (next_token->id == TokenIdBang) { | |
| 2370 | } else if (next_token->id == TokenIdBang) { | |
| 2353 | 2371 | *token_index += 1; |
| 2354 | 2372 | node->data.fn_proto.auto_err_set = true; |
| 2355 | 2373 | 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{ |
| 59 | 59 | return result; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | pub fn append(l: &Self, item: &const T) %void { | |
| 62 | pub fn append(l: &Self, item: &const T) !void { | |
| 63 | 63 | const new_item_ptr = try l.addOne(); |
| 64 | 64 | *new_item_ptr = *item; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | pub fn appendSlice(l: &Self, items: []align(A) const T) %void { | |
| 67 | pub fn appendSlice(l: &Self, items: []align(A) const T) !void { | |
| 68 | 68 | try l.ensureCapacity(l.len + items.len); |
| 69 | 69 | mem.copy(T, l.items[l.len..], items); |
| 70 | 70 | l.len += items.len; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | pub fn resize(l: &Self, new_len: usize) %void { | |
| 73 | pub fn resize(l: &Self, new_len: usize) !void { | |
| 74 | 74 | try l.ensureCapacity(new_len); |
| 75 | 75 | l.len = new_len; |
| 76 | 76 | } |
| ... | ... | @@ -80,7 +80,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 80 | 80 | l.len = new_len; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | pub fn ensureCapacity(l: &Self, new_capacity: usize) %void { | |
| 83 | pub fn ensureCapacity(l: &Self, new_capacity: usize) !void { | |
| 84 | 84 | var better_capacity = l.items.len; |
| 85 | 85 | if (better_capacity >= new_capacity) return; |
| 86 | 86 | while (true) { |
| ... | ... | @@ -90,7 +90,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 90 | 90 | l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | pub fn addOne(l: &Self) %&T { | |
| 93 | pub fn addOne(l: &Self) !&T { | |
| 94 | 94 | const new_length = l.len + 1; |
| 95 | 95 | try l.ensureCapacity(new_length); |
| 96 | 96 | const result = &l.items[l.len]; |
std/base64.zig+9-14| ... | ... | @@ -79,8 +79,6 @@ pub const Base64Encoder = struct { |
| 79 | 79 | }; |
| 80 | 80 | |
| 81 | 81 | pub const standard_decoder = Base64Decoder.init(standard_alphabet_chars, standard_pad_char); |
| 82 | error InvalidPadding; | |
| 83 | error InvalidCharacter; | |
| 84 | 82 | |
| 85 | 83 | pub const Base64Decoder = struct { |
| 86 | 84 | /// e.g. 'A' => 0. |
| ... | ... | @@ -111,7 +109,7 @@ pub const Base64Decoder = struct { |
| 111 | 109 | } |
| 112 | 110 | |
| 113 | 111 | /// 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 { | |
| 115 | 113 | if (source.len % 4 != 0) return error.InvalidPadding; |
| 116 | 114 | return calcDecodedSizeExactUnsafe(source, decoder.pad_char); |
| 117 | 115 | } |
| ... | ... | @@ -119,7 +117,7 @@ pub const Base64Decoder = struct { |
| 119 | 117 | /// dest.len must be what you get from ::calcSize. |
| 120 | 118 | /// invalid characters result in error.InvalidCharacter. |
| 121 | 119 | /// 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 { | |
| 123 | 121 | assert(dest.len == (decoder.calcSize(source) catch unreachable)); |
| 124 | 122 | assert(source.len % 4 == 0); |
| 125 | 123 | |
| ... | ... | @@ -163,8 +161,6 @@ pub const Base64Decoder = struct { |
| 163 | 161 | } |
| 164 | 162 | }; |
| 165 | 163 | |
| 166 | error OutputTooSmall; | |
| 167 | ||
| 168 | 164 | pub const Base64DecoderWithIgnore = struct { |
| 169 | 165 | decoder: Base64Decoder, |
| 170 | 166 | char_is_ignored: [256]bool, |
| ... | ... | @@ -185,7 +181,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 185 | 181 | } |
| 186 | 182 | |
| 187 | 183 | /// 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 { | |
| 189 | 185 | return @divTrunc(encoded_len, 4) * 3; |
| 190 | 186 | } |
| 191 | 187 | |
| ... | ... | @@ -193,7 +189,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 193 | 189 | /// Invalid padding results in error.InvalidPadding. |
| 194 | 190 | /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound. |
| 195 | 191 | /// 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 { | |
| 197 | 193 | const decoder = &decoder_with_ignore.decoder; |
| 198 | 194 | |
| 199 | 195 | var src_cursor: usize = 0; |
| ... | ... | @@ -378,7 +374,7 @@ test "base64" { |
| 378 | 374 | comptime (testBase64() catch unreachable); |
| 379 | 375 | } |
| 380 | 376 | |
| 381 | fn testBase64() %void { | |
| 377 | fn testBase64() !void { | |
| 382 | 378 | try testAllApis("", ""); |
| 383 | 379 | try testAllApis("f", "Zg=="); |
| 384 | 380 | try testAllApis("fo", "Zm8="); |
| ... | ... | @@ -412,7 +408,7 @@ fn testBase64() %void { |
| 412 | 408 | try testOutputTooSmallError("AAAAAA=="); |
| 413 | 409 | } |
| 414 | 410 | |
| 415 | fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) %void { | |
| 411 | fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void { | |
| 416 | 412 | // Base64Encoder |
| 417 | 413 | { |
| 418 | 414 | var buffer: [0x100]u8 = undefined; |
| ... | ... | @@ -449,7 +445,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) %void |
| 449 | 445 | } |
| 450 | 446 | } |
| 451 | 447 | |
| 452 | fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) %void { | |
| 448 | fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !void { | |
| 453 | 449 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( |
| 454 | 450 | standard_alphabet_chars, standard_pad_char, " "); |
| 455 | 451 | var buffer: [0x100]u8 = undefined; |
| ... | ... | @@ -458,8 +454,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) %voi |
| 458 | 454 | assert(mem.eql(u8, decoded[0..written], expected_decoded)); |
| 459 | 455 | } |
| 460 | 456 | |
| 461 | error ExpectedError; | |
| 462 | fn testError(encoded: []const u8, expected_err: error) %void { | |
| 457 | fn testError(encoded: []const u8, expected_err: error) !void { | |
| 463 | 458 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( |
| 464 | 459 | standard_alphabet_chars, standard_pad_char, " "); |
| 465 | 460 | var buffer: [0x100]u8 = undefined; |
| ... | ... | @@ -475,7 +470,7 @@ fn testError(encoded: []const u8, expected_err: error) %void { |
| 475 | 470 | } else |err| if (err != expected_err) return err; |
| 476 | 471 | } |
| 477 | 472 | |
| 478 | fn testOutputTooSmallError(encoded: []const u8) %void { | |
| 473 | fn testOutputTooSmallError(encoded: []const u8) !void { | |
| 479 | 474 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( |
| 480 | 475 | standard_alphabet_chars, standard_pad_char, " "); |
| 481 | 476 | var buffer: [0x100]u8 = undefined; |
std/buf_map.zig+2-2| ... | ... | @@ -27,7 +27,7 @@ pub const BufMap = struct { |
| 27 | 27 | self.hash_map.deinit(); |
| 28 | 28 | } |
| 29 | 29 | |
| 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 { | |
| 31 | 31 | if (self.hash_map.get(key)) |entry| { |
| 32 | 32 | const value_copy = try self.copy(value); |
| 33 | 33 | errdefer self.free(value_copy); |
| ... | ... | @@ -67,7 +67,7 @@ pub const BufMap = struct { |
| 67 | 67 | self.hash_map.allocator.free(mut_value); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | fn copy(self: &BufMap, value: []const u8) %[]const u8 { | |
| 70 | fn copy(self: &BufMap, value: []const u8) ![]const u8 { | |
| 71 | 71 | const result = try self.hash_map.allocator.alloc(u8, value.len); |
| 72 | 72 | mem.copy(u8, result, value); |
| 73 | 73 | return result; |
std/buf_set.zig+2-2| ... | ... | @@ -24,7 +24,7 @@ pub const BufSet = struct { |
| 24 | 24 | self.hash_map.deinit(); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | pub fn put(self: &BufSet, key: []const u8) %void { | |
| 27 | pub fn put(self: &BufSet, key: []const u8) !void { | |
| 28 | 28 | if (self.hash_map.get(key) == null) { |
| 29 | 29 | const key_copy = try self.copy(key); |
| 30 | 30 | errdefer self.free(key_copy); |
| ... | ... | @@ -55,7 +55,7 @@ pub const BufSet = struct { |
| 55 | 55 | self.hash_map.allocator.free(mut_value); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | fn copy(self: &BufSet, value: []const u8) %[]const u8 { | |
| 58 | fn copy(self: &BufSet, value: []const u8) ![]const u8 { | |
| 59 | 59 | const result = try self.hash_map.allocator.alloc(u8, value.len); |
| 60 | 60 | mem.copy(u8, result, value); |
| 61 | 61 | return result; |
std/buffer.zig+9-9| ... | ... | @@ -12,14 +12,14 @@ pub const Buffer = struct { |
| 12 | 12 | list: ArrayList(u8), |
| 13 | 13 | |
| 14 | 14 | /// Must deinitialize with deinit. |
| 15 | pub fn init(allocator: &Allocator, m: []const u8) %Buffer { | |
| 15 | pub fn init(allocator: &Allocator, m: []const u8) !Buffer { | |
| 16 | 16 | var self = try initSize(allocator, m.len); |
| 17 | 17 | mem.copy(u8, self.list.items, m); |
| 18 | 18 | return self; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /// Must deinitialize with deinit. |
| 22 | pub fn initSize(allocator: &Allocator, size: usize) %Buffer { | |
| 22 | pub fn initSize(allocator: &Allocator, size: usize) !Buffer { | |
| 23 | 23 | var self = initNull(allocator); |
| 24 | 24 | try self.resize(size); |
| 25 | 25 | return self; |
| ... | ... | @@ -37,7 +37,7 @@ pub const Buffer = struct { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /// Must deinitialize with deinit. |
| 40 | pub fn initFromBuffer(buffer: &const Buffer) %Buffer { | |
| 40 | pub fn initFromBuffer(buffer: &const Buffer) !Buffer { | |
| 41 | 41 | return Buffer.init(buffer.list.allocator, buffer.toSliceConst()); |
| 42 | 42 | } |
| 43 | 43 | |
| ... | ... | @@ -80,7 +80,7 @@ pub const Buffer = struct { |
| 80 | 80 | self.list.items[self.len()] = 0; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | pub fn resize(self: &Buffer, new_len: usize) %void { | |
| 83 | pub fn resize(self: &Buffer, new_len: usize) !void { | |
| 84 | 84 | try self.list.resize(new_len + 1); |
| 85 | 85 | self.list.items[self.len()] = 0; |
| 86 | 86 | } |
| ... | ... | @@ -93,24 +93,24 @@ pub const Buffer = struct { |
| 93 | 93 | return self.list.len - 1; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | pub fn append(self: &Buffer, m: []const u8) %void { | |
| 96 | pub fn append(self: &Buffer, m: []const u8) !void { | |
| 97 | 97 | const old_len = self.len(); |
| 98 | 98 | try self.resize(old_len + m.len); |
| 99 | 99 | mem.copy(u8, self.list.toSlice()[old_len..], m); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // 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 { | |
| 104 | 104 | return fmt.format(self, append, format, args); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // TODO: remove, use OutStream for this |
| 108 | pub fn appendByte(self: &Buffer, byte: u8) %void { | |
| 108 | pub fn appendByte(self: &Buffer, byte: u8) !void { | |
| 109 | 109 | return self.appendByteNTimes(byte, 1); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // 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 { | |
| 114 | 114 | var prev_size: usize = self.len(); |
| 115 | 115 | const new_size = prev_size + count; |
| 116 | 116 | try self.resize(new_size); |
| ... | ... | @@ -137,7 +137,7 @@ pub const Buffer = struct { |
| 137 | 137 | return mem.eql(u8, self.list.items[start..l], m); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | pub fn replaceContents(self: &const Buffer, m: []const u8) %void { | |
| 140 | pub fn replaceContents(self: &const Buffer, m: []const u8) !void { | |
| 141 | 141 | try self.resize(m.len); |
| 142 | 142 | mem.copy(u8, self.list.toSlice(), m); |
| 143 | 143 | } |
std/build.zig+21-28| ... | ... | @@ -15,13 +15,6 @@ const BufSet = std.BufSet; |
| 15 | 15 | const BufMap = std.BufMap; |
| 16 | 16 | const fmt_lib = std.fmt; |
| 17 | 17 | |
| 18 | error ExtraArg; | |
| 19 | error UncleanExit; | |
| 20 | error InvalidStepName; | |
| 21 | error DependencyLoopDetected; | |
| 22 | error NoCompilerFound; | |
| 23 | error NeedAnObject; | |
| 24 | ||
| 25 | 18 | pub const Builder = struct { |
| 26 | 19 | uninstall_tls: TopLevelStep, |
| 27 | 20 | install_tls: TopLevelStep, |
| ... | ... | @@ -242,7 +235,7 @@ pub const Builder = struct { |
| 242 | 235 | self.lib_paths.append(path) catch unreachable; |
| 243 | 236 | } |
| 244 | 237 | |
| 245 | pub fn make(self: &Builder, step_names: []const []const u8) %void { | |
| 238 | pub fn make(self: &Builder, step_names: []const []const u8) !void { | |
| 246 | 239 | var wanted_steps = ArrayList(&Step).init(self.allocator); |
| 247 | 240 | defer wanted_steps.deinit(); |
| 248 | 241 | |
| ... | ... | @@ -278,7 +271,7 @@ pub const Builder = struct { |
| 278 | 271 | return &self.uninstall_tls.step; |
| 279 | 272 | } |
| 280 | 273 | |
| 281 | fn makeUninstall(uninstall_step: &Step) %void { | |
| 274 | fn makeUninstall(uninstall_step: &Step) !void { | |
| 282 | 275 | const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step); |
| 283 | 276 | const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls); |
| 284 | 277 | |
| ... | ... | @@ -292,7 +285,7 @@ pub const Builder = struct { |
| 292 | 285 | // TODO remove empty directories |
| 293 | 286 | } |
| 294 | 287 | |
| 295 | fn makeOneStep(self: &Builder, s: &Step) %void { | |
| 288 | fn makeOneStep(self: &Builder, s: &Step) !void { | |
| 296 | 289 | if (s.loop_flag) { |
| 297 | 290 | warn("Dependency loop detected:\n {}\n", s.name); |
| 298 | 291 | return error.DependencyLoopDetected; |
| ... | ... | @@ -313,7 +306,7 @@ pub const Builder = struct { |
| 313 | 306 | try s.make(); |
| 314 | 307 | } |
| 315 | 308 | |
| 316 | fn getTopLevelStepByName(self: &Builder, name: []const u8) %&Step { | |
| 309 | fn getTopLevelStepByName(self: &Builder, name: []const u8) !&Step { | |
| 317 | 310 | for (self.top_level_steps.toSliceConst()) |top_level_step| { |
| 318 | 311 | if (mem.eql(u8, top_level_step.step.name, name)) { |
| 319 | 312 | return &top_level_step.step; |
| ... | ... | @@ -548,7 +541,7 @@ pub const Builder = struct { |
| 548 | 541 | return self.invalid_user_input; |
| 549 | 542 | } |
| 550 | 543 | |
| 551 | fn spawnChild(self: &Builder, argv: []const []const u8) %void { | |
| 544 | fn spawnChild(self: &Builder, argv: []const []const u8) !void { | |
| 552 | 545 | return self.spawnChildEnvMap(null, &self.env_map, argv); |
| 553 | 546 | } |
| 554 | 547 | |
| ... | ... | @@ -595,7 +588,7 @@ pub const Builder = struct { |
| 595 | 588 | } |
| 596 | 589 | } |
| 597 | 590 | |
| 598 | pub fn makePath(self: &Builder, path: []const u8) %void { | |
| 591 | pub fn makePath(self: &Builder, path: []const u8) !void { | |
| 599 | 592 | os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { |
| 600 | 593 | warn("Unable to create path {}: {}\n", path, @errorName(err)); |
| 601 | 594 | return err; |
| ... | ... | @@ -630,11 +623,11 @@ pub const Builder = struct { |
| 630 | 623 | self.installed_files.append(full_path) catch unreachable; |
| 631 | 624 | } |
| 632 | 625 | |
| 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 { | |
| 634 | 627 | return self.copyFileMode(source_path, dest_path, 0o666); |
| 635 | 628 | } |
| 636 | 629 | |
| 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 { | |
| 638 | 631 | if (self.verbose) { |
| 639 | 632 | warn("cp {} {}\n", source_path, dest_path); |
| 640 | 633 | } |
| ... | ... | @@ -672,7 +665,7 @@ pub const Builder = struct { |
| 672 | 665 | } |
| 673 | 666 | } |
| 674 | 667 | |
| 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 { | |
| 676 | 669 | // TODO report error for ambiguous situations |
| 677 | 670 | const exe_extension = (Target { .Native = {}}).exeFileExt(); |
| 678 | 671 | for (self.search_prefixes.toSliceConst()) |search_prefix| { |
| ... | ... | @@ -721,7 +714,7 @@ pub const Builder = struct { |
| 721 | 714 | return error.FileNotFound; |
| 722 | 715 | } |
| 723 | 716 | |
| 724 | pub fn exec(self: &Builder, argv: []const []const u8) %[]u8 { | |
| 717 | pub fn exec(self: &Builder, argv: []const []const u8) ![]u8 { | |
| 725 | 718 | const max_output_size = 100 * 1024; |
| 726 | 719 | const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size); |
| 727 | 720 | switch (result.term) { |
| ... | ... | @@ -1180,12 +1173,12 @@ pub const LibExeObjStep = struct { |
| 1180 | 1173 | self.disable_libc = disable; |
| 1181 | 1174 | } |
| 1182 | 1175 | |
| 1183 | fn make(step: &Step) %void { | |
| 1176 | fn make(step: &Step) !void { | |
| 1184 | 1177 | const self = @fieldParentPtr(LibExeObjStep, "step", step); |
| 1185 | 1178 | return if (self.is_zig) self.makeZig() else self.makeC(); |
| 1186 | 1179 | } |
| 1187 | 1180 | |
| 1188 | fn makeZig(self: &LibExeObjStep) %void { | |
| 1181 | fn makeZig(self: &LibExeObjStep) !void { | |
| 1189 | 1182 | const builder = self.builder; |
| 1190 | 1183 | |
| 1191 | 1184 | assert(self.is_zig); |
| ... | ... | @@ -1396,7 +1389,7 @@ pub const LibExeObjStep = struct { |
| 1396 | 1389 | } |
| 1397 | 1390 | } |
| 1398 | 1391 | |
| 1399 | fn makeC(self: &LibExeObjStep) %void { | |
| 1392 | fn makeC(self: &LibExeObjStep) !void { | |
| 1400 | 1393 | const builder = self.builder; |
| 1401 | 1394 | |
| 1402 | 1395 | const cc = builder.getCCExe(); |
| ... | ... | @@ -1687,7 +1680,7 @@ pub const TestStep = struct { |
| 1687 | 1680 | self.exec_cmd_args = args; |
| 1688 | 1681 | } |
| 1689 | 1682 | |
| 1690 | fn make(step: &Step) %void { | |
| 1683 | fn make(step: &Step) !void { | |
| 1691 | 1684 | const self = @fieldParentPtr(TestStep, "step", step); |
| 1692 | 1685 | const builder = self.builder; |
| 1693 | 1686 | |
| ... | ... | @@ -1796,7 +1789,7 @@ pub const CommandStep = struct { |
| 1796 | 1789 | return self; |
| 1797 | 1790 | } |
| 1798 | 1791 | |
| 1799 | fn make(step: &Step) %void { | |
| 1792 | fn make(step: &Step) !void { | |
| 1800 | 1793 | const self = @fieldParentPtr(CommandStep, "step", step); |
| 1801 | 1794 | |
| 1802 | 1795 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; |
| ... | ... | @@ -1836,7 +1829,7 @@ const InstallArtifactStep = struct { |
| 1836 | 1829 | return self; |
| 1837 | 1830 | } |
| 1838 | 1831 | |
| 1839 | fn make(step: &Step) %void { | |
| 1832 | fn make(step: &Step) !void { | |
| 1840 | 1833 | const self = @fieldParentPtr(Self, "step", step); |
| 1841 | 1834 | const builder = self.builder; |
| 1842 | 1835 | |
| ... | ... | @@ -1868,7 +1861,7 @@ pub const InstallFileStep = struct { |
| 1868 | 1861 | }; |
| 1869 | 1862 | } |
| 1870 | 1863 | |
| 1871 | fn make(step: &Step) %void { | |
| 1864 | fn make(step: &Step) !void { | |
| 1872 | 1865 | const self = @fieldParentPtr(InstallFileStep, "step", step); |
| 1873 | 1866 | try self.builder.copyFile(self.src_path, self.dest_path); |
| 1874 | 1867 | } |
| ... | ... | @@ -1889,7 +1882,7 @@ pub const WriteFileStep = struct { |
| 1889 | 1882 | }; |
| 1890 | 1883 | } |
| 1891 | 1884 | |
| 1892 | fn make(step: &Step) %void { | |
| 1885 | fn make(step: &Step) !void { | |
| 1893 | 1886 | const self = @fieldParentPtr(WriteFileStep, "step", step); |
| 1894 | 1887 | const full_path = self.builder.pathFromRoot(self.file_path); |
| 1895 | 1888 | const full_path_dir = os.path.dirname(full_path); |
| ... | ... | @@ -1917,7 +1910,7 @@ pub const LogStep = struct { |
| 1917 | 1910 | }; |
| 1918 | 1911 | } |
| 1919 | 1912 | |
| 1920 | fn make(step: &Step) %void { | |
| 1913 | fn make(step: &Step) !void { | |
| 1921 | 1914 | const self = @fieldParentPtr(LogStep, "step", step); |
| 1922 | 1915 | warn("{}", self.data); |
| 1923 | 1916 | } |
| ... | ... | @@ -1936,7 +1929,7 @@ pub const RemoveDirStep = struct { |
| 1936 | 1929 | }; |
| 1937 | 1930 | } |
| 1938 | 1931 | |
| 1939 | fn make(step: &Step) %void { | |
| 1932 | fn make(step: &Step) !void { | |
| 1940 | 1933 | const self = @fieldParentPtr(RemoveDirStep, "step", step); |
| 1941 | 1934 | |
| 1942 | 1935 | const full_path = self.builder.pathFromRoot(self.dir_path); |
| ... | ... | @@ -1967,7 +1960,7 @@ pub const Step = struct { |
| 1967 | 1960 | return init(name, allocator, makeNoOp); |
| 1968 | 1961 | } |
| 1969 | 1962 | |
| 1970 | pub fn make(self: &Step) %void { | |
| 1963 | pub fn make(self: &Step) !void { | |
| 1971 | 1964 | if (self.done_flag) |
| 1972 | 1965 | return; |
| 1973 | 1966 |
std/crypto/throughput_test.zig+1-1| ... | ... | @@ -18,7 +18,7 @@ const c = @cImport({ |
| 18 | 18 | |
| 19 | 19 | const Mb = 1024 * 1024; |
| 20 | 20 | |
| 21 | pub fn main() %void { | |
| 21 | pub fn main() !void { | |
| 22 | 22 | var stdout_file = try std.io.getStdOut(); |
| 23 | 23 | var stdout_out_stream = std.io.FileOutStream.init(&stdout_file); |
| 24 | 24 | const stdout = &stdout_out_stream.stream; |
std/cstr.zig+2-2| ... | ... | @@ -42,7 +42,7 @@ fn testCStrFnsImpl() void { |
| 42 | 42 | /// Returns a mutable slice with exactly the same size which is guaranteed to |
| 43 | 43 | /// have a null byte after it. |
| 44 | 44 | /// Caller owns the returned memory. |
| 45 | pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) %[]u8 { | |
| 45 | pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) ![]u8 { | |
| 46 | 46 | const result = try allocator.alloc(u8, slice.len + 1); |
| 47 | 47 | mem.copy(u8, result, slice); |
| 48 | 48 | result[slice.len] = 0; |
| ... | ... | @@ -56,7 +56,7 @@ pub const NullTerminated2DArray = struct { |
| 56 | 56 | |
| 57 | 57 | /// Takes N lists of strings, concatenates the lists together, and adds a null terminator |
| 58 | 58 | /// 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 { | |
| 60 | 60 | var new_len: usize = 1; // 1 for the list null |
| 61 | 61 | var byte_count: usize = 0; |
| 62 | 62 | for (slices) |slice| { |
std/debug/failing_allocator.zig+2-2| ... | ... | @@ -28,7 +28,7 @@ pub const FailingAllocator = struct { |
| 28 | 28 | }; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) %[]u8 { | |
| 31 | fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) ![]u8 { | |
| 32 | 32 | const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); |
| 33 | 33 | if (self.index == self.fail_index) { |
| 34 | 34 | return error.OutOfMemory; |
| ... | ... | @@ -39,7 +39,7 @@ pub const FailingAllocator = struct { |
| 39 | 39 | return result; |
| 40 | 40 | } |
| 41 | 41 | |
| 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 { | |
| 43 | 43 | const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); |
| 44 | 44 | if (new_size <= old_mem.len) { |
| 45 | 45 | self.freed_bytes += old_mem.len - new_size; |
std/elf.zig+4-6| ... | ... | @@ -6,8 +6,6 @@ const mem = std.mem; |
| 6 | 6 | const debug = std.debug; |
| 7 | 7 | const InStream = std.stream.InStream; |
| 8 | 8 | |
| 9 | error InvalidFormat; | |
| 10 | ||
| 11 | 9 | pub const SHT_NULL = 0; |
| 12 | 10 | pub const SHT_PROGBITS = 1; |
| 13 | 11 | pub const SHT_SYMTAB = 2; |
| ... | ... | @@ -81,14 +79,14 @@ pub const Elf = struct { |
| 81 | 79 | prealloc_file: io.File, |
| 82 | 80 | |
| 83 | 81 | /// 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 { | |
| 85 | 83 | try elf.prealloc_file.open(path); |
| 86 | 84 | try elf.openFile(allocator, &elf.prealloc_file); |
| 87 | 85 | elf.auto_close_stream = true; |
| 88 | 86 | } |
| 89 | 87 | |
| 90 | 88 | /// 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 { | |
| 92 | 90 | elf.allocator = allocator; |
| 93 | 91 | elf.in_file = file; |
| 94 | 92 | elf.auto_close_stream = false; |
| ... | ... | @@ -239,7 +237,7 @@ pub const Elf = struct { |
| 239 | 237 | elf.in_file.close(); |
| 240 | 238 | } |
| 241 | 239 | |
| 242 | pub fn findSection(elf: &Elf, name: []const u8) %?&SectionHeader { | |
| 240 | pub fn findSection(elf: &Elf, name: []const u8) !?&SectionHeader { | |
| 243 | 241 | var file_stream = io.FileInStream.init(elf.in_file); |
| 244 | 242 | const in = &file_stream.stream; |
| 245 | 243 | |
| ... | ... | @@ -263,7 +261,7 @@ pub const Elf = struct { |
| 263 | 261 | return null; |
| 264 | 262 | } |
| 265 | 263 | |
| 266 | pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) %void { | |
| 264 | pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) !void { | |
| 267 | 265 | try elf.in_file.seekTo(elf_section.offset); |
| 268 | 266 | } |
| 269 | 267 | }; |
std/fmt/index.zig+31-34| ... | ... | @@ -24,8 +24,8 @@ const State = enum { // TODO put inside format function and make sure the name a |
| 24 | 24 | /// Renders fmt string with args, calling output with slices of bytes. |
| 25 | 25 | /// If `output` returns an error, the error is returned from `format` and |
| 26 | 26 | /// `output` is not called again. |
| 27 | pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, | |
| 28 | comptime fmt: []const u8, args: ...) %void | |
| 27 | pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, | |
| 28 | comptime fmt: []const u8, args: ...) Errors!void | |
| 29 | 29 | { |
| 30 | 30 | comptime var start_index = 0; |
| 31 | 31 | comptime var state = State.Start; |
| ... | ... | @@ -58,7 +58,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 58 | 58 | start_index = i; |
| 59 | 59 | }, |
| 60 | 60 | '}' => { |
| 61 | try formatValue(args[next_arg], context, output); | |
| 61 | try formatValue(args[next_arg], context, Errors, output); | |
| 62 | 62 | next_arg += 1; |
| 63 | 63 | state = State.Start; |
| 64 | 64 | start_index = i + 1; |
| ... | ... | @@ -110,7 +110,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 110 | 110 | }, |
| 111 | 111 | State.Integer => switch (c) { |
| 112 | 112 | '}' => { |
| 113 | try formatInt(args[next_arg], radix, uppercase, width, context, output); | |
| 113 | try formatInt(args[next_arg], radix, uppercase, width, context, Errors, output); | |
| 114 | 114 | next_arg += 1; |
| 115 | 115 | state = State.Start; |
| 116 | 116 | start_index = i + 1; |
| ... | ... | @@ -124,7 +124,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 124 | 124 | State.IntegerWidth => switch (c) { |
| 125 | 125 | '}' => { |
| 126 | 126 | 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); | |
| 128 | 128 | next_arg += 1; |
| 129 | 129 | state = State.Start; |
| 130 | 130 | start_index = i + 1; |
| ... | ... | @@ -134,7 +134,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 134 | 134 | }, |
| 135 | 135 | State.Float => switch (c) { |
| 136 | 136 | '}' => { |
| 137 | try formatFloatDecimal(args[next_arg], 0, context, output); | |
| 137 | try formatFloatDecimal(args[next_arg], 0, context, Errors, output); | |
| 138 | 138 | next_arg += 1; |
| 139 | 139 | state = State.Start; |
| 140 | 140 | start_index = i + 1; |
| ... | ... | @@ -148,7 +148,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 148 | 148 | State.FloatWidth => switch (c) { |
| 149 | 149 | '}' => { |
| 150 | 150 | 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); | |
| 152 | 152 | next_arg += 1; |
| 153 | 153 | state = State.Start; |
| 154 | 154 | start_index = i + 1; |
| ... | ... | @@ -159,7 +159,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 159 | 159 | State.BufWidth => switch (c) { |
| 160 | 160 | '}' => { |
| 161 | 161 | 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); | |
| 163 | 163 | next_arg += 1; |
| 164 | 164 | state = State.Start; |
| 165 | 165 | start_index = i + 1; |
| ... | ... | @@ -169,7 +169,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 169 | 169 | }, |
| 170 | 170 | State.Character => switch (c) { |
| 171 | 171 | '}' => { |
| 172 | try formatAsciiChar(args[next_arg], context, output); | |
| 172 | try formatAsciiChar(args[next_arg], context, Errors, output); | |
| 173 | 173 | next_arg += 1; |
| 174 | 174 | state = State.Start; |
| 175 | 175 | start_index = i + 1; |
| ... | ... | @@ -191,7 +191,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void { | |
| 194 | pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 195 | 195 | const T = @typeOf(value); |
| 196 | 196 | switch (@typeId(T)) { |
| 197 | 197 | builtin.TypeId.Int => { |
| ... | ... | @@ -208,16 +208,16 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons |
| 208 | 208 | }, |
| 209 | 209 | builtin.TypeId.Nullable => { |
| 210 | 210 | if (value) |payload| { |
| 211 | return formatValue(payload, context, output); | |
| 211 | return formatValue(payload, context, Errors, output); | |
| 212 | 212 | } else { |
| 213 | 213 | return output(context, "null"); |
| 214 | 214 | } |
| 215 | 215 | }, |
| 216 | 216 | builtin.TypeId.ErrorUnion => { |
| 217 | 217 | if (value) |payload| { |
| 218 | return formatValue(payload, context, output); | |
| 218 | return formatValue(payload, context, Errors, output); | |
| 219 | 219 | } else |err| { |
| 220 | return formatValue(err, context, output); | |
| 220 | return formatValue(err, context, Errors, output); | |
| 221 | 221 | } |
| 222 | 222 | }, |
| 223 | 223 | builtin.TypeId.Error => { |
| ... | ... | @@ -240,12 +240,12 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)%void) %void { | |
| 243 | pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 244 | 244 | return output(context, (&c)[0..1]); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | pub 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 | |
| 249 | 249 | { |
| 250 | 250 | try output(context, buf); |
| 251 | 251 | |
| ... | ... | @@ -256,7 +256,7 @@ pub fn formatBuf(buf: []const u8, width: usize, |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void { | |
| 259 | pub fn formatFloat(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 260 | 260 | var x = f64(value); |
| 261 | 261 | |
| 262 | 262 | // Errol doesn't handle these special cases. |
| ... | ... | @@ -294,7 +294,7 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn(@typeOf(context), []const u8)%void) %void { | |
| 297 | pub fn formatFloatDecimal(value: var, precision: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 298 | 298 | var x = f64(value); |
| 299 | 299 | |
| 300 | 300 | // Errol doesn't handle these special cases. |
| ... | ... | @@ -336,7 +336,7 @@ pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn |
| 336 | 336 | |
| 337 | 337 | |
| 338 | 338 | pub 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 | |
| 340 | 340 | { |
| 341 | 341 | if (@typeOf(value).is_signed) { |
| 342 | 342 | return formatIntSigned(value, base, uppercase, width, context, output); |
| ... | ... | @@ -346,7 +346,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | fn 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 | |
| 350 | 350 | { |
| 351 | 351 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 352 | 352 | if (value < 0) { |
| ... | ... | @@ -367,7 +367,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | fn 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 | |
| 371 | 371 | { |
| 372 | 372 | // max_int_digits accounts for the minus sign. when printing an unsigned |
| 373 | 373 | // number we don't need to do that. |
| ... | ... | @@ -417,12 +417,12 @@ const FormatIntBuf = struct { |
| 417 | 417 | out_buf: []u8, |
| 418 | 418 | index: usize, |
| 419 | 419 | }; |
| 420 | fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) %void { | |
| 420 | fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) !void { | |
| 421 | 421 | mem.copy(u8, context.out_buf[context.index..], bytes); |
| 422 | 422 | context.index += bytes.len; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) %T { | |
| 425 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { | |
| 426 | 426 | if (!T.is_signed) |
| 427 | 427 | return parseUnsigned(T, buf, radix); |
| 428 | 428 | if (buf.len == 0) |
| ... | ... | @@ -446,7 +446,7 @@ test "fmt.parseInt" { |
| 446 | 446 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) %T { | |
| 449 | pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) !T { | |
| 450 | 450 | var x: T = 0; |
| 451 | 451 | |
| 452 | 452 | for (buf) |c| { |
| ... | ... | @@ -458,8 +458,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) %T { |
| 458 | 458 | return x; |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | error InvalidChar; | |
| 462 | fn charToDigit(c: u8, radix: u8) %u8 { | |
| 461 | fn charToDigit(c: u8, radix: u8) !u8 { | |
| 463 | 462 | const value = switch (c) { |
| 464 | 463 | '0' ... '9' => c - '0', |
| 465 | 464 | 'A' ... 'Z' => c - 'A' + 10, |
| ... | ... | @@ -485,28 +484,26 @@ const BufPrintContext = struct { |
| 485 | 484 | remaining: []u8, |
| 486 | 485 | }; |
| 487 | 486 | |
| 488 | error BufferTooSmall; | |
| 489 | fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) %void { | |
| 487 | fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void { | |
| 490 | 488 | if (context.remaining.len < bytes.len) return error.BufferTooSmall; |
| 491 | 489 | mem.copy(u8, context.remaining, bytes); |
| 492 | 490 | context.remaining = context.remaining[bytes.len..]; |
| 493 | 491 | } |
| 494 | 492 | |
| 495 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) %[]u8 { | |
| 493 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 { | |
| 496 | 494 | var context = BufPrintContext { .remaining = buf, }; |
| 497 | 495 | try format(&context, bufPrintWrite, fmt, args); |
| 498 | 496 | return buf[0..buf.len - context.remaining.len]; |
| 499 | 497 | } |
| 500 | 498 | |
| 501 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) %[]u8 { | |
| 499 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 { | |
| 502 | 500 | 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); | |
| 505 | 502 | const buf = try allocator.alloc(u8, size); |
| 506 | 503 | return bufPrint(buf, fmt, args); |
| 507 | 504 | } |
| 508 | 505 | |
| 509 | fn countSize(size: &usize, bytes: []const u8) %void { | |
| 506 | fn countSize(size: &usize, bytes: []const u8) void { | |
| 510 | 507 | *size += bytes.len; |
| 511 | 508 | } |
| 512 | 509 | |
| ... | ... | @@ -561,13 +558,13 @@ test "fmt.format" { |
| 561 | 558 | } |
| 562 | 559 | { |
| 563 | 560 | var buf1: [32]u8 = undefined; |
| 564 | const value: %i32 = 1234; | |
| 561 | const value: error!i32 = 1234; | |
| 565 | 562 | const result = try bufPrint(buf1[0..], "error union: {}\n", value); |
| 566 | 563 | assert(mem.eql(u8, result, "error union: 1234\n")); |
| 567 | 564 | } |
| 568 | 565 | { |
| 569 | 566 | var buf1: [32]u8 = undefined; |
| 570 | const value: %i32 = error.InvalidChar; | |
| 567 | const value: error!i32 = error.InvalidChar; | |
| 571 | 568 | const result = try bufPrint(buf1[0..], "error union: {}\n", value); |
| 572 | 569 | assert(mem.eql(u8, result, "error union: error.InvalidChar\n")); |
| 573 | 570 | } |
std/hash_map.zig+2-2| ... | ... | @@ -80,7 +80,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /// 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 { | |
| 84 | 84 | if (hm.entries.len == 0) { |
| 85 | 85 | try hm.initCapacity(16); |
| 86 | 86 | } |
| ... | ... | @@ -151,7 +151,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 151 | 151 | }; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | fn initCapacity(hm: &Self, capacity: usize) %void { | |
| 154 | fn initCapacity(hm: &Self, capacity: usize) !void { | |
| 155 | 155 | hm.entries = try hm.allocator.alloc(Entry, capacity); |
| 156 | 156 | hm.size = 0; |
| 157 | 157 | hm.max_distance_from_start_index = 0; |
std/heap.zig+5-7| ... | ... | @@ -9,8 +9,6 @@ const c = std.c; |
| 9 | 9 | |
| 10 | 10 | const Allocator = mem.Allocator; |
| 11 | 11 | |
| 12 | error OutOfMemory; | |
| 13 | ||
| 14 | 12 | pub const c_allocator = &c_allocator_state; |
| 15 | 13 | var c_allocator_state = Allocator { |
| 16 | 14 | .allocFn = cAlloc, |
| ... | ... | @@ -18,14 +16,14 @@ var c_allocator_state = Allocator { |
| 18 | 16 | .freeFn = cFree, |
| 19 | 17 | }; |
| 20 | 18 | |
| 21 | fn cAlloc(self: &Allocator, n: usize, alignment: u29) %[]u8 { | |
| 19 | fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 { | |
| 22 | 20 | return if (c.malloc(usize(n))) |buf| |
| 23 | 21 | @ptrCast(&u8, buf)[0..n] |
| 24 | 22 | else |
| 25 | 23 | error.OutOfMemory; |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 { | |
| 26 | fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 { | |
| 29 | 27 | const old_ptr = @ptrCast(&c_void, old_mem.ptr); |
| 30 | 28 | if (c.realloc(old_ptr, new_size)) |buf| { |
| 31 | 29 | return @ptrCast(&u8, buf)[0..new_size]; |
| ... | ... | @@ -47,7 +45,7 @@ pub const IncrementingAllocator = struct { |
| 47 | 45 | end_index: usize, |
| 48 | 46 | heap_handle: if (builtin.os == Os.windows) os.windows.HANDLE else void, |
| 49 | 47 | |
| 50 | fn init(capacity: usize) %IncrementingAllocator { | |
| 48 | fn init(capacity: usize) !IncrementingAllocator { | |
| 51 | 49 | switch (builtin.os) { |
| 52 | 50 | Os.linux, Os.macosx, Os.ios => { |
| 53 | 51 | const p = os.posix; |
| ... | ... | @@ -105,7 +103,7 @@ pub const IncrementingAllocator = struct { |
| 105 | 103 | return self.bytes.len - self.end_index; |
| 106 | 104 | } |
| 107 | 105 | |
| 108 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 { | |
| 106 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 { | |
| 109 | 107 | const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator); |
| 110 | 108 | const addr = @ptrToInt(&self.bytes[self.end_index]); |
| 111 | 109 | const rem = @rem(addr, alignment); |
| ... | ... | @@ -120,7 +118,7 @@ pub const IncrementingAllocator = struct { |
| 120 | 118 | return result; |
| 121 | 119 | } |
| 122 | 120 | |
| 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 { | |
| 124 | 122 | if (new_size <= old_mem.len) { |
| 125 | 123 | return old_mem[0..new_size]; |
| 126 | 124 | } else { |
std/io.zig+41-67| ... | ... | @@ -26,31 +26,7 @@ test "import io tests" { |
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | /// The function received invalid input at runtime. An Invalid error means a | |
| 30 | /// bug in the program that called the function. | |
| 31 | error Invalid; | |
| 32 | ||
| 33 | error DiskQuota; | |
| 34 | error FileTooBig; | |
| 35 | error Io; | |
| 36 | error NoSpaceLeft; | |
| 37 | error BadPerm; | |
| 38 | error BrokenPipe; | |
| 39 | error BadFd; | |
| 40 | error IsDir; | |
| 41 | error NotDir; | |
| 42 | error SymLinkLoop; | |
| 43 | error ProcessFdQuotaExceeded; | |
| 44 | error SystemFdQuotaExceeded; | |
| 45 | error NameTooLong; | |
| 46 | error NoDevice; | |
| 47 | error PathNotFound; | |
| 48 | error OutOfMemory; | |
| 49 | error Unseekable; | |
| 50 | error EndOfFile; | |
| 51 | error FilePosLargerThanPointerRange; | |
| 52 | ||
| 53 | pub fn getStdErr() %File { | |
| 29 | pub fn getStdErr() !File { | |
| 54 | 30 | const handle = if (is_windows) |
| 55 | 31 | try os.windowsGetStdHandle(system.STD_ERROR_HANDLE) |
| 56 | 32 | else if (is_posix) |
| ... | ... | @@ -60,7 +36,7 @@ pub fn getStdErr() %File { |
| 60 | 36 | return File.openHandle(handle); |
| 61 | 37 | } |
| 62 | 38 | |
| 63 | pub fn getStdOut() %File { | |
| 39 | pub fn getStdOut() !File { | |
| 64 | 40 | const handle = if (is_windows) |
| 65 | 41 | try os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE) |
| 66 | 42 | else if (is_posix) |
| ... | ... | @@ -70,7 +46,7 @@ pub fn getStdOut() %File { |
| 70 | 46 | return File.openHandle(handle); |
| 71 | 47 | } |
| 72 | 48 | |
| 73 | pub fn getStdIn() %File { | |
| 49 | pub fn getStdIn() !File { | |
| 74 | 50 | const handle = if (is_windows) |
| 75 | 51 | try os.windowsGetStdHandle(system.STD_INPUT_HANDLE) |
| 76 | 52 | else if (is_posix) |
| ... | ... | @@ -94,7 +70,7 @@ pub const FileInStream = struct { |
| 94 | 70 | }; |
| 95 | 71 | } |
| 96 | 72 | |
| 97 | fn readFn(in_stream: &InStream, buffer: []u8) %usize { | |
| 73 | fn readFn(in_stream: &InStream, buffer: []u8) !usize { | |
| 98 | 74 | const self = @fieldParentPtr(FileInStream, "stream", in_stream); |
| 99 | 75 | return self.file.read(buffer); |
| 100 | 76 | } |
| ... | ... | @@ -114,7 +90,7 @@ pub const FileOutStream = struct { |
| 114 | 90 | }; |
| 115 | 91 | } |
| 116 | 92 | |
| 117 | fn writeFn(out_stream: &OutStream, bytes: []const u8) %void { | |
| 93 | fn writeFn(out_stream: &OutStream, bytes: []const u8) !void { | |
| 118 | 94 | const self = @fieldParentPtr(FileOutStream, "stream", out_stream); |
| 119 | 95 | return self.file.write(bytes); |
| 120 | 96 | } |
| ... | ... | @@ -129,7 +105,7 @@ pub const File = struct { |
| 129 | 105 | /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned. |
| 130 | 106 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 131 | 107 | /// 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 { | |
| 133 | 109 | if (is_posix) { |
| 134 | 110 | const flags = system.O_LARGEFILE|system.O_RDONLY; |
| 135 | 111 | const fd = try os.posixOpen(path, flags, 0, allocator); |
| ... | ... | @@ -144,7 +120,7 @@ pub const File = struct { |
| 144 | 120 | } |
| 145 | 121 | |
| 146 | 122 | /// 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 { | |
| 148 | 124 | return openWriteMode(path, 0o666, allocator); |
| 149 | 125 | |
| 150 | 126 | } |
| ... | ... | @@ -154,7 +130,7 @@ pub const File = struct { |
| 154 | 130 | /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned. |
| 155 | 131 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 156 | 132 | /// 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 { | |
| 158 | 134 | if (is_posix) { |
| 159 | 135 | const flags = system.O_LARGEFILE|system.O_WRONLY|system.O_CREAT|system.O_CLOEXEC|system.O_TRUNC; |
| 160 | 136 | const fd = try os.posixOpen(path, flags, mode, allocator); |
| ... | ... | @@ -189,7 +165,7 @@ pub const File = struct { |
| 189 | 165 | return os.isTty(self.handle); |
| 190 | 166 | } |
| 191 | 167 | |
| 192 | pub fn seekForward(self: &File, amount: isize) %void { | |
| 168 | pub fn seekForward(self: &File, amount: isize) !void { | |
| 193 | 169 | switch (builtin.os) { |
| 194 | 170 | Os.linux, Os.macosx, Os.ios => { |
| 195 | 171 | const result = system.lseek(self.handle, amount, system.SEEK_CUR); |
| ... | ... | @@ -218,7 +194,7 @@ pub const File = struct { |
| 218 | 194 | } |
| 219 | 195 | } |
| 220 | 196 | |
| 221 | pub fn seekTo(self: &File, pos: usize) %void { | |
| 197 | pub fn seekTo(self: &File, pos: usize) !void { | |
| 222 | 198 | switch (builtin.os) { |
| 223 | 199 | Os.linux, Os.macosx, Os.ios => { |
| 224 | 200 | const ipos = try math.cast(isize, pos); |
| ... | ... | @@ -249,7 +225,7 @@ pub const File = struct { |
| 249 | 225 | } |
| 250 | 226 | } |
| 251 | 227 | |
| 252 | pub fn getPos(self: &File) %usize { | |
| 228 | pub fn getPos(self: &File) !usize { | |
| 253 | 229 | switch (builtin.os) { |
| 254 | 230 | Os.linux, Os.macosx, Os.ios => { |
| 255 | 231 | const result = system.lseek(self.handle, 0, system.SEEK_CUR); |
| ... | ... | @@ -289,7 +265,7 @@ pub const File = struct { |
| 289 | 265 | } |
| 290 | 266 | } |
| 291 | 267 | |
| 292 | pub fn getEndPos(self: &File) %usize { | |
| 268 | pub fn getEndPos(self: &File) !usize { | |
| 293 | 269 | if (is_posix) { |
| 294 | 270 | var stat: system.Stat = undefined; |
| 295 | 271 | const err = system.getErrno(system.fstat(self.handle, &stat)); |
| ... | ... | @@ -318,7 +294,7 @@ pub const File = struct { |
| 318 | 294 | } |
| 319 | 295 | } |
| 320 | 296 | |
| 321 | pub fn read(self: &File, buffer: []u8) %usize { | |
| 297 | pub fn read(self: &File, buffer: []u8) !usize { | |
| 322 | 298 | if (is_posix) { |
| 323 | 299 | var index: usize = 0; |
| 324 | 300 | while (index < buffer.len) { |
| ... | ... | @@ -360,7 +336,7 @@ pub const File = struct { |
| 360 | 336 | } |
| 361 | 337 | } |
| 362 | 338 | |
| 363 | fn write(self: &File, bytes: []const u8) %void { | |
| 339 | fn write(self: &File, bytes: []const u8) !void { | |
| 364 | 340 | if (is_posix) { |
| 365 | 341 | try os.posixWrite(self.handle, bytes); |
| 366 | 342 | } else if (is_windows) { |
| ... | ... | @@ -371,19 +347,16 @@ pub const File = struct { |
| 371 | 347 | } |
| 372 | 348 | }; |
| 373 | 349 | |
| 374 | error StreamTooLong; | |
| 375 | error EndOfStream; | |
| 376 | ||
| 377 | 350 | pub const InStream = struct { |
| 378 | 351 | /// Return the number of bytes read. If the number read is smaller than buf.len, it |
| 379 | 352 | /// means the stream reached the end. Reaching the end of a stream is not an error |
| 380 | 353 | /// condition. |
| 381 | readFn: fn(self: &InStream, buffer: []u8) %usize, | |
| 354 | readFn: fn(self: &InStream, buffer: []u8) !usize, | |
| 382 | 355 | |
| 383 | 356 | /// Replaces `buffer` contents by reading from the stream until it is finished. |
| 384 | 357 | /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and |
| 385 | 358 | /// 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 { | |
| 387 | 360 | try buffer.resize(0); |
| 388 | 361 | |
| 389 | 362 | var actual_buf_len: usize = 0; |
| ... | ... | @@ -408,7 +381,7 @@ pub const InStream = struct { |
| 408 | 381 | /// memory would be greater than `max_size`, returns `error.StreamTooLong`. |
| 409 | 382 | /// Caller owns returned memory. |
| 410 | 383 | /// 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 { | |
| 412 | 385 | var buf = Buffer.initNull(allocator); |
| 413 | 386 | defer buf.deinit(); |
| 414 | 387 | |
| ... | ... | @@ -420,7 +393,7 @@ pub const InStream = struct { |
| 420 | 393 | /// Does not include the delimiter in the result. |
| 421 | 394 | /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents |
| 422 | 395 | /// 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 { | |
| 424 | 397 | try buf.resize(0); |
| 425 | 398 | |
| 426 | 399 | while (true) { |
| ... | ... | @@ -443,7 +416,7 @@ pub const InStream = struct { |
| 443 | 416 | /// Caller owns returned memory. |
| 444 | 417 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 445 | 418 | pub fn readUntilDelimiterAlloc(self: &InStream, allocator: &mem.Allocator, |
| 446 | delimiter: u8, max_size: usize) %[]u8 | |
| 419 | delimiter: u8, max_size: usize) ![]u8 | |
| 447 | 420 | { |
| 448 | 421 | var buf = Buffer.initNull(allocator); |
| 449 | 422 | defer buf.deinit(); |
| ... | ... | @@ -455,43 +428,43 @@ pub const InStream = struct { |
| 455 | 428 | /// Returns the number of bytes read. If the number read is smaller than buf.len, it |
| 456 | 429 | /// means the stream reached the end. Reaching the end of a stream is not an error |
| 457 | 430 | /// condition. |
| 458 | pub fn read(self: &InStream, buffer: []u8) %usize { | |
| 431 | pub fn read(self: &InStream, buffer: []u8) !usize { | |
| 459 | 432 | return self.readFn(self, buffer); |
| 460 | 433 | } |
| 461 | 434 | |
| 462 | 435 | /// 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 { | |
| 464 | 437 | const amt_read = try self.read(buf); |
| 465 | 438 | if (amt_read < buf.len) return error.EndOfStream; |
| 466 | 439 | } |
| 467 | 440 | |
| 468 | 441 | /// Reads 1 byte from the stream or returns `error.EndOfStream`. |
| 469 | pub fn readByte(self: &InStream) %u8 { | |
| 442 | pub fn readByte(self: &InStream) !u8 { | |
| 470 | 443 | var result: [1]u8 = undefined; |
| 471 | 444 | try self.readNoEof(result[0..]); |
| 472 | 445 | return result[0]; |
| 473 | 446 | } |
| 474 | 447 | |
| 475 | 448 | /// Same as `readByte` except the returned byte is signed. |
| 476 | pub fn readByteSigned(self: &InStream) %i8 { | |
| 449 | pub fn readByteSigned(self: &InStream) !i8 { | |
| 477 | 450 | return @bitCast(i8, try self.readByte()); |
| 478 | 451 | } |
| 479 | 452 | |
| 480 | pub fn readIntLe(self: &InStream, comptime T: type) %T { | |
| 453 | pub fn readIntLe(self: &InStream, comptime T: type) !T { | |
| 481 | 454 | return self.readInt(builtin.Endian.Little, T); |
| 482 | 455 | } |
| 483 | 456 | |
| 484 | pub fn readIntBe(self: &InStream, comptime T: type) %T { | |
| 457 | pub fn readIntBe(self: &InStream, comptime T: type) !T { | |
| 485 | 458 | return self.readInt(builtin.Endian.Big, T); |
| 486 | 459 | } |
| 487 | 460 | |
| 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 { | |
| 489 | 462 | var bytes: [@sizeOf(T)]u8 = undefined; |
| 490 | 463 | try self.readNoEof(bytes[0..]); |
| 491 | 464 | return mem.readInt(bytes, T, endian); |
| 492 | 465 | } |
| 493 | 466 | |
| 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 { | |
| 495 | 468 | assert(size <= @sizeOf(T)); |
| 496 | 469 | assert(size <= 8); |
| 497 | 470 | var input_buf: [8]u8 = undefined; |
| ... | ... | @@ -504,22 +477,23 @@ pub const InStream = struct { |
| 504 | 477 | }; |
| 505 | 478 | |
| 506 | 479 | pub 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, | |
| 508 | 482 | |
| 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); | |
| 511 | 485 | } |
| 512 | 486 | |
| 513 | pub fn write(self: &OutStream, bytes: []const u8) %void { | |
| 487 | pub fn write(self: &OutStream, bytes: []const u8) !void { | |
| 514 | 488 | return self.writeFn(self, bytes); |
| 515 | 489 | } |
| 516 | 490 | |
| 517 | pub fn writeByte(self: &OutStream, byte: u8) %void { | |
| 491 | pub fn writeByte(self: &OutStream, byte: u8) !void { | |
| 518 | 492 | const slice = (&byte)[0..1]; |
| 519 | 493 | return self.writeFn(self, slice); |
| 520 | 494 | } |
| 521 | 495 | |
| 522 | pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) %void { | |
| 496 | pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) !void { | |
| 523 | 497 | const slice = (&byte)[0..1]; |
| 524 | 498 | var i: usize = 0; |
| 525 | 499 | while (i < n) : (i += 1) { |
| ... | ... | @@ -532,19 +506,19 @@ pub const OutStream = struct { |
| 532 | 506 | /// a fixed size buffer of size `std.os.max_noalloc_path_len` is an attempted solution. If the fixed |
| 533 | 507 | /// size buffer is too small, and the provided allocator is null, `error.NameTooLong` is returned. |
| 534 | 508 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 535 | pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) %void { | |
| 509 | pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) !void { | |
| 536 | 510 | var file = try File.openWrite(path, allocator); |
| 537 | 511 | defer file.close(); |
| 538 | 512 | try file.write(data); |
| 539 | 513 | } |
| 540 | 514 | |
| 541 | 515 | /// On success, caller owns returned buffer. |
| 542 | pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) %[]u8 { | |
| 516 | pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) ![]u8 { | |
| 543 | 517 | return readFileAllocExtra(path, allocator, 0); |
| 544 | 518 | } |
| 545 | 519 | /// On success, caller owns returned buffer. |
| 546 | 520 | /// Allocates extra_len extra bytes at the end of the file buffer, which are uninitialized. |
| 547 | pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) %[]u8 { | |
| 521 | pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) ![]u8 { | |
| 548 | 522 | var file = try File.openRead(path, allocator); |
| 549 | 523 | defer file.close(); |
| 550 | 524 | |
| ... | ... | @@ -589,7 +563,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) type { |
| 589 | 563 | }; |
| 590 | 564 | } |
| 591 | 565 | |
| 592 | fn readFn(in_stream: &InStream, dest: []u8) %usize { | |
| 566 | fn readFn(in_stream: &InStream, dest: []u8) !usize { | |
| 593 | 567 | const self = @fieldParentPtr(Self, "stream", in_stream); |
| 594 | 568 | |
| 595 | 569 | var dest_index: usize = 0; |
| ... | ... | @@ -652,7 +626,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type { |
| 652 | 626 | }; |
| 653 | 627 | } |
| 654 | 628 | |
| 655 | pub fn flush(self: &Self) %void { | |
| 629 | pub fn flush(self: &Self) !void { | |
| 656 | 630 | if (self.index == 0) |
| 657 | 631 | return; |
| 658 | 632 | |
| ... | ... | @@ -660,7 +634,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type { |
| 660 | 634 | self.index = 0; |
| 661 | 635 | } |
| 662 | 636 | |
| 663 | fn writeFn(out_stream: &OutStream, bytes: []const u8) %void { | |
| 637 | fn writeFn(out_stream: &OutStream, bytes: []const u8) !void { | |
| 664 | 638 | const self = @fieldParentPtr(Self, "stream", out_stream); |
| 665 | 639 | |
| 666 | 640 | if (bytes.len >= self.buffer.len) { |
| ... | ... | @@ -698,7 +672,7 @@ pub const BufferOutStream = struct { |
| 698 | 672 | }; |
| 699 | 673 | } |
| 700 | 674 | |
| 701 | fn writeFn(out_stream: &OutStream, bytes: []const u8) %void { | |
| 675 | fn writeFn(out_stream: &OutStream, bytes: []const u8) !void { | |
| 702 | 676 | const self = @fieldParentPtr(BufferOutStream, "stream", out_stream); |
| 703 | 677 | return self.buffer.append(bytes); |
| 704 | 678 | } |
std/linked_list.zig+2-2| ... | ... | @@ -190,7 +190,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 190 | 190 | /// |
| 191 | 191 | /// Returns: |
| 192 | 192 | /// A pointer to the new node. |
| 193 | pub fn allocateNode(list: &Self, allocator: &Allocator) %&Node { | |
| 193 | pub fn allocateNode(list: &Self, allocator: &Allocator) !&Node { | |
| 194 | 194 | comptime assert(!isIntrusive()); |
| 195 | 195 | return allocator.create(Node); |
| 196 | 196 | } |
| ... | ... | @@ -213,7 +213,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 213 | 213 | /// |
| 214 | 214 | /// Returns: |
| 215 | 215 | /// 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 { | |
| 217 | 217 | comptime assert(!isIntrusive()); |
| 218 | 218 | var node = try list.allocateNode(allocator); |
| 219 | 219 | *node = Node.init(data); |
std/math/index.zig+13-31| ... | ... | @@ -191,30 +191,26 @@ test "math.max" { |
| 191 | 191 | assert(max(i32(-1), i32(2)) == 2); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | error Overflow; | |
| 195 | pub fn mul(comptime T: type, a: T, b: T) %T { | |
| 194 | pub fn mul(comptime T: type, a: T, b: T) !T { | |
| 196 | 195 | var answer: T = undefined; |
| 197 | 196 | return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 198 | 197 | } |
| 199 | 198 | |
| 200 | error Overflow; | |
| 201 | pub fn add(comptime T: type, a: T, b: T) %T { | |
| 199 | pub fn add(comptime T: type, a: T, b: T) !T { | |
| 202 | 200 | var answer: T = undefined; |
| 203 | 201 | return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 204 | 202 | } |
| 205 | 203 | |
| 206 | error Overflow; | |
| 207 | pub fn sub(comptime T: type, a: T, b: T) %T { | |
| 204 | pub fn sub(comptime T: type, a: T, b: T) !T { | |
| 208 | 205 | var answer: T = undefined; |
| 209 | 206 | return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 210 | 207 | } |
| 211 | 208 | |
| 212 | pub fn negate(x: var) %@typeOf(x) { | |
| 209 | pub fn negate(x: var) !@typeOf(x) { | |
| 213 | 210 | return sub(@typeOf(x), 0, x); |
| 214 | 211 | } |
| 215 | 212 | |
| 216 | error Overflow; | |
| 217 | pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) %T { | |
| 213 | pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T { | |
| 218 | 214 | var answer: T = undefined; |
| 219 | 215 | return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer; |
| 220 | 216 | } |
| ... | ... | @@ -323,8 +319,7 @@ fn testOverflow() void { |
| 323 | 319 | } |
| 324 | 320 | |
| 325 | 321 | |
| 326 | error Overflow; | |
| 327 | pub fn absInt(x: var) %@typeOf(x) { | |
| 322 | pub fn absInt(x: var) !@typeOf(x) { | |
| 328 | 323 | const T = @typeOf(x); |
| 329 | 324 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt |
| 330 | 325 | comptime assert(T.is_signed); // must pass a signed integer to absInt |
| ... | ... | @@ -347,9 +342,7 @@ fn testAbsInt() void { |
| 347 | 342 | |
| 348 | 343 | pub const absFloat = @import("fabs.zig").fabs; |
| 349 | 344 | |
| 350 | error DivisionByZero; | |
| 351 | error Overflow; | |
| 352 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) %T { | |
| 345 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { | |
| 353 | 346 | @setRuntimeSafety(false); |
| 354 | 347 | if (denominator == 0) |
| 355 | 348 | return error.DivisionByZero; |
| ... | ... | @@ -372,9 +365,7 @@ fn testDivTrunc() void { |
| 372 | 365 | assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0); |
| 373 | 366 | } |
| 374 | 367 | |
| 375 | error DivisionByZero; | |
| 376 | error Overflow; | |
| 377 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) %T { | |
| 368 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { | |
| 378 | 369 | @setRuntimeSafety(false); |
| 379 | 370 | if (denominator == 0) |
| 380 | 371 | return error.DivisionByZero; |
| ... | ... | @@ -397,10 +388,7 @@ fn testDivFloor() void { |
| 397 | 388 | assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0); |
| 398 | 389 | } |
| 399 | 390 | |
| 400 | error DivisionByZero; | |
| 401 | error Overflow; | |
| 402 | error UnexpectedRemainder; | |
| 403 | pub fn divExact(comptime T: type, numerator: T, denominator: T) %T { | |
| 391 | pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { | |
| 404 | 392 | @setRuntimeSafety(false); |
| 405 | 393 | if (denominator == 0) |
| 406 | 394 | return error.DivisionByZero; |
| ... | ... | @@ -428,9 +416,7 @@ fn testDivExact() void { |
| 428 | 416 | if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder); |
| 429 | 417 | } |
| 430 | 418 | |
| 431 | error DivisionByZero; | |
| 432 | error NegativeDenominator; | |
| 433 | pub fn mod(comptime T: type, numerator: T, denominator: T) %T { | |
| 419 | pub fn mod(comptime T: type, numerator: T, denominator: T) !T { | |
| 434 | 420 | @setRuntimeSafety(false); |
| 435 | 421 | if (denominator == 0) |
| 436 | 422 | return error.DivisionByZero; |
| ... | ... | @@ -455,9 +441,7 @@ fn testMod() void { |
| 455 | 441 | if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 456 | 442 | } |
| 457 | 443 | |
| 458 | error DivisionByZero; | |
| 459 | error NegativeDenominator; | |
| 460 | pub fn rem(comptime T: type, numerator: T, denominator: T) %T { | |
| 444 | pub fn rem(comptime T: type, numerator: T, denominator: T) !T { | |
| 461 | 445 | @setRuntimeSafety(false); |
| 462 | 446 | if (denominator == 0) |
| 463 | 447 | return error.DivisionByZero; |
| ... | ... | @@ -505,8 +489,7 @@ test "math.absCast" { |
| 505 | 489 | |
| 506 | 490 | /// Returns the negation of the integer parameter. |
| 507 | 491 | /// Result is a signed integer. |
| 508 | error Overflow; | |
| 509 | pub fn negateCast(x: var) %@IntType(true, @typeOf(x).bit_count) { | |
| 492 | pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { | |
| 510 | 493 | if (@typeOf(x).is_signed) |
| 511 | 494 | return negate(x); |
| 512 | 495 | |
| ... | ... | @@ -532,8 +515,7 @@ test "math.negateCast" { |
| 532 | 515 | |
| 533 | 516 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| 534 | 517 | /// return an error. |
| 535 | error Overflow; | |
| 536 | pub fn cast(comptime T: type, x: var) %T { | |
| 518 | pub fn cast(comptime T: type, x: var) !T { | |
| 537 | 519 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer |
| 538 | 520 | if (x > @maxValue(T)) { |
| 539 | 521 | return error.Overflow; |
std/mem.zig+11-11| ... | ... | @@ -4,13 +4,13 @@ const assert = debug.assert; |
| 4 | 4 | const math = std.math; |
| 5 | 5 | const builtin = @import("builtin"); |
| 6 | 6 | |
| 7 | error OutOfMemory; | |
| 8 | ||
| 9 | 7 | pub const Allocator = struct { |
| 8 | const Errors = error {OutOfMemory}; | |
| 9 | ||
| 10 | 10 | /// Allocate byte_count bytes and return them in a slice, with the |
| 11 | 11 | /// slice's pointer aligned at least to alignment bytes. |
| 12 | 12 | /// 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, | |
| 14 | 14 | |
| 15 | 15 | /// If `new_byte_count > old_mem.len`: |
| 16 | 16 | /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn. |
| ... | ... | @@ -21,12 +21,12 @@ pub const Allocator = struct { |
| 21 | 21 | /// * alignment <= alignment of old_mem.ptr |
| 22 | 22 | /// |
| 23 | 23 | /// 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, | |
| 25 | 25 | |
| 26 | 26 | /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn` |
| 27 | 27 | freeFn: fn (self: &Allocator, old_mem: []u8) void, |
| 28 | 28 | |
| 29 | fn create(self: &Allocator, comptime T: type) %&T { | |
| 29 | fn create(self: &Allocator, comptime T: type) !&T { | |
| 30 | 30 | const slice = try self.alloc(T, 1); |
| 31 | 31 | return &slice[0]; |
| 32 | 32 | } |
| ... | ... | @@ -35,7 +35,7 @@ pub const Allocator = struct { |
| 35 | 35 | self.free(ptr[0..1]); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | fn alloc(self: &Allocator, comptime T: type, n: usize) %[]T { | |
| 38 | fn alloc(self: &Allocator, comptime T: type, n: usize) ![]T { | |
| 39 | 39 | return self.alignedAlloc(T, @alignOf(T), n); |
| 40 | 40 | } |
| 41 | 41 | |
| ... | ... | @@ -51,7 +51,7 @@ pub const Allocator = struct { |
| 51 | 51 | return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); |
| 52 | 52 | } |
| 53 | 53 | |
| 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 { | |
| 55 | 55 | return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n); |
| 56 | 56 | } |
| 57 | 57 | |
| ... | ... | @@ -123,7 +123,7 @@ pub const FixedBufferAllocator = struct { |
| 123 | 123 | }; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 { | |
| 126 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 { | |
| 127 | 127 | const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator); |
| 128 | 128 | const addr = @ptrToInt(&self.buffer[self.end_index]); |
| 129 | 129 | const rem = @rem(addr, alignment); |
| ... | ... | @@ -138,7 +138,7 @@ pub const FixedBufferAllocator = struct { |
| 138 | 138 | return result; |
| 139 | 139 | } |
| 140 | 140 | |
| 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 { | |
| 142 | 142 | if (new_size <= old_mem.len) { |
| 143 | 143 | return old_mem[0..new_size]; |
| 144 | 144 | } else { |
| ... | ... | @@ -197,7 +197,7 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /// Copies ::m to newly allocated memory. Caller is responsible to free it. |
| 200 | pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) %[]T { | |
| 200 | pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) ![]T { | |
| 201 | 201 | const new_buf = try allocator.alloc(T, m.len); |
| 202 | 202 | copy(T, new_buf, m); |
| 203 | 203 | return new_buf; |
| ... | ... | @@ -428,7 +428,7 @@ const SplitIterator = struct { |
| 428 | 428 | |
| 429 | 429 | /// Naively combines a series of strings with a separator. |
| 430 | 430 | /// Allocates memory for the result, which must be freed by the caller. |
| 431 | pub fn join(allocator: &Allocator, sep: u8, strings: ...) %[]u8 { | |
| 431 | pub fn join(allocator: &Allocator, sep: u8, strings: ...) ![]u8 { | |
| 432 | 432 | comptime assert(strings.len >= 1); |
| 433 | 433 | var total_strings_len: usize = strings.len; // 1 sep per string |
| 434 | 434 | { |
std/net.zig+9-25| ... | ... | @@ -5,19 +5,10 @@ const endian = std.endian; |
| 5 | 5 | |
| 6 | 6 | // TODO don't trust this file, it bit rotted. start over |
| 7 | 7 | |
| 8 | error SigInterrupt; | |
| 9 | error Io; | |
| 10 | error TimedOut; | |
| 11 | error ConnectionReset; | |
| 12 | error ConnectionRefused; | |
| 13 | error OutOfMemory; | |
| 14 | error NotSocket; | |
| 15 | error BadFd; | |
| 16 | ||
| 17 | 8 | const Connection = struct { |
| 18 | 9 | socket_fd: i32, |
| 19 | 10 | |
| 20 | pub fn send(c: Connection, buf: []const u8) %usize { | |
| 11 | pub fn send(c: Connection, buf: []const u8) !usize { | |
| 21 | 12 | const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0); |
| 22 | 13 | const send_err = linux.getErrno(send_ret); |
| 23 | 14 | switch (send_err) { |
| ... | ... | @@ -31,7 +22,7 @@ const Connection = struct { |
| 31 | 22 | } |
| 32 | 23 | } |
| 33 | 24 | |
| 34 | pub fn recv(c: Connection, buf: []u8) %[]u8 { | |
| 25 | pub fn recv(c: Connection, buf: []u8) ![]u8 { | |
| 35 | 26 | const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null); |
| 36 | 27 | const recv_err = linux.getErrno(recv_ret); |
| 37 | 28 | switch (recv_err) { |
| ... | ... | @@ -48,7 +39,7 @@ const Connection = struct { |
| 48 | 39 | } |
| 49 | 40 | } |
| 50 | 41 | |
| 51 | pub fn close(c: Connection) %void { | |
| 42 | pub fn close(c: Connection) !void { | |
| 52 | 43 | switch (linux.getErrno(linux.close(c.socket_fd))) { |
| 53 | 44 | 0 => return, |
| 54 | 45 | linux.EBADF => unreachable, |
| ... | ... | @@ -66,7 +57,7 @@ const Address = struct { |
| 66 | 57 | sort_key: i32, |
| 67 | 58 | }; |
| 68 | 59 | |
| 69 | pub fn lookup(hostname: []const u8, out_addrs: []Address) %[]Address { | |
| 60 | pub fn lookup(hostname: []const u8, out_addrs: []Address) ![]Address { | |
| 70 | 61 | if (hostname.len == 0) { |
| 71 | 62 | |
| 72 | 63 | unreachable; // TODO |
| ... | ... | @@ -75,7 +66,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) %[]Address { |
| 75 | 66 | unreachable; // TODO |
| 76 | 67 | } |
| 77 | 68 | |
| 78 | pub fn connectAddr(addr: &Address, port: u16) %Connection { | |
| 69 | pub fn connectAddr(addr: &Address, port: u16) !Connection { | |
| 79 | 70 | const socket_ret = linux.socket(addr.family, linux.SOCK_STREAM, linux.PROTO_tcp); |
| 80 | 71 | const socket_err = linux.getErrno(socket_ret); |
| 81 | 72 | if (socket_err > 0) { |
| ... | ... | @@ -118,7 +109,7 @@ pub fn connectAddr(addr: &Address, port: u16) %Connection { |
| 118 | 109 | }; |
| 119 | 110 | } |
| 120 | 111 | |
| 121 | pub fn connect(hostname: []const u8, port: u16) %Connection { | |
| 112 | pub fn connect(hostname: []const u8, port: u16) !Connection { | |
| 122 | 113 | var addrs_buf: [1]Address = undefined; |
| 123 | 114 | const addrs_slice = try lookup(hostname, addrs_buf[0..]); |
| 124 | 115 | const main_addr = &addrs_slice[0]; |
| ... | ... | @@ -126,9 +117,7 @@ pub fn connect(hostname: []const u8, port: u16) %Connection { |
| 126 | 117 | return connectAddr(main_addr, port); |
| 127 | 118 | } |
| 128 | 119 | |
| 129 | error InvalidIpLiteral; | |
| 130 | ||
| 131 | pub fn parseIpLiteral(buf: []const u8) %Address { | |
| 120 | pub fn parseIpLiteral(buf: []const u8) !Address { | |
| 132 | 121 | |
| 133 | 122 | return error.InvalidIpLiteral; |
| 134 | 123 | } |
| ... | ... | @@ -146,12 +135,7 @@ fn hexDigit(c: u8) u8 { |
| 146 | 135 | } |
| 147 | 136 | } |
| 148 | 137 | |
| 149 | error InvalidChar; | |
| 150 | error Overflow; | |
| 151 | error JunkAtEnd; | |
| 152 | error Incomplete; | |
| 153 | ||
| 154 | fn parseIp6(buf: []const u8) %Address { | |
| 138 | fn parseIp6(buf: []const u8) !Address { | |
| 155 | 139 | var result: Address = undefined; |
| 156 | 140 | result.family = linux.AF_INET6; |
| 157 | 141 | result.scope_id = 0; |
| ... | ... | @@ -232,7 +216,7 @@ fn parseIp6(buf: []const u8) %Address { |
| 232 | 216 | return error.Incomplete; |
| 233 | 217 | } |
| 234 | 218 | |
| 235 | fn parseIp4(buf: []const u8) %u32 { | |
| 219 | fn parseIp4(buf: []const u8) !u32 { | |
| 236 | 220 | var result: u32 = undefined; |
| 237 | 221 | const out_ptr = ([]u8)((&result)[0..1]); |
| 238 | 222 |
std/os/child_process.zig+23-27| ... | ... | @@ -13,10 +13,6 @@ const builtin = @import("builtin"); |
| 13 | 13 | const Os = builtin.Os; |
| 14 | 14 | const LinkedList = std.LinkedList; |
| 15 | 15 | |
| 16 | error PermissionDenied; | |
| 17 | error ProcessNotFound; | |
| 18 | error InvalidName; | |
| 19 | ||
| 20 | 16 | var children_nodes = LinkedList(&ChildProcess).init(); |
| 21 | 17 | |
| 22 | 18 | const is_windows = builtin.os == Os.windows; |
| ... | ... | @@ -74,7 +70,7 @@ pub const ChildProcess = struct { |
| 74 | 70 | |
| 75 | 71 | /// First argument in argv is the executable. |
| 76 | 72 | /// 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 { | |
| 78 | 74 | const child = try allocator.create(ChildProcess); |
| 79 | 75 | errdefer allocator.destroy(child); |
| 80 | 76 | |
| ... | ... | @@ -103,7 +99,7 @@ pub const ChildProcess = struct { |
| 103 | 99 | return child; |
| 104 | 100 | } |
| 105 | 101 | |
| 106 | pub fn setUserName(self: &ChildProcess, name: []const u8) %void { | |
| 102 | pub fn setUserName(self: &ChildProcess, name: []const u8) !void { | |
| 107 | 103 | const user_info = try os.getUserInfo(name); |
| 108 | 104 | self.uid = user_info.uid; |
| 109 | 105 | self.gid = user_info.gid; |
| ... | ... | @@ -111,7 +107,7 @@ pub const ChildProcess = struct { |
| 111 | 107 | |
| 112 | 108 | /// onTerm can be called before `spawn` returns. |
| 113 | 109 | /// On success must call `kill` or `wait`. |
| 114 | pub fn spawn(self: &ChildProcess) %void { | |
| 110 | pub fn spawn(self: &ChildProcess) !void { | |
| 115 | 111 | if (is_windows) { |
| 116 | 112 | return self.spawnWindows(); |
| 117 | 113 | } else { |
| ... | ... | @@ -119,13 +115,13 @@ pub const ChildProcess = struct { |
| 119 | 115 | } |
| 120 | 116 | } |
| 121 | 117 | |
| 122 | pub fn spawnAndWait(self: &ChildProcess) %Term { | |
| 118 | pub fn spawnAndWait(self: &ChildProcess) !Term { | |
| 123 | 119 | try self.spawn(); |
| 124 | 120 | return self.wait(); |
| 125 | 121 | } |
| 126 | 122 | |
| 127 | 123 | /// Forcibly terminates child process and then cleans up all resources. |
| 128 | pub fn kill(self: &ChildProcess) %Term { | |
| 124 | pub fn kill(self: &ChildProcess) !Term { | |
| 129 | 125 | if (is_windows) { |
| 130 | 126 | return self.killWindows(1); |
| 131 | 127 | } else { |
| ... | ... | @@ -133,7 +129,7 @@ pub const ChildProcess = struct { |
| 133 | 129 | } |
| 134 | 130 | } |
| 135 | 131 | |
| 136 | pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) %Term { | |
| 132 | pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) !Term { | |
| 137 | 133 | if (self.term) |term| { |
| 138 | 134 | self.cleanupStreams(); |
| 139 | 135 | return term; |
| ... | ... | @@ -149,7 +145,7 @@ pub const ChildProcess = struct { |
| 149 | 145 | return ??self.term; |
| 150 | 146 | } |
| 151 | 147 | |
| 152 | pub fn killPosix(self: &ChildProcess) %Term { | |
| 148 | pub fn killPosix(self: &ChildProcess) !Term { | |
| 153 | 149 | block_SIGCHLD(); |
| 154 | 150 | defer restore_SIGCHLD(); |
| 155 | 151 | |
| ... | ... | @@ -172,7 +168,7 @@ pub const ChildProcess = struct { |
| 172 | 168 | } |
| 173 | 169 | |
| 174 | 170 | /// 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 { | |
| 176 | 172 | if (is_windows) { |
| 177 | 173 | return self.waitWindows(); |
| 178 | 174 | } else { |
| ... | ... | @@ -220,7 +216,7 @@ pub const ChildProcess = struct { |
| 220 | 216 | }; |
| 221 | 217 | } |
| 222 | 218 | |
| 223 | fn waitWindows(self: &ChildProcess) %Term { | |
| 219 | fn waitWindows(self: &ChildProcess) !Term { | |
| 224 | 220 | if (self.term) |term| { |
| 225 | 221 | self.cleanupStreams(); |
| 226 | 222 | return term; |
| ... | ... | @@ -230,7 +226,7 @@ pub const ChildProcess = struct { |
| 230 | 226 | return ??self.term; |
| 231 | 227 | } |
| 232 | 228 | |
| 233 | fn waitPosix(self: &ChildProcess) %Term { | |
| 229 | fn waitPosix(self: &ChildProcess) !Term { | |
| 234 | 230 | block_SIGCHLD(); |
| 235 | 231 | defer restore_SIGCHLD(); |
| 236 | 232 | |
| ... | ... | @@ -247,7 +243,7 @@ pub const ChildProcess = struct { |
| 247 | 243 | self.allocator.destroy(self); |
| 248 | 244 | } |
| 249 | 245 | |
| 250 | fn waitUnwrappedWindows(self: &ChildProcess) %void { | |
| 246 | fn waitUnwrappedWindows(self: &ChildProcess) !void { | |
| 251 | 247 | const result = os.windowsWaitSingle(self.handle, windows.INFINITE); |
| 252 | 248 | |
| 253 | 249 | self.term = (%Term)(x: { |
| ... | ... | @@ -295,7 +291,7 @@ pub const ChildProcess = struct { |
| 295 | 291 | if (self.stderr) |*stderr| { stderr.close(); self.stderr = null; } |
| 296 | 292 | } |
| 297 | 293 | |
| 298 | fn cleanupAfterWait(self: &ChildProcess, status: i32) %Term { | |
| 294 | fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term { | |
| 299 | 295 | children_nodes.remove(&self.llnode); |
| 300 | 296 | |
| 301 | 297 | defer { |
| ... | ... | @@ -331,7 +327,7 @@ pub const ChildProcess = struct { |
| 331 | 327 | ; |
| 332 | 328 | } |
| 333 | 329 | |
| 334 | fn spawnPosix(self: &ChildProcess) %void { | |
| 330 | fn spawnPosix(self: &ChildProcess) !void { | |
| 335 | 331 | // TODO atomically set a flag saying that we already did this |
| 336 | 332 | install_SIGCHLD_handler(); |
| 337 | 333 | |
| ... | ... | @@ -440,7 +436,7 @@ pub const ChildProcess = struct { |
| 440 | 436 | if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); } |
| 441 | 437 | } |
| 442 | 438 | |
| 443 | fn spawnWindows(self: &ChildProcess) %void { | |
| 439 | fn spawnWindows(self: &ChildProcess) !void { | |
| 444 | 440 | const saAttr = windows.SECURITY_ATTRIBUTES { |
| 445 | 441 | .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES), |
| 446 | 442 | .bInheritHandle = windows.TRUE, |
| ... | ... | @@ -623,7 +619,7 @@ pub const ChildProcess = struct { |
| 623 | 619 | if (self.stdout_behavior == StdIo.Pipe) { os.close(??g_hChildStd_OUT_Wr); } |
| 624 | 620 | } |
| 625 | 621 | |
| 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 { | |
| 627 | 623 | switch (stdio) { |
| 628 | 624 | StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno), |
| 629 | 625 | StdIo.Close => os.close(std_fileno), |
| ... | ... | @@ -655,7 +651,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ? |
| 655 | 651 | |
| 656 | 652 | /// Caller must dealloc. |
| 657 | 653 | /// Guarantees a null byte at result[result.len]. |
| 658 | fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) %[]u8 { | |
| 654 | fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) ![]u8 { | |
| 659 | 655 | var buf = try Buffer.initSize(allocator, 0); |
| 660 | 656 | defer buf.deinit(); |
| 661 | 657 | |
| ... | ... | @@ -700,7 +696,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void { |
| 700 | 696 | // a namespace field lookup |
| 701 | 697 | const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; |
| 702 | 698 | |
| 703 | fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { | |
| 699 | fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void { | |
| 704 | 700 | if (windows.CreatePipe(rd, wr, sattr, 0) == 0) { |
| 705 | 701 | const err = windows.GetLastError(); |
| 706 | 702 | return switch (err) { |
| ... | ... | @@ -709,7 +705,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECUR |
| 709 | 705 | } |
| 710 | 706 | } |
| 711 | 707 | |
| 712 | fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) %void { | |
| 708 | fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) !void { | |
| 713 | 709 | if (windows.SetHandleInformation(h, mask, flags) == 0) { |
| 714 | 710 | const err = windows.GetLastError(); |
| 715 | 711 | return switch (err) { |
| ... | ... | @@ -718,7 +714,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D |
| 718 | 714 | } |
| 719 | 715 | } |
| 720 | 716 | |
| 721 | fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { | |
| 717 | fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void { | |
| 722 | 718 | var rd_h: windows.HANDLE = undefined; |
| 723 | 719 | var wr_h: windows.HANDLE = undefined; |
| 724 | 720 | try windowsMakePipe(&rd_h, &wr_h, sattr); |
| ... | ... | @@ -728,7 +724,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S |
| 728 | 724 | *wr = wr_h; |
| 729 | 725 | } |
| 730 | 726 | |
| 731 | fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { | |
| 727 | fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void { | |
| 732 | 728 | var rd_h: windows.HANDLE = undefined; |
| 733 | 729 | var wr_h: windows.HANDLE = undefined; |
| 734 | 730 | try windowsMakePipe(&rd_h, &wr_h, sattr); |
| ... | ... | @@ -738,7 +734,7 @@ fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const |
| 738 | 734 | *wr = wr_h; |
| 739 | 735 | } |
| 740 | 736 | |
| 741 | fn makePipe() %[2]i32 { | |
| 737 | fn makePipe() ![2]i32 { | |
| 742 | 738 | var fds: [2]i32 = undefined; |
| 743 | 739 | const err = posix.getErrno(posix.pipe(&fds)); |
| 744 | 740 | if (err > 0) { |
| ... | ... | @@ -764,13 +760,13 @@ fn forkChildErrReport(fd: i32, err: error) noreturn { |
| 764 | 760 | |
| 765 | 761 | const ErrInt = @IntType(false, @sizeOf(error) * 8); |
| 766 | 762 | |
| 767 | fn writeIntFd(fd: i32, value: ErrInt) %void { | |
| 763 | fn writeIntFd(fd: i32, value: ErrInt) !void { | |
| 768 | 764 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 769 | 765 | mem.writeInt(bytes[0..], value, builtin.endian); |
| 770 | 766 | os.posixWrite(fd, bytes[0..]) catch return error.SystemResources; |
| 771 | 767 | } |
| 772 | 768 | |
| 773 | fn readIntFd(fd: i32) %ErrInt { | |
| 769 | fn readIntFd(fd: i32) !ErrInt { | |
| 774 | 770 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 775 | 771 | os.posixRead(fd, bytes[0..]) catch return error.SystemResources; |
| 776 | 772 | return mem.readInt(bytes[0..], ErrInt, builtin.endian); |
std/os/get_user_id.zig+2-5| ... | ... | @@ -9,7 +9,7 @@ pub const UserInfo = struct { |
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | 11 | /// POSIX function which gets a uid from username. |
| 12 | pub fn getUserInfo(name: []const u8) %UserInfo { | |
| 12 | pub fn getUserInfo(name: []const u8) !UserInfo { | |
| 13 | 13 | return switch (builtin.os) { |
| 14 | 14 | Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name), |
| 15 | 15 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -24,13 +24,10 @@ const State = enum { |
| 24 | 24 | ReadGroupId, |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | error UserNotFound; | |
| 28 | error CorruptPasswordFile; | |
| 29 | ||
| 30 | 27 | // TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else |
| 31 | 28 | // like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`. |
| 32 | 29 | |
| 33 | pub fn posixGetUserInfo(name: []const u8) %UserInfo { | |
| 30 | pub fn posixGetUserInfo(name: []const u8) !UserInfo { | |
| 34 | 31 | var in_stream = try io.InStream.open("/etc/passwd", null); |
| 35 | 32 | defer in_stream.close(); |
| 36 | 33 |
std/os/index.zig-2| ... | ... | @@ -1470,8 +1470,6 @@ test "std.os" { |
| 1470 | 1470 | } |
| 1471 | 1471 | |
| 1472 | 1472 | |
| 1473 | error Unexpected; | |
| 1474 | ||
| 1475 | 1473 | // TODO make this a build variable that you can set |
| 1476 | 1474 | const unexpected_error_tracing = false; |
| 1477 | 1475 |
std/os/linux.zig+1-1| ... | ... | @@ -720,7 +720,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: |
| 720 | 720 | // error SystemResources; |
| 721 | 721 | // error Io; |
| 722 | 722 | // |
| 723 | // pub fn if_nametoindex(name: []u8) %u32 { | |
| 723 | // pub fn if_nametoindex(name: []u8) !u32 { | |
| 724 | 724 | // var ifr: ifreq = undefined; |
| 725 | 725 | // |
| 726 | 726 | // if (name.len >= ifr.ifr_name.len) { |
std/os/path.zig+11-18| ... | ... | @@ -32,7 +32,7 @@ pub fn isSep(byte: u8) bool { |
| 32 | 32 | |
| 33 | 33 | /// Naively combines a series of paths with the native path seperator. |
| 34 | 34 | /// Allocates memory for the result, which must be freed by the caller. |
| 35 | pub fn join(allocator: &Allocator, paths: ...) %[]u8 { | |
| 35 | pub fn join(allocator: &Allocator, paths: ...) ![]u8 { | |
| 36 | 36 | if (is_windows) { |
| 37 | 37 | return joinWindows(allocator, paths); |
| 38 | 38 | } else { |
| ... | ... | @@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) %[]u8 { |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | pub fn joinWindows(allocator: &Allocator, paths: ...) %[]u8 { | |
| 43 | pub fn joinWindows(allocator: &Allocator, paths: ...) ![]u8 { | |
| 44 | 44 | return mem.join(allocator, sep_windows, paths); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | pub fn joinPosix(allocator: &Allocator, paths: ...) %[]u8 { | |
| 47 | pub fn joinPosix(allocator: &Allocator, paths: ...) ![]u8 { | |
| 48 | 48 | return mem.join(allocator, sep_posix, paths); |
| 49 | 49 | } |
| 50 | 50 | |
| ... | ... | @@ -313,7 +313,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool { |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /// Converts the command line arguments into a slice and calls `resolveSlice`. |
| 316 | pub fn resolve(allocator: &Allocator, args: ...) %[]u8 { | |
| 316 | pub fn resolve(allocator: &Allocator, args: ...) ![]u8 { | |
| 317 | 317 | var paths: [args.len][]const u8 = undefined; |
| 318 | 318 | comptime var arg_i = 0; |
| 319 | 319 | inline while (arg_i < args.len) : (arg_i += 1) { |
| ... | ... | @@ -323,7 +323,7 @@ pub fn resolve(allocator: &Allocator, args: ...) %[]u8 { |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. |
| 326 | pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 { | |
| 326 | pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 { | |
| 327 | 327 | if (is_windows) { |
| 328 | 328 | return resolveWindows(allocator, paths); |
| 329 | 329 | } else { |
| ... | ... | @@ -337,7 +337,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 { |
| 337 | 337 | /// If all paths are relative it uses the current working directory as a starting point. |
| 338 | 338 | /// Each drive has its own current working directory. |
| 339 | 339 | /// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters. |
| 340 | pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 { | |
| 340 | pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 { | |
| 341 | 341 | if (paths.len == 0) { |
| 342 | 342 | assert(is_windows); // resolveWindows called on non windows can't use getCwd |
| 343 | 343 | return os.getCwd(allocator); |
| ... | ... | @@ -520,7 +520,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 { |
| 520 | 520 | /// It resolves "." and "..". |
| 521 | 521 | /// The result does not have a trailing path separator. |
| 522 | 522 | /// If all paths are relative it uses the current working directory as a starting point. |
| 523 | pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) %[]u8 { | |
| 523 | pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) ![]u8 { | |
| 524 | 524 | if (paths.len == 0) { |
| 525 | 525 | assert(!is_windows); // resolvePosix called on windows can't use getCwd |
| 526 | 526 | return os.getCwd(allocator); |
| ... | ... | @@ -890,7 +890,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void { |
| 890 | 890 | /// resolve to the same path (after calling `resolve` on each), a zero-length |
| 891 | 891 | /// string is returned. |
| 892 | 892 | /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. |
| 893 | pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { | |
| 893 | pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 { | |
| 894 | 894 | if (is_windows) { |
| 895 | 895 | return relativeWindows(allocator, from, to); |
| 896 | 896 | } else { |
| ... | ... | @@ -898,7 +898,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { |
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { | |
| 901 | pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 { | |
| 902 | 902 | const resolved_from = try resolveWindows(allocator, [][]const u8{from}); |
| 903 | 903 | defer allocator.free(resolved_from); |
| 904 | 904 | |
| ... | ... | @@ -971,7 +971,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) |
| 971 | 971 | return []u8{}; |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { | |
| 974 | pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 { | |
| 975 | 975 | const resolved_from = try resolvePosix(allocator, [][]const u8{from}); |
| 976 | 976 | defer allocator.free(resolved_from); |
| 977 | 977 | |
| ... | ... | @@ -1066,18 +1066,11 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1066 | 1066 | assert(mem.eql(u8, result, expected_output)); |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | error AccessDenied; | |
| 1070 | error FileNotFound; | |
| 1071 | error NotSupported; | |
| 1072 | error NotDir; | |
| 1073 | error NameTooLong; | |
| 1074 | error SymLinkLoop; | |
| 1075 | error InputOutput; | |
| 1076 | 1069 | /// Return the canonicalized absolute pathname. |
| 1077 | 1070 | /// Expands all symbolic links and resolves references to `.`, `..`, and |
| 1078 | 1071 | /// extra `/` characters in ::pathname. |
| 1079 | 1072 | /// Caller must deallocate result. |
| 1080 | pub fn real(allocator: &Allocator, pathname: []const u8) %[]u8 { | |
| 1073 | pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 { | |
| 1081 | 1074 | switch (builtin.os) { |
| 1082 | 1075 | Os.windows => { |
| 1083 | 1076 | 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; |
| 6 | 6 | const BufMap = std.BufMap; |
| 7 | 7 | const cstr = std.cstr; |
| 8 | 8 | |
| 9 | error WaitAbandoned; | |
| 10 | error WaitTimeOut; | |
| 11 | error Unexpected; | |
| 12 | ||
| 13 | pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) %void { | |
| 9 | pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) !void { | |
| 14 | 10 | const result = windows.WaitForSingleObject(handle, milliseconds); |
| 15 | 11 | return switch (result) { |
| 16 | 12 | windows.WAIT_ABANDONED => error.WaitAbandoned, |
| ... | ... | @@ -30,12 +26,7 @@ pub fn windowsClose(handle: windows.HANDLE) void { |
| 30 | 26 | assert(windows.CloseHandle(handle) != 0); |
| 31 | 27 | } |
| 32 | 28 | |
| 33 | error SystemResources; | |
| 34 | error OperationAborted; | |
| 35 | error IoPending; | |
| 36 | error BrokenPipe; | |
| 37 | ||
| 38 | pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) %void { | |
| 29 | pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) !void { | |
| 39 | 30 | if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) { |
| 40 | 31 | const err = windows.GetLastError(); |
| 41 | 32 | return switch (err) { |
| ... | ... | @@ -75,9 +66,6 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool { |
| 75 | 66 | mem.indexOf(u16, name_wide, []u16{'-','p','t','y'}) != null; |
| 76 | 67 | } |
| 77 | 68 | |
| 78 | error SharingViolation; | |
| 79 | error PipeBusy; | |
| 80 | ||
| 81 | 69 | /// `file_path` may need to be copied in memory to add a null terminating byte. In this case |
| 82 | 70 | /// a fixed size buffer of size ::max_noalloc_path_len is an attempted solution. If the fixed |
| 83 | 71 | /// 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 |
| 120 | 108 | } |
| 121 | 109 | |
| 122 | 110 | /// Caller must free result. |
| 123 | pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) %[]u8 { | |
| 111 | pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) ![]u8 { | |
| 124 | 112 | // count bytes needed |
| 125 | 113 | const bytes_needed = x: { |
| 126 | 114 | 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) |
| 151 | 139 | return result; |
| 152 | 140 | } |
| 153 | 141 | |
| 154 | error DllNotFound; | |
| 155 | pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) %windows.HMODULE { | |
| 142 | pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) !windows.HMODULE { | |
| 156 | 143 | const padded_buff = try cstr.addNullByte(allocator, dll_path); |
| 157 | 144 | defer allocator.free(padded_buff); |
| 158 | 145 | return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound; |
std/special/build_file_template.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | const mode = b.standardReleaseOptions(); |
| 5 | 5 | const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig"); |
| 6 | 6 | exe.setBuildMode(mode); |
std/special/build_runner.zig+3-5| ... | ... | @@ -8,9 +8,7 @@ const mem = std.mem; |
| 8 | 8 | const ArrayList = std.ArrayList; |
| 9 | 9 | const warn = std.debug.warn; |
| 10 | 10 | |
| 11 | error InvalidArgs; | |
| 12 | ||
| 13 | pub fn main() %void { | |
| 11 | pub fn main() !void { | |
| 14 | 12 | var arg_it = os.args(); |
| 15 | 13 | |
| 16 | 14 | // TODO use a more general purpose allocator here |
| ... | ... | @@ -125,7 +123,7 @@ pub fn main() %void { |
| 125 | 123 | }; |
| 126 | 124 | } |
| 127 | 125 | |
| 128 | fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) %void { | |
| 126 | fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) !void { | |
| 129 | 127 | // run the build script to collect the options |
| 130 | 128 | if (!already_ran_build) { |
| 131 | 129 | builder.setInstallPrefix(null); |
| ... | ... | @@ -188,7 +186,7 @@ fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutSt |
| 188 | 186 | return error.InvalidArgs; |
| 189 | 187 | } |
| 190 | 188 | |
| 191 | fn unwrapArg(arg: %[]u8) %[]u8 { | |
| 189 | fn unwrapArg(arg: %[]u8) ![]u8 { | |
| 192 | 190 | return arg catch |err| { |
| 193 | 191 | warn("Unable to parse command line: {}\n", err); |
| 194 | 192 | return err; |
std/unicode.zig+6-14| ... | ... | @@ -1,11 +1,9 @@ |
| 1 | 1 | const std = @import("./index.zig"); |
| 2 | 2 | |
| 3 | error Utf8InvalidStartByte; | |
| 4 | ||
| 5 | 3 | /// Given the first byte of a UTF-8 codepoint, |
| 6 | 4 | /// returns a number 1-4 indicating the total length of the codepoint in bytes. |
| 7 | 5 | /// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte. |
| 8 | pub fn utf8ByteSequenceLength(first_byte: u8) %u3 { | |
| 6 | pub fn utf8ByteSequenceLength(first_byte: u8) !u3 { | |
| 9 | 7 | if (first_byte < 0b10000000) return u3(1); |
| 10 | 8 | if (first_byte & 0b11100000 == 0b11000000) return u3(2); |
| 11 | 9 | if (first_byte & 0b11110000 == 0b11100000) return u3(3); |
| ... | ... | @@ -13,16 +11,11 @@ pub fn utf8ByteSequenceLength(first_byte: u8) %u3 { |
| 13 | 11 | return error.Utf8InvalidStartByte; |
| 14 | 12 | } |
| 15 | 13 | |
| 16 | error Utf8OverlongEncoding; | |
| 17 | error Utf8ExpectedContinuation; | |
| 18 | error Utf8EncodesSurrogateHalf; | |
| 19 | error Utf8CodepointTooLarge; | |
| 20 | ||
| 21 | 14 | /// Decodes the UTF-8 codepoint encoded in the given slice of bytes. |
| 22 | 15 | /// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable. |
| 23 | 16 | /// If you already know the length at comptime, you can call one of |
| 24 | 17 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. |
| 25 | pub fn utf8Decode(bytes: []const u8) %u32 { | |
| 18 | pub fn utf8Decode(bytes: []const u8) !u32 { | |
| 26 | 19 | return switch (bytes.len) { |
| 27 | 20 | 1 => u32(bytes[0]), |
| 28 | 21 | 2 => utf8Decode2(bytes), |
| ... | ... | @@ -31,7 +24,7 @@ pub fn utf8Decode(bytes: []const u8) %u32 { |
| 31 | 24 | else => unreachable, |
| 32 | 25 | }; |
| 33 | 26 | } |
| 34 | pub fn utf8Decode2(bytes: []const u8) %u32 { | |
| 27 | pub fn utf8Decode2(bytes: []const u8) !u32 { | |
| 35 | 28 | std.debug.assert(bytes.len == 2); |
| 36 | 29 | std.debug.assert(bytes[0] & 0b11100000 == 0b11000000); |
| 37 | 30 | var value: u32 = bytes[0] & 0b00011111; |
| ... | ... | @@ -44,7 +37,7 @@ pub fn utf8Decode2(bytes: []const u8) %u32 { |
| 44 | 37 | |
| 45 | 38 | return value; |
| 46 | 39 | } |
| 47 | pub fn utf8Decode3(bytes: []const u8) %u32 { | |
| 40 | pub fn utf8Decode3(bytes: []const u8) !u32 { | |
| 48 | 41 | std.debug.assert(bytes.len == 3); |
| 49 | 42 | std.debug.assert(bytes[0] & 0b11110000 == 0b11100000); |
| 50 | 43 | var value: u32 = bytes[0] & 0b00001111; |
| ... | ... | @@ -62,7 +55,7 @@ pub fn utf8Decode3(bytes: []const u8) %u32 { |
| 62 | 55 | |
| 63 | 56 | return value; |
| 64 | 57 | } |
| 65 | pub fn utf8Decode4(bytes: []const u8) %u32 { | |
| 58 | pub fn utf8Decode4(bytes: []const u8) !u32 { | |
| 66 | 59 | std.debug.assert(bytes.len == 4); |
| 67 | 60 | std.debug.assert(bytes[0] & 0b11111000 == 0b11110000); |
| 68 | 61 | var value: u32 = bytes[0] & 0b00000111; |
| ... | ... | @@ -85,7 +78,6 @@ pub fn utf8Decode4(bytes: []const u8) %u32 { |
| 85 | 78 | return value; |
| 86 | 79 | } |
| 87 | 80 | |
| 88 | error UnexpectedEof; | |
| 89 | 81 | test "valid utf8" { |
| 90 | 82 | testValid("\x00", 0x0); |
| 91 | 83 | testValid("\x20", 0x20); |
| ... | ... | @@ -161,7 +153,7 @@ fn testValid(bytes: []const u8, expected_codepoint: u32) void { |
| 161 | 153 | std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint); |
| 162 | 154 | } |
| 163 | 155 | |
| 164 | fn testDecode(bytes: []const u8) %u32 { | |
| 156 | fn testDecode(bytes: []const u8) !u32 { | |
| 165 | 157 | const length = try utf8ByteSequenceLength(bytes[0]); |
| 166 | 158 | if (bytes.len < length) return error.UnexpectedEof; |
| 167 | 159 | std.debug.assert(bytes.len == length); |
test/cases/cast.zig+6-8| ... | ... | @@ -32,7 +32,6 @@ fn funcWithConstPtrPtr(x: &const &i32) void { |
| 32 | 32 | **x += 1; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | error ItBroke; | |
| 36 | 35 | test "explicit cast from integer to error type" { |
| 37 | 36 | testCastIntToErr(error.ItBroke); |
| 38 | 37 | comptime testCastIntToErr(error.ItBroke); |
| ... | ... | @@ -110,11 +109,11 @@ test "return null from fn() %?&T" { |
| 110 | 109 | const b = returnNullLitFromMaybeTypeErrorRef(); |
| 111 | 110 | assert((try a) == null and (try b) == null); |
| 112 | 111 | } |
| 113 | fn returnNullFromMaybeTypeErrorRef() %?&A { | |
| 112 | fn returnNullFromMaybeTypeErrorRef() !?&A { | |
| 114 | 113 | const a: ?&A = null; |
| 115 | 114 | return a; |
| 116 | 115 | } |
| 117 | fn returnNullLitFromMaybeTypeErrorRef() %?&A { | |
| 116 | fn returnNullLitFromMaybeTypeErrorRef() !?&A { | |
| 118 | 117 | return null; |
| 119 | 118 | } |
| 120 | 119 | |
| ... | ... | @@ -170,7 +169,7 @@ fn testCastZeroArrayToErrSliceMut() void { |
| 170 | 169 | assert((gimmeErrOrSlice() catch unreachable).len == 0); |
| 171 | 170 | } |
| 172 | 171 | |
| 173 | fn gimmeErrOrSlice() %[]u8 { | |
| 172 | fn gimmeErrOrSlice() ![]u8 { | |
| 174 | 173 | return []u8{}; |
| 175 | 174 | } |
| 176 | 175 | |
| ... | ... | @@ -188,7 +187,7 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" { |
| 188 | 187 | assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); |
| 189 | 188 | } |
| 190 | 189 | } |
| 191 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) %[]u8 { | |
| 190 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) ![]u8 { | |
| 192 | 191 | if (a) { |
| 193 | 192 | return []u8{}; |
| 194 | 193 | } |
| ... | ... | @@ -238,14 +237,13 @@ test "peer type resolution: error and [N]T" { |
| 238 | 237 | comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | error BadValue; | |
| 242 | //fn testPeerErrorAndArray(x: u8) %[]const u8 { | |
| 240 | //fn testPeerErrorAndArray(x: u8) ![]const u8 { | |
| 243 | 241 | // return switch (x) { |
| 244 | 242 | // 0x00 => "OK", |
| 245 | 243 | // else => error.BadValue, |
| 246 | 244 | // }; |
| 247 | 245 | //} |
| 248 | fn testPeerErrorAndArray2(x: u8) %[]const u8 { | |
| 246 | fn testPeerErrorAndArray2(x: u8) ![]const u8 { | |
| 249 | 247 | return switch (x) { |
| 250 | 248 | 0x00 => "OK", |
| 251 | 249 | 0x01 => "OKK", |
test/cases/defer.zig+1-3| ... | ... | @@ -3,9 +3,7 @@ const assert = @import("std").debug.assert; |
| 3 | 3 | var result: [3]u8 = undefined; |
| 4 | 4 | var index: usize = undefined; |
| 5 | 5 | |
| 6 | error FalseNotAllowed; | |
| 7 | ||
| 8 | fn runSomeErrorDefers(x: bool) %bool { | |
| 6 | fn runSomeErrorDefers(x: bool) !bool { | |
| 9 | 7 | index = 0; |
| 10 | 8 | defer {result[index] = 'a'; index += 1;} |
| 11 | 9 | errdefer {result[index] = 'b'; index += 1;} |
test/cases/enum_with_members.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const ET = union(enum) { |
| 6 | 6 | SINT: i32, |
| 7 | 7 | UINT: u32, |
| 8 | 8 | |
| 9 | pub fn print(a: &const ET, buf: []u8) %usize { | |
| 9 | pub fn print(a: &const ET, buf: []u8) !usize { | |
| 10 | 10 | return switch (*a) { |
| 11 | 11 | ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0), |
| 12 | 12 | ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0), |
test/cases/error.zig+6-15| ... | ... | @@ -1,16 +1,16 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | pub fn foo() %i32 { | |
| 4 | pub fn foo() !i32 { | |
| 5 | 5 | const x = try bar(); |
| 6 | 6 | return x + 1; |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | pub fn bar() %i32 { | |
| 9 | pub fn bar() !i32 { | |
| 10 | 10 | return 13; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | pub fn baz() %i32 { | |
| 13 | pub fn baz() !i32 { | |
| 14 | 14 | const y = foo() catch 1234; |
| 15 | 15 | return y + 1; |
| 16 | 16 | } |
| ... | ... | @@ -19,7 +19,6 @@ test "error wrapping" { |
| 19 | 19 | assert((baz() catch unreachable) == 15); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | error ItBroke; | |
| 23 | 22 | fn gimmeItBroke() []const u8 { |
| 24 | 23 | return @errorName(error.ItBroke); |
| 25 | 24 | } |
| ... | ... | @@ -28,8 +27,6 @@ test "@errorName" { |
| 28 | 27 | assert(mem.eql(u8, @errorName(error.AnError), "AnError")); |
| 29 | 28 | assert(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName")); |
| 30 | 29 | } |
| 31 | error AnError; | |
| 32 | error ALongerErrorName; | |
| 33 | 30 | |
| 34 | 31 | |
| 35 | 32 | test "error values" { |
| ... | ... | @@ -37,16 +34,11 @@ test "error values" { |
| 37 | 34 | const b = i32(error.err2); |
| 38 | 35 | assert(a != b); |
| 39 | 36 | } |
| 40 | error err1; | |
| 41 | error err2; | |
| 42 | 37 | |
| 43 | 38 | |
| 44 | 39 | test "redefinition of error values allowed" { |
| 45 | 40 | shouldBeNotEqual(error.AnError, error.SecondError); |
| 46 | 41 | } |
| 47 | error AnError; | |
| 48 | error AnError; | |
| 49 | error SecondError; | |
| 50 | 42 | fn shouldBeNotEqual(a: error, b: error) void { |
| 51 | 43 | if (a == b) unreachable; |
| 52 | 44 | } |
| ... | ... | @@ -58,8 +50,7 @@ test "error binary operator" { |
| 58 | 50 | assert(a == 3); |
| 59 | 51 | assert(b == 10); |
| 60 | 52 | } |
| 61 | error ItBroke; | |
| 62 | fn errBinaryOperatorG(x: bool) %isize { | |
| 53 | fn errBinaryOperatorG(x: bool) !isize { | |
| 63 | 54 | return if (x) error.ItBroke else isize(10); |
| 64 | 55 | } |
| 65 | 56 | |
| ... | ... | @@ -75,11 +66,11 @@ test "error return in assignment" { |
| 75 | 66 | doErrReturnInAssignment() catch unreachable; |
| 76 | 67 | } |
| 77 | 68 | |
| 78 | fn doErrReturnInAssignment() %void { | |
| 69 | fn doErrReturnInAssignment() !void { | |
| 79 | 70 | var x : i32 = undefined; |
| 80 | 71 | x = try makeANonErr(); |
| 81 | 72 | } |
| 82 | 73 | |
| 83 | fn makeANonErr() %i32 { | |
| 74 | fn makeANonErr() !i32 { | |
| 84 | 75 | return 1; |
| 85 | 76 | } |
test/cases/ir_block_deps.zig+1-3| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | fn foo(id: u64) %i32 { | |
| 3 | fn foo(id: u64) !i32 { | |
| 4 | 4 | return switch (id) { |
| 5 | 5 | 1 => getErrInt(), |
| 6 | 6 | 2 => { |
| ... | ... | @@ -13,8 +13,6 @@ fn foo(id: u64) %i32 { |
| 13 | 13 | |
| 14 | 14 | fn getErrInt() %i32 { return 0; } |
| 15 | 15 | |
| 16 | error ItBroke; | |
| 17 | ||
| 18 | 16 | test "ir block deps" { |
| 19 | 17 | assert((foo(1) catch unreachable) == 0); |
| 20 | 18 | assert((foo(2) catch unreachable) == 0); |
test/cases/misc.zig+2-2| ... | ... | @@ -262,7 +262,7 @@ test "generic malloc free" { |
| 262 | 262 | memFree(u8, a); |
| 263 | 263 | } |
| 264 | 264 | const some_mem : [100]u8 = undefined; |
| 265 | fn memAlloc(comptime T: type, n: usize) %[]T { | |
| 265 | fn memAlloc(comptime T: type, n: usize) ![]T { | |
| 266 | 266 | return @ptrCast(&T, &some_mem[0])[0..n]; |
| 267 | 267 | } |
| 268 | 268 | fn memFree(comptime T: type, memory: []T) void { } |
| ... | ... | @@ -419,7 +419,7 @@ test "cast slice to u8 slice" { |
| 419 | 419 | test "pointer to void return type" { |
| 420 | 420 | testPointerToVoidReturnType() catch unreachable; |
| 421 | 421 | } |
| 422 | fn testPointerToVoidReturnType() %void { | |
| 422 | fn testPointerToVoidReturnType() !void { | |
| 423 | 423 | const a = testPointerToVoidReturnType2(); |
| 424 | 424 | return *a; |
| 425 | 425 | } |
test/cases/switch.zig+1-1| ... | ... | @@ -225,7 +225,7 @@ fn switchWithUnreachable(x: i32) i32 { |
| 225 | 225 | return 10; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | fn return_a_number() %i32 { | |
| 228 | fn return_a_number() !i32 { | |
| 229 | 229 | return 1; |
| 230 | 230 | } |
| 231 | 231 |
test/cases/switch_prong_err_enum.zig+2-4| ... | ... | @@ -2,19 +2,17 @@ const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | 3 | var read_count: u64 = 0; |
| 4 | 4 | |
| 5 | fn readOnce() %u64 { | |
| 5 | fn readOnce() !u64 { | |
| 6 | 6 | read_count += 1; |
| 7 | 7 | return read_count; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | error InvalidDebugInfo; | |
| 11 | ||
| 12 | 10 | const FormValue = union(enum) { |
| 13 | 11 | Address: u64, |
| 14 | 12 | Other: bool, |
| 15 | 13 | }; |
| 16 | 14 | |
| 17 | fn doThing(form_id: u64) %FormValue { | |
| 15 | fn doThing(form_id: u64) !FormValue { | |
| 18 | 16 | return switch (form_id) { |
| 19 | 17 | 17 => FormValue { .Address = try readOnce() }, |
| 20 | 18 | else => error.InvalidDebugInfo, |
test/cases/switch_prong_implicit_cast.zig+1-3| ... | ... | @@ -5,9 +5,7 @@ const FormValue = union(enum) { |
| 5 | 5 | Two: bool, |
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | error Whatever; | |
| 9 | ||
| 10 | fn foo(id: u64) %FormValue { | |
| 8 | fn foo(id: u64) !FormValue { | |
| 11 | 9 | return switch (id) { |
| 12 | 10 | 2 => FormValue { .Two = true }, |
| 13 | 11 | 1 => FormValue { .One = {} }, |
test/cases/try.zig+2-5| ... | ... | @@ -17,10 +17,7 @@ fn tryOnErrorUnionImpl() void { |
| 17 | 17 | assert(x == 11); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | error ItBroke; | |
| 21 | error NoMem; | |
| 22 | error CrappedOut; | |
| 23 | fn returnsTen() %i32 { | |
| 20 | fn returnsTen() !i32 { | |
| 24 | 21 | return 10; |
| 25 | 22 | } |
| 26 | 23 | |
| ... | ... | @@ -32,7 +29,7 @@ test "try without vars" { |
| 32 | 29 | assert(result2 == 1); |
| 33 | 30 | } |
| 34 | 31 | |
| 35 | fn failIfTrue(ok: bool) %void { | |
| 32 | fn failIfTrue(ok: bool) !void { | |
| 36 | 33 | if (ok) { |
| 37 | 34 | return error.ItBroke; |
| 38 | 35 | } else { |
test/cases/while.zig+2-4| ... | ... | @@ -50,7 +50,7 @@ fn runContinueAndBreakTest() void { |
| 50 | 50 | test "return with implicit cast from while loop" { |
| 51 | 51 | returnWithImplicitCastFromWhileLoopTest() catch unreachable; |
| 52 | 52 | } |
| 53 | fn returnWithImplicitCastFromWhileLoopTest() %void { | |
| 53 | fn returnWithImplicitCastFromWhileLoopTest() !void { | |
| 54 | 54 | while (true) { |
| 55 | 55 | return; |
| 56 | 56 | } |
| ... | ... | @@ -116,8 +116,7 @@ test "while with error union condition" { |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | var numbers_left: i32 = undefined; |
| 119 | error OutOfNumbers; | |
| 120 | fn getNumberOrErr() %i32 { | |
| 119 | fn getNumberOrErr() !i32 { | |
| 121 | 120 | return if (numbers_left == 0) |
| 122 | 121 | error.OutOfNumbers |
| 123 | 122 | else x: { |
| ... | ... | @@ -205,7 +204,6 @@ fn testContinueOuter() void { |
| 205 | 204 | |
| 206 | 205 | fn returnNull() ?i32 { return null; } |
| 207 | 206 | fn returnMaybe(x: i32) ?i32 { return x; } |
| 208 | error YouWantedAnError; | |
| 209 | 207 | fn returnError() %i32 { return error.YouWantedAnError; } |
| 210 | 208 | fn returnSuccess(x: i32) %i32 { return x; } |
| 211 | 209 | fn returnFalse() bool { return false; } |
test/compare_output.zig+16-16| ... | ... | @@ -15,7 +15,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 15 | 15 | \\use @import("std").io; |
| 16 | 16 | \\use @import("foo.zig"); |
| 17 | 17 | \\ |
| 18 | \\pub fn main() %void { | |
| 18 | \\pub fn main() !void { | |
| 19 | 19 | \\ privateFunction(); |
| 20 | 20 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); |
| 21 | 21 | \\ stdout.print("OK 2\n") catch unreachable; |
| ... | ... | @@ -49,7 +49,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 49 | 49 | \\use @import("foo.zig"); |
| 50 | 50 | \\use @import("bar.zig"); |
| 51 | 51 | \\ |
| 52 | \\pub fn main() %void { | |
| 52 | \\pub fn main() !void { | |
| 53 | 53 | \\ foo_function(); |
| 54 | 54 | \\ bar_function(); |
| 55 | 55 | \\} |
| ... | ... | @@ -89,7 +89,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 89 | 89 | var tc = cases.create("two files use import each other", |
| 90 | 90 | \\use @import("a.zig"); |
| 91 | 91 | \\ |
| 92 | \\pub fn main() %void { | |
| 92 | \\pub fn main() !void { | |
| 93 | 93 | \\ ok(); |
| 94 | 94 | \\} |
| 95 | 95 | , "OK\n"); |
| ... | ... | @@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 118 | 118 | cases.add("hello world without libc", |
| 119 | 119 | \\const io = @import("std").io; |
| 120 | 120 | \\ |
| 121 | \\pub fn main() %void { | |
| 121 | \\pub fn main() !void { | |
| 122 | 122 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 123 | 123 | \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; |
| 124 | 124 | \\} |
| ... | ... | @@ -268,7 +268,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 268 | 268 | \\const z = io.stdin_fileno; |
| 269 | 269 | \\const x : @typeOf(y) = 1234; |
| 270 | 270 | \\const y : u16 = 5678; |
| 271 | \\pub fn main() %void { | |
| 271 | \\pub fn main() !void { | |
| 272 | 272 | \\ var x_local : i32 = print_ok(x); |
| 273 | 273 | \\} |
| 274 | 274 | \\fn print_ok(val: @typeOf(x)) @typeOf(foo) { |
| ... | ... | @@ -351,7 +351,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 351 | 351 | \\ fn method(b: &const Bar) bool { return true; } |
| 352 | 352 | \\}; |
| 353 | 353 | \\ |
| 354 | \\pub fn main() %void { | |
| 354 | \\pub fn main() !void { | |
| 355 | 355 | \\ const bar = Bar {.field2 = 13,}; |
| 356 | 356 | \\ const foo = Foo {.field1 = bar,}; |
| 357 | 357 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| ... | ... | @@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 367 | 367 | |
| 368 | 368 | cases.add("defer with only fallthrough", |
| 369 | 369 | \\const io = @import("std").io; |
| 370 | \\pub fn main() %void { | |
| 370 | \\pub fn main() !void { | |
| 371 | 371 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 372 | 372 | \\ stdout.print("before\n") catch unreachable; |
| 373 | 373 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | ... | @@ -380,7 +380,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 380 | 380 | cases.add("defer with return", |
| 381 | 381 | \\const io = @import("std").io; |
| 382 | 382 | \\const os = @import("std").os; |
| 383 | \\pub fn main() %void { | |
| 383 | \\pub fn main() !void { | |
| 384 | 384 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 385 | 385 | \\ stdout.print("before\n") catch unreachable; |
| 386 | 386 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | ... | @@ -394,10 +394,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 394 | 394 | |
| 395 | 395 | cases.add("errdefer and it fails", |
| 396 | 396 | \\const io = @import("std").io; |
| 397 | \\pub fn main() %void { | |
| 397 | \\pub fn main() !void { | |
| 398 | 398 | \\ do_test() catch return; |
| 399 | 399 | \\} |
| 400 | \\fn do_test() %void { | |
| 400 | \\fn do_test() !void { | |
| 401 | 401 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 402 | 402 | \\ stdout.print("before\n") catch unreachable; |
| 403 | 403 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | ... | @@ -407,17 +407,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 407 | 407 | \\ stdout.print("after\n") catch unreachable; |
| 408 | 408 | \\} |
| 409 | 409 | \\error IToldYouItWouldFail; |
| 410 | \\fn its_gonna_fail() %void { | |
| 410 | \\fn its_gonna_fail() !void { | |
| 411 | 411 | \\ return error.IToldYouItWouldFail; |
| 412 | 412 | \\} |
| 413 | 413 | , "before\ndeferErr\ndefer1\n"); |
| 414 | 414 | |
| 415 | 415 | cases.add("errdefer and it passes", |
| 416 | 416 | \\const io = @import("std").io; |
| 417 | \\pub fn main() %void { | |
| 417 | \\pub fn main() !void { | |
| 418 | 418 | \\ do_test() catch return; |
| 419 | 419 | \\} |
| 420 | \\fn do_test() %void { | |
| 420 | \\fn do_test() !void { | |
| 421 | 421 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 422 | 422 | \\ stdout.print("before\n") catch unreachable; |
| 423 | 423 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | ... | @@ -434,7 +434,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 434 | 434 | \\const foo_txt = @embedFile("foo.txt"); |
| 435 | 435 | \\const io = @import("std").io; |
| 436 | 436 | \\ |
| 437 | \\pub fn main() %void { | |
| 437 | \\pub fn main() !void { | |
| 438 | 438 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 439 | 439 | \\ stdout.print(foo_txt) catch unreachable; |
| 440 | 440 | \\} |
| ... | ... | @@ -452,7 +452,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 452 | 452 | \\const os = std.os; |
| 453 | 453 | \\const allocator = std.debug.global_allocator; |
| 454 | 454 | \\ |
| 455 | \\pub fn main() %void { | |
| 455 | \\pub fn main() !void { | |
| 456 | 456 | \\ var args_it = os.args(); |
| 457 | 457 | \\ var stdout_file = try io.getStdOut(); |
| 458 | 458 | \\ var stdout_adapter = io.FileOutStream.init(&stdout_file); |
| ... | ... | @@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 493 | 493 | \\const os = std.os; |
| 494 | 494 | \\const allocator = std.debug.global_allocator; |
| 495 | 495 | \\ |
| 496 | \\pub fn main() %void { | |
| 496 | \\pub fn main() !void { | |
| 497 | 497 | \\ var args_it = os.args(); |
| 498 | 498 | \\ var stdout_file = try io.getStdOut(); |
| 499 | 499 | \\ 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 { |
| 1383 | 1383 | , ".tmp_source.zig:6:13: error: cannot assign to constant"); |
| 1384 | 1384 | |
| 1385 | 1385 | cases.add("return from defer expression", |
| 1386 | \\pub fn testTrickyDefer() %void { | |
| 1386 | \\pub fn testTrickyDefer() !void { | |
| 1387 | 1387 | \\ defer canFail() catch {}; |
| 1388 | 1388 | \\ |
| 1389 | 1389 | \\ defer try canFail(); |
| ... | ... | @@ -1970,7 +1970,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 1970 | 1970 | \\fn foo1(args: ...) void {} |
| 1971 | 1971 | \\fn foo2(args: ...) void {} |
| 1972 | 1972 | \\ |
| 1973 | \\pub fn main() %void { | |
| 1973 | \\pub fn main() !void { | |
| 1974 | 1974 | \\ foos[0](); |
| 1975 | 1975 | \\} |
| 1976 | 1976 | , |
| ... | ... | @@ -1982,7 +1982,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 1982 | 1982 | \\fn foo1(arg: var) void {} |
| 1983 | 1983 | \\fn foo2(arg: var) void {} |
| 1984 | 1984 | \\ |
| 1985 | \\pub fn main() %void { | |
| 1985 | \\pub fn main() !void { | |
| 1986 | 1986 | \\ foos[0](true); |
| 1987 | 1987 | \\} |
| 1988 | 1988 | , |
test/runtime_safety.zig+21-21| ... | ... | @@ -5,7 +5,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 5 | 5 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 6 | 6 | \\ @import("std").os.exit(126); |
| 7 | 7 | \\} |
| 8 | \\pub fn main() %void { | |
| 8 | \\pub fn main() !void { | |
| 9 | 9 | \\ @panic("oh no"); |
| 10 | 10 | \\} |
| 11 | 11 | ); |
| ... | ... | @@ -14,7 +14,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 14 | 14 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 15 | 15 | \\ @import("std").os.exit(126); |
| 16 | 16 | \\} |
| 17 | \\pub fn main() %void { | |
| 17 | \\pub fn main() !void { | |
| 18 | 18 | \\ const a = []i32{1, 2, 3, 4}; |
| 19 | 19 | \\ baz(bar(a)); |
| 20 | 20 | \\} |
| ... | ... | @@ -29,7 +29,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 29 | 29 | \\ @import("std").os.exit(126); |
| 30 | 30 | \\} |
| 31 | 31 | \\error Whatever; |
| 32 | \\pub fn main() %void { | |
| 32 | \\pub fn main() !void { | |
| 33 | 33 | \\ const x = add(65530, 10); |
| 34 | 34 | \\ if (x == 0) return error.Whatever; |
| 35 | 35 | \\} |
| ... | ... | @@ -43,7 +43,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 43 | 43 | \\ @import("std").os.exit(126); |
| 44 | 44 | \\} |
| 45 | 45 | \\error Whatever; |
| 46 | \\pub fn main() %void { | |
| 46 | \\pub fn main() !void { | |
| 47 | 47 | \\ const x = sub(10, 20); |
| 48 | 48 | \\ if (x == 0) return error.Whatever; |
| 49 | 49 | \\} |
| ... | ... | @@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 57 | 57 | \\ @import("std").os.exit(126); |
| 58 | 58 | \\} |
| 59 | 59 | \\error Whatever; |
| 60 | \\pub fn main() %void { | |
| 60 | \\pub fn main() !void { | |
| 61 | 61 | \\ const x = mul(300, 6000); |
| 62 | 62 | \\ if (x == 0) return error.Whatever; |
| 63 | 63 | \\} |
| ... | ... | @@ -71,7 +71,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 71 | 71 | \\ @import("std").os.exit(126); |
| 72 | 72 | \\} |
| 73 | 73 | \\error Whatever; |
| 74 | \\pub fn main() %void { | |
| 74 | \\pub fn main() !void { | |
| 75 | 75 | \\ const x = neg(-32768); |
| 76 | 76 | \\ if (x == 32767) return error.Whatever; |
| 77 | 77 | \\} |
| ... | ... | @@ -85,7 +85,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 85 | 85 | \\ @import("std").os.exit(126); |
| 86 | 86 | \\} |
| 87 | 87 | \\error Whatever; |
| 88 | \\pub fn main() %void { | |
| 88 | \\pub fn main() !void { | |
| 89 | 89 | \\ const x = div(-32768, -1); |
| 90 | 90 | \\ if (x == 32767) return error.Whatever; |
| 91 | 91 | \\} |
| ... | ... | @@ -99,7 +99,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 99 | 99 | \\ @import("std").os.exit(126); |
| 100 | 100 | \\} |
| 101 | 101 | \\error Whatever; |
| 102 | \\pub fn main() %void { | |
| 102 | \\pub fn main() !void { | |
| 103 | 103 | \\ const x = shl(-16385, 1); |
| 104 | 104 | \\ if (x == 0) return error.Whatever; |
| 105 | 105 | \\} |
| ... | ... | @@ -113,7 +113,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 113 | 113 | \\ @import("std").os.exit(126); |
| 114 | 114 | \\} |
| 115 | 115 | \\error Whatever; |
| 116 | \\pub fn main() %void { | |
| 116 | \\pub fn main() !void { | |
| 117 | 117 | \\ const x = shl(0b0010111111111111, 3); |
| 118 | 118 | \\ if (x == 0) return error.Whatever; |
| 119 | 119 | \\} |
| ... | ... | @@ -127,7 +127,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 127 | 127 | \\ @import("std").os.exit(126); |
| 128 | 128 | \\} |
| 129 | 129 | \\error Whatever; |
| 130 | \\pub fn main() %void { | |
| 130 | \\pub fn main() !void { | |
| 131 | 131 | \\ const x = shr(-16385, 1); |
| 132 | 132 | \\ if (x == 0) return error.Whatever; |
| 133 | 133 | \\} |
| ... | ... | @@ -141,7 +141,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 141 | 141 | \\ @import("std").os.exit(126); |
| 142 | 142 | \\} |
| 143 | 143 | \\error Whatever; |
| 144 | \\pub fn main() %void { | |
| 144 | \\pub fn main() !void { | |
| 145 | 145 | \\ const x = shr(0b0010111111111111, 3); |
| 146 | 146 | \\ if (x == 0) return error.Whatever; |
| 147 | 147 | \\} |
| ... | ... | @@ -155,7 +155,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 155 | 155 | \\ @import("std").os.exit(126); |
| 156 | 156 | \\} |
| 157 | 157 | \\error Whatever; |
| 158 | \\pub fn main() %void { | |
| 158 | \\pub fn main() !void { | |
| 159 | 159 | \\ const x = div0(999, 0); |
| 160 | 160 | \\} |
| 161 | 161 | \\fn div0(a: i32, b: i32) i32 { |
| ... | ... | @@ -168,7 +168,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 168 | 168 | \\ @import("std").os.exit(126); |
| 169 | 169 | \\} |
| 170 | 170 | \\error Whatever; |
| 171 | \\pub fn main() %void { | |
| 171 | \\pub fn main() !void { | |
| 172 | 172 | \\ const x = divExact(10, 3); |
| 173 | 173 | \\ if (x == 0) return error.Whatever; |
| 174 | 174 | \\} |
| ... | ... | @@ -182,7 +182,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 182 | 182 | \\ @import("std").os.exit(126); |
| 183 | 183 | \\} |
| 184 | 184 | \\error Whatever; |
| 185 | \\pub fn main() %void { | |
| 185 | \\pub fn main() !void { | |
| 186 | 186 | \\ const x = widenSlice([]u8{1, 2, 3, 4, 5}); |
| 187 | 187 | \\ if (x.len == 0) return error.Whatever; |
| 188 | 188 | \\} |
| ... | ... | @@ -196,7 +196,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 196 | 196 | \\ @import("std").os.exit(126); |
| 197 | 197 | \\} |
| 198 | 198 | \\error Whatever; |
| 199 | \\pub fn main() %void { | |
| 199 | \\pub fn main() !void { | |
| 200 | 200 | \\ const x = shorten_cast(200); |
| 201 | 201 | \\ if (x == 0) return error.Whatever; |
| 202 | 202 | \\} |
| ... | ... | @@ -210,7 +210,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 210 | 210 | \\ @import("std").os.exit(126); |
| 211 | 211 | \\} |
| 212 | 212 | \\error Whatever; |
| 213 | \\pub fn main() %void { | |
| 213 | \\pub fn main() !void { | |
| 214 | 214 | \\ const x = unsigned_cast(-10); |
| 215 | 215 | \\ if (x == 0) return error.Whatever; |
| 216 | 216 | \\} |
| ... | ... | @@ -227,10 +227,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 227 | 227 | \\ @import("std").os.exit(0); // test failed |
| 228 | 228 | \\} |
| 229 | 229 | \\error Whatever; |
| 230 | \\pub fn main() %void { | |
| 230 | \\pub fn main() !void { | |
| 231 | 231 | \\ bar() catch unreachable; |
| 232 | 232 | \\} |
| 233 | \\fn bar() %void { | |
| 233 | \\fn bar() !void { | |
| 234 | 234 | \\ return error.Whatever; |
| 235 | 235 | \\} |
| 236 | 236 | ); |
| ... | ... | @@ -239,7 +239,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 239 | 239 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 240 | 240 | \\ @import("std").os.exit(126); |
| 241 | 241 | \\} |
| 242 | \\pub fn main() %void { | |
| 242 | \\pub fn main() !void { | |
| 243 | 243 | \\ _ = bar(9999); |
| 244 | 244 | \\} |
| 245 | 245 | \\fn bar(x: u32) error { |
| ... | ... | @@ -252,7 +252,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 252 | 252 | \\ @import("std").os.exit(126); |
| 253 | 253 | \\} |
| 254 | 254 | \\error Wrong; |
| 255 | \\pub fn main() %void { | |
| 255 | \\pub fn main() !void { | |
| 256 | 256 | \\ var array align(4) = []u32{0x11111111, 0x11111111}; |
| 257 | 257 | \\ const bytes = ([]u8)(array[0..]); |
| 258 | 258 | \\ if (foo(bytes) != 0x11111111) return error.Wrong; |
| ... | ... | @@ -274,7 +274,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 274 | 274 | \\ int: u32, |
| 275 | 275 | \\}; |
| 276 | 276 | \\ |
| 277 | \\pub fn main() %void { | |
| 277 | \\pub fn main() !void { | |
| 278 | 278 | \\ var f = Foo { .int = 42 }; |
| 279 | 279 | \\ bar(&f); |
| 280 | 280 | \\} |
test/standalone/brace_expansion/build.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | const main = b.addTest("main.zig"); |
| 5 | 5 | main.setBuildMode(b.standardReleaseOptions()); |
| 6 | 6 |
test/standalone/brace_expansion/main.zig+5-8| ... | ... | @@ -6,9 +6,6 @@ const assert = debug.assert; |
| 6 | 6 | const Buffer = std.Buffer; |
| 7 | 7 | const ArrayList = std.ArrayList; |
| 8 | 8 | |
| 9 | error InvalidInput; | |
| 10 | error OutOfMem; | |
| 11 | ||
| 12 | 9 | const Token = union(enum) { |
| 13 | 10 | Word: []const u8, |
| 14 | 11 | OpenBrace, |
| ... | ... | @@ -19,7 +16,7 @@ const Token = union(enum) { |
| 19 | 16 | |
| 20 | 17 | var global_allocator: &mem.Allocator = undefined; |
| 21 | 18 | |
| 22 | fn tokenize(input:[] const u8) %ArrayList(Token) { | |
| 19 | fn tokenize(input:[] const u8) !ArrayList(Token) { | |
| 23 | 20 | const State = enum { |
| 24 | 21 | Start, |
| 25 | 22 | Word, |
| ... | ... | @@ -71,7 +68,7 @@ const Node = union(enum) { |
| 71 | 68 | Combine: []Node, |
| 72 | 69 | }; |
| 73 | 70 | |
| 74 | fn parse(tokens: &const ArrayList(Token), token_index: &usize) %Node { | |
| 71 | fn parse(tokens: &const ArrayList(Token), token_index: &usize) !Node { | |
| 75 | 72 | const first_token = tokens.items[*token_index]; |
| 76 | 73 | *token_index += 1; |
| 77 | 74 | |
| ... | ... | @@ -107,7 +104,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) %Node { |
| 107 | 104 | } |
| 108 | 105 | } |
| 109 | 106 | |
| 110 | fn expandString(input: []const u8, output: &Buffer) %void { | |
| 107 | fn expandString(input: []const u8, output: &Buffer) !void { | |
| 111 | 108 | const tokens = try tokenize(input); |
| 112 | 109 | if (tokens.len == 1) { |
| 113 | 110 | return output.resize(0); |
| ... | ... | @@ -135,7 +132,7 @@ fn expandString(input: []const u8, output: &Buffer) %void { |
| 135 | 132 | } |
| 136 | 133 | } |
| 137 | 134 | |
| 138 | fn expandNode(node: &const Node, output: &ArrayList(Buffer)) %void { | |
| 135 | fn expandNode(node: &const Node, output: &ArrayList(Buffer)) !void { | |
| 139 | 136 | assert(output.len == 0); |
| 140 | 137 | switch (*node) { |
| 141 | 138 | Node.Scalar => |scalar| { |
| ... | ... | @@ -172,7 +169,7 @@ fn expandNode(node: &const Node, output: &ArrayList(Buffer)) %void { |
| 172 | 169 | } |
| 173 | 170 | } |
| 174 | 171 | |
| 175 | pub fn main() %void { | |
| 172 | pub fn main() !void { | |
| 176 | 173 | var stdin_file = try io.getStdIn(); |
| 177 | 174 | var stdout_file = try io.getStdOut(); |
| 178 | 175 |
test/standalone/issue_339/build.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | const obj = b.addObject("test", "test.zig"); |
| 5 | 5 | |
| 6 | 6 | const test_step = b.step("test", "Test the program"); |
test/standalone/pkg_import/build.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | const exe = b.addExecutable("test", "test.zig"); |
| 5 | 5 | exe.addPackagePath("my_pkg", "pkg.zig"); |
| 6 | 6 |
test/standalone/pkg_import/test.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const my_pkg = @import("my_pkg"); |
| 2 | 2 | const assert = @import("std").debug.assert; |
| 3 | 3 | |
| 4 | pub fn main() %void { | |
| 4 | pub fn main() !void { | |
| 5 | 5 | assert(my_pkg.add(10, 20) == 30); |
| 6 | 6 | } |
test/standalone/use_alias/build.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | |
| 3 | pub fn build(b: &Builder) %void { | |
| 3 | pub fn build(b: &Builder) !void { | |
| 4 | 4 | b.addCIncludePath("."); |
| 5 | 5 | |
| 6 | 6 | const main = b.addTest("main.zig"); |
test/tests.zig+5-8| ... | ... | @@ -45,9 +45,6 @@ const test_targets = []TestTarget { |
| 45 | 45 | }, |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | error TestFailed; | |
| 49 | error CompilationIncorrectlySucceeded; | |
| 50 | ||
| 51 | 48 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB |
| 52 | 49 | |
| 53 | 50 | pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| ... | ... | @@ -248,7 +245,7 @@ pub const CompareOutputContext = struct { |
| 248 | 245 | return ptr; |
| 249 | 246 | } |
| 250 | 247 | |
| 251 | fn make(step: &build.Step) %void { | |
| 248 | fn make(step: &build.Step) !void { | |
| 252 | 249 | const self = @fieldParentPtr(RunCompareOutputStep, "step", step); |
| 253 | 250 | const b = self.context.b; |
| 254 | 251 | |
| ... | ... | @@ -337,7 +334,7 @@ pub const CompareOutputContext = struct { |
| 337 | 334 | return ptr; |
| 338 | 335 | } |
| 339 | 336 | |
| 340 | fn make(step: &build.Step) %void { | |
| 337 | fn make(step: &build.Step) !void { | |
| 341 | 338 | const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step); |
| 342 | 339 | const b = self.context.b; |
| 343 | 340 | |
| ... | ... | @@ -563,7 +560,7 @@ pub const CompileErrorContext = struct { |
| 563 | 560 | return ptr; |
| 564 | 561 | } |
| 565 | 562 | |
| 566 | fn make(step: &build.Step) %void { | |
| 563 | fn make(step: &build.Step) !void { | |
| 567 | 564 | const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); |
| 568 | 565 | const b = self.context.b; |
| 569 | 566 | |
| ... | ... | @@ -847,7 +844,7 @@ pub const TranslateCContext = struct { |
| 847 | 844 | return ptr; |
| 848 | 845 | } |
| 849 | 846 | |
| 850 | fn make(step: &build.Step) %void { | |
| 847 | fn make(step: &build.Step) !void { | |
| 851 | 848 | const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step); |
| 852 | 849 | const b = self.context.b; |
| 853 | 850 | |
| ... | ... | @@ -1045,7 +1042,7 @@ pub const GenHContext = struct { |
| 1045 | 1042 | return ptr; |
| 1046 | 1043 | } |
| 1047 | 1044 | |
| 1048 | fn make(step: &build.Step) %void { | |
| 1045 | fn make(step: &build.Step) !void { | |
| 1049 | 1046 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); |
| 1050 | 1047 | const b = self.context.b; |
| 1051 | 1048 |