From cf39819478e237255109d0343e642db70e88071b Mon Sep 17 00:00:00 2001
From: Andrew Kelley
The other component to error handling is defer statements.
- In addition to an unconditional defer, Zig has %defer,
+ In addition to an unconditional defer, Zig has errdefer,
which evaluates the deferred expression on block exit path if and only if
the function returned with an error from the block.
For a C-ABI-compatible enum, use extern enum:
TODO packed enum
@@ -2191,7 +2191,7 @@ test "while else" { assert(!rangeHasNumber(0, 10, 15)); } -fn rangeHasNumber(begin: usize, end: usize, number: usize) -> bool { +fn rangeHasNumber(begin: usize, end: usize, number: usize) bool { var i = begin; // While loops are expressions. The result of the expression is the // result of the else clause of a while loop, which is executed when @@ -2242,14 +2242,14 @@ test "while null capture" { } var numbers_left: u32 = undefined; -fn eventuallyNullSequence() -> ?u32 { +fn eventuallyNullSequence() ?u32 { return if (numbers_left == 0) null else blk: { numbers_left -= 1; break :blk numbers_left; }; } error ReachedZero; -fn eventuallyErrorSequence() -> %u32 { +fn eventuallyErrorSequence() %u32 { return if (numbers_left == 0) error.ReachedZero else blk: { numbers_left -= 1; break :blk numbers_left; @@ -2274,7 +2274,7 @@ test "inline while loop" { assert(sum == 9); } -fn typeNameLength(comptime T: type) -> usize { +fn typeNameLength(comptime T: type) usize { return @typeName(T).len; } {#code_end#} @@ -2367,7 +2367,7 @@ test "inline for loop" { assert(sum == 9); } -fn typeNameLength(comptime T: type) -> usize { +fn typeNameLength(comptime T: type) usize { return @typeName(T).len; } {#code_end#} @@ -2493,7 +2493,7 @@ const assert = std.debug.assert; const warn = std.debug.warn; // defer will execute an expression at the end of the current scope. -fn deferExample() -> usize { +fn deferExample() usize { var a: usize = 1; { @@ -2512,7 +2512,7 @@ test "defer basics" { // If multiple defer statements are specified, they will be executed in // the reverse order they were run. -fn deferUnwindExample() { +fn deferUnwindExample() void { warn("\n"); defer { @@ -2539,7 +2539,7 @@ test "defer unwinding" { // This is especially useful in allowing a function to clean up properly // on error, and replaces goto error handling tactics as seen in c. error DeferError; -fn deferErrorExample(is_error: bool) -> %void { +fn deferErrorExample(is_error: bool) %void { warn("\nstart of function\n"); // This will always be executed on exit @@ -2587,7 +2587,7 @@ test "basic math" { {#code_end#}In fact, this is how assert is implemented:
{#code_begin|test_err#} -fn assert(ok: bool) { +fn assert(ok: bool) void { if (!ok) unreachable; // assertion failure } @@ -2630,7 +2630,7 @@ test "type of unreachable" { thenoreturn type is compatible with every other type. Consider:
{#code_begin|test#}
-fn foo(condition: bool, b: u32) {
+fn foo(condition: bool, b: u32) void {
const a = if (condition) b else return;
@panic("do something with a");
}
@@ -2641,14 +2641,14 @@ test "noreturn" {
Another use case for noreturn is the exit function:
@@ -2728,7 +2728,7 @@ const Foo = struct { x: i32, }; -fn bar(foo: Foo) {} +fn bar(foo: Foo) void {} test "pass aggregate type by value to function" { bar(Foo {.x = 12,}); @@ -2743,7 +2743,7 @@ const Foo = struct { x: i32, }; -fn bar(foo: &const Foo) {} +fn bar(foo: &const Foo) void {} test "implicitly cast to const pointer" { bar(Foo {.x = 12,}); @@ -2798,7 +2798,7 @@ error UnexpectedToken; error InvalidChar; error Overflow; -pub fn parseU64(buf: []const u8, radix: u8) -> %u64 { +pub fn parseU64(buf: []const u8, radix: u8) %u64 { var x: u64 = 0; for (buf) |c| { @@ -2822,7 +2822,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -> %u64 { return x; } -fn charToDigit(c: u8) -> u8 { +fn charToDigit(c: u8) u8 { return switch (c) { '0' ... '9' => c - '0', 'A' ... 'Z' => c - 'A' + 10, @@ -2857,7 +2857,7 @@ test "parse u64" {
If you want to provide a default value, you can use the catch binary operator:
Let's say you wanted to return the error if you got one, otherwise continue with the function logic:
{#code_begin|syntax#} -fn doAThing(str: []u8) -> %void { +fn doAThing(str: []u8) %void { const number = parseU64(str, 10) catch |err| return err; // ... } @@ -2879,7 +2879,7 @@ fn doAThing(str: []u8) -> %void { There is a shortcut for this. Thetry expression:
{#code_begin|syntax#}
-fn doAThing(str: []u8) -> %void {
+fn doAThing(str: []u8) %void {
const number = try parseU64(str, 10);
// ...
}
@@ -2907,7 +2907,7 @@ fn doAThing(str: []u8) -> %void {
the if and switch expression:
{#code_begin|syntax#}
-fn doAThing(str: []u8) {
+fn doAThing(str: []u8) void {
if (parseU64(str, 10)) |number| {
doSomethingWithNumber(number);
} else |err| switch (err) {
@@ -2929,7 +2929,7 @@ fn doAThing(str: []u8) {
Example:
{#code_begin|syntax#}
-fn createFoo(param: i32) -> %Foo {
+fn createFoo(param: i32) %Foo {
const foo = try tryToAllocateFoo();
// now we have allocated foo. we need to free it if the function fails.
// but we want to return it if the function succeeds.
@@ -3018,9 +3018,9 @@ struct Foo *do_a_thing(void) {
Zig code
{#code_begin|syntax#} // malloc prototype included for reference -extern fn malloc(size: size_t) -> ?&u8; +extern fn malloc(size: size_t) ?&u8; -fn doAThing() -> ?&Foo { +fn doAThing() ?&Foo { const ptr = malloc(1234) ?? return null; // ... } @@ -3047,7 +3047,7 @@ fn doAThing() -> ?&Foo { In Zig you can accomplish the same thing: {#code_begin|syntax#} -fn doAThing(nullable_foo: ?&Foo) { +fn doAThing(nullable_foo: ?&Foo) void { // do some stuff if (nullable_foo) |foo| { @@ -3104,13 +3104,13 @@ fn doAThing(nullable_foo: ?&Foo) { Compile-time parameters is how Zig implements generics. It is compile-time duck typing. {#code_begin|syntax#} -fn max(comptime T: type, a: T, b: T) -> T { +fn max(comptime T: type, a: T, b: T) T { return if (a > b) a else b; } -fn gimmeTheBiggerFloat(a: f32, b: f32) -> f32 { +fn gimmeTheBiggerFloat(a: f32, b: f32) f32 { return max(f32, a, b); } -fn gimmeTheBiggerInteger(a: u64, b: u64) -> u64 { +fn gimmeTheBiggerInteger(a: u64, b: u64) u64 { return max(u64, a, b); } {#code_end#} @@ -3132,13 +3132,13 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) -> u64 { For example, if we were to introduce another function to the above snippet: {#code_begin|test_err|unable to evaluate constant expression#} -fn max(comptime T: type, a: T, b: T) -> T { +fn max(comptime T: type, a: T, b: T) T { return if (a > b) a else b; } test "try to pass a runtime type" { foo(false); } -fn foo(condition: bool) { +fn foo(condition: bool) void { const result = max( if (condition) f32 else u64, 1234, @@ -3157,7 +3157,7 @@ fn foo(condition: bool) { For example: {#code_begin|test_err|operator not allowed for type 'bool'#} -fn max(comptime T: type, a: T, b: T) -> T { +fn max(comptime T: type, a: T, b: T) T { return if (a > b) a else b; } test "try to compare bools" { @@ -3170,7 +3170,7 @@ test "try to compare bools" { if we wanted to: {#code_begin|test#} -fn max(comptime T: type, a: T, b: T) -> T { +fn max(comptime T: type, a: T, b: T) T { if (T == bool) { return a or b; } else if (a > b) { @@ -3193,7 +3193,7 @@ test "try to compare bools" { this: {#code_begin|syntax#} -fn max(a: bool, b: bool) -> bool { +fn max(a: bool, b: bool) bool { return a or b; } {#code_end#} @@ -3224,7 +3224,7 @@ const assert = @import("std").debug.assert; const CmdFn = struct { name: []const u8, - func: fn(i32) -> i32, + func: fn(i32) i32, }; const cmd_fns = []CmdFn{ @@ -3232,11 +3232,11 @@ const cmd_fns = []CmdFn{ CmdFn {.name = "two", .func = two}, CmdFn {.name = "three", .func = three}, }; -fn one(value: i32) -> i32 { return value + 1; } -fn two(value: i32) -> i32 { return value + 2; } -fn three(value: i32) -> i32 { return value + 3; } +fn one(value: i32) i32 { return value + 1; } +fn two(value: i32) i32 { return value + 2; } +fn three(value: i32) i32 { return value + 3; } -fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 { +fn performFn(comptime prefix_char: u8, start_value: i32) i32 { var result: i32 = start_value; comptime var i = 0; inline while (i < cmd_fns.len) : (i += 1) { @@ -3262,7 +3262,7 @@ test "perform fn" { {#code_begin|syntax#} // From the line: // assert(performFn('t', 1) == 6); -fn performFn(start_value: i32) -> i32 { +fn performFn(start_value: i32) i32 { var result: i32 = start_value; result = two(result); result = three(result); @@ -3272,7 +3272,7 @@ fn performFn(start_value: i32) -> i32 { {#code_begin|syntax#} // From the line: // assert(performFn('o', 0) == 1); -fn performFn(start_value: i32) -> i32 { +fn performFn(start_value: i32) i32 { var result: i32 = start_value; result = one(result); return result; @@ -3281,7 +3281,7 @@ fn performFn(start_value: i32) -> i32 { {#code_begin|syntax#} // From the line: // assert(performFn('w', 99) == 99); -fn performFn(start_value: i32) -> i32 { +fn performFn(start_value: i32) i32 { var result: i32 = start_value; return result; } @@ -3302,7 +3302,7 @@ fn performFn(start_value: i32) -> i32 { If this cannot be accomplished, the compiler will emit an error. For example: {#code_begin|test_err|unable to evaluate constant expression#} -extern fn exit() -> noreturn; +extern fn exit() noreturn; test "foo" { comptime { @@ -3335,7 +3335,7 @@ test "foo" { {#code_begin|test#} const assert = @import("std").debug.assert; -fn fibonacci(index: u32) -> u32 { +fn fibonacci(index: u32) u32 { if (index < 2) return index; return fibonacci(index - 1) + fibonacci(index - 2); } @@ -3356,7 +3356,7 @@ test "fibonacci" { {#code_begin|test_err|operation caused overflow#} const assert = @import("std").debug.assert; -fn fibonacci(index: u32) -> u32 { +fn fibonacci(index: u32) u32 { //if (index < 2) return index; return fibonacci(index - 1) + fibonacci(index - 2); } @@ -3379,7 +3379,7 @@ test "fibonacci" { {#code_begin|test_err|evaluation exceeded 1000 backwards branches#} const assert = @import("std").debug.assert; -fn fibonacci(index: i32) -> i32 { +fn fibonacci(index: i32) i32 { //if (index < 2) return index; return fibonacci(index - 1) + fibonacci(index - 2); } @@ -3402,7 +3402,7 @@ test "fibonacci" { {#code_begin|test_err|encountered @panic at compile-time#} const assert = @import("std").debug.assert; -fn fibonacci(index: i32) -> i32 { +fn fibonacci(index: i32) i32 { if (index < 2) return index; return fibonacci(index - 1) + fibonacci(index - 2); } @@ -3430,7 +3430,7 @@ test "fibonacci" { const first_25_primes = firstNPrimes(25); const sum_of_first_25_primes = sum(first_25_primes); -fn firstNPrimes(comptime n: usize) -> [n]i32 { +fn firstNPrimes(comptime n: usize) [n]i32 { var prime_list: [n]i32 = undefined; var next_index: usize = 0; var test_number: i32 = 2; @@ -3451,7 +3451,7 @@ fn firstNPrimes(comptime n: usize) -> [n]i32 { return prime_list; } -fn sum(numbers: []const i32) -> i32 { +fn sum(numbers: []const i32) i32 { var result: i32 = 0; for (numbers) |x| { result += x; @@ -3487,7 +3487,7 @@ test "variable values" { the typei32. In Zig we refer to the type as List(i32).
{#code_begin|syntax#}
-fn List(comptime T: type) -> type {
+fn List(comptime T: type) type {
return struct {
items: []T,
len: usize,
@@ -3526,7 +3526,7 @@ const warn = @import("std").debug.warn;
const a_number: i32 = 1234;
const a_string = "foobar";
-pub fn main() {
+pub fn main() void {
warn("here is a string: '{}' here is a number: {}\n", a_string, a_number);
}
{#code_end#}
@@ -3537,7 +3537,7 @@ pub fn main() {
{#code_begin|syntax#}
/// Calls print and then flushes the buffer.
-pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) -> %void {
+pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) %void {
const State = enum {
Start,
OpenBrace,
@@ -3609,7 +3609,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) -> %void
and emits a function that actually looks like this:
{#code_begin|syntax#}
-pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) -> %void {
+pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) %void {
try self.write("here is a string: '");
try self.printValue(arg0);
try self.write("' here is a number: ");
@@ -3623,7 +3623,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) -> %void {
on the type:
{#code_begin|syntax#}
-pub fn printValue(self: &OutStream, value: var) -> %void {
+pub fn printValue(self: &OutStream, value: var) %void {
const T = @typeOf(value);
if (@isInteger(T)) {
return self.printInt(T, value);
@@ -3665,7 +3665,7 @@ const a_number: i32 = 1234;
const a_string = "foobar";
const fmt = "here is a string: '{}' here is a number: {}\n";
-pub fn main() {
+pub fn main() void {
warn(fmt, a_string, a_number);
}
{#code_end#}
@@ -4101,7 +4101,7 @@ test "inline function call" {
assert(@inlineCall(add, 3, 9) == 12);
}
-fn add(a: i32, b: i32) -> i32 { return a + b; }
+fn add(a: i32, b: i32) i32 { return a + b; }
{#code_end#}
Unlike a normal function call, however, @inlineCall guarantees that the call
@@ -4246,8 +4246,8 @@ fn add(a: i32, b: i32) -> i32 { a + b }
const Derp = @OpaqueType();
const Wat = @OpaqueType();
-extern fn bar(d: &Derp);
-export fn foo(w: &Wat) {
+extern fn bar(d: &Derp) void;
+export fn foo(w: &Wat) void {
bar(w);
}
@@ -4552,7 +4552,7 @@ pub const TypeId = enum {
{#code_begin|syntax#}
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const exe = b.addExecutable("example", "example.zig");
exe.setBuildMode(b.standardReleaseOptions());
b.default_step.dependOn(&exe.step);
@@ -4612,7 +4612,7 @@ test "safety check" {
comptime {
assert(false);
}
-fn assert(ok: bool) {
+fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
{#code_end#}
@@ -4694,7 +4694,7 @@ comptime {
{#code_begin|exe_err#}
const math = @import("std").math;
const warn = @import("std").debug.warn;
-pub fn main() -> %void {
+pub fn main() %void {
var byte: u8 = 255;
byte = if (math.add(u8, byte, 1)) |result| result else |err| {
@@ -4722,7 +4722,7 @@ pub fn main() -> %void {
if expression:
{#code_begin|exe|test#}
const warn = @import("std").debug.warn;
-pub fn main() {
+pub fn main() void {
const nullable_number: ?i32 = null;
if (nullable_number) |number| {
@@ -4838,7 +4838,7 @@ comptime {
error UnableToReturnNumber;
-fn getNumberOrFail() -> %i32 {
+fn getNumberOrFail() %i32 {
return error.UnableToReturnNumber;
}
{#code_end#}
@@ -4848,7 +4848,7 @@ fn getNumberOrFail() -> %i32 {
{#code_begin|exe#}
const warn = @import("std").debug.warn;
-pub fn main() {
+pub fn main() void {
const result = getNumberOrFail();
if (result) |number| {
@@ -4860,7 +4860,7 @@ pub fn main() {
error UnableToReturnNumber;
-fn getNumberOrFail() -> %i32 {
+fn getNumberOrFail() %i32 {
return error.UnableToReturnNumber;
}
{#code_end#}
@@ -5177,9 +5177,9 @@ pub const have_error_return_tracing = true;
{#header_open|C String Literals#}
{#code_begin|exe#}
{#link_libc#}
-extern fn puts(&const u8);
+extern fn puts(&const u8) void;
-pub fn main() {
+pub fn main() void {
puts(c"this has a null terminator");
puts(
c\\and so
@@ -5202,7 +5202,7 @@ const c = @cImport({
@cDefine("_NO_CRT_STDIO_INLINE", "1");
@cInclude("stdio.h");
});
-pub fn main() {
+pub fn main() void {
_ = c.printf(c"hello\n");
}
{#code_end#}
@@ -5237,7 +5237,7 @@ const c = @cImport({
const base64 = @import("std").base64;
export fn decode_base_64(dest_ptr: &u8, dest_len: usize,
- source_ptr: &const u8, source_len: usize) -> usize
+ source_ptr: &const u8, source_len: usize) usize
{
const src = source_ptr[0..source_len];
const dest = dest_ptr[0..dest_len];
@@ -5268,7 +5268,7 @@ int main(int argc, char **argv) {
{#code_begin|syntax#}
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addCExecutable("test");
@@ -5498,7 +5498,7 @@ const string_alias = []u8;
const StructName = struct {};
const StructAlias = StructName;
-fn functionName(param_name: TypeName) {
+fn functionName(param_name: TypeName) void {
var functionPointer = functionName;
functionPointer();
functionPointer = otherFunction;
@@ -5506,14 +5506,14 @@ fn functionName(param_name: TypeName) {
}
const functionAlias = functionName;
-fn ListTemplateFunction(comptime ChildType: type, comptime fixed_size: usize) -> type {
+fn ListTemplateFunction(comptime ChildType: type, comptime fixed_size: usize) type {
return List(ChildType, fixed_size);
}
-fn ShortList(comptime T: type, comptime n: usize) -> type {
+fn ShortList(comptime T: type, comptime n: usize) type {
return struct {
field_name: [n]T,
- fn methodName() {}
+ fn methodName() void {}
};
}
@@ -5526,7 +5526,7 @@ const xml_document =
const XmlParser = struct {};
// The initials BE (Big Endian) are just another word in Zig identifier names.
-fn readU32Be() -> u32 {}
+fn readU32Be() u32 {}
{#code_end#}
See the Zig Standard Library for more examples.
@@ -5558,7 +5558,7 @@ UseDecl = "use" Expression ";"
ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";"
-FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("->" TypeExpr)
+FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") TypeExpr
FnDef = option("inline" | "export") FnProto Block
diff --git a/example/cat/main.zig b/example/cat/main.zig
index dce8db3f0d..f519ca3f18 100644
--- a/example/cat/main.zig
+++ b/example/cat/main.zig
@@ -5,7 +5,7 @@ const os = std.os;
const warn = std.debug.warn;
const allocator = std.debug.global_allocator;
-pub fn main() -> %void {
+pub fn main() %void {
var args_it = os.args();
const exe = try unwrapArg(??args_it.next(allocator));
var catted_anything = false;
@@ -36,12 +36,12 @@ pub fn main() -> %void {
}
}
-fn usage(exe: []const u8) -> %void {
+fn usage(exe: []const u8) %void {
warn("Usage: {} [FILE]...\n", exe);
return error.Invalid;
}
-fn cat_file(stdout: &io.File, file: &io.File) -> %void {
+fn cat_file(stdout: &io.File, file: &io.File) %void {
var buf: [1024 * 4]u8 = undefined;
while (true) {
@@ -61,7 +61,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void {
}
}
-fn unwrapArg(arg: %[]u8) -> %[]u8 {
+fn unwrapArg(arg: %[]u8) %[]u8 {
return arg catch |err| {
warn("Unable to parse command line: {}\n", err);
return err;
diff --git a/example/guess_number/main.zig b/example/guess_number/main.zig
index 69486a2528..482fb2f61e 100644
--- a/example/guess_number/main.zig
+++ b/example/guess_number/main.zig
@@ -5,7 +5,7 @@ const fmt = std.fmt;
const Rand = std.rand.Rand;
const os = std.os;
-pub fn main() -> %void {
+pub fn main() %void {
var stdout_file = try io.getStdOut();
var stdout_file_stream = io.FileOutStream.init(&stdout_file);
const stdout = &stdout_file_stream.stream;
diff --git a/example/hello_world/hello.zig b/example/hello_world/hello.zig
index e9e568187e..9fd050d701 100644
--- a/example/hello_world/hello.zig
+++ b/example/hello_world/hello.zig
@@ -1,6 +1,6 @@
const std = @import("std");
-pub fn main() -> %void {
+pub fn main() %void {
// If this program is run without stdout attached, exit with an error.
var stdout_file = try std.io.getStdOut();
// If this program encounters pipe failure when printing to stdout, exit
diff --git a/example/hello_world/hello_libc.zig b/example/hello_world/hello_libc.zig
index ea8aec1e4f..60123c6fd8 100644
--- a/example/hello_world/hello_libc.zig
+++ b/example/hello_world/hello_libc.zig
@@ -7,7 +7,7 @@ const c = @cImport({
const msg = c"Hello, world!\n";
-export fn main(argc: c_int, argv: &&u8) -> c_int {
+export fn main(argc: c_int, argv: &&u8) c_int {
if (c.printf(msg) != c_int(c.strlen(msg)))
return -1;
diff --git a/example/hello_world/hello_windows.zig b/example/hello_world/hello_windows.zig
index 83d362bd1d..f55db2edeb 100644
--- a/example/hello_world/hello_windows.zig
+++ b/example/hello_world/hello_windows.zig
@@ -1,6 +1,6 @@
use @import("std").os.windows;
-export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) -> INT {
+export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT {
_ = MessageBoxA(null, c"hello", c"title", 0);
return 0;
}
diff --git a/example/mix_o_files/base64.zig b/example/mix_o_files/base64.zig
index 49c9bc6012..553c780b98 100644
--- a/example/mix_o_files/base64.zig
+++ b/example/mix_o_files/base64.zig
@@ -1,6 +1,6 @@
const base64 = @import("std").base64;
-export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize {
+export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) usize {
const src = source_ptr[0..source_len];
const dest = dest_ptr[0..dest_len];
const base64_decoder = base64.standard_decoder_unsafe;
diff --git a/example/mix_o_files/build.zig b/example/mix_o_files/build.zig
index 4bba69b091..25d0fdd2ff 100644
--- a/example/mix_o_files/build.zig
+++ b/example/mix_o_files/build.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addCExecutable("test");
diff --git a/example/shared_library/build.zig b/example/shared_library/build.zig
index 147b54401c..52d60da819 100644
--- a/example/shared_library/build.zig
+++ b/example/shared_library/build.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addCExecutable("test");
diff --git a/example/shared_library/mathtest.zig b/example/shared_library/mathtest.zig
index bb0175bff2..a04ec1544d 100644
--- a/example/shared_library/mathtest.zig
+++ b/example/shared_library/mathtest.zig
@@ -1,3 +1,3 @@
-export fn add(a: i32, b: i32) -> i32 {
+export fn add(a: i32, b: i32) i32 {
return a + b;
}
diff --git a/src-self-hosted/ast.zig b/src-self-hosted/ast.zig
index 5fd836b950..b63c0a347e 100644
--- a/src-self-hosted/ast.zig
+++ b/src-self-hosted/ast.zig
@@ -20,7 +20,7 @@ pub const Node = struct {
FloatLiteral,
};
- pub fn iterate(base: &Node, index: usize) -> ?&Node {
+ pub fn iterate(base: &Node, index: usize) ?&Node {
return switch (base.id) {
Id.Root => @fieldParentPtr(NodeRoot, "base", base).iterate(index),
Id.VarDecl => @fieldParentPtr(NodeVarDecl, "base", base).iterate(index),
@@ -35,7 +35,7 @@ pub const Node = struct {
};
}
- pub fn destroy(base: &Node, allocator: &mem.Allocator) {
+ pub fn destroy(base: &Node, allocator: &mem.Allocator) void {
return switch (base.id) {
Id.Root => allocator.destroy(@fieldParentPtr(NodeRoot, "base", base)),
Id.VarDecl => allocator.destroy(@fieldParentPtr(NodeVarDecl, "base", base)),
@@ -55,7 +55,7 @@ pub const NodeRoot = struct {
base: Node,
decls: ArrayList(&Node),
- pub fn iterate(self: &NodeRoot, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeRoot, index: usize) ?&Node {
if (index < self.decls.len) {
return self.decls.items[self.decls.len - index - 1];
}
@@ -76,7 +76,7 @@ pub const NodeVarDecl = struct {
align_node: ?&Node,
init_node: ?&Node,
- pub fn iterate(self: &NodeVarDecl, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeVarDecl, index: usize) ?&Node {
var i = index;
if (self.type_node) |type_node| {
@@ -102,7 +102,7 @@ pub const NodeIdentifier = struct {
base: Node,
name_token: Token,
- pub fn iterate(self: &NodeIdentifier, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeIdentifier, index: usize) ?&Node {
return null;
}
};
@@ -113,7 +113,7 @@ pub const NodeFnProto = struct {
fn_token: Token,
name_token: ?Token,
params: ArrayList(&Node),
- return_type: ?&Node,
+ return_type: &Node,
var_args_token: ?Token,
extern_token: ?Token,
inline_token: ?Token,
@@ -122,7 +122,7 @@ pub const NodeFnProto = struct {
lib_name: ?&Node, // populated if this is an extern declaration
align_expr: ?&Node, // populated if align(A) is present
- pub fn iterate(self: &NodeFnProto, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeFnProto, index: usize) ?&Node {
var i = index;
if (self.body_node) |body_node| {
@@ -130,10 +130,8 @@ pub const NodeFnProto = struct {
i -= 1;
}
- if (self.return_type) |return_type| {
- if (i < 1) return return_type;
- i -= 1;
- }
+ if (i < 1) return self.return_type;
+ i -= 1;
if (self.align_expr) |align_expr| {
if (i < 1) return align_expr;
@@ -160,7 +158,7 @@ pub const NodeParamDecl = struct {
type_node: &Node,
var_args_token: ?Token,
- pub fn iterate(self: &NodeParamDecl, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeParamDecl, index: usize) ?&Node {
var i = index;
if (i < 1) return self.type_node;
@@ -176,7 +174,7 @@ pub const NodeBlock = struct {
end_token: Token,
statements: ArrayList(&Node),
- pub fn iterate(self: &NodeBlock, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeBlock, index: usize) ?&Node {
var i = index;
if (i < self.statements.len) return self.statements.items[i];
@@ -198,7 +196,7 @@ pub const NodeInfixOp = struct {
BangEqual,
};
- pub fn iterate(self: &NodeInfixOp, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeInfixOp, index: usize) ?&Node {
var i = index;
if (i < 1) return self.lhs;
@@ -234,7 +232,7 @@ pub const NodePrefixOp = struct {
volatile_token: ?Token,
};
- pub fn iterate(self: &NodePrefixOp, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodePrefixOp, index: usize) ?&Node {
var i = index;
switch (self.op) {
@@ -258,7 +256,7 @@ pub const NodeIntegerLiteral = struct {
base: Node,
token: Token,
- pub fn iterate(self: &NodeIntegerLiteral, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeIntegerLiteral, index: usize) ?&Node {
return null;
}
};
@@ -267,7 +265,7 @@ pub const NodeFloatLiteral = struct {
base: Node,
token: Token,
- pub fn iterate(self: &NodeFloatLiteral, index: usize) -> ?&Node {
+ pub fn iterate(self: &NodeFloatLiteral, index: usize) ?&Node {
return null;
}
};
diff --git a/src-self-hosted/llvm.zig b/src-self-hosted/llvm.zig
index 6a1439291b..16c359adcf 100644
--- a/src-self-hosted/llvm.zig
+++ b/src-self-hosted/llvm.zig
@@ -7,7 +7,7 @@ pub const ModuleRef = removeNullability(c.LLVMModuleRef);
pub const ContextRef = removeNullability(c.LLVMContextRef);
pub const BuilderRef = removeNullability(c.LLVMBuilderRef);
-fn removeNullability(comptime T: type) -> type {
+fn removeNullability(comptime T: type) type {
comptime assert(@typeId(T) == builtin.TypeId.Nullable);
return T.Child;
}
diff --git a/src-self-hosted/main.zig b/src-self-hosted/main.zig
index 8a2f6888eb..7f9e5073a5 100644
--- a/src-self-hosted/main.zig
+++ b/src-self-hosted/main.zig
@@ -20,7 +20,7 @@ error ZigInstallationNotFound;
const default_zig_cache_name = "zig-cache";
-pub fn main() -> %void {
+pub fn main() %void {
main2() catch |err| {
if (err != error.InvalidCommandLineArguments) {
warn("{}\n", @errorName(err));
@@ -39,7 +39,7 @@ const Cmd = enum {
Targets,
};
-fn badArgs(comptime format: []const u8, args: ...) -> error {
+fn badArgs(comptime format: []const u8, args: ...) error {
var stderr = try io.getStdErr();
var stderr_stream_adapter = io.FileOutStream.init(&stderr);
const stderr_stream = &stderr_stream_adapter.stream;
@@ -48,7 +48,7 @@ fn badArgs(comptime format: []const u8, args: ...) -> error {
return error.InvalidCommandLineArguments;
}
-pub fn main2() -> %void {
+pub fn main2() %void {
const allocator = std.heap.c_allocator;
const args = try os.argsAlloc(allocator);
@@ -472,7 +472,7 @@ pub fn main2() -> %void {
}
}
-fn printUsage(stream: &io.OutStream) -> %void {
+fn printUsage(stream: &io.OutStream) %void {
try stream.write(
\\Usage: zig [command] [options]
\\
@@ -548,7 +548,7 @@ fn printUsage(stream: &io.OutStream) -> %void {
);
}
-fn printZen() -> %void {
+fn printZen() %void {
var stdout_file = try io.getStdErr();
try stdout_file.write(
\\
@@ -569,7 +569,7 @@ fn printZen() -> %void {
}
/// Caller must free result
-fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) -> %[]u8 {
+fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) %[]u8 {
if (zig_install_prefix_arg) |zig_install_prefix| {
return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| {
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
}
/// Caller must free result
-fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) -> %[]u8 {
+fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) %[]u8 {
const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig");
errdefer allocator.free(test_zig_dir);
@@ -599,7 +599,7 @@ fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) -> %[]
}
/// Caller must free result
-fn findZigLibDir(allocator: &mem.Allocator) -> %[]u8 {
+fn findZigLibDir(allocator: &mem.Allocator) %[]u8 {
const self_exe_path = try os.selfExeDirPath(allocator);
defer allocator.free(self_exe_path);
diff --git a/src-self-hosted/module.zig b/src-self-hosted/module.zig
index c246468915..f7bf6e0de7 100644
--- a/src-self-hosted/module.zig
+++ b/src-self-hosted/module.zig
@@ -110,7 +110,7 @@ pub const Module = struct {
};
pub fn create(allocator: &mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: &const Target,
- kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) -> %&Module
+ kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) %&Module
{
var name_buffer = try Buffer.init(allocator, name);
errdefer name_buffer.deinit();
@@ -185,11 +185,11 @@ pub const Module = struct {
return module_ptr;
}
- fn dump(self: &Module) {
+ fn dump(self: &Module) void {
c.LLVMDumpModule(self.module);
}
- pub fn destroy(self: &Module) {
+ pub fn destroy(self: &Module) void {
c.LLVMDisposeBuilder(self.builder);
c.LLVMDisposeModule(self.module);
c.LLVMContextDispose(self.context);
@@ -198,7 +198,7 @@ pub const Module = struct {
self.allocator.destroy(self);
}
- pub fn build(self: &Module) -> %void {
+ pub fn build(self: &Module) %void {
if (self.llvm_argv.len != 0) {
var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator,
[][]const []const u8 { [][]const u8{"zig (LLVM option parsing)"}, self.llvm_argv, });
@@ -244,16 +244,16 @@ pub const Module = struct {
var parser = Parser.init(&tokenizer, self.allocator, root_src_real_path);
defer parser.deinit();
- const root_node = try parser.parse();
- defer parser.freeAst(root_node);
+ const tree = try parser.parse();
+ defer tree.deinit();
var stderr_file = try std.io.getStdErr();
var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file);
const out_stream = &stderr_file_out_stream.stream;
- try parser.renderAst(out_stream, root_node);
+ try parser.renderAst(out_stream, tree.root_node);
warn("====fmt:====\n");
- try parser.renderSource(out_stream, root_node);
+ try parser.renderSource(out_stream, tree.root_node);
warn("====ir:====\n");
warn("TODO\n\n");
@@ -263,11 +263,11 @@ pub const Module = struct {
}
- pub fn link(self: &Module, out_file: ?[]const u8) -> %void {
+ pub fn link(self: &Module, out_file: ?[]const u8) %void {
warn("TODO link");
}
- pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) -> %&LinkLib {
+ pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) %&LinkLib {
const is_libc = mem.eql(u8, name, "c");
if (is_libc) {
@@ -297,7 +297,7 @@ pub const Module = struct {
}
};
-fn printError(comptime format: []const u8, args: ...) -> %void {
+fn printError(comptime format: []const u8, args: ...) %void {
var stderr_file = try std.io.getStdErr();
var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file);
const out_stream = &stderr_file_out_stream.stream;
diff --git a/src-self-hosted/parser.zig b/src-self-hosted/parser.zig
index 791bec3fa7..550d29b2c4 100644
--- a/src-self-hosted/parser.zig
+++ b/src-self-hosted/parser.zig
@@ -20,14 +20,25 @@ pub const Parser = struct {
put_back_tokens: [2]Token,
put_back_count: usize,
source_file_name: []const u8,
- cleanup_root_node: ?&ast.NodeRoot,
+
+ pub const Tree = struct {
+ root_node: &ast.NodeRoot,
+
+ pub fn deinit(self: &const Tree) void {
+ // TODO free the whole arena
+ }
+ };
// This memory contents are used only during a function call. It's used to repurpose memory;
- // specifically so that freeAst can be guaranteed to succeed.
+ // we reuse the same bytes for the stack data structure used by parsing, tree rendering, and
+ // source rendering.
const utility_bytes_align = @alignOf( union { a: RenderAstFrame, b: State, c: RenderState } );
utility_bytes: []align(utility_bytes_align) u8,
- pub fn init(tokenizer: &Tokenizer, allocator: &mem.Allocator, source_file_name: []const u8) -> Parser {
+ /// `allocator` should be an arena allocator. Parser never calls free on anything. After you're
+ /// done with a Parser, free the arena. After the arena is freed, no member functions of Parser
+ /// may be called.
+ pub fn init(tokenizer: &Tokenizer, allocator: &mem.Allocator, source_file_name: []const u8) Parser {
return Parser {
.allocator = allocator,
.tokenizer = tokenizer,
@@ -35,12 +46,10 @@ pub const Parser = struct {
.put_back_count = 0,
.source_file_name = source_file_name,
.utility_bytes = []align(utility_bytes_align) u8{},
- .cleanup_root_node = null,
};
}
- pub fn deinit(self: &Parser) {
- assert(self.cleanup_root_node == null);
+ pub fn deinit(self: &Parser) void {
self.allocator.free(self.utility_bytes);
}
@@ -54,7 +63,7 @@ pub const Parser = struct {
NullableField: &?&ast.Node,
List: &ArrayList(&ast.Node),
- pub fn store(self: &const DestPtr, value: &ast.Node) -> %void {
+ pub fn store(self: &const DestPtr, value: &ast.Node) %void {
switch (*self) {
DestPtr.Field => |ptr| *ptr = value,
DestPtr.NullableField => |ptr| *ptr = value,
@@ -88,52 +97,16 @@ pub const Parser = struct {
Statement: &ast.NodeBlock,
};
- pub fn freeAst(self: &Parser, root_node: &ast.NodeRoot) {
- // utility_bytes is big enough to do this iteration since we were able to do
- // the parsing in the first place
- comptime assert(@sizeOf(State) >= @sizeOf(&ast.Node));
-
- var stack = self.initUtilityArrayList(&ast.Node);
- defer self.deinitUtilityArrayList(stack);
-
- stack.append(&root_node.base) catch unreachable;
- while (stack.popOrNull()) |node| {
- var i: usize = 0;
- while (node.iterate(i)) |child| : (i += 1) {
- if (child.iterate(0) != null) {
- stack.append(child) catch unreachable;
- } else {
- child.destroy(self.allocator);
- }
- }
- node.destroy(self.allocator);
- }
- }
-
- pub fn parse(self: &Parser) -> %&ast.NodeRoot {
- const result = self.parseInner() catch |err| x: {
- if (self.cleanup_root_node) |root_node| {
- self.freeAst(root_node);
- }
- break :x err;
- };
- self.cleanup_root_node = null;
- return result;
- }
-
- pub fn parseInner(self: &Parser) -> %&ast.NodeRoot {
+ /// Returns an AST tree, allocated with the parser's allocator.
+ /// Result should be freed with `freeAst` when done.
+ pub fn parse(self: &Parser) %Tree {
var stack = self.initUtilityArrayList(State);
defer self.deinitUtilityArrayList(stack);
- const root_node = x: {
- const root_node = try self.createRoot();
- errdefer self.allocator.destroy(root_node);
- // This stack append has to succeed for freeAst to work
- try stack.append(State.TopLevel);
- break :x root_node;
- };
- assert(self.cleanup_root_node == null);
- self.cleanup_root_node = root_node;
+ const root_node = try self.createRoot();
+ // TODO errdefer arena free root node
+
+ try stack.append(State.TopLevel);
while (true) {
//{
@@ -159,7 +132,7 @@ pub const Parser = struct {
stack.append(State { .TopLevelExtern = token }) catch unreachable;
continue;
},
- Token.Id.Eof => return root_node,
+ Token.Id.Eof => return Tree {.root_node = root_node},
else => {
self.putBackToken(token);
// TODO shouldn't need this cast
@@ -439,15 +412,11 @@ pub const Parser = struct {
if (token.id == Token.Id.Keyword_align) {
@panic("TODO fn proto align");
}
- if (token.id == Token.Id.Arrow) {
- stack.append(State {
- .TypeExpr = DestPtr {.NullableField = &fn_proto.return_type},
- }) catch unreachable;
- continue;
- } else {
- self.putBackToken(token);
- continue;
- }
+ self.putBackToken(token);
+ stack.append(State {
+ .TypeExpr = DestPtr {.Field = &fn_proto.return_type},
+ }) catch unreachable;
+ continue;
},
State.ParamDecl => |fn_proto| {
@@ -575,9 +544,8 @@ pub const Parser = struct {
}
}
- fn createRoot(self: &Parser) -> %&ast.NodeRoot {
+ fn createRoot(self: &Parser) %&ast.NodeRoot {
const node = try self.allocator.create(ast.NodeRoot);
- errdefer self.allocator.destroy(node);
*node = ast.NodeRoot {
.base = ast.Node {.id = ast.Node.Id.Root},
@@ -587,10 +555,9 @@ pub const Parser = struct {
}
fn createVarDecl(self: &Parser, visib_token: &const ?Token, mut_token: &const Token, comptime_token: &const ?Token,
- extern_token: &const ?Token) -> %&ast.NodeVarDecl
+ extern_token: &const ?Token) %&ast.NodeVarDecl
{
const node = try self.allocator.create(ast.NodeVarDecl);
- errdefer self.allocator.destroy(node);
*node = ast.NodeVarDecl {
.base = ast.Node {.id = ast.Node.Id.VarDecl},
@@ -610,10 +577,9 @@ pub const Parser = struct {
}
fn createFnProto(self: &Parser, fn_token: &const Token, extern_token: &const ?Token,
- cc_token: &const ?Token, visib_token: &const ?Token, inline_token: &const ?Token) -> %&ast.NodeFnProto
+ cc_token: &const ?Token, visib_token: &const ?Token, inline_token: &const ?Token) %&ast.NodeFnProto
{
const node = try self.allocator.create(ast.NodeFnProto);
- errdefer self.allocator.destroy(node);
*node = ast.NodeFnProto {
.base = ast.Node {.id = ast.Node.Id.FnProto},
@@ -621,7 +587,7 @@ pub const Parser = struct {
.name_token = null,
.fn_token = *fn_token,
.params = ArrayList(&ast.Node).init(self.allocator),
- .return_type = null,
+ .return_type = undefined,
.var_args_token = null,
.extern_token = *extern_token,
.inline_token = *inline_token,
@@ -633,9 +599,8 @@ pub const Parser = struct {
return node;
}
- fn createParamDecl(self: &Parser) -> %&ast.NodeParamDecl {
+ fn createParamDecl(self: &Parser) %&ast.NodeParamDecl {
const node = try self.allocator.create(ast.NodeParamDecl);
- errdefer self.allocator.destroy(node);
*node = ast.NodeParamDecl {
.base = ast.Node {.id = ast.Node.Id.ParamDecl},
@@ -648,9 +613,8 @@ pub const Parser = struct {
return node;
}
- fn createBlock(self: &Parser, begin_token: &const Token) -> %&ast.NodeBlock {
+ fn createBlock(self: &Parser, begin_token: &const Token) %&ast.NodeBlock {
const node = try self.allocator.create(ast.NodeBlock);
- errdefer self.allocator.destroy(node);
*node = ast.NodeBlock {
.base = ast.Node {.id = ast.Node.Id.Block},
@@ -661,9 +625,8 @@ pub const Parser = struct {
return node;
}
- fn createInfixOp(self: &Parser, op_token: &const Token, op: &const ast.NodeInfixOp.InfixOp) -> %&ast.NodeInfixOp {
+ fn createInfixOp(self: &Parser, op_token: &const Token, op: &const ast.NodeInfixOp.InfixOp) %&ast.NodeInfixOp {
const node = try self.allocator.create(ast.NodeInfixOp);
- errdefer self.allocator.destroy(node);
*node = ast.NodeInfixOp {
.base = ast.Node {.id = ast.Node.Id.InfixOp},
@@ -675,9 +638,8 @@ pub const Parser = struct {
return node;
}
- fn createPrefixOp(self: &Parser, op_token: &const Token, op: &const ast.NodePrefixOp.PrefixOp) -> %&ast.NodePrefixOp {
+ fn createPrefixOp(self: &Parser, op_token: &const Token, op: &const ast.NodePrefixOp.PrefixOp) %&ast.NodePrefixOp {
const node = try self.allocator.create(ast.NodePrefixOp);
- errdefer self.allocator.destroy(node);
*node = ast.NodePrefixOp {
.base = ast.Node {.id = ast.Node.Id.PrefixOp},
@@ -688,9 +650,8 @@ pub const Parser = struct {
return node;
}
- fn createIdentifier(self: &Parser, name_token: &const Token) -> %&ast.NodeIdentifier {
+ fn createIdentifier(self: &Parser, name_token: &const Token) %&ast.NodeIdentifier {
const node = try self.allocator.create(ast.NodeIdentifier);
- errdefer self.allocator.destroy(node);
*node = ast.NodeIdentifier {
.base = ast.Node {.id = ast.Node.Id.Identifier},
@@ -699,9 +660,8 @@ pub const Parser = struct {
return node;
}
- fn createIntegerLiteral(self: &Parser, token: &const Token) -> %&ast.NodeIntegerLiteral {
+ fn createIntegerLiteral(self: &Parser, token: &const Token) %&ast.NodeIntegerLiteral {
const node = try self.allocator.create(ast.NodeIntegerLiteral);
- errdefer self.allocator.destroy(node);
*node = ast.NodeIntegerLiteral {
.base = ast.Node {.id = ast.Node.Id.IntegerLiteral},
@@ -710,9 +670,8 @@ pub const Parser = struct {
return node;
}
- fn createFloatLiteral(self: &Parser, token: &const Token) -> %&ast.NodeFloatLiteral {
+ fn createFloatLiteral(self: &Parser, token: &const Token) %&ast.NodeFloatLiteral {
const node = try self.allocator.create(ast.NodeFloatLiteral);
- errdefer self.allocator.destroy(node);
*node = ast.NodeFloatLiteral {
.base = ast.Node {.id = ast.Node.Id.FloatLiteral},
@@ -721,40 +680,36 @@ pub const Parser = struct {
return node;
}
- fn createAttachIdentifier(self: &Parser, dest_ptr: &const DestPtr, name_token: &const Token) -> %&ast.NodeIdentifier {
+ fn createAttachIdentifier(self: &Parser, dest_ptr: &const DestPtr, name_token: &const Token) %&ast.NodeIdentifier {
const node = try self.createIdentifier(name_token);
- errdefer self.allocator.destroy(node);
try dest_ptr.store(&node.base);
return node;
}
- fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) -> %&ast.NodeParamDecl {
+ fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) %&ast.NodeParamDecl {
const node = try self.createParamDecl();
- errdefer self.allocator.destroy(node);
try list.append(&node.base);
return node;
}
fn createAttachFnProto(self: &Parser, list: &ArrayList(&ast.Node), fn_token: &const Token,
extern_token: &const ?Token, cc_token: &const ?Token, visib_token: &const ?Token,
- inline_token: &const ?Token) -> %&ast.NodeFnProto
+ inline_token: &const ?Token) %&ast.NodeFnProto
{
const node = try self.createFnProto(fn_token, extern_token, cc_token, visib_token, inline_token);
- errdefer self.allocator.destroy(node);
try list.append(&node.base);
return node;
}
fn createAttachVarDecl(self: &Parser, list: &ArrayList(&ast.Node), visib_token: &const ?Token,
- mut_token: &const Token, comptime_token: &const ?Token, extern_token: &const ?Token) -> %&ast.NodeVarDecl
+ mut_token: &const Token, comptime_token: &const ?Token, extern_token: &const ?Token) %&ast.NodeVarDecl
{
const node = try self.createVarDecl(visib_token, mut_token, comptime_token, extern_token);
- errdefer self.allocator.destroy(node);
try list.append(&node.base);
return node;
}
- fn parseError(self: &Parser, token: &const Token, comptime fmt: []const u8, args: ...) -> error {
+ fn parseError(self: &Parser, token: &const Token, comptime fmt: []const u8, args: ...) error {
const loc = self.tokenizer.getTokenLocation(token);
warn("{}:{}:{}: error: " ++ fmt ++ "\n", self.source_file_name, loc.line + 1, loc.column + 1, args);
warn("{}\n", self.tokenizer.buffer[loc.line_start..loc.line_end]);
@@ -775,24 +730,24 @@ pub const Parser = struct {
return error.ParseError;
}
- fn expectToken(self: &Parser, token: &const Token, id: @TagType(Token.Id)) -> %void {
+ fn expectToken(self: &Parser, token: &const Token, id: @TagType(Token.Id)) %void {
if (token.id != id) {
return self.parseError(token, "expected {}, found {}", @tagName(id), @tagName(token.id));
}
}
- fn eatToken(self: &Parser, id: @TagType(Token.Id)) -> %Token {
+ fn eatToken(self: &Parser, id: @TagType(Token.Id)) %Token {
const token = self.getNextToken();
try self.expectToken(token, id);
return token;
}
- fn putBackToken(self: &Parser, token: &const Token) {
+ fn putBackToken(self: &Parser, token: &const Token) void {
self.put_back_tokens[self.put_back_count] = *token;
self.put_back_count += 1;
}
- fn getNextToken(self: &Parser) -> Token {
+ fn getNextToken(self: &Parser) Token {
if (self.put_back_count != 0) {
const put_back_index = self.put_back_count - 1;
const put_back_token = self.put_back_tokens[put_back_index];
@@ -808,7 +763,7 @@ pub const Parser = struct {
indent: usize,
};
- pub fn renderAst(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) -> %void {
+ pub fn renderAst(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) %void {
var stack = self.initUtilityArrayList(RenderAstFrame);
defer self.deinitUtilityArrayList(stack);
@@ -847,7 +802,7 @@ pub const Parser = struct {
Indent: usize,
};
- pub fn renderSource(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) -> %void {
+ pub fn renderSource(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) %void {
var stack = self.initUtilityArrayList(RenderState);
defer self.deinitUtilityArrayList(stack);
@@ -1039,14 +994,12 @@ pub const Parser = struct {
if (fn_proto.align_expr != null) {
@panic("TODO");
}
- if (fn_proto.return_type) |return_type| {
- try stream.print(" -> ");
- if (fn_proto.body_node) |body_node| {
- try stack.append(RenderState { .Expression = body_node});
- try stack.append(RenderState { .Text = " "});
- }
- try stack.append(RenderState { .Expression = return_type});
+ try stream.print(" ");
+ if (fn_proto.body_node) |body_node| {
+ try stack.append(RenderState { .Expression = body_node});
+ try stack.append(RenderState { .Text = " "});
}
+ try stack.append(RenderState { .Expression = fn_proto.return_type});
},
RenderState.Statement => |base| {
switch (base.id) {
@@ -1066,7 +1019,7 @@ pub const Parser = struct {
}
}
- fn initUtilityArrayList(self: &Parser, comptime T: type) -> ArrayList(T) {
+ fn initUtilityArrayList(self: &Parser, comptime T: type) ArrayList(T) {
const new_byte_count = self.utility_bytes.len - self.utility_bytes.len % @sizeOf(T);
self.utility_bytes = self.allocator.alignedShrink(u8, utility_bytes_align, self.utility_bytes, new_byte_count);
const typed_slice = ([]T)(self.utility_bytes);
@@ -1077,7 +1030,7 @@ pub const Parser = struct {
};
}
- fn deinitUtilityArrayList(self: &Parser, list: var) {
+ fn deinitUtilityArrayList(self: &Parser, list: var) void {
self.utility_bytes = ([]align(utility_bytes_align) u8)(list.items);
}
@@ -1085,7 +1038,7 @@ pub const Parser = struct {
var fixed_buffer_mem: [100 * 1024]u8 = undefined;
-fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 {
+fn testParse(source: []const u8, allocator: &mem.Allocator) %[]u8 {
var padded_source: [0x100]u8 = undefined;
std.mem.copy(u8, padded_source[0..source.len], source);
padded_source[source.len + 0] = '\n';
@@ -1096,30 +1049,34 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 {
var parser = Parser.init(&tokenizer, allocator, "(memory buffer)");
defer parser.deinit();
- const root_node = try parser.parse();
- defer parser.freeAst(root_node);
+ const tree = try parser.parse();
+ defer tree.deinit();
var buffer = try std.Buffer.initSize(allocator, 0);
var buffer_out_stream = io.BufferOutStream.init(&buffer);
- try parser.renderSource(&buffer_out_stream.stream, root_node);
+ try parser.renderSource(&buffer_out_stream.stream, tree.root_node);
return buffer.toOwnedSlice();
}
+error TestFailed;
+error NondeterministicMemoryUsage;
+error MemoryLeakDetected;
+
// TODO test for memory leaks
// TODO test for valid frees
-fn testCanonical(source: []const u8) {
+fn testCanonical(source: []const u8) %void {
const needed_alloc_count = x: {
// Try it once with unlimited memory, make sure it works
var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));
- const result_source = testParse(source, &failing_allocator.allocator) catch @panic("test failed");
+ const result_source = try testParse(source, &failing_allocator.allocator);
if (!mem.eql(u8, result_source, source)) {
warn("\n====== expected this output: =========\n");
warn("{}", source);
warn("\n======== instead found this: =========\n");
warn("{}", result_source);
warn("\n======================================\n");
- @panic("test failed");
+ return error.TestFailed;
}
failing_allocator.allocator.free(result_source);
break :x failing_allocator.index;
@@ -1130,7 +1087,7 @@ fn testCanonical(source: []const u8) {
var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, fail_index);
if (testParse(source, &failing_allocator.allocator)) |_| {
- @panic("non-deterministic memory usage");
+ return error.NondeterministicMemoryUsage;
} else |err| {
assert(err == error.OutOfMemory);
// TODO make this pass
@@ -1139,19 +1096,19 @@ fn testCanonical(source: []const u8) {
// fail_index, needed_alloc_count,
// failing_allocator.allocated_bytes, failing_allocator.freed_bytes,
// failing_allocator.index, failing_allocator.deallocations);
- // @panic("memory leak detected");
+ // return error.MemoryLeakDetected;
//}
}
}
}
test "zig fmt" {
- testCanonical(
- \\extern fn puts(s: &const u8) -> c_int;
+ try testCanonical(
+ \\extern fn puts(s: &const u8) c_int;
\\
);
- testCanonical(
+ try testCanonical(
\\const a = b;
\\pub const a = b;
\\var a = b;
@@ -1163,44 +1120,44 @@ test "zig fmt" {
\\
);
- testCanonical(
+ try testCanonical(
\\extern var foo: c_int;
\\
);
- testCanonical(
+ try testCanonical(
\\var foo: c_int align(1);
\\
);
- testCanonical(
- \\fn main(argc: c_int, argv: &&u8) -> c_int {
+ try testCanonical(
+ \\fn main(argc: c_int, argv: &&u8) c_int {
\\ const a = b;
\\}
\\
);
- testCanonical(
- \\fn foo(argc: c_int, argv: &&u8) -> c_int {
+ try testCanonical(
+ \\fn foo(argc: c_int, argv: &&u8) c_int {
\\ return 0;
\\}
\\
);
- testCanonical(
- \\extern fn f1(s: &align(&u8) u8) -> c_int;
+ try testCanonical(
+ \\extern fn f1(s: &align(&u8) u8) c_int;
\\
);
- testCanonical(
- \\extern fn f1(s: &&align(1) &const &volatile u8) -> c_int;
- \\extern fn f2(s: &align(1) const &align(1) volatile &const volatile u8) -> c_int;
- \\extern fn f3(s: &align(1) const volatile u8) -> c_int;
+ try testCanonical(
+ \\extern fn f1(s: &&align(1) &const &volatile u8) c_int;
+ \\extern fn f2(s: &align(1) const &align(1) volatile &const volatile u8) c_int;
+ \\extern fn f3(s: &align(1) const volatile u8) c_int;
\\
);
- testCanonical(
- \\fn f1(a: bool, b: bool) -> bool {
+ try testCanonical(
+ \\fn f1(a: bool, b: bool) bool {
\\ a != b;
\\ return a == b;
\\}
diff --git a/src-self-hosted/target.zig b/src-self-hosted/target.zig
index 0f04e66744..375b48f10d 100644
--- a/src-self-hosted/target.zig
+++ b/src-self-hosted/target.zig
@@ -11,7 +11,7 @@ pub const Target = union(enum) {
Native,
Cross: CrossTarget,
- pub fn oFileExt(self: &const Target) -> []const u8 {
+ pub fn oFileExt(self: &const Target) []const u8 {
const environ = switch (*self) {
Target.Native => builtin.environ,
Target.Cross => |t| t.environ,
@@ -22,28 +22,28 @@ pub const Target = union(enum) {
};
}
- pub fn exeFileExt(self: &const Target) -> []const u8 {
+ pub fn exeFileExt(self: &const Target) []const u8 {
return switch (self.getOs()) {
builtin.Os.windows => ".exe",
else => "",
};
}
- pub fn getOs(self: &const Target) -> builtin.Os {
+ pub fn getOs(self: &const Target) builtin.Os {
return switch (*self) {
Target.Native => builtin.os,
Target.Cross => |t| t.os,
};
}
- pub fn isDarwin(self: &const Target) -> bool {
+ pub fn isDarwin(self: &const Target) bool {
return switch (self.getOs()) {
builtin.Os.ios, builtin.Os.macosx => true,
else => false,
};
}
- pub fn isWindows(self: &const Target) -> bool {
+ pub fn isWindows(self: &const Target) bool {
return switch (self.getOs()) {
builtin.Os.windows => true,
else => false,
@@ -51,7 +51,7 @@ pub const Target = union(enum) {
}
};
-pub fn initializeAll() {
+pub fn initializeAll() void {
c.LLVMInitializeAllTargets();
c.LLVMInitializeAllTargetInfos();
c.LLVMInitializeAllTargetMCs();
diff --git a/src-self-hosted/tokenizer.zig b/src-self-hosted/tokenizer.zig
index f6ba130b25..f1f87abfc9 100644
--- a/src-self-hosted/tokenizer.zig
+++ b/src-self-hosted/tokenizer.zig
@@ -53,7 +53,7 @@ pub const Token = struct {
KeywordId{.bytes="while", .id = Id.Keyword_while},
};
- fn getKeyword(bytes: []const u8) -> ?Id {
+ fn getKeyword(bytes: []const u8) ?Id {
for (keywords) |kw| {
if (mem.eql(u8, kw.bytes, bytes)) {
return kw.id;
@@ -146,7 +146,7 @@ pub const Tokenizer = struct {
line_end: usize,
};
- pub fn getTokenLocation(self: &Tokenizer, token: &const Token) -> Location {
+ pub fn getTokenLocation(self: &Tokenizer, token: &const Token) Location {
var loc = Location {
.line = 0,
.column = 0,
@@ -171,13 +171,13 @@ pub const Tokenizer = struct {
}
/// For debugging purposes
- pub fn dump(self: &Tokenizer, token: &const Token) {
+ pub fn dump(self: &Tokenizer, token: &const Token) void {
std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);
}
/// buffer must end with "\n\n\n". This is so that attempting to decode
/// a the 3 trailing bytes of a 4-byte utf8 sequence is never a buffer overflow.
- pub fn init(buffer: []const u8) -> Tokenizer {
+ pub fn init(buffer: []const u8) Tokenizer {
std.debug.assert(buffer[buffer.len - 1] == '\n');
std.debug.assert(buffer[buffer.len - 2] == '\n');
std.debug.assert(buffer[buffer.len - 3] == '\n');
@@ -212,7 +212,7 @@ pub const Tokenizer = struct {
Period2,
};
- pub fn next(self: &Tokenizer) -> Token {
+ pub fn next(self: &Tokenizer) Token {
if (self.pending_invalid_token) |token| {
self.pending_invalid_token = null;
return token;
@@ -528,11 +528,11 @@ pub const Tokenizer = struct {
return result;
}
- pub fn getTokenSlice(self: &const Tokenizer, token: &const Token) -> []const u8 {
+ pub fn getTokenSlice(self: &const Tokenizer, token: &const Token) []const u8 {
return self.buffer[token.start..token.end];
}
- fn checkLiteralCharacter(self: &Tokenizer) {
+ fn checkLiteralCharacter(self: &Tokenizer) void {
if (self.pending_invalid_token != null) return;
const invalid_length = self.getInvalidCharacterLength();
if (invalid_length == 0) return;
@@ -543,7 +543,7 @@ pub const Tokenizer = struct {
};
}
- fn getInvalidCharacterLength(self: &Tokenizer) -> u3 {
+ fn getInvalidCharacterLength(self: &Tokenizer) u3 {
const c0 = self.buffer[self.index];
if (c0 < 0x80) {
if (c0 < 0x20 or c0 == 0x7f) {
@@ -636,7 +636,7 @@ test "tokenizer - illegal unicode codepoints" {
testTokenize("//\xe2\x80\xaa", []Token.Id{});
}
-fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) {
+fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
// (test authors, just make this bigger if you need it)
var padded_source: [0x100]u8 = undefined;
std.mem.copy(u8, padded_source[0..source.len], source);
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 1880b71fbb..49f8e093a0 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -918,9 +918,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
if (fn_type_id->alignment != 0) {
buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment);
}
- if (fn_type_id->return_type->id != TypeTableEntryIdVoid) {
- buf_appendf(&fn_type->name, " -> %s", buf_ptr(&fn_type_id->return_type->name));
- }
+ buf_appendf(&fn_type->name, " %s", buf_ptr(&fn_type_id->return_type->name));
skip_debug_info = skip_debug_info || !fn_type_id->return_type->di_type;
// next, loop over the parameters again and compute debug information
@@ -1082,7 +1080,7 @@ TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
const char *comma_str = (i == 0) ? "" : ",";
buf_appendf(&fn_type->name, "%svar", comma_str);
}
- buf_appendf(&fn_type->name, ")->var");
+ buf_appendf(&fn_type->name, ")var");
fn_type->data.fn.fn_type_id = *fn_type_id;
fn_type->data.fn.is_generic = true;
@@ -2665,7 +2663,7 @@ static bool scope_is_root_decls(Scope *scope) {
static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) {
add_node_error(g, proto_node,
- buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) -> unreachable', found '%s'",
+ buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) unreachable', found '%s'",
buf_ptr(&fn_type->name)));
}
diff --git a/src/ast_render.cpp b/src/ast_render.cpp
index 9910b17f0d..79cbc1b49a 100644
--- a/src/ast_render.cpp
+++ b/src/ast_render.cpp
@@ -450,10 +450,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
}
AstNode *return_type_node = node->data.fn_proto.return_type;
- if (return_type_node != nullptr) {
- fprintf(ar->f, " -> ");
- render_node_grouped(ar, return_type_node);
- }
+ assert(return_type_node != nullptr);
+ fprintf(ar->f, " ");
+ render_node_grouped(ar, return_type_node);
break;
}
case NodeTypeFnDef:
diff --git a/src/parser.cpp b/src/parser.cpp
index 3439ec0c54..12293bc61b 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -84,11 +84,6 @@ static AstNode *ast_create_node(ParseContext *pc, NodeType type, Token *first_to
return node;
}
-static AstNode *ast_create_void_type_node(ParseContext *pc, Token *token) {
- AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);
- node->data.symbol_expr.symbol = pc->void_buf;
- return node;
-}
static void parse_asm_template(ParseContext *pc, AstNode *node) {
Buf *asm_template = node->data.asm_expr.asm_template;
@@ -2245,7 +2240,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
}
/*
-FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("->" TypeExpr)
+FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") TypeExpr
*/
static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) {
Token *first_token = &pc->tokens->at(*token_index);
@@ -2320,12 +2315,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
ast_eat_token(pc, token_index, TokenIdRParen);
next_token = &pc->tokens->at(*token_index);
}
- if (next_token->id == TokenIdArrow) {
- *token_index += 1;
- node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, false);
- } else {
- node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);
- }
+ node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true);
return node;
}
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index 2c00038a48..9bea476352 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -920,7 +920,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
// void foo(void) -> Foo;
// we want to keep the return type AST node.
if (is_c_void_type(proto_node->data.fn_proto.return_type)) {
- proto_node->data.fn_proto.return_type = nullptr;
+ proto_node->data.fn_proto.return_type = trans_create_node_symbol_str(c, "void");
}
}
diff --git a/std/array_list.zig b/std/array_list.zig
index a16dec113c..bc4d3c1d81 100644
--- a/std/array_list.zig
+++ b/std/array_list.zig
@@ -4,11 +4,11 @@ const assert = debug.assert;
const mem = std.mem;
const Allocator = mem.Allocator;
-pub fn ArrayList(comptime T: type) -> type {
+pub fn ArrayList(comptime T: type) type {
return AlignedArrayList(T, @alignOf(T));
}
-pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
+pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
return struct {
const Self = this;
@@ -20,7 +20,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
allocator: &Allocator,
/// Deinitialize with `deinit` or use `toOwnedSlice`.
- pub fn init(allocator: &Allocator) -> Self {
+ pub fn init(allocator: &Allocator) Self {
return Self {
.items = []align(A) T{},
.len = 0,
@@ -28,22 +28,22 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
};
}
- pub fn deinit(l: &Self) {
+ pub fn deinit(l: &Self) void {
l.allocator.free(l.items);
}
- pub fn toSlice(l: &Self) -> []align(A) T {
+ pub fn toSlice(l: &Self) []align(A) T {
return l.items[0..l.len];
}
- pub fn toSliceConst(l: &const Self) -> []align(A) const T {
+ pub fn toSliceConst(l: &const Self) []align(A) const T {
return l.items[0..l.len];
}
/// ArrayList takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
- pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) -> Self {
+ pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {
return Self {
.items = slice,
.len = slice.len,
@@ -52,35 +52,35 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
}
/// The caller owns the returned memory. ArrayList becomes empty.
- pub fn toOwnedSlice(self: &Self) -> []align(A) T {
+ pub fn toOwnedSlice(self: &Self) []align(A) T {
const allocator = self.allocator;
const result = allocator.alignedShrink(T, A, self.items, self.len);
*self = init(allocator);
return result;
}
- pub fn append(l: &Self, item: &const T) -> %void {
+ pub fn append(l: &Self, item: &const T) %void {
const new_item_ptr = try l.addOne();
*new_item_ptr = *item;
}
- pub fn appendSlice(l: &Self, items: []align(A) const T) -> %void {
+ pub fn appendSlice(l: &Self, items: []align(A) const T) %void {
try l.ensureCapacity(l.len + items.len);
mem.copy(T, l.items[l.len..], items);
l.len += items.len;
}
- pub fn resize(l: &Self, new_len: usize) -> %void {
+ pub fn resize(l: &Self, new_len: usize) %void {
try l.ensureCapacity(new_len);
l.len = new_len;
}
- pub fn shrink(l: &Self, new_len: usize) {
+ pub fn shrink(l: &Self, new_len: usize) void {
assert(new_len <= l.len);
l.len = new_len;
}
- pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void {
+ pub fn ensureCapacity(l: &Self, new_capacity: usize) %void {
var better_capacity = l.items.len;
if (better_capacity >= new_capacity) return;
while (true) {
@@ -90,7 +90,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity);
}
- pub fn addOne(l: &Self) -> %&T {
+ pub fn addOne(l: &Self) %&T {
const new_length = l.len + 1;
try l.ensureCapacity(new_length);
const result = &l.items[l.len];
@@ -98,12 +98,12 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
return result;
}
- pub fn pop(self: &Self) -> T {
+ pub fn pop(self: &Self) T {
self.len -= 1;
return self.items[self.len];
}
- pub fn popOrNull(self: &Self) -> ?T {
+ pub fn popOrNull(self: &Self) ?T {
if (self.len == 0)
return null;
return self.pop();
diff --git a/std/base64.zig b/std/base64.zig
index 10650d3243..8cd89b67b5 100644
--- a/std/base64.zig
+++ b/std/base64.zig
@@ -11,7 +11,7 @@ pub const Base64Encoder = struct {
pad_char: u8,
/// a bunch of assertions, then simply pass the data right through.
- pub fn init(alphabet_chars: []const u8, pad_char: u8) -> Base64Encoder {
+ pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64Encoder {
assert(alphabet_chars.len == 64);
var char_in_alphabet = []bool{false} ** 256;
for (alphabet_chars) |c| {
@@ -27,12 +27,12 @@ pub const Base64Encoder = struct {
}
/// ceil(source_len * 4/3)
- pub fn calcSize(source_len: usize) -> usize {
+ pub fn calcSize(source_len: usize) usize {
return @divTrunc(source_len + 2, 3) * 4;
}
/// dest.len must be what you get from ::calcSize.
- pub fn encode(encoder: &const Base64Encoder, dest: []u8, source: []const u8) {
+ pub fn encode(encoder: &const Base64Encoder, dest: []u8, source: []const u8) void {
assert(dest.len == Base64Encoder.calcSize(source.len));
var i: usize = 0;
@@ -90,7 +90,7 @@ pub const Base64Decoder = struct {
char_in_alphabet: [256]bool,
pad_char: u8,
- pub fn init(alphabet_chars: []const u8, pad_char: u8) -> Base64Decoder {
+ pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64Decoder {
assert(alphabet_chars.len == 64);
var result = Base64Decoder{
@@ -111,7 +111,7 @@ pub const Base64Decoder = struct {
}
/// If the encoded buffer is detected to be invalid, returns error.InvalidPadding.
- pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) -> %usize {
+ pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) %usize {
if (source.len % 4 != 0) return error.InvalidPadding;
return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
}
@@ -119,7 +119,7 @@ pub const Base64Decoder = struct {
/// dest.len must be what you get from ::calcSize.
/// invalid characters result in error.InvalidCharacter.
/// invalid padding results in error.InvalidPadding.
- pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) -> %void {
+ pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) %void {
assert(dest.len == (decoder.calcSize(source) catch unreachable));
assert(source.len % 4 == 0);
@@ -168,7 +168,7 @@ error OutputTooSmall;
pub const Base64DecoderWithIgnore = struct {
decoder: Base64Decoder,
char_is_ignored: [256]bool,
- pub fn init(alphabet_chars: []const u8, pad_char: u8, ignore_chars: []const u8) -> Base64DecoderWithIgnore {
+ pub fn init(alphabet_chars: []const u8, pad_char: u8, ignore_chars: []const u8) Base64DecoderWithIgnore {
var result = Base64DecoderWithIgnore {
.decoder = Base64Decoder.init(alphabet_chars, pad_char),
.char_is_ignored = []bool{false} ** 256,
@@ -185,7 +185,7 @@ pub const Base64DecoderWithIgnore = struct {
}
/// If no characters end up being ignored or padding, this will be the exact decoded size.
- pub fn calcSizeUpperBound(encoded_len: usize) -> %usize {
+ pub fn calcSizeUpperBound(encoded_len: usize) %usize {
return @divTrunc(encoded_len, 4) * 3;
}
@@ -193,7 +193,7 @@ pub const Base64DecoderWithIgnore = struct {
/// Invalid padding results in error.InvalidPadding.
/// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound.
/// Returns the number of bytes writen to dest.
- pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) -> %usize {
+ pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) %usize {
const decoder = &decoder_with_ignore.decoder;
var src_cursor: usize = 0;
@@ -293,7 +293,7 @@ pub const Base64DecoderUnsafe = struct {
char_to_index: [256]u8,
pad_char: u8,
- pub fn init(alphabet_chars: []const u8, pad_char: u8) -> Base64DecoderUnsafe {
+ pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64DecoderUnsafe {
assert(alphabet_chars.len == 64);
var result = Base64DecoderUnsafe {
.char_to_index = undefined,
@@ -307,13 +307,13 @@ pub const Base64DecoderUnsafe = struct {
}
/// The source buffer must be valid.
- pub fn calcSize(decoder: &const Base64DecoderUnsafe, source: []const u8) -> usize {
+ pub fn calcSize(decoder: &const Base64DecoderUnsafe, source: []const u8) usize {
return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
}
/// dest.len must be what you get from ::calcDecodedSizeExactUnsafe.
/// invalid characters or padding will result in undefined values.
- pub fn decode(decoder: &const Base64DecoderUnsafe, dest: []u8, source: []const u8) {
+ pub fn decode(decoder: &const Base64DecoderUnsafe, dest: []u8, source: []const u8) void {
assert(dest.len == decoder.calcSize(source));
var src_index: usize = 0;
@@ -359,7 +359,7 @@ pub const Base64DecoderUnsafe = struct {
}
};
-fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize {
+fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) usize {
if (source.len == 0) return 0;
var result = @divExact(source.len, 4) * 3;
if (source[source.len - 1] == pad_char) {
@@ -378,7 +378,7 @@ test "base64" {
comptime (testBase64() catch unreachable);
}
-fn testBase64() -> %void {
+fn testBase64() %void {
try testAllApis("", "");
try testAllApis("f", "Zg==");
try testAllApis("fo", "Zm8=");
@@ -412,7 +412,7 @@ fn testBase64() -> %void {
try testOutputTooSmallError("AAAAAA==");
}
-fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) -> %void {
+fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) %void {
// Base64Encoder
{
var buffer: [0x100]u8 = undefined;
@@ -449,7 +449,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) -> %v
}
}
-fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) -> %void {
+fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) %void {
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
standard_alphabet_chars, standard_pad_char, " ");
var buffer: [0x100]u8 = undefined;
@@ -459,7 +459,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) -> %
}
error ExpectedError;
-fn testError(encoded: []const u8, expected_err: error) -> %void {
+fn testError(encoded: []const u8, expected_err: error) %void {
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
standard_alphabet_chars, standard_pad_char, " ");
var buffer: [0x100]u8 = undefined;
@@ -475,7 +475,7 @@ fn testError(encoded: []const u8, expected_err: error) -> %void {
} else |err| if (err != expected_err) return err;
}
-fn testOutputTooSmallError(encoded: []const u8) -> %void {
+fn testOutputTooSmallError(encoded: []const u8) %void {
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(
standard_alphabet_chars, standard_pad_char, " ");
var buffer: [0x100]u8 = undefined;
diff --git a/std/buf_map.zig b/std/buf_map.zig
index 5063884b2c..15ffe785e6 100644
--- a/std/buf_map.zig
+++ b/std/buf_map.zig
@@ -9,14 +9,14 @@ pub const BufMap = struct {
const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);
- pub fn init(allocator: &Allocator) -> BufMap {
+ pub fn init(allocator: &Allocator) BufMap {
var self = BufMap {
.hash_map = BufMapHashMap.init(allocator),
};
return self;
}
- pub fn deinit(self: &BufMap) {
+ pub fn deinit(self: &BufMap) void {
var it = self.hash_map.iterator();
while (true) {
const entry = it.next() ?? break;
@@ -27,7 +27,7 @@ pub const BufMap = struct {
self.hash_map.deinit();
}
- pub fn set(self: &BufMap, key: []const u8, value: []const u8) -> %void {
+ pub fn set(self: &BufMap, key: []const u8, value: []const u8) %void {
if (self.hash_map.get(key)) |entry| {
const value_copy = try self.copy(value);
errdefer self.free(value_copy);
@@ -42,32 +42,32 @@ pub const BufMap = struct {
}
}
- pub fn get(self: &BufMap, key: []const u8) -> ?[]const u8 {
+ pub fn get(self: &BufMap, key: []const u8) ?[]const u8 {
const entry = self.hash_map.get(key) ?? return null;
return entry.value;
}
- pub fn delete(self: &BufMap, key: []const u8) {
+ pub fn delete(self: &BufMap, key: []const u8) void {
const entry = self.hash_map.remove(key) ?? return;
self.free(entry.key);
self.free(entry.value);
}
- pub fn count(self: &const BufMap) -> usize {
+ pub fn count(self: &const BufMap) usize {
return self.hash_map.size;
}
- pub fn iterator(self: &const BufMap) -> BufMapHashMap.Iterator {
+ pub fn iterator(self: &const BufMap) BufMapHashMap.Iterator {
return self.hash_map.iterator();
}
- fn free(self: &BufMap, value: []const u8) {
+ fn free(self: &BufMap, value: []const u8) void {
// remove the const
const mut_value = @ptrCast(&u8, value.ptr)[0..value.len];
self.hash_map.allocator.free(mut_value);
}
- fn copy(self: &BufMap, value: []const u8) -> %[]const u8 {
+ fn copy(self: &BufMap, value: []const u8) %[]const u8 {
const result = try self.hash_map.allocator.alloc(u8, value.len);
mem.copy(u8, result, value);
return result;
diff --git a/std/buf_set.zig b/std/buf_set.zig
index b5b252911f..2349c17433 100644
--- a/std/buf_set.zig
+++ b/std/buf_set.zig
@@ -7,14 +7,14 @@ pub const BufSet = struct {
const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
- pub fn init(a: &Allocator) -> BufSet {
+ pub fn init(a: &Allocator) BufSet {
var self = BufSet {
.hash_map = BufSetHashMap.init(a),
};
return self;
}
- pub fn deinit(self: &BufSet) {
+ pub fn deinit(self: &BufSet) void {
var it = self.hash_map.iterator();
while (true) {
const entry = it.next() ?? break;
@@ -24,7 +24,7 @@ pub const BufSet = struct {
self.hash_map.deinit();
}
- pub fn put(self: &BufSet, key: []const u8) -> %void {
+ pub fn put(self: &BufSet, key: []const u8) %void {
if (self.hash_map.get(key) == null) {
const key_copy = try self.copy(key);
errdefer self.free(key_copy);
@@ -32,30 +32,30 @@ pub const BufSet = struct {
}
}
- pub fn delete(self: &BufSet, key: []const u8) {
+ pub fn delete(self: &BufSet, key: []const u8) void {
const entry = self.hash_map.remove(key) ?? return;
self.free(entry.key);
}
- pub fn count(self: &const BufSet) -> usize {
+ pub fn count(self: &const BufSet) usize {
return self.hash_map.size;
}
- pub fn iterator(self: &const BufSet) -> BufSetHashMap.Iterator {
+ pub fn iterator(self: &const BufSet) BufSetHashMap.Iterator {
return self.hash_map.iterator();
}
- pub fn allocator(self: &const BufSet) -> &Allocator {
+ pub fn allocator(self: &const BufSet) &Allocator {
return self.hash_map.allocator;
}
- fn free(self: &BufSet, value: []const u8) {
+ fn free(self: &BufSet, value: []const u8) void {
// remove the const
const mut_value = @ptrCast(&u8, value.ptr)[0..value.len];
self.hash_map.allocator.free(mut_value);
}
- fn copy(self: &BufSet, value: []const u8) -> %[]const u8 {
+ fn copy(self: &BufSet, value: []const u8) %[]const u8 {
const result = try self.hash_map.allocator.alloc(u8, value.len);
mem.copy(u8, result, value);
return result;
diff --git a/std/buffer.zig b/std/buffer.zig
index be69eafcfe..34428aa8e4 100644
--- a/std/buffer.zig
+++ b/std/buffer.zig
@@ -12,14 +12,14 @@ pub const Buffer = struct {
list: ArrayList(u8),
/// Must deinitialize with deinit.
- pub fn init(allocator: &Allocator, m: []const u8) -> %Buffer {
+ pub fn init(allocator: &Allocator, m: []const u8) %Buffer {
var self = try initSize(allocator, m.len);
mem.copy(u8, self.list.items, m);
return self;
}
/// Must deinitialize with deinit.
- pub fn initSize(allocator: &Allocator, size: usize) -> %Buffer {
+ pub fn initSize(allocator: &Allocator, size: usize) %Buffer {
var self = initNull(allocator);
try self.resize(size);
return self;
@@ -30,21 +30,21 @@ pub const Buffer = struct {
/// * ::replaceContents
/// * ::replaceContentsBuffer
/// * ::resize
- pub fn initNull(allocator: &Allocator) -> Buffer {
+ pub fn initNull(allocator: &Allocator) Buffer {
return Buffer {
.list = ArrayList(u8).init(allocator),
};
}
/// Must deinitialize with deinit.
- pub fn initFromBuffer(buffer: &const Buffer) -> %Buffer {
+ pub fn initFromBuffer(buffer: &const Buffer) %Buffer {
return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
}
/// Buffer takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Must deinitialize with deinit.
- pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) -> Buffer {
+ pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) Buffer {
var self = Buffer {
.list = ArrayList(u8).fromOwnedSlice(allocator, slice),
};
@@ -54,7 +54,7 @@ pub const Buffer = struct {
/// The caller owns the returned memory. The Buffer becomes null and
/// is safe to `deinit`.
- pub fn toOwnedSlice(self: &Buffer) -> []u8 {
+ pub fn toOwnedSlice(self: &Buffer) []u8 {
const allocator = self.list.allocator;
const result = allocator.shrink(u8, self.list.items, self.len());
*self = initNull(allocator);
@@ -62,55 +62,55 @@ pub const Buffer = struct {
}
- pub fn deinit(self: &Buffer) {
+ pub fn deinit(self: &Buffer) void {
self.list.deinit();
}
- pub fn toSlice(self: &Buffer) -> []u8 {
+ pub fn toSlice(self: &Buffer) []u8 {
return self.list.toSlice()[0..self.len()];
}
- pub fn toSliceConst(self: &const Buffer) -> []const u8 {
+ pub fn toSliceConst(self: &const Buffer) []const u8 {
return self.list.toSliceConst()[0..self.len()];
}
- pub fn shrink(self: &Buffer, new_len: usize) {
+ pub fn shrink(self: &Buffer, new_len: usize) void {
assert(new_len <= self.len());
self.list.shrink(new_len + 1);
self.list.items[self.len()] = 0;
}
- pub fn resize(self: &Buffer, new_len: usize) -> %void {
+ pub fn resize(self: &Buffer, new_len: usize) %void {
try self.list.resize(new_len + 1);
self.list.items[self.len()] = 0;
}
- pub fn isNull(self: &const Buffer) -> bool {
+ pub fn isNull(self: &const Buffer) bool {
return self.list.len == 0;
}
- pub fn len(self: &const Buffer) -> usize {
+ pub fn len(self: &const Buffer) usize {
return self.list.len - 1;
}
- pub fn append(self: &Buffer, m: []const u8) -> %void {
+ pub fn append(self: &Buffer, m: []const u8) %void {
const old_len = self.len();
try self.resize(old_len + m.len);
mem.copy(u8, self.list.toSlice()[old_len..], m);
}
// TODO: remove, use OutStream for this
- pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) -> %void {
+ pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) %void {
return fmt.format(self, append, format, args);
}
// TODO: remove, use OutStream for this
- pub fn appendByte(self: &Buffer, byte: u8) -> %void {
+ pub fn appendByte(self: &Buffer, byte: u8) %void {
return self.appendByteNTimes(byte, 1);
}
// TODO: remove, use OutStream for this
- pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) -> %void {
+ pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) %void {
var prev_size: usize = self.len();
const new_size = prev_size + count;
try self.resize(new_size);
@@ -121,29 +121,29 @@ pub const Buffer = struct {
}
}
- pub fn eql(self: &const Buffer, m: []const u8) -> bool {
+ pub fn eql(self: &const Buffer, m: []const u8) bool {
return mem.eql(u8, self.toSliceConst(), m);
}
- pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {
+ pub fn startsWith(self: &const Buffer, m: []const u8) bool {
if (self.len() < m.len) return false;
return mem.eql(u8, self.list.items[0..m.len], m);
}
- pub fn endsWith(self: &const Buffer, m: []const u8) -> bool {
+ pub fn endsWith(self: &const Buffer, m: []const u8) bool {
const l = self.len();
if (l < m.len) return false;
const start = l - m.len;
return mem.eql(u8, self.list.items[start..l], m);
}
- pub fn replaceContents(self: &const Buffer, m: []const u8) -> %void {
+ pub fn replaceContents(self: &const Buffer, m: []const u8) %void {
try self.resize(m.len);
mem.copy(u8, self.list.toSlice(), m);
}
/// For passing to C functions.
- pub fn ptr(self: &const Buffer) -> &u8 {
+ pub fn ptr(self: &const Buffer) &u8 {
return self.list.items.ptr;
}
};
diff --git a/std/build.zig b/std/build.zig
index 2b61d4971b..6c56988896 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -90,7 +90,7 @@ pub const Builder = struct {
};
pub fn init(allocator: &Allocator, zig_exe: []const u8, build_root: []const u8,
- cache_root: []const u8) -> Builder
+ cache_root: []const u8) Builder
{
var self = Builder {
.zig_exe = zig_exe,
@@ -136,7 +136,7 @@ pub const Builder = struct {
return self;
}
- pub fn deinit(self: &Builder) {
+ pub fn deinit(self: &Builder) void {
self.lib_paths.deinit();
self.include_paths.deinit();
self.rpaths.deinit();
@@ -144,85 +144,85 @@ pub const Builder = struct {
self.top_level_steps.deinit();
}
- pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) {
+ pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) void {
self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default
self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
}
- pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
+ pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
return LibExeObjStep.createExecutable(self, name, root_src);
}
- pub fn addObject(self: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep {
+ pub fn addObject(self: &Builder, name: []const u8, root_src: []const u8) &LibExeObjStep {
return LibExeObjStep.createObject(self, name, root_src);
}
pub fn addSharedLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8,
- ver: &const Version) -> &LibExeObjStep
+ ver: &const Version) &LibExeObjStep
{
return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);
}
- pub fn addStaticLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
+ pub fn addStaticLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
return LibExeObjStep.createStaticLibrary(self, name, root_src);
}
- pub fn addTest(self: &Builder, root_src: []const u8) -> &TestStep {
+ pub fn addTest(self: &Builder, root_src: []const u8) &TestStep {
const test_step = self.allocator.create(TestStep) catch unreachable;
*test_step = TestStep.init(self, root_src);
return test_step;
}
- pub fn addAssemble(self: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep {
+ pub fn addAssemble(self: &Builder, name: []const u8, src: []const u8) &LibExeObjStep {
const obj_step = LibExeObjStep.createObject(self, name, null);
obj_step.addAssemblyFile(src);
return obj_step;
}
- pub fn addCStaticLibrary(self: &Builder, name: []const u8) -> &LibExeObjStep {
+ pub fn addCStaticLibrary(self: &Builder, name: []const u8) &LibExeObjStep {
return LibExeObjStep.createCStaticLibrary(self, name);
}
- pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) -> &LibExeObjStep {
+ pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) &LibExeObjStep {
return LibExeObjStep.createCSharedLibrary(self, name, ver);
}
- pub fn addCExecutable(self: &Builder, name: []const u8) -> &LibExeObjStep {
+ pub fn addCExecutable(self: &Builder, name: []const u8) &LibExeObjStep {
return LibExeObjStep.createCExecutable(self, name);
}
- pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep {
+ pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) &LibExeObjStep {
return LibExeObjStep.createCObject(self, name, src);
}
/// ::argv is copied.
pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
- argv: []const []const u8) -> &CommandStep
+ argv: []const []const u8) &CommandStep
{
return CommandStep.create(self, cwd, env_map, argv);
}
- pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) -> &WriteFileStep {
+ pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) &WriteFileStep {
const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
*write_file_step = WriteFileStep.init(self, file_path, data);
return write_file_step;
}
- pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep {
+ pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) &LogStep {
const data = self.fmt(format, args);
const log_step = self.allocator.create(LogStep) catch unreachable;
*log_step = LogStep.init(self, data);
return log_step;
}
- pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) -> &RemoveDirStep {
+ pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) &RemoveDirStep {
const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
*remove_dir_step = RemoveDirStep.init(self, dir_path);
return remove_dir_step;
}
- pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) -> Version {
+ pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) Version {
return Version {
.major = major,
.minor = minor,
@@ -230,19 +230,19 @@ pub const Builder = struct {
};
}
- pub fn addCIncludePath(self: &Builder, path: []const u8) {
+ pub fn addCIncludePath(self: &Builder, path: []const u8) void {
self.include_paths.append(path) catch unreachable;
}
- pub fn addRPath(self: &Builder, path: []const u8) {
+ pub fn addRPath(self: &Builder, path: []const u8) void {
self.rpaths.append(path) catch unreachable;
}
- pub fn addLibPath(self: &Builder, path: []const u8) {
+ pub fn addLibPath(self: &Builder, path: []const u8) void {
self.lib_paths.append(path) catch unreachable;
}
- pub fn make(self: &Builder, step_names: []const []const u8) -> %void {
+ pub fn make(self: &Builder, step_names: []const []const u8) %void {
var wanted_steps = ArrayList(&Step).init(self.allocator);
defer wanted_steps.deinit();
@@ -260,7 +260,7 @@ pub const Builder = struct {
}
}
- pub fn getInstallStep(self: &Builder) -> &Step {
+ pub fn getInstallStep(self: &Builder) &Step {
if (self.have_install_step)
return &self.install_tls.step;
@@ -269,7 +269,7 @@ pub const Builder = struct {
return &self.install_tls.step;
}
- pub fn getUninstallStep(self: &Builder) -> &Step {
+ pub fn getUninstallStep(self: &Builder) &Step {
if (self.have_uninstall_step)
return &self.uninstall_tls.step;
@@ -278,7 +278,7 @@ pub const Builder = struct {
return &self.uninstall_tls.step;
}
- fn makeUninstall(uninstall_step: &Step) -> %void {
+ fn makeUninstall(uninstall_step: &Step) %void {
const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
@@ -292,7 +292,7 @@ pub const Builder = struct {
// TODO remove empty directories
}
- fn makeOneStep(self: &Builder, s: &Step) -> %void {
+ fn makeOneStep(self: &Builder, s: &Step) %void {
if (s.loop_flag) {
warn("Dependency loop detected:\n {}\n", s.name);
return error.DependencyLoopDetected;
@@ -313,7 +313,7 @@ pub const Builder = struct {
try s.make();
}
- fn getTopLevelStepByName(self: &Builder, name: []const u8) -> %&Step {
+ fn getTopLevelStepByName(self: &Builder, name: []const u8) %&Step {
for (self.top_level_steps.toSliceConst()) |top_level_step| {
if (mem.eql(u8, top_level_step.step.name, name)) {
return &top_level_step.step;
@@ -323,7 +323,7 @@ pub const Builder = struct {
return error.InvalidStepName;
}
- fn processNixOSEnvVars(self: &Builder) {
+ fn processNixOSEnvVars(self: &Builder) void {
if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
var it = mem.split(nix_cflags_compile, " ");
while (true) {
@@ -365,7 +365,7 @@ pub const Builder = struct {
}
}
- pub fn option(self: &Builder, comptime T: type, name: []const u8, description: []const u8) -> ?T {
+ pub fn option(self: &Builder, comptime T: type, name: []const u8, description: []const u8) ?T {
const type_id = comptime typeToEnum(T);
const available_option = AvailableOption {
.name = name,
@@ -418,7 +418,7 @@ pub const Builder = struct {
}
}
- pub fn step(self: &Builder, name: []const u8, description: []const u8) -> &Step {
+ pub fn step(self: &Builder, name: []const u8, description: []const u8) &Step {
const step_info = self.allocator.create(TopLevelStep) catch unreachable;
*step_info = TopLevelStep {
.step = Step.initNoOp(name, self.allocator),
@@ -428,7 +428,7 @@ pub const Builder = struct {
return &step_info.step;
}
- pub fn standardReleaseOptions(self: &Builder) -> builtin.Mode {
+ pub fn standardReleaseOptions(self: &Builder) builtin.Mode {
if (self.release_mode) |mode| return mode;
const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;
@@ -449,7 +449,7 @@ pub const Builder = struct {
return mode;
}
- pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool {
+ pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) bool {
if (self.user_input_options.put(name, UserInputOption {
.name = name,
.value = UserValue { .Scalar = value },
@@ -486,7 +486,7 @@ pub const Builder = struct {
return false;
}
- pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool {
+ pub fn addUserInputFlag(self: &Builder, name: []const u8) bool {
if (self.user_input_options.put(name, UserInputOption {
.name = name,
.value = UserValue {.Flag = {} },
@@ -507,7 +507,7 @@ pub const Builder = struct {
return false;
}
- fn typeToEnum(comptime T: type) -> TypeId {
+ fn typeToEnum(comptime T: type) TypeId {
return switch (@typeId(T)) {
builtin.TypeId.Int => TypeId.Int,
builtin.TypeId.Float => TypeId.Float,
@@ -520,11 +520,11 @@ pub const Builder = struct {
};
}
- fn markInvalidUserInput(self: &Builder) {
+ fn markInvalidUserInput(self: &Builder) void {
self.invalid_user_input = true;
}
- pub fn typeIdName(id: TypeId) -> []const u8 {
+ pub fn typeIdName(id: TypeId) []const u8 {
return switch (id) {
TypeId.Bool => "bool",
TypeId.Int => "int",
@@ -534,7 +534,7 @@ pub const Builder = struct {
};
}
- pub fn validateUserInputDidItFail(self: &Builder) -> bool {
+ pub fn validateUserInputDidItFail(self: &Builder) bool {
// make sure all args are used
var it = self.user_input_options.iterator();
while (true) {
@@ -548,11 +548,11 @@ pub const Builder = struct {
return self.invalid_user_input;
}
- fn spawnChild(self: &Builder, argv: []const []const u8) -> %void {
+ fn spawnChild(self: &Builder, argv: []const []const u8) %void {
return self.spawnChildEnvMap(null, &self.env_map, argv);
}
- fn printCmd(cwd: ?[]const u8, argv: []const []const u8) {
+ fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd);
for (argv) |arg| {
warn("{} ", arg);
@@ -561,7 +561,7 @@ pub const Builder = struct {
}
fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
- argv: []const []const u8) -> %void
+ argv: []const []const u8) %void
{
if (self.verbose) {
printCmd(cwd, argv);
@@ -595,28 +595,28 @@ pub const Builder = struct {
}
}
- pub fn makePath(self: &Builder, path: []const u8) -> %void {
+ pub fn makePath(self: &Builder, path: []const u8) %void {
os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
warn("Unable to create path {}: {}\n", path, @errorName(err));
return err;
};
}
- pub fn installArtifact(self: &Builder, artifact: &LibExeObjStep) {
+ pub fn installArtifact(self: &Builder, artifact: &LibExeObjStep) void {
self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
}
- pub fn addInstallArtifact(self: &Builder, artifact: &LibExeObjStep) -> &InstallArtifactStep {
+ pub fn addInstallArtifact(self: &Builder, artifact: &LibExeObjStep) &InstallArtifactStep {
return InstallArtifactStep.create(self, artifact);
}
///::dest_rel_path is relative to prefix path or it can be an absolute path
- pub fn installFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) {
+ pub fn installFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) void {
self.getInstallStep().dependOn(&self.addInstallFile(src_path, dest_rel_path).step);
}
///::dest_rel_path is relative to prefix path or it can be an absolute path
- pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) -> &InstallFileStep {
+ pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) &InstallFileStep {
const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;
self.pushInstalledFile(full_dest_path);
@@ -625,16 +625,16 @@ pub const Builder = struct {
return install_step;
}
- pub fn pushInstalledFile(self: &Builder, full_path: []const u8) {
+ pub fn pushInstalledFile(self: &Builder, full_path: []const u8) void {
_ = self.getUninstallStep();
self.installed_files.append(full_path) catch unreachable;
}
- fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) -> %void {
+ fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) %void {
return self.copyFileMode(source_path, dest_path, 0o666);
}
- fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: usize) -> %void {
+ fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: usize) %void {
if (self.verbose) {
warn("cp {} {}\n", source_path, dest_path);
}
@@ -651,15 +651,15 @@ pub const Builder = struct {
};
}
- fn pathFromRoot(self: &Builder, rel_path: []const u8) -> []u8 {
+ fn pathFromRoot(self: &Builder, rel_path: []const u8) []u8 {
return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable;
}
- pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 {
+ pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) []u8 {
return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
}
- fn getCCExe(self: &Builder) -> []const u8 {
+ fn getCCExe(self: &Builder) []const u8 {
if (builtin.environ == builtin.Environ.msvc) {
return "cl.exe";
} else {
@@ -672,7 +672,7 @@ pub const Builder = struct {
}
}
- pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {
+ pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) %[]const u8 {
// TODO report error for ambiguous situations
const exe_extension = (Target { .Native = {}}).exeFileExt();
for (self.search_prefixes.toSliceConst()) |search_prefix| {
@@ -721,7 +721,7 @@ pub const Builder = struct {
return error.FileNotFound;
}
- pub fn exec(self: &Builder, argv: []const []const u8) -> %[]u8 {
+ pub fn exec(self: &Builder, argv: []const []const u8) %[]u8 {
const max_output_size = 100 * 1024;
const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size);
switch (result.term) {
@@ -743,7 +743,7 @@ pub const Builder = struct {
}
}
- pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) {
+ pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) void {
self.search_prefixes.append(search_prefix) catch unreachable;
}
};
@@ -764,7 +764,7 @@ pub const Target = union(enum) {
Native: void,
Cross: CrossTarget,
- pub fn oFileExt(self: &const Target) -> []const u8 {
+ pub fn oFileExt(self: &const Target) []const u8 {
const environ = switch (*self) {
Target.Native => builtin.environ,
Target.Cross => |t| t.environ,
@@ -775,42 +775,42 @@ pub const Target = union(enum) {
};
}
- pub fn exeFileExt(self: &const Target) -> []const u8 {
+ pub fn exeFileExt(self: &const Target) []const u8 {
return switch (self.getOs()) {
builtin.Os.windows => ".exe",
else => "",
};
}
- pub fn libFileExt(self: &const Target) -> []const u8 {
+ pub fn libFileExt(self: &const Target) []const u8 {
return switch (self.getOs()) {
builtin.Os.windows => ".lib",
else => ".a",
};
}
- pub fn getOs(self: &const Target) -> builtin.Os {
+ pub fn getOs(self: &const Target) builtin.Os {
return switch (*self) {
Target.Native => builtin.os,
Target.Cross => |t| t.os,
};
}
- pub fn isDarwin(self: &const Target) -> bool {
+ pub fn isDarwin(self: &const Target) bool {
return switch (self.getOs()) {
builtin.Os.ios, builtin.Os.macosx => true,
else => false,
};
}
- pub fn isWindows(self: &const Target) -> bool {
+ pub fn isWindows(self: &const Target) bool {
return switch (self.getOs()) {
builtin.Os.windows => true,
else => false,
};
}
- pub fn wantSharedLibSymLinks(self: &const Target) -> bool {
+ pub fn wantSharedLibSymLinks(self: &const Target) bool {
return !self.isWindows();
}
};
@@ -865,58 +865,58 @@ pub const LibExeObjStep = struct {
};
pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8,
- ver: &const Version) -> &LibExeObjStep
+ ver: &const Version) &LibExeObjStep
{
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
return self;
}
- pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) -> &LibExeObjStep {
+ pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initC(builder, name, Kind.Lib, version, false);
return self;
}
- pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
+ pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
return self;
}
- pub fn createCStaticLibrary(builder: &Builder, name: []const u8) -> &LibExeObjStep {
+ pub fn createCStaticLibrary(builder: &Builder, name: []const u8) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
return self;
}
- pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep {
+ pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
return self;
}
- pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep {
+ pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
self.object_src = src;
return self;
}
- pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
+ pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
return self;
}
- pub fn createCExecutable(builder: &Builder, name: []const u8) -> &LibExeObjStep {
+ pub fn createCExecutable(builder: &Builder, name: []const u8) &LibExeObjStep {
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
*self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
return self;
}
fn initExtraArgs(builder: &Builder, name: []const u8, root_src: ?[]const u8, kind: Kind,
- static: bool, ver: &const Version) -> LibExeObjStep
+ static: bool, ver: &const Version) LibExeObjStep
{
var self = LibExeObjStep {
.strip = false,
@@ -956,7 +956,7 @@ pub const LibExeObjStep = struct {
return self;
}
- fn initC(builder: &Builder, name: []const u8, kind: Kind, version: &const Version, static: bool) -> LibExeObjStep {
+ fn initC(builder: &Builder, name: []const u8, kind: Kind, version: &const Version, static: bool) LibExeObjStep {
var self = LibExeObjStep {
.builder = builder,
.name = name,
@@ -996,7 +996,7 @@ pub const LibExeObjStep = struct {
return self;
}
- fn computeOutFileNames(self: &LibExeObjStep) {
+ fn computeOutFileNames(self: &LibExeObjStep) void {
switch (self.kind) {
Kind.Obj => {
self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
@@ -1031,7 +1031,7 @@ pub const LibExeObjStep = struct {
}
pub fn setTarget(self: &LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os,
- target_environ: builtin.Environ)
+ target_environ: builtin.Environ) void
{
self.target = Target {
.Cross = CrossTarget {
@@ -1044,16 +1044,16 @@ pub const LibExeObjStep = struct {
}
// TODO respect this in the C args
- pub fn setLinkerScriptPath(self: &LibExeObjStep, path: []const u8) {
+ pub fn setLinkerScriptPath(self: &LibExeObjStep, path: []const u8) void {
self.linker_script = path;
}
- pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) {
+ pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) void {
assert(self.target.isDarwin());
self.frameworks.put(framework_name) catch unreachable;
}
- pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) {
+ pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) void {
assert(self.kind != Kind.Obj);
assert(lib.kind == Kind.Lib);
@@ -1074,26 +1074,26 @@ pub const LibExeObjStep = struct {
}
}
- pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) {
+ pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) void {
assert(self.kind != Kind.Obj);
self.link_libs.put(name) catch unreachable;
}
- pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) {
+ pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) void {
assert(self.kind != Kind.Obj);
assert(!self.is_zig);
self.source_files.append(file) catch unreachable;
}
- pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {
+ pub fn setVerboseLink(self: &LibExeObjStep, value: bool) void {
self.verbose_link = value;
}
- pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) {
+ pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) void {
self.build_mode = mode;
}
- pub fn setOutputPath(self: &LibExeObjStep, file_path: []const u8) {
+ pub fn setOutputPath(self: &LibExeObjStep, file_path: []const u8) void {
self.output_path = file_path;
// catch a common mistake
@@ -1102,14 +1102,14 @@ pub const LibExeObjStep = struct {
}
}
- pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 {
+ pub fn getOutputPath(self: &LibExeObjStep) []const u8 {
return if (self.output_path) |output_path|
output_path
else
os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
}
- pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {
+ pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) void {
self.output_h_path = file_path;
// catch a common mistake
@@ -1118,24 +1118,24 @@ pub const LibExeObjStep = struct {
}
}
- pub fn getOutputHPath(self: &LibExeObjStep) -> []const u8 {
+ pub fn getOutputHPath(self: &LibExeObjStep) []const u8 {
return if (self.output_h_path) |output_h_path|
output_h_path
else
os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
}
- pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) {
+ pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) void {
self.assembly_files.append(path) catch unreachable;
}
- pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) {
+ pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) void {
assert(self.kind != Kind.Obj);
self.object_files.append(path) catch unreachable;
}
- pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) {
+ pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) void {
assert(obj.kind == Kind.Obj);
assert(self.kind != Kind.Obj);
@@ -1152,15 +1152,15 @@ pub const LibExeObjStep = struct {
self.include_dirs.append(self.builder.cache_root) catch unreachable;
}
- pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) {
+ pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) void {
self.include_dirs.append(path) catch unreachable;
}
- pub fn addLibPath(self: &LibExeObjStep, path: []const u8) {
+ pub fn addLibPath(self: &LibExeObjStep, path: []const u8) void {
self.lib_paths.append(path) catch unreachable;
}
- pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) {
+ pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
assert(self.is_zig);
self.packages.append(Pkg {
@@ -1169,23 +1169,23 @@ pub const LibExeObjStep = struct {
}) catch unreachable;
}
- pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) {
+ pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) void {
for (flags) |flag| {
self.cflags.append(flag) catch unreachable;
}
}
- pub fn setNoStdLib(self: &LibExeObjStep, disable: bool) {
+ pub fn setNoStdLib(self: &LibExeObjStep, disable: bool) void {
assert(!self.is_zig);
self.disable_libc = disable;
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(LibExeObjStep, "step", step);
return if (self.is_zig) self.makeZig() else self.makeC();
}
- fn makeZig(self: &LibExeObjStep) -> %void {
+ fn makeZig(self: &LibExeObjStep) %void {
const builder = self.builder;
assert(self.is_zig);
@@ -1351,7 +1351,7 @@ pub const LibExeObjStep = struct {
}
}
- fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) {
+ fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) void {
if (!self.strip) {
args.append("-g") catch unreachable;
}
@@ -1396,7 +1396,7 @@ pub const LibExeObjStep = struct {
}
}
- fn makeC(self: &LibExeObjStep) -> %void {
+ fn makeC(self: &LibExeObjStep) %void {
const builder = self.builder;
const cc = builder.getCCExe();
@@ -1635,7 +1635,7 @@ pub const TestStep = struct {
target: Target,
exec_cmd_args: ?[]const ?[]const u8,
- pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {
+ pub fn init(builder: &Builder, root_src: []const u8) TestStep {
const step_name = builder.fmt("test {}", root_src);
return TestStep {
.step = Step.init(step_name, builder.allocator, make),
@@ -1651,28 +1651,28 @@ pub const TestStep = struct {
};
}
- pub fn setVerbose(self: &TestStep, value: bool) {
+ pub fn setVerbose(self: &TestStep, value: bool) void {
self.verbose = value;
}
- pub fn setBuildMode(self: &TestStep, mode: builtin.Mode) {
+ pub fn setBuildMode(self: &TestStep, mode: builtin.Mode) void {
self.build_mode = mode;
}
- pub fn linkSystemLibrary(self: &TestStep, name: []const u8) {
+ pub fn linkSystemLibrary(self: &TestStep, name: []const u8) void {
self.link_libs.put(name) catch unreachable;
}
- pub fn setNamePrefix(self: &TestStep, text: []const u8) {
+ pub fn setNamePrefix(self: &TestStep, text: []const u8) void {
self.name_prefix = text;
}
- pub fn setFilter(self: &TestStep, text: ?[]const u8) {
+ pub fn setFilter(self: &TestStep, text: ?[]const u8) void {
self.filter = text;
}
pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os,
- target_environ: builtin.Environ)
+ target_environ: builtin.Environ) void
{
self.target = Target {
.Cross = CrossTarget {
@@ -1683,11 +1683,11 @@ pub const TestStep = struct {
};
}
- pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) {
+ pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) void {
self.exec_cmd_args = args;
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(TestStep, "step", step);
const builder = self.builder;
@@ -1781,7 +1781,7 @@ pub const CommandStep = struct {
/// ::argv is copied.
pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
- argv: []const []const u8) -> &CommandStep
+ argv: []const []const u8) &CommandStep
{
const self = builder.allocator.create(CommandStep) catch unreachable;
*self = CommandStep {
@@ -1796,7 +1796,7 @@ pub const CommandStep = struct {
return self;
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(CommandStep, "step", step);
const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;
@@ -1812,7 +1812,7 @@ const InstallArtifactStep = struct {
const Self = this;
- pub fn create(builder: &Builder, artifact: &LibExeObjStep) -> &Self {
+ pub fn create(builder: &Builder, artifact: &LibExeObjStep) &Self {
const self = builder.allocator.create(Self) catch unreachable;
const dest_dir = switch (artifact.kind) {
LibExeObjStep.Kind.Obj => unreachable,
@@ -1836,7 +1836,7 @@ const InstallArtifactStep = struct {
return self;
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(Self, "step", step);
const builder = self.builder;
@@ -1859,7 +1859,7 @@ pub const InstallFileStep = struct {
src_path: []const u8,
dest_path: []const u8,
- pub fn init(builder: &Builder, src_path: []const u8, dest_path: []const u8) -> InstallFileStep {
+ pub fn init(builder: &Builder, src_path: []const u8, dest_path: []const u8) InstallFileStep {
return InstallFileStep {
.builder = builder,
.step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),
@@ -1868,7 +1868,7 @@ pub const InstallFileStep = struct {
};
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(InstallFileStep, "step", step);
try self.builder.copyFile(self.src_path, self.dest_path);
}
@@ -1880,7 +1880,7 @@ pub const WriteFileStep = struct {
file_path: []const u8,
data: []const u8,
- pub fn init(builder: &Builder, file_path: []const u8, data: []const u8) -> WriteFileStep {
+ pub fn init(builder: &Builder, file_path: []const u8, data: []const u8) WriteFileStep {
return WriteFileStep {
.builder = builder,
.step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),
@@ -1889,7 +1889,7 @@ pub const WriteFileStep = struct {
};
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(WriteFileStep, "step", step);
const full_path = self.builder.pathFromRoot(self.file_path);
const full_path_dir = os.path.dirname(full_path);
@@ -1909,7 +1909,7 @@ pub const LogStep = struct {
builder: &Builder,
data: []const u8,
- pub fn init(builder: &Builder, data: []const u8) -> LogStep {
+ pub fn init(builder: &Builder, data: []const u8) LogStep {
return LogStep {
.builder = builder,
.step = Step.init(builder.fmt("log {}", data), builder.allocator, make),
@@ -1917,7 +1917,7 @@ pub const LogStep = struct {
};
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(LogStep, "step", step);
warn("{}", self.data);
}
@@ -1928,7 +1928,7 @@ pub const RemoveDirStep = struct {
builder: &Builder,
dir_path: []const u8,
- pub fn init(builder: &Builder, dir_path: []const u8) -> RemoveDirStep {
+ pub fn init(builder: &Builder, dir_path: []const u8) RemoveDirStep {
return RemoveDirStep {
.builder = builder,
.step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),
@@ -1936,7 +1936,7 @@ pub const RemoveDirStep = struct {
};
}
- fn make(step: &Step) -> %void {
+ fn make(step: &Step) %void {
const self = @fieldParentPtr(RemoveDirStep, "step", step);
const full_path = self.builder.pathFromRoot(self.dir_path);
@@ -1949,12 +1949,12 @@ pub const RemoveDirStep = struct {
pub const Step = struct {
name: []const u8,
- makeFn: fn(self: &Step) -> %void,
+ makeFn: fn(self: &Step) %void,
dependencies: ArrayList(&Step),
loop_flag: bool,
done_flag: bool,
- pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)->%void) -> Step {
+ pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)%void) Step {
return Step {
.name = name,
.makeFn = makeFn,
@@ -1963,11 +1963,11 @@ pub const Step = struct {
.done_flag = false,
};
}
- pub fn initNoOp(name: []const u8, allocator: &Allocator) -> Step {
+ pub fn initNoOp(name: []const u8, allocator: &Allocator) Step {
return init(name, allocator, makeNoOp);
}
- pub fn make(self: &Step) -> %void {
+ pub fn make(self: &Step) %void {
if (self.done_flag)
return;
@@ -1975,15 +1975,15 @@ pub const Step = struct {
self.done_flag = true;
}
- pub fn dependOn(self: &Step, other: &Step) {
+ pub fn dependOn(self: &Step, other: &Step) void {
self.dependencies.append(other) catch unreachable;
}
- fn makeNoOp(self: &Step) -> %void {}
+ fn makeNoOp(self: &Step) %void {}
};
fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_major_only: []const u8,
- filename_name_only: []const u8) -> %void
+ filename_name_only: []const u8) %void
{
const out_dir = os.path.dirname(output_path);
const out_basename = os.path.basename(output_path);
diff --git a/std/c/darwin.zig b/std/c/darwin.zig
index 006dcc066b..f0890d4ec0 100644
--- a/std/c/darwin.zig
+++ b/std/c/darwin.zig
@@ -1,5 +1,5 @@
-extern "c" fn __error() -> &c_int;
-pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) -> c_int;
+extern "c" fn __error() &c_int;
+pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;
pub use @import("../os/darwin_errno.zig");
@@ -41,7 +41,7 @@ pub const sigset_t = u32;
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
pub const Sigaction = extern struct {
- handler: extern fn(c_int),
+ handler: extern fn(c_int)void,
sa_mask: sigset_t,
sa_flags: c_int,
};
diff --git a/std/c/index.zig b/std/c/index.zig
index 58359ed131..7b34ccea82 100644
--- a/std/c/index.zig
+++ b/std/c/index.zig
@@ -9,43 +9,43 @@ pub use switch(builtin.os) {
};
const empty_import = @import("../empty.zig");
-pub extern "c" fn abort() -> noreturn;
-pub extern "c" fn exit(code: c_int) -> noreturn;
-pub extern "c" fn isatty(fd: c_int) -> c_int;
-pub extern "c" fn close(fd: c_int) -> c_int;
-pub extern "c" fn fstat(fd: c_int, buf: &Stat) -> c_int;
-pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: &Stat) -> c_int;
-pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) -> isize;
-pub extern "c" fn open(path: &const u8, oflag: c_int, ...) -> c_int;
-pub extern "c" fn raise(sig: c_int) -> c_int;
-pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) -> isize;
-pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) -> c_int;
-pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) -> c_int;
+pub extern "c" fn abort() noreturn;
+pub extern "c" fn exit(code: c_int) noreturn;
+pub extern "c" fn isatty(fd: c_int) c_int;
+pub extern "c" fn close(fd: c_int) c_int;
+pub extern "c" fn fstat(fd: c_int, buf: &Stat) c_int;
+pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: &Stat) c_int;
+pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize;
+pub extern "c" fn open(path: &const u8, oflag: c_int, ...) c_int;
+pub extern "c" fn raise(sig: c_int) c_int;
+pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) isize;
+pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) c_int;
+pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) c_int;
pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int,
- fd: c_int, offset: isize) -> ?&c_void;
-pub extern "c" fn munmap(addr: &c_void, len: usize) -> c_int;
-pub extern "c" fn unlink(path: &const u8) -> c_int;
-pub extern "c" fn getcwd(buf: &u8, size: usize) -> ?&u8;
-pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) -> c_int;
-pub extern "c" fn fork() -> c_int;
-pub extern "c" fn pipe(fds: &c_int) -> c_int;
-pub extern "c" fn mkdir(path: &const u8, mode: c_uint) -> c_int;
-pub extern "c" fn symlink(existing: &const u8, new: &const u8) -> c_int;
-pub extern "c" fn rename(old: &const u8, new: &const u8) -> c_int;
-pub extern "c" fn chdir(path: &const u8) -> c_int;
+ fd: c_int, offset: isize) ?&c_void;
+pub extern "c" fn munmap(addr: &c_void, len: usize) c_int;
+pub extern "c" fn unlink(path: &const u8) c_int;
+pub extern "c" fn getcwd(buf: &u8, size: usize) ?&u8;
+pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) c_int;
+pub extern "c" fn fork() c_int;
+pub extern "c" fn pipe(fds: &c_int) c_int;
+pub extern "c" fn mkdir(path: &const u8, mode: c_uint) c_int;
+pub extern "c" fn symlink(existing: &const u8, new: &const u8) c_int;
+pub extern "c" fn rename(old: &const u8, new: &const u8) c_int;
+pub extern "c" fn chdir(path: &const u8) c_int;
pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8,
- envp: &const ?&const u8) -> c_int;
-pub extern "c" fn dup(fd: c_int) -> c_int;
-pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) -> c_int;
-pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) -> isize;
-pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) -> ?&u8;
-pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) -> c_int;
-pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> c_int;
-pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?×pec) -> c_int;
-pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) -> c_int;
-pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) -> c_int;
+ envp: &const ?&const u8) c_int;
+pub extern "c" fn dup(fd: c_int) c_int;
+pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
+pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
+pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
+pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
+pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
+pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?×pec) c_int;
+pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
+pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
-pub extern "c" fn malloc(usize) -> ?&c_void;
-pub extern "c" fn realloc(&c_void, usize) -> ?&c_void;
-pub extern "c" fn free(&c_void);
-pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) -> c_int;
+pub extern "c" fn malloc(usize) ?&c_void;
+pub extern "c" fn realloc(&c_void, usize) ?&c_void;
+pub extern "c" fn free(&c_void) void;
+pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int;
diff --git a/std/c/linux.zig b/std/c/linux.zig
index 48ba90351b..6378955795 100644
--- a/std/c/linux.zig
+++ b/std/c/linux.zig
@@ -1,5 +1,5 @@
pub use @import("../os/linux_errno.zig");
-pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) -> c_int;
-extern "c" fn __errno_location() -> &c_int;
+pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) c_int;
+extern "c" fn __errno_location() &c_int;
pub const _errno = __errno_location;
diff --git a/std/c/windows.zig b/std/c/windows.zig
index 6df1067ebf..6e8b17eda8 100644
--- a/std/c/windows.zig
+++ b/std/c/windows.zig
@@ -1 +1 @@
-pub extern "c" fn _errno() -> &c_int;
+pub extern "c" fn _errno() &c_int;
diff --git a/std/crypto/blake2.zig b/std/crypto/blake2.zig
index 7c943c752a..ea0a68b184 100644
--- a/std/crypto/blake2.zig
+++ b/std/crypto/blake2.zig
@@ -9,7 +9,7 @@ const RoundParam = struct {
a: usize, b: usize, c: usize, d: usize, x: usize, y: usize,
};
-fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) -> RoundParam {
+fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) RoundParam {
return RoundParam { .a = a, .b = b, .c = c, .d = d, .x = x, .y = y, };
}
@@ -19,7 +19,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) -> RoundParam
pub const Blake2s224 = Blake2s(224);
pub const Blake2s256 = Blake2s(256);
-fn Blake2s(comptime out_len: usize) -> type { return struct {
+fn Blake2s(comptime out_len: usize) type { return struct {
const Self = this;
const block_size = 64;
const digest_size = out_len / 8;
@@ -48,7 +48,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct {
buf: [64]u8,
buf_len: u8,
- pub fn init() -> Self {
+ pub fn init() Self {
debug.assert(8 <= out_len and out_len <= 512);
var s: Self = undefined;
@@ -56,7 +56,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct {
return s;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
mem.copy(u32, d.h[0..], iv[0..]);
// No key plus default parameters
@@ -65,13 +65,13 @@ fn Blake2s(comptime out_len: usize) -> type { return struct {
d.buf_len = 0;
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Self.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var off: usize = 0;
// Partial buffer exists from previous update. Copy into buffer then hash.
@@ -94,7 +94,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct {
d.buf_len += u8(b[off..].len);
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
debug.assert(out.len >= out_len / 8);
mem.set(u8, d.buf[d.buf_len..], 0);
@@ -108,7 +108,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct {
}
}
- fn round(d: &Self, b: []const u8, last: bool) {
+ fn round(d: &Self, b: []const u8, last: bool) void {
debug.assert(b.len == 64);
var m: [16]u32 = undefined;
@@ -236,7 +236,7 @@ test "blake2s256 streaming" {
pub const Blake2b384 = Blake2b(384);
pub const Blake2b512 = Blake2b(512);
-fn Blake2b(comptime out_len: usize) -> type { return struct {
+fn Blake2b(comptime out_len: usize) type { return struct {
const Self = this;
const block_size = 128;
const digest_size = out_len / 8;
@@ -269,7 +269,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct {
buf: [128]u8,
buf_len: u8,
- pub fn init() -> Self {
+ pub fn init() Self {
debug.assert(8 <= out_len and out_len <= 512);
var s: Self = undefined;
@@ -277,7 +277,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct {
return s;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
mem.copy(u64, d.h[0..], iv[0..]);
// No key plus default parameters
@@ -286,13 +286,13 @@ fn Blake2b(comptime out_len: usize) -> type { return struct {
d.buf_len = 0;
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Self.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var off: usize = 0;
// Partial buffer exists from previous update. Copy into buffer then hash.
@@ -315,7 +315,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct {
d.buf_len += u8(b[off..].len);
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
mem.set(u8, d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);
@@ -327,7 +327,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct {
}
}
- fn round(d: &Self, b: []const u8, last: bool) {
+ fn round(d: &Self, b: []const u8, last: bool) void {
debug.assert(b.len == 128);
var m: [16]u64 = undefined;
diff --git a/std/crypto/md5.zig b/std/crypto/md5.zig
index b0c40a8424..313bff91bf 100644
--- a/std/crypto/md5.zig
+++ b/std/crypto/md5.zig
@@ -10,7 +10,7 @@ const RoundParam = struct {
k: usize, s: u32, t: u32
};
-fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) -> RoundParam {
+fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundParam {
return RoundParam { .a = a, .b = b, .c = c, .d = d, .k = k, .s = s, .t = t };
}
@@ -25,13 +25,13 @@ pub const Md5 = struct {
buf_len: u8,
total_len: u64,
- pub fn init() -> Self {
+ pub fn init() Self {
var d: Self = undefined;
d.reset();
return d;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
d.s[0] = 0x67452301;
d.s[1] = 0xEFCDAB89;
d.s[2] = 0x98BADCFE;
@@ -40,13 +40,13 @@ pub const Md5 = struct {
d.total_len = 0;
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Md5.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var off: usize = 0;
// Partial buffer exists from previous update. Copy into buffer then hash.
@@ -71,7 +71,7 @@ pub const Md5 = struct {
d.total_len +%= b.len;
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
debug.assert(out.len >= 16);
// The buffer here will never be completely full.
@@ -103,7 +103,7 @@ pub const Md5 = struct {
}
}
- fn round(d: &Self, b: []const u8) {
+ fn round(d: &Self, b: []const u8) void {
debug.assert(b.len == 64);
var s: [16]u32 = undefined;
diff --git a/std/crypto/sha1.zig b/std/crypto/sha1.zig
index 94f29bde44..f0dd3c3377 100644
--- a/std/crypto/sha1.zig
+++ b/std/crypto/sha1.zig
@@ -10,7 +10,7 @@ const RoundParam = struct {
a: usize, b: usize, c: usize, d: usize, e: usize, i: u32,
};
-fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) -> RoundParam {
+fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam {
return RoundParam { .a = a, .b = b, .c = c, .d = d, .e = e, .i = i };
}
@@ -25,13 +25,13 @@ pub const Sha1 = struct {
buf_len: u8,
total_len: u64,
- pub fn init() -> Self {
+ pub fn init() Self {
var d: Self = undefined;
d.reset();
return d;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
d.s[0] = 0x67452301;
d.s[1] = 0xEFCDAB89;
d.s[2] = 0x98BADCFE;
@@ -41,13 +41,13 @@ pub const Sha1 = struct {
d.total_len = 0;
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Sha1.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var off: usize = 0;
// Partial buffer exists from previous update. Copy into buffer then hash.
@@ -71,7 +71,7 @@ pub const Sha1 = struct {
d.total_len += b.len;
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
debug.assert(out.len >= 20);
// The buffer here will never be completely full.
@@ -103,7 +103,7 @@ pub const Sha1 = struct {
}
}
- fn round(d: &Self, b: []const u8) {
+ fn round(d: &Self, b: []const u8) void {
debug.assert(b.len == 64);
var s: [16]u32 = undefined;
diff --git a/std/crypto/sha2.zig b/std/crypto/sha2.zig
index deb65cd321..bfb604d456 100644
--- a/std/crypto/sha2.zig
+++ b/std/crypto/sha2.zig
@@ -13,7 +13,7 @@ const RoundParam256 = struct {
i: usize, k: u32,
};
-fn Rp256(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u32) -> RoundParam256 {
+fn Rp256(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u32) RoundParam256 {
return RoundParam256 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k };
}
@@ -56,7 +56,7 @@ const Sha256Params = Sha2Params32 {
pub const Sha224 = Sha2_32(Sha224Params);
pub const Sha256 = Sha2_32(Sha256Params);
-fn Sha2_32(comptime params: Sha2Params32) -> type { return struct {
+fn Sha2_32(comptime params: Sha2Params32) type { return struct {
const Self = this;
const block_size = 64;
const digest_size = params.out_len / 8;
@@ -67,13 +67,13 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct {
buf_len: u8,
total_len: u64,
- pub fn init() -> Self {
+ pub fn init() Self {
var d: Self = undefined;
d.reset();
return d;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
d.s[0] = params.iv0;
d.s[1] = params.iv1;
d.s[2] = params.iv2;
@@ -86,13 +86,13 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct {
d.total_len = 0;
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Self.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var off: usize = 0;
// Partial buffer exists from previous update. Copy into buffer then hash.
@@ -116,7 +116,7 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct {
d.total_len += b.len;
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
debug.assert(out.len >= params.out_len / 8);
// The buffer here will never be completely full.
@@ -151,7 +151,7 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct {
}
}
- fn round(d: &Self, b: []const u8) {
+ fn round(d: &Self, b: []const u8) void {
debug.assert(b.len == 64);
var s: [64]u32 = undefined;
@@ -329,7 +329,7 @@ const RoundParam512 = struct {
i: usize, k: u64,
};
-fn Rp512(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u64) -> RoundParam512 {
+fn Rp512(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u64) RoundParam512 {
return RoundParam512 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k };
}
@@ -372,7 +372,7 @@ const Sha512Params = Sha2Params64 {
pub const Sha384 = Sha2_64(Sha384Params);
pub const Sha512 = Sha2_64(Sha512Params);
-fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
+fn Sha2_64(comptime params: Sha2Params64) type { return struct {
const Self = this;
const block_size = 128;
const digest_size = params.out_len / 8;
@@ -383,13 +383,13 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
buf_len: u8,
total_len: u128,
- pub fn init() -> Self {
+ pub fn init() Self {
var d: Self = undefined;
d.reset();
return d;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
d.s[0] = params.iv0;
d.s[1] = params.iv1;
d.s[2] = params.iv2;
@@ -402,13 +402,13 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
d.total_len = 0;
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Self.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var off: usize = 0;
// Partial buffer exists from previous update. Copy into buffer then hash.
@@ -432,7 +432,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
d.total_len += b.len;
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
debug.assert(out.len >= params.out_len / 8);
// The buffer here will never be completely full.
@@ -467,7 +467,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
}
}
- fn round(d: &Self, b: []const u8) {
+ fn round(d: &Self, b: []const u8) void {
debug.assert(b.len == 128);
var s: [80]u64 = undefined;
diff --git a/std/crypto/sha3.zig b/std/crypto/sha3.zig
index 8ba7cf20d5..759ddf43aa 100644
--- a/std/crypto/sha3.zig
+++ b/std/crypto/sha3.zig
@@ -10,7 +10,7 @@ pub const Sha3_256 = Keccak(256, 0x06);
pub const Sha3_384 = Keccak(384, 0x06);
pub const Sha3_512 = Keccak(512, 0x06);
-fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct {
+fn Keccak(comptime bits: usize, comptime delim: u8) type { return struct {
const Self = this;
const block_size = 200;
const digest_size = bits / 8;
@@ -19,25 +19,25 @@ fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct {
offset: usize,
rate: usize,
- pub fn init() -> Self {
+ pub fn init() Self {
var d: Self = undefined;
d.reset();
return d;
}
- pub fn reset(d: &Self) {
+ pub fn reset(d: &Self) void {
mem.set(u8, d.s[0..], 0);
d.offset = 0;
d.rate = 200 - (bits / 4);
}
- pub fn hash(b: []const u8, out: []u8) {
+ pub fn hash(b: []const u8, out: []u8) void {
var d = Self.init();
d.update(b);
d.final(out);
}
- pub fn update(d: &Self, b: []const u8) {
+ pub fn update(d: &Self, b: []const u8) void {
var ip: usize = 0;
var len = b.len;
var rate = d.rate - d.offset;
@@ -62,7 +62,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct {
d.offset = offset + len;
}
- pub fn final(d: &Self, out: []u8) {
+ pub fn final(d: &Self, out: []u8) void {
// padding
d.s[d.offset] ^= delim;
d.s[d.rate - 1] ^= 0x80;
@@ -109,7 +109,7 @@ const M5 = []const usize {
0, 1, 2, 3, 4, 0, 1, 2, 3, 4
};
-fn keccak_f(comptime F: usize, d: []u8) {
+fn keccak_f(comptime F: usize, d: []u8) void {
debug.assert(d.len == F / 8);
const B = F / 25;
diff --git a/std/crypto/test.zig b/std/crypto/test.zig
index a357988901..e41c6a7a2d 100644
--- a/std/crypto/test.zig
+++ b/std/crypto/test.zig
@@ -3,7 +3,7 @@ const mem = @import("../mem.zig");
const fmt = @import("../fmt/index.zig");
// Hash using the specified hasher `H` asserting `expected == H(input)`.
-pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) {
+pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void {
var h: [expected.len / 2]u8 = undefined;
Hasher.hash(input, h[0..]);
@@ -11,7 +11,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
}
// Assert `expected` == `input` where `input` is a bytestring.
-pub fn assertEqual(comptime expected: []const u8, input: []const u8) {
+pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
var expected_bytes: [expected.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
*r = fmt.parseInt(u8, expected[2*i .. 2*i+2], 16) catch unreachable;
diff --git a/std/crypto/throughput_test.zig b/std/crypto/throughput_test.zig
index 5285af3ed6..1ebe64d5a4 100644
--- a/std/crypto/throughput_test.zig
+++ b/std/crypto/throughput_test.zig
@@ -18,7 +18,7 @@ const c = @cImport({
const Mb = 1024 * 1024;
-pub fn main() -> %void {
+pub fn main() %void {
var stdout_file = try std.io.getStdOut();
var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
const stdout = &stdout_out_stream.stream;
diff --git a/std/cstr.zig b/std/cstr.zig
index 31fb4ccca7..987c6d3341 100644
--- a/std/cstr.zig
+++ b/std/cstr.zig
@@ -3,13 +3,13 @@ const debug = std.debug;
const mem = std.mem;
const assert = debug.assert;
-pub fn len(ptr: &const u8) -> usize {
+pub fn len(ptr: &const u8) usize {
var count: usize = 0;
while (ptr[count] != 0) : (count += 1) {}
return count;
}
-pub fn cmp(a: &const u8, b: &const u8) -> i8 {
+pub fn cmp(a: &const u8, b: &const u8) i8 {
var index: usize = 0;
while (a[index] == b[index] and a[index] != 0) : (index += 1) {}
if (a[index] > b[index]) {
@@ -21,11 +21,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 {
}
}
-pub fn toSliceConst(str: &const u8) -> []const u8 {
+pub fn toSliceConst(str: &const u8) []const u8 {
return str[0..len(str)];
}
-pub fn toSlice(str: &u8) -> []u8 {
+pub fn toSlice(str: &u8) []u8 {
return str[0..len(str)];
}
@@ -34,7 +34,7 @@ test "cstr fns" {
testCStrFnsImpl();
}
-fn testCStrFnsImpl() {
+fn testCStrFnsImpl() void {
assert(cmp(c"aoeu", c"aoez") == -1);
assert(len(c"123456789") == 9);
}
@@ -42,7 +42,7 @@ fn testCStrFnsImpl() {
/// Returns a mutable slice with exactly the same size which is guaranteed to
/// have a null byte after it.
/// Caller owns the returned memory.
-pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) -> %[]u8 {
+pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) %[]u8 {
const result = try allocator.alloc(u8, slice.len + 1);
mem.copy(u8, result, slice);
result[slice.len] = 0;
@@ -56,7 +56,7 @@ pub const NullTerminated2DArray = struct {
/// Takes N lists of strings, concatenates the lists together, and adds a null terminator
/// Caller must deinit result
- pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) -> %NullTerminated2DArray {
+ pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) %NullTerminated2DArray {
var new_len: usize = 1; // 1 for the list null
var byte_count: usize = 0;
for (slices) |slice| {
@@ -96,7 +96,7 @@ pub const NullTerminated2DArray = struct {
};
}
- pub fn deinit(self: &NullTerminated2DArray) {
+ pub fn deinit(self: &NullTerminated2DArray) void {
const buf = @ptrCast(&u8, self.ptr);
self.allocator.free(buf[0..self.byte_count]);
}
diff --git a/std/debug/failing_allocator.zig b/std/debug/failing_allocator.zig
index 2076a4cf1f..cc5a8bc045 100644
--- a/std/debug/failing_allocator.zig
+++ b/std/debug/failing_allocator.zig
@@ -12,7 +12,7 @@ pub const FailingAllocator = struct {
freed_bytes: usize,
deallocations: usize,
- pub fn init(allocator: &mem.Allocator, fail_index: usize) -> FailingAllocator {
+ pub fn init(allocator: &mem.Allocator, fail_index: usize) FailingAllocator {
return FailingAllocator {
.internal_allocator = allocator,
.fail_index = fail_index,
@@ -28,7 +28,7 @@ pub const FailingAllocator = struct {
};
}
- fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) -> %[]u8 {
+ fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) %[]u8 {
const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
if (self.index == self.fail_index) {
return error.OutOfMemory;
@@ -39,7 +39,7 @@ pub const FailingAllocator = struct {
return result;
}
- fn realloc(allocator: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
+ fn realloc(allocator: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
if (new_size <= old_mem.len) {
self.freed_bytes += old_mem.len - new_size;
@@ -55,7 +55,7 @@ pub const FailingAllocator = struct {
return result;
}
- fn free(allocator: &mem.Allocator, bytes: []u8) {
+ fn free(allocator: &mem.Allocator, bytes: []u8) void {
const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
self.freed_bytes += bytes.len;
self.deallocations += 1;
diff --git a/std/debug/index.zig b/std/debug/index.zig
index df5cc0a322..ccf5f6d413 100644
--- a/std/debug/index.zig
+++ b/std/debug/index.zig
@@ -25,11 +25,11 @@ error TodoSupportCOFFDebugInfo;
var stderr_file: io.File = undefined;
var stderr_file_out_stream: io.FileOutStream = undefined;
var stderr_stream: ?&io.OutStream = null;
-pub fn warn(comptime fmt: []const u8, args: ...) {
+pub fn warn(comptime fmt: []const u8, args: ...) void {
const stderr = getStderrStream() catch return;
stderr.print(fmt, args) catch return;
}
-fn getStderrStream() -> %&io.OutStream {
+fn getStderrStream() %&io.OutStream {
if (stderr_stream) |st| {
return st;
} else {
@@ -42,7 +42,7 @@ fn getStderrStream() -> %&io.OutStream {
}
var self_debug_info: ?&ElfStackTrace = null;
-pub fn getSelfDebugInfo() -> %&ElfStackTrace {
+pub fn getSelfDebugInfo() %&ElfStackTrace {
if (self_debug_info) |info| {
return info;
} else {
@@ -53,7 +53,7 @@ pub fn getSelfDebugInfo() -> %&ElfStackTrace {
}
/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
-pub fn dumpCurrentStackTrace() {
+pub fn dumpCurrentStackTrace() void {
const stderr = getStderrStream() catch return;
const debug_info = getSelfDebugInfo() catch |err| {
stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return;
@@ -67,7 +67,7 @@ pub fn dumpCurrentStackTrace() {
}
/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
-pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) {
+pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) void {
const stderr = getStderrStream() catch return;
const debug_info = getSelfDebugInfo() catch |err| {
stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return;
@@ -85,7 +85,7 @@ pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) {
/// generated, and the `unreachable` statement triggers a panic.
/// In ReleaseFast and ReleaseSmall modes, calls to this function can be
/// optimized away.
-pub fn assert(ok: bool) {
+pub fn assert(ok: bool) void {
if (!ok) {
// In ReleaseFast test mode, we still want assert(false) to crash, so
// we insert an explicit call to @panic instead of unreachable.
@@ -100,7 +100,7 @@ pub fn assert(ok: bool) {
/// Call this function when you want to panic if the condition is not true.
/// If `ok` is `false`, this function will panic in every release mode.
-pub fn assertOrPanic(ok: bool) {
+pub fn assertOrPanic(ok: bool) void {
if (!ok) {
@panic("assertion failure");
}
@@ -108,7 +108,7 @@ pub fn assertOrPanic(ok: bool) {
var panicking = false;
/// This is the default panic implementation.
-pub fn panic(comptime format: []const u8, args: ...) -> noreturn {
+pub fn panic(comptime format: []const u8, args: ...) noreturn {
// TODO an intrinsic that labels this as unlikely to be reached
// TODO
@@ -130,7 +130,7 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn {
os.abort();
}
-pub fn panicWithTrace(trace: &const builtin.StackTrace, comptime format: []const u8, args: ...) -> noreturn {
+pub fn panicWithTrace(trace: &const builtin.StackTrace, comptime format: []const u8, args: ...) noreturn {
if (panicking) {
os.abort();
} else {
@@ -153,7 +153,7 @@ error PathNotFound;
error InvalidDebugInfo;
pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: &io.OutStream, allocator: &mem.Allocator,
- debug_info: &ElfStackTrace, tty_color: bool) -> %void
+ debug_info: &ElfStackTrace, tty_color: bool) %void
{
var frame_index: usize = undefined;
var frames_left: usize = undefined;
@@ -175,7 +175,7 @@ pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: &io.O
}
pub fn writeCurrentStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator,
- debug_info: &ElfStackTrace, tty_color: bool, ignore_frame_count: usize) -> %void
+ debug_info: &ElfStackTrace, tty_color: bool, ignore_frame_count: usize) %void
{
var ignored_count: usize = 0;
@@ -191,7 +191,7 @@ pub fn writeCurrentStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocat
}
}
-fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, address: usize) -> %void {
+fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, address: usize) %void {
if (builtin.os == builtin.Os.windows) {
return error.UnsupportedDebugInfo;
}
@@ -232,7 +232,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, a
}
}
-pub fn openSelfDebugInfo(allocator: &mem.Allocator) -> %&ElfStackTrace {
+pub fn openSelfDebugInfo(allocator: &mem.Allocator) %&ElfStackTrace {
switch (builtin.object_format) {
builtin.ObjectFormat.elf => {
const st = try allocator.create(ElfStackTrace);
@@ -276,7 +276,7 @@ pub fn openSelfDebugInfo(allocator: &mem.Allocator) -> %&ElfStackTrace {
}
}
-fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_info: &const LineInfo) -> %void {
+fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_info: &const LineInfo) %void {
var f = try io.File.openRead(line_info.file_name, allocator);
defer f.close();
// TODO fstat and make sure that the file has the correct size
@@ -320,17 +320,17 @@ pub const ElfStackTrace = struct {
abbrev_table_list: ArrayList(AbbrevTableHeader),
compile_unit_list: ArrayList(CompileUnit),
- pub fn allocator(self: &const ElfStackTrace) -> &mem.Allocator {
+ pub fn allocator(self: &const ElfStackTrace) &mem.Allocator {
return self.abbrev_table_list.allocator;
}
- pub fn readString(self: &ElfStackTrace) -> %[]u8 {
+ pub fn readString(self: &ElfStackTrace) %[]u8 {
var in_file_stream = io.FileInStream.init(&self.self_exe_file);
const in_stream = &in_file_stream.stream;
return readStringRaw(self.allocator(), in_stream);
}
- pub fn close(self: &ElfStackTrace) {
+ pub fn close(self: &ElfStackTrace) void {
self.self_exe_file.close();
self.elf.close();
}
@@ -387,7 +387,7 @@ const Constant = struct {
payload: []u8,
signed: bool,
- fn asUnsignedLe(self: &const Constant) -> %u64 {
+ fn asUnsignedLe(self: &const Constant) %u64 {
if (self.payload.len > @sizeOf(u64))
return error.InvalidDebugInfo;
if (self.signed)
@@ -406,7 +406,7 @@ const Die = struct {
value: FormValue,
};
- fn getAttr(self: &const Die, id: u64) -> ?&const FormValue {
+ fn getAttr(self: &const Die, id: u64) ?&const FormValue {
for (self.attrs.toSliceConst()) |*attr| {
if (attr.id == id)
return &attr.value;
@@ -414,7 +414,7 @@ const Die = struct {
return null;
}
- fn getAttrAddr(self: &const Die, id: u64) -> %u64 {
+ fn getAttrAddr(self: &const Die, id: u64) %u64 {
const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
return switch (*form_value) {
FormValue.Address => |value| value,
@@ -422,7 +422,7 @@ const Die = struct {
};
}
- fn getAttrSecOffset(self: &const Die, id: u64) -> %u64 {
+ fn getAttrSecOffset(self: &const Die, id: u64) %u64 {
const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
return switch (*form_value) {
FormValue.Const => |value| value.asUnsignedLe(),
@@ -431,7 +431,7 @@ const Die = struct {
};
}
- fn getAttrUnsignedLe(self: &const Die, id: u64) -> %u64 {
+ fn getAttrUnsignedLe(self: &const Die, id: u64) %u64 {
const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
return switch (*form_value) {
FormValue.Const => |value| value.asUnsignedLe(),
@@ -439,7 +439,7 @@ const Die = struct {
};
}
- fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) -> %[]u8 {
+ fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) %[]u8 {
const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
return switch (*form_value) {
FormValue.String => |value| value,
@@ -462,7 +462,7 @@ const LineInfo = struct {
file_name: []u8,
allocator: &mem.Allocator,
- fn deinit(self: &const LineInfo) {
+ fn deinit(self: &const LineInfo) void {
self.allocator.free(self.file_name);
}
};
@@ -489,7 +489,7 @@ const LineNumberProgram = struct {
prev_end_sequence: bool,
pub fn init(is_stmt: bool, include_dirs: []const []const u8,
- file_entries: &ArrayList(FileEntry), target_address: usize) -> LineNumberProgram
+ file_entries: &ArrayList(FileEntry), target_address: usize) LineNumberProgram
{
return LineNumberProgram {
.address = 0,
@@ -512,7 +512,7 @@ const LineNumberProgram = struct {
};
}
- pub fn checkLineMatch(self: &LineNumberProgram) -> %?LineInfo {
+ pub fn checkLineMatch(self: &LineNumberProgram) %?LineInfo {
if (self.target_address >= self.prev_address and self.target_address < self.address) {
const file_entry = if (self.prev_file == 0) {
return error.MissingDebugInfo;
@@ -544,7 +544,7 @@ const LineNumberProgram = struct {
}
};
-fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 {
+fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) %[]u8 {
var buf = ArrayList(u8).init(allocator);
while (true) {
const byte = try in_stream.readByte();
@@ -555,58 +555,58 @@ fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 {
return buf.toSlice();
}
-fn getString(st: &ElfStackTrace, offset: u64) -> %[]u8 {
+fn getString(st: &ElfStackTrace, offset: u64) %[]u8 {
const pos = st.debug_str.offset + offset;
try st.self_exe_file.seekTo(pos);
return st.readString();
}
-fn readAllocBytes(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %[]u8 {
+fn readAllocBytes(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %[]u8 {
const buf = try global_allocator.alloc(u8, size);
errdefer global_allocator.free(buf);
if ((try in_stream.read(buf)) < size) return error.EndOfFile;
return buf;
}
-fn parseFormValueBlockLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue {
+fn parseFormValueBlockLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %FormValue {
const buf = try readAllocBytes(allocator, in_stream, size);
return FormValue { .Block = buf };
}
-fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue {
+fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %FormValue {
const block_len = try in_stream.readVarInt(builtin.Endian.Little, usize, size);
return parseFormValueBlockLen(allocator, in_stream, block_len);
}
-fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) -> %FormValue {
+fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) %FormValue {
return FormValue { .Const = Constant {
.signed = signed,
.payload = try readAllocBytes(allocator, in_stream, size),
}};
}
-fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) -> %u64 {
+fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) %u64 {
return if (is_64) try in_stream.readIntLe(u64)
else u64(try in_stream.readIntLe(u32)) ;
}
-fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {
+fn parseFormValueTargetAddrSize(in_stream: &io.InStream) %u64 {
return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLe(u32))
else if (@sizeOf(usize) == 8) try in_stream.readIntLe(u64)
else unreachable;
}
-fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue {
+fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %FormValue {
const buf = try readAllocBytes(allocator, in_stream, size);
return FormValue { .Ref = buf };
}
-fn parseFormValueRef(allocator: &mem.Allocator, in_stream: &io.InStream, comptime T: type) -> %FormValue {
+fn parseFormValueRef(allocator: &mem.Allocator, in_stream: &io.InStream, comptime T: type) %FormValue {
const block_len = try in_stream.readIntLe(T);
return parseFormValueRefLen(allocator, in_stream, block_len);
}
-fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u64, is_64: bool) -> %FormValue {
+fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u64, is_64: bool) %FormValue {
return switch (form_id) {
DW.FORM_addr => FormValue { .Address = try parseFormValueTargetAddrSize(in_stream) },
DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),
@@ -656,7 +656,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
};
}
-fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable {
+fn parseAbbrevTable(st: &ElfStackTrace) %AbbrevTable {
const in_file = &st.self_exe_file;
var in_file_stream = io.FileInStream.init(in_file);
const in_stream = &in_file_stream.stream;
@@ -688,7 +688,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable {
/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
/// seeks in the stream and parses it.
-fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) -> %&const AbbrevTable {
+fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) %&const AbbrevTable {
for (st.abbrev_table_list.toSlice()) |*header| {
if (header.offset == abbrev_offset) {
return &header.table;
@@ -702,7 +702,7 @@ fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) -> %&const AbbrevTable
return &st.abbrev_table_list.items[st.abbrev_table_list.len - 1].table;
}
-fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) -> ?&const AbbrevTableEntry {
+fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) ?&const AbbrevTableEntry {
for (abbrev_table.toSliceConst()) |*table_entry| {
if (table_entry.abbrev_code == abbrev_code)
return table_entry;
@@ -710,7 +710,7 @@ fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) -> ?&
return null;
}
-fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) -> %Die {
+fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) %Die {
const in_file = &st.self_exe_file;
var in_file_stream = io.FileInStream.init(in_file);
const in_stream = &in_file_stream.stream;
@@ -732,7 +732,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) -
return result;
}
-fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, target_address: usize) -> %LineInfo {
+fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, target_address: usize) %LineInfo {
const compile_unit_cwd = try compile_unit.die.getAttrString(st, DW.AT_comp_dir);
const in_file = &st.self_exe_file;
@@ -910,7 +910,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe
return error.MissingDebugInfo;
}
-fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
+fn scanAllCompileUnits(st: &ElfStackTrace) %void {
const debug_info_end = st.debug_info.offset + st.debug_info.size;
var this_unit_offset = st.debug_info.offset;
var cu_index: usize = 0;
@@ -986,7 +986,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
}
}
-fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUnit {
+fn findCompileUnit(st: &ElfStackTrace, target_address: u64) %&const CompileUnit {
var in_file_stream = io.FileInStream.init(&st.self_exe_file);
const in_stream = &in_file_stream.stream;
for (st.compile_unit_list.toSlice()) |*compile_unit| {
@@ -1022,7 +1022,7 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUn
return error.MissingDebugInfo;
}
-fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 {
+fn readInitialLength(in_stream: &io.InStream, is_64: &bool) %u64 {
const first_32_bits = try in_stream.readIntLe(u32);
*is_64 = (first_32_bits == 0xffffffff);
if (*is_64) {
@@ -1033,7 +1033,7 @@ fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 {
}
}
-fn readULeb128(in_stream: &io.InStream) -> %u64 {
+fn readULeb128(in_stream: &io.InStream) %u64 {
var result: u64 = 0;
var shift: usize = 0;
@@ -1054,7 +1054,7 @@ fn readULeb128(in_stream: &io.InStream) -> %u64 {
}
}
-fn readILeb128(in_stream: &io.InStream) -> %i64 {
+fn readILeb128(in_stream: &io.InStream) %i64 {
var result: i64 = 0;
var shift: usize = 0;
diff --git a/std/elf.zig b/std/elf.zig
index 377bd76f11..59e2150c69 100644
--- a/std/elf.zig
+++ b/std/elf.zig
@@ -81,14 +81,14 @@ pub const Elf = struct {
prealloc_file: io.File,
/// Call close when done.
- pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) -> %void {
+ pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) %void {
try elf.prealloc_file.open(path);
try elf.openFile(allocator, &elf.prealloc_file);
elf.auto_close_stream = true;
}
/// Call close when done.
- pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &io.File) -> %void {
+ pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &io.File) %void {
elf.allocator = allocator;
elf.in_file = file;
elf.auto_close_stream = false;
@@ -232,14 +232,14 @@ pub const Elf = struct {
}
}
- pub fn close(elf: &Elf) {
+ pub fn close(elf: &Elf) void {
elf.allocator.free(elf.section_headers);
if (elf.auto_close_stream)
elf.in_file.close();
}
- pub fn findSection(elf: &Elf, name: []const u8) -> %?&SectionHeader {
+ pub fn findSection(elf: &Elf, name: []const u8) %?&SectionHeader {
var file_stream = io.FileInStream.init(elf.in_file);
const in = &file_stream.stream;
@@ -263,7 +263,7 @@ pub const Elf = struct {
return null;
}
- pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) -> %void {
+ pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) %void {
try elf.in_file.seekTo(elf_section.offset);
}
};
diff --git a/std/endian.zig b/std/endian.zig
index 4e67cfc7a5..121505d24d 100644
--- a/std/endian.zig
+++ b/std/endian.zig
@@ -1,19 +1,19 @@
const mem = @import("mem.zig");
const builtin = @import("builtin");
-pub fn swapIfLe(comptime T: type, x: T) -> T {
+pub fn swapIfLe(comptime T: type, x: T) T {
return swapIf(builtin.Endian.Little, T, x);
}
-pub fn swapIfBe(comptime T: type, x: T) -> T {
+pub fn swapIfBe(comptime T: type, x: T) T {
return swapIf(builtin.Endian.Big, T, x);
}
-pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T {
+pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) T {
return if (builtin.endian == endian) swap(T, x) else x;
}
-pub fn swap(comptime T: type, x: T) -> T {
+pub fn swap(comptime T: type, x: T) T {
var buf: [@sizeOf(T)]u8 = undefined;
mem.writeInt(buf[0..], x, builtin.Endian.Little);
return mem.readInt(buf, T, builtin.Endian.Big);
diff --git a/std/fmt/errol/enum3.zig b/std/fmt/errol/enum3.zig
index feb84da9a4..f8299d3c6f 100644
--- a/std/fmt/errol/enum3.zig
+++ b/std/fmt/errol/enum3.zig
@@ -438,7 +438,7 @@ const Slab = struct {
exp: i32,
};
-fn slab(str: []const u8, exp: i32) -> Slab {
+fn slab(str: []const u8, exp: i32) Slab {
return Slab {
.str = str,
.exp = exp,
diff --git a/std/fmt/errol/index.zig b/std/fmt/errol/index.zig
index ba4447c631..42287bd25b 100644
--- a/std/fmt/errol/index.zig
+++ b/std/fmt/errol/index.zig
@@ -13,7 +13,7 @@ pub const FloatDecimal = struct {
};
/// Corrected Errol3 double to ASCII conversion.
-pub fn errol3(value: f64, buffer: []u8) -> FloatDecimal {
+pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
const bits = @bitCast(u64, value);
const i = tableLowerBound(bits);
if (i < enum3.len and enum3[i] == bits) {
@@ -30,7 +30,7 @@ pub fn errol3(value: f64, buffer: []u8) -> FloatDecimal {
}
/// Uncorrected Errol3 double to ASCII conversion.
-fn errol3u(val: f64, buffer: []u8) -> FloatDecimal {
+fn errol3u(val: f64, buffer: []u8) FloatDecimal {
// check if in integer or fixed range
if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) {
@@ -133,7 +133,7 @@ fn errol3u(val: f64, buffer: []u8) -> FloatDecimal {
};
}
-fn tableLowerBound(k: u64) -> usize {
+fn tableLowerBound(k: u64) usize {
var i = enum3.len;
var j: usize = 0;
@@ -153,7 +153,7 @@ fn tableLowerBound(k: u64) -> usize {
/// @in: The HP number.
/// @val: The double.
/// &returns: The HP number.
-fn hpProd(in: &const HP, val: f64) -> HP {
+fn hpProd(in: &const HP, val: f64) HP {
var hi: f64 = undefined;
var lo: f64 = undefined;
split(in.val, &hi, &lo);
@@ -175,12 +175,12 @@ fn hpProd(in: &const HP, val: f64) -> HP {
/// @val: The double.
/// @hi: The high bits.
/// @lo: The low bits.
-fn split(val: f64, hi: &f64, lo: &f64) {
+fn split(val: f64, hi: &f64, lo: &f64) void {
*hi = gethi(val);
*lo = val - *hi;
}
-fn gethi(in: f64) -> f64 {
+fn gethi(in: f64) f64 {
const bits = @bitCast(u64, in);
const new_bits = bits & 0xFFFFFFFFF8000000;
return @bitCast(f64, new_bits);
@@ -188,7 +188,7 @@ fn gethi(in: f64) -> f64 {
/// Normalize the number by factoring in the error.
/// @hp: The float pair.
-fn hpNormalize(hp: &HP) {
+fn hpNormalize(hp: &HP) void {
const val = hp.val;
hp.val += hp.off;
@@ -197,7 +197,7 @@ fn hpNormalize(hp: &HP) {
/// Divide the high-precision number by ten.
/// @hp: The high-precision number
-fn hpDiv10(hp: &HP) {
+fn hpDiv10(hp: &HP) void {
var val = hp.val;
hp.val /= 10.0;
@@ -213,7 +213,7 @@ fn hpDiv10(hp: &HP) {
/// Multiply the high-precision number by ten.
/// @hp: The high-precision number
-fn hpMul10(hp: &HP) {
+fn hpMul10(hp: &HP) void {
const val = hp.val;
hp.val *= 10.0;
@@ -233,7 +233,7 @@ fn hpMul10(hp: &HP) {
/// @val: The val.
/// @buf: The output buffer.
/// &return: The exponent.
-fn errolInt(val: f64, buffer: []u8) -> FloatDecimal {
+fn errolInt(val: f64, buffer: []u8) FloatDecimal {
const pow19 = u128(1e19);
assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
@@ -291,7 +291,7 @@ fn errolInt(val: f64, buffer: []u8) -> FloatDecimal {
/// @val: The val.
/// @buf: The output buffer.
/// &return: The exponent.
-fn errolFixed(val: f64, buffer: []u8) -> FloatDecimal {
+fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
assert((val >= 16.0) and (val < 9.007199254740992e15));
const u = u64(val);
@@ -347,11 +347,11 @@ fn errolFixed(val: f64, buffer: []u8) -> FloatDecimal {
};
}
-fn fpnext(val: f64) -> f64 {
+fn fpnext(val: f64) f64 {
return @bitCast(f64, @bitCast(u64, val) +% 1);
}
-fn fpprev(val: f64) -> f64 {
+fn fpprev(val: f64) f64 {
return @bitCast(f64, @bitCast(u64, val) -% 1);
}
@@ -373,7 +373,7 @@ pub const c_digits_lut = []u8 {
'9', '8', '9', '9',
};
-fn u64toa(value_param: u64, buffer: []u8) -> usize {
+fn u64toa(value_param: u64, buffer: []u8) usize {
var value = value_param;
const kTen8: u64 = 100000000;
const kTen9: u64 = kTen8 * 10;
@@ -606,7 +606,7 @@ fn u64toa(value_param: u64, buffer: []u8) -> usize {
return buf_index;
}
-fn fpeint(from: f64) -> u128 {
+fn fpeint(from: f64) u128 {
const bits = @bitCast(u64, from);
assert((bits & ((1 << 52) - 1)) == 0);
@@ -621,7 +621,7 @@ fn fpeint(from: f64) -> u128 {
/// @a: Integer a.
/// @b: Integer b.
/// &returns: An index within [0, 19).
-fn mismatch10(a: u64, b: u64) -> i32 {
+fn mismatch10(a: u64, b: u64) i32 {
const pow10 = 10000000000;
const af = a / pow10;
const bf = b / pow10;
diff --git a/std/fmt/index.zig b/std/fmt/index.zig
index 4c4a809e6a..b7ae018bdc 100644
--- a/std/fmt/index.zig
+++ b/std/fmt/index.zig
@@ -24,8 +24,8 @@ const State = enum { // TODO put inside format function and make sure the name a
/// Renders fmt string with args, calling output with slices of bytes.
/// If `output` returns an error, the error is returned from `format` and
/// `output` is not called again.
-pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
- comptime fmt: []const u8, args: ...) -> %void
+pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void,
+ comptime fmt: []const u8, args: ...) %void
{
comptime var start_index = 0;
comptime var state = State.Start;
@@ -191,7 +191,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
}
}
-pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void {
+pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
const T = @typeOf(value);
switch (@typeId(T)) {
builtin.TypeId.Int => {
@@ -240,12 +240,12 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
}
}
-pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void {
+pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
return output(context, (&c)[0..1]);
}
pub fn formatBuf(buf: []const u8, width: usize,
- context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void
+ context: var, output: fn(@typeOf(context), []const u8)%void) %void
{
try output(context, buf);
@@ -256,7 +256,7 @@ pub fn formatBuf(buf: []const u8, width: usize,
}
}
-pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void {
+pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
var x = f64(value);
// Errol doesn't handle these special cases.
@@ -294,7 +294,7 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons
}
}
-pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void {
+pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn(@typeOf(context), []const u8)%void) %void {
var x = f64(value);
// Errol doesn't handle these special cases.
@@ -336,7 +336,7 @@ pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn
pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
- context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void
+ context: var, output: fn(@typeOf(context), []const u8)%void) %void
{
if (@typeOf(value).is_signed) {
return formatIntSigned(value, base, uppercase, width, context, output);
@@ -346,7 +346,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
}
fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
- context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void
+ context: var, output: fn(@typeOf(context), []const u8)%void) %void
{
const uint = @IntType(false, @typeOf(value).bit_count);
if (value < 0) {
@@ -367,7 +367,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
}
fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
- context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void
+ context: var, output: fn(@typeOf(context), []const u8)%void) %void
{
// max_int_digits accounts for the minus sign. when printing an unsigned
// number we don't need to do that.
@@ -405,7 +405,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
}
}
-pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> usize {
+pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize {
var context = FormatIntBuf {
.out_buf = out_buf,
.index = 0,
@@ -417,12 +417,12 @@ const FormatIntBuf = struct {
out_buf: []u8,
index: usize,
};
-fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) -> %void {
+fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) %void {
mem.copy(u8, context.out_buf[context.index..], bytes);
context.index += bytes.len;
}
-pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T {
+pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) %T {
if (!T.is_signed)
return parseUnsigned(T, buf, radix);
if (buf.len == 0)
@@ -446,7 +446,7 @@ test "fmt.parseInt" {
assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
}
-pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) -> %T {
+pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) %T {
var x: T = 0;
for (buf) |c| {
@@ -459,7 +459,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) -> %T {
}
error InvalidChar;
-fn charToDigit(c: u8, radix: u8) -> %u8 {
+fn charToDigit(c: u8, radix: u8) %u8 {
const value = switch (c) {
'0' ... '9' => c - '0',
'A' ... 'Z' => c - 'A' + 10,
@@ -473,7 +473,7 @@ fn charToDigit(c: u8, radix: u8) -> %u8 {
return value;
}
-fn digitToChar(digit: u8, uppercase: bool) -> u8 {
+fn digitToChar(digit: u8, uppercase: bool) u8 {
return switch (digit) {
0 ... 9 => digit + '0',
10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
@@ -486,19 +486,19 @@ const BufPrintContext = struct {
};
error BufferTooSmall;
-fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) -> %void {
+fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) %void {
if (context.remaining.len < bytes.len) return error.BufferTooSmall;
mem.copy(u8, context.remaining, bytes);
context.remaining = context.remaining[bytes.len..];
}
-pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 {
+pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) %[]u8 {
var context = BufPrintContext { .remaining = buf, };
try format(&context, bufPrintWrite, fmt, args);
return buf[0..buf.len - context.remaining.len];
}
-pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {
+pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) %[]u8 {
var size: usize = 0;
// Cannot fail because `countSize` cannot fail.
format(&size, countSize, fmt, args) catch unreachable;
@@ -506,7 +506,7 @@ pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...
return bufPrint(buf, fmt, args);
}
-fn countSize(size: &usize, bytes: []const u8) -> %void {
+fn countSize(size: &usize, bytes: []const u8) %void {
*size += bytes.len;
}
@@ -528,7 +528,7 @@ test "buf print int" {
assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42"));
}
-fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> []u8 {
+fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) []u8 {
return buf[0..formatIntBuf(buf, value, base, uppercase, width)];
}
@@ -644,7 +644,7 @@ test "fmt.format" {
}
}
-pub fn trim(buf: []const u8) -> []const u8 {
+pub fn trim(buf: []const u8) []const u8 {
var start: usize = 0;
while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) { }
@@ -671,7 +671,7 @@ test "fmt.trim" {
assert(mem.eql(u8, "abc", trim("abc ")));
}
-pub fn isWhiteSpace(byte: u8) -> bool {
+pub fn isWhiteSpace(byte: u8) bool {
return switch (byte) {
' ', '\t', '\n', '\r' => true,
else => false,
diff --git a/std/hash_map.zig b/std/hash_map.zig
index 2cd08d1280..96ec10b933 100644
--- a/std/hash_map.zig
+++ b/std/hash_map.zig
@@ -10,8 +10,8 @@ const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast;
const debug_u32 = if (want_modification_safety) u32 else void;
pub fn HashMap(comptime K: type, comptime V: type,
- comptime hash: fn(key: K)->u32,
- comptime eql: fn(a: K, b: K)->bool) -> type
+ comptime hash: fn(key: K)u32,
+ comptime eql: fn(a: K, b: K)bool) type
{
return struct {
entries: []Entry,
@@ -39,7 +39,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
// used to detect concurrent modification
initial_modification_count: debug_u32,
- pub fn next(it: &Iterator) -> ?&Entry {
+ pub fn next(it: &Iterator) ?&Entry {
if (want_modification_safety) {
assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification
}
@@ -56,7 +56,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
}
};
- pub fn init(allocator: &Allocator) -> Self {
+ pub fn init(allocator: &Allocator) Self {
return Self {
.entries = []Entry{},
.allocator = allocator,
@@ -66,11 +66,11 @@ pub fn HashMap(comptime K: type, comptime V: type,
};
}
- pub fn deinit(hm: &Self) {
+ pub fn deinit(hm: &Self) void {
hm.allocator.free(hm.entries);
}
- pub fn clear(hm: &Self) {
+ pub fn clear(hm: &Self) void {
for (hm.entries) |*entry| {
entry.used = false;
}
@@ -80,7 +80,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
}
/// Returns the value that was already there.
- pub fn put(hm: &Self, key: K, value: &const V) -> %?V {
+ pub fn put(hm: &Self, key: K, value: &const V) %?V {
if (hm.entries.len == 0) {
try hm.initCapacity(16);
}
@@ -102,18 +102,18 @@ pub fn HashMap(comptime K: type, comptime V: type,
return hm.internalPut(key, value);
}
- pub fn get(hm: &Self, key: K) -> ?&Entry {
+ pub fn get(hm: &Self, key: K) ?&Entry {
if (hm.entries.len == 0) {
return null;
}
return hm.internalGet(key);
}
- pub fn contains(hm: &Self, key: K) -> bool {
+ pub fn contains(hm: &Self, key: K) bool {
return hm.get(key) != null;
}
- pub fn remove(hm: &Self, key: K) -> ?&Entry {
+ pub fn remove(hm: &Self, key: K) ?&Entry {
hm.incrementModificationCount();
const start_index = hm.keyToIndex(key);
{var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) {
@@ -142,7 +142,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
return null;
}
- pub fn iterator(hm: &const Self) -> Iterator {
+ pub fn iterator(hm: &const Self) Iterator {
return Iterator {
.hm = hm,
.count = 0,
@@ -151,7 +151,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
};
}
- fn initCapacity(hm: &Self, capacity: usize) -> %void {
+ fn initCapacity(hm: &Self, capacity: usize) %void {
hm.entries = try hm.allocator.alloc(Entry, capacity);
hm.size = 0;
hm.max_distance_from_start_index = 0;
@@ -160,14 +160,14 @@ pub fn HashMap(comptime K: type, comptime V: type,
}
}
- fn incrementModificationCount(hm: &Self) {
+ fn incrementModificationCount(hm: &Self) void {
if (want_modification_safety) {
hm.modification_count +%= 1;
}
}
/// Returns the value that was already there.
- fn internalPut(hm: &Self, orig_key: K, orig_value: &const V) -> ?V {
+ fn internalPut(hm: &Self, orig_key: K, orig_value: &const V) ?V {
var key = orig_key;
var value = *orig_value;
const start_index = hm.keyToIndex(key);
@@ -217,7 +217,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
unreachable; // put into a full map
}
- fn internalGet(hm: &Self, key: K) -> ?&Entry {
+ fn internalGet(hm: &Self, key: K) ?&Entry {
const start_index = hm.keyToIndex(key);
{var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) {
const index = (start_index + roll_over) % hm.entries.len;
@@ -229,7 +229,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
return null;
}
- fn keyToIndex(hm: &Self, key: K) -> usize {
+ fn keyToIndex(hm: &Self, key: K) usize {
return usize(hash(key)) % hm.entries.len;
}
};
@@ -254,10 +254,10 @@ test "basicHashMapTest" {
assert(map.get(2) == null);
}
-fn hash_i32(x: i32) -> u32 {
+fn hash_i32(x: i32) u32 {
return @bitCast(u32, x);
}
-fn eql_i32(a: i32, b: i32) -> bool {
+fn eql_i32(a: i32, b: i32) bool {
return a == b;
}
diff --git a/std/heap.zig b/std/heap.zig
index f88ac9b1a6..f023e7376d 100644
--- a/std/heap.zig
+++ b/std/heap.zig
@@ -18,14 +18,14 @@ var c_allocator_state = Allocator {
.freeFn = cFree,
};
-fn cAlloc(self: &Allocator, n: usize, alignment: u29) -> %[]u8 {
+fn cAlloc(self: &Allocator, n: usize, alignment: u29) %[]u8 {
return if (c.malloc(usize(n))) |buf|
@ptrCast(&u8, buf)[0..n]
else
error.OutOfMemory;
}
-fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
+fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
const old_ptr = @ptrCast(&c_void, old_mem.ptr);
if (c.realloc(old_ptr, new_size)) |buf| {
return @ptrCast(&u8, buf)[0..new_size];
@@ -36,7 +36,7 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ->
}
}
-fn cFree(self: &Allocator, old_mem: []u8) {
+fn cFree(self: &Allocator, old_mem: []u8) void {
const old_ptr = @ptrCast(&c_void, old_mem.ptr);
c.free(old_ptr);
}
@@ -47,7 +47,7 @@ pub const IncrementingAllocator = struct {
end_index: usize,
heap_handle: if (builtin.os == Os.windows) os.windows.HANDLE else void,
- fn init(capacity: usize) -> %IncrementingAllocator {
+ fn init(capacity: usize) %IncrementingAllocator {
switch (builtin.os) {
Os.linux, Os.macosx, Os.ios => {
const p = os.posix;
@@ -85,7 +85,7 @@ pub const IncrementingAllocator = struct {
}
}
- fn deinit(self: &IncrementingAllocator) {
+ fn deinit(self: &IncrementingAllocator) void {
switch (builtin.os) {
Os.linux, Os.macosx, Os.ios => {
_ = os.posix.munmap(self.bytes.ptr, self.bytes.len);
@@ -97,15 +97,15 @@ pub const IncrementingAllocator = struct {
}
}
- fn reset(self: &IncrementingAllocator) {
+ fn reset(self: &IncrementingAllocator) void {
self.end_index = 0;
}
- fn bytesLeft(self: &const IncrementingAllocator) -> usize {
+ fn bytesLeft(self: &const IncrementingAllocator) usize {
return self.bytes.len - self.end_index;
}
- fn alloc(allocator: &Allocator, n: usize, alignment: u29) -> %[]u8 {
+ fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 {
const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator);
const addr = @ptrToInt(&self.bytes[self.end_index]);
const rem = @rem(addr, alignment);
@@ -120,7 +120,7 @@ pub const IncrementingAllocator = struct {
return result;
}
- fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
+ fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
if (new_size <= old_mem.len) {
return old_mem[0..new_size];
} else {
@@ -130,7 +130,7 @@ pub const IncrementingAllocator = struct {
}
}
- fn free(allocator: &Allocator, bytes: []u8) {
+ fn free(allocator: &Allocator, bytes: []u8) void {
// Do nothing. That's the point of an incrementing allocator.
}
};
diff --git a/std/io.zig b/std/io.zig
index fd8bb80984..41f32622f8 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -50,7 +50,7 @@ error Unseekable;
error EndOfFile;
error FilePosLargerThanPointerRange;
-pub fn getStdErr() -> %File {
+pub fn getStdErr() %File {
const handle = if (is_windows)
try os.windowsGetStdHandle(system.STD_ERROR_HANDLE)
else if (is_posix)
@@ -60,7 +60,7 @@ pub fn getStdErr() -> %File {
return File.openHandle(handle);
}
-pub fn getStdOut() -> %File {
+pub fn getStdOut() %File {
const handle = if (is_windows)
try os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE)
else if (is_posix)
@@ -70,7 +70,7 @@ pub fn getStdOut() -> %File {
return File.openHandle(handle);
}
-pub fn getStdIn() -> %File {
+pub fn getStdIn() %File {
const handle = if (is_windows)
try os.windowsGetStdHandle(system.STD_INPUT_HANDLE)
else if (is_posix)
@@ -85,7 +85,7 @@ pub const FileInStream = struct {
file: &File,
stream: InStream,
- pub fn init(file: &File) -> FileInStream {
+ pub fn init(file: &File) FileInStream {
return FileInStream {
.file = file,
.stream = InStream {
@@ -94,7 +94,7 @@ pub const FileInStream = struct {
};
}
- fn readFn(in_stream: &InStream, buffer: []u8) -> %usize {
+ fn readFn(in_stream: &InStream, buffer: []u8) %usize {
const self = @fieldParentPtr(FileInStream, "stream", in_stream);
return self.file.read(buffer);
}
@@ -105,7 +105,7 @@ pub const FileOutStream = struct {
file: &File,
stream: OutStream,
- pub fn init(file: &File) -> FileOutStream {
+ pub fn init(file: &File) FileOutStream {
return FileOutStream {
.file = file,
.stream = OutStream {
@@ -114,7 +114,7 @@ pub const FileOutStream = struct {
};
}
- fn writeFn(out_stream: &OutStream, bytes: []const u8) -> %void {
+ fn writeFn(out_stream: &OutStream, bytes: []const u8) %void {
const self = @fieldParentPtr(FileOutStream, "stream", out_stream);
return self.file.write(bytes);
}
@@ -129,7 +129,7 @@ pub const File = struct {
/// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned.
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
/// Call close to clean up.
- pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) -> %File {
+ pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) %File {
if (is_posix) {
const flags = system.O_LARGEFILE|system.O_RDONLY;
const fd = try os.posixOpen(path, flags, 0, allocator);
@@ -144,7 +144,7 @@ pub const File = struct {
}
/// Calls `openWriteMode` with 0o666 for the mode.
- pub fn openWrite(path: []const u8, allocator: ?&mem.Allocator) -> %File {
+ pub fn openWrite(path: []const u8, allocator: ?&mem.Allocator) %File {
return openWriteMode(path, 0o666, allocator);
}
@@ -154,7 +154,7 @@ pub const File = struct {
/// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned.
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
/// Call close to clean up.
- pub fn openWriteMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) -> %File {
+ pub fn openWriteMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) %File {
if (is_posix) {
const flags = system.O_LARGEFILE|system.O_WRONLY|system.O_CREAT|system.O_CLOEXEC|system.O_TRUNC;
const fd = try os.posixOpen(path, flags, mode, allocator);
@@ -170,7 +170,7 @@ pub const File = struct {
}
- pub fn openHandle(handle: os.FileHandle) -> File {
+ pub fn openHandle(handle: os.FileHandle) File {
return File {
.handle = handle,
};
@@ -179,17 +179,17 @@ pub const File = struct {
/// Upon success, the stream is in an uninitialized state. To continue using it,
/// you must use the open() function.
- pub fn close(self: &File) {
+ pub fn close(self: &File) void {
os.close(self.handle);
self.handle = undefined;
}
/// Calls `os.isTty` on `self.handle`.
- pub fn isTty(self: &File) -> bool {
+ pub fn isTty(self: &File) bool {
return os.isTty(self.handle);
}
- pub fn seekForward(self: &File, amount: isize) -> %void {
+ pub fn seekForward(self: &File, amount: isize) %void {
switch (builtin.os) {
Os.linux, Os.macosx, Os.ios => {
const result = system.lseek(self.handle, amount, system.SEEK_CUR);
@@ -218,7 +218,7 @@ pub const File = struct {
}
}
- pub fn seekTo(self: &File, pos: usize) -> %void {
+ pub fn seekTo(self: &File, pos: usize) %void {
switch (builtin.os) {
Os.linux, Os.macosx, Os.ios => {
const ipos = try math.cast(isize, pos);
@@ -249,7 +249,7 @@ pub const File = struct {
}
}
- pub fn getPos(self: &File) -> %usize {
+ pub fn getPos(self: &File) %usize {
switch (builtin.os) {
Os.linux, Os.macosx, Os.ios => {
const result = system.lseek(self.handle, 0, system.SEEK_CUR);
@@ -289,7 +289,7 @@ pub const File = struct {
}
}
- pub fn getEndPos(self: &File) -> %usize {
+ pub fn getEndPos(self: &File) %usize {
if (is_posix) {
var stat: system.Stat = undefined;
const err = system.getErrno(system.fstat(self.handle, &stat));
@@ -318,7 +318,7 @@ pub const File = struct {
}
}
- pub fn read(self: &File, buffer: []u8) -> %usize {
+ pub fn read(self: &File, buffer: []u8) %usize {
if (is_posix) {
var index: usize = 0;
while (index < buffer.len) {
@@ -360,7 +360,7 @@ pub const File = struct {
}
}
- fn write(self: &File, bytes: []const u8) -> %void {
+ fn write(self: &File, bytes: []const u8) %void {
if (is_posix) {
try os.posixWrite(self.handle, bytes);
} else if (is_windows) {
@@ -378,12 +378,12 @@ pub const InStream = struct {
/// Return the number of bytes read. If the number read is smaller than buf.len, it
/// means the stream reached the end. Reaching the end of a stream is not an error
/// condition.
- readFn: fn(self: &InStream, buffer: []u8) -> %usize,
+ readFn: fn(self: &InStream, buffer: []u8) %usize,
/// Replaces `buffer` contents by reading from the stream until it is finished.
/// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
/// the contents read from the stream are lost.
- pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) -> %void {
+ pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) %void {
try buffer.resize(0);
var actual_buf_len: usize = 0;
@@ -408,7 +408,7 @@ pub const InStream = struct {
/// memory would be greater than `max_size`, returns `error.StreamTooLong`.
/// Caller owns returned memory.
/// If this function returns an error, the contents from the stream read so far are lost.
- pub fn readAllAlloc(self: &InStream, allocator: &mem.Allocator, max_size: usize) -> %[]u8 {
+ pub fn readAllAlloc(self: &InStream, allocator: &mem.Allocator, max_size: usize) %[]u8 {
var buf = Buffer.initNull(allocator);
defer buf.deinit();
@@ -420,7 +420,7 @@ pub const InStream = struct {
/// Does not include the delimiter in the result.
/// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents
/// read from the stream so far are lost.
- pub fn readUntilDelimiterBuffer(self: &InStream, buffer: &Buffer, delimiter: u8, max_size: usize) -> %void {
+ pub fn readUntilDelimiterBuffer(self: &InStream, buffer: &Buffer, delimiter: u8, max_size: usize) %void {
try buf.resize(0);
while (true) {
@@ -443,7 +443,7 @@ pub const InStream = struct {
/// Caller owns returned memory.
/// If this function returns an error, the contents from the stream read so far are lost.
pub fn readUntilDelimiterAlloc(self: &InStream, allocator: &mem.Allocator,
- delimiter: u8, max_size: usize) -> %[]u8
+ delimiter: u8, max_size: usize) %[]u8
{
var buf = Buffer.initNull(allocator);
defer buf.deinit();
@@ -455,43 +455,43 @@ pub const InStream = struct {
/// Returns the number of bytes read. If the number read is smaller than buf.len, it
/// means the stream reached the end. Reaching the end of a stream is not an error
/// condition.
- pub fn read(self: &InStream, buffer: []u8) -> %usize {
+ pub fn read(self: &InStream, buffer: []u8) %usize {
return self.readFn(self, buffer);
}
/// Same as `read` but end of stream returns `error.EndOfStream`.
- pub fn readNoEof(self: &InStream, buf: []u8) -> %void {
+ pub fn readNoEof(self: &InStream, buf: []u8) %void {
const amt_read = try self.read(buf);
if (amt_read < buf.len) return error.EndOfStream;
}
/// Reads 1 byte from the stream or returns `error.EndOfStream`.
- pub fn readByte(self: &InStream) -> %u8 {
+ pub fn readByte(self: &InStream) %u8 {
var result: [1]u8 = undefined;
try self.readNoEof(result[0..]);
return result[0];
}
/// Same as `readByte` except the returned byte is signed.
- pub fn readByteSigned(self: &InStream) -> %i8 {
+ pub fn readByteSigned(self: &InStream) %i8 {
return @bitCast(i8, try self.readByte());
}
- pub fn readIntLe(self: &InStream, comptime T: type) -> %T {
+ pub fn readIntLe(self: &InStream, comptime T: type) %T {
return self.readInt(builtin.Endian.Little, T);
}
- pub fn readIntBe(self: &InStream, comptime T: type) -> %T {
+ pub fn readIntBe(self: &InStream, comptime T: type) %T {
return self.readInt(builtin.Endian.Big, T);
}
- pub fn readInt(self: &InStream, endian: builtin.Endian, comptime T: type) -> %T {
+ pub fn readInt(self: &InStream, endian: builtin.Endian, comptime T: type) %T {
var bytes: [@sizeOf(T)]u8 = undefined;
try self.readNoEof(bytes[0..]);
return mem.readInt(bytes, T, endian);
}
- pub fn readVarInt(self: &InStream, endian: builtin.Endian, comptime T: type, size: usize) -> %T {
+ pub fn readVarInt(self: &InStream, endian: builtin.Endian, comptime T: type, size: usize) %T {
assert(size <= @sizeOf(T));
assert(size <= 8);
var input_buf: [8]u8 = undefined;
@@ -504,22 +504,22 @@ pub const InStream = struct {
};
pub const OutStream = struct {
- writeFn: fn(self: &OutStream, bytes: []const u8) -> %void,
+ writeFn: fn(self: &OutStream, bytes: []const u8) %void,
- pub fn print(self: &OutStream, comptime format: []const u8, args: ...) -> %void {
+ pub fn print(self: &OutStream, comptime format: []const u8, args: ...) %void {
return std.fmt.format(self, self.writeFn, format, args);
}
- pub fn write(self: &OutStream, bytes: []const u8) -> %void {
+ pub fn write(self: &OutStream, bytes: []const u8) %void {
return self.writeFn(self, bytes);
}
- pub fn writeByte(self: &OutStream, byte: u8) -> %void {
+ pub fn writeByte(self: &OutStream, byte: u8) %void {
const slice = (&byte)[0..1];
return self.writeFn(self, slice);
}
- pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) -> %void {
+ pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) %void {
const slice = (&byte)[0..1];
var i: usize = 0;
while (i < n) : (i += 1) {
@@ -532,19 +532,19 @@ pub const OutStream = struct {
/// a fixed size buffer of size `std.os.max_noalloc_path_len` is an attempted solution. If the fixed
/// size buffer is too small, and the provided allocator is null, `error.NameTooLong` is returned.
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
-pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) -> %void {
+pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) %void {
var file = try File.openWrite(path, allocator);
defer file.close();
try file.write(data);
}
/// On success, caller owns returned buffer.
-pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) -> %[]u8 {
+pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) %[]u8 {
return readFileAllocExtra(path, allocator, 0);
}
/// On success, caller owns returned buffer.
/// Allocates extra_len extra bytes at the end of the file buffer, which are uninitialized.
-pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) -> %[]u8 {
+pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) %[]u8 {
var file = try File.openRead(path, allocator);
defer file.close();
@@ -559,7 +559,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len
pub const BufferedInStream = BufferedInStreamCustom(os.page_size);
-pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type {
+pub fn BufferedInStreamCustom(comptime buffer_size: usize) type {
return struct {
const Self = this;
@@ -571,7 +571,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type {
start_index: usize,
end_index: usize,
- pub fn init(unbuffered_in_stream: &InStream) -> Self {
+ pub fn init(unbuffered_in_stream: &InStream) Self {
return Self {
.unbuffered_in_stream = unbuffered_in_stream,
.buffer = undefined,
@@ -589,7 +589,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type {
};
}
- fn readFn(in_stream: &InStream, dest: []u8) -> %usize {
+ fn readFn(in_stream: &InStream, dest: []u8) %usize {
const self = @fieldParentPtr(Self, "stream", in_stream);
var dest_index: usize = 0;
@@ -630,7 +630,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type {
pub const BufferedOutStream = BufferedOutStreamCustom(os.page_size);
-pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type {
+pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type {
return struct {
const Self = this;
@@ -641,7 +641,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type {
buffer: [buffer_size]u8,
index: usize,
- pub fn init(unbuffered_out_stream: &OutStream) -> Self {
+ pub fn init(unbuffered_out_stream: &OutStream) Self {
return Self {
.unbuffered_out_stream = unbuffered_out_stream,
.buffer = undefined,
@@ -652,7 +652,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type {
};
}
- pub fn flush(self: &Self) -> %void {
+ pub fn flush(self: &Self) %void {
if (self.index == 0)
return;
@@ -660,7 +660,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type {
self.index = 0;
}
- fn writeFn(out_stream: &OutStream, bytes: []const u8) -> %void {
+ fn writeFn(out_stream: &OutStream, bytes: []const u8) %void {
const self = @fieldParentPtr(Self, "stream", out_stream);
if (bytes.len >= self.buffer.len) {
@@ -689,7 +689,7 @@ pub const BufferOutStream = struct {
buffer: &Buffer,
stream: OutStream,
- pub fn init(buffer: &Buffer) -> BufferOutStream {
+ pub fn init(buffer: &Buffer) BufferOutStream {
return BufferOutStream {
.buffer = buffer,
.stream = OutStream {
@@ -698,7 +698,7 @@ pub const BufferOutStream = struct {
};
}
- fn writeFn(out_stream: &OutStream, bytes: []const u8) -> %void {
+ fn writeFn(out_stream: &OutStream, bytes: []const u8) %void {
const self = @fieldParentPtr(BufferOutStream, "stream", out_stream);
return self.buffer.append(bytes);
}
diff --git a/std/linked_list.zig b/std/linked_list.zig
index 09a01e22b4..ffd68d5147 100644
--- a/std/linked_list.zig
+++ b/std/linked_list.zig
@@ -5,17 +5,17 @@ const mem = std.mem;
const Allocator = mem.Allocator;
/// Generic non-intrusive doubly linked list.
-pub fn LinkedList(comptime T: type) -> type {
+pub fn LinkedList(comptime T: type) type {
return BaseLinkedList(T, void, "");
}
/// Generic intrusive doubly linked list.
-pub fn IntrusiveLinkedList(comptime ParentType: type, comptime field_name: []const u8) -> type {
+pub fn IntrusiveLinkedList(comptime ParentType: type, comptime field_name: []const u8) type {
return BaseLinkedList(void, ParentType, field_name);
}
/// Generic doubly linked list.
-fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_name: []const u8) -> type {
+fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_name: []const u8) type {
return struct {
const Self = this;
@@ -25,7 +25,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
next: ?&Node,
data: T,
- pub fn init(value: &const T) -> Node {
+ pub fn init(value: &const T) Node {
return Node {
.prev = null,
.next = null,
@@ -33,12 +33,12 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
};
}
- pub fn initIntrusive() -> Node {
+ pub fn initIntrusive() Node {
// TODO: when #678 is solved this can become `init`.
return Node.init({});
}
- pub fn toData(node: &Node) -> &ParentType {
+ pub fn toData(node: &Node) &ParentType {
comptime assert(isIntrusive());
return @fieldParentPtr(ParentType, field_name, node);
}
@@ -52,7 +52,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Returns:
/// An empty linked list.
- pub fn init() -> Self {
+ pub fn init() Self {
return Self {
.first = null,
.last = null,
@@ -60,7 +60,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
};
}
- fn isIntrusive() -> bool {
+ fn isIntrusive() bool {
return ParentType != void or field_name.len != 0;
}
@@ -69,7 +69,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
/// Arguments:
/// node: Pointer to a node in the list.
/// new_node: Pointer to the new node to insert.
- pub fn insertAfter(list: &Self, node: &Node, new_node: &Node) {
+ pub fn insertAfter(list: &Self, node: &Node, new_node: &Node) void {
new_node.prev = node;
if (node.next) |next_node| {
// Intermediate node.
@@ -90,7 +90,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
/// Arguments:
/// node: Pointer to a node in the list.
/// new_node: Pointer to the new node to insert.
- pub fn insertBefore(list: &Self, node: &Node, new_node: &Node) {
+ pub fn insertBefore(list: &Self, node: &Node, new_node: &Node) void {
new_node.next = node;
if (node.prev) |prev_node| {
// Intermediate node.
@@ -110,7 +110,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Arguments:
/// new_node: Pointer to the new node to insert.
- pub fn append(list: &Self, new_node: &Node) {
+ pub fn append(list: &Self, new_node: &Node) void {
if (list.last) |last| {
// Insert after last.
list.insertAfter(last, new_node);
@@ -124,7 +124,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Arguments:
/// new_node: Pointer to the new node to insert.
- pub fn prepend(list: &Self, new_node: &Node) {
+ pub fn prepend(list: &Self, new_node: &Node) void {
if (list.first) |first| {
// Insert before first.
list.insertBefore(first, new_node);
@@ -143,7 +143,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Arguments:
/// node: Pointer to the node to be removed.
- pub fn remove(list: &Self, node: &Node) {
+ pub fn remove(list: &Self, node: &Node) void {
if (node.prev) |prev_node| {
// Intermediate node.
prev_node.next = node.next;
@@ -167,7 +167,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Returns:
/// A pointer to the last node in the list.
- pub fn pop(list: &Self) -> ?&Node {
+ pub fn pop(list: &Self) ?&Node {
const last = list.last ?? return null;
list.remove(last);
return last;
@@ -177,7 +177,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Returns:
/// A pointer to the first node in the list.
- pub fn popFirst(list: &Self) -> ?&Node {
+ pub fn popFirst(list: &Self) ?&Node {
const first = list.first ?? return null;
list.remove(first);
return first;
@@ -190,7 +190,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Returns:
/// A pointer to the new node.
- pub fn allocateNode(list: &Self, allocator: &Allocator) -> %&Node {
+ pub fn allocateNode(list: &Self, allocator: &Allocator) %&Node {
comptime assert(!isIntrusive());
return allocator.create(Node);
}
@@ -200,7 +200,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
/// Arguments:
/// node: Pointer to the node to deallocate.
/// allocator: Dynamic memory allocator.
- pub fn destroyNode(list: &Self, node: &Node, allocator: &Allocator) {
+ pub fn destroyNode(list: &Self, node: &Node, allocator: &Allocator) void {
comptime assert(!isIntrusive());
allocator.destroy(node);
}
@@ -213,7 +213,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
///
/// Returns:
/// A pointer to the new node.
- pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) -> %&Node {
+ pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) %&Node {
comptime assert(!isIntrusive());
var node = try list.allocateNode(allocator);
*node = Node.init(data);
diff --git a/std/math/acos.zig b/std/math/acos.zig
index 8adce39bff..a4f08af306 100644
--- a/std/math/acos.zig
+++ b/std/math/acos.zig
@@ -6,7 +6,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn acos(x: var) -> @typeOf(x) {
+pub fn acos(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => acos32(x),
@@ -15,7 +15,7 @@ pub fn acos(x: var) -> @typeOf(x) {
};
}
-fn r32(z: f32) -> f32 {
+fn r32(z: f32) f32 {
const pS0 = 1.6666586697e-01;
const pS1 = -4.2743422091e-02;
const pS2 = -8.6563630030e-03;
@@ -26,7 +26,7 @@ fn r32(z: f32) -> f32 {
return p / q;
}
-fn acos32(x: f32) -> f32 {
+fn acos32(x: f32) f32 {
const pio2_hi = 1.5707962513e+00;
const pio2_lo = 7.5497894159e-08;
@@ -73,7 +73,7 @@ fn acos32(x: f32) -> f32 {
return 2 * (df + w);
}
-fn r64(z: f64) -> f64 {
+fn r64(z: f64) f64 {
const pS0: f64 = 1.66666666666666657415e-01;
const pS1: f64 = -3.25565818622400915405e-01;
const pS2: f64 = 2.01212532134862925881e-01;
@@ -90,7 +90,7 @@ fn r64(z: f64) -> f64 {
return p / q;
}
-fn acos64(x: f64) -> f64 {
+fn acos64(x: f64) f64 {
const pio2_hi: f64 = 1.57079632679489655800e+00;
const pio2_lo: f64 = 6.12323399573676603587e-17;
diff --git a/std/math/acosh.zig b/std/math/acosh.zig
index 91094302dd..9be323e1f6 100644
--- a/std/math/acosh.zig
+++ b/std/math/acosh.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn acosh(x: var) -> @typeOf(x) {
+pub fn acosh(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => acosh32(x),
@@ -18,7 +18,7 @@ pub fn acosh(x: var) -> @typeOf(x) {
}
// acosh(x) = log(x + sqrt(x * x - 1))
-fn acosh32(x: f32) -> f32 {
+fn acosh32(x: f32) f32 {
const u = @bitCast(u32, x);
const i = u & 0x7FFFFFFF;
@@ -36,7 +36,7 @@ fn acosh32(x: f32) -> f32 {
}
}
-fn acosh64(x: f64) -> f64 {
+fn acosh64(x: f64) f64 {
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
diff --git a/std/math/asin.zig b/std/math/asin.zig
index a0209be0c8..9fa5a80ea5 100644
--- a/std/math/asin.zig
+++ b/std/math/asin.zig
@@ -7,7 +7,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn asin(x: var) -> @typeOf(x) {
+pub fn asin(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => asin32(x),
@@ -16,7 +16,7 @@ pub fn asin(x: var) -> @typeOf(x) {
};
}
-fn r32(z: f32) -> f32 {
+fn r32(z: f32) f32 {
const pS0 = 1.6666586697e-01;
const pS1 = -4.2743422091e-02;
const pS2 = -8.6563630030e-03;
@@ -27,7 +27,7 @@ fn r32(z: f32) -> f32 {
return p / q;
}
-fn asin32(x: f32) -> f32 {
+fn asin32(x: f32) f32 {
const pio2 = 1.570796326794896558e+00;
const hx: u32 = @bitCast(u32, x);
@@ -65,7 +65,7 @@ fn asin32(x: f32) -> f32 {
}
}
-fn r64(z: f64) -> f64 {
+fn r64(z: f64) f64 {
const pS0: f64 = 1.66666666666666657415e-01;
const pS1: f64 = -3.25565818622400915405e-01;
const pS2: f64 = 2.01212532134862925881e-01;
@@ -82,7 +82,7 @@ fn r64(z: f64) -> f64 {
return p / q;
}
-fn asin64(x: f64) -> f64 {
+fn asin64(x: f64) f64 {
const pio2_hi: f64 = 1.57079632679489655800e+00;
const pio2_lo: f64 = 6.12323399573676603587e-17;
diff --git a/std/math/asinh.zig b/std/math/asinh.zig
index d95565fc6d..af8c2d8f54 100644
--- a/std/math/asinh.zig
+++ b/std/math/asinh.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn asinh(x: var) -> @typeOf(x) {
+pub fn asinh(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => asinh32(x),
@@ -18,7 +18,7 @@ pub fn asinh(x: var) -> @typeOf(x) {
}
// asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5)
-fn asinh32(x: f32) -> f32 {
+fn asinh32(x: f32) f32 {
const u = @bitCast(u32, x);
const i = u & 0x7FFFFFFF;
const s = i >> 31;
@@ -50,7 +50,7 @@ fn asinh32(x: f32) -> f32 {
return if (s != 0) -rx else rx;
}
-fn asinh64(x: f64) -> f64 {
+fn asinh64(x: f64) f64 {
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
const s = u >> 63;
diff --git a/std/math/atan.zig b/std/math/atan.zig
index fbfade50a0..c315adc42d 100644
--- a/std/math/atan.zig
+++ b/std/math/atan.zig
@@ -7,7 +7,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn atan(x: var) -> @typeOf(x) {
+pub fn atan(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => atan32(x),
@@ -16,7 +16,7 @@ pub fn atan(x: var) -> @typeOf(x) {
};
}
-fn atan32(x_: f32) -> f32 {
+fn atan32(x_: f32) f32 {
const atanhi = []const f32 {
4.6364760399e-01, // atan(0.5)hi
7.8539812565e-01, // atan(1.0)hi
@@ -108,7 +108,7 @@ fn atan32(x_: f32) -> f32 {
}
}
-fn atan64(x_: f64) -> f64 {
+fn atan64(x_: f64) f64 {
const atanhi = []const f64 {
4.63647609000806093515e-01, // atan(0.5)hi
7.85398163397448278999e-01, // atan(1.0)hi
diff --git a/std/math/atan2.zig b/std/math/atan2.zig
index 11e1b8cd89..6f29b7b18d 100644
--- a/std/math/atan2.zig
+++ b/std/math/atan2.zig
@@ -22,7 +22,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-fn atan2(comptime T: type, x: T, y: T) -> T {
+fn atan2(comptime T: type, x: T, y: T) T {
return switch (T) {
f32 => atan2_32(x, y),
f64 => atan2_64(x, y),
@@ -30,7 +30,7 @@ fn atan2(comptime T: type, x: T, y: T) -> T {
};
}
-fn atan2_32(y: f32, x: f32) -> f32 {
+fn atan2_32(y: f32, x: f32) f32 {
const pi: f32 = 3.1415927410e+00;
const pi_lo: f32 = -8.7422776573e-08;
@@ -115,7 +115,7 @@ fn atan2_32(y: f32, x: f32) -> f32 {
}
}
-fn atan2_64(y: f64, x: f64) -> f64 {
+fn atan2_64(y: f64, x: f64) f64 {
const pi: f64 = 3.1415926535897931160E+00;
const pi_lo: f64 = 1.2246467991473531772E-16;
diff --git a/std/math/atanh.zig b/std/math/atanh.zig
index e787506765..8ca0cc85bc 100644
--- a/std/math/atanh.zig
+++ b/std/math/atanh.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn atanh(x: var) -> @typeOf(x) {
+pub fn atanh(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => atanh_32(x),
@@ -18,7 +18,7 @@ pub fn atanh(x: var) -> @typeOf(x) {
}
// atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5)
-fn atanh_32(x: f32) -> f32 {
+fn atanh_32(x: f32) f32 {
const u = @bitCast(u32, x);
const i = u & 0x7FFFFFFF;
const s = u >> 31;
@@ -47,7 +47,7 @@ fn atanh_32(x: f32) -> f32 {
return if (s != 0) -y else y;
}
-fn atanh_64(x: f64) -> f64 {
+fn atanh_64(x: f64) f64 {
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
const s = u >> 63;
diff --git a/std/math/cbrt.zig b/std/math/cbrt.zig
index 9725716f3b..a265392ff7 100644
--- a/std/math/cbrt.zig
+++ b/std/math/cbrt.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn cbrt(x: var) -> @typeOf(x) {
+pub fn cbrt(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => cbrt32(x),
@@ -17,7 +17,7 @@ pub fn cbrt(x: var) -> @typeOf(x) {
};
}
-fn cbrt32(x: f32) -> f32 {
+fn cbrt32(x: f32) f32 {
const B1: u32 = 709958130; // (127 - 127.0 / 3 - 0.03306235651) * 2^23
const B2: u32 = 642849266; // (127 - 127.0 / 3 - 24 / 3 - 0.03306235651) * 2^23
@@ -57,7 +57,7 @@ fn cbrt32(x: f32) -> f32 {
return f32(t);
}
-fn cbrt64(x: f64) -> f64 {
+fn cbrt64(x: f64) f64 {
const B1: u32 = 715094163; // (1023 - 1023 / 3 - 0.03306235651 * 2^20
const B2: u32 = 696219795; // (1023 - 1023 / 3 - 54 / 3 - 0.03306235651 * 2^20
diff --git a/std/math/ceil.zig b/std/math/ceil.zig
index 141b5c0fc5..5bdb84ca00 100644
--- a/std/math/ceil.zig
+++ b/std/math/ceil.zig
@@ -9,7 +9,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn ceil(x: var) -> @typeOf(x) {
+pub fn ceil(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => ceil32(x),
@@ -18,7 +18,7 @@ pub fn ceil(x: var) -> @typeOf(x) {
};
}
-fn ceil32(x: f32) -> f32 {
+fn ceil32(x: f32) f32 {
var u = @bitCast(u32, x);
var e = i32((u >> 23) & 0xFF) - 0x7F;
var m: u32 = undefined;
@@ -51,7 +51,7 @@ fn ceil32(x: f32) -> f32 {
}
}
-fn ceil64(x: f64) -> f64 {
+fn ceil64(x: f64) f64 {
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
var y: f64 = undefined;
diff --git a/std/math/copysign.zig b/std/math/copysign.zig
index ebf12313ff..4ca8f82f4b 100644
--- a/std/math/copysign.zig
+++ b/std/math/copysign.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn copysign(comptime T: type, x: T, y: T) -> T {
+pub fn copysign(comptime T: type, x: T, y: T) T {
return switch (T) {
f32 => copysign32(x, y),
f64 => copysign64(x, y),
@@ -10,7 +10,7 @@ pub fn copysign(comptime T: type, x: T, y: T) -> T {
};
}
-fn copysign32(x: f32, y: f32) -> f32 {
+fn copysign32(x: f32, y: f32) f32 {
const ux = @bitCast(u32, x);
const uy = @bitCast(u32, y);
@@ -19,7 +19,7 @@ fn copysign32(x: f32, y: f32) -> f32 {
return @bitCast(f32, h1 | h2);
}
-fn copysign64(x: f64, y: f64) -> f64 {
+fn copysign64(x: f64, y: f64) f64 {
const ux = @bitCast(u64, x);
const uy = @bitCast(u64, y);
diff --git a/std/math/cos.zig b/std/math/cos.zig
index 88a0193db1..bb405b0d10 100644
--- a/std/math/cos.zig
+++ b/std/math/cos.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn cos(x: var) -> @typeOf(x) {
+pub fn cos(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => cos32(x),
@@ -36,7 +36,7 @@ const C5 = 4.16666666666665929218E-2;
// NOTE: This is taken from the go stdlib. The musl implementation is much more complex.
//
// This may have slight differences on some edge cases and may need to replaced if so.
-fn cos32(x_: f32) -> f32 {
+fn cos32(x_: f32) f32 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const pi4a = 7.85398125648498535156e-1;
@@ -89,7 +89,7 @@ fn cos32(x_: f32) -> f32 {
}
}
-fn cos64(x_: f64) -> f64 {
+fn cos64(x_: f64) f64 {
const pi4a = 7.85398125648498535156e-1;
const pi4b = 3.77489470793079817668E-8;
const pi4c = 2.69515142907905952645E-15;
diff --git a/std/math/cosh.zig b/std/math/cosh.zig
index 6e57e85d14..fa46219986 100644
--- a/std/math/cosh.zig
+++ b/std/math/cosh.zig
@@ -10,7 +10,7 @@ const math = std.math;
const expo2 = @import("expo2.zig").expo2;
const assert = std.debug.assert;
-pub fn cosh(x: var) -> @typeOf(x) {
+pub fn cosh(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => cosh32(x),
@@ -22,7 +22,7 @@ pub fn cosh(x: var) -> @typeOf(x) {
// cosh(x) = (exp(x) + 1 / exp(x)) / 2
// = 1 + 0.5 * (exp(x) - 1) * (exp(x) - 1) / exp(x)
// = 1 + (x * x) / 2 + o(x^4)
-fn cosh32(x: f32) -> f32 {
+fn cosh32(x: f32) f32 {
const u = @bitCast(u32, x);
const ux = u & 0x7FFFFFFF;
const ax = @bitCast(f32, ux);
@@ -47,7 +47,7 @@ fn cosh32(x: f32) -> f32 {
return expo2(ax);
}
-fn cosh64(x: f64) -> f64 {
+fn cosh64(x: f64) f64 {
const u = @bitCast(u64, x);
const w = u32(u >> 32);
const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
diff --git a/std/math/exp.zig b/std/math/exp.zig
index 4cce18ffe5..4032930a43 100644
--- a/std/math/exp.zig
+++ b/std/math/exp.zig
@@ -7,7 +7,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn exp(x: var) -> @typeOf(x) {
+pub fn exp(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => exp32(x),
@@ -16,7 +16,7 @@ pub fn exp(x: var) -> @typeOf(x) {
};
}
-fn exp32(x_: f32) -> f32 {
+fn exp32(x_: f32) f32 {
const half = []f32 { 0.5, -0.5 };
const ln2hi = 6.9314575195e-1;
const ln2lo = 1.4286067653e-6;
@@ -93,7 +93,7 @@ fn exp32(x_: f32) -> f32 {
}
}
-fn exp64(x_: f64) -> f64 {
+fn exp64(x_: f64) f64 {
const half = []const f64 { 0.5, -0.5 };
const ln2hi: f64 = 6.93147180369123816490e-01;
const ln2lo: f64 = 1.90821492927058770002e-10;
diff --git a/std/math/exp2.zig b/std/math/exp2.zig
index 4ce7de909e..790bd1a558 100644
--- a/std/math/exp2.zig
+++ b/std/math/exp2.zig
@@ -7,7 +7,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn exp2(x: var) -> @typeOf(x) {
+pub fn exp2(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => exp2_32(x),
@@ -35,7 +35,7 @@ const exp2ft = []const f64 {
0x1.5ab07dd485429p+0,
};
-fn exp2_32(x: f32) -> f32 {
+fn exp2_32(x: f32) f32 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const tblsiz = u32(exp2ft.len);
@@ -352,7 +352,7 @@ const exp2dt = []f64 {
0x1.690f4b19e9471p+0, -0x1.9780p-45,
};
-fn exp2_64(x: f64) -> f64 {
+fn exp2_64(x: f64) f64 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const tblsiz = u32(exp2dt.len / 2);
diff --git a/std/math/expm1.zig b/std/math/expm1.zig
index f2d4d4f183..316f0e3e71 100644
--- a/std/math/expm1.zig
+++ b/std/math/expm1.zig
@@ -9,7 +9,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn expm1(x: var) -> @typeOf(x) {
+pub fn expm1(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => expm1_32(x),
@@ -18,7 +18,7 @@ pub fn expm1(x: var) -> @typeOf(x) {
};
}
-fn expm1_32(x_: f32) -> f32 {
+fn expm1_32(x_: f32) f32 {
@setFloatMode(this, builtin.FloatMode.Strict);
const o_threshold: f32 = 8.8721679688e+01;
const ln2_hi: f32 = 6.9313812256e-01;
@@ -145,7 +145,7 @@ fn expm1_32(x_: f32) -> f32 {
}
}
-fn expm1_64(x_: f64) -> f64 {
+fn expm1_64(x_: f64) f64 {
@setFloatMode(this, builtin.FloatMode.Strict);
const o_threshold: f64 = 7.09782712893383973096e+02;
const ln2_hi: f64 = 6.93147180369123816490e-01;
diff --git a/std/math/expo2.zig b/std/math/expo2.zig
index 93111391a2..15b80c710c 100644
--- a/std/math/expo2.zig
+++ b/std/math/expo2.zig
@@ -1,6 +1,6 @@
const math = @import("index.zig");
-pub fn expo2(x: var) -> @typeOf(x) {
+pub fn expo2(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => expo2f(x),
@@ -9,7 +9,7 @@ pub fn expo2(x: var) -> @typeOf(x) {
};
}
-fn expo2f(x: f32) -> f32 {
+fn expo2f(x: f32) f32 {
const k: u32 = 235;
const kln2 = 0x1.45C778p+7;
@@ -18,7 +18,7 @@ fn expo2f(x: f32) -> f32 {
return math.exp(x - kln2) * scale * scale;
}
-fn expo2d(x: f64) -> f64 {
+fn expo2d(x: f64) f64 {
const k: u32 = 2043;
const kln2 = 0x1.62066151ADD8BP+10;
diff --git a/std/math/fabs.zig b/std/math/fabs.zig
index dc1184dcc8..821624e1bc 100644
--- a/std/math/fabs.zig
+++ b/std/math/fabs.zig
@@ -7,7 +7,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn fabs(x: var) -> @typeOf(x) {
+pub fn fabs(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => fabs32(x),
@@ -16,13 +16,13 @@ pub fn fabs(x: var) -> @typeOf(x) {
};
}
-fn fabs32(x: f32) -> f32 {
+fn fabs32(x: f32) f32 {
var u = @bitCast(u32, x);
u &= 0x7FFFFFFF;
return @bitCast(f32, u);
}
-fn fabs64(x: f64) -> f64 {
+fn fabs64(x: f64) f64 {
var u = @bitCast(u64, x);
u &= @maxValue(u64) >> 1;
return @bitCast(f64, u);
diff --git a/std/math/floor.zig b/std/math/floor.zig
index 910dfd1901..1b8e2dfeed 100644
--- a/std/math/floor.zig
+++ b/std/math/floor.zig
@@ -9,7 +9,7 @@ const assert = std.debug.assert;
const std = @import("../index.zig");
const math = std.math;
-pub fn floor(x: var) -> @typeOf(x) {
+pub fn floor(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => floor32(x),
@@ -18,7 +18,7 @@ pub fn floor(x: var) -> @typeOf(x) {
};
}
-fn floor32(x: f32) -> f32 {
+fn floor32(x: f32) f32 {
var u = @bitCast(u32, x);
const e = i32((u >> 23) & 0xFF) - 0x7F;
var m: u32 = undefined;
@@ -52,7 +52,7 @@ fn floor32(x: f32) -> f32 {
}
}
-fn floor64(x: f64) -> f64 {
+fn floor64(x: f64) f64 {
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
var y: f64 = undefined;
diff --git a/std/math/fma.zig b/std/math/fma.zig
index b48cfc83b2..e8d146db34 100644
--- a/std/math/fma.zig
+++ b/std/math/fma.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn fma(comptime T: type, x: T, y: T, z: T) -> T {
+pub fn fma(comptime T: type, x: T, y: T, z: T) T {
return switch (T) {
f32 => fma32(x, y, z),
f64 => fma64(x, y ,z),
@@ -10,7 +10,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) -> T {
};
}
-fn fma32(x: f32, y: f32, z: f32) -> f32 {
+fn fma32(x: f32, y: f32, z: f32) f32 {
const xy = f64(x) * y;
const xy_z = xy + z;
const u = @bitCast(u64, xy_z);
@@ -24,7 +24,7 @@ fn fma32(x: f32, y: f32, z: f32) -> f32 {
}
}
-fn fma64(x: f64, y: f64, z: f64) -> f64 {
+fn fma64(x: f64, y: f64, z: f64) f64 {
if (!math.isFinite(x) or !math.isFinite(y)) {
return x * y + z;
}
@@ -73,7 +73,7 @@ fn fma64(x: f64, y: f64, z: f64) -> f64 {
const dd = struct { hi: f64, lo: f64, };
-fn dd_add(a: f64, b: f64) -> dd {
+fn dd_add(a: f64, b: f64) dd {
var ret: dd = undefined;
ret.hi = a + b;
const s = ret.hi - a;
@@ -81,7 +81,7 @@ fn dd_add(a: f64, b: f64) -> dd {
return ret;
}
-fn dd_mul(a: f64, b: f64) -> dd {
+fn dd_mul(a: f64, b: f64) dd {
var ret: dd = undefined;
const split: f64 = 0x1.0p27 + 1.0;
@@ -103,7 +103,7 @@ fn dd_mul(a: f64, b: f64) -> dd {
return ret;
}
-fn add_adjusted(a: f64, b: f64) -> f64 {
+fn add_adjusted(a: f64, b: f64) f64 {
var sum = dd_add(a, b);
if (sum.lo != 0) {
var uhii = @bitCast(u64, sum.hi);
@@ -117,7 +117,7 @@ fn add_adjusted(a: f64, b: f64) -> f64 {
return sum.hi;
}
-fn add_and_denorm(a: f64, b: f64, scale: i32) -> f64 {
+fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
var sum = dd_add(a, b);
if (sum.lo != 0) {
var uhii = @bitCast(u64, sum.hi);
diff --git a/std/math/frexp.zig b/std/math/frexp.zig
index a90121e5fe..b58af0a9bc 100644
--- a/std/math/frexp.zig
+++ b/std/math/frexp.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-fn frexp_result(comptime T: type) -> type {
+fn frexp_result(comptime T: type) type {
return struct {
significand: T,
exponent: i32,
@@ -17,7 +17,7 @@ fn frexp_result(comptime T: type) -> type {
pub const frexp32_result = frexp_result(f32);
pub const frexp64_result = frexp_result(f64);
-pub fn frexp(x: var) -> frexp_result(@typeOf(x)) {
+pub fn frexp(x: var) frexp_result(@typeOf(x)) {
const T = @typeOf(x);
return switch (T) {
f32 => frexp32(x),
@@ -26,7 +26,7 @@ pub fn frexp(x: var) -> frexp_result(@typeOf(x)) {
};
}
-fn frexp32(x: f32) -> frexp32_result {
+fn frexp32(x: f32) frexp32_result {
var result: frexp32_result = undefined;
var y = @bitCast(u32, x);
@@ -63,7 +63,7 @@ fn frexp32(x: f32) -> frexp32_result {
return result;
}
-fn frexp64(x: f64) -> frexp64_result {
+fn frexp64(x: f64) frexp64_result {
var result: frexp64_result = undefined;
var y = @bitCast(u64, x);
diff --git a/std/math/hypot.zig b/std/math/hypot.zig
index 6c0039b176..06427d0865 100644
--- a/std/math/hypot.zig
+++ b/std/math/hypot.zig
@@ -9,7 +9,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn hypot(comptime T: type, x: T, y: T) -> T {
+pub fn hypot(comptime T: type, x: T, y: T) T {
return switch (T) {
f32 => hypot32(x, y),
f64 => hypot64(x, y),
@@ -17,7 +17,7 @@ pub fn hypot(comptime T: type, x: T, y: T) -> T {
};
}
-fn hypot32(x: f32, y: f32) -> f32 {
+fn hypot32(x: f32, y: f32) f32 {
var ux = @bitCast(u32, x);
var uy = @bitCast(u32, y);
@@ -52,7 +52,7 @@ fn hypot32(x: f32, y: f32) -> f32 {
return z * math.sqrt(f32(f64(x) * x + f64(y) * y));
}
-fn sq(hi: &f64, lo: &f64, x: f64) {
+fn sq(hi: &f64, lo: &f64, x: f64) void {
const split: f64 = 0x1.0p27 + 1.0;
const xc = x * split;
const xh = x - xc + xc;
@@ -61,7 +61,7 @@ fn sq(hi: &f64, lo: &f64, x: f64) {
*lo = xh * xh - *hi + 2 * xh * xl + xl * xl;
}
-fn hypot64(x: f64, y: f64) -> f64 {
+fn hypot64(x: f64, y: f64) f64 {
var ux = @bitCast(u64, x);
var uy = @bitCast(u64, y);
diff --git a/std/math/ilogb.zig b/std/math/ilogb.zig
index db8e24d6c8..f1f33aff55 100644
--- a/std/math/ilogb.zig
+++ b/std/math/ilogb.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn ilogb(x: var) -> i32 {
+pub fn ilogb(x: var) i32 {
const T = @typeOf(x);
return switch (T) {
f32 => ilogb32(x),
@@ -21,7 +21,7 @@ pub fn ilogb(x: var) -> i32 {
const fp_ilogbnan = -1 - i32(@maxValue(u32) >> 1);
const fp_ilogb0 = fp_ilogbnan;
-fn ilogb32(x: f32) -> i32 {
+fn ilogb32(x: f32) i32 {
var u = @bitCast(u32, x);
var e = i32((u >> 23) & 0xFF);
@@ -57,7 +57,7 @@ fn ilogb32(x: f32) -> i32 {
return e - 0x7F;
}
-fn ilogb64(x: f64) -> i32 {
+fn ilogb64(x: f64) i32 {
var u = @bitCast(u64, x);
var e = i32((u >> 52) & 0x7FF);
diff --git a/std/math/index.zig b/std/math/index.zig
index e9023f68a9..64d24a4dfd 100644
--- a/std/math/index.zig
+++ b/std/math/index.zig
@@ -35,13 +35,13 @@ pub const nan = @import("nan.zig").nan;
pub const snan = @import("nan.zig").snan;
pub const inf = @import("inf.zig").inf;
-pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) -> bool {
+pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
assert(@typeId(T) == TypeId.Float);
return fabs(x - y) < epsilon;
}
// TODO: Hide the following in an internal module.
-pub fn forceEval(value: var) {
+pub fn forceEval(value: var) void {
const T = @typeOf(value);
switch (T) {
f32 => {
@@ -60,23 +60,23 @@ pub fn forceEval(value: var) {
}
}
-pub fn raiseInvalid() {
+pub fn raiseInvalid() void {
// Raise INVALID fpu exception
}
-pub fn raiseUnderflow() {
+pub fn raiseUnderflow() void {
// Raise UNDERFLOW fpu exception
}
-pub fn raiseOverflow() {
+pub fn raiseOverflow() void {
// Raise OVERFLOW fpu exception
}
-pub fn raiseInexact() {
+pub fn raiseInexact() void {
// Raise INEXACT fpu exception
}
-pub fn raiseDivByZero() {
+pub fn raiseDivByZero() void {
// Raise INEXACT fpu exception
}
@@ -175,7 +175,7 @@ test "math" {
}
-pub fn min(x: var, y: var) -> @typeOf(x + y) {
+pub fn min(x: var, y: var) @typeOf(x + y) {
return if (x < y) x else y;
}
@@ -183,7 +183,7 @@ test "math.min" {
assert(min(i32(-1), i32(2)) == -1);
}
-pub fn max(x: var, y: var) -> @typeOf(x + y) {
+pub fn max(x: var, y: var) @typeOf(x + y) {
return if (x > y) x else y;
}
@@ -192,36 +192,36 @@ test "math.max" {
}
error Overflow;
-pub fn mul(comptime T: type, a: T, b: T) -> %T {
+pub fn mul(comptime T: type, a: T, b: T) %T {
var answer: T = undefined;
return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer;
}
error Overflow;
-pub fn add(comptime T: type, a: T, b: T) -> %T {
+pub fn add(comptime T: type, a: T, b: T) %T {
var answer: T = undefined;
return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer;
}
error Overflow;
-pub fn sub(comptime T: type, a: T, b: T) -> %T {
+pub fn sub(comptime T: type, a: T, b: T) %T {
var answer: T = undefined;
return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
}
-pub fn negate(x: var) -> %@typeOf(x) {
+pub fn negate(x: var) %@typeOf(x) {
return sub(@typeOf(x), 0, x);
}
error Overflow;
-pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) -> %T {
+pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) %T {
var answer: T = undefined;
return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer;
}
/// Shifts left. Overflowed bits are truncated.
/// A negative shift amount results in a right shift.
-pub fn shl(comptime T: type, a: T, shift_amt: var) -> T {
+pub fn shl(comptime T: type, a: T, shift_amt: var) T {
const abs_shift_amt = absCast(shift_amt);
const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt);
@@ -245,7 +245,7 @@ test "math.shl" {
/// Shifts right. Overflowed bits are truncated.
/// A negative shift amount results in a lefft shift.
-pub fn shr(comptime T: type, a: T, shift_amt: var) -> T {
+pub fn shr(comptime T: type, a: T, shift_amt: var) T {
const abs_shift_amt = absCast(shift_amt);
const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt);
@@ -269,7 +269,7 @@ test "math.shr" {
/// Rotates right. Only unsigned values can be rotated.
/// Negative shift values results in shift modulo the bit count.
-pub fn rotr(comptime T: type, x: T, r: var) -> T {
+pub fn rotr(comptime T: type, x: T, r: var) T {
if (T.is_signed) {
@compileError("cannot rotate signed integer");
} else {
@@ -288,7 +288,7 @@ test "math.rotr" {
/// Rotates left. Only unsigned values can be rotated.
/// Negative shift values results in shift modulo the bit count.
-pub fn rotl(comptime T: type, x: T, r: var) -> T {
+pub fn rotl(comptime T: type, x: T, r: var) T {
if (T.is_signed) {
@compileError("cannot rotate signed integer");
} else {
@@ -306,7 +306,7 @@ test "math.rotl" {
}
-pub fn Log2Int(comptime T: type) -> type {
+pub fn Log2Int(comptime T: type) type {
return @IntType(false, log2(T.bit_count));
}
@@ -315,7 +315,7 @@ test "math overflow functions" {
comptime testOverflow();
}
-fn testOverflow() {
+fn testOverflow() void {
assert((mul(i32, 3, 4) catch unreachable) == 12);
assert((add(i32, 3, 4) catch unreachable) == 7);
assert((sub(i32, 3, 4) catch unreachable) == -1);
@@ -324,7 +324,7 @@ fn testOverflow() {
error Overflow;
-pub fn absInt(x: var) -> %@typeOf(x) {
+pub fn absInt(x: var) %@typeOf(x) {
const T = @typeOf(x);
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
comptime assert(T.is_signed); // must pass a signed integer to absInt
@@ -340,7 +340,7 @@ test "math.absInt" {
testAbsInt();
comptime testAbsInt();
}
-fn testAbsInt() {
+fn testAbsInt() void {
assert((absInt(i32(-10)) catch unreachable) == 10);
assert((absInt(i32(10)) catch unreachable) == 10);
}
@@ -349,7 +349,7 @@ pub const absFloat = @import("fabs.zig").fabs;
error DivisionByZero;
error Overflow;
-pub fn divTrunc(comptime T: type, numerator: T, denominator: T) -> %T {
+pub fn divTrunc(comptime T: type, numerator: T, denominator: T) %T {
@setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
@@ -362,7 +362,7 @@ test "math.divTrunc" {
testDivTrunc();
comptime testDivTrunc();
}
-fn testDivTrunc() {
+fn testDivTrunc() void {
assert((divTrunc(i32, 5, 3) catch unreachable) == 1);
assert((divTrunc(i32, -5, 3) catch unreachable) == -1);
if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
@@ -374,7 +374,7 @@ fn testDivTrunc() {
error DivisionByZero;
error Overflow;
-pub fn divFloor(comptime T: type, numerator: T, denominator: T) -> %T {
+pub fn divFloor(comptime T: type, numerator: T, denominator: T) %T {
@setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
@@ -387,7 +387,7 @@ test "math.divFloor" {
testDivFloor();
comptime testDivFloor();
}
-fn testDivFloor() {
+fn testDivFloor() void {
assert((divFloor(i32, 5, 3) catch unreachable) == 1);
assert((divFloor(i32, -5, 3) catch unreachable) == -2);
if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
@@ -400,7 +400,7 @@ fn testDivFloor() {
error DivisionByZero;
error Overflow;
error UnexpectedRemainder;
-pub fn divExact(comptime T: type, numerator: T, denominator: T) -> %T {
+pub fn divExact(comptime T: type, numerator: T, denominator: T) %T {
@setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
@@ -416,7 +416,7 @@ test "math.divExact" {
testDivExact();
comptime testDivExact();
}
-fn testDivExact() {
+fn testDivExact() void {
assert((divExact(i32, 10, 5) catch unreachable) == 2);
assert((divExact(i32, -10, 5) catch unreachable) == -2);
if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
@@ -430,7 +430,7 @@ fn testDivExact() {
error DivisionByZero;
error NegativeDenominator;
-pub fn mod(comptime T: type, numerator: T, denominator: T) -> %T {
+pub fn mod(comptime T: type, numerator: T, denominator: T) %T {
@setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
@@ -443,7 +443,7 @@ test "math.mod" {
testMod();
comptime testMod();
}
-fn testMod() {
+fn testMod() void {
assert((mod(i32, -5, 3) catch unreachable) == 1);
assert((mod(i32, 5, 3) catch unreachable) == 2);
if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
@@ -457,7 +457,7 @@ fn testMod() {
error DivisionByZero;
error NegativeDenominator;
-pub fn rem(comptime T: type, numerator: T, denominator: T) -> %T {
+pub fn rem(comptime T: type, numerator: T, denominator: T) %T {
@setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
@@ -470,7 +470,7 @@ test "math.rem" {
testRem();
comptime testRem();
}
-fn testRem() {
+fn testRem() void {
assert((rem(i32, -5, 3) catch unreachable) == -2);
assert((rem(i32, 5, 3) catch unreachable) == 2);
if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
@@ -484,7 +484,7 @@ fn testRem() {
/// Returns the absolute value of the integer parameter.
/// Result is an unsigned integer.
-pub fn absCast(x: var) -> @IntType(false, @typeOf(x).bit_count) {
+pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) {
const uint = @IntType(false, @typeOf(x).bit_count);
if (x >= 0)
return uint(x);
@@ -506,7 +506,7 @@ test "math.absCast" {
/// Returns the negation of the integer parameter.
/// Result is a signed integer.
error Overflow;
-pub fn negateCast(x: var) -> %@IntType(true, @typeOf(x).bit_count) {
+pub fn negateCast(x: var) %@IntType(true, @typeOf(x).bit_count) {
if (@typeOf(x).is_signed)
return negate(x);
@@ -533,7 +533,7 @@ test "math.negateCast" {
/// Cast an integer to a different integer type. If the value doesn't fit,
/// return an error.
error Overflow;
-pub fn cast(comptime T: type, x: var) -> %T {
+pub fn cast(comptime T: type, x: var) %T {
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
if (x > @maxValue(T)) {
return error.Overflow;
@@ -542,7 +542,7 @@ pub fn cast(comptime T: type, x: var) -> %T {
}
}
-pub fn floorPowerOfTwo(comptime T: type, value: T) -> T {
+pub fn floorPowerOfTwo(comptime T: type, value: T) T {
var x = value;
comptime var i = 1;
@@ -558,7 +558,7 @@ test "math.floorPowerOfTwo" {
comptime testFloorPowerOfTwo();
}
-fn testFloorPowerOfTwo() {
+fn testFloorPowerOfTwo() void {
assert(floorPowerOfTwo(u32, 63) == 32);
assert(floorPowerOfTwo(u32, 64) == 64);
assert(floorPowerOfTwo(u32, 65) == 64);
diff --git a/std/math/inf.zig b/std/math/inf.zig
index b253124c84..bde90b2be1 100644
--- a/std/math/inf.zig
+++ b/std/math/inf.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn inf(comptime T: type) -> T {
+pub fn inf(comptime T: type) T {
return switch (T) {
f32 => @bitCast(f32, math.inf_u32),
f64 => @bitCast(f64, math.inf_u64),
diff --git a/std/math/isfinite.zig b/std/math/isfinite.zig
index 67fcf3cd18..37ead03bba 100644
--- a/std/math/isfinite.zig
+++ b/std/math/isfinite.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn isFinite(x: var) -> bool {
+pub fn isFinite(x: var) bool {
const T = @typeOf(x);
switch (T) {
f32 => {
diff --git a/std/math/isinf.zig b/std/math/isinf.zig
index 75529fbb5e..a976fb73d2 100644
--- a/std/math/isinf.zig
+++ b/std/math/isinf.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn isInf(x: var) -> bool {
+pub fn isInf(x: var) bool {
const T = @typeOf(x);
switch (T) {
f32 => {
@@ -19,7 +19,7 @@ pub fn isInf(x: var) -> bool {
}
}
-pub fn isPositiveInf(x: var) -> bool {
+pub fn isPositiveInf(x: var) bool {
const T = @typeOf(x);
switch (T) {
f32 => {
@@ -34,7 +34,7 @@ pub fn isPositiveInf(x: var) -> bool {
}
}
-pub fn isNegativeInf(x: var) -> bool {
+pub fn isNegativeInf(x: var) bool {
const T = @typeOf(x);
switch (T) {
f32 => {
diff --git a/std/math/isnan.zig b/std/math/isnan.zig
index d494dddca8..67971e3d0c 100644
--- a/std/math/isnan.zig
+++ b/std/math/isnan.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn isNan(x: var) -> bool {
+pub fn isNan(x: var) bool {
const T = @typeOf(x);
switch (T) {
f32 => {
@@ -21,7 +21,7 @@ pub fn isNan(x: var) -> bool {
// Note: A signalling nan is identical to a standard right now by may have a different bit
// representation in the future when required.
-pub fn isSignalNan(x: var) -> bool {
+pub fn isSignalNan(x: var) bool {
return isNan(x);
}
diff --git a/std/math/isnormal.zig b/std/math/isnormal.zig
index 4d07bf4cb3..d5c1061cb1 100644
--- a/std/math/isnormal.zig
+++ b/std/math/isnormal.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn isNormal(x: var) -> bool {
+pub fn isNormal(x: var) bool {
const T = @typeOf(x);
switch (T) {
f32 => {
diff --git a/std/math/ln.zig b/std/math/ln.zig
index 57e2ffdec8..c349ed7c6f 100644
--- a/std/math/ln.zig
+++ b/std/math/ln.zig
@@ -11,7 +11,7 @@ const assert = std.debug.assert;
const builtin = @import("builtin");
const TypeId = builtin.TypeId;
-pub fn ln(x: var) -> @typeOf(x) {
+pub fn ln(x: var) @typeOf(x) {
const T = @typeOf(x);
switch (@typeId(T)) {
TypeId.FloatLiteral => {
@@ -34,7 +34,7 @@ pub fn ln(x: var) -> @typeOf(x) {
}
}
-pub fn ln_32(x_: f32) -> f32 {
+pub fn ln_32(x_: f32) f32 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const ln2_hi: f32 = 6.9313812256e-01;
@@ -88,7 +88,7 @@ pub fn ln_32(x_: f32) -> f32 {
return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
}
-pub fn ln_64(x_: f64) -> f64 {
+pub fn ln_64(x_: f64) f64 {
const ln2_hi: f64 = 6.93147180369123816490e-01;
const ln2_lo: f64 = 1.90821492927058770002e-10;
const Lg1: f64 = 6.666666666666735130e-01;
diff --git a/std/math/log.zig b/std/math/log.zig
index 6bed4c0da1..1cba1138db 100644
--- a/std/math/log.zig
+++ b/std/math/log.zig
@@ -4,7 +4,7 @@ const builtin = @import("builtin");
const TypeId = builtin.TypeId;
const assert = std.debug.assert;
-pub fn log(comptime T: type, base: T, x: T) -> T {
+pub fn log(comptime T: type, base: T, x: T) T {
if (base == 2) {
return math.log2(x);
} else if (base == 10) {
diff --git a/std/math/log10.zig b/std/math/log10.zig
index e27d3eb272..aa74caa901 100644
--- a/std/math/log10.zig
+++ b/std/math/log10.zig
@@ -11,7 +11,7 @@ const assert = std.debug.assert;
const builtin = @import("builtin");
const TypeId = builtin.TypeId;
-pub fn log10(x: var) -> @typeOf(x) {
+pub fn log10(x: var) @typeOf(x) {
const T = @typeOf(x);
switch (@typeId(T)) {
TypeId.FloatLiteral => {
@@ -34,7 +34,7 @@ pub fn log10(x: var) -> @typeOf(x) {
}
}
-pub fn log10_32(x_: f32) -> f32 {
+pub fn log10_32(x_: f32) f32 {
const ivln10hi: f32 = 4.3432617188e-01;
const ivln10lo: f32 = -3.1689971365e-05;
const log10_2hi: f32 = 3.0102920532e-01;
@@ -94,7 +94,7 @@ pub fn log10_32(x_: f32) -> f32 {
return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
}
-pub fn log10_64(x_: f64) -> f64 {
+pub fn log10_64(x_: f64) f64 {
const ivln10hi: f64 = 4.34294481878168880939e-01;
const ivln10lo: f64 = 2.50829467116452752298e-11;
const log10_2hi: f64 = 3.01029995663611771306e-01;
diff --git a/std/math/log1p.zig b/std/math/log1p.zig
index ce5aad1d85..4616a2f2ba 100644
--- a/std/math/log1p.zig
+++ b/std/math/log1p.zig
@@ -10,7 +10,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn log1p(x: var) -> @typeOf(x) {
+pub fn log1p(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => log1p_32(x),
@@ -19,7 +19,7 @@ pub fn log1p(x: var) -> @typeOf(x) {
};
}
-fn log1p_32(x: f32) -> f32 {
+fn log1p_32(x: f32) f32 {
const ln2_hi = 6.9313812256e-01;
const ln2_lo = 9.0580006145e-06;
const Lg1: f32 = 0xaaaaaa.0p-24;
@@ -95,7 +95,7 @@ fn log1p_32(x: f32) -> f32 {
return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
}
-fn log1p_64(x: f64) -> f64 {
+fn log1p_64(x: f64) f64 {
const ln2_hi: f64 = 6.93147180369123816490e-01;
const ln2_lo: f64 = 1.90821492927058770002e-10;
const Lg1: f64 = 6.666666666666735130e-01;
diff --git a/std/math/log2.zig b/std/math/log2.zig
index 7839759974..998d6d6c5e 100644
--- a/std/math/log2.zig
+++ b/std/math/log2.zig
@@ -11,7 +11,7 @@ const assert = std.debug.assert;
const builtin = @import("builtin");
const TypeId = builtin.TypeId;
-pub fn log2(x: var) -> @typeOf(x) {
+pub fn log2(x: var) @typeOf(x) {
const T = @typeOf(x);
switch (@typeId(T)) {
TypeId.FloatLiteral => {
@@ -37,12 +37,12 @@ pub fn log2(x: var) -> @typeOf(x) {
}
}
-pub fn log2_int(comptime T: type, x: T) -> T {
+pub fn log2_int(comptime T: type, x: T) T {
assert(x != 0);
return T.bit_count - 1 - T(@clz(x));
}
-pub fn log2_32(x_: f32) -> f32 {
+pub fn log2_32(x_: f32) f32 {
const ivln2hi: f32 = 1.4428710938e+00;
const ivln2lo: f32 = -1.7605285393e-04;
const Lg1: f32 = 0xaaaaaa.0p-24;
@@ -98,7 +98,7 @@ pub fn log2_32(x_: f32) -> f32 {
return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + f32(k);
}
-pub fn log2_64(x_: f64) -> f64 {
+pub fn log2_64(x_: f64) f64 {
const ivln2hi: f64 = 1.44269504072144627571e+00;
const ivln2lo: f64 = 1.67517131648865118353e-10;
const Lg1: f64 = 6.666666666666735130e-01;
diff --git a/std/math/modf.zig b/std/math/modf.zig
index dc17f35b54..a6606ce34c 100644
--- a/std/math/modf.zig
+++ b/std/math/modf.zig
@@ -7,7 +7,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-fn modf_result(comptime T: type) -> type {
+fn modf_result(comptime T: type) type {
return struct {
fpart: T,
ipart: T,
@@ -16,7 +16,7 @@ fn modf_result(comptime T: type) -> type {
pub const modf32_result = modf_result(f32);
pub const modf64_result = modf_result(f64);
-pub fn modf(x: var) -> modf_result(@typeOf(x)) {
+pub fn modf(x: var) modf_result(@typeOf(x)) {
const T = @typeOf(x);
return switch (T) {
f32 => modf32(x),
@@ -25,7 +25,7 @@ pub fn modf(x: var) -> modf_result(@typeOf(x)) {
};
}
-fn modf32(x: f32) -> modf32_result {
+fn modf32(x: f32) modf32_result {
var result: modf32_result = undefined;
const u = @bitCast(u32, x);
@@ -70,7 +70,7 @@ fn modf32(x: f32) -> modf32_result {
return result;
}
-fn modf64(x: f64) -> modf64_result {
+fn modf64(x: f64) modf64_result {
var result: modf64_result = undefined;
const u = @bitCast(u64, x);
diff --git a/std/math/nan.zig b/std/math/nan.zig
index e92bb04cb9..22461711d0 100644
--- a/std/math/nan.zig
+++ b/std/math/nan.zig
@@ -1,6 +1,6 @@
const math = @import("index.zig");
-pub fn nan(comptime T: type) -> T {
+pub fn nan(comptime T: type) T {
return switch (T) {
f32 => @bitCast(f32, math.nan_u32),
f64 => @bitCast(f64, math.nan_u64),
@@ -10,7 +10,7 @@ pub fn nan(comptime T: type) -> T {
// Note: A signalling nan is identical to a standard right now by may have a different bit
// representation in the future when required.
-pub fn snan(comptime T: type) -> T {
+pub fn snan(comptime T: type) T {
return switch (T) {
f32 => @bitCast(f32, math.nan_u32),
f64 => @bitCast(f64, math.nan_u64),
diff --git a/std/math/pow.zig b/std/math/pow.zig
index c0157ff16e..51908f30ea 100644
--- a/std/math/pow.zig
+++ b/std/math/pow.zig
@@ -27,7 +27,7 @@ const math = std.math;
const assert = std.debug.assert;
// This implementation is taken from the go stlib, musl is a bit more complex.
-pub fn pow(comptime T: type, x: T, y: T) -> T {
+pub fn pow(comptime T: type, x: T, y: T) T {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
@@ -170,7 +170,7 @@ pub fn pow(comptime T: type, x: T, y: T) -> T {
return math.scalbn(a1, ae);
}
-fn isOddInteger(x: f64) -> bool {
+fn isOddInteger(x: f64) bool {
const r = math.modf(x);
return r.fpart == 0.0 and i64(r.ipart) & 1 == 1;
}
diff --git a/std/math/round.zig b/std/math/round.zig
index 06b9e41f58..c16190da21 100644
--- a/std/math/round.zig
+++ b/std/math/round.zig
@@ -9,7 +9,7 @@ const assert = std.debug.assert;
const std = @import("../index.zig");
const math = std.math;
-pub fn round(x: var) -> @typeOf(x) {
+pub fn round(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => round32(x),
@@ -18,7 +18,7 @@ pub fn round(x: var) -> @typeOf(x) {
};
}
-fn round32(x_: f32) -> f32 {
+fn round32(x_: f32) f32 {
var x = x_;
const u = @bitCast(u32, x);
const e = (u >> 23) & 0xFF;
@@ -55,7 +55,7 @@ fn round32(x_: f32) -> f32 {
}
}
-fn round64(x_: f64) -> f64 {
+fn round64(x_: f64) f64 {
var x = x_;
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
diff --git a/std/math/scalbn.zig b/std/math/scalbn.zig
index 6d1c776593..deb5d989d2 100644
--- a/std/math/scalbn.zig
+++ b/std/math/scalbn.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn scalbn(x: var, n: i32) -> @typeOf(x) {
+pub fn scalbn(x: var, n: i32) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => scalbn32(x, n),
@@ -11,7 +11,7 @@ pub fn scalbn(x: var, n: i32) -> @typeOf(x) {
};
}
-fn scalbn32(x: f32, n_: i32) -> f32 {
+fn scalbn32(x: f32, n_: i32) f32 {
var y = x;
var n = n_;
@@ -41,7 +41,7 @@ fn scalbn32(x: f32, n_: i32) -> f32 {
return y * @bitCast(f32, u);
}
-fn scalbn64(x: f64, n_: i32) -> f64 {
+fn scalbn64(x: f64, n_: i32) f64 {
var y = x;
var n = n_;
diff --git a/std/math/signbit.zig b/std/math/signbit.zig
index b9bfe818de..a0191bed5c 100644
--- a/std/math/signbit.zig
+++ b/std/math/signbit.zig
@@ -2,7 +2,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn signbit(x: var) -> bool {
+pub fn signbit(x: var) bool {
const T = @typeOf(x);
return switch (T) {
f32 => signbit32(x),
@@ -11,12 +11,12 @@ pub fn signbit(x: var) -> bool {
};
}
-fn signbit32(x: f32) -> bool {
+fn signbit32(x: f32) bool {
const bits = @bitCast(u32, x);
return bits >> 31 != 0;
}
-fn signbit64(x: f64) -> bool {
+fn signbit64(x: f64) bool {
const bits = @bitCast(u64, x);
return bits >> 63 != 0;
}
diff --git a/std/math/sin.zig b/std/math/sin.zig
index 5b1090e99e..5dd869545b 100644
--- a/std/math/sin.zig
+++ b/std/math/sin.zig
@@ -9,7 +9,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn sin(x: var) -> @typeOf(x) {
+pub fn sin(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => sin32(x),
@@ -37,7 +37,7 @@ const C5 = 4.16666666666665929218E-2;
// NOTE: This is taken from the go stdlib. The musl implementation is much more complex.
//
// This may have slight differences on some edge cases and may need to replaced if so.
-fn sin32(x_: f32) -> f32 {
+fn sin32(x_: f32) f32 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const pi4a = 7.85398125648498535156e-1;
@@ -91,7 +91,7 @@ fn sin32(x_: f32) -> f32 {
}
}
-fn sin64(x_: f64) -> f64 {
+fn sin64(x_: f64) f64 {
const pi4a = 7.85398125648498535156e-1;
const pi4b = 3.77489470793079817668E-8;
const pi4c = 2.69515142907905952645E-15;
diff --git a/std/math/sinh.zig b/std/math/sinh.zig
index b0057f897b..85c9ae979b 100644
--- a/std/math/sinh.zig
+++ b/std/math/sinh.zig
@@ -10,7 +10,7 @@ const math = std.math;
const assert = std.debug.assert;
const expo2 = @import("expo2.zig").expo2;
-pub fn sinh(x: var) -> @typeOf(x) {
+pub fn sinh(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => sinh32(x),
@@ -22,7 +22,7 @@ pub fn sinh(x: var) -> @typeOf(x) {
// sinh(x) = (exp(x) - 1 / exp(x)) / 2
// = (exp(x) - 1 + (exp(x) - 1) / exp(x)) / 2
// = x + x^3 / 6 + o(x^5)
-fn sinh32(x: f32) -> f32 {
+fn sinh32(x: f32) f32 {
const u = @bitCast(u32, x);
const ux = u & 0x7FFFFFFF;
const ax = @bitCast(f32, ux);
@@ -53,7 +53,7 @@ fn sinh32(x: f32) -> f32 {
return 2 * h * expo2(ax);
}
-fn sinh64(x: f64) -> f64 {
+fn sinh64(x: f64) f64 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const u = @bitCast(u64, x);
diff --git a/std/math/sqrt.zig b/std/math/sqrt.zig
index 18cee6e248..690f8b6901 100644
--- a/std/math/sqrt.zig
+++ b/std/math/sqrt.zig
@@ -11,7 +11,7 @@ const assert = std.debug.assert;
const builtin = @import("builtin");
const TypeId = builtin.TypeId;
-pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
+pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
const T = @typeOf(x);
switch (@typeId(T)) {
TypeId.FloatLiteral => {
@@ -50,7 +50,7 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @
}
}
-fn sqrt32(x: f32) -> f32 {
+fn sqrt32(x: f32) f32 {
const tiny: f32 = 1.0e-30;
const sign: i32 = @bitCast(i32, u32(0x80000000));
var ix: i32 = @bitCast(i32, x);
@@ -129,7 +129,7 @@ fn sqrt32(x: f32) -> f32 {
// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
// behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are
// potentially some edge cases remaining that are not handled in the same way.
-fn sqrt64(x: f64) -> f64 {
+fn sqrt64(x: f64) f64 {
const tiny: f64 = 1.0e-300;
const sign: u32 = 0x80000000;
const u = @bitCast(u64, x);
@@ -308,7 +308,7 @@ test "math.sqrt64.special" {
assert(math.isNan(sqrt64(math.nan(f64))));
}
-fn sqrt_int(comptime T: type, value: T) -> @IntType(false, T.bit_count / 2) {
+fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
var op = value;
var res: T = 0;
var one: T = 1 << (T.bit_count - 2);
diff --git a/std/math/tan.zig b/std/math/tan.zig
index 9afe102d64..11428b6e8b 100644
--- a/std/math/tan.zig
+++ b/std/math/tan.zig
@@ -9,7 +9,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn tan(x: var) -> @typeOf(x) {
+pub fn tan(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => tan32(x),
@@ -30,7 +30,7 @@ const Tq4 = -5.38695755929454629881E7;
// NOTE: This is taken from the go stdlib. The musl implementation is much more complex.
//
// This may have slight differences on some edge cases and may need to replaced if so.
-fn tan32(x_: f32) -> f32 {
+fn tan32(x_: f32) f32 {
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const pi4a = 7.85398125648498535156e-1;
@@ -81,7 +81,7 @@ fn tan32(x_: f32) -> f32 {
return r;
}
-fn tan64(x_: f64) -> f64 {
+fn tan64(x_: f64) f64 {
const pi4a = 7.85398125648498535156e-1;
const pi4b = 3.77489470793079817668E-8;
const pi4c = 2.69515142907905952645E-15;
diff --git a/std/math/tanh.zig b/std/math/tanh.zig
index 8560538cdf..c1f5a0ca46 100644
--- a/std/math/tanh.zig
+++ b/std/math/tanh.zig
@@ -10,7 +10,7 @@ const math = std.math;
const assert = std.debug.assert;
const expo2 = @import("expo2.zig").expo2;
-pub fn tanh(x: var) -> @typeOf(x) {
+pub fn tanh(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => tanh32(x),
@@ -22,7 +22,7 @@ pub fn tanh(x: var) -> @typeOf(x) {
// tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
// = (exp(2x) - 1) / (exp(2x) - 1 + 2)
// = (1 - exp(-2x)) / (exp(-2x) - 1 + 2)
-fn tanh32(x: f32) -> f32 {
+fn tanh32(x: f32) f32 {
const u = @bitCast(u32, x);
const ux = u & 0x7FFFFFFF;
const ax = @bitCast(f32, ux);
@@ -66,7 +66,7 @@ fn tanh32(x: f32) -> f32 {
}
}
-fn tanh64(x: f64) -> f64 {
+fn tanh64(x: f64) f64 {
const u = @bitCast(u64, x);
const w = u32(u >> 32);
const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
diff --git a/std/math/trunc.zig b/std/math/trunc.zig
index 1d9032a22c..54aa6943f7 100644
--- a/std/math/trunc.zig
+++ b/std/math/trunc.zig
@@ -8,7 +8,7 @@ const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
-pub fn trunc(x: var) -> @typeOf(x) {
+pub fn trunc(x: var) @typeOf(x) {
const T = @typeOf(x);
return switch (T) {
f32 => trunc32(x),
@@ -17,7 +17,7 @@ pub fn trunc(x: var) -> @typeOf(x) {
};
}
-fn trunc32(x: f32) -> f32 {
+fn trunc32(x: f32) f32 {
const u = @bitCast(u32, x);
var e = i32(((u >> 23) & 0xFF)) - 0x7F + 9;
var m: u32 = undefined;
@@ -38,7 +38,7 @@ fn trunc32(x: f32) -> f32 {
}
}
-fn trunc64(x: f64) -> f64 {
+fn trunc64(x: f64) f64 {
const u = @bitCast(u64, x);
var e = i32(((u >> 52) & 0x7FF)) - 0x3FF + 12;
var m: u64 = undefined;
diff --git a/std/math/x86_64/sqrt.zig b/std/math/x86_64/sqrt.zig
index fbb898c297..ad9ce0c96c 100644
--- a/std/math/x86_64/sqrt.zig
+++ b/std/math/x86_64/sqrt.zig
@@ -1,4 +1,4 @@
-pub fn sqrt32(x: f32) -> f32 {
+pub fn sqrt32(x: f32) f32 {
return asm (
\\sqrtss %%xmm0, %%xmm0
: [ret] "={xmm0}" (-> f32)
@@ -6,7 +6,7 @@ pub fn sqrt32(x: f32) -> f32 {
);
}
-pub fn sqrt64(x: f64) -> f64 {
+pub fn sqrt64(x: f64) f64 {
return asm (
\\sqrtsd %%xmm0, %%xmm0
: [ret] "={xmm0}" (-> f64)
diff --git a/std/mem.zig b/std/mem.zig
index a4ce3843b3..86bf5e2f3d 100644
--- a/std/mem.zig
+++ b/std/mem.zig
@@ -10,7 +10,7 @@ pub const Allocator = struct {
/// Allocate byte_count bytes and return them in a slice, with the
/// slice's pointer aligned at least to alignment bytes.
/// The returned newly allocated memory is undefined.
- allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) -> %[]u8,
+ allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) %[]u8,
/// If `new_byte_count > old_mem.len`:
/// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.
@@ -21,26 +21,26 @@ pub const Allocator = struct {
/// * alignment <= alignment of old_mem.ptr
///
/// The returned newly allocated memory is undefined.
- reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) -> %[]u8,
+ reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) %[]u8,
/// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
- freeFn: fn (self: &Allocator, old_mem: []u8),
+ freeFn: fn (self: &Allocator, old_mem: []u8) void,
- fn create(self: &Allocator, comptime T: type) -> %&T {
+ fn create(self: &Allocator, comptime T: type) %&T {
const slice = try self.alloc(T, 1);
return &slice[0];
}
- fn destroy(self: &Allocator, ptr: var) {
+ fn destroy(self: &Allocator, ptr: var) void {
self.free(ptr[0..1]);
}
- fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T {
+ fn alloc(self: &Allocator, comptime T: type, n: usize) %[]T {
return self.alignedAlloc(T, @alignOf(T), n);
}
fn alignedAlloc(self: &Allocator, comptime T: type, comptime alignment: u29,
- n: usize) -> %[]align(alignment) T
+ n: usize) %[]align(alignment) T
{
const byte_count = try math.mul(usize, @sizeOf(T), n);
const byte_slice = try self.allocFn(self, byte_count, alignment);
@@ -51,12 +51,12 @@ pub const Allocator = struct {
return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
}
- fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) -> %[]T {
+ fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) %[]T {
return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
}
fn alignedRealloc(self: &Allocator, comptime T: type, comptime alignment: u29,
- old_mem: []align(alignment) T, n: usize) -> %[]align(alignment) T
+ old_mem: []align(alignment) T, n: usize) %[]align(alignment) T
{
if (old_mem.len == 0) {
return self.alloc(T, n);
@@ -75,12 +75,12 @@ pub const Allocator = struct {
/// Reallocate, but `n` must be less than or equal to `old_mem.len`.
/// Unlike `realloc`, this function cannot fail.
/// Shrinking to 0 is the same as calling `free`.
- fn shrink(self: &Allocator, comptime T: type, old_mem: []T, n: usize) -> []T {
+ fn shrink(self: &Allocator, comptime T: type, old_mem: []T, n: usize) []T {
return self.alignedShrink(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
}
fn alignedShrink(self: &Allocator, comptime T: type, comptime alignment: u29,
- old_mem: []align(alignment) T, n: usize) -> []align(alignment) T
+ old_mem: []align(alignment) T, n: usize) []align(alignment) T
{
if (n == 0) {
self.free(old_mem);
@@ -97,7 +97,7 @@ pub const Allocator = struct {
return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
}
- fn free(self: &Allocator, memory: var) {
+ fn free(self: &Allocator, memory: var) void {
const bytes = ([]const u8)(memory);
if (bytes.len == 0)
return;
@@ -111,7 +111,7 @@ pub const FixedBufferAllocator = struct {
end_index: usize,
buffer: []u8,
- pub fn init(buffer: []u8) -> FixedBufferAllocator {
+ pub fn init(buffer: []u8) FixedBufferAllocator {
return FixedBufferAllocator {
.allocator = Allocator {
.allocFn = alloc,
@@ -123,7 +123,7 @@ pub const FixedBufferAllocator = struct {
};
}
- fn alloc(allocator: &Allocator, n: usize, alignment: u29) -> %[]u8 {
+ fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 {
const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
const addr = @ptrToInt(&self.buffer[self.end_index]);
const rem = @rem(addr, alignment);
@@ -138,7 +138,7 @@ pub const FixedBufferAllocator = struct {
return result;
}
- fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
+ fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 {
if (new_size <= old_mem.len) {
return old_mem[0..new_size];
} else {
@@ -148,13 +148,13 @@ pub const FixedBufferAllocator = struct {
}
}
- fn free(allocator: &Allocator, bytes: []u8) { }
+ fn free(allocator: &Allocator, bytes: []u8) void { }
};
/// Copy all of source into dest at position 0.
/// dest.len must be >= source.len.
-pub fn copy(comptime T: type, dest: []T, source: []const T) {
+pub fn copy(comptime T: type, dest: []T, source: []const T) void {
// TODO instead of manually doing this check for the whole array
// and turning off runtime safety, the compiler should detect loops like
// this and automatically omit safety checks for loops
@@ -163,12 +163,12 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) {
for (source) |s, i| dest[i] = s;
}
-pub fn set(comptime T: type, dest: []T, value: T) {
+pub fn set(comptime T: type, dest: []T, value: T) void {
for (dest) |*d| *d = value;
}
/// Returns true if lhs < rhs, false otherwise
-pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) -> bool {
+pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
const n = math.min(lhs.len, rhs.len);
var i: usize = 0;
while (i < n) : (i += 1) {
@@ -188,7 +188,7 @@ test "mem.lessThan" {
}
/// Compares two slices and returns whether they are equal.
-pub fn eql(comptime T: type, a: []const T, b: []const T) -> bool {
+pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
if (a.len != b.len) return false;
for (a) |item, index| {
if (b[index] != item) return false;
@@ -197,14 +197,14 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) -> bool {
}
/// Copies ::m to newly allocated memory. Caller is responsible to free it.
-pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) -> %[]T {
+pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) %[]T {
const new_buf = try allocator.alloc(T, m.len);
copy(T, new_buf, m);
return new_buf;
}
/// Remove values from the beginning and end of a slice.
-pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) -> []const T {
+pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T {
var begin: usize = 0;
var end: usize = slice.len;
while (begin < end and indexOfScalar(T, values_to_strip, slice[begin]) != null) : (begin += 1) {}
@@ -218,11 +218,11 @@ test "mem.trim" {
}
/// Linear search for the index of a scalar value inside a slice.
-pub fn indexOfScalar(comptime T: type, slice: []const T, value: T) -> ?usize {
+pub fn indexOfScalar(comptime T: type, slice: []const T, value: T) ?usize {
return indexOfScalarPos(T, slice, 0, value);
}
-pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) -> ?usize {
+pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) ?usize {
var i: usize = start_index;
while (i < slice.len) : (i += 1) {
if (slice[i] == value)
@@ -231,11 +231,11 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize,
return null;
}
-pub fn indexOfAny(comptime T: type, slice: []const T, values: []const T) -> ?usize {
+pub fn indexOfAny(comptime T: type, slice: []const T, values: []const T) ?usize {
return indexOfAnyPos(T, slice, 0, values);
}
-pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, values: []const T) -> ?usize {
+pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, values: []const T) ?usize {
var i: usize = start_index;
while (i < slice.len) : (i += 1) {
for (values) |value| {
@@ -246,12 +246,12 @@ pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, val
return null;
}
-pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) -> ?usize {
+pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize {
return indexOfPos(T, haystack, 0, needle);
}
// TODO boyer-moore algorithm
-pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) -> ?usize {
+pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
if (needle.len > haystack.len)
return null;
@@ -275,7 +275,7 @@ test "mem.indexOf" {
/// T specifies the return type, which must be large enough to store
/// the result.
/// See also ::readIntBE or ::readIntLE.
-pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) -> T {
+pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) T {
if (T.bit_count == 8) {
return bytes[0];
}
@@ -298,7 +298,7 @@ pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) -> T
/// Reads a big-endian int of type T from bytes.
/// bytes.len must be exactly @sizeOf(T).
-pub fn readIntBE(comptime T: type, bytes: []const u8) -> T {
+pub fn readIntBE(comptime T: type, bytes: []const u8) T {
if (T.is_signed) {
return @bitCast(T, readIntBE(@IntType(false, T.bit_count), bytes));
}
@@ -312,7 +312,7 @@ pub fn readIntBE(comptime T: type, bytes: []const u8) -> T {
/// Reads a little-endian int of type T from bytes.
/// bytes.len must be exactly @sizeOf(T).
-pub fn readIntLE(comptime T: type, bytes: []const u8) -> T {
+pub fn readIntLE(comptime T: type, bytes: []const u8) T {
if (T.is_signed) {
return @bitCast(T, readIntLE(@IntType(false, T.bit_count), bytes));
}
@@ -327,7 +327,7 @@ pub fn readIntLE(comptime T: type, bytes: []const u8) -> T {
/// Writes an integer to memory with size equal to bytes.len. Pads with zeroes
/// to fill the entire buffer provided.
/// value must be an integer.
-pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) {
+pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) void {
const uint = @IntType(false, @typeOf(value).bit_count);
var bits = @truncate(uint, value);
switch (endian) {
@@ -351,7 +351,7 @@ pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) {
}
-pub fn hash_slice_u8(k: []const u8) -> u32 {
+pub fn hash_slice_u8(k: []const u8) u32 {
// FNV 32-bit hash
var h: u32 = 2166136261;
for (k) |b| {
@@ -360,7 +360,7 @@ pub fn hash_slice_u8(k: []const u8) -> u32 {
return h;
}
-pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool {
+pub fn eql_slice_u8(a: []const u8, b: []const u8) bool {
return eql(u8, a, b);
}
@@ -368,7 +368,7 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool {
/// any of the bytes in `split_bytes`.
/// split(" abc def ghi ", " ")
/// Will return slices for "abc", "def", "ghi", null, in that order.
-pub fn split(buffer: []const u8, split_bytes: []const u8) -> SplitIterator {
+pub fn split(buffer: []const u8, split_bytes: []const u8) SplitIterator {
return SplitIterator {
.index = 0,
.buffer = buffer,
@@ -384,7 +384,7 @@ test "mem.split" {
assert(it.next() == null);
}
-pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) -> bool {
+pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
return if (needle.len > haystack.len) false else eql(T, haystack[0 .. needle.len], needle);
}
@@ -393,7 +393,7 @@ const SplitIterator = struct {
split_bytes: []const u8,
index: usize,
- pub fn next(self: &SplitIterator) -> ?[]const u8 {
+ pub fn next(self: &SplitIterator) ?[]const u8 {
// move to beginning of token
while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
const start = self.index;
@@ -409,14 +409,14 @@ const SplitIterator = struct {
}
/// Returns a slice of the remaining bytes. Does not affect iterator state.
- pub fn rest(self: &const SplitIterator) -> []const u8 {
+ pub fn rest(self: &const SplitIterator) []const u8 {
// move to beginning of token
var index: usize = self.index;
while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {}
return self.buffer[index..];
}
- fn isSplitByte(self: &const SplitIterator, byte: u8) -> bool {
+ fn isSplitByte(self: &const SplitIterator, byte: u8) bool {
for (self.split_bytes) |split_byte| {
if (byte == split_byte) {
return true;
@@ -428,7 +428,7 @@ const SplitIterator = struct {
/// Naively combines a series of strings with a separator.
/// Allocates memory for the result, which must be freed by the caller.
-pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 {
+pub fn join(allocator: &Allocator, sep: u8, strings: ...) %[]u8 {
comptime assert(strings.len >= 1);
var total_strings_len: usize = strings.len; // 1 sep per string
{
@@ -474,7 +474,7 @@ test "testReadInt" {
testReadIntImpl();
comptime testReadIntImpl();
}
-fn testReadIntImpl() {
+fn testReadIntImpl() void {
{
const bytes = []u8{ 0x12, 0x34, 0x56, 0x78 };
assert(readInt(bytes, u32, builtin.Endian.Big) == 0x12345678);
@@ -507,7 +507,7 @@ test "testWriteInt" {
testWriteIntImpl();
comptime testWriteIntImpl();
}
-fn testWriteIntImpl() {
+fn testWriteIntImpl() void {
var bytes: [4]u8 = undefined;
writeInt(bytes[0..], u32(0x12345678), builtin.Endian.Big);
@@ -524,7 +524,7 @@ fn testWriteIntImpl() {
}
-pub fn min(comptime T: type, slice: []const T) -> T {
+pub fn min(comptime T: type, slice: []const T) T {
var best = slice[0];
for (slice[1..]) |item| {
best = math.min(best, item);
@@ -536,7 +536,7 @@ test "mem.min" {
assert(min(u8, "abcdefg") == 'a');
}
-pub fn max(comptime T: type, slice: []const T) -> T {
+pub fn max(comptime T: type, slice: []const T) T {
var best = slice[0];
for (slice[1..]) |item| {
best = math.max(best, item);
@@ -548,14 +548,14 @@ test "mem.max" {
assert(max(u8, "abcdefg") == 'g');
}
-pub fn swap(comptime T: type, a: &T, b: &T) {
+pub fn swap(comptime T: type, a: &T, b: &T) void {
const tmp = *a;
*a = *b;
*b = tmp;
}
/// In-place order reversal of a slice
-pub fn reverse(comptime T: type, items: []T) {
+pub fn reverse(comptime T: type, items: []T) void {
var i: usize = 0;
const end = items.len / 2;
while (i < end) : (i += 1) {
@@ -572,7 +572,7 @@ test "std.mem.reverse" {
/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
/// Assumes 0 <= amount <= items.len
-pub fn rotate(comptime T: type, items: []T, amount: usize) {
+pub fn rotate(comptime T: type, items: []T, amount: usize) void {
reverse(T, items[0..amount]);
reverse(T, items[amount..]);
reverse(T, items);
diff --git a/std/net.zig b/std/net.zig
index fa337eab75..4fbfd9b9aa 100644
--- a/std/net.zig
+++ b/std/net.zig
@@ -17,7 +17,7 @@ error BadFd;
const Connection = struct {
socket_fd: i32,
- pub fn send(c: Connection, buf: []const u8) -> %usize {
+ pub fn send(c: Connection, buf: []const u8) %usize {
const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0);
const send_err = linux.getErrno(send_ret);
switch (send_err) {
@@ -31,7 +31,7 @@ const Connection = struct {
}
}
- pub fn recv(c: Connection, buf: []u8) -> %[]u8 {
+ pub fn recv(c: Connection, buf: []u8) %[]u8 {
const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null);
const recv_err = linux.getErrno(recv_ret);
switch (recv_err) {
@@ -48,7 +48,7 @@ const Connection = struct {
}
}
- pub fn close(c: Connection) -> %void {
+ pub fn close(c: Connection) %void {
switch (linux.getErrno(linux.close(c.socket_fd))) {
0 => return,
linux.EBADF => unreachable,
@@ -66,7 +66,7 @@ const Address = struct {
sort_key: i32,
};
-pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
+pub fn lookup(hostname: []const u8, out_addrs: []Address) %[]Address {
if (hostname.len == 0) {
unreachable; // TODO
@@ -75,7 +75,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
unreachable; // TODO
}
-pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
+pub fn connectAddr(addr: &Address, port: u16) %Connection {
const socket_ret = linux.socket(addr.family, linux.SOCK_STREAM, linux.PROTO_tcp);
const socket_err = linux.getErrno(socket_ret);
if (socket_err > 0) {
@@ -118,7 +118,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
};
}
-pub fn connect(hostname: []const u8, port: u16) -> %Connection {
+pub fn connect(hostname: []const u8, port: u16) %Connection {
var addrs_buf: [1]Address = undefined;
const addrs_slice = try lookup(hostname, addrs_buf[0..]);
const main_addr = &addrs_slice[0];
@@ -128,12 +128,12 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection {
error InvalidIpLiteral;
-pub fn parseIpLiteral(buf: []const u8) -> %Address {
+pub fn parseIpLiteral(buf: []const u8) %Address {
return error.InvalidIpLiteral;
}
-fn hexDigit(c: u8) -> u8 {
+fn hexDigit(c: u8) u8 {
// TODO use switch with range
if ('0' <= c and c <= '9') {
return c - '0';
@@ -151,7 +151,7 @@ error Overflow;
error JunkAtEnd;
error Incomplete;
-fn parseIp6(buf: []const u8) -> %Address {
+fn parseIp6(buf: []const u8) %Address {
var result: Address = undefined;
result.family = linux.AF_INET6;
result.scope_id = 0;
@@ -232,7 +232,7 @@ fn parseIp6(buf: []const u8) -> %Address {
return error.Incomplete;
}
-fn parseIp4(buf: []const u8) -> %u32 {
+fn parseIp4(buf: []const u8) %u32 {
var result: u32 = undefined;
const out_ptr = ([]u8)((&result)[0..1]);
diff --git a/std/os/child_process.zig b/std/os/child_process.zig
index aaa7ac3970..f4709ce75a 100644
--- a/std/os/child_process.zig
+++ b/std/os/child_process.zig
@@ -37,7 +37,7 @@ pub const ChildProcess = struct {
pub argv: []const []const u8,
/// Possibly called from a signal handler. Must set this before calling `spawn`.
- pub onTerm: ?fn(&ChildProcess),
+ pub onTerm: ?fn(&ChildProcess)void,
/// Leave as null to use the current env map using the supplied allocator.
pub env_map: ?&const BufMap,
@@ -74,7 +74,7 @@ pub const ChildProcess = struct {
/// First argument in argv is the executable.
/// On success must call deinit.
- pub fn init(argv: []const []const u8, allocator: &mem.Allocator) -> %&ChildProcess {
+ pub fn init(argv: []const []const u8, allocator: &mem.Allocator) %&ChildProcess {
const child = try allocator.create(ChildProcess);
errdefer allocator.destroy(child);
@@ -103,7 +103,7 @@ pub const ChildProcess = struct {
return child;
}
- pub fn setUserName(self: &ChildProcess, name: []const u8) -> %void {
+ pub fn setUserName(self: &ChildProcess, name: []const u8) %void {
const user_info = try os.getUserInfo(name);
self.uid = user_info.uid;
self.gid = user_info.gid;
@@ -111,7 +111,7 @@ pub const ChildProcess = struct {
/// onTerm can be called before `spawn` returns.
/// On success must call `kill` or `wait`.
- pub fn spawn(self: &ChildProcess) -> %void {
+ pub fn spawn(self: &ChildProcess) %void {
if (is_windows) {
return self.spawnWindows();
} else {
@@ -119,13 +119,13 @@ pub const ChildProcess = struct {
}
}
- pub fn spawnAndWait(self: &ChildProcess) -> %Term {
+ pub fn spawnAndWait(self: &ChildProcess) %Term {
try self.spawn();
return self.wait();
}
/// Forcibly terminates child process and then cleans up all resources.
- pub fn kill(self: &ChildProcess) -> %Term {
+ pub fn kill(self: &ChildProcess) %Term {
if (is_windows) {
return self.killWindows(1);
} else {
@@ -133,7 +133,7 @@ pub const ChildProcess = struct {
}
}
- pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) -> %Term {
+ pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) %Term {
if (self.term) |term| {
self.cleanupStreams();
return term;
@@ -149,7 +149,7 @@ pub const ChildProcess = struct {
return ??self.term;
}
- pub fn killPosix(self: &ChildProcess) -> %Term {
+ pub fn killPosix(self: &ChildProcess) %Term {
block_SIGCHLD();
defer restore_SIGCHLD();
@@ -172,7 +172,7 @@ pub const ChildProcess = struct {
}
/// Blocks until child process terminates and then cleans up all resources.
- pub fn wait(self: &ChildProcess) -> %Term {
+ pub fn wait(self: &ChildProcess) %Term {
if (is_windows) {
return self.waitWindows();
} else {
@@ -189,7 +189,7 @@ pub const ChildProcess = struct {
/// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
/// If it succeeds, the caller owns result.stdout and result.stderr memory.
pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8,
- env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult
+ env_map: ?&const BufMap, max_output_size: usize) %ExecResult
{
const child = try ChildProcess.init(argv, allocator);
defer child.deinit();
@@ -220,7 +220,7 @@ pub const ChildProcess = struct {
};
}
- fn waitWindows(self: &ChildProcess) -> %Term {
+ fn waitWindows(self: &ChildProcess) %Term {
if (self.term) |term| {
self.cleanupStreams();
return term;
@@ -230,7 +230,7 @@ pub const ChildProcess = struct {
return ??self.term;
}
- fn waitPosix(self: &ChildProcess) -> %Term {
+ fn waitPosix(self: &ChildProcess) %Term {
block_SIGCHLD();
defer restore_SIGCHLD();
@@ -243,11 +243,11 @@ pub const ChildProcess = struct {
return ??self.term;
}
- pub fn deinit(self: &ChildProcess) {
+ pub fn deinit(self: &ChildProcess) void {
self.allocator.destroy(self);
}
- fn waitUnwrappedWindows(self: &ChildProcess) -> %void {
+ fn waitUnwrappedWindows(self: &ChildProcess) %void {
const result = os.windowsWaitSingle(self.handle, windows.INFINITE);
self.term = (%Term)(x: {
@@ -265,7 +265,7 @@ pub const ChildProcess = struct {
return result;
}
- fn waitUnwrapped(self: &ChildProcess) {
+ fn waitUnwrapped(self: &ChildProcess) void {
var status: i32 = undefined;
while (true) {
const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));
@@ -281,7 +281,7 @@ pub const ChildProcess = struct {
}
}
- fn handleWaitResult(self: &ChildProcess, status: i32) {
+ fn handleWaitResult(self: &ChildProcess, status: i32) void {
self.term = self.cleanupAfterWait(status);
if (self.onTerm) |onTerm| {
@@ -289,13 +289,13 @@ pub const ChildProcess = struct {
}
}
- fn cleanupStreams(self: &ChildProcess) {
+ fn cleanupStreams(self: &ChildProcess) void {
if (self.stdin) |*stdin| { stdin.close(); self.stdin = null; }
if (self.stdout) |*stdout| { stdout.close(); self.stdout = null; }
if (self.stderr) |*stderr| { stderr.close(); self.stderr = null; }
}
- fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term {
+ fn cleanupAfterWait(self: &ChildProcess, status: i32) %Term {
children_nodes.remove(&self.llnode);
defer {
@@ -319,7 +319,7 @@ pub const ChildProcess = struct {
return statusToTerm(status);
}
- fn statusToTerm(status: i32) -> Term {
+ fn statusToTerm(status: i32) Term {
return if (posix.WIFEXITED(status))
Term { .Exited = posix.WEXITSTATUS(status) }
else if (posix.WIFSIGNALED(status))
@@ -331,7 +331,7 @@ pub const ChildProcess = struct {
;
}
- fn spawnPosix(self: &ChildProcess) -> %void {
+ fn spawnPosix(self: &ChildProcess) %void {
// TODO atomically set a flag saying that we already did this
install_SIGCHLD_handler();
@@ -440,7 +440,7 @@ pub const ChildProcess = struct {
if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); }
}
- fn spawnWindows(self: &ChildProcess) -> %void {
+ fn spawnWindows(self: &ChildProcess) %void {
const saAttr = windows.SECURITY_ATTRIBUTES {
.nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
.bInheritHandle = windows.TRUE,
@@ -623,7 +623,7 @@ pub const ChildProcess = struct {
if (self.stdout_behavior == StdIo.Pipe) { os.close(??g_hChildStd_OUT_Wr); }
}
- fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) -> %void {
+ fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) %void {
switch (stdio) {
StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno),
StdIo.Close => os.close(std_fileno),
@@ -635,7 +635,7 @@ pub const ChildProcess = struct {
};
fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?&u8,
- lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) -> %void
+ lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) %void
{
if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0,
@ptrCast(?&c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0)
@@ -655,7 +655,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
/// Caller must dealloc.
/// Guarantees a null byte at result[result.len].
-fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) -> %[]u8 {
+fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) %[]u8 {
var buf = try Buffer.initSize(allocator, 0);
defer buf.deinit();
@@ -690,7 +690,7 @@ fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8)
return buf.toOwnedSlice();
}
-fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) {
+fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void {
if (rd) |h| os.close(h);
if (wr) |h| os.close(h);
}
@@ -700,7 +700,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) {
// a namespace field lookup
const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;
-fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void {
+fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void {
if (windows.CreatePipe(rd, wr, sattr, 0) == 0) {
const err = windows.GetLastError();
return switch (err) {
@@ -709,7 +709,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECUR
}
}
-fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) -> %void {
+fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) %void {
if (windows.SetHandleInformation(h, mask, flags) == 0) {
const err = windows.GetLastError();
return switch (err) {
@@ -718,7 +718,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D
}
}
-fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void {
+fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void {
var rd_h: windows.HANDLE = undefined;
var wr_h: windows.HANDLE = undefined;
try windowsMakePipe(&rd_h, &wr_h, sattr);
@@ -728,7 +728,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S
*wr = wr_h;
}
-fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void {
+fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void {
var rd_h: windows.HANDLE = undefined;
var wr_h: windows.HANDLE = undefined;
try windowsMakePipe(&rd_h, &wr_h, sattr);
@@ -738,7 +738,7 @@ fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const
*wr = wr_h;
}
-fn makePipe() -> %[2]i32 {
+fn makePipe() %[2]i32 {
var fds: [2]i32 = undefined;
const err = posix.getErrno(posix.pipe(&fds));
if (err > 0) {
@@ -750,33 +750,33 @@ fn makePipe() -> %[2]i32 {
return fds;
}
-fn destroyPipe(pipe: &const [2]i32) {
+fn destroyPipe(pipe: &const [2]i32) void {
os.close((*pipe)[0]);
os.close((*pipe)[1]);
}
// Child of fork calls this to report an error to the fork parent.
// Then the child exits.
-fn forkChildErrReport(fd: i32, err: error) -> noreturn {
+fn forkChildErrReport(fd: i32, err: error) noreturn {
_ = writeIntFd(fd, ErrInt(err));
posix.exit(1);
}
const ErrInt = @IntType(false, @sizeOf(error) * 8);
-fn writeIntFd(fd: i32, value: ErrInt) -> %void {
+fn writeIntFd(fd: i32, value: ErrInt) %void {
var bytes: [@sizeOf(ErrInt)]u8 = undefined;
mem.writeInt(bytes[0..], value, builtin.endian);
os.posixWrite(fd, bytes[0..]) catch return error.SystemResources;
}
-fn readIntFd(fd: i32) -> %ErrInt {
+fn readIntFd(fd: i32) %ErrInt {
var bytes: [@sizeOf(ErrInt)]u8 = undefined;
os.posixRead(fd, bytes[0..]) catch return error.SystemResources;
return mem.readInt(bytes[0..], ErrInt, builtin.endian);
}
-extern fn sigchld_handler(_: i32) {
+extern fn sigchld_handler(_: i32) void {
while (true) {
var status: i32 = undefined;
const pid_result = posix.waitpid(-1, &status, posix.WNOHANG);
@@ -794,7 +794,7 @@ extern fn sigchld_handler(_: i32) {
}
}
-fn handleTerm(pid: i32, status: i32) {
+fn handleTerm(pid: i32, status: i32) void {
var it = children_nodes.first;
while (it) |node| : (it = node.next) {
if (node.data.pid == pid) {
@@ -810,12 +810,12 @@ const sigchld_set = x: {
break :x signal_set;
};
-fn block_SIGCHLD() {
+fn block_SIGCHLD() void {
const err = posix.getErrno(posix.sigprocmask(posix.SIG_BLOCK, &sigchld_set, null));
assert(err == 0);
}
-fn restore_SIGCHLD() {
+fn restore_SIGCHLD() void {
const err = posix.getErrno(posix.sigprocmask(posix.SIG_UNBLOCK, &sigchld_set, null));
assert(err == 0);
}
@@ -826,7 +826,7 @@ const sigchld_action = posix.Sigaction {
.flags = posix.SA_RESTART | posix.SA_NOCLDSTOP,
};
-fn install_SIGCHLD_handler() {
+fn install_SIGCHLD_handler() void {
const err = posix.getErrno(posix.sigaction(posix.SIGCHLD, &sigchld_action, null));
assert(err == 0);
}
diff --git a/std/os/darwin.zig b/std/os/darwin.zig
index 7e3e5e823e..ebc6f65f55 100644
--- a/std/os/darwin.zig
+++ b/std/os/darwin.zig
@@ -98,67 +98,67 @@ pub const SIGINFO = 29; /// information request
pub const SIGUSR1 = 30; /// user defined signal 1
pub const SIGUSR2 = 31; /// user defined signal 2
-fn wstatus(x: i32) -> i32 { return x & 0o177; }
+fn wstatus(x: i32) i32 { return x & 0o177; }
const wstopped = 0o177;
-pub fn WEXITSTATUS(x: i32) -> i32 { return x >> 8; }
-pub fn WTERMSIG(x: i32) -> i32 { return wstatus(x); }
-pub fn WSTOPSIG(x: i32) -> i32 { return x >> 8; }
-pub fn WIFEXITED(x: i32) -> bool { return wstatus(x) == 0; }
-pub fn WIFSTOPPED(x: i32) -> bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; }
-pub fn WIFSIGNALED(x: i32) -> bool { return wstatus(x) != wstopped and wstatus(x) != 0; }
+pub fn WEXITSTATUS(x: i32) i32 { return x >> 8; }
+pub fn WTERMSIG(x: i32) i32 { return wstatus(x); }
+pub fn WSTOPSIG(x: i32) i32 { return x >> 8; }
+pub fn WIFEXITED(x: i32) bool { return wstatus(x) == 0; }
+pub fn WIFSTOPPED(x: i32) bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; }
+pub fn WIFSIGNALED(x: i32) bool { return wstatus(x) != wstopped and wstatus(x) != 0; }
/// Get the errno from a syscall return value, or 0 for no error.
-pub fn getErrno(r: usize) -> usize {
+pub fn getErrno(r: usize) usize {
const signed_r = @bitCast(isize, r);
return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
}
-pub fn close(fd: i32) -> usize {
+pub fn close(fd: i32) usize {
return errnoWrap(c.close(fd));
}
-pub fn abort() -> noreturn {
+pub fn abort() noreturn {
c.abort();
}
-pub fn exit(code: i32) -> noreturn {
+pub fn exit(code: i32) noreturn {
c.exit(code);
}
-pub fn isatty(fd: i32) -> bool {
+pub fn isatty(fd: i32) bool {
return c.isatty(fd) != 0;
}
-pub fn fstat(fd: i32, buf: &c.Stat) -> usize {
+pub fn fstat(fd: i32, buf: &c.Stat) usize {
return errnoWrap(c.@"fstat$INODE64"(fd, buf));
}
-pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize {
+pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
return errnoWrap(c.lseek(fd, offset, whence));
}
-pub fn open(path: &const u8, flags: u32, mode: usize) -> usize {
+pub fn open(path: &const u8, flags: u32, mode: usize) usize {
return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
}
-pub fn raise(sig: i32) -> usize {
+pub fn raise(sig: i32) usize {
return errnoWrap(c.raise(sig));
}
-pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize {
+pub fn read(fd: i32, buf: &u8, nbyte: usize) usize {
return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte));
}
-pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize {
+pub fn stat(noalias path: &const u8, noalias buf: &stat) usize {
return errnoWrap(c.stat(path, buf));
}
-pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize {
+pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
}
pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
- offset: isize) -> usize
+ offset: isize) usize
{
const ptr_result = c.mmap(@ptrCast(&c_void, address), length,
@bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
@@ -166,87 +166,85 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
return errnoWrap(isize_result);
}
-pub fn munmap(address: &u8, length: usize) -> usize {
+pub fn munmap(address: &u8, length: usize) usize {
return errnoWrap(c.munmap(@ptrCast(&c_void, address), length));
}
-pub fn unlink(path: &const u8) -> usize {
+pub fn unlink(path: &const u8) usize {
return errnoWrap(c.unlink(path));
}
-pub fn getcwd(buf: &u8, size: usize) -> usize {
+pub fn getcwd(buf: &u8, size: usize) usize {
return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0;
}
-pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize {
+pub fn waitpid(pid: i32, status: &i32, options: u32) usize {
comptime assert(i32.bit_count == c_int.bit_count);
return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)));
}
-pub fn fork() -> usize {
+pub fn fork() usize {
return errnoWrap(c.fork());
}
-pub fn pipe(fds: &[2]i32) -> usize {
+pub fn pipe(fds: &[2]i32) usize {
comptime assert(i32.bit_count == c_int.bit_count);
return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));
}
-pub fn mkdir(path: &const u8, mode: u32) -> usize {
+pub fn mkdir(path: &const u8, mode: u32) usize {
return errnoWrap(c.mkdir(path, mode));
}
-pub fn symlink(existing: &const u8, new: &const u8) -> usize {
+pub fn symlink(existing: &const u8, new: &const u8) usize {
return errnoWrap(c.symlink(existing, new));
}
-pub fn rename(old: &const u8, new: &const u8) -> usize {
+pub fn rename(old: &const u8, new: &const u8) usize {
return errnoWrap(c.rename(old, new));
}
-pub fn chdir(path: &const u8) -> usize {
+pub fn chdir(path: &const u8) usize {
return errnoWrap(c.chdir(path));
}
-pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8)
- -> usize
-{
+pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
return errnoWrap(c.execve(path, argv, envp));
}
-pub fn dup2(old: i32, new: i32) -> usize {
+pub fn dup2(old: i32, new: i32) usize {
return errnoWrap(c.dup2(old, new));
}
-pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
+pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
return errnoWrap(c.readlink(path, buf_ptr, buf_len));
}
-pub fn nanosleep(req: &const timespec, rem: ?×pec) -> usize {
+pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
return errnoWrap(c.nanosleep(req, rem));
}
-pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize {
+pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize {
return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0;
}
-pub fn setreuid(ruid: u32, euid: u32) -> usize {
+pub fn setreuid(ruid: u32, euid: u32) usize {
return errnoWrap(c.setreuid(ruid, euid));
}
-pub fn setregid(rgid: u32, egid: u32) -> usize {
+pub fn setregid(rgid: u32, egid: u32) usize {
return errnoWrap(c.setregid(rgid, egid));
}
-pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
+pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));
}
-pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
+pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
assert(sig != SIGKILL);
assert(sig != SIGSTOP);
var cact = c.Sigaction {
- .handler = @ptrCast(extern fn(c_int), act.handler),
+ .handler = @ptrCast(extern fn(c_int)void, act.handler),
.sa_flags = @bitCast(c_int, act.flags),
.sa_mask = act.mask,
};
@@ -257,7 +255,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti
}
if (oact) |old| {
*old = Sigaction {
- .handler = @ptrCast(extern fn(i32), coact.handler),
+ .handler = @ptrCast(extern fn(i32)void, coact.handler),
.flags = @bitCast(u32, coact.sa_flags),
.mask = coact.sa_mask,
};
@@ -273,18 +271,18 @@ pub const Stat = c.Stat;
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = struct {
- handler: extern fn(i32),
+ handler: extern fn(i32)void,
mask: sigset_t,
flags: u32,
};
-pub fn sigaddset(set: &sigset_t, signo: u5) {
+pub fn sigaddset(set: &sigset_t, signo: u5) void {
*set |= u32(1) << (signo - 1);
}
/// Takes the return value from a syscall and formats it back in the way
/// that the kernel represents it to libc. Errno was a mistake, let's make
/// it go away forever.
-fn errnoWrap(value: isize) -> usize {
+fn errnoWrap(value: isize) usize {
return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
}
diff --git a/std/os/get_user_id.zig b/std/os/get_user_id.zig
index 7485f788fc..68cb268169 100644
--- a/std/os/get_user_id.zig
+++ b/std/os/get_user_id.zig
@@ -9,7 +9,7 @@ pub const UserInfo = struct {
};
/// POSIX function which gets a uid from username.
-pub fn getUserInfo(name: []const u8) -> %UserInfo {
+pub fn getUserInfo(name: []const u8) %UserInfo {
return switch (builtin.os) {
Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),
else => @compileError("Unsupported OS"),
@@ -30,7 +30,7 @@ error CorruptPasswordFile;
// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else
// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.
-pub fn posixGetUserInfo(name: []const u8) -> %UserInfo {
+pub fn posixGetUserInfo(name: []const u8) %UserInfo {
var in_stream = try io.InStream.open("/etc/passwd", null);
defer in_stream.close();
diff --git a/std/os/index.zig b/std/os/index.zig
index 34ab49ca56..4451faf103 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -75,7 +75,7 @@ error WouldBlock;
/// Fills `buf` with random bytes. If linking against libc, this calls the
/// appropriate OS-specific library call. Otherwise it uses the zig standard
/// library implementation.
-pub fn getRandomBytes(buf: []u8) -> %void {
+pub fn getRandomBytes(buf: []u8) %void {
switch (builtin.os) {
Os.linux => while (true) {
// TODO check libc version and potentially call c.getrandom.
@@ -127,7 +127,7 @@ test "os.getRandomBytes" {
/// Raises a signal in the current kernel thread, ending its execution.
/// If linking against libc, this calls the abort() libc function. Otherwise
/// it uses the zig standard library implementation.
-pub fn abort() -> noreturn {
+pub fn abort() noreturn {
@setCold(true);
if (builtin.link_libc) {
c.abort();
@@ -149,7 +149,7 @@ pub fn abort() -> noreturn {
}
/// Exits the program cleanly with the specified status code.
-pub fn exit(status: u8) -> noreturn {
+pub fn exit(status: u8) noreturn {
@setCold(true);
if (builtin.link_libc) {
c.exit(status);
@@ -166,7 +166,7 @@ pub fn exit(status: u8) -> noreturn {
}
/// Closes the file handle. Keeps trying if it gets interrupted by a signal.
-pub fn close(handle: FileHandle) {
+pub fn close(handle: FileHandle) void {
if (is_windows) {
windows_util.windowsClose(handle);
} else {
@@ -182,7 +182,7 @@ pub fn close(handle: FileHandle) {
}
/// Calls POSIX read, and keeps trying if it gets interrupted.
-pub fn posixRead(fd: i32, buf: []u8) -> %void {
+pub fn posixRead(fd: i32, buf: []u8) %void {
var index: usize = 0;
while (index < buf.len) {
const amt_written = posix.read(fd, &buf[index], buf.len - index);
@@ -213,7 +213,7 @@ error NoSpaceLeft;
error BrokenPipe;
/// Calls POSIX write, and keeps trying if it gets interrupted.
-pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
+pub fn posixWrite(fd: i32, bytes: []const u8) %void {
while (true) {
const write_ret = posix.write(fd, bytes.ptr, bytes.len);
const write_err = posix.getErrno(write_ret);
@@ -243,7 +243,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
/// Calls POSIX open, keeps trying if it gets interrupted, and translates
/// the return value into zig errors.
-pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) -> %i32 {
+pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) %i32 {
var stack_buf: [max_noalloc_path_len]u8 = undefined;
var path0: []u8 = undefined;
var need_free = false;
@@ -292,7 +292,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al
}
}
-pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void {
+pub fn posixDup2(old_fd: i32, new_fd: i32) %void {
while (true) {
const err = posix.getErrno(posix.dup2(old_fd, new_fd));
if (err > 0) {
@@ -307,7 +307,7 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void {
}
}
-pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) -> %[]?&u8 {
+pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) %[]?&u8 {
const envp_count = env_map.count();
const envp_buf = try allocator.alloc(?&u8, envp_count + 1);
mem.set(?&u8, envp_buf, null);
@@ -330,7 +330,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)
return envp_buf;
}
-pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) {
+pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {
for (envp_buf) |env| {
const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
allocator.free(env_buf);
@@ -344,7 +344,7 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) {
/// `argv[0]` is the executable path.
/// This function also uses the PATH environment variable to get the full path to the executable.
pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap,
- allocator: &Allocator) -> %void
+ allocator: &Allocator) %void
{
const argv_buf = try allocator.alloc(?&u8, argv.len + 1);
mem.set(?&u8, argv_buf, null);
@@ -400,7 +400,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap,
return posixExecveErrnoToErr(err);
}
-fn posixExecveErrnoToErr(err: usize) -> error {
+fn posixExecveErrnoToErr(err: usize) error {
assert(err > 0);
return switch (err) {
posix.EFAULT => unreachable,
@@ -419,7 +419,7 @@ fn posixExecveErrnoToErr(err: usize) -> error {
pub var posix_environ_raw: []&u8 = undefined;
/// Caller must free result when done.
-pub fn getEnvMap(allocator: &Allocator) -> %BufMap {
+pub fn getEnvMap(allocator: &Allocator) %BufMap {
var result = BufMap.init(allocator);
errdefer result.deinit();
@@ -463,7 +463,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap {
}
}
-pub fn getEnvPosix(key: []const u8) -> ?[]const u8 {
+pub fn getEnvPosix(key: []const u8) ?[]const u8 {
for (posix_environ_raw) |ptr| {
var line_i: usize = 0;
while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {}
@@ -483,7 +483,7 @@ pub fn getEnvPosix(key: []const u8) -> ?[]const u8 {
error EnvironmentVariableNotFound;
/// Caller must free returned memory.
-pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 {
+pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) %[]u8 {
if (is_windows) {
const key_with_null = try cstr.addNullByte(allocator, key);
defer allocator.free(key_with_null);
@@ -517,7 +517,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 {
}
/// Caller must free the returned memory.
-pub fn getCwd(allocator: &Allocator) -> %[]u8 {
+pub fn getCwd(allocator: &Allocator) %[]u8 {
switch (builtin.os) {
Os.windows => {
var buf = try allocator.alloc(u8, 256);
@@ -564,7 +564,7 @@ test "os.getCwd" {
_ = getCwd(debug.global_allocator);
}
-pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
+pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void {
if (is_windows) {
return symLinkWindows(allocator, existing_path, new_path);
} else {
@@ -572,7 +572,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
}
}
-pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
+pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void {
const existing_with_null = try cstr.addNullByte(allocator, existing_path);
defer allocator.free(existing_with_null);
const new_with_null = try cstr.addNullByte(allocator, new_path);
@@ -586,7 +586,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path
}
}
-pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
+pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void {
const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2);
defer allocator.free(full_buf);
@@ -623,7 +623,7 @@ const b64_fs_encoder = base64.Base64Encoder.init(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
base64.standard_pad_char);
-pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
+pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void {
if (symLink(allocator, existing_path, new_path)) {
return;
} else |err| {
@@ -652,7 +652,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
}
-pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void {
+pub fn deleteFile(allocator: &Allocator, file_path: []const u8) %void {
if (builtin.os == Os.windows) {
return deleteFileWindows(allocator, file_path);
} else {
@@ -663,7 +663,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void {
error FileNotFound;
error AccessDenied;
-pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void {
+pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) %void {
const buf = try allocator.alloc(u8, file_path.len + 1);
defer allocator.free(buf);
@@ -681,7 +681,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void
}
}
-pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void {
+pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) %void {
const buf = try allocator.alloc(u8, file_path.len + 1);
defer allocator.free(buf);
@@ -708,13 +708,13 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void {
}
/// Calls ::copyFileMode with 0o666 for the mode.
-pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) -> %void {
+pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) %void {
return copyFileMode(allocator, source_path, dest_path, 0o666);
}
// TODO instead of accepting a mode argument, use the mode from fstat'ing the source path once open
/// Guaranteed to be atomic.
-pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: usize) -> %void {
+pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: usize) %void {
var rand_buf: [12]u8 = undefined;
const tmp_path = try allocator.alloc(u8, dest_path.len + base64.Base64Encoder.calcSize(rand_buf.len));
defer allocator.free(tmp_path);
@@ -738,7 +738,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [
}
}
-pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) -> %void {
+pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) %void {
const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2);
defer allocator.free(full_buf);
@@ -783,7 +783,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
}
}
-pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {
+pub fn makeDir(allocator: &Allocator, dir_path: []const u8) %void {
if (is_windows) {
return makeDirWindows(allocator, dir_path);
} else {
@@ -791,7 +791,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void {
}
}
-pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void {
+pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) %void {
const path_buf = try cstr.addNullByte(allocator, dir_path);
defer allocator.free(path_buf);
@@ -805,7 +805,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void {
}
}
-pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void {
+pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) %void {
const path_buf = try cstr.addNullByte(allocator, dir_path);
defer allocator.free(path_buf);
@@ -831,7 +831,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void {
/// Calls makeDir recursively to make an entire path. Returns success if the path
/// already exists and is a directory.
-pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void {
+pub fn makePath(allocator: &Allocator, full_path: []const u8) %void {
const resolved_path = try path.resolve(allocator, full_path);
defer allocator.free(resolved_path);
@@ -869,7 +869,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void {
/// Returns ::error.DirNotEmpty if the directory is not empty.
/// To delete a directory recursively, see ::deleteTree
-pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void {
+pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) %void {
const path_buf = try allocator.alloc(u8, dir_path.len + 1);
defer allocator.free(path_buf);
@@ -898,7 +898,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void {
/// removes it. If it cannot be removed because it is a non-empty directory,
/// this function recursively removes its entries and then tries again.
// TODO non-recursive implementation
-pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void {
+pub fn deleteTree(allocator: &Allocator, full_path: []const u8) %void {
start_over: while (true) {
// First, try deleting the item as a file. This way we don't follow sym links.
if (deleteFile(allocator, full_path)) {
@@ -967,7 +967,7 @@ pub const Dir = struct {
};
};
- pub fn open(allocator: &Allocator, dir_path: []const u8) -> %Dir {
+ pub fn open(allocator: &Allocator, dir_path: []const u8) %Dir {
const fd = try posixOpen(dir_path, posix.O_RDONLY|posix.O_DIRECTORY|posix.O_CLOEXEC, 0, allocator);
return Dir {
.allocator = allocator,
@@ -978,14 +978,14 @@ pub const Dir = struct {
};
}
- pub fn close(self: &Dir) {
+ pub fn close(self: &Dir) void {
self.allocator.free(self.buf);
os.close(self.fd);
}
/// Memory such as file names referenced in this returned entry becomes invalid
/// with subsequent calls to next, as well as when this ::Dir is deinitialized.
- pub fn next(self: &Dir) -> %?Entry {
+ pub fn next(self: &Dir) %?Entry {
start_over: while (true) {
if (self.index >= self.end_index) {
if (self.buf.len == 0) {
@@ -1042,7 +1042,7 @@ pub const Dir = struct {
}
};
-pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void {
+pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) %void {
const path_buf = try allocator.alloc(u8, dir_path.len + 1);
defer allocator.free(path_buf);
@@ -1066,7 +1066,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void {
}
/// Read value of a symbolic link.
-pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
+pub fn readLink(allocator: &Allocator, pathname: []const u8) %[]u8 {
const path_buf = try allocator.alloc(u8, pathname.len + 1);
defer allocator.free(path_buf);
@@ -1099,7 +1099,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
}
}
-pub fn sleep(seconds: usize, nanoseconds: usize) {
+pub fn sleep(seconds: usize, nanoseconds: usize) void {
switch(builtin.os) {
Os.linux, Os.macosx, Os.ios => {
posixSleep(u63(seconds), u63(nanoseconds));
@@ -1113,7 +1113,7 @@ pub fn sleep(seconds: usize, nanoseconds: usize) {
}
const u63 = @IntType(false, 63);
-pub fn posixSleep(seconds: u63, nanoseconds: u63) {
+pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
var req = posix.timespec {
.tv_sec = seconds,
.tv_nsec = nanoseconds,
@@ -1147,7 +1147,7 @@ error ResourceLimitReached;
error InvalidUserId;
error PermissionDenied;
-pub fn posix_setuid(uid: u32) -> %void {
+pub fn posix_setuid(uid: u32) %void {
const err = posix.getErrno(posix.setuid(uid));
if (err == 0) return;
return switch (err) {
@@ -1158,7 +1158,7 @@ pub fn posix_setuid(uid: u32) -> %void {
};
}
-pub fn posix_setreuid(ruid: u32, euid: u32) -> %void {
+pub fn posix_setreuid(ruid: u32, euid: u32) %void {
const err = posix.getErrno(posix.setreuid(ruid, euid));
if (err == 0) return;
return switch (err) {
@@ -1169,7 +1169,7 @@ pub fn posix_setreuid(ruid: u32, euid: u32) -> %void {
};
}
-pub fn posix_setgid(gid: u32) -> %void {
+pub fn posix_setgid(gid: u32) %void {
const err = posix.getErrno(posix.setgid(gid));
if (err == 0) return;
return switch (err) {
@@ -1180,7 +1180,7 @@ pub fn posix_setgid(gid: u32) -> %void {
};
}
-pub fn posix_setregid(rgid: u32, egid: u32) -> %void {
+pub fn posix_setregid(rgid: u32, egid: u32) %void {
const err = posix.getErrno(posix.setregid(rgid, egid));
if (err == 0) return;
return switch (err) {
@@ -1192,7 +1192,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) -> %void {
}
error NoStdHandles;
-pub fn windowsGetStdHandle(handle_id: windows.DWORD) -> %windows.HANDLE {
+pub fn windowsGetStdHandle(handle_id: windows.DWORD) %windows.HANDLE {
if (windows.GetStdHandle(handle_id)) |handle| {
if (handle == windows.INVALID_HANDLE_VALUE) {
const err = windows.GetLastError();
@@ -1210,14 +1210,14 @@ pub const ArgIteratorPosix = struct {
index: usize,
count: usize,
- pub fn init() -> ArgIteratorPosix {
+ pub fn init() ArgIteratorPosix {
return ArgIteratorPosix {
.index = 0,
.count = raw.len,
};
}
- pub fn next(self: &ArgIteratorPosix) -> ?[]const u8 {
+ pub fn next(self: &ArgIteratorPosix) ?[]const u8 {
if (self.index == self.count)
return null;
@@ -1226,7 +1226,7 @@ pub const ArgIteratorPosix = struct {
return cstr.toSlice(s);
}
- pub fn skip(self: &ArgIteratorPosix) -> bool {
+ pub fn skip(self: &ArgIteratorPosix) bool {
if (self.index == self.count)
return false;
@@ -1246,11 +1246,11 @@ pub const ArgIteratorWindows = struct {
quote_count: usize,
seen_quote_count: usize,
- pub fn init() -> ArgIteratorWindows {
+ pub fn init() ArgIteratorWindows {
return initWithCmdLine(windows.GetCommandLineA());
}
- pub fn initWithCmdLine(cmd_line: &const u8) -> ArgIteratorWindows {
+ pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {
return ArgIteratorWindows {
.index = 0,
.cmd_line = cmd_line,
@@ -1261,7 +1261,7 @@ pub const ArgIteratorWindows = struct {
}
/// You must free the returned memory when done.
- pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) -> ?%[]u8 {
+ pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) ?%[]u8 {
// march forward over whitespace
while (true) : (self.index += 1) {
const byte = self.cmd_line[self.index];
@@ -1275,7 +1275,7 @@ pub const ArgIteratorWindows = struct {
return self.internalNext(allocator);
}
- pub fn skip(self: &ArgIteratorWindows) -> bool {
+ pub fn skip(self: &ArgIteratorWindows) bool {
// march forward over whitespace
while (true) : (self.index += 1) {
const byte = self.cmd_line[self.index];
@@ -1314,7 +1314,7 @@ pub const ArgIteratorWindows = struct {
}
}
- fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) -> %[]u8 {
+ fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) %[]u8 {
var buf = try Buffer.initSize(allocator, 0);
defer buf.deinit();
@@ -1358,14 +1358,14 @@ pub const ArgIteratorWindows = struct {
}
}
- fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) -> %void {
+ fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) %void {
var i: usize = 0;
while (i < emit_count) : (i += 1) {
try buf.appendByte('\\');
}
}
- fn countQuotes(cmd_line: &const u8) -> usize {
+ fn countQuotes(cmd_line: &const u8) usize {
var result: usize = 0;
var backslash_count: usize = 0;
var index: usize = 0;
@@ -1390,14 +1390,14 @@ pub const ArgIteratorWindows = struct {
pub const ArgIterator = struct {
inner: if (builtin.os == Os.windows) ArgIteratorWindows else ArgIteratorPosix,
- pub fn init() -> ArgIterator {
+ pub fn init() ArgIterator {
return ArgIterator {
.inner = if (builtin.os == Os.windows) ArgIteratorWindows.init() else ArgIteratorPosix.init(),
};
}
/// You must free the returned memory when done.
- pub fn next(self: &ArgIterator, allocator: &Allocator) -> ?%[]u8 {
+ pub fn next(self: &ArgIterator, allocator: &Allocator) ?%[]u8 {
if (builtin.os == Os.windows) {
return self.inner.next(allocator);
} else {
@@ -1406,23 +1406,23 @@ pub const ArgIterator = struct {
}
/// If you only are targeting posix you can call this and not need an allocator.
- pub fn nextPosix(self: &ArgIterator) -> ?[]const u8 {
+ pub fn nextPosix(self: &ArgIterator) ?[]const u8 {
return self.inner.next();
}
/// Parse past 1 argument without capturing it.
/// Returns `true` if skipped an arg, `false` if we are at the end.
- pub fn skip(self: &ArgIterator) -> bool {
+ pub fn skip(self: &ArgIterator) bool {
return self.inner.skip();
}
};
-pub fn args() -> ArgIterator {
+pub fn args() ArgIterator {
return ArgIterator.init();
}
/// Caller must call freeArgs on result.
-pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 {
+pub fn argsAlloc(allocator: &mem.Allocator) %[]const []u8 {
// TODO refactor to only make 1 allocation.
var it = args();
var contents = try Buffer.initSize(allocator, 0);
@@ -1459,7 +1459,7 @@ pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 {
return result_slice_list;
}
-pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) {
+pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {
var total_bytes: usize = 0;
for (args_alloc) |arg| {
total_bytes += @sizeOf([]u8) + arg.len;
@@ -1481,7 +1481,7 @@ test "windows arg parsing" {
[][]const u8{".\\..\\zig-cache\\build", "bin\\zig.exe", ".\\..", ".\\..\\zig-cache", "--help"});
}
-fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) {
+fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) void {
var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
for (expected_args) |expected_arg| {
const arg = ??it.next(debug.global_allocator) catch unreachable;
@@ -1511,7 +1511,7 @@ const unexpected_error_tracing = false;
/// Call this when you made a syscall or something that sets errno
/// and you get an unexpected error.
-pub fn unexpectedErrorPosix(errno: usize) -> error {
+pub fn unexpectedErrorPosix(errno: usize) error {
if (unexpected_error_tracing) {
debug.warn("unexpected errno: {}\n", errno);
debug.dumpStackTrace();
@@ -1521,7 +1521,7 @@ pub fn unexpectedErrorPosix(errno: usize) -> error {
/// Call this when you made a windows DLL call or something that does SetLastError
/// and you get an unexpected error.
-pub fn unexpectedErrorWindows(err: windows.DWORD) -> error {
+pub fn unexpectedErrorWindows(err: windows.DWORD) error {
if (unexpected_error_tracing) {
debug.warn("unexpected GetLastError(): {}\n", err);
debug.dumpStackTrace();
@@ -1529,7 +1529,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) -> error {
return error.Unexpected;
}
-pub fn openSelfExe() -> %io.File {
+pub fn openSelfExe() %io.File {
switch (builtin.os) {
Os.linux => {
return io.File.openRead("/proc/self/exe", null);
@@ -1547,7 +1547,7 @@ pub fn openSelfExe() -> %io.File {
/// This function may return an error if the current executable
/// was deleted after spawning.
/// Caller owns returned memory.
-pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
+pub fn selfExePath(allocator: &mem.Allocator) %[]u8 {
switch (builtin.os) {
Os.linux => {
// If the currently executing binary has been deleted,
@@ -1590,7 +1590,7 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
/// Get the directory path that contains the current executable.
/// Caller owns returned memory.
-pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
+pub fn selfExeDirPath(allocator: &mem.Allocator) %[]u8 {
switch (builtin.os) {
Os.linux => {
// If the currently executing binary has been deleted,
@@ -1612,7 +1612,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
}
}
-pub fn isTty(handle: FileHandle) -> bool {
+pub fn isTty(handle: FileHandle) bool {
if (is_windows) {
return windows_util.windowsIsTty(handle);
} else {
diff --git a/std/os/linux.zig b/std/os/linux.zig
index c254f83d10..04cdafb0ac 100644
--- a/std/os/linux.zig
+++ b/std/os/linux.zig
@@ -368,14 +368,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
pub const TFD_TIMER_ABSTIME = 1;
pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
-fn unsigned(s: i32) -> u32 { return @bitCast(u32, s); }
-fn signed(s: u32) -> i32 { return @bitCast(i32, s); }
-pub fn WEXITSTATUS(s: i32) -> i32 { return signed((unsigned(s) & 0xff00) >> 8); }
-pub fn WTERMSIG(s: i32) -> i32 { return signed(unsigned(s) & 0x7f); }
-pub fn WSTOPSIG(s: i32) -> i32 { return WEXITSTATUS(s); }
-pub fn WIFEXITED(s: i32) -> bool { return WTERMSIG(s) == 0; }
-pub fn WIFSTOPPED(s: i32) -> bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }
-pub fn WIFSIGNALED(s: i32) -> bool { return (unsigned(s)&0xffff)-%1 < 0xff; }
+fn unsigned(s: i32) u32 { return @bitCast(u32, s); }
+fn signed(s: u32) i32 { return @bitCast(i32, s); }
+pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); }
+pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); }
+pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); }
+pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; }
+pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }
+pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; }
pub const winsize = extern struct {
@@ -386,161 +386,159 @@ pub const winsize = extern struct {
};
/// Get the errno from a syscall return value, or 0 for no error.
-pub fn getErrno(r: usize) -> usize {
+pub fn getErrno(r: usize) usize {
const signed_r = @bitCast(isize, r);
return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
}
-pub fn dup2(old: i32, new: i32) -> usize {
+pub fn dup2(old: i32, new: i32) usize {
return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));
}
-pub fn chdir(path: &const u8) -> usize {
+pub fn chdir(path: &const u8) usize {
return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
}
-pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
+pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
}
-pub fn fork() -> usize {
+pub fn fork() usize {
return arch.syscall0(arch.SYS_fork);
}
-pub fn getcwd(buf: &u8, size: usize) -> usize {
+pub fn getcwd(buf: &u8, size: usize) usize {
return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size);
}
-pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {
+pub fn getdents(fd: i32, dirp: &u8, count: usize) usize {
return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);
}
-pub fn isatty(fd: i32) -> bool {
+pub fn isatty(fd: i32) bool {
var wsz: winsize = undefined;
return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
}
-pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
+pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
}
-pub fn mkdir(path: &const u8, mode: u32) -> usize {
+pub fn mkdir(path: &const u8, mode: u32) usize {
return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
}
-pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
- -> usize
-{
+pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
@bitCast(usize, offset));
}
-pub fn munmap(address: &u8, length: usize) -> usize {
+pub fn munmap(address: &u8, length: usize) usize {
return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length);
}
-pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
+pub fn read(fd: i32, buf: &u8, count: usize) usize {
return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count);
}
-pub fn rmdir(path: &const u8) -> usize {
+pub fn rmdir(path: &const u8) usize {
return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
}
-pub fn symlink(existing: &const u8, new: &const u8) -> usize {
+pub fn symlink(existing: &const u8, new: &const u8) usize {
return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
}
-pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
+pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize {
return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
}
-pub fn pipe(fd: &[2]i32) -> usize {
+pub fn pipe(fd: &[2]i32) usize {
return pipe2(fd, 0);
}
-pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {
+pub fn pipe2(fd: &[2]i32, flags: usize) usize {
return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
}
-pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
+pub fn write(fd: i32, buf: &const u8, count: usize) usize {
return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count);
}
-pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
+pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize {
return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);
}
-pub fn rename(old: &const u8, new: &const u8) -> usize {
+pub fn rename(old: &const u8, new: &const u8) usize {
return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
}
-pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {
+pub fn open(path: &const u8, flags: u32, perm: usize) usize {
return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
}
-pub fn create(path: &const u8, perm: usize) -> usize {
+pub fn create(path: &const u8, perm: usize) usize {
return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
}
-pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
+pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize {
return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);
}
-pub fn close(fd: i32) -> usize {
+pub fn close(fd: i32) usize {
return arch.syscall1(arch.SYS_close, usize(fd));
}
-pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {
+pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos);
}
-pub fn exit(status: i32) -> noreturn {
+pub fn exit(status: i32) noreturn {
_ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
unreachable;
}
-pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
+pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags));
}
-pub fn kill(pid: i32, sig: i32) -> usize {
+pub fn kill(pid: i32, sig: i32) usize {
return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig));
}
-pub fn unlink(path: &const u8) -> usize {
+pub fn unlink(path: &const u8) usize {
return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
}
-pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {
+pub fn waitpid(pid: i32, status: &i32, options: i32) usize {
return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
}
-pub fn nanosleep(req: &const timespec, rem: ?×pec) -> usize {
+pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
}
-pub fn setuid(uid: u32) -> usize {
+pub fn setuid(uid: u32) usize {
return arch.syscall1(arch.SYS_setuid, uid);
}
-pub fn setgid(gid: u32) -> usize {
+pub fn setgid(gid: u32) usize {
return arch.syscall1(arch.SYS_setgid, gid);
}
-pub fn setreuid(ruid: u32, euid: u32) -> usize {
+pub fn setreuid(ruid: u32, euid: u32) usize {
return arch.syscall2(arch.SYS_setreuid, ruid, euid);
}
-pub fn setregid(rgid: u32, egid: u32) -> usize {
+pub fn setregid(rgid: u32, egid: u32) usize {
return arch.syscall2(arch.SYS_setregid, rgid, egid);
}
-pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
+pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);
}
-pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
+pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
assert(sig >= 1);
assert(sig != SIGKILL);
assert(sig != SIGSTOP);
@@ -548,7 +546,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
.handler = act.handler,
.flags = act.flags | SA_RESTORER,
.mask = undefined,
- .restorer = @ptrCast(extern fn(), arch.restore_rt),
+ .restorer = @ptrCast(extern fn()void, arch.restore_rt),
};
var ksa_old: k_sigaction = undefined;
@memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
@@ -571,25 +569,25 @@ const all_mask = []usize{@maxValue(usize)};
const app_mask = []usize{0xfffffffc7fffffff};
const k_sigaction = extern struct {
- handler: extern fn(i32),
+ handler: extern fn(i32)void,
flags: usize,
- restorer: extern fn(),
+ restorer: extern fn()void,
mask: [2]u32,
};
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = struct {
- handler: extern fn(i32),
+ handler: extern fn(i32)void,
mask: sigset_t,
flags: u32,
};
-pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize));
-pub const SIG_DFL = @intToPtr(extern fn(i32), 0);
-pub const SIG_IGN = @intToPtr(extern fn(i32), 1);
+pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize));
+pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0);
+pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1);
pub const empty_sigset = []usize{0} ** sigset_t.len;
-pub fn raise(sig: i32) -> usize {
+pub fn raise(sig: i32) usize {
var set: sigset_t = undefined;
blockAppSignals(&set);
const tid = i32(arch.syscall0(arch.SYS_gettid));
@@ -598,24 +596,24 @@ pub fn raise(sig: i32) -> usize {
return ret;
}
-fn blockAllSignals(set: &sigset_t) {
+fn blockAllSignals(set: &sigset_t) void {
_ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8);
}
-fn blockAppSignals(set: &sigset_t) {
+fn blockAppSignals(set: &sigset_t) void {
_ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8);
}
-fn restoreSignals(set: &sigset_t) {
+fn restoreSignals(set: &sigset_t) void {
_ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8);
}
-pub fn sigaddset(set: &sigset_t, sig: u6) {
+pub fn sigaddset(set: &sigset_t, sig: u6) void {
const s = sig - 1;
(*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
}
-pub fn sigismember(set: &const sigset_t, sig: u6) -> bool {
+pub fn sigismember(set: &const sigset_t, sig: u6) bool {
const s = sig - 1;
return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
}
@@ -652,69 +650,69 @@ pub const iovec = extern struct {
iov_len: usize,
};
-pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
+pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));
}
-pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
+pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));
}
-pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
+pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize {
return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol));
}
-pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
+pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize {
return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen));
}
-pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
+pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize {
return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen));
}
-pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
+pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize {
return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);
}
-pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
+pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize {
return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len));
}
-pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
+pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize {
return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
}
pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
- noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
+ noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize
{
return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
}
-pub fn shutdown(fd: i32, how: i32) -> usize {
+pub fn shutdown(fd: i32, how: i32) usize {
return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how));
}
-pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
+pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize {
return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len));
}
-pub fn listen(fd: i32, backlog: i32) -> usize {
+pub fn listen(fd: i32, backlog: i32) usize {
return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog));
}
-pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
+pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize {
return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));
}
-pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
+pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]));
}
-pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
+pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
return accept4(fd, addr, len, 0);
}
-pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
+pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize {
return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);
}
@@ -722,7 +720,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags:
// error SystemResources;
// error Io;
//
-// pub fn if_nametoindex(name: []u8) -> %u32 {
+// pub fn if_nametoindex(name: []u8) %u32 {
// var ifr: ifreq = undefined;
//
// if (name.len >= ifr.ifr_name.len) {
@@ -749,7 +747,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags:
pub const Stat = arch.Stat;
pub const timespec = arch.timespec;
-pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {
+pub fn fstat(fd: i32, stat_buf: &Stat) usize {
return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf));
}
@@ -760,19 +758,19 @@ pub const epoll_event = extern struct {
data: epoll_data
};
-pub fn epoll_create() -> usize {
+pub fn epoll_create() usize {
return arch.syscall1(arch.SYS_epoll_create, usize(1));
}
-pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) -> usize {
+pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize {
return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
}
-pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) -> usize {
+pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) usize {
return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
}
-pub fn timerfd_create(clockid: i32, flags: u32) -> usize {
+pub fn timerfd_create(clockid: i32, flags: u32) usize {
return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags));
}
@@ -781,11 +779,11 @@ pub const itimerspec = extern struct {
it_value: timespec
};
-pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) -> usize {
+pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {
return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));
}
-pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) -> usize {
+pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize {
return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));
}
diff --git a/std/os/linux_i386.zig b/std/os/linux_i386.zig
index ed49e33c2b..353461562b 100644
--- a/std/os/linux_i386.zig
+++ b/std/os/linux_i386.zig
@@ -419,20 +419,20 @@ pub const F_GETOWN_EX = 16;
pub const F_GETOWNER_UIDS = 17;
-pub inline fn syscall0(number: usize) -> usize {
+pub inline fn syscall0(number: usize) usize {
asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number))
}
-pub inline fn syscall1(number: usize, arg1: usize) -> usize {
+pub inline fn syscall1(number: usize, arg1: usize) usize {
asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
[arg1] "{ebx}" (arg1))
}
-pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
+pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
@@ -440,7 +440,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
[arg2] "{ecx}" (arg2))
}
-pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
@@ -449,7 +449,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) ->
[arg3] "{edx}" (arg3))
}
-pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
+pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
@@ -486,7 +486,7 @@ pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
[arg6] "{ebp}" (arg6))
}
-pub nakedcc fn restore() {
+pub nakedcc fn restore() void {
asm volatile (
\\popl %%eax
\\movl $119, %%eax
@@ -496,7 +496,7 @@ pub nakedcc fn restore() {
: "rcx", "r11")
}
-pub nakedcc fn restore_rt() {
+pub nakedcc fn restore_rt() void {
asm volatile ("int $0x80"
:
: [number] "{eax}" (usize(SYS_rt_sigreturn))
diff --git a/std/os/linux_x86_64.zig b/std/os/linux_x86_64.zig
index db78decde2..3706633745 100644
--- a/std/os/linux_x86_64.zig
+++ b/std/os/linux_x86_64.zig
@@ -370,14 +370,14 @@ pub const F_GETOWN_EX = 16;
pub const F_GETOWNER_UIDS = 17;
-pub fn syscall0(number: usize) -> usize {
+pub fn syscall0(number: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
: [number] "{rax}" (number)
: "rcx", "r11");
}
-pub fn syscall1(number: usize, arg1: usize) -> usize {
+pub fn syscall1(number: usize, arg1: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
: [number] "{rax}" (number),
@@ -385,7 +385,7 @@ pub fn syscall1(number: usize, arg1: usize) -> usize {
: "rcx", "r11");
}
-pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
+pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
: [number] "{rax}" (number),
@@ -394,7 +394,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
: "rcx", "r11");
}
-pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
: [number] "{rax}" (number),
@@ -404,7 +404,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
: "rcx", "r11");
}
-pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
+pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
: [number] "{rax}" (number),
@@ -415,7 +415,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
: "rcx", "r11");
}
-pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
+pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
: [number] "{rax}" (number),
@@ -428,7 +428,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
}
pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
- arg5: usize, arg6: usize) -> usize
+ arg5: usize, arg6: usize) usize
{
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize)
@@ -442,7 +442,7 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
: "rcx", "r11");
}
-pub nakedcc fn restore_rt() {
+pub nakedcc fn restore_rt() void {
return asm volatile ("syscall"
:
: [number] "{rax}" (usize(SYS_rt_sigreturn))
diff --git a/std/os/path.zig b/std/os/path.zig
index c71fa68716..eb95f83f45 100644
--- a/std/os/path.zig
+++ b/std/os/path.zig
@@ -22,7 +22,7 @@ pub const delimiter = if (is_windows) delimiter_windows else delimiter_posix;
const is_windows = builtin.os == builtin.Os.windows;
-pub fn isSep(byte: u8) -> bool {
+pub fn isSep(byte: u8) bool {
if (is_windows) {
return byte == '/' or byte == '\\';
} else {
@@ -32,7 +32,7 @@ pub fn isSep(byte: u8) -> bool {
/// Naively combines a series of paths with the native path seperator.
/// Allocates memory for the result, which must be freed by the caller.
-pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 {
+pub fn join(allocator: &Allocator, paths: ...) %[]u8 {
if (is_windows) {
return joinWindows(allocator, paths);
} else {
@@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 {
}
}
-pub fn joinWindows(allocator: &Allocator, paths: ...) -> %[]u8 {
+pub fn joinWindows(allocator: &Allocator, paths: ...) %[]u8 {
return mem.join(allocator, sep_windows, paths);
}
-pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 {
+pub fn joinPosix(allocator: &Allocator, paths: ...) %[]u8 {
return mem.join(allocator, sep_posix, paths);
}
@@ -69,7 +69,7 @@ test "os.path.join" {
"/home/andy/dev/zig/build/lib/zig/std/io.zig"));
}
-pub fn isAbsolute(path: []const u8) -> bool {
+pub fn isAbsolute(path: []const u8) bool {
if (is_windows) {
return isAbsoluteWindows(path);
} else {
@@ -77,7 +77,7 @@ pub fn isAbsolute(path: []const u8) -> bool {
}
}
-pub fn isAbsoluteWindows(path: []const u8) -> bool {
+pub fn isAbsoluteWindows(path: []const u8) bool {
if (path[0] == '/')
return true;
@@ -96,7 +96,7 @@ pub fn isAbsoluteWindows(path: []const u8) -> bool {
return false;
}
-pub fn isAbsolutePosix(path: []const u8) -> bool {
+pub fn isAbsolutePosix(path: []const u8) bool {
return path[0] == sep_posix;
}
@@ -129,11 +129,11 @@ test "os.path.isAbsolutePosix" {
testIsAbsolutePosix("./baz", false);
}
-fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) {
+fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {
assert(isAbsoluteWindows(path) == expected_result);
}
-fn testIsAbsolutePosix(path: []const u8, expected_result: bool) {
+fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {
assert(isAbsolutePosix(path) == expected_result);
}
@@ -149,7 +149,7 @@ pub const WindowsPath = struct {
};
};
-pub fn windowsParsePath(path: []const u8) -> WindowsPath {
+pub fn windowsParsePath(path: []const u8) WindowsPath {
if (path.len >= 2 and path[1] == ':') {
return WindowsPath {
.is_abs = isAbsoluteWindows(path),
@@ -248,7 +248,7 @@ test "os.path.windowsParsePath" {
}
}
-pub fn diskDesignator(path: []const u8) -> []const u8 {
+pub fn diskDesignator(path: []const u8) []const u8 {
if (is_windows) {
return diskDesignatorWindows(path);
} else {
@@ -256,11 +256,11 @@ pub fn diskDesignator(path: []const u8) -> []const u8 {
}
}
-pub fn diskDesignatorWindows(path: []const u8) -> []const u8 {
+pub fn diskDesignatorWindows(path: []const u8) []const u8 {
return windowsParsePath(path).disk_designator;
}
-fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool {
+fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
const sep1 = ns1[0];
const sep2 = ns2[0];
@@ -271,7 +271,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool {
return asciiEqlIgnoreCase(??it1.next(), ??it2.next());
}
-fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) -> bool {
+fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool {
switch (kind) {
WindowsPath.Kind.None => {
assert(p1.len == 0);
@@ -294,14 +294,14 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
}
}
-fn asciiUpper(byte: u8) -> u8 {
+fn asciiUpper(byte: u8) u8 {
return switch (byte) {
'a' ... 'z' => 'A' + (byte - 'a'),
else => byte,
};
}
-fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool {
+fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
if (s1.len != s2.len)
return false;
var i: usize = 0;
@@ -313,7 +313,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool {
}
/// Converts the command line arguments into a slice and calls `resolveSlice`.
-pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 {
+pub fn resolve(allocator: &Allocator, args: ...) %[]u8 {
var paths: [args.len][]const u8 = undefined;
comptime var arg_i = 0;
inline while (arg_i < args.len) : (arg_i += 1) {
@@ -323,7 +323,7 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 {
}
/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
-pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
+pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 {
if (is_windows) {
return resolveWindows(allocator, paths);
} else {
@@ -337,7 +337,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
/// If all paths are relative it uses the current working directory as a starting point.
/// Each drive has its own current working directory.
/// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters.
-pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
+pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 {
if (paths.len == 0) {
assert(is_windows); // resolveWindows called on non windows can't use getCwd
return os.getCwd(allocator);
@@ -520,7 +520,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8
/// It resolves "." and "..".
/// The result does not have a trailing path separator.
/// If all paths are relative it uses the current working directory as a starting point.
-pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
+pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) %[]u8 {
if (paths.len == 0) {
assert(!is_windows); // resolvePosix called on windows can't use getCwd
return os.getCwd(allocator);
@@ -648,15 +648,15 @@ test "os.path.resolvePosix" {
assert(mem.eql(u8, testResolvePosix([][]const u8{"/foo/tmp.3/", "../tmp.3/cycles/root.js"}), "/foo/tmp.3/cycles/root.js"));
}
-fn testResolveWindows(paths: []const []const u8) -> []u8 {
+fn testResolveWindows(paths: []const []const u8) []u8 {
return resolveWindows(debug.global_allocator, paths) catch unreachable;
}
-fn testResolvePosix(paths: []const []const u8) -> []u8 {
+fn testResolvePosix(paths: []const []const u8) []u8 {
return resolvePosix(debug.global_allocator, paths) catch unreachable;
}
-pub fn dirname(path: []const u8) -> []const u8 {
+pub fn dirname(path: []const u8) []const u8 {
if (is_windows) {
return dirnameWindows(path);
} else {
@@ -664,7 +664,7 @@ pub fn dirname(path: []const u8) -> []const u8 {
}
}
-pub fn dirnameWindows(path: []const u8) -> []const u8 {
+pub fn dirnameWindows(path: []const u8) []const u8 {
if (path.len == 0)
return path[0..0];
@@ -695,7 +695,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 {
return path[0..end_index];
}
-pub fn dirnamePosix(path: []const u8) -> []const u8 {
+pub fn dirnamePosix(path: []const u8) []const u8 {
if (path.len == 0)
return path[0..0];
@@ -766,15 +766,15 @@ test "os.path.dirnameWindows" {
testDirnameWindows("foo", "");
}
-fn testDirnamePosix(input: []const u8, expected_output: []const u8) {
+fn testDirnamePosix(input: []const u8, expected_output: []const u8) void {
assert(mem.eql(u8, dirnamePosix(input), expected_output));
}
-fn testDirnameWindows(input: []const u8, expected_output: []const u8) {
+fn testDirnameWindows(input: []const u8, expected_output: []const u8) void {
assert(mem.eql(u8, dirnameWindows(input), expected_output));
}
-pub fn basename(path: []const u8) -> []const u8 {
+pub fn basename(path: []const u8) []const u8 {
if (is_windows) {
return basenameWindows(path);
} else {
@@ -782,7 +782,7 @@ pub fn basename(path: []const u8) -> []const u8 {
}
}
-pub fn basenamePosix(path: []const u8) -> []const u8 {
+pub fn basenamePosix(path: []const u8) []const u8 {
if (path.len == 0)
return []u8{};
@@ -803,7 +803,7 @@ pub fn basenamePosix(path: []const u8) -> []const u8 {
return path[start_index + 1..end_index];
}
-pub fn basenameWindows(path: []const u8) -> []const u8 {
+pub fn basenameWindows(path: []const u8) []const u8 {
if (path.len == 0)
return []u8{};
@@ -874,15 +874,15 @@ test "os.path.basename" {
testBasenameWindows("file:stream", "file:stream");
}
-fn testBasename(input: []const u8, expected_output: []const u8) {
+fn testBasename(input: []const u8, expected_output: []const u8) void {
assert(mem.eql(u8, basename(input), expected_output));
}
-fn testBasenamePosix(input: []const u8, expected_output: []const u8) {
+fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {
assert(mem.eql(u8, basenamePosix(input), expected_output));
}
-fn testBasenameWindows(input: []const u8, expected_output: []const u8) {
+fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
assert(mem.eql(u8, basenameWindows(input), expected_output));
}
@@ -890,7 +890,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) {
/// resolve to the same path (after calling `resolve` on each), a zero-length
/// string is returned.
/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
-pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 {
+pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
if (is_windows) {
return relativeWindows(allocator, from, to);
} else {
@@ -898,7 +898,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u
}
}
-pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 {
+pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
const resolved_from = try resolveWindows(allocator, [][]const u8{from});
defer allocator.free(resolved_from);
@@ -971,7 +971,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)
return []u8{};
}
-pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 {
+pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 {
const resolved_from = try resolvePosix(allocator, [][]const u8{from});
defer allocator.free(resolved_from);
@@ -1056,12 +1056,12 @@ test "os.path.relative" {
testRelativePosix("/baz", "/baz-quux", "../baz-quux");
}
-fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) {
+fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void {
const result = relativePosix(debug.global_allocator, from, to) catch unreachable;
assert(mem.eql(u8, result, expected_output));
}
-fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) {
+fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void {
const result = relativeWindows(debug.global_allocator, from, to) catch unreachable;
assert(mem.eql(u8, result, expected_output));
}
@@ -1077,7 +1077,7 @@ error InputOutput;
/// Expands all symbolic links and resolves references to `.`, `..`, and
/// extra `/` characters in ::pathname.
/// Caller must deallocate result.
-pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
+pub fn real(allocator: &Allocator, pathname: []const u8) %[]u8 {
switch (builtin.os) {
Os.windows => {
const pathname_buf = try allocator.alloc(u8, pathname.len + 1);
diff --git a/std/os/windows/index.zig b/std/os/windows/index.zig
index 524760d9ed..e7bf1916f4 100644
--- a/std/os/windows/index.zig
+++ b/std/os/windows/index.zig
@@ -1,100 +1,100 @@
pub const ERROR = @import("error.zig");
pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR,
- pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> BOOL;
+ pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) BOOL;
-pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
+pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL;
-pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> BOOL;
+pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) BOOL;
-pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
+pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;
pub extern "kernel32" stdcallcc fn CreateDirectoryA(lpPathName: LPCSTR,
- lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) -> BOOL;
+ lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) BOOL;
pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,
dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,
- dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE;
+ dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) HANDLE;
pub extern "kernel32" stdcallcc fn CreatePipe(hReadPipe: &HANDLE, hWritePipe: &HANDLE,
- lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) -> BOOL;
+ lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) BOOL;
pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lpCommandLine: LPSTR,
lpProcessAttributes: ?&SECURITY_ATTRIBUTES, lpThreadAttributes: ?&SECURITY_ATTRIBUTES, bInheritHandles: BOOL,
dwCreationFlags: DWORD, lpEnvironment: ?LPVOID, lpCurrentDirectory: ?LPCSTR, lpStartupInfo: &STARTUPINFOA,
- lpProcessInformation: &PROCESS_INFORMATION) -> BOOL;
+ lpProcessInformation: &PROCESS_INFORMATION) BOOL;
pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR,
- dwFlags: DWORD) -> BOOLEAN;
+ dwFlags: DWORD) BOOLEAN;
-pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> BOOL;
+pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) BOOL;
-pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;
+pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn;
-pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) -> BOOL;
+pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL;
-pub extern "kernel32" stdcallcc fn GetCommandLineA() -> LPSTR;
+pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;
-pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> BOOL;
+pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) BOOL;
-pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD;
+pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD;
-pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() -> ?LPCH;
+pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH;
-pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) -> DWORD;
+pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD;
-pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL;
+pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) BOOL;
-pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL;
+pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) BOOL;
-pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) -> DWORD;
+pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) DWORD;
-pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
+pub extern "kernel32" stdcallcc fn GetLastError() DWORD;
pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void,
- in_dwBufferSize: DWORD) -> BOOL;
+ in_dwBufferSize: DWORD) BOOL;
pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR,
- cchFilePath: DWORD, dwFlags: DWORD) -> DWORD;
+ cchFilePath: DWORD, dwFlags: DWORD) DWORD;
-pub extern "kernel32" stdcallcc fn GetProcessHeap() -> ?HANDLE;
+pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE;
-pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) -> ?HANDLE;
+pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE;
-pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> ?LPVOID;
+pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?LPVOID;
-pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
+pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) BOOL;
pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR,
- dwFlags: DWORD) -> BOOL;
+ dwFlags: DWORD) BOOL;
pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVOID,
in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,
- in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL;
+ in_out_lpOverlapped: ?&OVERLAPPED) BOOL;
pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER,
- out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) -> BOOL;
+ out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) BOOL;
-pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL;
+pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) BOOL;
-pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD);
+pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD) void;
-pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
+pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) BOOL;
-pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
+pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) DWORD;
pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &const c_void,
in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD,
- in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL;
+ in_out_lpOverlapped: ?&OVERLAPPED) BOOL;
//TODO: call unicode versions instead of relying on ANSI code page
-pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) -> ?HMODULE;
+pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) ?HMODULE;
-pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) -> BOOL;
+pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL;
-pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) -> c_int;
+pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int;
pub const PROV_RSA_FULL = 1;
@@ -295,4 +295,4 @@ pub const MOVEFILE_WRITE_THROUGH = 8;
pub const FILE_BEGIN = 0;
pub const FILE_CURRENT = 1;
-pub const FILE_END = 2;
\ No newline at end of file
+pub const FILE_END = 2;
diff --git a/std/os/windows/util.zig b/std/os/windows/util.zig
index f1c6f049ee..a8a2e3fcd5 100644
--- a/std/os/windows/util.zig
+++ b/std/os/windows/util.zig
@@ -10,7 +10,7 @@ error WaitAbandoned;
error WaitTimeOut;
error Unexpected;
-pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) -> %void {
+pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) %void {
const result = windows.WaitForSingleObject(handle, milliseconds);
return switch (result) {
windows.WAIT_ABANDONED => error.WaitAbandoned,
@@ -26,7 +26,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) ->
};
}
-pub fn windowsClose(handle: windows.HANDLE) {
+pub fn windowsClose(handle: windows.HANDLE) void {
assert(windows.CloseHandle(handle) != 0);
}
@@ -35,7 +35,7 @@ error OperationAborted;
error IoPending;
error BrokenPipe;
-pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void {
+pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) %void {
if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
const err = windows.GetLastError();
return switch (err) {
@@ -50,7 +50,7 @@ pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void {
}
}
-pub fn windowsIsTty(handle: windows.HANDLE) -> bool {
+pub fn windowsIsTty(handle: windows.HANDLE) bool {
if (windowsIsCygwinPty(handle))
return true;
@@ -58,7 +58,7 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool {
return windows.GetConsoleMode(handle, &out) != 0;
}
-pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool {
+pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
const size = @sizeOf(windows.FILE_NAME_INFO);
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
@@ -83,7 +83,7 @@ error PipeBusy;
/// size buffer is too small, and the provided allocator is null, ::error.NameTooLong is returned.
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_mode: windows.DWORD,
- creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) -> %windows.HANDLE
+ creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) %windows.HANDLE
{
var stack_buf: [os.max_noalloc_path_len]u8 = undefined;
var path0: []u8 = undefined;
@@ -120,7 +120,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m
}
/// Caller must free result.
-pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) -> %[]u8 {
+pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) %[]u8 {
// count bytes needed
const bytes_needed = x: {
var bytes_needed: usize = 1; // 1 for the final null byte
@@ -152,13 +152,13 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)
}
error DllNotFound;
-pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) -> %windows.HMODULE {
+pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) %windows.HMODULE {
const padded_buff = try cstr.addNullByte(allocator, dll_path);
defer allocator.free(padded_buff);
return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound;
}
-pub fn windowsUnloadDll(hModule: windows.HMODULE) {
+pub fn windowsUnloadDll(hModule: windows.HMODULE) void {
assert(windows.FreeLibrary(hModule)!= 0);
}
diff --git a/std/os/zen.zig b/std/os/zen.zig
index 37ec68763d..f31d46e481 100644
--- a/std/os/zen.zig
+++ b/std/os/zen.zig
@@ -21,28 +21,28 @@ pub const SYS_createThread = 5;
//// Syscalls ////
////////////////////
-pub fn exit(status: i32) -> noreturn {
+pub fn exit(status: i32) noreturn {
_ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
unreachable;
}
-pub fn createMailbox(id: u16) {
+pub fn createMailbox(id: u16) void {
_ = syscall1(SYS_createMailbox, id);
}
-pub fn send(mailbox_id: u16, data: usize) {
+pub fn send(mailbox_id: u16, data: usize) void {
_ = syscall2(SYS_send, mailbox_id, data);
}
-pub fn receive(mailbox_id: u16) -> usize {
+pub fn receive(mailbox_id: u16) usize {
return syscall1(SYS_receive, mailbox_id);
}
-pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) -> bool {
+pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0;
}
-pub fn createThread(function: fn()) -> u16 {
+pub fn createThread(function: fn()) u16 {
return u16(syscall1(SYS_createThread, @ptrToInt(function)));
}
@@ -51,20 +51,20 @@ pub fn createThread(function: fn()) -> u16 {
//// Syscall stubs ////
/////////////////////////
-pub inline fn syscall0(number: usize) -> usize {
+pub inline fn syscall0(number: usize) usize {
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number));
}
-pub inline fn syscall1(number: usize, arg1: usize) -> usize {
+pub inline fn syscall1(number: usize, arg1: usize) usize {
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
[arg1] "{ecx}" (arg1));
}
-pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
+pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
@@ -72,7 +72,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
[arg2] "{edx}" (arg2));
}
-pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
@@ -81,7 +81,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) ->
[arg3] "{ebx}" (arg3));
}
-pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
+pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
: [number] "{eax}" (number),
@@ -92,7 +92,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg
}
pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
- arg4: usize, arg5: usize) -> usize
+ arg4: usize, arg5: usize) usize
{
return asm volatile ("int $0x80"
: [ret] "={eax}" (-> usize)
diff --git a/std/rand.zig b/std/rand.zig
index 5f4c9c2015..96f0a385a4 100644
--- a/std/rand.zig
+++ b/std/rand.zig
@@ -28,14 +28,14 @@ pub const Rand = struct {
rng: Rng,
/// Initialize random state with the given seed.
- pub fn init(seed: usize) -> Rand {
+ pub fn init(seed: usize) Rand {
return Rand {
.rng = Rng.init(seed),
};
}
/// Get an integer or boolean with random bits.
- pub fn scalar(r: &Rand, comptime T: type) -> T {
+ pub fn scalar(r: &Rand, comptime T: type) T {
if (T == usize) {
return r.rng.get();
} else if (T == bool) {
@@ -48,7 +48,7 @@ pub const Rand = struct {
}
/// Fill `buf` with randomness.
- pub fn fillBytes(r: &Rand, buf: []u8) {
+ pub fn fillBytes(r: &Rand, buf: []u8) void {
var bytes_left = buf.len;
while (bytes_left >= @sizeOf(usize)) {
mem.writeInt(buf[buf.len - bytes_left..], r.rng.get(), builtin.Endian.Little);
@@ -66,7 +66,7 @@ pub const Rand = struct {
/// Get a random unsigned integer with even distribution between `start`
/// inclusive and `end` exclusive.
- pub fn range(r: &Rand, comptime T: type, start: T, end: T) -> T {
+ pub fn range(r: &Rand, comptime T: type, start: T, end: T) T {
assert(start <= end);
if (T.is_signed) {
const uint = @IntType(false, T.bit_count);
@@ -108,7 +108,7 @@ pub const Rand = struct {
}
/// Get a floating point value in the range 0.0..1.0.
- pub fn float(r: &Rand, comptime T: type) -> T {
+ pub fn float(r: &Rand, comptime T: type) T {
// TODO Implement this way instead:
// const int = @int_type(false, @sizeOf(T) * 8);
// const mask = ((1 << @float_mantissa_bit_count(T)) - 1);
@@ -132,7 +132,7 @@ fn MersenneTwister(
comptime u: math.Log2Int(int), comptime d: int,
comptime s: math.Log2Int(int), comptime b: int,
comptime t: math.Log2Int(int), comptime c: int,
- comptime l: math.Log2Int(int), comptime f: int) -> type
+ comptime l: math.Log2Int(int), comptime f: int) type
{
return struct {
const Self = this;
@@ -140,7 +140,7 @@ fn MersenneTwister(
array: [n]int,
index: usize,
- pub fn init(seed: int) -> Self {
+ pub fn init(seed: int) Self {
var mt = Self {
.array = undefined,
.index = n,
@@ -156,7 +156,7 @@ fn MersenneTwister(
return mt;
}
- pub fn get(mt: &Self) -> int {
+ pub fn get(mt: &Self) int {
const mag01 = []int{0, a};
const LM: int = (1 << r) - 1;
const UM = ~LM;
@@ -224,7 +224,7 @@ test "rand.Rand.range" {
testRange(&r, 10, 14);
}
-fn testRange(r: &Rand, start: i32, end: i32) {
+fn testRange(r: &Rand, start: i32, end: i32) void {
const count = usize(end - start);
var values_buffer = []bool{false} ** 20;
const values = values_buffer[0..count];
diff --git a/std/sort.zig b/std/sort.zig
index 8554ab495a..c628922a69 100644
--- a/std/sort.zig
+++ b/std/sort.zig
@@ -5,7 +5,7 @@ const math = std.math;
const builtin = @import("builtin");
/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).
-pub fn insertionSort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) {
+pub fn insertionSort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) void {
{var i: usize = 1; while (i < items.len) : (i += 1) {
const x = items[i];
var j: usize = i;
@@ -20,11 +20,11 @@ const Range = struct {
start: usize,
end: usize,
- fn init(start: usize, end: usize) -> Range {
+ fn init(start: usize, end: usize) Range {
return Range { .start = start, .end = end };
}
- fn length(self: &const Range) -> usize {
+ fn length(self: &const Range) usize {
return self.end - self.start;
}
};
@@ -39,7 +39,7 @@ const Iterator = struct {
decimal_step: usize,
numerator_step: usize,
- fn init(size2: usize, min_level: usize) -> Iterator {
+ fn init(size2: usize, min_level: usize) Iterator {
const power_of_two = math.floorPowerOfTwo(usize, size2);
const denominator = power_of_two / min_level;
return Iterator {
@@ -53,12 +53,12 @@ const Iterator = struct {
};
}
- fn begin(self: &Iterator) {
+ fn begin(self: &Iterator) void {
self.numerator = 0;
self.decimal = 0;
}
- fn nextRange(self: &Iterator) -> Range {
+ fn nextRange(self: &Iterator) Range {
const start = self.decimal;
self.decimal += self.decimal_step;
@@ -71,11 +71,11 @@ const Iterator = struct {
return Range {.start = start, .end = self.decimal};
}
- fn finished(self: &Iterator) -> bool {
+ fn finished(self: &Iterator) bool {
return self.decimal >= self.size;
}
- fn nextLevel(self: &Iterator) -> bool {
+ fn nextLevel(self: &Iterator) bool {
self.decimal_step += self.decimal_step;
self.numerator_step += self.numerator_step;
if (self.numerator_step >= self.denominator) {
@@ -86,7 +86,7 @@ const Iterator = struct {
return (self.decimal_step < self.size);
}
- fn length(self: &Iterator) -> usize {
+ fn length(self: &Iterator) usize {
return self.decimal_step;
}
};
@@ -100,7 +100,7 @@ const Pull = struct {
/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required).
/// Currently implemented as block sort.
-pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) {
+pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) void {
// Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c
var cache: [512]T = undefined;
@@ -709,7 +709,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
}
// merge operation without a buffer
-fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn(&const T,&const T)->bool) {
+fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn(&const T,&const T)bool) void {
if (A_arg.length() == 0 or B_arg.length() == 0) return;
// this just repeatedly binary searches into B and rotates A into position.
@@ -751,7 +751,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const
}
// merge operation using an internal buffer
-fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)->bool, buffer: &const Range) {
+fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)bool, buffer: &const Range) void {
// whenever we find a value to add to the final array, swap it with the value that's already in that spot
// when this algorithm is finished, 'buffer' will contain its original contents, but in a different order
var A_count: usize = 0;
@@ -778,7 +778,7 @@ fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range,
blockSwap(T, items, buffer.start + A_count, A.start + insert, A.length() - A_count);
}
-fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_size: usize) {
+fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_size: usize) void {
var index: usize = 0;
while (index < block_size) : (index += 1) {
mem.swap(T, &items[start1 + index], &items[start2 + index]);
@@ -787,7 +787,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s
// combine a linear search with a binary search to reduce the number of comparisons in situations
// where have some idea as to how many unique values there are and where the next value might be
-fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize {
+fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize {
if (range.length() == 0) return range.start;
const skip = math.max(range.length()/unique, usize(1));
@@ -801,7 +801,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const
return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan);
}
-fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize {
+fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize {
if (range.length() == 0) return range.start;
const skip = math.max(range.length()/unique, usize(1));
@@ -815,7 +815,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons
return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan);
}
-fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize {
+fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize {
if (range.length() == 0) return range.start;
const skip = math.max(range.length()/unique, usize(1));
@@ -829,7 +829,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const
return binaryLast(T, items, value, Range.init(index - skip, index), lessThan);
}
-fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize {
+fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize {
if (range.length() == 0) return range.start;
const skip = math.max(range.length()/unique, usize(1));
@@ -843,7 +843,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const
return binaryLast(T, items, value, Range.init(index, index + skip), lessThan);
}
-fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool) -> usize {
+fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool) usize {
var start = range.start;
var end = range.end - 1;
if (range.start >= range.end) return range.end;
@@ -861,7 +861,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang
return start;
}
-fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool) -> usize {
+fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool) usize {
var start = range.start;
var end = range.end - 1;
if (range.start >= range.end) return range.end;
@@ -879,7 +879,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range
return start;
}
-fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)->bool, into: []T) {
+fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)bool, into: []T) void {
var A_index: usize = A.start;
var B_index: usize = B.start;
const A_last = A.end;
@@ -909,7 +909,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less
}
}
-fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)->bool, cache: []T) {
+fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)bool, cache: []T) void {
// A fits into the cache, so use that instead of the internal buffer
var A_index: usize = 0;
var B_index: usize = B.start;
@@ -937,7 +937,7 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range,
mem.copy(T, items[insert_index..], cache[A_index..A_last]);
}
-fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool, order: &[8]u8, x: usize, y: usize) {
+fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool, order: &[8]u8, x: usize, y: usize) void {
if (lessThan(items[y], items[x]) or
((*order)[x] > (*order)[y] and !lessThan(items[x], items[y])))
{
@@ -946,19 +946,19 @@ fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)
}
}
-fn i32asc(lhs: &const i32, rhs: &const i32) -> bool {
+fn i32asc(lhs: &const i32, rhs: &const i32) bool {
return *lhs < *rhs;
}
-fn i32desc(lhs: &const i32, rhs: &const i32) -> bool {
+fn i32desc(lhs: &const i32, rhs: &const i32) bool {
return *rhs < *lhs;
}
-fn u8asc(lhs: &const u8, rhs: &const u8) -> bool {
+fn u8asc(lhs: &const u8, rhs: &const u8) bool {
return *lhs < *rhs;
}
-fn u8desc(lhs: &const u8, rhs: &const u8) -> bool {
+fn u8desc(lhs: &const u8, rhs: &const u8) bool {
return *rhs < *lhs;
}
@@ -967,7 +967,7 @@ test "stable sort" {
// TODO: uncomment this after https://github.com/zig-lang/zig/issues/639
//comptime testStableSort();
}
-fn testStableSort() {
+fn testStableSort() void {
var expected = []IdAndValue {
IdAndValue{.id = 0, .value = 0},
IdAndValue{.id = 1, .value = 0},
@@ -1015,7 +1015,7 @@ const IdAndValue = struct {
id: usize,
value: i32,
};
-fn cmpByValue(a: &const IdAndValue, b: &const IdAndValue) -> bool {
+fn cmpByValue(a: &const IdAndValue, b: &const IdAndValue) bool {
return i32asc(a.value, b.value);
}
@@ -1092,7 +1092,7 @@ test "sort fuzz testing" {
var fixed_buffer_mem: [100 * 1024]u8 = undefined;
-fn fuzzTest(rng: &std.rand.Rand) {
+fn fuzzTest(rng: &std.rand.Rand) void {
const array_size = rng.range(usize, 0, 1000);
var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;
@@ -1113,7 +1113,7 @@ fn fuzzTest(rng: &std.rand.Rand) {
}
}
-pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) -> T {
+pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) T {
var i: usize = 0;
var smallest = items[0];
for (items[1..]) |item| {
@@ -1124,7 +1124,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const
return smallest;
}
-pub fn max(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) -> T {
+pub fn max(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) T {
var i: usize = 0;
var biggest = items[0];
for (items[1..]) |item| {
diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig
index 77bb7316a9..bcb3456353 100644
--- a/std/special/bootstrap.zig
+++ b/std/special/bootstrap.zig
@@ -20,11 +20,11 @@ comptime {
}
}
-extern fn zenMain() -> noreturn {
+extern fn zenMain() noreturn {
std.os.posix.exit(callMain());
}
-nakedcc fn _start() -> noreturn {
+nakedcc fn _start() noreturn {
switch (builtin.arch) {
builtin.Arch.x86_64 => {
argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize));
@@ -39,20 +39,20 @@ nakedcc fn _start() -> noreturn {
@noInlineCall(posixCallMainAndExit);
}
-extern fn WinMainCRTStartup() -> noreturn {
+extern fn WinMainCRTStartup() noreturn {
@setAlignStack(16);
std.os.windows.ExitProcess(callMain());
}
-fn posixCallMainAndExit() -> noreturn {
+fn posixCallMainAndExit() noreturn {
const argc = *argc_ptr;
const argv = @ptrCast(&&u8, &argc_ptr[1]);
const envp = @ptrCast(&?&u8, &argv[argc + 1]);
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
}
-fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) -> u8 {
+fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) u8 {
std.os.ArgIteratorPosix.raw = argv[0..argc];
var env_count: usize = 0;
@@ -62,11 +62,11 @@ fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) -> u8 {
return callMain();
}
-extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 {
+extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) i32 {
return callMainWithArgs(usize(c_argc), c_argv, c_envp);
}
-fn callMain() -> u8 {
+fn callMain() u8 {
switch (@typeId(@typeOf(root.main).ReturnType)) {
builtin.TypeId.NoReturn => {
root.main();
diff --git a/std/special/bootstrap_lib.zig b/std/special/bootstrap_lib.zig
index 3c7789f30a..40b6588838 100644
--- a/std/special/bootstrap_lib.zig
+++ b/std/special/bootstrap_lib.zig
@@ -7,7 +7,7 @@ comptime {
}
stdcallcc fn _DllMainCRTStartup(hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD,
- lpReserved: std.os.windows.LPVOID) -> std.os.windows.BOOL
+ lpReserved: std.os.windows.LPVOID) std.os.windows.BOOL
{
return std.os.windows.TRUE;
}
diff --git a/std/special/build_file_template.zig b/std/special/build_file_template.zig
index 9f6da497f4..282759bedb 100644
--- a/std/special/build_file_template.zig
+++ b/std/special/build_file_template.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig");
exe.setBuildMode(mode);
diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig
index 4722aff07a..e1648276aa 100644
--- a/std/special/build_runner.zig
+++ b/std/special/build_runner.zig
@@ -10,7 +10,7 @@ const warn = std.debug.warn;
error InvalidArgs;
-pub fn main() -> %void {
+pub fn main() %void {
var arg_it = os.args();
// TODO use a more general purpose allocator here
@@ -125,7 +125,7 @@ pub fn main() -> %void {
};
}
-fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> %void {
+fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) %void {
// run the build script to collect the options
if (!already_ran_build) {
builder.setInstallPrefix(null);
@@ -183,12 +183,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
);
}
-fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> error {
+fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) error {
usage(builder, already_ran_build, out_stream) catch {};
return error.InvalidArgs;
}
-fn unwrapArg(arg: %[]u8) -> %[]u8 {
+fn unwrapArg(arg: %[]u8) %[]u8 {
return arg catch |err| {
warn("Unable to parse command line: {}\n", err);
return err;
diff --git a/std/special/builtin.zig b/std/special/builtin.zig
index 41d58adb01..268d0ab545 100644
--- a/std/special/builtin.zig
+++ b/std/special/builtin.zig
@@ -5,7 +5,7 @@ const builtin = @import("builtin");
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
-pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
+pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn {
if (builtin.is_test) {
@setCold(true);
@import("std").debug.panic("{}", msg);
@@ -17,7 +17,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret
// Note that memset does not return `dest`, like the libc API.
// The semantics of memset is dictated by the corresponding
// LLVM intrinsics, not by the libc API.
-export fn memset(dest: ?&u8, c: u8, n: usize) {
+export fn memset(dest: ?&u8, c: u8, n: usize) void {
@setRuntimeSafety(false);
var index: usize = 0;
@@ -28,7 +28,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) {
// Note that memcpy does not return `dest`, like the libc API.
// The semantics of memcpy is dictated by the corresponding
// LLVM intrinsics, not by the libc API.
-export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
+export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) void {
@setRuntimeSafety(false);
var index: usize = 0;
@@ -41,23 +41,23 @@ comptime {
@export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong);
}
}
-extern fn __stack_chk_fail() -> noreturn {
+extern fn __stack_chk_fail() noreturn {
@panic("stack smashing detected");
}
const math = @import("../math/index.zig");
-export fn fmodf(x: f32, y: f32) -> f32 { return generic_fmod(f32, x, y); }
-export fn fmod(x: f64, y: f64) -> f64 { return generic_fmod(f64, x, y); }
+export fn fmodf(x: f32, y: f32) f32 { return generic_fmod(f32, x, y); }
+export fn fmod(x: f64, y: f64) f64 { return generic_fmod(f64, x, y); }
// TODO add intrinsics for these (and probably the double version too)
// and have the math stuff use the intrinsic. same as @mod and @rem
-export fn floorf(x: f32) -> f32 { return math.floor(x); }
-export fn ceilf(x: f32) -> f32 { return math.ceil(x); }
-export fn floor(x: f64) -> f64 { return math.floor(x); }
-export fn ceil(x: f64) -> f64 { return math.ceil(x); }
+export fn floorf(x: f32) f32 { return math.floor(x); }
+export fn ceilf(x: f32) f32 { return math.ceil(x); }
+export fn floor(x: f64) f64 { return math.floor(x); }
+export fn ceil(x: f64) f64 { return math.ceil(x); }
-fn generic_fmod(comptime T: type, x: T, y: T) -> T {
+fn generic_fmod(comptime T: type, x: T, y: T) T {
@setRuntimeSafety(false);
const uint = @IntType(false, T.bit_count);
@@ -133,7 +133,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
return @bitCast(T, ux);
}
-fn isNan(comptime T: type, bits: T) -> bool {
+fn isNan(comptime T: type, bits: T) bool {
if (T == u32) {
return (bits & 0x7fffffff) > 0x7f800000;
} else if (T == u64) {
diff --git a/std/special/compiler_rt/aulldiv.zig b/std/special/compiler_rt/aulldiv.zig
index 96a7f6c624..d99bc94ff5 100644
--- a/std/special/compiler_rt/aulldiv.zig
+++ b/std/special/compiler_rt/aulldiv.zig
@@ -1,4 +1,4 @@
-pub nakedcc fn _aulldiv() {
+pub nakedcc fn _aulldiv() void {
@setRuntimeSafety(false);
asm volatile (
\\.intel_syntax noprefix
diff --git a/std/special/compiler_rt/aullrem.zig b/std/special/compiler_rt/aullrem.zig
index 2fdfc63008..51c4eebe3e 100644
--- a/std/special/compiler_rt/aullrem.zig
+++ b/std/special/compiler_rt/aullrem.zig
@@ -1,4 +1,4 @@
-pub nakedcc fn _aullrem() {
+pub nakedcc fn _aullrem() void {
@setRuntimeSafety(false);
asm volatile (
\\.intel_syntax noprefix
diff --git a/std/special/compiler_rt/comparetf2.zig b/std/special/compiler_rt/comparetf2.zig
index e0fcca8718..c189e5803b 100644
--- a/std/special/compiler_rt/comparetf2.zig
+++ b/std/special/compiler_rt/comparetf2.zig
@@ -21,7 +21,7 @@ const infRep = exponentMask;
const builtin = @import("builtin");
const is_test = builtin.is_test;
-pub extern fn __letf2(a: f128, b: f128) -> c_int {
+pub extern fn __letf2(a: f128, b: f128) c_int {
@setRuntimeSafety(is_test);
const aInt = @bitCast(rep_t, a);
@@ -66,7 +66,7 @@ const GE_EQUAL = c_int(0);
const GE_GREATER = c_int(1);
const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
-pub extern fn __getf2(a: f128, b: f128) -> c_int {
+pub extern fn __getf2(a: f128, b: f128) c_int {
@setRuntimeSafety(is_test);
const aInt = @bitCast(srep_t, a);
@@ -93,7 +93,7 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {
;
}
-pub extern fn __unordtf2(a: f128, b: f128) -> c_int {
+pub extern fn __unordtf2(a: f128, b: f128) c_int {
@setRuntimeSafety(is_test);
const aAbs = @bitCast(rep_t, a) & absMask;
diff --git a/std/special/compiler_rt/fixuint.zig b/std/special/compiler_rt/fixuint.zig
index 7ac54c30db..b01bc48118 100644
--- a/std/special/compiler_rt/fixuint.zig
+++ b/std/special/compiler_rt/fixuint.zig
@@ -1,7 +1,7 @@
const is_test = @import("builtin").is_test;
const Log2Int = @import("../../math/index.zig").Log2Int;
-pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuint_t {
+pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t {
@setRuntimeSafety(is_test);
const rep_t = switch (fp_t) {
diff --git a/std/special/compiler_rt/fixunsdfdi.zig b/std/special/compiler_rt/fixunsdfdi.zig
index 376043c2e7..37a8a01a50 100644
--- a/std/special/compiler_rt/fixunsdfdi.zig
+++ b/std/special/compiler_rt/fixunsdfdi.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunsdfdi(a: f64) -> u64 {
+pub extern fn __fixunsdfdi(a: f64) u64 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f64, u64, a);
}
diff --git a/std/special/compiler_rt/fixunsdfdi_test.zig b/std/special/compiler_rt/fixunsdfdi_test.zig
index 2a0e778ba3..3443a4938e 100644
--- a/std/special/compiler_rt/fixunsdfdi_test.zig
+++ b/std/special/compiler_rt/fixunsdfdi_test.zig
@@ -1,7 +1,7 @@
const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunsdfdi(a: f64, expected: u64) {
+fn test__fixunsdfdi(a: f64, expected: u64) void {
const x = __fixunsdfdi(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunsdfsi.zig b/std/special/compiler_rt/fixunsdfsi.zig
index a0b52bcc88..0b5aebb7f6 100644
--- a/std/special/compiler_rt/fixunsdfsi.zig
+++ b/std/special/compiler_rt/fixunsdfsi.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunsdfsi(a: f64) -> u32 {
+pub extern fn __fixunsdfsi(a: f64) u32 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f64, u32, a);
}
diff --git a/std/special/compiler_rt/fixunsdfsi_test.zig b/std/special/compiler_rt/fixunsdfsi_test.zig
index 6116391391..3c74bc5f4c 100644
--- a/std/special/compiler_rt/fixunsdfsi_test.zig
+++ b/std/special/compiler_rt/fixunsdfsi_test.zig
@@ -1,7 +1,7 @@
const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunsdfsi(a: f64, expected: u32) {
+fn test__fixunsdfsi(a: f64, expected: u32) void {
const x = __fixunsdfsi(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunsdfti.zig b/std/special/compiler_rt/fixunsdfti.zig
index 6f2ef417c9..6e1ded46e5 100644
--- a/std/special/compiler_rt/fixunsdfti.zig
+++ b/std/special/compiler_rt/fixunsdfti.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunsdfti(a: f64) -> u128 {
+pub extern fn __fixunsdfti(a: f64) u128 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f64, u128, a);
}
diff --git a/std/special/compiler_rt/fixunsdfti_test.zig b/std/special/compiler_rt/fixunsdfti_test.zig
index dc7f1c29cd..3cb7687887 100644
--- a/std/special/compiler_rt/fixunsdfti_test.zig
+++ b/std/special/compiler_rt/fixunsdfti_test.zig
@@ -1,7 +1,7 @@
const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunsdfti(a: f64, expected: u128) {
+fn test__fixunsdfti(a: f64, expected: u128) void {
const x = __fixunsdfti(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunssfdi.zig b/std/special/compiler_rt/fixunssfdi.zig
index e8811c0c93..36d4acc28c 100644
--- a/std/special/compiler_rt/fixunssfdi.zig
+++ b/std/special/compiler_rt/fixunssfdi.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunssfdi(a: f32) -> u64 {
+pub extern fn __fixunssfdi(a: f32) u64 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f32, u64, a);
}
diff --git a/std/special/compiler_rt/fixunssfdi_test.zig b/std/special/compiler_rt/fixunssfdi_test.zig
index 41827a0834..de27323777 100644
--- a/std/special/compiler_rt/fixunssfdi_test.zig
+++ b/std/special/compiler_rt/fixunssfdi_test.zig
@@ -1,7 +1,7 @@
const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunssfdi(a: f32, expected: u64) {
+fn test__fixunssfdi(a: f32, expected: u64) void {
const x = __fixunssfdi(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunssfsi.zig b/std/special/compiler_rt/fixunssfsi.zig
index 20d659696a..53130286a1 100644
--- a/std/special/compiler_rt/fixunssfsi.zig
+++ b/std/special/compiler_rt/fixunssfsi.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunssfsi(a: f32) -> u32 {
+pub extern fn __fixunssfsi(a: f32) u32 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f32, u32, a);
}
diff --git a/std/special/compiler_rt/fixunssfsi_test.zig b/std/special/compiler_rt/fixunssfsi_test.zig
index 664c02ea73..47ed21d4f4 100644
--- a/std/special/compiler_rt/fixunssfsi_test.zig
+++ b/std/special/compiler_rt/fixunssfsi_test.zig
@@ -1,7 +1,7 @@
const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunssfsi(a: f32, expected: u32) {
+fn test__fixunssfsi(a: f32, expected: u32) void {
const x = __fixunssfsi(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunssfti.zig b/std/special/compiler_rt/fixunssfti.zig
index 0ad5b85475..0abd73fe76 100644
--- a/std/special/compiler_rt/fixunssfti.zig
+++ b/std/special/compiler_rt/fixunssfti.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunssfti(a: f32) -> u128 {
+pub extern fn __fixunssfti(a: f32) u128 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f32, u128, a);
}
diff --git a/std/special/compiler_rt/fixunssfti_test.zig b/std/special/compiler_rt/fixunssfti_test.zig
index 712df893c1..3033eb0def 100644
--- a/std/special/compiler_rt/fixunssfti_test.zig
+++ b/std/special/compiler_rt/fixunssfti_test.zig
@@ -1,7 +1,7 @@
const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunssfti(a: f32, expected: u128) {
+fn test__fixunssfti(a: f32, expected: u128) void {
const x = __fixunssfti(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunstfdi.zig b/std/special/compiler_rt/fixunstfdi.zig
index 5d95771761..e352044708 100644
--- a/std/special/compiler_rt/fixunstfdi.zig
+++ b/std/special/compiler_rt/fixunstfdi.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunstfdi(a: f128) -> u64 {
+pub extern fn __fixunstfdi(a: f128) u64 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f128, u64, a);
}
diff --git a/std/special/compiler_rt/fixunstfdi_test.zig b/std/special/compiler_rt/fixunstfdi_test.zig
index b5526f62a6..d1f5f6496a 100644
--- a/std/special/compiler_rt/fixunstfdi_test.zig
+++ b/std/special/compiler_rt/fixunstfdi_test.zig
@@ -1,7 +1,7 @@
const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunstfdi(a: f128, expected: u64) {
+fn test__fixunstfdi(a: f128, expected: u64) void {
const x = __fixunstfdi(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunstfsi.zig b/std/special/compiler_rt/fixunstfsi.zig
index f0fbf71fdf..579c559790 100644
--- a/std/special/compiler_rt/fixunstfsi.zig
+++ b/std/special/compiler_rt/fixunstfsi.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunstfsi(a: f128) -> u32 {
+pub extern fn __fixunstfsi(a: f128) u32 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f128, u32, a);
}
diff --git a/std/special/compiler_rt/fixunstfsi_test.zig b/std/special/compiler_rt/fixunstfsi_test.zig
index 74b3507c44..8bdf36d9d4 100644
--- a/std/special/compiler_rt/fixunstfsi_test.zig
+++ b/std/special/compiler_rt/fixunstfsi_test.zig
@@ -1,7 +1,7 @@
const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunstfsi(a: f128, expected: u32) {
+fn test__fixunstfsi(a: f128, expected: u32) void {
const x = __fixunstfsi(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/fixunstfti.zig b/std/special/compiler_rt/fixunstfti.zig
index 9e4c5f1829..fea99eb6e8 100644
--- a/std/special/compiler_rt/fixunstfti.zig
+++ b/std/special/compiler_rt/fixunstfti.zig
@@ -1,7 +1,7 @@
const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
-pub extern fn __fixunstfti(a: f128) -> u128 {
+pub extern fn __fixunstfti(a: f128) u128 {
@setRuntimeSafety(builtin.is_test);
return fixuint(f128, u128, a);
}
diff --git a/std/special/compiler_rt/fixunstfti_test.zig b/std/special/compiler_rt/fixunstfti_test.zig
index a6c9ea0f68..d9eb60e59b 100644
--- a/std/special/compiler_rt/fixunstfti_test.zig
+++ b/std/special/compiler_rt/fixunstfti_test.zig
@@ -1,7 +1,7 @@
const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
const assert = @import("../../index.zig").debug.assert;
-fn test__fixunstfti(a: f128, expected: u128) {
+fn test__fixunstfti(a: f128, expected: u128) void {
const x = __fixunstfti(a);
assert(x == expected);
}
diff --git a/std/special/compiler_rt/index.zig b/std/special/compiler_rt/index.zig
index 97b78e3606..d12b0d2fd6 100644
--- a/std/special/compiler_rt/index.zig
+++ b/std/special/compiler_rt/index.zig
@@ -74,7 +74,7 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
-pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
+pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn {
@setCold(true);
if (is_test) {
@import("std").debug.panic("{}", msg);
@@ -83,12 +83,12 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret
}
}
-extern fn __udivdi3(a: u64, b: u64) -> u64 {
+extern fn __udivdi3(a: u64, b: u64) u64 {
@setRuntimeSafety(is_test);
return __udivmoddi4(a, b, null);
}
-extern fn __umoddi3(a: u64, b: u64) -> u64 {
+extern fn __umoddi3(a: u64, b: u64) u64 {
@setRuntimeSafety(is_test);
var r: u64 = undefined;
@@ -100,14 +100,14 @@ const AeabiUlDivModResult = extern struct {
quot: u64,
rem: u64,
};
-extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult {
+extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) AeabiUlDivModResult {
@setRuntimeSafety(is_test);
var result: AeabiUlDivModResult = undefined;
result.quot = __udivmoddi4(numerator, denominator, &result.rem);
return result;
}
-fn isArmArch() -> bool {
+fn isArmArch() bool {
return switch (builtin.arch) {
builtin.Arch.armv8_2a,
builtin.Arch.armv8_1a,
@@ -132,7 +132,7 @@ fn isArmArch() -> bool {
};
}
-nakedcc fn __aeabi_uidivmod() {
+nakedcc fn __aeabi_uidivmod() void {
@setRuntimeSafety(false);
asm volatile (
\\ push { lr }
@@ -149,7 +149,7 @@ nakedcc fn __aeabi_uidivmod() {
// then decrement %esp by %eax. Preserves all registers except %esp and flags.
// This routine is windows specific
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
-nakedcc fn _chkstk() align(4) {
+nakedcc fn _chkstk() align(4) void {
@setRuntimeSafety(false);
asm volatile (
@@ -173,7 +173,7 @@ nakedcc fn _chkstk() align(4) {
);
}
-nakedcc fn __chkstk() align(4) {
+nakedcc fn __chkstk() align(4) void {
@setRuntimeSafety(false);
asm volatile (
@@ -200,7 +200,7 @@ nakedcc fn __chkstk() align(4) {
// _chkstk routine
// This routine is windows specific
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
-nakedcc fn __chkstk_ms() align(4) {
+nakedcc fn __chkstk_ms() align(4) void {
@setRuntimeSafety(false);
asm volatile (
@@ -224,7 +224,7 @@ nakedcc fn __chkstk_ms() align(4) {
);
}
-nakedcc fn ___chkstk_ms() align(4) {
+nakedcc fn ___chkstk_ms() align(4) void {
@setRuntimeSafety(false);
asm volatile (
@@ -248,7 +248,7 @@ nakedcc fn ___chkstk_ms() align(4) {
);
}
-extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
+extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {
@setRuntimeSafety(is_test);
const d = __udivsi3(a, b);
@@ -257,7 +257,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
}
-extern fn __udivsi3(n: u32, d: u32) -> u32 {
+extern fn __udivsi3(n: u32, d: u32) u32 {
@setRuntimeSafety(is_test);
const n_uword_bits: c_uint = u32.bit_count;
@@ -304,7 +304,7 @@ test "test_umoddi3" {
test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
}
-fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) {
+fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
const r = __umoddi3(a, b);
assert(r == expected_r);
}
@@ -450,7 +450,7 @@ test "test_udivsi3" {
}
}
-fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) {
+fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
const q: u32 = __udivsi3(a, b);
assert(q == expected_q);
}
diff --git a/std/special/compiler_rt/udivmod.zig b/std/special/compiler_rt/udivmod.zig
index c215830ba1..82751d5993 100644
--- a/std/special/compiler_rt/udivmod.zig
+++ b/std/special/compiler_rt/udivmod.zig
@@ -4,7 +4,7 @@ const is_test = builtin.is_test;
const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 };
const high = 1 - low;
-pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) -> DoubleInt {
+pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt {
@setRuntimeSafety(is_test);
const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
diff --git a/std/special/compiler_rt/udivmoddi4.zig b/std/special/compiler_rt/udivmoddi4.zig
index 9387c176c4..6cc54bb6bf 100644
--- a/std/special/compiler_rt/udivmoddi4.zig
+++ b/std/special/compiler_rt/udivmoddi4.zig
@@ -1,7 +1,7 @@
const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
-pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) -> u64 {
+pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) u64 {
@setRuntimeSafety(builtin.is_test);
return udivmod(u64, a, b, maybe_rem);
}
diff --git a/std/special/compiler_rt/udivmoddi4_test.zig b/std/special/compiler_rt/udivmoddi4_test.zig
index 3cc5359a51..324626d3f9 100644
--- a/std/special/compiler_rt/udivmoddi4_test.zig
+++ b/std/special/compiler_rt/udivmoddi4_test.zig
@@ -1,7 +1,7 @@
const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
const assert = @import("std").debug.assert;
-fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) {
+fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
var r: u64 = undefined;
const q = __udivmoddi4(a, b, &r);
assert(q == expected_q);
diff --git a/std/special/compiler_rt/udivmodti4.zig b/std/special/compiler_rt/udivmodti4.zig
index 2119e1a879..196d067aef 100644
--- a/std/special/compiler_rt/udivmodti4.zig
+++ b/std/special/compiler_rt/udivmodti4.zig
@@ -1,7 +1,7 @@
const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
-pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) -> u128 {
+pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {
@setRuntimeSafety(builtin.is_test);
return udivmod(u128, a, b, maybe_rem);
}
diff --git a/std/special/compiler_rt/udivmodti4_test.zig b/std/special/compiler_rt/udivmodti4_test.zig
index 30837e7a2d..48d65b43c6 100644
--- a/std/special/compiler_rt/udivmodti4_test.zig
+++ b/std/special/compiler_rt/udivmodti4_test.zig
@@ -1,7 +1,7 @@
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const assert = @import("std").debug.assert;
-fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) {
+fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
var r: u128 = undefined;
const q = __udivmodti4(a, b, &r);
assert(q == expected_q);
diff --git a/std/special/compiler_rt/udivti3.zig b/std/special/compiler_rt/udivti3.zig
index b19f62ffbc..eaecbac4d2 100644
--- a/std/special/compiler_rt/udivti3.zig
+++ b/std/special/compiler_rt/udivti3.zig
@@ -1,7 +1,7 @@
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const builtin = @import("builtin");
-pub extern fn __udivti3(a: u128, b: u128) -> u128 {
+pub extern fn __udivti3(a: u128, b: u128) u128 {
@setRuntimeSafety(builtin.is_test);
return __udivmodti4(a, b, null);
}
diff --git a/std/special/compiler_rt/umodti3.zig b/std/special/compiler_rt/umodti3.zig
index 51cf172261..26b306efa9 100644
--- a/std/special/compiler_rt/umodti3.zig
+++ b/std/special/compiler_rt/umodti3.zig
@@ -1,7 +1,7 @@
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const builtin = @import("builtin");
-pub extern fn __umodti3(a: u128, b: u128) -> u128 {
+pub extern fn __umodti3(a: u128, b: u128) u128 {
@setRuntimeSafety(builtin.is_test);
var r: u128 = undefined;
_ = __udivmodti4(a, b, &r);
diff --git a/std/special/panic.zig b/std/special/panic.zig
index 7aaaa78d0a..cfefa8e839 100644
--- a/std/special/panic.zig
+++ b/std/special/panic.zig
@@ -6,7 +6,7 @@
const builtin = @import("builtin");
const std = @import("std");
-pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
+pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn {
@setCold(true);
switch (builtin.os) {
// TODO: fix panic in zen.
diff --git a/std/special/test_runner.zig b/std/special/test_runner.zig
index c5c0bad40c..3284f740b0 100644
--- a/std/special/test_runner.zig
+++ b/std/special/test_runner.zig
@@ -4,7 +4,7 @@ const builtin = @import("builtin");
const test_fn_list = builtin.__zig_test_fn_slice;
const warn = std.debug.warn;
-pub fn main() -> %void {
+pub fn main() %void {
for (test_fn_list) |test_fn, i| {
warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
diff --git a/std/unicode.zig b/std/unicode.zig
index d21ed0204a..235ac4ceac 100644
--- a/std/unicode.zig
+++ b/std/unicode.zig
@@ -5,7 +5,7 @@ error Utf8InvalidStartByte;
/// Given the first byte of a UTF-8 codepoint,
/// returns a number 1-4 indicating the total length of the codepoint in bytes.
/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
-pub fn utf8ByteSequenceLength(first_byte: u8) -> %u3 {
+pub fn utf8ByteSequenceLength(first_byte: u8) %u3 {
if (first_byte < 0b10000000) return u3(1);
if (first_byte & 0b11100000 == 0b11000000) return u3(2);
if (first_byte & 0b11110000 == 0b11100000) return u3(3);
@@ -22,7 +22,7 @@ error Utf8CodepointTooLarge;
/// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable.
/// If you already know the length at comptime, you can call one of
/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
-pub fn utf8Decode(bytes: []const u8) -> %u32 {
+pub fn utf8Decode(bytes: []const u8) %u32 {
return switch (bytes.len) {
1 => u32(bytes[0]),
2 => utf8Decode2(bytes),
@@ -31,7 +31,7 @@ pub fn utf8Decode(bytes: []const u8) -> %u32 {
else => unreachable,
};
}
-pub fn utf8Decode2(bytes: []const u8) -> %u32 {
+pub fn utf8Decode2(bytes: []const u8) %u32 {
std.debug.assert(bytes.len == 2);
std.debug.assert(bytes[0] & 0b11100000 == 0b11000000);
var value: u32 = bytes[0] & 0b00011111;
@@ -44,7 +44,7 @@ pub fn utf8Decode2(bytes: []const u8) -> %u32 {
return value;
}
-pub fn utf8Decode3(bytes: []const u8) -> %u32 {
+pub fn utf8Decode3(bytes: []const u8) %u32 {
std.debug.assert(bytes.len == 3);
std.debug.assert(bytes[0] & 0b11110000 == 0b11100000);
var value: u32 = bytes[0] & 0b00001111;
@@ -62,7 +62,7 @@ pub fn utf8Decode3(bytes: []const u8) -> %u32 {
return value;
}
-pub fn utf8Decode4(bytes: []const u8) -> %u32 {
+pub fn utf8Decode4(bytes: []const u8) %u32 {
std.debug.assert(bytes.len == 4);
std.debug.assert(bytes[0] & 0b11111000 == 0b11110000);
var value: u32 = bytes[0] & 0b00000111;
@@ -149,7 +149,7 @@ test "misc invalid utf8" {
testValid("\xee\x80\x80", 0xe000);
}
-fn testError(bytes: []const u8, expected_err: error) {
+fn testError(bytes: []const u8, expected_err: error) void {
if (testDecode(bytes)) |_| {
unreachable;
} else |err| {
@@ -157,11 +157,11 @@ fn testError(bytes: []const u8, expected_err: error) {
}
}
-fn testValid(bytes: []const u8, expected_codepoint: u32) {
+fn testValid(bytes: []const u8, expected_codepoint: u32) void {
std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint);
}
-fn testDecode(bytes: []const u8) -> %u32 {
+fn testDecode(bytes: []const u8) %u32 {
const length = try utf8ByteSequenceLength(bytes[0]);
if (bytes.len < length) return error.UnexpectedEof;
std.debug.assert(bytes.len == length);
diff --git a/std/zlib/deflate.zig b/std/zlib/deflate.zig
deleted file mode 100644
index 7374d33cf1..0000000000
--- a/std/zlib/deflate.zig
+++ /dev/null
@@ -1,522 +0,0 @@
-const z_stream = struct {
- /// next input byte */
- next_in: &const u8,
-
- /// number of bytes available at next_in
- avail_in: u16,
- /// total number of input bytes read so far
- total_in: u32,
-
- /// next output byte will go here
- next_out: u8,
- /// remaining free space at next_out
- avail_out: u16,
- /// total number of bytes output so far
- total_out: u32,
-
- /// last error message, NULL if no error
- msg: ?&const u8,
- /// not visible by applications
- state:
- struct internal_state FAR *state; // not visible by applications */
-
- alloc_func zalloc; // used to allocate the internal state */
- free_func zfree; // used to free the internal state */
- voidpf opaque; // private data object passed to zalloc and zfree */
-
- int data_type; // best guess about the data type: binary or text
- // for deflate, or the decoding state for inflate */
- uint32_t adler; // Adler-32 or CRC-32 value of the uncompressed data */
- uint32_t reserved; // reserved for future use */
-};
-
-typedef struct internal_state {
- z_stream * strm; /* pointer back to this zlib stream */
- int status; /* as the name implies */
- uint8_t *pending_buf; /* output still pending */
- ulg pending_buf_size; /* size of pending_buf */
- uint8_t *pending_out; /* next pending byte to output to the stream */
- ulg pending; /* nb of bytes in the pending buffer */
- int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
- gz_headerp gzhead; /* gzip header information to write */
- ulg gzindex; /* where in extra, name, or comment */
- uint8_t method; /* can only be DEFLATED */
- int last_flush; /* value of flush param for previous deflate call */
-
- /* used by deflate.c: */
-
- uint16_t w_size; /* LZ77 window size (32K by default) */
- uint16_t w_bits; /* log2(w_size) (8..16) */
- uint16_t w_mask; /* w_size - 1 */
-
- uint8_t *window;
- /* Sliding window. Input bytes are read into the second half of the window,
- * and move to the first half later to keep a dictionary of at least wSize
- * bytes. With this organization, matches are limited to a distance of
- * wSize-MAX_MATCH bytes, but this ensures that IO is always
- * performed with a length multiple of the block size. Also, it limits
- * the window size to 64K, which is quite useful on MSDOS.
- * To do: use the user input buffer as sliding window.
- */
-
- ulg window_size;
- /* Actual size of window: 2*wSize, except when the user input buffer
- * is directly used as sliding window.
- */
-
- Posf *prev;
- /* Link to older string with same hash index. To limit the size of this
- * array to 64K, this link is maintained only for the last 32K strings.
- * An index in this array is thus a window index modulo 32K.
- */
-
- Posf *head; /* Heads of the hash chains or NIL. */
-
- uint16_t ins_h; /* hash index of string to be inserted */
- uint16_t hash_size; /* number of elements in hash table */
- uint16_t hash_bits; /* log2(hash_size) */
- uint16_t hash_mask; /* hash_size-1 */
-
- uint16_t hash_shift;
- /* Number of bits by which ins_h must be shifted at each input
- * step. It must be such that after MIN_MATCH steps, the oldest
- * byte no longer takes part in the hash key, that is:
- * hash_shift * MIN_MATCH >= hash_bits
- */
-
- long block_start;
- /* Window position at the beginning of the current output block. Gets
- * negative when the window is moved backwards.
- */
-
- uint16_t match_length; /* length of best match */
- IPos prev_match; /* previous match */
- int match_available; /* set if previous match exists */
- uint16_t strstart; /* start of string to insert */
- uint16_t match_start; /* start of matching string */
- uint16_t lookahead; /* number of valid bytes ahead in window */
-
- uint16_t prev_length;
- /* Length of the best match at previous step. Matches not greater than this
- * are discarded. This is used in the lazy match evaluation.
- */
-
- uint16_t max_chain_length;
- /* To speed up deflation, hash chains are never searched beyond this
- * length. A higher limit improves compression ratio but degrades the
- * speed.
- */
-
- uint16_t max_lazy_match;
- /* Attempt to find a better match only when the current match is strictly
- * smaller than this value. This mechanism is used only for compression
- * levels >= 4.
- */
-# define max_insert_length max_lazy_match
- /* Insert new strings in the hash table only if the match length is not
- * greater than this length. This saves time but degrades compression.
- * max_insert_length is used only for compression levels <= 3.
- */
-
- int level; /* compression level (1..9) */
- int strategy; /* favor or force Huffman coding*/
-
- uint16_t good_match;
- /* Use a faster search when the previous match is longer than this */
-
- int nice_match; /* Stop searching when current match exceeds this */
-
- /* used by trees.c: */
- /* Didn't use ct_data typedef below to suppress compiler warning */
- struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
- struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
- struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
-
- struct tree_desc_s l_desc; /* desc. for literal tree */
- struct tree_desc_s d_desc; /* desc. for distance tree */
- struct tree_desc_s bl_desc; /* desc. for bit length tree */
-
- ush bl_count[MAX_BITS+1];
- /* number of codes at each bit length for an optimal tree */
-
- int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
- int heap_len; /* number of elements in the heap */
- int heap_max; /* element of largest frequency */
- /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
- * The same heap array is used to build all trees.
- */
-
- uch depth[2*L_CODES+1];
- /* Depth of each subtree used as tie breaker for trees of equal frequency
- */
-
- uchf *l_buf; /* buffer for literals or lengths */
-
- uint16_t lit_bufsize;
- /* Size of match buffer for literals/lengths. There are 4 reasons for
- * limiting lit_bufsize to 64K:
- * - frequencies can be kept in 16 bit counters
- * - if compression is not successful for the first block, all input
- * data is still in the window so we can still emit a stored block even
- * when input comes from standard input. (This can also be done for
- * all blocks if lit_bufsize is not greater than 32K.)
- * - if compression is not successful for a file smaller than 64K, we can
- * even emit a stored file instead of a stored block (saving 5 bytes).
- * This is applicable only for zip (not gzip or zlib).
- * - creating new Huffman trees less frequently may not provide fast
- * adaptation to changes in the input data statistics. (Take for
- * example a binary file with poorly compressible code followed by
- * a highly compressible string table.) Smaller buffer sizes give
- * fast adaptation but have of course the overhead of transmitting
- * trees more frequently.
- * - I can't count above 4
- */
-
- uint16_t last_lit; /* running index in l_buf */
-
- ushf *d_buf;
- /* Buffer for distances. To simplify the code, d_buf and l_buf have
- * the same number of elements. To use different lengths, an extra flag
- * array would be necessary.
- */
-
- ulg opt_len; /* bit length of current block with optimal trees */
- ulg static_len; /* bit length of current block with static trees */
- uint16_t matches; /* number of string matches in current block */
- uint16_t insert; /* bytes at end of window left to insert */
-
-#ifdef ZLIB_DEBUG
- ulg compressed_len; /* total bit length of compressed file mod 2^32 */
- ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
-#endif
-
- ush bi_buf;
- /* Output buffer. bits are inserted starting at the bottom (least
- * significant bits).
- */
- int bi_valid;
- /* Number of valid bits in bi_buf. All bits above the last valid bit
- * are always zero.
- */
-
- ulg high_water;
- /* High water mark offset in window for initialized bytes -- bytes above
- * this are set to zero in order to avoid memory check warnings when
- * longest match routines access bytes past the input. This is then
- * updated to the new high water mark.
- */
-
-} FAR deflate_state;
-
-fn deflate(strm: &z_stream, flush: int) -> %void {
-
-}
-
-int deflate (z_stream * strm, int flush) {
- int old_flush; /* value of flush param for previous deflate call */
- deflate_state *s;
-
- if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
- return Z_STREAM_ERROR;
- }
- s = strm->state;
-
- if (strm->next_out == Z_NULL ||
- (strm->avail_in != 0 && strm->next_in == Z_NULL) ||
- (s->status == FINISH_STATE && flush != Z_FINISH)) {
- ERR_RETURN(strm, Z_STREAM_ERROR);
- }
- if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
-
- old_flush = s->last_flush;
- s->last_flush = flush;
-
- /* Flush as much pending output as possible */
- if (s->pending != 0) {
- flush_pending(strm);
- if (strm->avail_out == 0) {
- /* Since avail_out is 0, deflate will be called again with
- * more output space, but possibly with both pending and
- * avail_in equal to zero. There won't be anything to do,
- * but this is not an error situation so make sure we
- * return OK instead of BUF_ERROR at next call of deflate:
- */
- s->last_flush = -1;
- return Z_OK;
- }
-
- /* Make sure there is something to do and avoid duplicate consecutive
- * flushes. For repeated and useless calls with Z_FINISH, we keep
- * returning Z_STREAM_END instead of Z_BUF_ERROR.
- */
- } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
- flush != Z_FINISH) {
- ERR_RETURN(strm, Z_BUF_ERROR);
- }
-
- /* User must not provide more input after the first FINISH: */
- if (s->status == FINISH_STATE && strm->avail_in != 0) {
- ERR_RETURN(strm, Z_BUF_ERROR);
- }
-
- /* Write the header */
- if (s->status == INIT_STATE) {
- /* zlib header */
- uint16_t header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
- uint16_t level_flags;
-
- if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
- level_flags = 0;
- else if (s->level < 6)
- level_flags = 1;
- else if (s->level == 6)
- level_flags = 2;
- else
- level_flags = 3;
- header |= (level_flags << 6);
- if (s->strstart != 0) header |= PRESET_DICT;
- header += 31 - (header % 31);
-
- putShortMSB(s, header);
-
- /* Save the adler32 of the preset dictionary: */
- if (s->strstart != 0) {
- putShortMSB(s, (uint16_t)(strm->adler >> 16));
- putShortMSB(s, (uint16_t)(strm->adler & 0xffff));
- }
- strm->adler = adler32(0L, Z_NULL, 0);
- s->status = BUSY_STATE;
-
- /* Compression must start with an empty pending buffer */
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- }
-#ifdef GZIP
- if (s->status == GZIP_STATE) {
- /* gzip header */
- strm->adler = crc32(0L, Z_NULL, 0);
- put_byte(s, 31);
- put_byte(s, 139);
- put_byte(s, 8);
- if (s->gzhead == Z_NULL) {
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, 0);
- put_byte(s, s->level == 9 ? 2 :
- (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
- 4 : 0));
- put_byte(s, OS_CODE);
- s->status = BUSY_STATE;
-
- /* Compression must start with an empty pending buffer */
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- }
- else {
- put_byte(s, (s->gzhead->text ? 1 : 0) +
- (s->gzhead->hcrc ? 2 : 0) +
- (s->gzhead->extra == Z_NULL ? 0 : 4) +
- (s->gzhead->name == Z_NULL ? 0 : 8) +
- (s->gzhead->comment == Z_NULL ? 0 : 16)
- );
- put_byte(s, (uint8_t)(s->gzhead->time & 0xff));
- put_byte(s, (uint8_t)((s->gzhead->time >> 8) & 0xff));
- put_byte(s, (uint8_t)((s->gzhead->time >> 16) & 0xff));
- put_byte(s, (uint8_t)((s->gzhead->time >> 24) & 0xff));
- put_byte(s, s->level == 9 ? 2 :
- (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
- 4 : 0));
- put_byte(s, s->gzhead->os & 0xff);
- if (s->gzhead->extra != Z_NULL) {
- put_byte(s, s->gzhead->extra_len & 0xff);
- put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
- }
- if (s->gzhead->hcrc)
- strm->adler = crc32(strm->adler, s->pending_buf,
- s->pending);
- s->gzindex = 0;
- s->status = EXTRA_STATE;
- }
- }
- if (s->status == EXTRA_STATE) {
- if (s->gzhead->extra != Z_NULL) {
- ulg beg = s->pending; /* start of bytes to update crc */
- uint16_t left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
- while (s->pending + left > s->pending_buf_size) {
- uint16_t copy = s->pending_buf_size - s->pending;
- zmemcpy(s->pending_buf + s->pending,
- s->gzhead->extra + s->gzindex, copy);
- s->pending = s->pending_buf_size;
- HCRC_UPDATE(beg);
- s->gzindex += copy;
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- beg = 0;
- left -= copy;
- }
- zmemcpy(s->pending_buf + s->pending,
- s->gzhead->extra + s->gzindex, left);
- s->pending += left;
- HCRC_UPDATE(beg);
- s->gzindex = 0;
- }
- s->status = NAME_STATE;
- }
- if (s->status == NAME_STATE) {
- if (s->gzhead->name != Z_NULL) {
- ulg beg = s->pending; /* start of bytes to update crc */
- int val;
- do {
- if (s->pending == s->pending_buf_size) {
- HCRC_UPDATE(beg);
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- beg = 0;
- }
- val = s->gzhead->name[s->gzindex++];
- put_byte(s, val);
- } while (val != 0);
- HCRC_UPDATE(beg);
- s->gzindex = 0;
- }
- s->status = COMMENT_STATE;
- }
- if (s->status == COMMENT_STATE) {
- if (s->gzhead->comment != Z_NULL) {
- ulg beg = s->pending; /* start of bytes to update crc */
- int val;
- do {
- if (s->pending == s->pending_buf_size) {
- HCRC_UPDATE(beg);
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- beg = 0;
- }
- val = s->gzhead->comment[s->gzindex++];
- put_byte(s, val);
- } while (val != 0);
- HCRC_UPDATE(beg);
- }
- s->status = HCRC_STATE;
- }
- if (s->status == HCRC_STATE) {
- if (s->gzhead->hcrc) {
- if (s->pending + 2 > s->pending_buf_size) {
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- }
- put_byte(s, (uint8_t)(strm->adler & 0xff));
- put_byte(s, (uint8_t)((strm->adler >> 8) & 0xff));
- strm->adler = crc32(0L, Z_NULL, 0);
- }
- s->status = BUSY_STATE;
-
- /* Compression must start with an empty pending buffer */
- flush_pending(strm);
- if (s->pending != 0) {
- s->last_flush = -1;
- return Z_OK;
- }
- }
-#endif
-
- /* Start a new block or continue the current one.
- */
- if (strm->avail_in != 0 || s->lookahead != 0 ||
- (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
- block_state bstate;
-
- bstate = s->level == 0 ? deflate_stored(s, flush) :
- s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
- s->strategy == Z_RLE ? deflate_rle(s, flush) :
- (*(configuration_table[s->level].func))(s, flush);
-
- if (bstate == finish_started || bstate == finish_done) {
- s->status = FINISH_STATE;
- }
- if (bstate == need_more || bstate == finish_started) {
- if (strm->avail_out == 0) {
- s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
- }
- return Z_OK;
- /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
- * of deflate should use the same flush parameter to make sure
- * that the flush is complete. So we don't have to output an
- * empty block here, this will be done at next call. This also
- * ensures that for a very small output buffer, we emit at most
- * one empty block.
- */
- }
- if (bstate == block_done) {
- if (flush == Z_PARTIAL_FLUSH) {
- _tr_align(s);
- } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
- _tr_stored_block(s, (char*)0, 0L, 0);
- /* For a full flush, this empty block will be recognized
- * as a special marker by inflate_sync().
- */
- if (flush == Z_FULL_FLUSH) {
- CLEAR_HASH(s); /* forget history */
- if (s->lookahead == 0) {
- s->strstart = 0;
- s->block_start = 0L;
- s->insert = 0;
- }
- }
- }
- flush_pending(strm);
- if (strm->avail_out == 0) {
- s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
- return Z_OK;
- }
- }
- }
-
- if (flush != Z_FINISH) return Z_OK;
- if (s->wrap <= 0) return Z_STREAM_END;
-
- /* Write the trailer */
-#ifdef GZIP
- if (s->wrap == 2) {
- put_byte(s, (uint8_t)(strm->adler & 0xff));
- put_byte(s, (uint8_t)((strm->adler >> 8) & 0xff));
- put_byte(s, (uint8_t)((strm->adler >> 16) & 0xff));
- put_byte(s, (uint8_t)((strm->adler >> 24) & 0xff));
- put_byte(s, (uint8_t)(strm->total_in & 0xff));
- put_byte(s, (uint8_t)((strm->total_in >> 8) & 0xff));
- put_byte(s, (uint8_t)((strm->total_in >> 16) & 0xff));
- put_byte(s, (uint8_t)((strm->total_in >> 24) & 0xff));
- }
- else
-#endif
- {
- putShortMSB(s, (uint16_t)(strm->adler >> 16));
- putShortMSB(s, (uint16_t)(strm->adler & 0xffff));
- }
- flush_pending(strm);
- /* If avail_out is zero, the application will call deflate again
- * to flush the rest.
- */
- if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
- return s->pending != 0 ? Z_OK : Z_STREAM_END;
-}
diff --git a/std/zlib/inflate.zig b/std/zlib/inflate.zig
deleted file mode 100644
index 1bb3f858ac..0000000000
--- a/std/zlib/inflate.zig
+++ /dev/null
@@ -1,969 +0,0 @@
-
-error Z_STREAM_ERROR;
-error Z_STREAM_END;
-error Z_NEED_DICT;
-error Z_ERRNO;
-error Z_STREAM_ERROR;
-error Z_DATA_ERROR;
-error Z_MEM_ERROR;
-error Z_BUF_ERROR;
-error Z_VERSION_ERROR;
-
-pub Flush = enum {
- NO_FLUSH,
- PARTIAL_FLUSH,
- SYNC_FLUSH,
- FULL_FLUSH,
- FINISH,
- BLOCK,
- TREES,
-};
-
-const code = struct {
- /// operation, extra bits, table bits
- op: u8,
- /// bits in this part of the code
- bits: u8,
- /// offset in table or code value
- val: u16,
-};
-
-/// State maintained between inflate() calls -- approximately 7K bytes, not
-/// including the allocated sliding window, which is up to 32K bytes.
-const inflate_state = struct {
- z_stream * strm; /* pointer back to this zlib stream */
- inflate_mode mode; /* current inflate mode */
- int last; /* true if processing last block */
- int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
- bit 2 true to validate check value */
- int havedict; /* true if dictionary provided */
- int flags; /* gzip header method and flags (0 if zlib) */
- unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
- unsigned long check; /* protected copy of check value */
- unsigned long total; /* protected copy of output count */
- gz_headerp head; /* where to save gzip header information */
- /* sliding window */
- unsigned wbits; /* log base 2 of requested window size */
- unsigned wsize; /* window size or zero if not using window */
- unsigned whave; /* valid bytes in the window */
- unsigned wnext; /* window write index */
- u8 FAR *window; /* allocated sliding window, if needed */
- /* bit accumulator */
- unsigned long hold; /* input bit accumulator */
- unsigned bits; /* number of bits in "in" */
- /* for string and stored block copying */
- unsigned length; /* literal or length of data to copy */
- unsigned offset; /* distance back to copy string from */
- /* for table and code decoding */
- unsigned extra; /* extra bits needed */
- /* fixed and dynamic code tables */
- code const FAR *lencode; /* starting table for length/literal codes */
- code const FAR *distcode; /* starting table for distance codes */
- unsigned lenbits; /* index bits for lencode */
- unsigned distbits; /* index bits for distcode */
- /* dynamic table building */
- unsigned ncode; /* number of code length code lengths */
- unsigned nlen; /* number of length code lengths */
- unsigned ndist; /* number of distance code lengths */
- unsigned have; /* number of code lengths in lens[] */
- code FAR *next; /* next available space in codes[] */
- unsigned short lens[320]; /* temporary storage for code lengths */
- unsigned short work[288]; /* work area for code table building */
- code codes[ENOUGH]; /* space for code tables */
- int sane; /* if false, allow invalid distance too far */
- int back; /* bits back of last unprocessed length/lit */
- unsigned was; /* initial length of match */
-};
-
-const alloc_func = fn(opaque: &c_void, items: u16, size: u16);
-const free_func = fn(opaque: &c_void, address: &c_void);
-
-const z_stream = struct {
- /// next input byte
- next_in: &u8,
- /// number of bytes available at next_in
- avail_in: u16,
- /// total number of input bytes read so far
- total_in: u32,
-
- /// next output byte will go here
- next_out: &u8,
- /// remaining free space at next_out
- avail_out: u16,
- /// total number of bytes output so far */
- total_out: u32,
-
- /// last error message, NULL if no error
- msg: &const u8,
- /// not visible by applications
- state: &inflate_state,
-
- /// used to allocate the internal state
- zalloc: alloc_func,
- /// used to free the internal state
- zfree: free_func,
- /// private data object passed to zalloc and zfree
- opaque: &c_void,
-
- /// best guess about the data type: binary or text
- /// for deflate, or the decoding state for inflate
- data_type: i32,
-
- /// Adler-32 or CRC-32 value of the uncompressed data
- adler: u32,
-};
-
-// Possible inflate modes between inflate() calls
-/// i: waiting for magic header
-pub const HEAD = 16180;
-/// i: waiting for method and flags (gzip)
-pub const FLAGS = 16181;
-/// i: waiting for modification time (gzip)
-pub const TIME = 16182;
-/// i: waiting for extra flags and operating system (gzip)
-pub const OS = 16183;
-/// i: waiting for extra length (gzip)
-pub const EXLEN = 16184;
-/// i: waiting for extra bytes (gzip)
-pub const EXTRA = 16185;
-/// i: waiting for end of file name (gzip)
-pub const NAME = 16186;
-/// i: waiting for end of comment (gzip)
-pub const COMMENT = 16187;
-/// i: waiting for header crc (gzip)
-pub const HCRC = 16188;
-/// i: waiting for dictionary check value
-pub const DICTID = 16189;
-/// waiting for inflateSetDictionary() call
-pub const DICT = 16190;
-/// i: waiting for type bits, including last-flag bit
-pub const TYPE = 16191;
-/// i: same, but skip check to exit inflate on new block
-pub const TYPEDO = 16192;
-/// i: waiting for stored size (length and complement)
-pub const STORED = 16193;
-/// i/o: same as COPY below, but only first time in
-pub const COPY_ = 16194;
-/// i/o: waiting for input or output to copy stored block
-pub const COPY = 16195;
-/// i: waiting for dynamic block table lengths
-pub const TABLE = 16196;
-/// i: waiting for code length code lengths
-pub const LENLENS = 16197;
-/// i: waiting for length/lit and distance code lengths
-pub const CODELENS = 16198;
-/// i: same as LEN below, but only first time in
-pub const LEN_ = 16199;
-/// i: waiting for length/lit/eob code
-pub const LEN = 16200;
-/// i: waiting for length extra bits
-pub const LENEXT = 16201;
-/// i: waiting for distance code
-pub const DIST = 16202;
-/// i: waiting for distance extra bits
-pub const DISTEXT = 16203;
-/// o: waiting for output space to copy string
-pub const MATCH = 16204;
-/// o: waiting for output space to write literal
-pub const LIT = 16205;
-/// i: waiting for 32-bit check value
-pub const CHECK = 16206;
-/// i: waiting for 32-bit length (gzip)
-pub const LENGTH = 16207;
-/// finished check, done -- remain here until reset
-pub const DONE = 16208;
-/// got a data error -- remain here until reset
-pub const BAD = 16209;
-/// got an inflate() memory error -- remain here until reset
-pub const MEM = 16210;
-/// looking for synchronization bytes to restart inflate() */
-pub const SYNC = 16211;
-
-/// inflate() uses a state machine to process as much input data and generate as
-/// much output data as possible before returning. The state machine is
-/// structured roughly as follows:
-///
-/// for (;;) switch (state) {
-/// ...
-/// case STATEn:
-/// if (not enough input data or output space to make progress)
-/// return;
-/// ... make progress ...
-/// state = STATEm;
-/// break;
-/// ...
-/// }
-///
-/// so when inflate() is called again, the same case is attempted again, and
-/// if the appropriate resources are provided, the machine proceeds to the
-/// next state. The NEEDBITS() macro is usually the way the state evaluates
-/// whether it can proceed or should return. NEEDBITS() does the return if
-/// the requested bits are not available. The typical use of the BITS macros
-/// is:
-///
-/// NEEDBITS(n);
-/// ... do something with BITS(n) ...
-/// DROPBITS(n);
-///
-/// where NEEDBITS(n) either returns from inflate() if there isn't enough
-/// input left to load n bits into the accumulator, or it continues. BITS(n)
-/// gives the low n bits in the accumulator. When done, DROPBITS(n) drops
-/// the low n bits off the accumulator. INITBITS() clears the accumulator
-/// and sets the number of available bits to zero. BYTEBITS() discards just
-/// enough bits to put the accumulator on a byte boundary. After BYTEBITS()
-/// and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
-///
-/// NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
-/// if there is no input available. The decoding of variable length codes uses
-/// PULLBYTE() directly in order to pull just enough bytes to decode the next
-/// code, and no more.
-///
-/// Some states loop until they get enough input, making sure that enough
-/// state information is maintained to continue the loop where it left off
-/// if NEEDBITS() returns in the loop. For example, want, need, and keep
-/// would all have to actually be part of the saved state in case NEEDBITS()
-/// returns:
-///
-/// case STATEw:
-/// while (want < need) {
-/// NEEDBITS(n);
-/// keep[want++] = BITS(n);
-/// DROPBITS(n);
-/// }
-/// state = STATEx;
-/// case STATEx:
-///
-/// As shown above, if the next state is also the next case, then the break
-/// is omitted.
-///
-/// A state may also return if there is not enough output space available to
-/// complete that state. Those states are copying stored data, writing a
-/// literal byte, and copying a matching string.
-///
-/// When returning, a "goto inf_leave" is used to update the total counters,
-/// update the check value, and determine whether any progress has been made
-/// during that inflate() call in order to return the proper return code.
-/// Progress is defined as a change in either strm->avail_in or strm->avail_out.
-/// When there is a window, goto inf_leave will update the window with the last
-/// output written. If a goto inf_leave occurs in the middle of decompression
-/// and there is no window currently, goto inf_leave will create one and copy
-/// output to the window for the next call of inflate().
-///
-/// In this implementation, the flush parameter of inflate() only affects the
-/// return code (per zlib.h). inflate() always writes as much as possible to
-/// strm->next_out, given the space available and the provided input--the effect
-/// documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
-/// the allocation of and copying into a sliding window until necessary, which
-/// provides the effect documented in zlib.h for Z_FINISH when the entire input
-/// stream available. So the only thing the flush parameter actually does is:
-/// when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
-/// will return Z_BUF_ERROR if it has not reached the end of the stream.
-pub fn inflate(strm: &z_stream, flush: Flush, gunzip: bool) -> %void {
- // next input
- var next: &const u8 = undefined;
- // next output
- var put: &u8 = undefined;
-
- // available input and output
- var have: u16 = undefined;
- var left: u16 = undefined;
-
- // bit buffer
- var hold: u32 = undefined;
- // bits in bit buffer
- var bits: u16 = undefined;
- // save starting available input and output
- var in: u16 = undefined;
- var out: u16 = undefined;
- // number of stored or match bytes to copy
- var copy: u16 = undefined;
- // where to copy match bytes from
- var from: &u8 = undefined;
- // current decoding table entry
- var here: code = undefined;
- // parent table entry
- var last: code = undefined;
- // length to copy for repeats, bits to drop
- var len: u16 = undefined;
-
- // return code
- var ret: error = undefined;
-
- // buffer for gzip header crc calculation
- var hbuf: [4]u8 = undefined;
-
- // permutation of code lengths
- const short_order = []u16 = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
- if (inflateStateCheck(strm) or strm.next_out == Z_NULL or (strm.next_in == Z_NULL and strm.avail_in != 0)) {
- return error.Z_STREAM_ERROR;
- }
-
- var state: &inflate_state = strm.state;
- if (state.mode == TYPE) {
- state.mode = TYPEDO; // skip check
- }
- put = strm.next_out; \
- left = strm.avail_out; \
- next = strm.next_in; \
- have = strm.avail_in; \
- hold = state.hold; \
- bits = state.bits; \
- in = have;
- out = left;
- ret = Z_OK;
- for (;;)
- switch (state.mode) {
- case HEAD:
- if (state.wrap == 0) {
- state.mode = TYPEDO;
- break;
- }
- NEEDBITS(16);
-#ifdef GUNZIP
- if ((state.wrap & 2) && hold == 0x8b1f) { /* gzip header */
- if (state.wbits == 0)
- state.wbits = 15;
- state.check = crc32(0L, Z_NULL, 0);
- CRC2(state.check, hold);
- INITBITS();
- state.mode = FLAGS;
- break;
- }
- state.flags = 0; /* expect zlib header */
- if (state.head != Z_NULL)
- state.head.done = -1;
- if (!(state.wrap & 1) || /* check if zlib header allowed */
-#else
- if (
-#endif
- ((BITS(8) << 8) + (hold >> 8)) % 31) {
- strm.msg = (char *)"incorrect header check";
- state.mode = BAD;
- break;
- }
- if (BITS(4) != Z_DEFLATED) {
- strm.msg = (char *)"unknown compression method";
- state.mode = BAD;
- break;
- }
- DROPBITS(4);
- len = BITS(4) + 8;
- if (state.wbits == 0)
- state.wbits = len;
- if (len > 15 || len > state.wbits) {
- strm.msg = (char *)"invalid window size";
- state.mode = BAD;
- break;
- }
- state.dmax = 1U << len;
- Tracev((stderr, "inflate: zlib header ok\n"));
- strm.adler = state.check = adler32(0L, Z_NULL, 0);
- state.mode = hold & 0x200 ? DICTID : TYPE;
- INITBITS();
- break;
-#ifdef GUNZIP
- case FLAGS:
- NEEDBITS(16);
- state.flags = (int)(hold);
- if ((state.flags & 0xff) != Z_DEFLATED) {
- strm.msg = (char *)"unknown compression method";
- state.mode = BAD;
- break;
- }
- if (state.flags & 0xe000) {
- strm.msg = (char *)"unknown header flags set";
- state.mode = BAD;
- break;
- }
- if (state.head != Z_NULL)
- state.head.text = (int)((hold >> 8) & 1);
- if ((state.flags & 0x0200) && (state.wrap & 4))
- CRC2(state.check, hold);
- INITBITS();
- state.mode = TIME;
- case TIME:
- NEEDBITS(32);
- if (state.head != Z_NULL)
- state.head.time = hold;
- if ((state.flags & 0x0200) && (state.wrap & 4))
- CRC4(state.check, hold);
- INITBITS();
- state.mode = OS;
- case OS:
- NEEDBITS(16);
- if (state.head != Z_NULL) {
- state.head.xflags = (int)(hold & 0xff);
- state.head.os = (int)(hold >> 8);
- }
- if ((state.flags & 0x0200) && (state.wrap & 4))
- CRC2(state.check, hold);
- INITBITS();
- state.mode = EXLEN;
- case EXLEN:
- if (state.flags & 0x0400) {
- NEEDBITS(16);
- state.length = (unsigned)(hold);
- if (state.head != Z_NULL)
- state.head.extra_len = (unsigned)hold;
- if ((state.flags & 0x0200) && (state.wrap & 4))
- CRC2(state.check, hold);
- INITBITS();
- }
- else if (state.head != Z_NULL)
- state.head.extra = Z_NULL;
- state.mode = EXTRA;
- case EXTRA:
- if (state.flags & 0x0400) {
- copy = state.length;
- if (copy > have) copy = have;
- if (copy) {
- if (state.head != Z_NULL &&
- state.head.extra != Z_NULL) {
- len = state.head.extra_len - state.length;
- zmemcpy(state.head.extra + len, next,
- len + copy > state.head.extra_max ?
- state.head.extra_max - len : copy);
- }
- if ((state.flags & 0x0200) && (state.wrap & 4))
- state.check = crc32(state.check, next, copy);
- have -= copy;
- next += copy;
- state.length -= copy;
- }
- if (state.length) goto inf_leave;
- }
- state.length = 0;
- state.mode = NAME;
- case NAME:
- if (state.flags & 0x0800) {
- if (have == 0) goto inf_leave;
- copy = 0;
- do {
- len = (unsigned)(next[copy++]);
- if (state.head != Z_NULL &&
- state.head.name != Z_NULL &&
- state.length < state.head.name_max)
- state.head.name[state.length++] = (Bytef)len;
- } while (len && copy < have);
- if ((state.flags & 0x0200) && (state.wrap & 4))
- state.check = crc32(state.check, next, copy);
- have -= copy;
- next += copy;
- if (len) goto inf_leave;
- }
- else if (state.head != Z_NULL)
- state.head.name = Z_NULL;
- state.length = 0;
- state.mode = COMMENT;
- case COMMENT:
- if (state.flags & 0x1000) {
- if (have == 0) goto inf_leave;
- copy = 0;
- do {
- len = (unsigned)(next[copy++]);
- if (state.head != Z_NULL &&
- state.head.comment != Z_NULL &&
- state.length < state.head.comm_max)
- state.head.comment[state.length++] = (Bytef)len;
- } while (len && copy < have);
- if ((state.flags & 0x0200) && (state.wrap & 4))
- state.check = crc32(state.check, next, copy);
- have -= copy;
- next += copy;
- if (len) goto inf_leave;
- }
- else if (state.head != Z_NULL)
- state.head.comment = Z_NULL;
- state.mode = HCRC;
- case HCRC:
- if (state.flags & 0x0200) {
- NEEDBITS(16);
- if ((state.wrap & 4) && hold != (state.check & 0xffff)) {
- strm.msg = (char *)"header crc mismatch";
- state.mode = BAD;
- break;
- }
- INITBITS();
- }
- if (state.head != Z_NULL) {
- state.head.hcrc = (int)((state.flags >> 9) & 1);
- state.head.done = 1;
- }
- strm.adler = state.check = crc32(0L, Z_NULL, 0);
- state.mode = TYPE;
- break;
-#endif
- case DICTID:
- NEEDBITS(32);
- strm.adler = state.check = ZSWAP32(hold);
- INITBITS();
- state.mode = DICT;
- case DICT:
- if (state.havedict == 0) {
- strm.next_out = put; \
- strm.avail_out = left; \
- strm.next_in = next; \
- strm.avail_in = have; \
- state.hold = hold; \
- state.bits = bits; \
- return Z_NEED_DICT;
- }
- strm.adler = state.check = adler32(0L, Z_NULL, 0);
- state.mode = TYPE;
- case TYPE:
- if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
- case TYPEDO:
- if (state.last) {
- BYTEBITS();
- state.mode = CHECK;
- break;
- }
- NEEDBITS(3);
- state.last = BITS(1);
- DROPBITS(1);
- switch (BITS(2)) {
- case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
- state.last ? " (last)" : ""));
- state.mode = STORED;
- break;
- case 1: /* fixed block */
- fixedtables(state);
- Tracev((stderr, "inflate: fixed codes block%s\n",
- state.last ? " (last)" : ""));
- state.mode = LEN_; /* decode codes */
- if (flush == Z_TREES) {
- DROPBITS(2);
- goto inf_leave;
- }
- break;
- case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
- state.last ? " (last)" : ""));
- state.mode = TABLE;
- break;
- case 3:
- strm.msg = (char *)"invalid block type";
- state.mode = BAD;
- }
- DROPBITS(2);
- break;
- case STORED:
- BYTEBITS(); /* go to byte boundary */
- NEEDBITS(32);
- if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
- strm.msg = (char *)"invalid stored block lengths";
- state.mode = BAD;
- break;
- }
- state.length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %u\n",
- state.length));
- INITBITS();
- state.mode = COPY_;
- if (flush == Z_TREES) goto inf_leave;
- case COPY_:
- state.mode = COPY;
- case COPY:
- copy = state.length;
- if (copy) {
- if (copy > have) copy = have;
- if (copy > left) copy = left;
- if (copy == 0) goto inf_leave;
- zmemcpy(put, next, copy);
- have -= copy;
- next += copy;
- left -= copy;
- put += copy;
- state.length -= copy;
- break;
- }
- Tracev((stderr, "inflate: stored end\n"));
- state.mode = TYPE;
- break;
- case TABLE:
- NEEDBITS(14);
- state.nlen = BITS(5) + 257;
- DROPBITS(5);
- state.ndist = BITS(5) + 1;
- DROPBITS(5);
- state.ncode = BITS(4) + 4;
- DROPBITS(4);
-#ifndef PKZIP_BUG_WORKAROUND
- if (state.nlen > 286 || state.ndist > 30) {
- strm.msg = (char *)"too many length or distance symbols";
- state.mode = BAD;
- break;
- }
-#endif
- Tracev((stderr, "inflate: table sizes ok\n"));
- state.have = 0;
- state.mode = LENLENS;
- case LENLENS:
- while (state.have < state.ncode) {
- NEEDBITS(3);
- state.lens[order[state.have++]] = (unsigned short)BITS(3);
- DROPBITS(3);
- }
- while (state.have < 19)
- state.lens[order[state.have++]] = 0;
- state.next = state.codes;
- state.lencode = (const code FAR *)(state.next);
- state.lenbits = 7;
- ret = inflate_table(CODES, state.lens, 19, &(state.next),
- &(state.lenbits), state.work);
- if (ret) {
- strm.msg = (char *)"invalid code lengths set";
- state.mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: code lengths ok\n"));
- state.have = 0;
- state.mode = CODELENS;
- case CODELENS:
- while (state.have < state.nlen + state.ndist) {
- for (;;) {
- here = state.lencode[BITS(state.lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if (here.val < 16) {
- DROPBITS(here.bits);
- state.lens[state.have++] = here.val;
- }
- else {
- if (here.val == 16) {
- NEEDBITS(here.bits + 2);
- DROPBITS(here.bits);
- if (state.have == 0) {
- strm.msg = (char *)"invalid bit length repeat";
- state.mode = BAD;
- break;
- }
- len = state.lens[state.have - 1];
- copy = 3 + BITS(2);
- DROPBITS(2);
- }
- else if (here.val == 17) {
- NEEDBITS(here.bits + 3);
- DROPBITS(here.bits);
- len = 0;
- copy = 3 + BITS(3);
- DROPBITS(3);
- }
- else {
- NEEDBITS(here.bits + 7);
- DROPBITS(here.bits);
- len = 0;
- copy = 11 + BITS(7);
- DROPBITS(7);
- }
- if (state.have + copy > state.nlen + state.ndist) {
- strm.msg = (char *)"invalid bit length repeat";
- state.mode = BAD;
- break;
- }
- while (copy--)
- state.lens[state.have++] = (unsigned short)len;
- }
- }
-
- /* handle error breaks in while */
- if (state.mode == BAD) break;
-
- /* check for end-of-block code (better have one) */
- if (state.lens[256] == 0) {
- strm.msg = (char *)"invalid code -- missing end-of-block";
- state.mode = BAD;
- break;
- }
-
- /* build code tables -- note: do not change the lenbits or distbits
- values here (9 and 6) without reading the comments in inftrees.h
- concerning the ENOUGH constants, which depend on those values */
- state.next = state.codes;
- state.lencode = (const code FAR *)(state.next);
- state.lenbits = 9;
- ret = inflate_table(LENS, state.lens, state.nlen, &(state.next),
- &(state.lenbits), state.work);
- if (ret) {
- strm.msg = (char *)"invalid literal/lengths set";
- state.mode = BAD;
- break;
- }
- state.distcode = (const code FAR *)(state.next);
- state.distbits = 6;
- ret = inflate_table(DISTS, state.lens + state.nlen, state.ndist,
- &(state.next), &(state.distbits), state.work);
- if (ret) {
- strm.msg = (char *)"invalid distances set";
- state.mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: codes ok\n"));
- state.mode = LEN_;
- if (flush == Z_TREES) goto inf_leave;
- case LEN_:
- state.mode = LEN;
- case LEN:
- if (have >= 6 && left >= 258) {
- strm.next_out = put; \
- strm.avail_out = left; \
- strm.next_in = next; \
- strm.avail_in = have; \
- state.hold = hold; \
- state.bits = bits; \
-
- inflate_fast(strm, out);
-
- put = strm.next_out; \
- left = strm.avail_out; \
- next = strm.next_in; \
- have = strm.avail_in; \
- hold = state.hold; \
- bits = state.bits; \
- if (state.mode == TYPE)
- state.back = -1;
- break;
- }
- state.back = 0;
- for (;;) {
- here = state.lencode[BITS(state.lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if (here.op && (here.op & 0xf0) == 0) {
- last = here;
- for (;;) {
- here = state.lencode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
- PULLBYTE();
- }
- DROPBITS(last.bits);
- state.back += last.bits;
- }
- DROPBITS(here.bits);
- state.back += here.bits;
- state.length = (unsigned)here.val;
- if ((int)(here.op) == 0) {
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
- "inflate: literal '%c'\n" :
- "inflate: literal 0x%02x\n", here.val));
- state.mode = LIT;
- break;
- }
- if (here.op & 32) {
- Tracevv((stderr, "inflate: end of block\n"));
- state.back = -1;
- state.mode = TYPE;
- break;
- }
- if (here.op & 64) {
- strm.msg = (char *)"invalid literal/length code";
- state.mode = BAD;
- break;
- }
- state.extra = (unsigned)(here.op) & 15;
- state.mode = LENEXT;
- case LENEXT:
- if (state.extra) {
- NEEDBITS(state.extra);
- state.length += BITS(state.extra);
- DROPBITS(state.extra);
- state.back += state.extra;
- }
- Tracevv((stderr, "inflate: length %u\n", state.length));
- state.was = state.length;
- state.mode = DIST;
- case DIST:
- for (;;) {
- here = state.distcode[BITS(state.distbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if ((here.op & 0xf0) == 0) {
- last = here;
- for (;;) {
- here = state.distcode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
- PULLBYTE();
- }
- DROPBITS(last.bits);
- state.back += last.bits;
- }
- DROPBITS(here.bits);
- state.back += here.bits;
- if (here.op & 64) {
- strm.msg = (char *)"invalid distance code";
- state.mode = BAD;
- break;
- }
- state.offset = (unsigned)here.val;
- state.extra = (unsigned)(here.op) & 15;
- state.mode = DISTEXT;
- case DISTEXT:
- if (state.extra) {
- NEEDBITS(state.extra);
- state.offset += BITS(state.extra);
- DROPBITS(state.extra);
- state.back += state.extra;
- }
-#ifdef INFLATE_STRICT
- if (state.offset > state.dmax) {
- strm.msg = (char *)"invalid distance too far back";
- state.mode = BAD;
- break;
- }
-#endif
- Tracevv((stderr, "inflate: distance %u\n", state.offset));
- state.mode = MATCH;
- case MATCH:
- if (left == 0) goto inf_leave;
- copy = out - left;
- if (state.offset > copy) { /* copy from window */
- copy = state.offset - copy;
- if (copy > state.whave) {
- if (state.sane) {
- strm.msg = (char *)"invalid distance too far back";
- state.mode = BAD;
- break;
- }
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- Trace((stderr, "inflate.c too far\n"));
- copy -= state.whave;
- if (copy > state.length) copy = state.length;
- if (copy > left) copy = left;
- left -= copy;
- state.length -= copy;
- do {
- *put++ = 0;
- } while (--copy);
- if (state.length == 0) state.mode = LEN;
- break;
-#endif
- }
- if (copy > state.wnext) {
- copy -= state.wnext;
- from = state.window + (state.wsize - copy);
- }
- else
- from = state.window + (state.wnext - copy);
- if (copy > state.length) copy = state.length;
- }
- else { /* copy from output */
- from = put - state.offset;
- copy = state.length;
- }
- if (copy > left) copy = left;
- left -= copy;
- state.length -= copy;
- do {
- *put++ = *from++;
- } while (--copy);
- if (state.length == 0) state.mode = LEN;
- break;
- case LIT:
- if (left == 0) goto inf_leave;
- *put++ = (u8)(state.length);
- left--;
- state.mode = LEN;
- break;
- case CHECK:
- if (state.wrap) {
- NEEDBITS(32);
- out -= left;
- strm.total_out += out;
- state.total += out;
- if ((state.wrap & 4) && out)
- strm.adler = state.check =
- UPDATE(state.check, put - out, out);
- out = left;
- if ((state.wrap & 4) && (
-#ifdef GUNZIP
- state.flags ? hold :
-#endif
- ZSWAP32(hold)) != state.check) {
- strm.msg = (char *)"incorrect data check";
- state.mode = BAD;
- break;
- }
- INITBITS();
- Tracev((stderr, "inflate: check matches trailer\n"));
- }
-#ifdef GUNZIP
- state.mode = LENGTH;
- case LENGTH:
- if (state.wrap && state.flags) {
- NEEDBITS(32);
- if (hold != (state.total & 0xffffffffUL)) {
- strm.msg = (char *)"incorrect length check";
- state.mode = BAD;
- break;
- }
- INITBITS();
- Tracev((stderr, "inflate: length matches trailer\n"));
- }
-#endif
- state.mode = DONE;
- case DONE:
- ret = Z_STREAM_END;
- goto inf_leave;
- case BAD:
- ret = Z_DATA_ERROR;
- goto inf_leave;
- case MEM:
- return Z_MEM_ERROR;
- case SYNC:
- default:
- return Z_STREAM_ERROR;
- }
-
- /*
- Return from inflate(), updating the total counts and the check value.
- If there was no progress during the inflate() call, return a buffer
- error. Call updatewindow() to create and/or update the window state.
- Note: a memory error from inflate() is non-recoverable.
- */
- inf_leave:
- strm.next_out = put; \
- strm.avail_out = left; \
- strm.next_in = next; \
- strm.avail_in = have; \
- state.hold = hold; \
- state.bits = bits; \
- if (state.wsize || (out != strm.avail_out && state.mode < BAD &&
- (state.mode < CHECK || flush != Z_FINISH)))
- if (updatewindow(strm, strm.next_out, out - strm.avail_out)) {
- state.mode = MEM;
- return Z_MEM_ERROR;
- }
- in -= strm.avail_in;
- out -= strm.avail_out;
- strm.total_in += in;
- strm.total_out += out;
- state.total += out;
- if ((state.wrap & 4) && out)
- strm.adler = state.check =
- UPDATE(state.check, strm.next_out - out, out);
- strm.data_type = (int)state.bits + (state.last ? 64 : 0) +
- (state.mode == TYPE ? 128 : 0) +
- (state.mode == LEN_ || state.mode == COPY_ ? 256 : 0);
- if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
- ret = Z_BUF_ERROR;
- return ret;
-}
-
-local int inflateStateCheck(z_stream * strm) {
- struct inflate_state FAR *state;
- if (strm == Z_NULL ||
- strm.zalloc == (alloc_func)0 || strm.zfree == (free_func)0)
- return 1;
- state = (struct inflate_state FAR *)strm.state;
- if (state == Z_NULL || state.strm != strm ||
- state.mode < HEAD || state.mode > SYNC)
- return 1;
- return 0;
-}
diff --git a/test/assemble_and_link.zig b/test/assemble_and_link.zig
index 2433637ef6..2593f3306a 100644
--- a/test/assemble_and_link.zig
+++ b/test/assemble_and_link.zig
@@ -1,7 +1,7 @@
const builtin = @import("builtin");
const tests = @import("tests.zig");
-pub fn addCases(cases: &tests.CompareOutputContext) {
+pub fn addCases(cases: &tests.CompareOutputContext) void {
if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
cases.addAsm("hello world linux x86_64",
\\.text
diff --git a/test/build_examples.zig b/test/build_examples.zig
index 666dac8df1..b0d939006a 100644
--- a/test/build_examples.zig
+++ b/test/build_examples.zig
@@ -2,7 +2,7 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
const is_windows = builtin.os == builtin.Os.windows;
-pub fn addCases(cases: &tests.BuildExamplesContext) {
+pub fn addCases(cases: &tests.BuildExamplesContext) void {
cases.add("example/hello_world/hello.zig");
cases.addC("example/hello_world/hello_libc.zig");
cases.add("example/cat/main.zig");
diff --git a/test/cases/align.zig b/test/cases/align.zig
index 3105945e04..ad3a66a2e0 100644
--- a/test/cases/align.zig
+++ b/test/cases/align.zig
@@ -10,14 +10,14 @@ test "global variable alignment" {
assert(@typeOf(slice) == []align(4) u8);
}
-fn derp() align(@sizeOf(usize) * 2) -> i32 { return 1234; }
-fn noop1() align(1) {}
-fn noop4() align(4) {}
+fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
+fn noop1() align(1) void {}
+fn noop4() align(4) void {}
test "function alignment" {
assert(derp() == 1234);
- assert(@typeOf(noop1) == fn() align(1));
- assert(@typeOf(noop4) == fn() align(4));
+ assert(@typeOf(noop1) == fn() align(1) void);
+ assert(@typeOf(noop4) == fn() align(4) void);
noop1();
noop4();
}
@@ -53,19 +53,19 @@ test "implicitly decreasing pointer alignment" {
assert(addUnaligned(&a, &b) == 7);
}
-fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) -> u32 { return *a + *b; }
+fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) u32 { return *a + *b; }
test "implicitly decreasing slice alignment" {
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7);
}
-fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) -> u32 { return a[0] + b[0]; }
+fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { return a[0] + b[0]; }
test "specifying alignment allows pointer cast" {
testBytesAlign(0x33);
}
-fn testBytesAlign(b: u8) {
+fn testBytesAlign(b: u8) void {
var bytes align(4) = []u8{b, b, b, b};
const ptr = @ptrCast(&u32, &bytes[0]);
assert(*ptr == 0x33333333);
@@ -74,7 +74,7 @@ fn testBytesAlign(b: u8) {
test "specifying alignment allows slice cast" {
testBytesAlignSlice(0x33);
}
-fn testBytesAlignSlice(b: u8) {
+fn testBytesAlignSlice(b: u8) void {
var bytes align(4) = []u8{b, b, b, b};
const slice = ([]u32)(bytes[0..]);
assert(slice[0] == 0x33333333);
@@ -85,10 +85,10 @@ test "@alignCast pointers" {
expectsOnly1(&x);
assert(x == 2);
}
-fn expectsOnly1(x: &align(1) u32) {
+fn expectsOnly1(x: &align(1) u32) void {
expects4(@alignCast(4, x));
}
-fn expects4(x: &align(4) u32) {
+fn expects4(x: &align(4) u32) void {
*x += 1;
}
@@ -98,10 +98,10 @@ test "@alignCast slices" {
sliceExpectsOnly1(slice);
assert(slice[0] == 2);
}
-fn sliceExpectsOnly1(slice: []align(1) u32) {
+fn sliceExpectsOnly1(slice: []align(1) u32) void {
sliceExpects4(@alignCast(4, slice));
}
-fn sliceExpects4(slice: []align(4) u32) {
+fn sliceExpects4(slice: []align(4) u32) void {
slice[0] += 1;
}
@@ -111,24 +111,24 @@ test "implicitly decreasing fn alignment" {
testImplicitlyDecreaseFnAlign(alignedBig, 5678);
}
-fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) {
+fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
assert(ptr() == answer);
}
-fn alignedSmall() align(8) -> i32 { return 1234; }
-fn alignedBig() align(16) -> i32 { return 5678; }
+fn alignedSmall() align(8) i32 { return 1234; }
+fn alignedBig() align(16) i32 { return 5678; }
test "@alignCast functions" {
assert(fnExpectsOnly1(simple4) == 0x19);
}
-fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 {
+fn fnExpectsOnly1(ptr: fn()align(1) i32) i32 {
return fnExpects4(@alignCast(4, ptr));
}
-fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 {
+fn fnExpects4(ptr: fn()align(4) i32) i32 {
return ptr();
}
-fn simple4() align(4) -> i32 { return 0x19; }
+fn simple4() align(4) i32 { return 0x19; }
test "generic function with align param" {
@@ -137,7 +137,7 @@ test "generic function with align param" {
assert(whyWouldYouEverDoThis(8) == 0x1);
}
-fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) -> u8 { return 0x1; }
+fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { return 0x1; }
test "@ptrCast preserves alignment of bigger source" {
@@ -175,10 +175,10 @@ test "compile-time known array index has best alignment possible" {
testIndex2(&array[0], 2, &u8);
testIndex2(&array[0], 3, &u8);
}
-fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) {
+fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) void {
assert(@typeOf(&smaller[index]) == T);
}
-fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) {
+fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) void {
assert(@typeOf(&ptr[index]) == T);
}
@@ -187,7 +187,7 @@ test "alignstack" {
assert(fnWithAlignedStack() == 1234);
}
-fn fnWithAlignedStack() -> i32 {
+fn fnWithAlignedStack() i32 {
@setAlignStack(256);
return 1234;
}
diff --git a/test/cases/array.zig b/test/cases/array.zig
index bf77e51fee..577161dd16 100644
--- a/test/cases/array.zig
+++ b/test/cases/array.zig
@@ -21,7 +21,7 @@ test "arrays" {
assert(accumulator == 15);
assert(getArrayLen(array) == 5);
}
-fn getArrayLen(a: []const u32) -> usize {
+fn getArrayLen(a: []const u32) usize {
return a.len;
}
diff --git a/test/cases/asm.zig b/test/cases/asm.zig
index 8a3020fe23..1c4208f403 100644
--- a/test/cases/asm.zig
+++ b/test/cases/asm.zig
@@ -17,8 +17,8 @@ test "module level assembly" {
}
}
-extern fn aoeu() -> i32;
+extern fn aoeu() i32;
-export fn derp() -> i32 {
+export fn derp() i32 {
return 1234;
}
diff --git a/test/cases/bitcast.zig b/test/cases/bitcast.zig
index 0a92d9d606..f1f2ccd672 100644
--- a/test/cases/bitcast.zig
+++ b/test/cases/bitcast.zig
@@ -5,10 +5,10 @@ test "@bitCast i32 -> u32" {
comptime testBitCast_i32_u32();
}
-fn testBitCast_i32_u32() {
+fn testBitCast_i32_u32() void {
assert(conv(-1) == @maxValue(u32));
assert(conv2(@maxValue(u32)) == -1);
}
-fn conv(x: i32) -> u32 { return @bitCast(u32, x); }
-fn conv2(x: u32) -> i32 { return @bitCast(i32, x); }
+fn conv(x: i32) u32 { return @bitCast(u32, x); }
+fn conv2(x: u32) i32 { return @bitCast(i32, x); }
diff --git a/test/cases/bool.zig b/test/cases/bool.zig
index 1203e696ba..07d30454ee 100644
--- a/test/cases/bool.zig
+++ b/test/cases/bool.zig
@@ -13,7 +13,7 @@ test "cast bool to int" {
nonConstCastBoolToInt(t, f);
}
-fn nonConstCastBoolToInt(t: bool, f: bool) {
+fn nonConstCastBoolToInt(t: bool, f: bool) void {
assert(i32(t) == i32(1));
assert(i32(f) == i32(0));
}
@@ -21,7 +21,7 @@ fn nonConstCastBoolToInt(t: bool, f: bool) {
test "bool cmp" {
assert(testBoolCmp(true, false) == false);
}
-fn testBoolCmp(a: bool, b: bool) -> bool {
+fn testBoolCmp(a: bool, b: bool) bool {
return a == b;
}
diff --git a/test/cases/bugs/655.zig b/test/cases/bugs/655.zig
index a0da9d53a2..e6a275004c 100644
--- a/test/cases/bugs/655.zig
+++ b/test/cases/bugs/655.zig
@@ -7,6 +7,6 @@ test "function with &const parameter with type dereferenced by namespace" {
foo(x);
}
-fn foo(x: &const other_file.Integer) {
+fn foo(x: &const other_file.Integer) void {
std.debug.assert(*x == 1234);
}
diff --git a/test/cases/bugs/656.zig b/test/cases/bugs/656.zig
index 70000c9efd..ce3eec8046 100644
--- a/test/cases/bugs/656.zig
+++ b/test/cases/bugs/656.zig
@@ -13,7 +13,7 @@ test "nullable if after an if in a switch prong of a switch with 2 prongs in an
foo(false, true);
}
-fn foo(a: bool, b: bool) {
+fn foo(a: bool, b: bool) void {
var prefix_op = PrefixOp { .AddrOf = Value { .align_expr = 1234 } };
if (a) {
} else {
diff --git a/test/cases/cast.zig b/test/cases/cast.zig
index 673c5891e3..2455179c89 100644
--- a/test/cases/cast.zig
+++ b/test/cases/cast.zig
@@ -28,7 +28,7 @@ test "implicitly cast a pointer to a const pointer of it" {
assert(x == 2);
}
-fn funcWithConstPtrPtr(x: &const &i32) {
+fn funcWithConstPtrPtr(x: &const &i32) void {
**x += 1;
}
@@ -37,7 +37,7 @@ test "explicit cast from integer to error type" {
testCastIntToErr(error.ItBroke);
comptime testCastIntToErr(error.ItBroke);
}
-fn testCastIntToErr(err: error) {
+fn testCastIntToErr(err: error) void {
const x = usize(err);
const y = error(x);
assert(error.ItBroke == y);
@@ -49,7 +49,7 @@ test "peer resolve arrays of different size to const slice" {
comptime assert(mem.eql(u8, boolToStr(true), "true"));
comptime assert(mem.eql(u8, boolToStr(false), "false"));
}
-fn boolToStr(b: bool) -> []const u8 {
+fn boolToStr(b: bool) []const u8 {
return if (b) "true" else "false";
}
@@ -58,7 +58,7 @@ test "peer resolve array and const slice" {
testPeerResolveArrayConstSlice(true);
comptime testPeerResolveArrayConstSlice(true);
}
-fn testPeerResolveArrayConstSlice(b: bool) {
+fn testPeerResolveArrayConstSlice(b: bool) void {
const value1 = if (b) "aoeu" else ([]const u8)("zz");
const value2 = if (b) ([]const u8)("zz") else "aoeu";
assert(mem.eql(u8, value1, "aoeu"));
@@ -82,7 +82,7 @@ test "implicitly cast from T to %?T" {
const A = struct {
a: i32,
};
-fn castToMaybeTypeError(z: i32) {
+fn castToMaybeTypeError(z: i32) void {
const x = i32(1);
const y: %?i32 = x;
assert(??(try y) == 1);
@@ -99,22 +99,22 @@ test "implicitly cast from int to %?T" {
implicitIntLitToMaybe();
comptime implicitIntLitToMaybe();
}
-fn implicitIntLitToMaybe() {
+fn implicitIntLitToMaybe() void {
const f: ?i32 = 1;
const g: %?i32 = 1;
}
-test "return null from fn() -> %?&T" {
+test "return null from fn() %?&T" {
const a = returnNullFromMaybeTypeErrorRef();
const b = returnNullLitFromMaybeTypeErrorRef();
assert((try a) == null and (try b) == null);
}
-fn returnNullFromMaybeTypeErrorRef() -> %?&A {
+fn returnNullFromMaybeTypeErrorRef() %?&A {
const a: ?&A = null;
return a;
}
-fn returnNullLitFromMaybeTypeErrorRef() -> %?&A {
+fn returnNullLitFromMaybeTypeErrorRef() %?&A {
return null;
}
@@ -126,7 +126,7 @@ test "peer type resolution: ?T and T" {
assert(??peerTypeTAndMaybeT(false, false) == 3);
}
}
-fn peerTypeTAndMaybeT(c: bool, b: bool) -> ?usize {
+fn peerTypeTAndMaybeT(c: bool, b: bool) ?usize {
if (c) {
return if (b) null else usize(0);
}
@@ -143,7 +143,7 @@ test "peer type resolution: [0]u8 and []const u8" {
assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
}
}
-fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) -> []const u8 {
+fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
if (a) {
return []const u8 {};
}
@@ -156,7 +156,7 @@ test "implicitly cast from [N]T to ?[]const T" {
comptime assert(mem.eql(u8, ??castToMaybeSlice(), "hi"));
}
-fn castToMaybeSlice() -> ?[]const u8 {
+fn castToMaybeSlice() ?[]const u8 {
return "hi";
}
@@ -166,11 +166,11 @@ test "implicitly cast from [0]T to %[]T" {
comptime testCastZeroArrayToErrSliceMut();
}
-fn testCastZeroArrayToErrSliceMut() {
+fn testCastZeroArrayToErrSliceMut() void {
assert((gimmeErrOrSlice() catch unreachable).len == 0);
}
-fn gimmeErrOrSlice() -> %[]u8 {
+fn gimmeErrOrSlice() %[]u8 {
return []u8{};
}
@@ -188,7 +188,7 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" {
assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
}
}
-fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
+fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) %[]u8 {
if (a) {
return []u8{};
}
@@ -200,7 +200,7 @@ test "resolve undefined with integer" {
testResolveUndefWithInt(true, 1234);
comptime testResolveUndefWithInt(true, 1234);
}
-fn testResolveUndefWithInt(b: bool, x: i32) {
+fn testResolveUndefWithInt(b: bool, x: i32) void {
const value = if (b) x else undefined;
if (b) {
assert(value == x);
@@ -212,7 +212,7 @@ test "implicit cast from &const [N]T to []const T" {
comptime testCastConstArrayRefToConstSlice();
}
-fn testCastConstArrayRefToConstSlice() {
+fn testCastConstArrayRefToConstSlice() void {
const blah = "aoeu";
const const_array_ref = &blah;
assert(@typeOf(const_array_ref) == &const [4]u8);
@@ -224,7 +224,7 @@ test "var args implicitly casts by value arg to const ref" {
foo("hello");
}
-fn foo(args: ...) {
+fn foo(args: ...) void {
assert(@typeOf(args[0]) == &const [5]u8);
}
@@ -239,13 +239,13 @@ test "peer type resolution: error and [N]T" {
}
error BadValue;
-//fn testPeerErrorAndArray(x: u8) -> %[]const u8 {
+//fn testPeerErrorAndArray(x: u8) %[]const u8 {
// return switch (x) {
// 0x00 => "OK",
// else => error.BadValue,
// };
//}
-fn testPeerErrorAndArray2(x: u8) -> %[]const u8 {
+fn testPeerErrorAndArray2(x: u8) %[]const u8 {
return switch (x) {
0x00 => "OK",
0x01 => "OKK",
@@ -265,15 +265,15 @@ test "cast u128 to f128 and back" {
testCast128();
}
-fn testCast128() {
+fn testCast128() void {
assert(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
}
-fn cast128Int(x: f128) -> u128 {
+fn cast128Int(x: f128) u128 {
return @bitCast(u128, x);
}
-fn cast128Float(x: u128) -> f128 {
+fn cast128Float(x: u128) f128 {
return @bitCast(f128, x);
}
diff --git a/test/cases/const_slice_child.zig b/test/cases/const_slice_child.zig
index 4b7905ec97..456b115234 100644
--- a/test/cases/const_slice_child.zig
+++ b/test/cases/const_slice_child.zig
@@ -13,14 +13,14 @@ test "const slice child" {
bar(strs.len);
}
-fn foo(args: [][]const u8) {
+fn foo(args: [][]const u8) void {
assert(args.len == 3);
assert(streql(args[0], "one"));
assert(streql(args[1], "two"));
assert(streql(args[2], "three"));
}
-fn bar(argc: usize) {
+fn bar(argc: usize) void {
const args = debug.global_allocator.alloc([]const u8, argc) catch unreachable;
for (args) |_, i| {
const ptr = argv[i];
@@ -29,13 +29,13 @@ fn bar(argc: usize) {
foo(args);
}
-fn strlen(ptr: &const u8) -> usize {
+fn strlen(ptr: &const u8) usize {
var count: usize = 0;
while (ptr[count] != 0) : (count += 1) {}
return count;
}
-fn streql(a: []const u8, b: []const u8) -> bool {
+fn streql(a: []const u8, b: []const u8) bool {
if (a.len != b.len) return false;
for (a) |item, index| {
if (b[index] != item) return false;
diff --git a/test/cases/defer.zig b/test/cases/defer.zig
index 4fefce0389..6490ec0acd 100644
--- a/test/cases/defer.zig
+++ b/test/cases/defer.zig
@@ -5,7 +5,7 @@ var index: usize = undefined;
error FalseNotAllowed;
-fn runSomeErrorDefers(x: bool) -> %bool {
+fn runSomeErrorDefers(x: bool) %bool {
index = 0;
defer {result[index] = 'a'; index += 1;}
errdefer {result[index] = 'b'; index += 1;}
@@ -33,7 +33,7 @@ test "break and continue inside loop inside defer expression" {
comptime testBreakContInDefer(10);
}
-fn testBreakContInDefer(x: usize) {
+fn testBreakContInDefer(x: usize) void {
defer {
var i: usize = 0;
while (i < x) : (i += 1) {
diff --git a/test/cases/enum.zig b/test/cases/enum.zig
index 6f0f1c4730..8020e593f8 100644
--- a/test/cases/enum.zig
+++ b/test/cases/enum.zig
@@ -40,7 +40,7 @@ const Bar = enum {
D,
};
-fn returnAnInt(x: i32) -> Foo {
+fn returnAnInt(x: i32) Foo {
return Foo { .One = x };
}
@@ -52,14 +52,14 @@ test "constant enum with payload" {
shouldBeNotEmpty(full);
}
-fn shouldBeEmpty(x: &const AnEnumWithPayload) {
+fn shouldBeEmpty(x: &const AnEnumWithPayload) void {
switch (*x) {
AnEnumWithPayload.Empty => {},
else => unreachable,
}
}
-fn shouldBeNotEmpty(x: &const AnEnumWithPayload) {
+fn shouldBeNotEmpty(x: &const AnEnumWithPayload) void {
switch (*x) {
AnEnumWithPayload.Empty => unreachable,
else => {},
@@ -89,7 +89,7 @@ test "enum to int" {
shouldEqual(Number.Four, 4);
}
-fn shouldEqual(n: Number, expected: u3) {
+fn shouldEqual(n: Number, expected: u3) void {
assert(u3(n) == expected);
}
@@ -97,7 +97,7 @@ fn shouldEqual(n: Number, expected: u3) {
test "int to enum" {
testIntToEnumEval(3);
}
-fn testIntToEnumEval(x: i32) {
+fn testIntToEnumEval(x: i32) void {
assert(IntToEnumNumber(u3(x)) == IntToEnumNumber.Three);
}
const IntToEnumNumber = enum {
@@ -114,7 +114,7 @@ test "@tagName" {
comptime assert(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
}
-fn testEnumTagNameBare(n: BareNumber) -> []const u8 {
+fn testEnumTagNameBare(n: BareNumber) []const u8 {
return @tagName(n);
}
@@ -270,15 +270,15 @@ test "bit field access with enum fields" {
assert(data.b == B.Four3);
}
-fn getA(data: &const BitFieldOfEnums) -> A {
+fn getA(data: &const BitFieldOfEnums) A {
return data.a;
}
-fn getB(data: &const BitFieldOfEnums) -> B {
+fn getB(data: &const BitFieldOfEnums) B {
return data.b;
}
-fn getC(data: &const BitFieldOfEnums) -> C {
+fn getC(data: &const BitFieldOfEnums) C {
return data.c;
}
@@ -287,7 +287,7 @@ test "casting enum to its tag type" {
comptime testCastEnumToTagType(Small2.Two);
}
-fn testCastEnumToTagType(value: Small2) {
+fn testCastEnumToTagType(value: Small2) void {
assert(u2(value) == 1);
}
@@ -303,7 +303,7 @@ test "enum with specified tag values" {
comptime testEnumWithSpecifiedTagValues(MultipleChoice.C);
}
-fn testEnumWithSpecifiedTagValues(x: MultipleChoice) {
+fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
assert(u32(x) == 60);
assert(1234 == switch (x) {
MultipleChoice.A => 1,
@@ -330,7 +330,7 @@ test "enum with specified and unspecified tag values" {
comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
}
-fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) {
+fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
assert(u32(x) == 1000);
assert(1234 == switch (x) {
MultipleChoice2.A => 1,
@@ -354,7 +354,7 @@ const EnumWithOneMember = enum {
Eof,
};
-fn doALoopThing(id: EnumWithOneMember) {
+fn doALoopThing(id: EnumWithOneMember) void {
while (true) {
if (id == EnumWithOneMember.Eof) {
break;
diff --git a/test/cases/enum_with_members.zig b/test/cases/enum_with_members.zig
index b5bf3ae299..9abc15d129 100644
--- a/test/cases/enum_with_members.zig
+++ b/test/cases/enum_with_members.zig
@@ -6,7 +6,7 @@ const ET = union(enum) {
SINT: i32,
UINT: u32,
- pub fn print(a: &const ET, buf: []u8) -> %usize {
+ pub fn print(a: &const ET, buf: []u8) %usize {
return switch (*a) {
ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
diff --git a/test/cases/error.zig b/test/cases/error.zig
index f4743082d9..47e5f25be9 100644
--- a/test/cases/error.zig
+++ b/test/cases/error.zig
@@ -1,16 +1,16 @@
const assert = @import("std").debug.assert;
const mem = @import("std").mem;
-pub fn foo() -> %i32 {
+pub fn foo() %i32 {
const x = try bar();
return x + 1;
}
-pub fn bar() -> %i32 {
+pub fn bar() %i32 {
return 13;
}
-pub fn baz() -> %i32 {
+pub fn baz() %i32 {
const y = foo() catch 1234;
return y + 1;
}
@@ -20,7 +20,7 @@ test "error wrapping" {
}
error ItBroke;
-fn gimmeItBroke() -> []const u8 {
+fn gimmeItBroke() []const u8 {
return @errorName(error.ItBroke);
}
@@ -47,7 +47,7 @@ test "redefinition of error values allowed" {
error AnError;
error AnError;
error SecondError;
-fn shouldBeNotEqual(a: error, b: error) {
+fn shouldBeNotEqual(a: error, b: error) void {
if (a == b) unreachable;
}
@@ -59,7 +59,7 @@ test "error binary operator" {
assert(b == 10);
}
error ItBroke;
-fn errBinaryOperatorG(x: bool) -> %isize {
+fn errBinaryOperatorG(x: bool) %isize {
return if (x) error.ItBroke else isize(10);
}
@@ -68,18 +68,18 @@ test "unwrap simple value from error" {
const i = unwrapSimpleValueFromErrorDo() catch unreachable;
assert(i == 13);
}
-fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }
+fn unwrapSimpleValueFromErrorDo() %isize { return 13; }
test "error return in assignment" {
doErrReturnInAssignment() catch unreachable;
}
-fn doErrReturnInAssignment() -> %void {
+fn doErrReturnInAssignment() %void {
var x : i32 = undefined;
x = try makeANonErr();
}
-fn makeANonErr() -> %i32 {
+fn makeANonErr() %i32 {
return 1;
}
diff --git a/test/cases/eval.zig b/test/cases/eval.zig
index 484e1885fe..e8dd828b4d 100644
--- a/test/cases/eval.zig
+++ b/test/cases/eval.zig
@@ -5,14 +5,14 @@ test "compile time recursion" {
assert(some_data.len == 21);
}
var some_data: [usize(fibonacci(7))]u8 = undefined;
-fn fibonacci(x: i32) -> i32 {
+fn fibonacci(x: i32) i32 {
if (x <= 1) return 1;
return fibonacci(x - 1) + fibonacci(x - 2);
}
-fn unwrapAndAddOne(blah: ?i32) -> i32 {
+fn unwrapAndAddOne(blah: ?i32) i32 {
return ??blah + 1;
}
const should_be_1235 = unwrapAndAddOne(1234);
@@ -28,7 +28,7 @@ test "inlined loop" {
assert(sum == 15);
}
-fn gimme1or2(comptime a: bool) -> i32 {
+fn gimme1or2(comptime a: bool) i32 {
const x: i32 = 1;
const y: i32 = 2;
comptime var z: i32 = if (a) x else y;
@@ -44,14 +44,14 @@ test "static function evaluation" {
assert(statically_added_number == 3);
}
const statically_added_number = staticAdd(1, 2);
-fn staticAdd(a: i32, b: i32) -> i32 { return a + b; }
+fn staticAdd(a: i32, b: i32) i32 { return a + b; }
test "const expr eval on single expr blocks" {
assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
}
-fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
+fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
const literal = 3;
const result = if (b) b: {
@@ -77,7 +77,7 @@ const Point = struct {
y: i32,
};
const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) };
-fn makePoint(x: i32, y: i32) -> Point {
+fn makePoint(x: i32, y: i32) Point {
return Point {
.x = x,
.y = y,
@@ -93,7 +93,7 @@ const static_vec3 = vec3(0.0, 0.0, 1.0);
pub const Vec3 = struct {
data: [3]f32,
};
-pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
+pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
return Vec3 {
.data = []f32 { x, y, z, },
};
@@ -156,7 +156,7 @@ test "try to trick eval with runtime if" {
assert(testTryToTrickEvalWithRuntimeIf(true) == 10);
}
-fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize {
+fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
comptime var i: usize = 0;
inline while (i < 10) : (i += 1) {
const result = if (b) false else true;
@@ -166,7 +166,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize {
}
}
-fn max(comptime T: type, a: T, b: T) -> T {
+fn max(comptime T: type, a: T, b: T) T {
if (T == bool) {
return a or b;
} else if (a > b) {
@@ -175,7 +175,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
return b;
}
}
-fn letsTryToCompareBools(a: bool, b: bool) -> bool {
+fn letsTryToCompareBools(a: bool, b: bool) bool {
return max(bool, a, b);
}
test "inlined block and runtime block phi" {
@@ -194,7 +194,7 @@ test "inlined block and runtime block phi" {
const CmdFn = struct {
name: []const u8,
- func: fn(i32) -> i32,
+ func: fn(i32) i32,
};
const cmd_fns = []CmdFn{
@@ -202,11 +202,11 @@ const cmd_fns = []CmdFn{
CmdFn {.name = "two", .func = two},
CmdFn {.name = "three", .func = three},
};
-fn one(value: i32) -> i32 { return value + 1; }
-fn two(value: i32) -> i32 { return value + 2; }
-fn three(value: i32) -> i32 { return value + 3; }
+fn one(value: i32) i32 { return value + 1; }
+fn two(value: i32) i32 { return value + 2; }
+fn three(value: i32) i32 { return value + 3; }
-fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 {
+fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
var result: i32 = start_value;
comptime var i = 0;
inline while (i < cmd_fns.len) : (i += 1) {
@@ -228,7 +228,7 @@ test "eval @setRuntimeSafety at compile-time" {
assert(result == 1234);
}
-fn fnWithSetRuntimeSafety() -> i32{
+fn fnWithSetRuntimeSafety() i32{
@setRuntimeSafety(true);
return 1234;
}
@@ -238,7 +238,7 @@ test "eval @setFloatMode at compile-time" {
assert(result == 1234.0);
}
-fn fnWithFloatMode() -> f32 {
+fn fnWithFloatMode() f32 {
@setFloatMode(this, builtin.FloatMode.Strict);
return 1234.0;
}
@@ -247,7 +247,7 @@ fn fnWithFloatMode() -> f32 {
const SimpleStruct = struct {
field: i32,
- fn method(self: &const SimpleStruct) -> i32 {
+ fn method(self: &const SimpleStruct) i32 {
return self.field + 3;
}
};
@@ -271,7 +271,7 @@ test "ptr to local array argument at comptime" {
}
}
-fn modifySomeBytes(bytes: []u8) {
+fn modifySomeBytes(bytes: []u8) void {
bytes[0] = 'a';
bytes[9] = 'b';
}
@@ -280,7 +280,7 @@ fn modifySomeBytes(bytes: []u8) {
test "comparisons 0 <= uint and 0 > uint should be comptime" {
testCompTimeUIntComparisons(1234);
}
-fn testCompTimeUIntComparisons(x: u32) {
+fn testCompTimeUIntComparisons(x: u32) void {
if (!(0 <= x)) {
@compileError("this condition should be comptime known");
}
@@ -339,7 +339,7 @@ test "const global shares pointer with other same one" {
assertEqualPtrs(&hi1[0], &hi2[0]);
comptime assert(&hi1[0] == &hi2[0]);
}
-fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) {
+fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) void {
assert(ptr1 == ptr2);
}
@@ -376,7 +376,7 @@ test "f128 at compile time is lossy" {
// TODO need a better implementation of bigfloat_init_bigint
// assert(f128(1 << 113) == 10384593717069655257060992658440192);
-pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) -> type {
+pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
return struct {
pub const Node = struct { };
};
diff --git a/test/cases/field_parent_ptr.zig b/test/cases/field_parent_ptr.zig
index fcb5c544a3..2e519098cc 100644
--- a/test/cases/field_parent_ptr.zig
+++ b/test/cases/field_parent_ptr.zig
@@ -24,7 +24,7 @@ const foo = Foo {
.d = -10,
};
-fn testParentFieldPtr(c: &const i32) {
+fn testParentFieldPtr(c: &const i32) void {
assert(c == &foo.c);
const base = @fieldParentPtr(Foo, "c", c);
@@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) {
assert(&base.c == c);
}
-fn testParentFieldPtrFirst(a: &const bool) {
+fn testParentFieldPtrFirst(a: &const bool) void {
assert(a == &foo.a);
const base = @fieldParentPtr(Foo, "a", a);
diff --git a/test/cases/fn.zig b/test/cases/fn.zig
index aad68447b2..e492f6036c 100644
--- a/test/cases/fn.zig
+++ b/test/cases/fn.zig
@@ -3,7 +3,7 @@ const assert = @import("std").debug.assert;
test "params" {
assert(testParamsAdd(22, 11) == 33);
}
-fn testParamsAdd(a: i32, b: i32) -> i32 {
+fn testParamsAdd(a: i32, b: i32) i32 {
return a + b;
}
@@ -11,7 +11,7 @@ fn testParamsAdd(a: i32, b: i32) -> i32 {
test "local variables" {
testLocVars(2);
}
-fn testLocVars(b: i32) {
+fn testLocVars(b: i32) void {
const a: i32 = 1;
if (a + b != 3) unreachable;
}
@@ -20,7 +20,7 @@ fn testLocVars(b: i32) {
test "void parameters" {
voidFun(1, void{}, 2, {});
}
-fn voidFun(a: i32, b: void, c: i32, d: void) {
+fn voidFun(a: i32, b: void, c: i32, d: void) void {
const v = b;
const vv: void = if (a == 1) v else {};
assert(a + c == 3);
@@ -56,10 +56,10 @@ test "call function with empty string" {
acceptsString("");
}
-fn acceptsString(foo: []u8) { }
+fn acceptsString(foo: []u8) void { }
-fn @"weird function name"() -> i32 {
+fn @"weird function name"() i32 {
return 1234;
}
test "weird function name" {
@@ -70,9 +70,9 @@ test "implicit cast function unreachable return" {
wantsFnWithVoid(fnWithUnreachable);
}
-fn wantsFnWithVoid(f: fn()) { }
+fn wantsFnWithVoid(f: fn() void) void { }
-fn fnWithUnreachable() -> noreturn {
+fn fnWithUnreachable() noreturn {
unreachable;
}
@@ -83,14 +83,14 @@ test "function pointers" {
assert(f() == u32(i) + 5);
}
}
-fn fn1() -> u32 {return 5;}
-fn fn2() -> u32 {return 6;}
-fn fn3() -> u32 {return 7;}
-fn fn4() -> u32 {return 8;}
+fn fn1() u32 {return 5;}
+fn fn2() u32 {return 6;}
+fn fn3() u32 {return 7;}
+fn fn4() u32 {return 8;}
test "inline function call" {
assert(@inlineCall(add, 3, 9) == 12);
}
-fn add(a: i32, b: i32) -> i32 { return a + b; }
+fn add(a: i32, b: i32) i32 { return a + b; }
diff --git a/test/cases/for.zig b/test/cases/for.zig
index 5a7919541f..7bb0d7c9fa 100644
--- a/test/cases/for.zig
+++ b/test/cases/for.zig
@@ -22,7 +22,7 @@ test "for loop with pointer elem var" {
mangleString(target[0..]);
assert(mem.eql(u8, target, "bcdefgh"));
}
-fn mangleString(s: []u8) {
+fn mangleString(s: []u8) void {
for (s) |*c| {
*c += 1;
}
@@ -61,7 +61,7 @@ test "break from outer for loop" {
comptime testBreakOuter();
}
-fn testBreakOuter() {
+fn testBreakOuter() void {
var array = "aoeu";
var count: usize = 0;
outer: for (array) |_| {
@@ -78,7 +78,7 @@ test "continue outer for loop" {
comptime testContinueOuter();
}
-fn testContinueOuter() {
+fn testContinueOuter() void {
var array = "aoeu";
var counter: usize = 0;
outer: for (array) |_| {
diff --git a/test/cases/generics.zig b/test/cases/generics.zig
index 96500e39b2..19b4a598d8 100644
--- a/test/cases/generics.zig
+++ b/test/cases/generics.zig
@@ -6,11 +6,11 @@ test "simple generic fn" {
assert(add(2, 3) == 5);
}
-fn max(comptime T: type, a: T, b: T) -> T {
+fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
-fn add(comptime a: i32, b: i32) -> i32 {
+fn add(comptime a: i32, b: i32) i32 {
return (comptime a) + b;
}
@@ -19,15 +19,15 @@ test "compile time generic eval" {
assert(the_max == 5678);
}
-fn gimmeTheBigOne(a: u32, b: u32) -> u32 {
+fn gimmeTheBigOne(a: u32, b: u32) u32 {
return max(u32, a, b);
}
-fn shouldCallSameInstance(a: u32, b: u32) -> u32 {
+fn shouldCallSameInstance(a: u32, b: u32) u32 {
return max(u32, a, b);
}
-fn sameButWithFloats(a: f64, b: f64) -> f64 {
+fn sameButWithFloats(a: f64, b: f64) f64 {
return max(f64, a, b);
}
@@ -48,24 +48,24 @@ comptime {
assert(max_f64(1.2, 3.4) == 3.4);
}
-fn max_var(a: var, b: var) -> @typeOf(a + b) {
+fn max_var(a: var, b: var) @typeOf(a + b) {
return if (a > b) a else b;
}
-fn max_i32(a: i32, b: i32) -> i32 {
+fn max_i32(a: i32, b: i32) i32 {
return max_var(a, b);
}
-fn max_f64(a: f64, b: f64) -> f64 {
+fn max_f64(a: f64, b: f64) f64 {
return max_var(a, b);
}
-pub fn List(comptime T: type) -> type {
+pub fn List(comptime T: type) type {
return SmallList(T, 8);
}
-pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
+pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
return struct {
items: []T,
length: usize,
@@ -90,18 +90,18 @@ test "generic struct" {
assert(a1.value == a1.getVal());
assert(b1.getVal());
}
-fn GenNode(comptime T: type) -> type {
+fn GenNode(comptime T: type) type {
return struct {
value: T,
next: ?&GenNode(T),
- fn getVal(n: &const GenNode(T)) -> T { return n.value; }
+ fn getVal(n: &const GenNode(T)) T { return n.value; }
};
}
test "const decls in struct" {
assert(GenericDataThing(3).count_plus_one == 4);
}
-fn GenericDataThing(comptime count: isize) -> type {
+fn GenericDataThing(comptime count: isize) type {
return struct {
const count_plus_one = count + 1;
};
@@ -111,7 +111,7 @@ fn GenericDataThing(comptime count: isize) -> type {
test "use generic param in generic param" {
assert(aGenericFn(i32, 3, 4) == 7);
}
-fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T {
+fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
return a + b;
}
@@ -120,16 +120,16 @@ test "generic fn with implicit cast" {
assert(getFirstByte(u8, []u8 {13}) == 13);
assert(getFirstByte(u16, []u16 {0, 13}) == 0);
}
-fn getByte(ptr: ?&const u8) -> u8 {return *??ptr;}
-fn getFirstByte(comptime T: type, mem: []const T) -> u8 {
+fn getByte(ptr: ?&const u8) u8 {return *??ptr;}
+fn getFirstByte(comptime T: type, mem: []const T) u8 {
return getByte(@ptrCast(&const u8, &mem[0]));
}
-const foos = []fn(var) -> bool { foo1, foo2 };
+const foos = []fn(var) bool { foo1, foo2 };
-fn foo1(arg: var) -> bool { return arg; }
-fn foo2(arg: var) -> bool { return !arg; }
+fn foo1(arg: var) bool { return arg; }
+fn foo2(arg: var) bool { return !arg; }
test "array of generic fns" {
assert(foos[0](true));
diff --git a/test/cases/if.zig b/test/cases/if.zig
index d1fa717b50..2caae7448c 100644
--- a/test/cases/if.zig
+++ b/test/cases/if.zig
@@ -4,14 +4,14 @@ test "if statements" {
shouldBeEqual(1, 1);
firstEqlThird(2, 1, 2);
}
-fn shouldBeEqual(a: i32, b: i32) {
+fn shouldBeEqual(a: i32, b: i32) void {
if (a != b) {
unreachable;
} else {
return;
}
}
-fn firstEqlThird(a: i32, b: i32, c: i32) {
+fn firstEqlThird(a: i32, b: i32, c: i32) void {
if (a == b) {
unreachable;
} else if (b == c) {
@@ -27,7 +27,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) {
test "else if expression" {
assert(elseIfExpressionF(1) == 1);
}
-fn elseIfExpressionF(c: u8) -> u8 {
+fn elseIfExpressionF(c: u8) u8 {
if (c == 0) {
return 0;
} else if (c == 1) {
diff --git a/test/cases/import/a_namespace.zig b/test/cases/import/a_namespace.zig
index 40cdd69139..5cf906cf91 100644
--- a/test/cases/import/a_namespace.zig
+++ b/test/cases/import/a_namespace.zig
@@ -1 +1 @@
-pub fn foo() -> i32 { return 1234; }
+pub fn foo() i32 { return 1234; }
diff --git a/test/cases/incomplete_struct_param_tld.zig b/test/cases/incomplete_struct_param_tld.zig
index 50c078737b..a907ca748a 100644
--- a/test/cases/incomplete_struct_param_tld.zig
+++ b/test/cases/incomplete_struct_param_tld.zig
@@ -11,12 +11,12 @@ const B = struct {
const C = struct {
x: i32,
- fn d(c: &const C) -> i32 {
+ fn d(c: &const C) i32 {
return c.x;
}
};
-fn foo(a: &const A) -> i32 {
+fn foo(a: &const A) i32 {
return a.b.c.d();
}
diff --git a/test/cases/ir_block_deps.zig b/test/cases/ir_block_deps.zig
index 12b8808050..44dfa330a1 100644
--- a/test/cases/ir_block_deps.zig
+++ b/test/cases/ir_block_deps.zig
@@ -1,6 +1,6 @@
const assert = @import("std").debug.assert;
-fn foo(id: u64) -> %i32 {
+fn foo(id: u64) %i32 {
return switch (id) {
1 => getErrInt(),
2 => {
@@ -11,7 +11,7 @@ fn foo(id: u64) -> %i32 {
};
}
-fn getErrInt() -> %i32 { return 0; }
+fn getErrInt() %i32 { return 0; }
error ItBroke;
diff --git a/test/cases/math.zig b/test/cases/math.zig
index 88f32a2839..2deef08cd0 100644
--- a/test/cases/math.zig
+++ b/test/cases/math.zig
@@ -4,7 +4,7 @@ test "division" {
testDivision();
comptime testDivision();
}
-fn testDivision() {
+fn testDivision() void {
assert(div(u32, 13, 3) == 4);
assert(div(f32, 1.0, 2.0) == 0.5);
@@ -50,16 +50,16 @@ fn testDivision() {
assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1);
}
}
-fn div(comptime T: type, a: T, b: T) -> T {
+fn div(comptime T: type, a: T, b: T) T {
return a / b;
}
-fn divExact(comptime T: type, a: T, b: T) -> T {
+fn divExact(comptime T: type, a: T, b: T) T {
return @divExact(a, b);
}
-fn divFloor(comptime T: type, a: T, b: T) -> T {
+fn divFloor(comptime T: type, a: T, b: T) T {
return @divFloor(a, b);
}
-fn divTrunc(comptime T: type, a: T, b: T) -> T {
+fn divTrunc(comptime T: type, a: T, b: T) T {
return @divTrunc(a, b);
}
@@ -85,7 +85,7 @@ test "@clz" {
comptime testClz();
}
-fn testClz() {
+fn testClz() void {
assert(clz(u8(0b00001010)) == 4);
assert(clz(u8(0b10001010)) == 0);
assert(clz(u8(0b00000000)) == 8);
@@ -93,7 +93,7 @@ fn testClz() {
assert(clz(u128(0x10000000000000000)) == 63);
}
-fn clz(x: var) -> usize {
+fn clz(x: var) usize {
return @clz(x);
}
@@ -102,13 +102,13 @@ test "@ctz" {
comptime testCtz();
}
-fn testCtz() {
+fn testCtz() void {
assert(ctz(u8(0b10100000)) == 5);
assert(ctz(u8(0b10001010)) == 1);
assert(ctz(u8(0b00000000)) == 8);
}
-fn ctz(x: var) -> usize {
+fn ctz(x: var) usize {
return @ctz(x);
}
@@ -132,7 +132,7 @@ test "three expr in a row" {
testThreeExprInARow(false, true);
comptime testThreeExprInARow(false, true);
}
-fn testThreeExprInARow(f: bool, t: bool) {
+fn testThreeExprInARow(f: bool, t: bool) void {
assertFalse(f or f or f);
assertFalse(t and t and f);
assertFalse(1 | 2 | 4 != 7);
@@ -146,7 +146,7 @@ fn testThreeExprInARow(f: bool, t: bool) {
assertFalse(!!false);
assertFalse(i32(7) != --(i32(7)));
}
-fn assertFalse(b: bool) {
+fn assertFalse(b: bool) void {
assert(!b);
}
@@ -165,7 +165,7 @@ test "unsigned wrapping" {
testUnsignedWrappingEval(@maxValue(u32));
comptime testUnsignedWrappingEval(@maxValue(u32));
}
-fn testUnsignedWrappingEval(x: u32) {
+fn testUnsignedWrappingEval(x: u32) void {
const zero = x +% 1;
assert(zero == 0);
const orig = zero -% 1;
@@ -176,7 +176,7 @@ test "signed wrapping" {
testSignedWrappingEval(@maxValue(i32));
comptime testSignedWrappingEval(@maxValue(i32));
}
-fn testSignedWrappingEval(x: i32) {
+fn testSignedWrappingEval(x: i32) void {
const min_val = x +% 1;
assert(min_val == @minValue(i32));
const max_val = min_val -% 1;
@@ -187,7 +187,7 @@ test "negation wrapping" {
testNegationWrappingEval(@minValue(i16));
comptime testNegationWrappingEval(@minValue(i16));
}
-fn testNegationWrappingEval(x: i16) {
+fn testNegationWrappingEval(x: i16) void {
assert(x == -32768);
const neg = -%x;
assert(neg == -32768);
@@ -197,12 +197,12 @@ test "unsigned 64-bit division" {
test_u64_div();
comptime test_u64_div();
}
-fn test_u64_div() {
+fn test_u64_div() void {
const result = divWithResult(1152921504606846976, 34359738365);
assert(result.quotient == 33554432);
assert(result.remainder == 100663296);
}
-fn divWithResult(a: u64, b: u64) -> DivResult {
+fn divWithResult(a: u64, b: u64) DivResult {
return DivResult {
.quotient = a / b,
.remainder = a % b,
@@ -219,7 +219,7 @@ test "binary not" {
testBinaryNot(0b1010101010101010);
}
-fn testBinaryNot(x: u16) {
+fn testBinaryNot(x: u16) void {
assert(~x == 0b0101010101010101);
}
@@ -250,7 +250,7 @@ test "float equality" {
comptime testFloatEqualityImpl(x, y);
}
-fn testFloatEqualityImpl(x: f64, y: f64) {
+fn testFloatEqualityImpl(x: f64, y: f64) void {
const y2 = x + 1.0;
assert(y == y2);
}
@@ -285,7 +285,7 @@ test "truncating shift left" {
testShlTrunc(@maxValue(u16));
comptime testShlTrunc(@maxValue(u16));
}
-fn testShlTrunc(x: u16) {
+fn testShlTrunc(x: u16) void {
const shifted = x << 1;
assert(shifted == 65534);
}
@@ -294,7 +294,7 @@ test "truncating shift right" {
testShrTrunc(@maxValue(u16));
comptime testShrTrunc(@maxValue(u16));
}
-fn testShrTrunc(x: u16) {
+fn testShrTrunc(x: u16) void {
const shifted = x >> 1;
assert(shifted == 32767);
}
@@ -303,7 +303,7 @@ test "exact shift left" {
testShlExact(0b00110101);
comptime testShlExact(0b00110101);
}
-fn testShlExact(x: u8) {
+fn testShlExact(x: u8) void {
const shifted = @shlExact(x, 2);
assert(shifted == 0b11010100);
}
@@ -312,7 +312,7 @@ test "exact shift right" {
testShrExact(0b10110100);
comptime testShrExact(0b10110100);
}
-fn testShrExact(x: u8) {
+fn testShrExact(x: u8) void {
const shifted = @shrExact(x, 2);
assert(shifted == 0b00101101);
}
@@ -354,7 +354,7 @@ test "xor" {
comptime test_xor();
}
-fn test_xor() {
+fn test_xor() void {
assert(0xFF ^ 0x00 == 0xFF);
assert(0xF0 ^ 0x0F == 0xFF);
assert(0xFF ^ 0xF0 == 0x0F);
@@ -380,9 +380,9 @@ test "f128" {
comptime test_f128();
}
-fn make_f128(x: f128) -> f128 { return x; }
+fn make_f128(x: f128) f128 { return x; }
-fn test_f128() {
+fn test_f128() void {
assert(@sizeOf(f128) == 16);
assert(make_f128(1.0) == 1.0);
assert(make_f128(1.0) != 1.1);
@@ -392,6 +392,6 @@ fn test_f128() {
should_not_be_zero(1.0);
}
-fn should_not_be_zero(x: f128) {
+fn should_not_be_zero(x: f128) void {
assert(x != 0.0);
}
\ No newline at end of file
diff --git a/test/cases/misc.zig b/test/cases/misc.zig
index ee88c1359d..cfc3456738 100644
--- a/test/cases/misc.zig
+++ b/test/cases/misc.zig
@@ -6,7 +6,7 @@ const builtin = @import("builtin");
// normal comment
/// this is a documentation comment
/// doc comment line 2
-fn emptyFunctionWithComments() {}
+fn emptyFunctionWithComments() void {}
test "empty function with comments" {
emptyFunctionWithComments();
@@ -16,7 +16,7 @@ comptime {
@export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal);
}
-extern fn disabledExternFn() {
+extern fn disabledExternFn() void {
}
test "call disabled extern fn" {
@@ -104,7 +104,7 @@ test "short circuit" {
comptime testShortCircuit(false, true);
}
-fn testShortCircuit(f: bool, t: bool) {
+fn testShortCircuit(f: bool, t: bool) void {
var hit_1 = f;
var hit_2 = f;
var hit_3 = f;
@@ -134,11 +134,11 @@ fn testShortCircuit(f: bool, t: bool) {
test "truncate" {
assert(testTruncate(0x10fd) == 0xfd);
}
-fn testTruncate(x: u32) -> u8 {
+fn testTruncate(x: u32) u8 {
return @truncate(u8, x);
}
-fn first4KeysOfHomeRow() -> []const u8 {
+fn first4KeysOfHomeRow() []const u8 {
return "aoeu";
}
@@ -193,7 +193,7 @@ test "constant equal function pointers" {
assert(comptime x: {break :x emptyFn == alias;});
}
-fn emptyFn() {}
+fn emptyFn() void {}
test "hex escape" {
@@ -262,10 +262,10 @@ test "generic malloc free" {
memFree(u8, a);
}
const some_mem : [100]u8 = undefined;
-fn memAlloc(comptime T: type, n: usize) -> %[]T {
+fn memAlloc(comptime T: type, n: usize) %[]T {
return @ptrCast(&T, &some_mem[0])[0..n];
}
-fn memFree(comptime T: type, memory: []T) { }
+fn memFree(comptime T: type, memory: []T) void { }
test "cast undefined" {
@@ -273,22 +273,22 @@ test "cast undefined" {
const slice = ([]const u8)(array);
testCastUndefined(slice);
}
-fn testCastUndefined(x: []const u8) {}
+fn testCastUndefined(x: []const u8) void {}
test "cast small unsigned to larger signed" {
assert(castSmallUnsignedToLargerSigned1(200) == i16(200));
assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
}
-fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { return x; }
-fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { return x; }
+fn castSmallUnsignedToLargerSigned1(x: u8) i16 { return x; }
+fn castSmallUnsignedToLargerSigned2(x: u16) i64 { return x; }
test "implicit cast after unreachable" {
assert(outer() == 1234);
}
-fn inner() -> i32 { return 1234; }
-fn outer() -> i64 {
+fn inner() i32 { return 1234; }
+fn outer() i64 {
return inner();
}
@@ -307,11 +307,11 @@ test "call result of if else expression" {
assert(mem.eql(u8, f2(true), "a"));
assert(mem.eql(u8, f2(false), "b"));
}
-fn f2(x: bool) -> []const u8 {
+fn f2(x: bool) []const u8 {
return (if (x) fA else fB)();
}
-fn fA() -> []const u8 { return "a"; }
-fn fB() -> []const u8 { return "b"; }
+fn fA() []const u8 { return "a"; }
+fn fB() []const u8 { return "b"; }
test "const expression eval handling of variables" {
@@ -338,7 +338,7 @@ const Test3Point = struct {
};
const test3_foo = Test3Foo { .Three = Test3Point {.x = 3, .y = 4}};
const test3_bar = Test3Foo { .Two = 13};
-fn test3_1(f: &const Test3Foo) {
+fn test3_1(f: &const Test3Foo) void {
switch (*f) {
Test3Foo.Three => |pt| {
assert(pt.x == 3);
@@ -347,7 +347,7 @@ fn test3_1(f: &const Test3Foo) {
else => unreachable,
}
}
-fn test3_2(f: &const Test3Foo) {
+fn test3_2(f: &const Test3Foo) void {
switch (*f) {
Test3Foo.Two => |x| {
assert(x == 13);
@@ -367,7 +367,7 @@ const single_quote = '\'';
test "take address of parameter" {
testTakeAddressOfParameter(12.34);
}
-fn testTakeAddressOfParameter(f: f32) {
+fn testTakeAddressOfParameter(f: f32) void {
const f_ptr = &f;
assert(*f_ptr == 12.34);
}
@@ -378,7 +378,7 @@ test "pointer comparison" {
const b = &a;
assert(ptrEql(b, b));
}
-fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool {
+fn ptrEql(a: &const []const u8, b: &const []const u8) bool {
return a == b;
}
@@ -419,12 +419,12 @@ test "cast slice to u8 slice" {
test "pointer to void return type" {
testPointerToVoidReturnType() catch unreachable;
}
-fn testPointerToVoidReturnType() -> %void {
+fn testPointerToVoidReturnType() %void {
const a = testPointerToVoidReturnType2();
return *a;
}
const test_pointer_to_void_return_type_x = void{};
-fn testPointerToVoidReturnType2() -> &const void {
+fn testPointerToVoidReturnType2() &const void {
return &test_pointer_to_void_return_type_x;
}
@@ -444,7 +444,7 @@ test "array 2D const double ptr" {
testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
}
-fn testArray2DConstDoublePtr(ptr: &const f32) {
+fn testArray2DConstDoublePtr(ptr: &const f32) void {
assert(ptr[0] == 1.0);
assert(ptr[1] == 2.0);
}
@@ -481,7 +481,7 @@ test "@typeId" {
assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);
assert(@typeId(AUnionEnum) == Tid.Union);
assert(@typeId(AUnion) == Tid.Union);
- assert(@typeId(fn()) == Tid.Fn);
+ assert(@typeId(fn()void) == Tid.Fn);
assert(@typeId(@typeOf(builtin)) == Tid.Namespace);
assert(@typeId(@typeOf(x: {break :x this;})) == Tid.Block);
// TODO bound fn
@@ -536,7 +536,7 @@ var global_ptr = &gdt[0];
// can't really run this test but we can make sure it has no compile error
// and generates code
const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];
-export fn writeToVRam() {
+export fn writeToVRam() void {
vram[0] = 'X';
}
@@ -556,7 +556,7 @@ test "variable is allowed to be a pointer to an opaque type" {
var x: i32 = 1234;
_ = hereIsAnOpaqueType(@ptrCast(&OpaqueA, &x));
}
-fn hereIsAnOpaqueType(ptr: &OpaqueA) -> &OpaqueA {
+fn hereIsAnOpaqueType(ptr: &OpaqueA) &OpaqueA {
var a = ptr;
return a;
}
@@ -565,7 +565,7 @@ test "comptime if inside runtime while which unconditionally breaks" {
testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(true);
comptime testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(true);
}
-fn testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(cond: bool) {
+fn testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(cond: bool) void {
while (cond) {
if (false) { }
break;
@@ -583,7 +583,7 @@ test "struct inside function" {
comptime testStructInFn();
}
-fn testStructInFn() {
+fn testStructInFn() void {
const BlockKind = u32;
const Block = struct {
@@ -597,10 +597,10 @@ fn testStructInFn() {
assert(block.kind == 1235);
}
-fn fnThatClosesOverLocalConst() -> type {
+fn fnThatClosesOverLocalConst() type {
const c = 1;
return struct {
- fn g() -> i32 { return c; }
+ fn g() i32 { return c; }
};
}
@@ -614,6 +614,6 @@ test "cold function" {
comptime thisIsAColdFn();
}
-fn thisIsAColdFn() {
+fn thisIsAColdFn() void {
@setCold(true);
}
diff --git a/test/cases/null.zig b/test/cases/null.zig
index ad3d1bb8e2..35d72b729c 100644
--- a/test/cases/null.zig
+++ b/test/cases/null.zig
@@ -48,14 +48,14 @@ test "maybe return" {
comptime maybeReturnImpl();
}
-fn maybeReturnImpl() {
+fn maybeReturnImpl() void {
assert(??foo(1235));
if (foo(null) != null)
unreachable;
assert(!??foo(1234));
}
-fn foo(x: ?i32) -> ?bool {
+fn foo(x: ?i32) ?bool {
const value = x ?? return null;
return value > 1234;
}
@@ -64,7 +64,7 @@ fn foo(x: ?i32) -> ?bool {
test "if var maybe pointer" {
assert(shouldBeAPlus1(Particle {.a = 14, .b = 1, .c = 1, .d = 1}) == 15);
}
-fn shouldBeAPlus1(p: &const Particle) -> u64 {
+fn shouldBeAPlus1(p: &const Particle) u64 {
var maybe_particle: ?Particle = *p;
if (maybe_particle) |*particle| {
particle.a += 1;
@@ -100,7 +100,7 @@ const here_is_a_null_literal = SillyStruct {
test "test null runtime" {
testTestNullRuntime(null);
}
-fn testTestNullRuntime(x: ?i32) {
+fn testTestNullRuntime(x: ?i32) void {
assert(x == null);
assert(!(x != null));
}
@@ -110,12 +110,12 @@ test "nullable void" {
comptime nullableVoidImpl();
}
-fn nullableVoidImpl() {
+fn nullableVoidImpl() void {
assert(bar(null) == null);
assert(bar({}) != null);
}
-fn bar(x: ?void) -> ?void {
+fn bar(x: ?void) ?void {
if (x) |_| {
return {};
} else {
diff --git a/test/cases/pub_enum/index.zig b/test/cases/pub_enum/index.zig
index c954fa507d..7fdd07b8a3 100644
--- a/test/cases/pub_enum/index.zig
+++ b/test/cases/pub_enum/index.zig
@@ -4,7 +4,7 @@ const assert = @import("std").debug.assert;
test "pub enum" {
pubEnumTest(other.APubEnum.Two);
}
-fn pubEnumTest(foo: other.APubEnum) {
+fn pubEnumTest(foo: other.APubEnum) void {
assert(foo == other.APubEnum.Two);
}
diff --git a/test/cases/ref_var_in_if_after_if_2nd_switch_prong.zig b/test/cases/ref_var_in_if_after_if_2nd_switch_prong.zig
index 099b12a811..76cff3731a 100644
--- a/test/cases/ref_var_in_if_after_if_2nd_switch_prong.zig
+++ b/test/cases/ref_var_in_if_after_if_2nd_switch_prong.zig
@@ -16,7 +16,7 @@ const Num = enum {
Two,
};
-fn foo(c: bool, k: Num, c2: bool, b: []const u8) {
+fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
switch (k) {
Num.Two => {},
Num.One => {
@@ -31,7 +31,7 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) {
}
}
-fn a(x: []const u8) {
+fn a(x: []const u8) void {
assert(mem.eql(u8, x, "aoeu"));
ok = true;
}
diff --git a/test/cases/reflection.zig b/test/cases/reflection.zig
index 9b298f8823..8e103a3bc7 100644
--- a/test/cases/reflection.zig
+++ b/test/cases/reflection.zig
@@ -22,8 +22,8 @@ test "reflection: function return type, var args, and param types" {
}
}
-fn dummy(a: bool, b: i32, c: f32) -> i32 { return 1234; }
-fn dummy_varargs(args: ...) {}
+fn dummy(a: bool, b: i32, c: f32) i32 { return 1234; }
+fn dummy_varargs(args: ...) void {}
test "reflection: struct member types and names" {
comptime {
diff --git a/test/cases/slice.zig b/test/cases/slice.zig
index 379526d5d5..ea708ba3b5 100644
--- a/test/cases/slice.zig
+++ b/test/cases/slice.zig
@@ -22,7 +22,7 @@ test "runtime safety lets us slice from len..len" {
assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
}
-fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) -> []u8 {
+fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
return a_slice[start..end];
}
@@ -31,6 +31,6 @@ test "implicitly cast array of size 0 to slice" {
assertLenIsZero(msg);
}
-fn assertLenIsZero(msg: []const u8) {
+fn assertLenIsZero(msg: []const u8) void {
assert(msg.len == 0);
}
diff --git a/test/cases/struct.zig b/test/cases/struct.zig
index bdd2e5d049..7fb8421d6f 100644
--- a/test/cases/struct.zig
+++ b/test/cases/struct.zig
@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
const builtin = @import("builtin");
const StructWithNoFields = struct {
- fn add(a: i32, b: i32) -> i32 { return a + b; }
+ fn add(a: i32, b: i32) i32 { return a + b; }
};
const empty_global_instance = StructWithNoFields {};
@@ -14,7 +14,7 @@ test "call struct static method" {
test "return empty struct instance" {
_ = returnEmptyStructInstance();
}
-fn returnEmptyStructInstance() -> StructWithNoFields {
+fn returnEmptyStructInstance() StructWithNoFields {
return empty_global_instance;
}
@@ -54,10 +54,10 @@ const StructFoo = struct {
b : bool,
c : f32,
};
-fn testFoo(foo: &const StructFoo) {
+fn testFoo(foo: &const StructFoo) void {
assert(foo.b);
}
-fn testMutation(foo: &StructFoo) {
+fn testMutation(foo: &StructFoo) void {
foo.c = 100;
}
@@ -95,7 +95,7 @@ test "struct byval assign" {
assert(foo2.a == 1234);
}
-fn structInitializer() {
+fn structInitializer() void {
const val = Val { .x = 42 };
assert(val.x == 42);
}
@@ -106,12 +106,12 @@ test "fn call of struct field" {
}
const Foo = struct {
- ptr: fn() -> i32,
+ ptr: fn() i32,
};
-fn aFunc() -> i32 { return 13; }
+fn aFunc() i32 { return 13; }
-fn callStructField(foo: &const Foo) -> i32 {
+fn callStructField(foo: &const Foo) i32 {
return foo.ptr();
}
@@ -124,7 +124,7 @@ test "store member function in variable" {
}
const MemberFnTestFoo = struct {
x: i32,
- fn member(foo: &const MemberFnTestFoo) -> i32 { return foo.x; }
+ fn member(foo: &const MemberFnTestFoo) i32 { return foo.x; }
};
@@ -140,7 +140,7 @@ test "member functions" {
}
const MemberFnRand = struct {
seed: u32,
- pub fn getSeed(r: &const MemberFnRand) -> u32 {
+ pub fn getSeed(r: &const MemberFnRand) u32 {
return r.seed;
}
};
@@ -153,7 +153,7 @@ const Bar = struct {
x: i32,
y: i32,
};
-fn makeBar(x: i32, y: i32) -> Bar {
+fn makeBar(x: i32, y: i32) Bar {
return Bar {
.x = x,
.y = y,
@@ -165,7 +165,7 @@ test "empty struct method call" {
assert(es.method() == 1234);
}
const EmptyStruct = struct {
- fn method(es: &const EmptyStruct) -> i32 {
+ fn method(es: &const EmptyStruct) i32 {
return 1234;
}
};
@@ -175,14 +175,14 @@ test "return empty struct from fn" {
_ = testReturnEmptyStructFromFn();
}
const EmptyStruct2 = struct {};
-fn testReturnEmptyStructFromFn() -> EmptyStruct2 {
+fn testReturnEmptyStructFromFn() EmptyStruct2 {
return EmptyStruct2 {};
}
test "pass slice of empty struct to fn" {
assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1);
}
-fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize {
+fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
return slice.len;
}
@@ -229,15 +229,15 @@ test "bit field access" {
assert(data.b == 3);
}
-fn getA(data: &const BitField1) -> u3 {
+fn getA(data: &const BitField1) u3 {
return data.a;
}
-fn getB(data: &const BitField1) -> u3 {
+fn getB(data: &const BitField1) u3 {
return data.b;
}
-fn getC(data: &const BitField1) -> u2 {
+fn getC(data: &const BitField1) u2 {
return data.c;
}
diff --git a/test/cases/switch.zig b/test/cases/switch.zig
index 4e29b12a96..f742057e68 100644
--- a/test/cases/switch.zig
+++ b/test/cases/switch.zig
@@ -4,7 +4,7 @@ test "switch with numbers" {
testSwitchWithNumbers(13);
}
-fn testSwitchWithNumbers(x: u32) {
+fn testSwitchWithNumbers(x: u32) void {
const result = switch (x) {
1, 2, 3, 4 ... 8 => false,
13 => true,
@@ -20,7 +20,7 @@ test "switch with all ranges" {
assert(testSwitchWithAllRanges(301, 6) == 6);
}
-fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 {
+fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
return switch (x) {
0 ... 100 => 1,
101 ... 200 => 2,
@@ -53,7 +53,7 @@ const Fruit = enum {
Orange,
Banana,
};
-fn nonConstSwitchOnEnum(fruit: Fruit) {
+fn nonConstSwitchOnEnum(fruit: Fruit) void {
switch (fruit) {
Fruit.Apple => unreachable,
Fruit.Orange => {},
@@ -65,7 +65,7 @@ fn nonConstSwitchOnEnum(fruit: Fruit) {
test "switch statement" {
nonConstSwitch(SwitchStatmentFoo.C);
}
-fn nonConstSwitch(foo: SwitchStatmentFoo) {
+fn nonConstSwitch(foo: SwitchStatmentFoo) void {
const val = switch (foo) {
SwitchStatmentFoo.A => i32(1),
SwitchStatmentFoo.B => 2,
@@ -92,7 +92,7 @@ const SwitchProngWithVarEnum = union(enum) {
Two: f32,
Meh: void,
};
-fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {
+fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) void {
switch(*a) {
SwitchProngWithVarEnum.One => |x| {
assert(x == 13);
@@ -111,7 +111,7 @@ test "switch on enum using pointer capture" {
comptime testSwitchEnumPtrCapture();
}
-fn testSwitchEnumPtrCapture() {
+fn testSwitchEnumPtrCapture() void {
var value = SwitchProngWithVarEnum { .One = 1234 };
switch (value) {
SwitchProngWithVarEnum.One => |*x| *x += 1,
@@ -131,7 +131,7 @@ test "switch with multiple expressions" {
};
assert(x == 2);
}
-fn returnsFive() -> i32 {
+fn returnsFive() i32 {
return 5;
}
@@ -144,7 +144,7 @@ const Number = union(enum) {
const number = Number { .Three = 1.23 };
-fn returnsFalse() -> bool {
+fn returnsFalse() bool {
switch (number) {
Number.One => |x| return x > 1234,
Number.Two => |x| return x == 'a',
@@ -160,7 +160,7 @@ test "switch on type" {
assert(!trueIfBoolFalseOtherwise(i32));
}
-fn trueIfBoolFalseOtherwise(comptime T: type) -> bool {
+fn trueIfBoolFalseOtherwise(comptime T: type) bool {
return switch (T) {
bool => true,
else => false,
@@ -172,7 +172,7 @@ test "switch handles all cases of number" {
comptime testSwitchHandleAllCases();
}
-fn testSwitchHandleAllCases() {
+fn testSwitchHandleAllCases() void {
assert(testSwitchHandleAllCasesExhaustive(0) == 3);
assert(testSwitchHandleAllCasesExhaustive(1) == 2);
assert(testSwitchHandleAllCasesExhaustive(2) == 1);
@@ -185,7 +185,7 @@ fn testSwitchHandleAllCases() {
assert(testSwitchHandleAllCasesRange(230) == 3);
}
-fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 {
+fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
return switch (x) {
0 => u2(3),
1 => 2,
@@ -194,7 +194,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 {
};
}
-fn testSwitchHandleAllCasesRange(x: u8) -> u8 {
+fn testSwitchHandleAllCasesRange(x: u8) u8 {
return switch (x) {
0 ... 100 => u8(0),
101 ... 200 => 1,
@@ -209,12 +209,12 @@ test "switch all prongs unreachable" {
comptime testAllProngsUnreachable();
}
-fn testAllProngsUnreachable() {
+fn testAllProngsUnreachable() void {
assert(switchWithUnreachable(1) == 2);
assert(switchWithUnreachable(2) == 10);
}
-fn switchWithUnreachable(x: i32) -> i32 {
+fn switchWithUnreachable(x: i32) i32 {
while (true) {
switch (x) {
1 => return 2,
@@ -225,7 +225,7 @@ fn switchWithUnreachable(x: i32) -> i32 {
return 10;
}
-fn return_a_number() -> %i32 {
+fn return_a_number() %i32 {
return 1;
}
diff --git a/test/cases/switch_prong_err_enum.zig b/test/cases/switch_prong_err_enum.zig
index 0585112ecf..2da5b5f09a 100644
--- a/test/cases/switch_prong_err_enum.zig
+++ b/test/cases/switch_prong_err_enum.zig
@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
var read_count: u64 = 0;
-fn readOnce() -> %u64 {
+fn readOnce() %u64 {
read_count += 1;
return read_count;
}
@@ -14,7 +14,7 @@ const FormValue = union(enum) {
Other: bool,
};
-fn doThing(form_id: u64) -> %FormValue {
+fn doThing(form_id: u64) %FormValue {
return switch (form_id) {
17 => FormValue { .Address = try readOnce() },
else => error.InvalidDebugInfo,
diff --git a/test/cases/switch_prong_implicit_cast.zig b/test/cases/switch_prong_implicit_cast.zig
index b59231038d..300b8c21a1 100644
--- a/test/cases/switch_prong_implicit_cast.zig
+++ b/test/cases/switch_prong_implicit_cast.zig
@@ -7,7 +7,7 @@ const FormValue = union(enum) {
error Whatever;
-fn foo(id: u64) -> %FormValue {
+fn foo(id: u64) %FormValue {
return switch (id) {
2 => FormValue { .Two = true },
1 => FormValue { .One = {} },
diff --git a/test/cases/syntax.zig b/test/cases/syntax.zig
index 3ebca96ef9..6c851c0ff3 100644
--- a/test/cases/syntax.zig
+++ b/test/cases/syntax.zig
@@ -3,18 +3,18 @@
const struct_trailing_comma = struct { x: i32, y: i32, };
const struct_no_comma = struct { x: i32, y: i32 };
const struct_no_comma_void_type = struct { x: i32, y };
-const struct_fn_no_comma = struct { fn m() {} y: i32 };
+const struct_fn_no_comma = struct { fn m() void {} y: i32 };
const enum_no_comma = enum { A, B };
const enum_no_comma_type = enum { A, B: i32 };
-fn container_init() {
+fn container_init() void {
const S = struct { x: i32, y: i32 };
_ = S { .x = 1, .y = 2 };
_ = S { .x = 1, .y = 2, };
}
-fn switch_cases(x: i32) {
+fn switch_cases(x: i32) void {
switch (x) {
1,2,3 => {},
4,5, => {},
@@ -23,7 +23,7 @@ fn switch_cases(x: i32) {
}
}
-fn switch_prongs(x: i32) {
+fn switch_prongs(x: i32) void {
switch (x) {
0 => {},
else => {},
@@ -34,21 +34,21 @@ fn switch_prongs(x: i32) {
}
}
-const fn_no_comma = fn(i32, i32);
-const fn_trailing_comma = fn(i32, i32,);
-const fn_vararg_trailing_comma = fn(i32, i32, ...,);
+const fn_no_comma = fn(i32, i32)void;
+const fn_trailing_comma = fn(i32, i32,)void;
+const fn_vararg_trailing_comma = fn(i32, i32, ...,)void;
-fn fn_calls() {
- fn add(x: i32, y: i32,) -> i32 { x + y };
+fn fn_calls() void {
+ fn add(x: i32, y: i32,) i32 { x + y };
_ = add(1, 2);
_ = add(1, 2,);
- fn swallow(x: ...,) {};
+ fn swallow(x: ...,) void {};
_ = swallow(1,2,3,);
_ = swallow();
}
-fn asm_lists() {
+fn asm_lists() void {
if (false) { // Build AST but don't analyze
asm ("not real assembly"
:[a] "x" (x),);
diff --git a/test/cases/this.zig b/test/cases/this.zig
index b4e6b32a09..8ed5e1ae1a 100644
--- a/test/cases/this.zig
+++ b/test/cases/this.zig
@@ -2,24 +2,24 @@ const assert = @import("std").debug.assert;
const module = this;
-fn Point(comptime T: type) -> type {
+fn Point(comptime T: type) type {
return struct {
const Self = this;
x: T,
y: T,
- fn addOne(self: &Self) {
+ fn addOne(self: &Self) void {
self.x += 1;
self.y += 1;
}
};
}
-fn add(x: i32, y: i32) -> i32 {
+fn add(x: i32, y: i32) i32 {
return x + y;
}
-fn factorial(x: i32) -> i32 {
+fn factorial(x: i32) i32 {
const selfFn = this;
return if (x == 0) 1 else x * selfFn(x - 1);
}
diff --git a/test/cases/try.zig b/test/cases/try.zig
index 25b2f321fb..00259721b1 100644
--- a/test/cases/try.zig
+++ b/test/cases/try.zig
@@ -6,7 +6,7 @@ test "try on error union" {
}
-fn tryOnErrorUnionImpl() {
+fn tryOnErrorUnionImpl() void {
const x = if (returnsTen()) |val|
val + 1
else |err| switch (err) {
@@ -20,7 +20,7 @@ fn tryOnErrorUnionImpl() {
error ItBroke;
error NoMem;
error CrappedOut;
-fn returnsTen() -> %i32 {
+fn returnsTen() %i32 {
return 10;
}
@@ -32,7 +32,7 @@ test "try without vars" {
assert(result2 == 1);
}
-fn failIfTrue(ok: bool) -> %void {
+fn failIfTrue(ok: bool) %void {
if (ok) {
return error.ItBroke;
} else {
diff --git a/test/cases/undefined.zig b/test/cases/undefined.zig
index e2f8515fd7..bc81f9cf84 100644
--- a/test/cases/undefined.zig
+++ b/test/cases/undefined.zig
@@ -1,7 +1,7 @@
const assert = @import("std").debug.assert;
const mem = @import("std").mem;
-fn initStaticArray() -> [10]i32 {
+fn initStaticArray() [10]i32 {
var array: [10]i32 = undefined;
array[0] = 1;
array[4] = 2;
@@ -27,12 +27,12 @@ test "init static array to undefined" {
const Foo = struct {
x: i32,
- fn setFooXMethod(foo: &Foo) {
+ fn setFooXMethod(foo: &Foo) void {
foo.x = 3;
}
};
-fn setFooX(foo: &Foo) {
+fn setFooX(foo: &Foo) void {
foo.x = 2;
}
diff --git a/test/cases/union.zig b/test/cases/union.zig
index 74c840b883..ea8a9da188 100644
--- a/test/cases/union.zig
+++ b/test/cases/union.zig
@@ -55,11 +55,11 @@ test "init union with runtime value" {
assert(foo.int == 42);
}
-fn setFloat(foo: &Foo, x: f64) {
+fn setFloat(foo: &Foo, x: f64) void {
*foo = Foo { .float = x };
}
-fn setInt(foo: &Foo, x: i32) {
+fn setInt(foo: &Foo, x: i32) void {
*foo = Foo { .int = x };
}
@@ -92,11 +92,11 @@ test "union with specified enum tag" {
comptime doTest();
}
-fn doTest() {
+fn doTest() void {
assert(bar(Payload {.A = 1234}) == -10);
}
-fn bar(value: &const Payload) -> i32 {
+fn bar(value: &const Payload) i32 {
assert(Letter(*value) == Letter.A);
return switch (*value) {
Payload.A => |x| return x - 1244,
@@ -135,7 +135,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2 { .C = 123} );
}
-fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) {
+fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void {
assert(u32(@TagType(MultipleChoice2)(*x)) == 60);
assert(1123 == switch (*x) {
MultipleChoice2.A => 1,
@@ -187,7 +187,7 @@ test "cast union to tag type of union" {
comptime testCastUnionToTagType(TheUnion {.B = 1234});
}
-fn testCastUnionToTagType(x: &const TheUnion) {
+fn testCastUnionToTagType(x: &const TheUnion) void {
assert(TheTag(*x) == TheTag.B);
}
@@ -203,7 +203,7 @@ test "implicit cast union to its tag type" {
assert(x == Letter2.B);
giveMeLetterB(x);
}
-fn giveMeLetterB(x: Letter2) {
+fn giveMeLetterB(x: Letter2) void {
assert(x == Value2.B);
}
@@ -216,7 +216,7 @@ const TheUnion2 = union(enum) {
Item2: i32,
};
-fn assertIsTheUnion2Item1(value: &const TheUnion2) {
+fn assertIsTheUnion2Item1(value: &const TheUnion2) void {
assert(*value == TheUnion2.Item1);
}
@@ -232,7 +232,7 @@ test "constant packed union" {
});
}
-fn testConstPackedUnion(expected_tokens: []const PackThis) {
+fn testConstPackedUnion(expected_tokens: []const PackThis) void {
assert(expected_tokens[0].StringLiteral == 1);
}
diff --git a/test/cases/var_args.zig b/test/cases/var_args.zig
index aa8b210ad6..cead9eb8bf 100644
--- a/test/cases/var_args.zig
+++ b/test/cases/var_args.zig
@@ -1,6 +1,6 @@
const assert = @import("std").debug.assert;
-fn add(args: ...) -> i32 {
+fn add(args: ...) i32 {
var sum = i32(0);
{comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
sum += args[i];
@@ -14,7 +14,7 @@ test "add arbitrary args" {
assert(add() == 0);
}
-fn readFirstVarArg(args: ...) {
+fn readFirstVarArg(args: ...) void {
const value = args[0];
}
@@ -28,7 +28,7 @@ test "pass args directly" {
assert(addSomeStuff() == 0);
}
-fn addSomeStuff(args: ...) -> i32 {
+fn addSomeStuff(args: ...) i32 {
return add(args);
}
@@ -45,7 +45,7 @@ test "runtime parameter before var args" {
//}
}
-fn extraFn(extra: u32, args: ...) -> usize {
+fn extraFn(extra: u32, args: ...) usize {
if (args.len >= 1) {
assert(args[0] == false);
}
@@ -56,10 +56,10 @@ fn extraFn(extra: u32, args: ...) -> usize {
}
-const foos = []fn(...) -> bool { foo1, foo2 };
+const foos = []fn(...) bool { foo1, foo2 };
-fn foo1(args: ...) -> bool { return true; }
-fn foo2(args: ...) -> bool { return false; }
+fn foo1(args: ...) bool { return true; }
+fn foo2(args: ...) bool { return false; }
test "array of var args functions" {
assert(foos[0]());
@@ -73,7 +73,7 @@ test "pass array and slice of same array to var args should have same pointers"
return assertSlicePtrsEql(array, slice);
}
-fn assertSlicePtrsEql(args: ...) {
+fn assertSlicePtrsEql(args: ...) void {
const s1 = ([]const u8)(args[0]);
const s2 = args[1];
assert(s1.ptr == s2.ptr);
@@ -84,6 +84,6 @@ test "pass zero length array to var args param" {
doNothingWithFirstArg("");
}
-fn doNothingWithFirstArg(args: ...) {
+fn doNothingWithFirstArg(args: ...) void {
const a = args[0];
}
diff --git a/test/cases/while.zig b/test/cases/while.zig
index f1e269b9fd..5970e742ea 100644
--- a/test/cases/while.zig
+++ b/test/cases/while.zig
@@ -8,10 +8,10 @@ test "while loop" {
assert(i == 4);
assert(whileLoop1() == 1);
}
-fn whileLoop1() -> i32 {
+fn whileLoop1() i32 {
return whileLoop2();
}
-fn whileLoop2() -> i32 {
+fn whileLoop2() i32 {
while (true) {
return 1;
}
@@ -20,10 +20,10 @@ test "static eval while" {
assert(static_eval_while_number == 1);
}
const static_eval_while_number = staticWhileLoop1();
-fn staticWhileLoop1() -> i32 {
+fn staticWhileLoop1() i32 {
return whileLoop2();
}
-fn staticWhileLoop2() -> i32 {
+fn staticWhileLoop2() i32 {
while (true) {
return 1;
}
@@ -34,7 +34,7 @@ test "continue and break" {
assert(continue_and_break_counter == 8);
}
var continue_and_break_counter: i32 = 0;
-fn runContinueAndBreakTest() {
+fn runContinueAndBreakTest() void {
var i : i32 = 0;
while (true) {
continue_and_break_counter += 2;
@@ -50,7 +50,7 @@ fn runContinueAndBreakTest() {
test "return with implicit cast from while loop" {
returnWithImplicitCastFromWhileLoopTest() catch unreachable;
}
-fn returnWithImplicitCastFromWhileLoopTest() -> %void {
+fn returnWithImplicitCastFromWhileLoopTest() %void {
while (true) {
return;
}
@@ -117,7 +117,7 @@ test "while with error union condition" {
var numbers_left: i32 = undefined;
error OutOfNumbers;
-fn getNumberOrErr() -> %i32 {
+fn getNumberOrErr() %i32 {
return if (numbers_left == 0)
error.OutOfNumbers
else x: {
@@ -125,7 +125,7 @@ fn getNumberOrErr() -> %i32 {
break :x numbers_left;
};
}
-fn getNumberOrNull() -> ?i32 {
+fn getNumberOrNull() ?i32 {
return if (numbers_left == 0)
null
else x: {
@@ -181,7 +181,7 @@ test "break from outer while loop" {
comptime testBreakOuter();
}
-fn testBreakOuter() {
+fn testBreakOuter() void {
outer: while (true) {
while (true) {
break :outer;
@@ -194,7 +194,7 @@ test "continue outer while loop" {
comptime testContinueOuter();
}
-fn testContinueOuter() {
+fn testContinueOuter() void {
var i: usize = 0;
outer: while (i < 10) : (i += 1) {
while (true) {
@@ -203,10 +203,10 @@ fn testContinueOuter() {
}
}
-fn returnNull() -> ?i32 { return null; }
-fn returnMaybe(x: i32) -> ?i32 { return x; }
+fn returnNull() ?i32 { return null; }
+fn returnMaybe(x: i32) ?i32 { return x; }
error YouWantedAnError;
-fn returnError() -> %i32 { return error.YouWantedAnError; }
-fn returnSuccess(x: i32) -> %i32 { return x; }
-fn returnFalse() -> bool { return false; }
-fn returnTrue() -> bool { return true; }
+fn returnError() %i32 { return error.YouWantedAnError; }
+fn returnSuccess(x: i32) %i32 { return x; }
+fn returnFalse() bool { return false; }
+fn returnTrue() bool { return true; }
diff --git a/test/compare_output.zig b/test/compare_output.zig
index 1af94f9f4a..6e379c8d1e 100644
--- a/test/compare_output.zig
+++ b/test/compare_output.zig
@@ -1,10 +1,10 @@
const os = @import("std").os;
const tests = @import("tests.zig");
-pub fn addCases(cases: &tests.CompareOutputContext) {
+pub fn addCases(cases: &tests.CompareOutputContext) void {
cases.addC("hello world with libc",
\\const c = @cImport(@cInclude("stdio.h"));
- \\export fn main(argc: c_int, argv: &&u8) -> c_int {
+ \\export fn main(argc: c_int, argv: &&u8) c_int {
\\ _ = c.puts(c"Hello, world!");
\\ return 0;
\\}
@@ -15,13 +15,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\use @import("std").io;
\\use @import("foo.zig");
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ privateFunction();
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
\\ stdout.print("OK 2\n") catch unreachable;
\\}
\\
- \\fn privateFunction() {
+ \\fn privateFunction() void {
\\ printText();
\\}
, "OK 1\nOK 2\n");
@@ -31,12 +31,12 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\
\\// purposefully conflicting function with main.zig
\\// but it's private so it should be OK
- \\fn privateFunction() {
+ \\fn privateFunction() void {
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
\\ stdout.print("OK 1\n") catch unreachable;
\\}
\\
- \\pub fn printText() {
+ \\pub fn printText() void {
\\ privateFunction();
\\}
);
@@ -49,7 +49,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\use @import("foo.zig");
\\use @import("bar.zig");
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ foo_function();
\\ bar_function();
\\}
@@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
tc.addSourceFile("foo.zig",
\\use @import("std").io;
- \\pub fn foo_function() {
+ \\pub fn foo_function() void {
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
\\ stdout.print("OK\n") catch unreachable;
\\}
@@ -67,7 +67,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\use @import("other.zig");
\\use @import("std").io;
\\
- \\pub fn bar_function() {
+ \\pub fn bar_function() void {
\\ if (foo_function()) {
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
\\ stdout.print("OK\n") catch unreachable;
@@ -76,7 +76,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
);
tc.addSourceFile("other.zig",
- \\pub fn foo_function() -> bool {
+ \\pub fn foo_function() bool {
\\ // this one conflicts with the one from foo
\\ return true;
\\}
@@ -89,7 +89,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
var tc = cases.create("two files use import each other",
\\use @import("a.zig");
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ ok();
\\}
, "OK\n");
@@ -100,7 +100,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\
\\pub const a_text = "OK\n";
\\
- \\pub fn ok() {
+ \\pub fn ok() void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print(b_text) catch unreachable;
\\}
@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
cases.add("hello world without libc",
\\const io = @import("std").io;
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
\\}
@@ -137,7 +137,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ @cInclude("stdio.h");
\\});
\\
- \\export fn main(argc: c_int, argv: &&u8) -> c_int {
+ \\export fn main(argc: c_int, argv: &&u8) c_int {
\\ if (is_windows) {
\\ // we want actual \n, not \r\n
\\ _ = c._setmode(1, c._O_BINARY);
@@ -268,10 +268,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const z = io.stdin_fileno;
\\const x : @typeOf(y) = 1234;
\\const y : u16 = 5678;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ var x_local : i32 = print_ok(x);
\\}
- \\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) {
+ \\fn print_ok(val: @typeOf(x)) @typeOf(foo) {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print("OK\n") catch unreachable;
\\ return 0;
@@ -282,7 +282,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
cases.addC("expose function pointer to C land",
\\const c = @cImport(@cInclude("stdlib.h"));
\\
- \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
+ \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) c_int {
\\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);
\\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);
\\ if (*a_int < *b_int) {
@@ -294,7 +294,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ }
\\}
\\
- \\export fn main() -> c_int {
+ \\export fn main() c_int {
\\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
\\
\\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
@@ -322,7 +322,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ @cInclude("stdio.h");
\\});
\\
- \\export fn main(argc: c_int, argv: &&u8) -> c_int {
+ \\export fn main(argc: c_int, argv: &&u8) c_int {
\\ if (is_windows) {
\\ // we want actual \n, not \r\n
\\ _ = c._setmode(1, c._O_BINARY);
@@ -342,16 +342,16 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const Foo = struct {
\\ field1: Bar,
\\
- \\ fn method(a: &const Foo) -> bool { return true; }
+ \\ fn method(a: &const Foo) bool { return true; }
\\};
\\
\\const Bar = struct {
\\ field2: i32,
\\
- \\ fn method(b: &const Bar) -> bool { return true; }
+ \\ fn method(b: &const Bar) bool { return true; }
\\};
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const bar = Bar {.field2 = 13,};
\\ const foo = Foo {.field1 = bar,};
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
@@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
cases.add("defer with only fallthrough",
\\const io = @import("std").io;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print("before\n") catch unreachable;
\\ defer stdout.print("defer1\n") catch unreachable;
@@ -380,7 +380,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
cases.add("defer with return",
\\const io = @import("std").io;
\\const os = @import("std").os;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print("before\n") catch unreachable;
\\ defer stdout.print("defer1\n") catch unreachable;
@@ -394,10 +394,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
cases.add("errdefer and it fails",
\\const io = @import("std").io;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ do_test() catch return;
\\}
- \\fn do_test() -> %void {
+ \\fn do_test() %void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print("before\n") catch unreachable;
\\ defer stdout.print("defer1\n") catch unreachable;
@@ -407,17 +407,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ stdout.print("after\n") catch unreachable;
\\}
\\error IToldYouItWouldFail;
- \\fn its_gonna_fail() -> %void {
+ \\fn its_gonna_fail() %void {
\\ return error.IToldYouItWouldFail;
\\}
, "before\ndeferErr\ndefer1\n");
cases.add("errdefer and it passes",
\\const io = @import("std").io;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ do_test() catch return;
\\}
- \\fn do_test() -> %void {
+ \\fn do_test() %void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print("before\n") catch unreachable;
\\ defer stdout.print("defer1\n") catch unreachable;
@@ -426,7 +426,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ defer stdout.print("defer3\n") catch unreachable;
\\ stdout.print("after\n") catch unreachable;
\\}
- \\fn its_gonna_pass() -> %void { }
+ \\fn its_gonna_pass() %void { }
, "before\nafter\ndefer3\ndefer1\n");
cases.addCase(x: {
@@ -434,7 +434,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const foo_txt = @embedFile("foo.txt");
\\const io = @import("std").io;
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
\\ stdout.print(foo_txt) catch unreachable;
\\}
@@ -452,7 +452,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const os = std.os;
\\const allocator = std.debug.global_allocator;
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ var args_it = os.args();
\\ var stdout_file = try io.getStdOut();
\\ var stdout_adapter = io.FileOutStream.init(&stdout_file);
@@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const os = std.os;
\\const allocator = std.debug.global_allocator;
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ var args_it = os.args();
\\ var stdout_file = try io.getStdOut();
\\ var stdout_adapter = io.FileOutStream.init(&stdout_file);
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index b98b88468c..cc28f29f26 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -1,9 +1,9 @@
const tests = @import("tests.zig");
-pub fn addCases(cases: &tests.CompileErrorContext) {
+pub fn addCases(cases: &tests.CompileErrorContext) void {
cases.add("function with non-extern enum parameter",
\\const Foo = enum { A, B, C };
- \\export fn entry(foo: Foo) { }
+ \\export fn entry(foo: Foo) void { }
, ".tmp_source.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'");
cases.add("function with non-extern struct parameter",
@@ -12,7 +12,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B: f32,
\\ C: bool,
\\};
- \\export fn entry(foo: Foo) { }
+ \\export fn entry(foo: Foo) void { }
, ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'");
cases.add("function with non-extern union parameter",
@@ -21,13 +21,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B: f32,
\\ C: bool,
\\};
- \\export fn entry(foo: Foo) { }
+ \\export fn entry(foo: Foo) void { }
, ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'");
cases.add("switch on enum with 1 field with no prongs",
\\const Foo = enum { M };
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var f = Foo.M;
\\ switch (f) {}
\\}
@@ -40,7 +40,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:2:18: error: shift by negative value -1");
cases.add("@panic called at compile time",
- \\export fn entry() {
+ \\export fn entry() void {
\\ comptime {
\\ @panic("aoeu");
\\ }
@@ -48,16 +48,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:3:9: error: encountered @panic at compile-time");
cases.add("wrong return type for main",
- \\pub fn main() -> f32 { }
+ \\pub fn main() f32 { }
, "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'");
cases.add("double ?? on main return value",
- \\pub fn main() -> ??void {
+ \\pub fn main() ??void {
\\}
, "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'");
cases.add("bad identifier in function with struct defined inside function which references local const",
- \\export fn entry() {
+ \\export fn entry() void {
\\ const BlockKind = u32;
\\
\\ const Block = struct {
@@ -69,7 +69,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:8:5: error: use of undeclared identifier 'bogus'");
cases.add("labeled break not found",
- \\export fn entry() {
+ \\export fn entry() void {
\\ blah: while (true) {
\\ while (true) {
\\ break :outer;
@@ -79,7 +79,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:4:13: error: label not found: 'outer'");
cases.add("labeled continue not found",
- \\export fn entry() {
+ \\export fn entry() void {
\\ var i: usize = 0;
\\ blah: while (i < 10) : (i += 1) {
\\ while (true) {
@@ -90,17 +90,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:13: error: labeled loop not found: 'outer'");
cases.add("attempt to use 0 bit type in extern fn",
- \\extern fn foo(ptr: extern fn(&void));
+ \\extern fn foo(ptr: extern fn(&void) void) void;
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ foo(bar);
\\}
\\
- \\extern fn bar(x: &void) { }
+ \\extern fn bar(x: &void) void { }
, ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'");
cases.add("implicit semicolon - block statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ {}
\\ var good = {};
\\ ({})
@@ -109,7 +109,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - block expr",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = {};
\\ var good = {};
\\ _ = {}
@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - comptime statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ comptime {}
\\ var good = {};
\\ comptime ({})
@@ -127,7 +127,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - comptime expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = comptime {};
\\ var good = {};
\\ _ = comptime {}
@@ -136,7 +136,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - defer",
- \\export fn entry() {
+ \\export fn entry() void {
\\ defer {}
\\ var good = {};
\\ defer ({})
@@ -145,7 +145,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ if(true) {}
\\ var good = {};
\\ if(true) ({})
@@ -154,7 +154,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = if(true) {};
\\ var good = {};
\\ _ = if(true) {}
@@ -163,7 +163,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if-else statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ if(true) {} else {}
\\ var good = {};
\\ if(true) ({}) else ({})
@@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if-else expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = if(true) {} else {};
\\ var good = {};
\\ _ = if(true) {} else {}
@@ -181,7 +181,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if-else-if statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ if(true) {} else if(true) {}
\\ var good = {};
\\ if(true) ({}) else if(true) ({})
@@ -190,7 +190,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if-else-if expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = if(true) {} else if(true) {};
\\ var good = {};
\\ _ = if(true) {} else if(true) {}
@@ -199,7 +199,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if-else-if-else statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ if(true) {} else if(true) {} else {}
\\ var good = {};
\\ if(true) ({}) else if(true) ({}) else ({})
@@ -208,7 +208,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - if-else-if-else expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = if(true) {} else if(true) {} else {};
\\ var good = {};
\\ _ = if(true) {} else if(true) {} else {}
@@ -217,7 +217,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - test statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ if (foo()) |_| {}
\\ var good = {};
\\ if (foo()) |_| ({})
@@ -226,7 +226,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - test expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = if (foo()) |_| {};
\\ var good = {};
\\ _ = if (foo()) |_| {}
@@ -235,7 +235,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - while statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ while(true) {}
\\ var good = {};
\\ while(true) ({})
@@ -244,7 +244,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - while expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = while(true) {};
\\ var good = {};
\\ _ = while(true) {}
@@ -253,7 +253,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - while-continue statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ while(true):({}) {}
\\ var good = {};
\\ while(true):({}) ({})
@@ -262,7 +262,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - while-continue expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = while(true):({}) {};
\\ var good = {};
\\ _ = while(true):({}) {}
@@ -271,7 +271,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - for statement",
- \\export fn entry() {
+ \\export fn entry() void {
\\ for(foo()) {}
\\ var good = {};
\\ for(foo()) ({})
@@ -280,7 +280,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("implicit semicolon - for expression",
- \\export fn entry() {
+ \\export fn entry() void {
\\ _ = for(foo()) {};
\\ var good = {};
\\ _ = for(foo()) {}
@@ -289,60 +289,60 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
cases.add("multiple function definitions",
- \\fn a() {}
- \\fn a() {}
- \\export fn entry() { a(); }
+ \\fn a() void {}
+ \\fn a() void {}
+ \\export fn entry() void { a(); }
, ".tmp_source.zig:2:1: error: redefinition of 'a'");
cases.add("unreachable with return",
- \\fn a() -> noreturn {return;}
- \\export fn entry() { a(); }
- , ".tmp_source.zig:1:21: error: expected type 'noreturn', found 'void'");
+ \\fn a() noreturn {return;}
+ \\export fn entry() void { a(); }
+ , ".tmp_source.zig:1:18: error: expected type 'noreturn', found 'void'");
cases.add("control reaches end of non-void function",
- \\fn a() -> i32 {}
- \\export fn entry() { _ = a(); }
- , ".tmp_source.zig:1:15: error: expected type 'i32', found 'void'");
+ \\fn a() i32 {}
+ \\export fn entry() void { _ = a(); }
+ , ".tmp_source.zig:1:12: error: expected type 'i32', found 'void'");
cases.add("undefined function call",
- \\export fn a() {
+ \\export fn a() void {
\\ b();
\\}
, ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");
cases.add("wrong number of arguments",
- \\export fn a() {
+ \\export fn a() void {
\\ b(1);
\\}
- \\fn b(a: i32, b: i32, c: i32) { }
+ \\fn b(a: i32, b: i32, c: i32) void { }
, ".tmp_source.zig:2:6: error: expected 3 arguments, found 1");
cases.add("invalid type",
- \\fn a() -> bogus {}
- \\export fn entry() { _ = a(); }
- , ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'");
+ \\fn a() bogus {}
+ \\export fn entry() void { _ = a(); }
+ , ".tmp_source.zig:1:8: error: use of undeclared identifier 'bogus'");
cases.add("pointer to unreachable",
- \\fn a() -> &noreturn {}
- \\export fn entry() { _ = a(); }
- , ".tmp_source.zig:1:12: error: pointer to unreachable not allowed");
+ \\fn a() &noreturn {}
+ \\export fn entry() void { _ = a(); }
+ , ".tmp_source.zig:1:9: error: pointer to unreachable not allowed");
cases.add("unreachable code",
- \\export fn a() {
+ \\export fn a() void {
\\ return;
\\ b();
\\}
\\
- \\fn b() {}
+ \\fn b() void {}
, ".tmp_source.zig:3:5: error: unreachable code");
cases.add("bad import",
\\const bogus = @import("bogus-does-not-exist.zig");
- \\export fn entry() { bogus.bogo(); }
+ \\export fn entry() void { bogus.bogo(); }
, ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'");
cases.add("undeclared identifier",
- \\export fn a() {
+ \\export fn a() void {
\\ return
\\ b +
\\ c;
@@ -352,89 +352,89 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
cases.add("parameter redeclaration",
- \\fn f(a : i32, a : i32) {
+ \\fn f(a : i32, a : i32) void {
\\}
- \\export fn entry() { f(1, 2); }
+ \\export fn entry() void { f(1, 2); }
, ".tmp_source.zig:1:15: error: redeclaration of variable 'a'");
cases.add("local variable redeclaration",
- \\export fn f() {
+ \\export fn f() void {
\\ const a : i32 = 0;
\\ const a = 0;
\\}
, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");
cases.add("local variable redeclares parameter",
- \\fn f(a : i32) {
+ \\fn f(a : i32) void {
\\ const a = 0;
\\}
- \\export fn entry() { f(1); }
+ \\export fn entry() void { f(1); }
, ".tmp_source.zig:2:5: error: redeclaration of variable 'a'");
cases.add("variable has wrong type",
- \\export fn f() -> i32 {
+ \\export fn f() i32 {
\\ const a = c"a";
\\ return a;
\\}
, ".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'");
cases.add("if condition is bool, not int",
- \\export fn f() {
+ \\export fn f() void {
\\ if (0) {}
\\}
, ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'");
cases.add("assign unreachable",
- \\export fn f() {
+ \\export fn f() void {
\\ const a = return;
\\}
, ".tmp_source.zig:2:5: error: unreachable code");
cases.add("unreachable variable",
- \\export fn f() {
+ \\export fn f() void {
\\ const a: noreturn = {};
\\}
, ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed");
cases.add("unreachable parameter",
- \\fn f(a: noreturn) {}
- \\export fn entry() { f(); }
+ \\fn f(a: noreturn) void {}
+ \\export fn entry() void { f(); }
, ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed");
cases.add("bad assignment target",
- \\export fn f() {
+ \\export fn f() void {
\\ 3 = 3;
\\}
, ".tmp_source.zig:2:7: error: cannot assign to constant");
cases.add("assign to constant variable",
- \\export fn f() {
+ \\export fn f() void {
\\ const a = 3;
\\ a = 4;
\\}
, ".tmp_source.zig:3:7: error: cannot assign to constant");
cases.add("use of undeclared identifier",
- \\export fn f() {
+ \\export fn f() void {
\\ b = 3;
\\}
, ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");
cases.add("const is a statement, not an expression",
- \\export fn f() {
+ \\export fn f() void {
\\ (const a = 0);
\\}
, ".tmp_source.zig:2:6: error: invalid token: 'const'");
cases.add("array access of undeclared identifier",
- \\export fn f() {
+ \\export fn f() void {
\\ i[i] = i[i];
\\}
, ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'",
".tmp_source.zig:2:12: error: use of undeclared identifier 'i'");
cases.add("array access of non array",
- \\export fn f() {
+ \\export fn f() void {
\\ var bad : bool = undefined;
\\ bad[bad] = bad[bad];
\\}
@@ -442,7 +442,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:19: error: array access of non-array type 'bool'");
cases.add("array access with non integer index",
- \\export fn f() {
+ \\export fn f() void {
\\ var array = "aoeu";
\\ var bad = false;
\\ array[bad] = array[bad];
@@ -452,37 +452,37 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("write to const global variable",
\\const x : i32 = 99;
- \\fn f() {
+ \\fn f() void {
\\ x = 1;
\\}
- \\export fn entry() { f(); }
+ \\export fn entry() void { f(); }
, ".tmp_source.zig:3:7: error: cannot assign to constant");
cases.add("missing else clause",
- \\fn f(b: bool) {
+ \\fn f(b: bool) void {
\\ const x : i32 = if (b) h: { break :h 1; };
\\ const y = if (b) h: { break :h i32(1); };
\\}
- \\export fn entry() { f(true); }
+ \\export fn entry() void { f(true); }
, ".tmp_source.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");
cases.add("direct struct loop",
\\const A = struct { a : A, };
- \\export fn entry() -> usize { return @sizeOf(A); }
+ \\export fn entry() usize { return @sizeOf(A); }
, ".tmp_source.zig:1:11: error: struct 'A' contains itself");
cases.add("indirect struct loop",
\\const A = struct { b : B, };
\\const B = struct { c : C, };
\\const C = struct { a : A, };
- \\export fn entry() -> usize { return @sizeOf(A); }
+ \\export fn entry() usize { return @sizeOf(A); }
, ".tmp_source.zig:1:11: error: struct 'A' contains itself");
cases.add("invalid struct field",
\\const A = struct { x : i32, };
- \\export fn f() {
+ \\export fn f() void {
\\ var a : A = undefined;
\\ a.foo = 1;
\\ const y = a.bar;
@@ -514,7 +514,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ y : i32,
\\ z : i32,
\\};
- \\export fn f() {
+ \\export fn f() void {
\\ const a = A {
\\ .z = 1,
\\ .y = 2,
@@ -530,7 +530,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ y : i32,
\\ z : i32,
\\};
- \\export fn f() {
+ \\export fn f() void {
\\ // we want the error on the '{' not the 'A' because
\\ // the A could be a complicated expression
\\ const a = A {
@@ -546,7 +546,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ y : i32,
\\ z : i32,
\\};
- \\export fn f() {
+ \\export fn f() void {
\\ const a = A {
\\ .z = 4,
\\ .y = 2,
@@ -556,57 +556,57 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'");
cases.add("invalid break expression",
- \\export fn f() {
+ \\export fn f() void {
\\ break;
\\}
, ".tmp_source.zig:2:5: error: break expression outside loop");
cases.add("invalid continue expression",
- \\export fn f() {
+ \\export fn f() void {
\\ continue;
\\}
, ".tmp_source.zig:2:5: error: continue expression outside loop");
cases.add("invalid maybe type",
- \\export fn f() {
+ \\export fn f() void {
\\ if (true) |x| { }
\\}
, ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'");
cases.add("cast unreachable",
- \\fn f() -> i32 {
+ \\fn f() i32 {
\\ return i32(return 1);
\\}
- \\export fn entry() { _ = f(); }
+ \\export fn entry() void { _ = f(); }
, ".tmp_source.zig:2:15: error: unreachable code");
cases.add("invalid builtin fn",
- \\fn f() -> @bogus(foo) {
+ \\fn f() @bogus(foo) {
\\}
- \\export fn entry() { _ = f(); }
- , ".tmp_source.zig:1:11: error: invalid builtin function: 'bogus'");
+ \\export fn entry() void { _ = f(); }
+ , ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'");
cases.add("top level decl dependency loop",
\\const a : @typeOf(b) = 0;
\\const b : @typeOf(a) = 0;
- \\export fn entry() {
+ \\export fn entry() void {
\\ const c = a + b;
\\}
, ".tmp_source.zig:1:1: error: 'a' depends on itself");
cases.add("noalias on non pointer param",
- \\fn f(noalias x: i32) {}
- \\export fn entry() { f(1234); }
+ \\fn f(noalias x: i32) void {}
+ \\export fn entry() void { f(1234); }
, ".tmp_source.zig:1:6: error: noalias on non-pointer parameter");
cases.add("struct init syntax for array",
\\const foo = []u16{.x = 1024,};
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");
cases.add("type variables must be constant",
\\var foo = u8;
- \\export fn entry() -> foo {
+ \\export fn entry() foo {
\\ return 1;
\\}
, ".tmp_source.zig:1:1: error: variable of type 'type' must be constant");
@@ -616,11 +616,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = struct {};
\\const Bar = struct {};
\\
- \\fn f(Foo: i32) {
+ \\fn f(Foo: i32) void {
\\ var Bar : i32 = undefined;
\\}
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ f(1234);
\\}
,
@@ -636,7 +636,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Three,
\\ Four,
\\};
- \\fn f(n: Number) -> i32 {
+ \\fn f(n: Number) i32 {
\\ switch (n) {
\\ Number.One => 1,
\\ Number.Two => 2,
@@ -644,7 +644,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ }
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");
cases.add("switch expression - duplicate enumeration prong",
@@ -654,7 +654,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Three,
\\ Four,
\\};
- \\fn f(n: Number) -> i32 {
+ \\fn f(n: Number) i32 {
\\ switch (n) {
\\ Number.One => 1,
\\ Number.Two => 2,
@@ -664,7 +664,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ }
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:13:15: error: duplicate switch value",
".tmp_source.zig:10:15: note: other value is here");
@@ -675,7 +675,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Three,
\\ Four,
\\};
- \\fn f(n: Number) -> i32 {
+ \\fn f(n: Number) i32 {
\\ switch (n) {
\\ Number.One => 1,
\\ Number.Two => 2,
@@ -686,35 +686,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ }
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:13:15: error: duplicate switch value",
".tmp_source.zig:10:15: note: other value is here");
cases.add("switch expression - multiple else prongs",
- \\fn f(x: u32) {
+ \\fn f(x: u32) void {
\\ const value: bool = switch (x) {
\\ 1234 => false,
\\ else => true,
\\ else => true,
\\ };
\\}
- \\export fn entry() {
+ \\export fn entry() void {
\\ f(1234);
\\}
, ".tmp_source.zig:5:9: error: multiple else prongs in switch expression");
cases.add("switch expression - non exhaustive integer prongs",
- \\fn foo(x: u8) {
+ \\fn foo(x: u8) void {
\\ switch (x) {
\\ 0 => {},
\\ }
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
,
".tmp_source.zig:2:5: error: switch must handle all possibilities");
cases.add("switch expression - duplicate or overlapping integer value",
- \\fn foo(x: u8) -> u8 {
+ \\fn foo(x: u8) u8 {
\\ return switch (x) {
\\ 0 ... 100 => u8(0),
\\ 101 ... 200 => 1,
@@ -722,26 +722,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ 206 ... 255 => 3,
\\ };
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
,
".tmp_source.zig:6:9: error: duplicate switch value",
".tmp_source.zig:5:14: note: previous value is here");
cases.add("switch expression - switch on pointer type with no else",
- \\fn foo(x: &u8) {
+ \\fn foo(x: &u8) void {
\\ switch (x) {
\\ &y => {},
\\ }
\\}
\\const y: u8 = 100;
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
,
".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");
cases.add("global variable initializer must be constant expression",
- \\extern fn foo() -> i32;
+ \\extern fn foo() i32;
\\const x = foo();
- \\export fn entry() -> i32 { return x; }
+ \\export fn entry() i32 { return x; }
, ".tmp_source.zig:2:11: error: unable to evaluate constant expression");
cases.add("array concatenation with wrong type",
@@ -749,38 +749,38 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const derp = usize(1234);
\\const a = derp ++ "foo";
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
, ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");
cases.add("non compile time array concatenation",
- \\fn f() -> []u8 {
+ \\fn f() []u8 {
\\ return s ++ "foo";
\\}
\\var s: [10]u8 = undefined;
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:2:12: error: unable to evaluate constant expression");
cases.add("@cImport with bogus include",
\\const c = @cImport(@cInclude("bogus.h"));
- \\export fn entry() -> usize { return @sizeOf(@typeOf(c.bogo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); }
, ".tmp_source.zig:1:11: error: C import failed",
".h:1:10: note: 'bogus.h' file not found");
cases.add("address of number literal",
\\const x = 3;
\\const y = &x;
- \\fn foo() -> &const i32 { return y; }
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
- , ".tmp_source.zig:3:33: error: expected type '&const i32', found '&const (integer literal)'");
+ \\fn foo() &const i32 { return y; }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
+ , ".tmp_source.zig:3:30: error: expected type '&const i32', found '&const (integer literal)'");
cases.add("integer overflow error",
\\const x : u8 = 300;
- \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
, ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");
cases.add("incompatible number literals",
\\const x = 2 == 2.0;
- \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
, ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");
cases.add("missing function call param",
@@ -788,10 +788,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ a: i32,
\\ b: i32,
\\
- \\ fn member_a(foo: &const Foo) -> i32 {
+ \\ fn member_a(foo: &const Foo) i32 {
\\ return foo.a;
\\ }
- \\ fn member_b(foo: &const Foo) -> i32 {
+ \\ fn member_b(foo: &const Foo) i32 {
\\ return foo.b;
\\ }
\\};
@@ -802,59 +802,59 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Foo.member_b,
\\};
\\
- \\fn f(foo: &const Foo, index: usize) {
+ \\fn f(foo: &const Foo, index: usize) void {
\\ const result = members[index]();
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");
cases.add("missing function name and param name",
- \\fn () {}
- \\fn f(i32) {}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\fn () void {}
+ \\fn f(i32) void {}
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
,
".tmp_source.zig:1:1: error: missing function name",
".tmp_source.zig:2:6: error: missing parameter name");
cases.add("wrong function type",
- \\const fns = []fn(){ a, b, c };
- \\fn a() -> i32 {return 0;}
- \\fn b() -> i32 {return 1;}
- \\fn c() -> i32 {return 2;}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); }
- , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'");
+ \\const fns = []fn() void { a, b, c };
+ \\fn a() i32 {return 0;}
+ \\fn b() i32 {return 1;}
+ \\fn c() i32 {return 2;}
+ \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
+ , ".tmp_source.zig:1:27: error: expected type 'fn() void', found 'fn() i32'");
cases.add("extern function pointer mismatch",
- \\const fns = [](fn(i32)->i32){ a, b, c };
- \\pub fn a(x: i32) -> i32 {return x + 0;}
- \\pub fn b(x: i32) -> i32 {return x + 1;}
- \\export fn c(x: i32) -> i32 {return x + 2;}
+ \\const fns = [](fn(i32)i32) { a, b, c };
+ \\pub fn a(x: i32) i32 {return x + 0;}
+ \\pub fn b(x: i32) i32 {return x + 1;}
+ \\export fn c(x: i32) i32 {return x + 2;}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); }
- , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");
+ \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
+ , ".tmp_source.zig:1:36: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'");
cases.add("implicit cast from f64 to f32",
\\const x : f64 = 1.0;
\\const y : f32 = x;
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
, ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");
cases.add("colliding invalid top level functions",
- \\fn func() -> bogus {}
- \\fn func() -> bogus {}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(func)); }
+ \\fn func() bogus {}
+ \\fn func() bogus {}
+ \\export fn entry() usize { return @sizeOf(@typeOf(func)); }
,
".tmp_source.zig:2:1: error: redefinition of 'func'",
- ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'");
+ ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'");
cases.add("bogus compile var",
\\const x = @import("builtin").bogus;
- \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
, ".tmp_source.zig:1:29: error: no member named 'bogus' in '");
@@ -863,11 +863,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ y: [get()]u8,
\\};
\\var global_var: usize = 1;
- \\fn get() -> usize { return global_var; }
+ \\fn get() usize { return global_var; }
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(Foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
,
- ".tmp_source.zig:5:28: error: unable to evaluate constant expression",
+ ".tmp_source.zig:5:25: error: unable to evaluate constant expression",
".tmp_source.zig:2:12: note: called from here",
".tmp_source.zig:2:8: note: called from here");
@@ -878,7 +878,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\};
\\const x = Foo {.field = 1} + Foo {.field = 2};
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
, ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");
@@ -888,10 +888,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const int_x = u32(1) / u32(0);
\\const float_x = f32(1.0) / f32(0.0);
\\
- \\export fn entry1() -> usize { return @sizeOf(@typeOf(lit_int_x)); }
- \\export fn entry2() -> usize { return @sizeOf(@typeOf(lit_float_x)); }
- \\export fn entry3() -> usize { return @sizeOf(@typeOf(int_x)); }
- \\export fn entry4() -> usize { return @sizeOf(@typeOf(float_x)); }
+ \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
+ \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }
+ \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); }
+ \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); }
,
".tmp_source.zig:1:21: error: division by zero",
".tmp_source.zig:2:25: error: division by zero",
@@ -903,45 +903,45 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const foo = "a
\\b";
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:1:13: error: newline not allowed in string literal");
cases.add("invalid comparison for function pointers",
- \\fn foo() {}
+ \\fn foo() void {}
\\const invalid = foo > foo;
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(invalid)); }
- , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'");
+ \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); }
+ , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn() void'");
cases.add("generic function instance with non-constant expression",
- \\fn foo(comptime x: i32, y: i32) -> i32 { return x + y; }
- \\fn test1(a: i32, b: i32) -> i32 {
+ \\fn foo(comptime x: i32, y: i32) i32 { return x + y; }
+ \\fn test1(a: i32, b: i32) i32 {
\\ return foo(a, b);
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(test1)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(test1)); }
, ".tmp_source.zig:3:16: error: unable to evaluate constant expression");
cases.add("assign null to non-nullable pointer",
\\const a: &u8 = null;
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
, ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");
cases.add("indexing an array of size zero",
\\const array = []u8{};
- \\export fn foo() {
+ \\export fn foo() void {
\\ const pointer = &array[0];
\\}
, ".tmp_source.zig:3:27: error: index 0 outside array of size 0");
cases.add("compile time division by zero",
\\const y = foo(0);
- \\fn foo(x: u32) -> u32 {
+ \\fn foo(x: u32) u32 {
\\ return 1 / x;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
,
".tmp_source.zig:3:14: error: division by zero",
".tmp_source.zig:1:14: note: called from here");
@@ -949,17 +949,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("branch on undefined value",
\\const x = if (undefined) true else false;
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
, ".tmp_source.zig:1:15: error: use of undefined value");
cases.add("endless loop in function evaluation",
\\const seventh_fib_number = fibbonaci(7);
- \\fn fibbonaci(x: i32) -> i32 {
+ \\fn fibbonaci(x: i32) i32 {
\\ return fibbonaci(x - 1) + fibbonaci(x - 2);
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(seventh_fib_number)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }
,
".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",
".tmp_source.zig:3:21: note: called from here");
@@ -967,7 +967,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("@embedFile with bogus file",
\\const resource = @embedFile("bogus.txt");
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(resource)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(resource)); }
, ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");
cases.add("non-const expression in struct literal outside function",
@@ -975,9 +975,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ x: i32,
\\};
\\const a = Foo {.x = get_it()};
- \\extern fn get_it() -> i32;
+ \\extern fn get_it() i32;
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
, ".tmp_source.zig:4:21: error: unable to evaluate constant expression");
cases.add("non-const expression function call with struct return value outside function",
@@ -985,60 +985,60 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ x: i32,
\\};
\\const a = get_it();
- \\fn get_it() -> Foo {
+ \\fn get_it() Foo {
\\ global_side_effect = true;
\\ return Foo {.x = 13};
\\}
\\var global_side_effect = false;
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
,
".tmp_source.zig:6:24: error: unable to evaluate constant expression",
".tmp_source.zig:4:17: note: called from here");
cases.add("undeclared identifier error should mark fn as impure",
- \\export fn foo() {
+ \\export fn foo() void {
\\ test_a_thing();
\\}
- \\fn test_a_thing() {
+ \\fn test_a_thing() void {
\\ bad_fn_call();
\\}
, ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'");
cases.add("illegal comparison of types",
- \\fn bad_eql_1(a: []u8, b: []u8) -> bool {
+ \\fn bad_eql_1(a: []u8, b: []u8) bool {
\\ return a == b;
\\}
\\const EnumWithData = union(enum) {
\\ One: void,
\\ Two: i32,
\\};
- \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) -> bool {
+ \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) bool {
\\ return *a == *b;
\\}
\\
- \\export fn entry1() -> usize { return @sizeOf(@typeOf(bad_eql_1)); }
- \\export fn entry2() -> usize { return @sizeOf(@typeOf(bad_eql_2)); }
+ \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); }
+ \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); }
,
".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'",
".tmp_source.zig:9:15: error: operator not allowed for type 'EnumWithData'");
cases.add("non-const switch number literal",
- \\export fn foo() {
+ \\export fn foo() void {
\\ const x = switch (bar()) {
\\ 1, 2 => 1,
\\ 3, 4 => 2,
\\ else => 3,
\\ };
\\}
- \\fn bar() -> i32 {
+ \\fn bar() i32 {
\\ return 2;
\\}
, ".tmp_source.zig:2:15: error: unable to infer expression type");
cases.add("atomic orderings of cmpxchg - failure stricter than success",
\\const AtomicOrder = @import("builtin").AtomicOrder;
- \\export fn f() {
+ \\export fn f() void {
\\ var x: i32 = 1234;
\\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
\\}
@@ -1046,7 +1046,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
\\const AtomicOrder = @import("builtin").AtomicOrder;
- \\export fn f() {
+ \\export fn f() void {
\\ var x: i32 = 1234;
\\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
\\}
@@ -1054,22 +1054,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("negation overflow in function evaluation",
\\const y = neg(-128);
- \\fn neg(x: i8) -> i8 {
+ \\fn neg(x: i8) i8 {
\\ return -x;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
,
".tmp_source.zig:3:12: error: negation caused overflow",
".tmp_source.zig:1:14: note: called from here");
cases.add("add overflow in function evaluation",
\\const y = add(65530, 10);
- \\fn add(a: u16, b: u16) -> u16 {
+ \\fn add(a: u16, b: u16) u16 {
\\ return a + b;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
,
".tmp_source.zig:3:14: error: operation caused overflow",
".tmp_source.zig:1:14: note: called from here");
@@ -1077,47 +1077,47 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("sub overflow in function evaluation",
\\const y = sub(10, 20);
- \\fn sub(a: u16, b: u16) -> u16 {
+ \\fn sub(a: u16, b: u16) u16 {
\\ return a - b;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
,
".tmp_source.zig:3:14: error: operation caused overflow",
".tmp_source.zig:1:14: note: called from here");
cases.add("mul overflow in function evaluation",
\\const y = mul(300, 6000);
- \\fn mul(a: u16, b: u16) -> u16 {
+ \\fn mul(a: u16, b: u16) u16 {
\\ return a * b;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
,
".tmp_source.zig:3:14: error: operation caused overflow",
".tmp_source.zig:1:14: note: called from here");
cases.add("truncate sign mismatch",
- \\fn f() -> i8 {
+ \\fn f() i8 {
\\ const x: u32 = 10;
\\ return @truncate(i8, x);
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'");
cases.add("try in function with non error return type",
- \\export fn f() {
+ \\export fn f() void {
\\ try something();
\\}
- \\fn something() -> %void { }
+ \\fn something() %void { }
,
".tmp_source.zig:2:5: error: expected type 'void', found 'error'");
cases.add("invalid pointer for var type",
- \\extern fn ext() -> usize;
+ \\extern fn ext() usize;
\\var bytes: [ext()]u8 = undefined;
- \\export fn f() {
+ \\export fn f() void {
\\ for (bytes) |*b, i| {
\\ *b = u8(i);
\\ }
@@ -1125,21 +1125,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:2:13: error: unable to evaluate constant expression");
cases.add("export function with comptime parameter",
- \\export fn foo(comptime x: i32, y: i32) -> i32{
+ \\export fn foo(comptime x: i32, y: i32) i32{
\\ return x + y;
\\}
, ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
cases.add("extern function with comptime parameter",
- \\extern fn foo(comptime x: i32, y: i32) -> i32;
- \\fn f() -> i32 {
+ \\extern fn foo(comptime x: i32, y: i32) i32;
+ \\fn f() i32 {
\\ return foo(1, 2);
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
cases.add("convert fixed size array to slice with invalid size",
- \\export fn f() {
+ \\export fn f() void {
\\ var array: [5]u8 = undefined;
\\ var foo = ([]const u32)(array)[0];
\\}
@@ -1147,12 +1147,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("non-pure function returns type",
\\var a: u32 = 0;
- \\pub fn List(comptime T: type) -> type {
+ \\pub fn List(comptime T: type) type {
\\ a += 1;
\\ return SmallList(T, 8);
\\}
\\
- \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
+ \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
\\ return struct {
\\ items: []T,
\\ length: usize,
@@ -1160,7 +1160,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ };
\\}
\\
- \\export fn function_with_return_type_type() {
+ \\export fn function_with_return_type_type() void {
\\ var list: List(i32) = undefined;
\\ list.length = 10;
\\}
@@ -1169,46 +1169,46 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("bogus method call on slice",
\\var self = "aoeu";
- \\fn f(m: []const u8) {
+ \\fn f(m: []const u8) void {
\\ m.copy(u8, self[0..], m);
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");
cases.add("wrong number of arguments for method fn call",
\\const Foo = struct {
- \\ fn method(self: &const Foo, a: i32) {}
+ \\ fn method(self: &const Foo, a: i32) void {}
\\};
- \\fn f(foo: &const Foo) {
+ \\fn f(foo: &const Foo) void {
\\
\\ foo.method(1, 2);
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
, ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");
cases.add("assign through constant pointer",
- \\export fn f() {
+ \\export fn f() void {
\\ var cstr = c"Hat";
\\ cstr[0] = 'W';
\\}
, ".tmp_source.zig:3:11: error: cannot assign to constant");
cases.add("assign through constant slice",
- \\export fn f() {
+ \\export fn f() void {
\\ var cstr: []const u8 = "Hat";
\\ cstr[0] = 'W';
\\}
, ".tmp_source.zig:3:11: error: cannot assign to constant");
cases.add("main function with bogus args type",
- \\pub fn main(args: [][]bogus) -> %void {}
+ \\pub fn main(args: [][]bogus) %void {}
, ".tmp_source.zig:1:23: error: use of undeclared identifier 'bogus'");
cases.add("for loop missing element param",
- \\fn foo(blah: []u8) {
+ \\fn foo(blah: []u8) void {
\\ for (blah) { }
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:2:5: error: for loop expression missing element parameter");
cases.add("misspelled type with pointer only reference",
@@ -1235,27 +1235,27 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ jobject: ?JsonOA,
\\};
\\
- \\fn foo() {
+ \\fn foo() void {
\\ var jll: JasonList = undefined;
\\ jll.init(1234);
\\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");
cases.add("method call with first arg type primitive",
\\const Foo = struct {
\\ x: i32,
\\
- \\ fn init(x: i32) -> Foo {
+ \\ fn init(x: i32) Foo {
\\ return Foo {
\\ .x = x,
\\ };
\\ }
\\};
\\
- \\export fn f() {
+ \\export fn f() void {
\\ const derp = Foo.init(3);
\\
\\ derp.init();
@@ -1267,7 +1267,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ len: usize,
\\ allocator: &Allocator,
\\
- \\ pub fn init(allocator: &Allocator) -> List {
+ \\ pub fn init(allocator: &Allocator) List {
\\ return List {
\\ .len = 0,
\\ .allocator = allocator,
@@ -1283,7 +1283,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ field: i32,
\\};
\\
- \\export fn foo() {
+ \\export fn foo() void {
\\ var x = List.init(&global_allocator);
\\ x.init();
\\}
@@ -1294,14 +1294,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
\\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
, ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");
cases.addCase(x: {
const tc = cases.create("multiple files with private function error",
\\const foo = @import("foo.zig");
\\
- \\export fn callPrivFunction() {
+ \\export fn callPrivFunction() void {
\\ foo.privateFunction();
\\}
,
@@ -1309,7 +1309,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
"foo.zig:1:1: note: declared here");
tc.addSourceFile("foo.zig",
- \\fn privateFunction() { }
+ \\fn privateFunction() void { }
);
break :x tc;
@@ -1319,21 +1319,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const zero: i32 = 0;
\\const a = zero{1};
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
, ".tmp_source.zig:2:11: error: expected type, found 'i32'");
cases.add("assign to constant field",
\\const Foo = struct {
\\ field: i32,
\\};
- \\export fn derp() {
+ \\export fn derp() void {
\\ const f = Foo {.field = 1234,};
\\ f.field = 0;
\\}
, ".tmp_source.zig:6:13: error: cannot assign to constant");
cases.add("return from defer expression",
- \\pub fn testTrickyDefer() -> %void {
+ \\pub fn testTrickyDefer() %void {
\\ defer canFail() catch {};
\\
\\ defer try canFail();
@@ -1341,31 +1341,31 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ const a = maybeInt() ?? return;
\\}
\\
- \\fn canFail() -> %void { }
+ \\fn canFail() %void { }
\\
- \\pub fn maybeInt() -> ?i32 {
+ \\pub fn maybeInt() ?i32 {
\\ return 0;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(testTrickyDefer)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); }
, ".tmp_source.zig:4:11: error: cannot return from defer expression");
cases.add("attempt to access var args out of bounds",
- \\fn add(args: ...) -> i32 {
+ \\fn add(args: ...) i32 {
\\ return args[0] + args[1];
\\}
\\
- \\fn foo() -> i32 {
+ \\fn foo() i32 {
\\ return add(i32(1234));
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
,
".tmp_source.zig:2:26: error: index 1 outside argument list of size 1",
".tmp_source.zig:6:15: note: called from here");
cases.add("pass integer literal to var args",
- \\fn add(args: ...) -> i32 {
+ \\fn add(args: ...) i32 {
\\ var sum = i32(0);
\\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
\\ sum += args[i];
@@ -1373,34 +1373,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ return sum;
\\}
\\
- \\fn bar() -> i32 {
+ \\fn bar() i32 {
\\ return add(1, 2, 3, 4);
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(bar)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(bar)); }
, ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime");
cases.add("assign too big number to u16",
- \\export fn foo() {
+ \\export fn foo() void {
\\ var vga_mem: u16 = 0xB8000;
\\}
, ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
cases.add("global variable alignment non power of 2",
\\const some_data: [100]u8 align(3) = undefined;
- \\export fn entry() -> usize { return @sizeOf(@typeOf(some_data)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); }
, ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
cases.add("function alignment non power of 2",
- \\extern fn foo() align(3);
- \\export fn entry() { return foo(); }
+ \\extern fn foo() align(3) void;
+ \\export fn entry() void { return foo(); }
, ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
cases.add("compile log",
- \\export fn foo() {
+ \\export fn foo() void {
\\ comptime bar(12, "hi");
\\}
- \\fn bar(a: i32, b: []const u8) {
+ \\fn bar(a: i32, b: []const u8) void {
\\ @compileLog("begin");
\\ @compileLog("a", a, "b", b);
\\ @compileLog("end");
@@ -1420,15 +1420,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ c: u2,
\\};
\\
- \\fn foo(bit_field: &const BitField) -> u3 {
+ \\fn foo(bit_field: &const BitField) u3 {
\\ return bar(&bit_field.b);
\\}
\\
- \\fn bar(x: &const u3) -> u3 {
+ \\fn bar(x: &const u3) u3 {
\\ return *x;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
cases.add("referring to a struct that is invalid",
@@ -1436,11 +1436,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Type: u8,
\\};
\\
- \\export fn foo() {
+ \\export fn foo() void {
\\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
\\}
\\
- \\fn assert(ok: bool) {
+ \\fn assert(ok: bool) void {
\\ if (!ok) unreachable;
\\}
,
@@ -1448,92 +1448,92 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:6:20: note: called from here");
cases.add("control flow uses comptime var at runtime",
- \\export fn foo() {
+ \\export fn foo() void {
\\ comptime var i = 0;
\\ while (i < 5) : (i += 1) {
\\ bar();
\\ }
\\}
\\
- \\fn bar() { }
+ \\fn bar() void { }
,
".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
".tmp_source.zig:3:24: note: compile-time variable assigned here");
cases.add("ignored return value",
- \\export fn foo() {
+ \\export fn foo() void {
\\ bar();
\\}
- \\fn bar() -> i32 { return 0; }
+ \\fn bar() i32 { return 0; }
, ".tmp_source.zig:2:8: error: expression value is ignored");
cases.add("ignored assert-err-ok return value",
- \\export fn foo() {
+ \\export fn foo() void {
\\ bar() catch unreachable;
\\}
- \\fn bar() -> %i32 { return 0; }
+ \\fn bar() %i32 { return 0; }
, ".tmp_source.zig:2:11: error: expression value is ignored");
cases.add("ignored statement value",
- \\export fn foo() {
+ \\export fn foo() void {
\\ 1;
\\}
, ".tmp_source.zig:2:5: error: expression value is ignored");
cases.add("ignored comptime statement value",
- \\export fn foo() {
+ \\export fn foo() void {
\\ comptime {1;}
\\}
, ".tmp_source.zig:2:15: error: expression value is ignored");
cases.add("ignored comptime value",
- \\export fn foo() {
+ \\export fn foo() void {
\\ comptime 1;
\\}
, ".tmp_source.zig:2:5: error: expression value is ignored");
cases.add("ignored defered statement value",
- \\export fn foo() {
+ \\export fn foo() void {
\\ defer {1;}
\\}
, ".tmp_source.zig:2:12: error: expression value is ignored");
cases.add("ignored defered function call",
- \\export fn foo() {
+ \\export fn foo() void {
\\ defer bar();
\\}
- \\fn bar() -> %i32 { return 0; }
+ \\fn bar() %i32 { return 0; }
, ".tmp_source.zig:2:14: error: expression value is ignored");
cases.add("dereference an array",
\\var s_buffer: [10]u8 = undefined;
- \\pub fn pass(in: []u8) -> []u8 {
+ \\pub fn pass(in: []u8) []u8 {
\\ var out = &s_buffer;
\\ *out[0] = in[0];
\\ return (*out)[0..1];
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(pass)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(pass)); }
, ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'");
cases.add("pass const ptr to mutable ptr fn",
- \\fn foo() -> bool {
+ \\fn foo() bool {
\\ const a = ([]const u8)("a");
\\ const b = &a;
\\ return ptrEql(b, b);
\\}
- \\fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool {
+ \\fn ptrEql(a: &[]const u8, b: &[]const u8) bool {
\\ return true;
\\}
\\
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");
cases.addCase(x: {
const tc = cases.create("export collision",
\\const foo = @import("foo.zig");
\\
- \\export fn bar() -> usize {
+ \\export fn bar() usize {
\\ return foo.baz;
\\}
,
@@ -1541,7 +1541,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:8: note: other symbol here");
tc.addSourceFile("foo.zig",
- \\export fn bar() {}
+ \\export fn bar() void {}
\\pub const baz = 1234;
);
@@ -1550,20 +1550,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("pass non-copyable type by value to function",
\\const Point = struct { x: i32, y: i32, };
- \\fn foo(p: Point) { }
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\fn foo(p: Point) void { }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");
cases.add("implicit cast from array to mutable slice",
\\var global_array: [10]i32 = undefined;
- \\fn foo(param: []i32) {}
- \\export fn entry() {
+ \\fn foo(param: []i32) void {}
+ \\export fn entry() void {
\\ foo(global_array);
\\}
, ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'");
cases.add("ptrcast to non-pointer",
- \\export fn entry(a: &i32) -> usize {
+ \\export fn entry(a: &i32) usize {
\\ return @ptrCast(usize, a);
\\}
, ".tmp_source.zig:2:21: error: expected pointer, found 'usize'");
@@ -1571,10 +1571,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("too many error values to cast to small integer",
\\error A; error B; error C; error D; error E; error F; error G; error H;
\\const u2 = @IntType(false, 2);
- \\fn foo(e: error) -> u2 {
+ \\fn foo(e: error) u2 {
\\ return u2(e);
\\}
- \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
+ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'");
cases.add("asm at compile time",
@@ -1582,7 +1582,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ doSomeAsm();
\\}
\\
- \\fn doSomeAsm() {
+ \\fn doSomeAsm() void {
\\ asm volatile (
\\ \\.globl aoeu;
\\ \\.type aoeu, @function;
@@ -1593,13 +1593,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("invalid member of builtin enum",
\\const builtin = @import("builtin");
- \\export fn entry() {
+ \\export fn entry() void {
\\ const foo = builtin.Arch.x86;
\\}
, ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'");
cases.add("int to ptr of 0 bits",
- \\export fn foo() {
+ \\export fn foo() void {
\\ var x: usize = 0x1000;
\\ var y: &void = @intToPtr(&void, x);
\\}
@@ -1607,7 +1607,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("@fieldParentPtr - non struct",
\\const Foo = i32;
- \\export fn foo(a: &i32) -> &Foo {
+ \\export fn foo(a: &i32) &Foo {
\\ return @fieldParentPtr(Foo, "a", a);
\\}
, ".tmp_source.zig:3:28: error: expected struct type, found 'i32'");
@@ -1616,7 +1616,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = extern struct {
\\ derp: i32,
\\};
- \\export fn foo(a: &i32) -> &Foo {
+ \\export fn foo(a: &i32) &Foo {
\\ return @fieldParentPtr(Foo, "a", a);
\\}
, ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'");
@@ -1625,7 +1625,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = extern struct {
\\ a: i32,
\\};
- \\export fn foo(a: i32) -> &Foo {
+ \\export fn foo(a: i32) &Foo {
\\ return @fieldParentPtr(Foo, "a", a);
\\}
, ".tmp_source.zig:5:38: error: expected pointer, found 'i32'");
@@ -1657,7 +1657,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("@offsetOf - non struct",
\\const Foo = i32;
- \\export fn foo() -> usize {
+ \\export fn foo() usize {
\\ return @offsetOf(Foo, "a");
\\}
, ".tmp_source.zig:3:22: error: expected struct type, found 'i32'");
@@ -1666,7 +1666,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = struct {
\\ derp: i32,
\\};
- \\export fn foo() -> usize {
+ \\export fn foo() usize {
\\ return @offsetOf(Foo, "a");
\\}
, ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'");
@@ -1676,21 +1676,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, "error: no member named 'main' in '");
cases.addExe("private main fn",
- \\fn main() {}
+ \\fn main() void {}
,
"error: 'main' is private",
".tmp_source.zig:1:1: note: declared here");
cases.add("setting a section on an extern variable",
\\extern var foo: i32 section(".text2");
- \\export fn entry() -> i32 {
+ \\export fn entry() i32 {
\\ return foo;
\\}
,
".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'");
cases.add("setting a section on a local variable",
- \\export fn entry() -> i32 {
+ \\export fn entry() i32 {
\\ var foo: i32 section(".text2") = 1234;
\\ return foo;
\\}
@@ -1698,15 +1698,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'");
cases.add("setting a section on an extern fn",
- \\extern fn foo() section(".text2");
- \\export fn entry() {
+ \\extern fn foo() section(".text2") void;
+ \\export fn entry() void {
\\ foo();
\\}
,
".tmp_source.zig:1:25: error: cannot set section of external function 'foo'");
cases.add("returning address of local variable - simple",
- \\export fn foo() -> &i32 {
+ \\export fn foo() &i32 {
\\ var a: i32 = undefined;
\\ return &a;
\\}
@@ -1714,7 +1714,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:13: error: function returns address of local variable");
cases.add("returning address of local variable - phi",
- \\export fn foo(c: bool) -> &i32 {
+ \\export fn foo(c: bool) &i32 {
\\ var a: i32 = undefined;
\\ var b: i32 = undefined;
\\ return if (c) &a else &b;
@@ -1723,13 +1723,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:4:12: error: function returns address of local variable");
cases.add("inner struct member shadowing outer struct member",
- \\fn A() -> type {
+ \\fn A() type {
\\ return struct {
\\ b: B(),
\\
\\ const Self = this;
\\
- \\ fn B() -> type {
+ \\ fn B() type {
\\ return struct {
\\ const Self = this;
\\ };
@@ -1739,7 +1739,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\comptime {
\\ assert(A().B().Self != A().Self);
\\}
- \\fn assert(ok: bool) {
+ \\fn assert(ok: bool) void {
\\ if (!ok) unreachable;
\\}
,
@@ -1747,87 +1747,87 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:5:9: note: previous definition is here");
cases.add("while expected bool, got nullable",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (bar()) {}
\\}
- \\fn bar() -> ?i32 { return 1; }
+ \\fn bar() ?i32 { return 1; }
,
".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");
cases.add("while expected bool, got error union",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (bar()) {}
\\}
- \\fn bar() -> %i32 { return 1; }
+ \\fn bar() %i32 { return 1; }
,
".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'");
cases.add("while expected nullable, got bool",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (bar()) |x| {}
\\}
- \\fn bar() -> bool { return true; }
+ \\fn bar() bool { return true; }
,
".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");
cases.add("while expected nullable, got error union",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (bar()) |x| {}
\\}
- \\fn bar() -> %i32 { return 1; }
+ \\fn bar() %i32 { return 1; }
,
".tmp_source.zig:2:15: error: expected nullable type, found '%i32'");
cases.add("while expected error union, got bool",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (bar()) |x| {} else |err| {}
\\}
- \\fn bar() -> bool { return true; }
+ \\fn bar() bool { return true; }
,
".tmp_source.zig:2:15: error: expected error union type, found 'bool'");
cases.add("while expected error union, got nullable",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (bar()) |x| {} else |err| {}
\\}
- \\fn bar() -> ?i32 { return 1; }
+ \\fn bar() ?i32 { return 1; }
,
".tmp_source.zig:2:15: error: expected error union type, found '?i32'");
cases.add("inline fn calls itself indirectly",
- \\export fn foo() {
+ \\export fn foo() void {
\\ bar();
\\}
- \\inline fn bar() {
+ \\inline fn bar() void {
\\ baz();
\\ quux();
\\}
- \\inline fn baz() {
+ \\inline fn baz() void {
\\ bar();
\\ quux();
\\}
- \\extern fn quux();
+ \\extern fn quux() void;
,
".tmp_source.zig:4:8: error: unable to inline function");
cases.add("save reference to inline function",
- \\export fn foo() {
+ \\export fn foo() void {
\\ quux(@ptrToInt(bar));
\\}
- \\inline fn bar() { }
- \\extern fn quux(usize);
+ \\inline fn bar() void { }
+ \\extern fn quux(usize) void;
,
".tmp_source.zig:4:8: error: unable to inline function");
cases.add("signed integer division",
- \\export fn foo(a: i32, b: i32) -> i32 {
+ \\export fn foo(a: i32, b: i32) i32 {
\\ return a / b;
\\}
,
".tmp_source.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");
cases.add("signed integer remainder division",
- \\export fn foo(a: i32, b: i32) -> i32 {
+ \\export fn foo(a: i32, b: i32) i32 {
\\ return a % b;
\\}
,
@@ -1868,7 +1868,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");
cases.add("@setRuntimeSafety twice for same scope",
- \\export fn foo() {
+ \\export fn foo() void {
\\ @setRuntimeSafety(false);
\\ @setRuntimeSafety(false);
\\}
@@ -1877,7 +1877,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:5: note: first set here");
cases.add("@setFloatMode twice for same scope",
- \\export fn foo() {
+ \\export fn foo() void {
\\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);
\\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);
\\}
@@ -1886,14 +1886,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:5: note: first set here");
cases.add("array access of type",
- \\export fn foo() {
+ \\export fn foo() void {
\\ var b: u8[40] = undefined;
\\}
,
".tmp_source.zig:2:14: error: array access of non-array type 'type'");
cases.add("cannot break out of defer expression",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (true) {
\\ defer {
\\ break;
@@ -1904,7 +1904,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:4:13: error: cannot break out of defer expression");
cases.add("cannot continue out of defer expression",
- \\export fn foo() {
+ \\export fn foo() void {
\\ while (true) {
\\ defer {
\\ continue;
@@ -1915,24 +1915,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:4:13: error: cannot continue out of defer expression");
cases.add("calling a var args function only known at runtime",
- \\var foos = []fn(...) { foo1, foo2 };
+ \\var foos = []fn(...) void { foo1, foo2 };
\\
- \\fn foo1(args: ...) {}
- \\fn foo2(args: ...) {}
+ \\fn foo1(args: ...) void {}
+ \\fn foo2(args: ...) void {}
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ foos[0]();
\\}
,
".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value");
cases.add("calling a generic function only known at runtime",
- \\var foos = []fn(var) { foo1, foo2 };
+ \\var foos = []fn(var) void { foo1, foo2 };
\\
- \\fn foo1(arg: var) {}
- \\fn foo2(arg: var) {}
+ \\fn foo1(arg: var) void {}
+ \\fn foo2(arg: var) void {}
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ foos[0](true);
\\}
,
@@ -1944,7 +1944,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const bar = baz + foo;
\\const baz = 1;
\\
- \\export fn entry() -> i32 {
+ \\export fn entry() i32 {
\\ return bar;
\\}
,
@@ -1959,7 +1959,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\
\\var foo: Foo = undefined;
\\
- \\export fn entry() -> usize {
+ \\export fn entry() usize {
\\ return @sizeOf(@typeOf(foo.x));
\\}
,
@@ -1980,14 +1980,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:15: error: float literal out of range of any type");
cases.add("explicit cast float literal to integer when there is a fraction component",
- \\export fn entry() -> i32 {
+ \\export fn entry() i32 {
\\ return i32(12.34);
\\}
,
".tmp_source.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'");
cases.add("non pointer given to @ptrToInt",
- \\export fn entry(x: i32) -> usize {
+ \\export fn entry(x: i32) usize {
\\ return @ptrToInt(x);
\\}
,
@@ -2008,14 +2008,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:15: error: exact shift shifted out 1 bits");
cases.add("shifting without int type or comptime known",
- \\export fn entry(x: u8) -> u8 {
+ \\export fn entry(x: u8) u8 {
\\ return 0x11 << x;
\\}
,
".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known");
cases.add("shifting RHS is log2 of LHS int bit width",
- \\export fn entry(x: u8, y: u8) -> u8 {
+ \\export fn entry(x: u8, y: u8) u8 {
\\ return x << y;
\\}
,
@@ -2023,7 +2023,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("globally shadowing a primitive type",
\\const u16 = @intType(false, 8);
- \\export fn entry() {
+ \\export fn entry() void {
\\ const a: u16 = 300;
\\}
,
@@ -2035,12 +2035,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ b: u32,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var foo = Foo { .a = 1, .b = 10 };
\\ bar(&foo.b);
\\}
\\
- \\fn bar(x: &u32) {
+ \\fn bar(x: &u32) void {
\\ *x += 1;
\\}
,
@@ -2052,20 +2052,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ b: u32,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var foo = Foo { .a = 1, .b = 10 };
\\ foo.b += 1;
\\ bar((&foo.b)[0..1]);
\\}
\\
- \\fn bar(x: []u32) {
+ \\fn bar(x: []u32) void {
\\ x[0] += 1;
\\}
,
".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'");
cases.add("increase pointer alignment in @ptrCast",
- \\export fn entry() -> u32 {
+ \\export fn entry() u32 {
\\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};
\\ const ptr = @ptrCast(&u32, &bytes[0]);
\\ return *ptr;
@@ -2076,7 +2076,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:27: note: '&u32' has alignment 4");
cases.add("increase pointer alignment in slice resize",
- \\export fn entry() -> u32 {
+ \\export fn entry() u32 {
\\ var bytes = []u8{0x01, 0x02, 0x03, 0x04};
\\ return ([]u32)(bytes[0..])[0];
\\}
@@ -2086,26 +2086,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:19: note: '[]u32' has alignment 4");
cases.add("@alignCast expects pointer or slice",
- \\export fn entry() {
+ \\export fn entry() void {
\\ @alignCast(4, u32(3));
\\}
,
".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");
cases.add("passing an under-aligned function pointer",
- \\export fn entry() {
+ \\export fn entry() void {
\\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
\\}
- \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {
+ \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
\\ if (ptr() != answer) unreachable;
\\}
- \\fn alignedSmall() align(4) -> i32 { return 1234; }
+ \\fn alignedSmall() align(4) i32 { return 1234; }
,
- ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");
+ ".tmp_source.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'");
cases.add("passing a not-aligned-enough pointer to cmpxchg",
\\const AtomicOrder = @import("builtin").AtomicOrder;
- \\export fn entry() -> bool {
+ \\export fn entry() bool {
\\ var x: i32 align(1) = 1234;
\\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
\\ return x == 5678;
@@ -2124,7 +2124,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\comptime {
\\ foo();
\\}
- \\fn foo() {
+ \\fn foo() void {
\\ @setEvalBranchQuota(1001);
\\}
,
@@ -2134,8 +2134,8 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()",
\\const Derp = @OpaqueType();
- \\extern fn bar(d: &Derp);
- \\export fn foo() {
+ \\extern fn bar(d: &Derp) void;
+ \\export fn foo() void {
\\ const x = u8(1);
\\ bar(@ptrCast(&c_void, &x));
\\}
@@ -2145,7 +2145,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("non-const variables of things that require const variables",
\\const Opaque = @OpaqueType();
\\
- \\export fn entry(opaque: &Opaque) {
+ \\export fn entry(opaque: &Opaque) void {
\\ var m2 = &2;
\\ const y: u32 = *m2;
\\
@@ -2163,7 +2163,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\}
\\
\\const Foo = struct {
- \\ fn bar(self: &const Foo) {}
+ \\ fn bar(self: &const Foo) void {}
\\};
,
".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime",
@@ -2175,11 +2175,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime",
".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime",
".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime",
- ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo))' must be const or comptime",
+ ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo) void)' must be const or comptime",
".tmp_source.zig:17:4: error: unreachable code");
cases.add("wrong types given to atomic order args in cmpxchg",
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x: i32 = 1234;
\\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {}
\\}
@@ -2187,7 +2187,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'");
cases.add("wrong types given to @export",
- \\extern fn entry() { }
+ \\extern fn entry() void { }
\\comptime {
\\ @export("entry", entry, u32(1234));
\\}
@@ -2212,7 +2212,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ },
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ const a = MdNode.Header {
\\ .text = MdText.init(&std.debug.global_allocator),
\\ .weight = HeaderWeight.H1,
@@ -2229,24 +2229,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:5: error: @setAlignStack outside function");
cases.add("@setAlignStack in naked function",
- \\export nakedcc fn entry() {
+ \\export nakedcc fn entry() void {
\\ @setAlignStack(16);
\\}
,
".tmp_source.zig:2:5: error: @setAlignStack in naked function");
cases.add("@setAlignStack in inline function",
- \\export fn entry() {
+ \\export fn entry() void {
\\ foo();
\\}
- \\inline fn foo() {
+ \\inline fn foo() void {
\\ @setAlignStack(16);
\\}
,
".tmp_source.zig:5:5: error: @setAlignStack in inline function");
cases.add("@setAlignStack set twice",
- \\export fn entry() {
+ \\export fn entry() void {
\\ @setAlignStack(16);
\\ @setAlignStack(16);
\\}
@@ -2255,7 +2255,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:5: note: first set here");
cases.add("@setAlignStack too big",
- \\export fn entry() {
+ \\export fn entry() void {
\\ @setAlignStack(511 + 1);
\\}
,
@@ -2264,14 +2264,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("storing runtime value in compile time variable then using it",
\\const Mode = @import("builtin").Mode;
\\
- \\fn Free(comptime filename: []const u8) -> TestCase {
+ \\fn Free(comptime filename: []const u8) TestCase {
\\ return TestCase {
\\ .filename = filename,
\\ .problem_type = ProblemType.Free,
\\ };
\\}
\\
- \\fn LibC(comptime filename: []const u8) -> TestCase {
+ \\fn LibC(comptime filename: []const u8) TestCase {
\\ return TestCase {
\\ .filename = filename,
\\ .problem_type = ProblemType.LinkLibC,
@@ -2288,7 +2288,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ LinkLibC,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ const tests = []TestCase {
\\ Free("001"),
\\ Free("002"),
@@ -2309,34 +2309,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("field access of opaque type",
\\const MyType = @OpaqueType();
\\
- \\export fn entry() -> bool {
+ \\export fn entry() bool {
\\ var x: i32 = 1;
\\ return bar(@ptrCast(&MyType, &x));
\\}
\\
- \\fn bar(x: &MyType) -> bool {
+ \\fn bar(x: &MyType) bool {
\\ return x.blah;
\\}
,
".tmp_source.zig:9:13: error: type '&MyType' does not support field access");
cases.add("carriage return special case",
- "fn test() -> bool {\r\n" ++
+ "fn test() bool {\r\n" ++
" true\r\n" ++
"}\r\n"
,
- ".tmp_source.zig:1:20: error: invalid carriage return, only '\\n' line endings are supported");
+ ".tmp_source.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported");
cases.add("non-printable invalid character",
"\xff\xfe" ++
- \\fn test() -> bool {\r
+ \\fn test() bool {\r
\\ true\r
\\}
,
".tmp_source.zig:1:1: error: invalid character: '\\xff'");
cases.add("non-printable invalid character with escape alternative",
- "fn test() -> bool {\n" ++
+ "fn test() bool {\n" ++
"\ttrue\n" ++
"}\n"
,
@@ -2353,9 +2353,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\comptime {
\\ _ = @ArgType(@typeOf(add), 2);
\\}
- \\fn add(a: i32, b: i32) -> i32 { return a + b; }
+ \\fn add(a: i32, b: i32) i32 { return a + b; }
,
- ".tmp_source.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) -> i32' has 2 arguments");
+ ".tmp_source.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments");
cases.add("@memberType on unsupported type",
\\comptime {
@@ -2420,17 +2420,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members");
cases.add("calling var args extern function, passing array instead of pointer",
- \\export fn entry() {
+ \\export fn entry() void {
\\ foo("hello");
\\}
- \\pub extern fn foo(format: &const u8, ...);
+ \\pub extern fn foo(format: &const u8, ...) void;
,
".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'");
cases.add("constant inside comptime function has compile error",
\\const ContextAllocator = MemoryPool(usize);
\\
- \\pub fn MemoryPool(comptime T: type) -> type {
+ \\pub fn MemoryPool(comptime T: type) type {
\\ const free_list_t = @compileError("aoeu");
\\
\\ return struct {
@@ -2438,7 +2438,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ };
\\}
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var allocator: ContextAllocator = undefined;
\\}
,
@@ -2455,7 +2455,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Five,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x = Small.One;
\\}
,
@@ -2468,7 +2468,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Three,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x = Small.One;
\\}
,
@@ -2482,7 +2482,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Four,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x: u2 = Small.Two;
\\}
,
@@ -2496,7 +2496,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Four,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x = u3(Small.Two);
\\}
,
@@ -2510,7 +2510,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Four,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var y = u3(3);
\\ var x = Small(y);
\\}
@@ -2525,7 +2525,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ Four,
\\};
\\
- \\export fn entry() {
+ \\export fn entry() void {
\\ var y = Small.Two;
\\}
,
@@ -2535,7 +2535,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const MultipleChoice = struct {
\\ A: i32 = 20,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x: MultipleChoice = undefined;
\\}
,
@@ -2545,7 +2545,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const MultipleChoice = union {
\\ A: i32 = 20,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x: MultipleChoice = undefined;
\\}
,
@@ -2554,7 +2554,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("enum with 0 fields",
\\const Foo = enum {};
- \\export fn entry() -> usize {
+ \\export fn entry() usize {
\\ return @sizeOf(Foo);
\\}
,
@@ -2562,7 +2562,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("union with 0 fields",
\\const Foo = union {};
- \\export fn entry() -> usize {
+ \\export fn entry() usize {
\\ return @sizeOf(Foo);
\\}
,
@@ -2576,7 +2576,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ D = 1000,
\\ E = 60,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x = MultipleChoice.C;
\\}
,
@@ -2593,7 +2593,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ A: i32,
\\ B: f64,
\\};
- \\export fn entry() -> usize {
+ \\export fn entry() usize {
\\ return @sizeOf(Payload);
\\}
,
@@ -2604,7 +2604,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = union {
\\ A: i32,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ const x = @TagType(Foo);
\\}
,
@@ -2615,7 +2615,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = union(enum(f32)) {
\\ A: i32,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ const x = @TagType(Foo);
\\}
,
@@ -2625,7 +2625,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Foo = union(u32) {
\\ A: i32,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ const x = @TagType(Foo);
\\}
,
@@ -2639,7 +2639,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ D = 1000,
\\ E = 60,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x = MultipleChoice { .C = {} };
\\}
,
@@ -2658,7 +2658,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ C: bool,
\\ D: bool,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var a = Payload {.A = 1234};
\\}
,
@@ -2671,7 +2671,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B,
\\ C,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var b = Letter.B;
\\}
,
@@ -2682,7 +2682,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Letter = struct {
\\ A,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var a = Letter { .A = {} };
\\}
,
@@ -2692,7 +2692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\const Letter = extern union {
\\ A,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var a = Letter { .A = {} };
\\}
,
@@ -2709,7 +2709,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B: f64,
\\ C: bool,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var a = Payload { .A = 1234 };
\\}
,
@@ -2726,7 +2726,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B: f64,
\\ C: bool,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var a = Payload { .A = 1234 };
\\}
,
@@ -2738,11 +2738,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B: f64,
\\ C: bool,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ const a = Payload { .A = 1234 };
\\ foo(a);
\\}
- \\fn foo(a: &const Payload) {
+ \\fn foo(a: &const Payload) void {
\\ switch (*a) {
\\ Payload.A => {},
\\ else => unreachable,
@@ -2757,7 +2757,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ A = 10,
\\ B = 11,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x = Foo(0);
\\}
,
@@ -2771,7 +2771,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B,
\\ C,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ var x: Value = Letter.A;
\\}
,
@@ -2785,10 +2785,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ B,
\\ C,
\\};
- \\export fn entry() {
+ \\export fn entry() void {
\\ foo(Letter.A);
\\}
- \\fn foo(l: Letter) {
+ \\fn foo(l: Letter) void {
\\ var x: Value = l;
\\}
,
diff --git a/test/gen_h.zig b/test/gen_h.zig
index 82120d820e..5f28326ff6 100644
--- a/test/gen_h.zig
+++ b/test/gen_h.zig
@@ -1,9 +1,9 @@
const tests = @import("tests.zig");
-pub fn addCases(cases: &tests.GenHContext) {
+pub fn addCases(cases: &tests.GenHContext) void {
cases.add("declare enum",
\\const Foo = extern enum { A, B, C };
- \\export fn entry(foo: Foo) { }
+ \\export fn entry(foo: Foo) void { }
,
\\enum Foo {
\\ A = 0,
@@ -21,7 +21,7 @@ pub fn addCases(cases: &tests.GenHContext) {
\\ B: f32,
\\ C: bool,
\\};
- \\export fn entry(foo: Foo) { }
+ \\export fn entry(foo: Foo) void { }
,
\\struct Foo {
\\ int32_t A;
@@ -39,7 +39,7 @@ pub fn addCases(cases: &tests.GenHContext) {
\\ B: f32,
\\ C: bool,
\\};
- \\export fn entry(foo: Foo) { }
+ \\export fn entry(foo: Foo) void { }
,
\\union Foo {
\\ int32_t A;
@@ -56,7 +56,7 @@ pub fn addCases(cases: &tests.GenHContext) {
\\ A: [2]i32,
\\ B: [4]&u32,
\\};
- \\export fn entry(foo: Foo, bar: [3]u8) { }
+ \\export fn entry(foo: Foo, bar: [3]u8) void { }
,
\\struct Foo {
\\ int32_t A[2];
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig
index 25d6aa3577..3fb2a91544 100644
--- a/test/runtime_safety.zig
+++ b/test/runtime_safety.zig
@@ -1,263 +1,263 @@
const tests = @import("tests.zig");
-pub fn addCases(cases: &tests.CompareOutputContext) {
+pub fn addCases(cases: &tests.CompareOutputContext) void {
cases.addRuntimeSafety("calling panic",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ @panic("oh no");
\\}
);
cases.addRuntimeSafety("out of bounds slice access",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const a = []i32{1, 2, 3, 4};
\\ baz(bar(a));
\\}
- \\fn bar(a: []const i32) -> i32 {
+ \\fn bar(a: []const i32) i32 {
\\ return a[4];
\\}
- \\fn baz(a: i32) { }
+ \\fn baz(a: i32) void { }
);
cases.addRuntimeSafety("integer addition overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = add(65530, 10);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn add(a: u16, b: u16) -> u16 {
+ \\fn add(a: u16, b: u16) u16 {
\\ return a + b;
\\}
);
cases.addRuntimeSafety("integer subtraction overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = sub(10, 20);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn sub(a: u16, b: u16) -> u16 {
+ \\fn sub(a: u16, b: u16) u16 {
\\ return a - b;
\\}
);
cases.addRuntimeSafety("integer multiplication overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = mul(300, 6000);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn mul(a: u16, b: u16) -> u16 {
+ \\fn mul(a: u16, b: u16) u16 {
\\ return a * b;
\\}
);
cases.addRuntimeSafety("integer negation overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = neg(-32768);
\\ if (x == 32767) return error.Whatever;
\\}
- \\fn neg(a: i16) -> i16 {
+ \\fn neg(a: i16) i16 {
\\ return -a;
\\}
);
cases.addRuntimeSafety("signed integer division overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = div(-32768, -1);
\\ if (x == 32767) return error.Whatever;
\\}
- \\fn div(a: i16, b: i16) -> i16 {
+ \\fn div(a: i16, b: i16) i16 {
\\ return @divTrunc(a, b);
\\}
);
cases.addRuntimeSafety("signed shift left overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = shl(-16385, 1);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn shl(a: i16, b: u4) -> i16 {
+ \\fn shl(a: i16, b: u4) i16 {
\\ return @shlExact(a, b);
\\}
);
cases.addRuntimeSafety("unsigned shift left overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = shl(0b0010111111111111, 3);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn shl(a: u16, b: u4) -> u16 {
+ \\fn shl(a: u16, b: u4) u16 {
\\ return @shlExact(a, b);
\\}
);
cases.addRuntimeSafety("signed shift right overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = shr(-16385, 1);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn shr(a: i16, b: u4) -> i16 {
+ \\fn shr(a: i16, b: u4) i16 {
\\ return @shrExact(a, b);
\\}
);
cases.addRuntimeSafety("unsigned shift right overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = shr(0b0010111111111111, 3);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn shr(a: u16, b: u4) -> u16 {
+ \\fn shr(a: u16, b: u4) u16 {
\\ return @shrExact(a, b);
\\}
);
cases.addRuntimeSafety("integer division by zero",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = div0(999, 0);
\\}
- \\fn div0(a: i32, b: i32) -> i32 {
+ \\fn div0(a: i32, b: i32) i32 {
\\ return @divTrunc(a, b);
\\}
);
cases.addRuntimeSafety("exact division failure",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = divExact(10, 3);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn divExact(a: i32, b: i32) -> i32 {
+ \\fn divExact(a: i32, b: i32) i32 {
\\ return @divExact(a, b);
\\}
);
cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
\\ if (x.len == 0) return error.Whatever;
\\}
- \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
+ \\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 {
\\ return ([]align(1) const i32)(slice);
\\}
);
cases.addRuntimeSafety("value does not fit in shortening cast",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = shorten_cast(200);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn shorten_cast(x: i32) -> i8 {
+ \\fn shorten_cast(x: i32) i8 {
\\ return i8(x);
\\}
);
cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ const x = unsigned_cast(-10);
\\ if (x == 0) return error.Whatever;
\\}
- \\fn unsigned_cast(x: i32) -> u32 {
+ \\fn unsigned_cast(x: i32) u32 {
\\ return u32(x);
\\}
);
cases.addRuntimeSafety("unwrap error",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
\\ @import("std").os.exit(126); // good
\\ }
\\ @import("std").os.exit(0); // test failed
\\}
\\error Whatever;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ bar() catch unreachable;
\\}
- \\fn bar() -> %void {
+ \\fn bar() %void {
\\ return error.Whatever;
\\}
);
cases.addRuntimeSafety("cast integer to error and no code matches",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ _ = bar(9999);
\\}
- \\fn bar(x: u32) -> error {
+ \\fn bar(x: u32) error {
\\ return error(x);
\\}
);
cases.addRuntimeSafety("@alignCast misaligned",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\error Wrong;
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ var array align(4) = []u32{0x11111111, 0x11111111};
\\ const bytes = ([]u8)(array[0..]);
\\ if (foo(bytes) != 0x11111111) return error.Wrong;
\\}
- \\fn foo(bytes: []u8) -> u32 {
+ \\fn foo(bytes: []u8) u32 {
\\ const slice4 = bytes[1..5];
\\ const int_slice = ([]u32)(@alignCast(4, slice4));
\\ return int_slice[0];
@@ -265,7 +265,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
);
cases.addRuntimeSafety("bad union field access",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\}
\\
@@ -274,12 +274,12 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ int: u32,
\\};
\\
- \\pub fn main() -> %void {
+ \\pub fn main() %void {
\\ var f = Foo { .int = 42 };
\\ bar(&f);
\\}
\\
- \\fn bar(f: &Foo) {
+ \\fn bar(f: &Foo) void {
\\ f.float = 12.34;
\\}
);
diff --git a/test/standalone/brace_expansion/build.zig b/test/standalone/brace_expansion/build.zig
index d170b50fe0..af3160a8c6 100644
--- a/test/standalone/brace_expansion/build.zig
+++ b/test/standalone/brace_expansion/build.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const main = b.addTest("main.zig");
main.setBuildMode(b.standardReleaseOptions());
diff --git a/test/standalone/brace_expansion/main.zig b/test/standalone/brace_expansion/main.zig
index 54889a1ce2..995da8bb56 100644
--- a/test/standalone/brace_expansion/main.zig
+++ b/test/standalone/brace_expansion/main.zig
@@ -19,7 +19,7 @@ const Token = union(enum) {
var global_allocator: &mem.Allocator = undefined;
-fn tokenize(input:[] const u8) -> %ArrayList(Token) {
+fn tokenize(input:[] const u8) %ArrayList(Token) {
const State = enum {
Start,
Word,
@@ -71,7 +71,7 @@ const Node = union(enum) {
Combine: []Node,
};
-fn parse(tokens: &const ArrayList(Token), token_index: &usize) -> %Node {
+fn parse(tokens: &const ArrayList(Token), token_index: &usize) %Node {
const first_token = tokens.items[*token_index];
*token_index += 1;
@@ -107,7 +107,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) -> %Node {
}
}
-fn expandString(input: []const u8, output: &Buffer) -> %void {
+fn expandString(input: []const u8, output: &Buffer) %void {
const tokens = try tokenize(input);
if (tokens.len == 1) {
return output.resize(0);
@@ -135,7 +135,7 @@ fn expandString(input: []const u8, output: &Buffer) -> %void {
}
}
-fn expandNode(node: &const Node, output: &ArrayList(Buffer)) -> %void {
+fn expandNode(node: &const Node, output: &ArrayList(Buffer)) %void {
assert(output.len == 0);
switch (*node) {
Node.Scalar => |scalar| {
@@ -172,7 +172,7 @@ fn expandNode(node: &const Node, output: &ArrayList(Buffer)) -> %void {
}
}
-pub fn main() -> %void {
+pub fn main() %void {
var stdin_file = try io.getStdIn();
var stdout_file = try io.getStdOut();
@@ -208,7 +208,7 @@ test "invalid inputs" {
expectError("\n", error.InvalidInput);
}
-fn expectError(test_input: []const u8, expected_err: error) {
+fn expectError(test_input: []const u8, expected_err: error) void {
var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable;
defer output_buf.deinit();
@@ -242,7 +242,7 @@ test "valid inputs" {
expectExpansion("a{b}", "ab");
}
-fn expectExpansion(test_input: []const u8, expected_result: []const u8) {
+fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
var result = Buffer.initSize(global_allocator, 0) catch unreachable;
defer result.deinit();
diff --git a/test/standalone/issue_339/build.zig b/test/standalone/issue_339/build.zig
index b7b288f7a1..8cf4cfae77 100644
--- a/test/standalone/issue_339/build.zig
+++ b/test/standalone/issue_339/build.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const obj = b.addObject("test", "test.zig");
const test_step = b.step("test", "Test the program");
diff --git a/test/standalone/issue_339/test.zig b/test/standalone/issue_339/test.zig
index dd97ffa9b1..1c9480a0a6 100644
--- a/test/standalone/issue_339/test.zig
+++ b/test/standalone/issue_339/test.zig
@@ -1,8 +1,8 @@
const StackTrace = @import("builtin").StackTrace;
-pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) -> noreturn { @breakpoint(); while (true) {} }
+pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) noreturn { @breakpoint(); while (true) {} }
-fn bar() -> %void {}
+fn bar() %void {}
-export fn foo() {
+export fn foo() void {
bar() catch unreachable;
}
diff --git a/test/standalone/pkg_import/build.zig b/test/standalone/pkg_import/build.zig
index f40011d834..2caea10bfe 100644
--- a/test/standalone/pkg_import/build.zig
+++ b/test/standalone/pkg_import/build.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
const exe = b.addExecutable("test", "test.zig");
exe.addPackagePath("my_pkg", "pkg.zig");
diff --git a/test/standalone/pkg_import/pkg.zig b/test/standalone/pkg_import/pkg.zig
index 52ca884937..abb977a2ef 100644
--- a/test/standalone/pkg_import/pkg.zig
+++ b/test/standalone/pkg_import/pkg.zig
@@ -1 +1 @@
-pub fn add(a: i32, b: i32) -> i32 { return a + b; }
+pub fn add(a: i32, b: i32) i32 { return a + b; }
diff --git a/test/standalone/pkg_import/test.zig b/test/standalone/pkg_import/test.zig
index 1904a035af..9575671f2a 100644
--- a/test/standalone/pkg_import/test.zig
+++ b/test/standalone/pkg_import/test.zig
@@ -1,6 +1,6 @@
const my_pkg = @import("my_pkg");
const assert = @import("std").debug.assert;
-pub fn main() -> %void {
+pub fn main() %void {
assert(my_pkg.add(10, 20) == 30);
}
diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig
index beca6bc304..912058d5a9 100644
--- a/test/standalone/use_alias/build.zig
+++ b/test/standalone/use_alias/build.zig
@@ -1,6 +1,6 @@
const Builder = @import("std").build.Builder;
-pub fn build(b: &Builder) -> %void {
+pub fn build(b: &Builder) %void {
b.addCIncludePath(".");
const main = b.addTest("main.zig");
diff --git a/test/tests.zig b/test/tests.zig
index f86f222bf4..554bb6a2bc 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -50,7 +50,7 @@ error CompilationIncorrectlySucceeded;
const max_stdout_size = 1 * 1024 * 1024; // 1 MB
-pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
*cases = CompareOutputContext {
.b = b,
@@ -64,7 +64,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
return cases.step;
}
-pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
*cases = CompareOutputContext {
.b = b,
@@ -78,7 +78,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
return cases.step;
}
-pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(CompileErrorContext) catch unreachable;
*cases = CompileErrorContext {
.b = b,
@@ -92,7 +92,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
return cases.step;
}
-pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
*cases = BuildExamplesContext {
.b = b,
@@ -106,7 +106,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
return cases.step;
}
-pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
*cases = CompareOutputContext {
.b = b,
@@ -120,7 +120,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &
return cases.step;
}
-pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(TranslateCContext) catch unreachable;
*cases = TranslateCContext {
.b = b,
@@ -134,7 +134,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build
return cases.step;
}
-pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
const cases = b.allocator.create(GenHContext) catch unreachable;
*cases = GenHContext {
.b = b,
@@ -150,7 +150,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step
pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8,
- name:[] const u8, desc: []const u8, with_lldb: bool) -> &build.Step
+ name:[] const u8, desc: []const u8, with_lldb: bool) &build.Step
{
const step = b.step(b.fmt("test-{}", name), desc);
for (test_targets) |test_target| {
@@ -208,14 +208,14 @@ pub const CompareOutputContext = struct {
source: []const u8,
};
- pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
+ pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
self.sources.append(SourceFile {
.filename = filename,
.source = source,
}) catch unreachable;
}
- pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) {
+ pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) void {
self.cli_args = args;
}
};
@@ -231,7 +231,7 @@ pub const CompareOutputContext = struct {
pub fn create(context: &CompareOutputContext, exe_path: []const u8,
name: []const u8, expected_output: []const u8,
- cli_args: []const []const u8) -> &RunCompareOutputStep
+ cli_args: []const []const u8) &RunCompareOutputStep
{
const allocator = context.b.allocator;
const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
@@ -248,7 +248,7 @@ pub const CompareOutputContext = struct {
return ptr;
}
- fn make(step: &build.Step) -> %void {
+ fn make(step: &build.Step) %void {
const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
const b = self.context.b;
@@ -322,7 +322,7 @@ pub const CompareOutputContext = struct {
test_index: usize,
pub fn create(context: &CompareOutputContext, exe_path: []const u8,
- name: []const u8) -> &RuntimeSafetyRunStep
+ name: []const u8) &RuntimeSafetyRunStep
{
const allocator = context.b.allocator;
const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
@@ -337,7 +337,7 @@ pub const CompareOutputContext = struct {
return ptr;
}
- fn make(step: &build.Step) -> %void {
+ fn make(step: &build.Step) %void {
const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
const b = self.context.b;
@@ -383,7 +383,7 @@ pub const CompareOutputContext = struct {
};
pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8,
- expected_output: []const u8, special: Special) -> TestCase
+ expected_output: []const u8, special: Special) TestCase
{
var tc = TestCase {
.name = name,
@@ -399,33 +399,33 @@ pub const CompareOutputContext = struct {
}
pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8,
- expected_output: []const u8) -> TestCase
+ expected_output: []const u8) TestCase
{
return createExtra(self, name, source, expected_output, Special.None);
}
- pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) {
+ pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
var tc = self.create(name, source, expected_output);
tc.link_libc = true;
self.addCase(tc);
}
- pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) {
+ pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
const tc = self.create(name, source, expected_output);
self.addCase(tc);
}
- pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) {
+ pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
const tc = self.createExtra(name, source, expected_output, Special.Asm);
self.addCase(tc);
}
- pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) {
+ pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) void {
const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
self.addCase(tc);
}
- pub fn addCase(self: &CompareOutputContext, case: &const TestCase) {
+ pub fn addCase(self: &CompareOutputContext, case: &const TestCase) void {
const b = self.b;
const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
@@ -526,14 +526,14 @@ pub const CompileErrorContext = struct {
source: []const u8,
};
- pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
+ pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
self.sources.append(SourceFile {
.filename = filename,
.source = source,
}) catch unreachable;
}
- pub fn addExpectedError(self: &TestCase, text: []const u8) {
+ pub fn addExpectedError(self: &TestCase, text: []const u8) void {
self.expected_errors.append(text) catch unreachable;
}
};
@@ -547,7 +547,7 @@ pub const CompileErrorContext = struct {
build_mode: Mode,
pub fn create(context: &CompileErrorContext, name: []const u8,
- case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep
+ case: &const TestCase, build_mode: Mode) &CompileCmpOutputStep
{
const allocator = context.b.allocator;
const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
@@ -563,7 +563,7 @@ pub const CompileErrorContext = struct {
return ptr;
}
- fn make(step: &build.Step) -> %void {
+ fn make(step: &build.Step) %void {
const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
const b = self.context.b;
@@ -661,7 +661,7 @@ pub const CompileErrorContext = struct {
}
};
- fn printInvocation(args: []const []const u8) {
+ fn printInvocation(args: []const []const u8) void {
for (args) |arg| {
warn("{} ", arg);
}
@@ -669,7 +669,7 @@ pub const CompileErrorContext = struct {
}
pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8,
- expected_lines: ...) -> &TestCase
+ expected_lines: ...) &TestCase
{
const tc = self.b.allocator.create(TestCase) catch unreachable;
*tc = TestCase {
@@ -687,24 +687,24 @@ pub const CompileErrorContext = struct {
return tc;
}
- pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
var tc = self.create(name, source, expected_lines);
tc.link_libc = true;
self.addCase(tc);
}
- pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
var tc = self.create(name, source, expected_lines);
tc.is_exe = true;
self.addCase(tc);
}
- pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
const tc = self.create(name, source, expected_lines);
self.addCase(tc);
}
- pub fn addCase(self: &CompileErrorContext, case: &const TestCase) {
+ pub fn addCase(self: &CompileErrorContext, case: &const TestCase) void {
const b = self.b;
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
@@ -733,15 +733,15 @@ pub const BuildExamplesContext = struct {
test_index: usize,
test_filter: ?[]const u8,
- pub fn addC(self: &BuildExamplesContext, root_src: []const u8) {
+ pub fn addC(self: &BuildExamplesContext, root_src: []const u8) void {
self.addAllArgs(root_src, true);
}
- pub fn add(self: &BuildExamplesContext, root_src: []const u8) {
+ pub fn add(self: &BuildExamplesContext, root_src: []const u8) void {
self.addAllArgs(root_src, false);
}
- pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) {
+ pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) void {
const b = self.b;
const annotated_case_name = b.fmt("build {} (Debug)", build_file);
@@ -772,7 +772,7 @@ pub const BuildExamplesContext = struct {
self.step.dependOn(&log_step.step);
}
- pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) {
+ pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) void {
const b = self.b;
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
@@ -814,14 +814,14 @@ pub const TranslateCContext = struct {
source: []const u8,
};
- pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
+ pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
self.sources.append(SourceFile {
.filename = filename,
.source = source,
}) catch unreachable;
}
- pub fn addExpectedLine(self: &TestCase, text: []const u8) {
+ pub fn addExpectedLine(self: &TestCase, text: []const u8) void {
self.expected_lines.append(text) catch unreachable;
}
};
@@ -833,7 +833,7 @@ pub const TranslateCContext = struct {
test_index: usize,
case: &const TestCase,
- pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep {
+ pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) &TranslateCCmpOutputStep {
const allocator = context.b.allocator;
const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
*ptr = TranslateCCmpOutputStep {
@@ -847,7 +847,7 @@ pub const TranslateCContext = struct {
return ptr;
}
- fn make(step: &build.Step) -> %void {
+ fn make(step: &build.Step) %void {
const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
const b = self.context.b;
@@ -934,7 +934,7 @@ pub const TranslateCContext = struct {
}
};
- fn printInvocation(args: []const []const u8) {
+ fn printInvocation(args: []const []const u8) void {
for (args) |arg| {
warn("{} ", arg);
}
@@ -942,7 +942,7 @@ pub const TranslateCContext = struct {
}
pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
- source: []const u8, expected_lines: ...) -> &TestCase
+ source: []const u8, expected_lines: ...) &TestCase
{
const tc = self.b.allocator.create(TestCase) catch unreachable;
*tc = TestCase {
@@ -959,22 +959,22 @@ pub const TranslateCContext = struct {
return tc;
}
- pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
const tc = self.create(false, "source.h", name, source, expected_lines);
self.addCase(tc);
}
- pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
const tc = self.create(false, "source.c", name, source, expected_lines);
self.addCase(tc);
}
- pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
const tc = self.create(true, "source.h", name, source, expected_lines);
self.addCase(tc);
}
- pub fn addCase(self: &TranslateCContext, case: &const TestCase) {
+ pub fn addCase(self: &TranslateCContext, case: &const TestCase) void {
const b = self.b;
const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;
@@ -1010,14 +1010,14 @@ pub const GenHContext = struct {
source: []const u8,
};
- pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
+ pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
self.sources.append(SourceFile {
.filename = filename,
.source = source,
}) catch unreachable;
}
- pub fn addExpectedLine(self: &TestCase, text: []const u8) {
+ pub fn addExpectedLine(self: &TestCase, text: []const u8) void {
self.expected_lines.append(text) catch unreachable;
}
};
@@ -1030,7 +1030,7 @@ pub const GenHContext = struct {
test_index: usize,
case: &const TestCase,
- pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) -> &GenHCmpOutputStep {
+ pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) &GenHCmpOutputStep {
const allocator = context.b.allocator;
const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
*ptr = GenHCmpOutputStep {
@@ -1045,7 +1045,7 @@ pub const GenHContext = struct {
return ptr;
}
- fn make(step: &build.Step) -> %void {
+ fn make(step: &build.Step) %void {
const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
const b = self.context.b;
@@ -1071,7 +1071,7 @@ pub const GenHContext = struct {
}
};
- fn printInvocation(args: []const []const u8) {
+ fn printInvocation(args: []const []const u8) void {
for (args) |arg| {
warn("{} ", arg);
}
@@ -1079,7 +1079,7 @@ pub const GenHContext = struct {
}
pub fn create(self: &GenHContext, filename: []const u8, name: []const u8,
- source: []const u8, expected_lines: ...) -> &TestCase
+ source: []const u8, expected_lines: ...) &TestCase
{
const tc = self.b.allocator.create(TestCase) catch unreachable;
*tc = TestCase {
@@ -1095,12 +1095,12 @@ pub const GenHContext = struct {
return tc;
}
- pub fn add(self: &GenHContext, name: []const u8, source: []const u8, expected_lines: ...) {
+ pub fn add(self: &GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
const tc = self.create("test.zig", name, source, expected_lines);
self.addCase(tc);
}
- pub fn addCase(self: &GenHContext, case: &const TestCase) {
+ pub fn addCase(self: &GenHContext, case: &const TestCase) void {
const b = self.b;
const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
diff --git a/test/translate_c.zig b/test/translate_c.zig
index 8e6a8dda2c..e6270842b1 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -1,6 +1,6 @@
const tests = @import("tests.zig");
-pub fn addCases(cases: &tests.TranslateCContext) {
+pub fn addCases(cases: &tests.TranslateCContext) void {
cases.addAllowWarnings("simple data types",
\\#include