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