authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-30 16:09:11-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-30 16:09:11-04:00
logea58f4a5a95662637d2142727a0452542bcdb196
treed72b41fea06f8526e899014fd10c2bf9d1a4d759
parentb082cd4580890190218f876bf28816b4878ae85c

run zig fmt on the codebase


48 files changed, 140 insertions(+), 140 deletions(-)

src-self-hosted/main.zig+2-2
...@@ -41,7 +41,7 @@ const usage =...@@ -41,7 +41,7 @@ const usage =
4141
42const Command = struct {42const Command = struct {
43 name: []const u8,43 name: []const u8,
44 exec: fn(&Allocator, []const []const u8) error!void,44 exec: fn (&Allocator, []const []const u8) error!void,
45};45};
4646
47pub fn main() !void {47pub fn main() !void {
...@@ -862,7 +862,7 @@ fn cmdRun(allocator: &Allocator, args: []const []const u8) !void {...@@ -862,7 +862,7 @@ fn cmdRun(allocator: &Allocator, args: []const []const u8) !void {
862 for (args) |argv, i| {862 for (args) |argv, i| {
863 if (mem.eql(u8, argv, "--")) {863 if (mem.eql(u8, argv, "--")) {
864 compile_args = args[0..i];864 compile_args = args[0..i];
865 runtime_args = args[i + 1..];865 runtime_args = args[i + 1 ..];
866 break;866 break;
867 }867 }
868 }868 }
std/array_list.zig+3-3
...@@ -71,7 +71,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -71,7 +71,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
71 try l.ensureCapacity(l.len + 1);71 try l.ensureCapacity(l.len + 1);
72 l.len += 1;72 l.len += 1;
7373
74 mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]);74 mem.copy(T, l.items[n + 1 .. l.len], l.items[n .. l.len - 1]);
75 l.items[n] = item.*;75 l.items[n] = item.*;
76 }76 }
7777
...@@ -79,8 +79,8 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -79,8 +79,8 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
79 try l.ensureCapacity(l.len + items.len);79 try l.ensureCapacity(l.len + items.len);
80 l.len += items.len;80 l.len += items.len;
8181
82 mem.copy(T, l.items[n + items.len..l.len], l.items[n..l.len - items.len]);82 mem.copy(T, l.items[n + items.len .. l.len], l.items[n .. l.len - items.len]);
83 mem.copy(T, l.items[n..n + items.len], items);83 mem.copy(T, l.items[n .. n + items.len], items);
84 }84 }
8585
86 pub fn append(l: &Self, item: &const T) !void {86 pub fn append(l: &Self, item: &const T) !void {
std/base64.zig+1-1
...@@ -450,7 +450,7 @@ fn testError(encoded: []const u8, expected_err: error) !void {...@@ -450,7 +450,7 @@ fn testError(encoded: []const u8, expected_err: error) !void {
450fn testOutputTooSmallError(encoded: []const u8) !void {450fn testOutputTooSmallError(encoded: []const u8) !void {
451 const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");451 const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");
452 var buffer: [0x100]u8 = undefined;452 var buffer: [0x100]u8 = undefined;
453 var decoded = buffer[0..calcDecodedSizeExactUnsafe(encoded, standard_pad_char) - 1];453 var decoded = buffer[0 .. calcDecodedSizeExactUnsafe(encoded, standard_pad_char) - 1];
454 if (standard_decoder_ignore_space.decode(decoded, encoded)) |_| {454 if (standard_decoder_ignore_space.decode(decoded, encoded)) |_| {
455 return error.ExpectedError;455 return error.ExpectedError;
456 } else |err| if (err != error.OutputTooSmall) return err;456 } else |err| if (err != error.OutputTooSmall) return err;
std/build.zig+2-2
...@@ -1912,12 +1912,12 @@ pub const RemoveDirStep = struct {...@@ -1912,12 +1912,12 @@ pub const RemoveDirStep = struct {
19121912
1913pub const Step = struct {1913pub const Step = struct {
1914 name: []const u8,1914 name: []const u8,
1915 makeFn: fn(self: &Step) error!void,1915 makeFn: fn (self: &Step) error!void,
1916 dependencies: ArrayList(&Step),1916 dependencies: ArrayList(&Step),
1917 loop_flag: bool,1917 loop_flag: bool,
1918 done_flag: bool,1918 done_flag: bool,
19191919
1920 pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn(&Step) error!void) Step {1920 pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step) error!void) Step {
1921 return Step{1921 return Step{
1922 .name = name,1922 .name = name,
1923 .makeFn = makeFn,1923 .makeFn = makeFn,
std/c/darwin.zig+1-1
...@@ -60,7 +60,7 @@ pub const sigset_t = u32;...@@ -60,7 +60,7 @@ pub const sigset_t = u32;
6060
61/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.61/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
62pub const Sigaction = extern struct {62pub const Sigaction = extern struct {
63 handler: extern fn(c_int) void,63 handler: extern fn (c_int) void,
64 sa_mask: sigset_t,64 sa_mask: sigset_t,
65 sa_flags: c_int,65 sa_flags: c_int,
66};66};
std/c/index.zig+1-1
...@@ -52,7 +52,7 @@ pub extern "c" fn realloc(&c_void, usize) ?&c_void;...@@ -52,7 +52,7 @@ pub extern "c" fn realloc(&c_void, usize) ?&c_void;
52pub extern "c" fn free(&c_void) void;52pub extern "c" fn free(&c_void) void;
53pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int;53pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int;
5454
55pub extern "pthread" fn pthread_create(noalias newthread: &pthread_t, noalias attr: ?&const pthread_attr_t, start_routine: extern fn(?&c_void) ?&c_void, noalias arg: ?&c_void) c_int;55pub extern "pthread" fn pthread_create(noalias newthread: &pthread_t, noalias attr: ?&const pthread_attr_t, start_routine: extern fn (?&c_void) ?&c_void, noalias arg: ?&c_void) c_int;
56pub extern "pthread" fn pthread_attr_init(attr: &pthread_attr_t) c_int;56pub extern "pthread" fn pthread_attr_init(attr: &pthread_attr_t) c_int;
57pub extern "pthread" fn pthread_attr_setstack(attr: &pthread_attr_t, stackaddr: &c_void, stacksize: usize) c_int;57pub extern "pthread" fn pthread_attr_setstack(attr: &pthread_attr_t, stackaddr: &c_void, stacksize: usize) c_int;
58pub extern "pthread" fn pthread_attr_destroy(attr: &pthread_attr_t) c_int;58pub extern "pthread" fn pthread_attr_destroy(attr: &pthread_attr_t) c_int;
std/crypto/blake2.zig+8-8
...@@ -105,7 +105,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -105,7 +105,7 @@ fn Blake2s(comptime out_len: usize) type {
105 // Full middle blocks.105 // Full middle blocks.
106 while (off + 64 <= b.len) : (off += 64) {106 while (off + 64 <= b.len) : (off += 64) {
107 d.t += 64;107 d.t += 64;
108 d.round(b[off..off + 64], false);108 d.round(b[off .. off + 64], false);
109 }109 }
110110
111 // Copy any remainder for next pass.111 // Copy any remainder for next pass.
...@@ -120,10 +120,10 @@ fn Blake2s(comptime out_len: usize) type {...@@ -120,10 +120,10 @@ fn Blake2s(comptime out_len: usize) type {
120 d.t += d.buf_len;120 d.t += d.buf_len;
121 d.round(d.buf[0..], true);121 d.round(d.buf[0..], true);
122122
123 const rr = d.h[0..out_len / 32];123 const rr = d.h[0 .. out_len / 32];
124124
125 for (rr) |s, j| {125 for (rr) |s, j| {
126 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Little);126 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Little);
127 }127 }
128 }128 }
129129
...@@ -134,7 +134,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -134,7 +134,7 @@ fn Blake2s(comptime out_len: usize) type {
134 var v: [16]u32 = undefined;134 var v: [16]u32 = undefined;
135135
136 for (m) |*r, i| {136 for (m) |*r, i| {
137 r.* = mem.readIntLE(u32, b[4 * i..4 * i + 4]);137 r.* = mem.readIntLE(u32, b[4 * i .. 4 * i + 4]);
138 }138 }
139139
140 var k: usize = 0;140 var k: usize = 0;
...@@ -340,7 +340,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -340,7 +340,7 @@ fn Blake2b(comptime out_len: usize) type {
340 // Full middle blocks.340 // Full middle blocks.
341 while (off + 128 <= b.len) : (off += 128) {341 while (off + 128 <= b.len) : (off += 128) {
342 d.t += 128;342 d.t += 128;
343 d.round(b[off..off + 128], false);343 d.round(b[off .. off + 128], false);
344 }344 }
345345
346 // Copy any remainder for next pass.346 // Copy any remainder for next pass.
...@@ -353,10 +353,10 @@ fn Blake2b(comptime out_len: usize) type {...@@ -353,10 +353,10 @@ fn Blake2b(comptime out_len: usize) type {
353 d.t += d.buf_len;353 d.t += d.buf_len;
354 d.round(d.buf[0..], true);354 d.round(d.buf[0..], true);
355355
356 const rr = d.h[0..out_len / 64];356 const rr = d.h[0 .. out_len / 64];
357357
358 for (rr) |s, j| {358 for (rr) |s, j| {
359 mem.writeInt(out[8 * j..8 * j + 8], s, builtin.Endian.Little);359 mem.writeInt(out[8 * j .. 8 * j + 8], s, builtin.Endian.Little);
360 }360 }
361 }361 }
362362
...@@ -367,7 +367,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -367,7 +367,7 @@ fn Blake2b(comptime out_len: usize) type {
367 var v: [16]u64 = undefined;367 var v: [16]u64 = undefined;
368368
369 for (m) |*r, i| {369 for (m) |*r, i| {
370 r.* = mem.readIntLE(u64, b[8 * i..8 * i + 8]);370 r.* = mem.readIntLE(u64, b[8 * i .. 8 * i + 8]);
371 }371 }
372372
373 var k: usize = 0;373 var k: usize = 0;
std/crypto/md5.zig+2-2
...@@ -73,7 +73,7 @@ pub const Md5 = struct {...@@ -73,7 +73,7 @@ pub const Md5 = struct {
7373
74 // Full middle blocks.74 // Full middle blocks.
75 while (off + 64 <= b.len) : (off += 64) {75 while (off + 64 <= b.len) : (off += 64) {
76 d.round(b[off..off + 64]);76 d.round(b[off .. off + 64]);
77 }77 }
7878
79 // Copy any remainder for next pass.79 // Copy any remainder for next pass.
...@@ -112,7 +112,7 @@ pub const Md5 = struct {...@@ -112,7 +112,7 @@ pub const Md5 = struct {
112 d.round(d.buf[0..]);112 d.round(d.buf[0..]);
113113
114 for (d.s) |s, j| {114 for (d.s) |s, j| {
115 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Little);115 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Little);
116 }116 }
117 }117 }
118118
std/crypto/sha1.zig+2-2
...@@ -73,7 +73,7 @@ pub const Sha1 = struct {...@@ -73,7 +73,7 @@ pub const Sha1 = struct {
7373
74 // Full middle blocks.74 // Full middle blocks.
75 while (off + 64 <= b.len) : (off += 64) {75 while (off + 64 <= b.len) : (off += 64) {
76 d.round(b[off..off + 64]);76 d.round(b[off .. off + 64]);
77 }77 }
7878
79 // Copy any remainder for next pass.79 // Copy any remainder for next pass.
...@@ -111,7 +111,7 @@ pub const Sha1 = struct {...@@ -111,7 +111,7 @@ pub const Sha1 = struct {
111 d.round(d.buf[0..]);111 d.round(d.buf[0..]);
112112
113 for (d.s) |s, j| {113 for (d.s) |s, j| {
114 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Big);114 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Big);
115 }115 }
116 }116 }
117117
std/crypto/sha2.zig+6-6
...@@ -126,7 +126,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -126,7 +126,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
126126
127 // Full middle blocks.127 // Full middle blocks.
128 while (off + 64 <= b.len) : (off += 64) {128 while (off + 64 <= b.len) : (off += 64) {
129 d.round(b[off..off + 64]);129 d.round(b[off .. off + 64]);
130 }130 }
131131
132 // Copy any remainder for next pass.132 // Copy any remainder for next pass.
...@@ -164,10 +164,10 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -164,10 +164,10 @@ fn Sha2_32(comptime params: Sha2Params32) type {
164 d.round(d.buf[0..]);164 d.round(d.buf[0..]);
165165
166 // May truncate for possible 224 output166 // May truncate for possible 224 output
167 const rr = d.s[0..params.out_len / 32];167 const rr = d.s[0 .. params.out_len / 32];
168168
169 for (rr) |s, j| {169 for (rr) |s, j| {
170 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Big);170 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Big);
171 }171 }
172 }172 }
173173
...@@ -467,7 +467,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -467,7 +467,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
467467
468 // Full middle blocks.468 // Full middle blocks.
469 while (off + 128 <= b.len) : (off += 128) {469 while (off + 128 <= b.len) : (off += 128) {
470 d.round(b[off..off + 128]);470 d.round(b[off .. off + 128]);
471 }471 }
472472
473 // Copy any remainder for next pass.473 // Copy any remainder for next pass.
...@@ -505,10 +505,10 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -505,10 +505,10 @@ fn Sha2_64(comptime params: Sha2Params64) type {
505 d.round(d.buf[0..]);505 d.round(d.buf[0..]);
506506
507 // May truncate for possible 384 output507 // May truncate for possible 384 output
508 const rr = d.s[0..params.out_len / 64];508 const rr = d.s[0 .. params.out_len / 64];
509509
510 for (rr) |s, j| {510 for (rr) |s, j| {
511 mem.writeInt(out[8 * j..8 * j + 8], s, builtin.Endian.Big);511 mem.writeInt(out[8 * j .. 8 * j + 8], s, builtin.Endian.Big);
512 }512 }
513 }513 }
514514
std/crypto/sha3.zig+4-4
...@@ -46,7 +46,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {...@@ -46,7 +46,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
4646
47 // absorb47 // absorb
48 while (len >= rate) {48 while (len >= rate) {
49 for (d.s[offset..offset + rate]) |*r, i|49 for (d.s[offset .. offset + rate]) |*r, i|
50 r.* ^= b[ip..][i];50 r.* ^= b[ip..][i];
5151
52 keccak_f(1600, d.s[0..]);52 keccak_f(1600, d.s[0..]);
...@@ -57,7 +57,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {...@@ -57,7 +57,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
57 offset = 0;57 offset = 0;
58 }58 }
5959
60 for (d.s[offset..offset + len]) |*r, i|60 for (d.s[offset .. offset + len]) |*r, i|
61 r.* ^= b[ip..][i];61 r.* ^= b[ip..][i];
6262
63 d.offset = offset + len;63 d.offset = offset + len;
...@@ -193,7 +193,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {...@@ -193,7 +193,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
193 var c = []const u64{0} ** 5;193 var c = []const u64{0} ** 5;
194194
195 for (s) |*r, i| {195 for (s) |*r, i| {
196 r.* = mem.readIntLE(u64, d[8 * i..8 * i + 8]);196 r.* = mem.readIntLE(u64, d[8 * i .. 8 * i + 8]);
197 }197 }
198198
199 comptime var x: usize = 0;199 comptime var x: usize = 0;
...@@ -240,7 +240,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {...@@ -240,7 +240,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
240 }240 }
241241
242 for (s) |r, i| {242 for (s) |r, i| {
243 mem.writeInt(d[8 * i..8 * i + 8], r, builtin.Endian.Little);243 mem.writeInt(d[8 * i .. 8 * i + 8], r, builtin.Endian.Little);
244 }244 }
245}245}
246246
std/crypto/test.zig+1-1
...@@ -14,7 +14,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu...@@ -14,7 +14,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
14pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {14pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
15 var expected_bytes: [expected.len / 2]u8 = undefined;15 var expected_bytes: [expected.len / 2]u8 = undefined;
16 for (expected_bytes) |*r, i| {16 for (expected_bytes) |*r, i| {
17 r.* = fmt.parseInt(u8, expected[2 * i..2 * i + 2], 16) catch unreachable;17 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
18 }18 }
1919
20 debug.assert(mem.eql(u8, expected_bytes, input));20 debug.assert(mem.eql(u8, expected_bytes, input));
std/event.zig+2-2
...@@ -6,7 +6,7 @@ const mem = std.mem;...@@ -6,7 +6,7 @@ const mem = std.mem;
6const posix = std.os.posix;6const posix = std.os.posix;
77
8pub const TcpServer = struct {8pub const TcpServer = struct {
9 handleRequestFn: async<&mem.Allocator> fn(&TcpServer, &const std.net.Address, &const std.os.File) void,9 handleRequestFn: async<&mem.Allocator> fn (&TcpServer, &const std.net.Address, &const std.os.File) void,
1010
11 loop: &Loop,11 loop: &Loop,
12 sockfd: i32,12 sockfd: i32,
...@@ -32,7 +32,7 @@ pub const TcpServer = struct {...@@ -32,7 +32,7 @@ pub const TcpServer = struct {
32 };32 };
33 }33 }
3434
35 pub fn listen(self: &TcpServer, address: &const std.net.Address, handleRequestFn: async<&mem.Allocator> fn(&TcpServer, &const std.net.Address, &const std.os.File) void) !void {35 pub fn listen(self: &TcpServer, address: &const std.net.Address, handleRequestFn: async<&mem.Allocator> fn (&TcpServer, &const std.net.Address, &const std.os.File) void) !void {
36 self.handleRequestFn = handleRequestFn;36 self.handleRequestFn = handleRequestFn;
3737
38 try std.os.posixBind(self.sockfd, &address.os_addr);38 try std.os.posixBind(self.sockfd, &address.os_addr);
std/fmt/errol/index.zig+2-2
...@@ -60,7 +60,7 @@ pub fn roundToPrecision(float_decimal: &FloatDecimal, precision: usize, mode: Ro...@@ -60,7 +60,7 @@ pub fn roundToPrecision(float_decimal: &FloatDecimal, precision: usize, mode: Ro
6060
61 // Re-size the buffer to use the reserved leading byte.61 // Re-size the buffer to use the reserved leading byte.
62 const one_before = @intToPtr(&u8, @ptrToInt(&float_decimal.digits[0]) - 1);62 const one_before = @intToPtr(&u8, @ptrToInt(&float_decimal.digits[0]) - 1);
63 float_decimal.digits = one_before[0..float_decimal.digits.len + 1];63 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
64 float_decimal.digits[0] = '1';64 float_decimal.digits[0] = '1';
65 return;65 return;
66 }66 }
...@@ -84,7 +84,7 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {...@@ -84,7 +84,7 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
84 const i = tableLowerBound(bits);84 const i = tableLowerBound(bits);
85 if (i < enum3.len and enum3[i] == bits) {85 if (i < enum3.len and enum3[i] == bits) {
86 const data = enum3_data[i];86 const data = enum3_data[i];
87 const digits = buffer[1..data.str.len + 1];87 const digits = buffer[1 .. data.str.len + 1];
88 mem.copy(u8, digits, data.str);88 mem.copy(u8, digits, data.str);
89 return FloatDecimal{89 return FloatDecimal{
90 .digits = digits,90 .digits = digits,
std/fmt/index.zig+13-13
...@@ -11,7 +11,7 @@ const max_int_digits = 65;...@@ -11,7 +11,7 @@ const max_int_digits = 65;
11/// Renders fmt string with args, calling output with slices of bytes.11/// Renders fmt string with args, calling output with slices of bytes.
12/// If `output` returns an error, the error is returned from `format` and12/// If `output` returns an error, the error is returned from `format` and
13/// `output` is not called again.13/// `output` is not called again.
14pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {14pub fn format(context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {
15 const State = enum {15 const State = enum {
16 Start,16 Start,
17 OpenBrace,17 OpenBrace,
...@@ -268,7 +268,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),...@@ -268,7 +268,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
268 }268 }
269}269}
270270
271pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {271pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
272 const T = @typeOf(value);272 const T = @typeOf(value);
273 switch (@typeId(T)) {273 switch (@typeId(T)) {
274 builtin.TypeId.Int => {274 builtin.TypeId.Int => {
...@@ -317,11 +317,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@...@@ -317,11 +317,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
317 }317 }
318}318}
319319
320pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {320pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
321 return output(context, (&c)[0..1]);321 return output(context, (&c)[0..1]);
322}322}
323323
324pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {324pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
325 try output(context, buf);325 try output(context, buf);
326326
327 var leftover_padding = if (width > buf.len) (width - buf.len) else return;327 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
...@@ -334,7 +334,7 @@ pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: t...@@ -334,7 +334,7 @@ pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: t
334// Print a float in scientific notation to the specified precision. Null uses full precision.334// Print a float in scientific notation to the specified precision. Null uses full precision.
335// It should be the case that every full precision, printed value can be re-parsed back to the335// It should be the case that every full precision, printed value can be re-parsed back to the
336// same type unambiguously.336// same type unambiguously.
337pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {337pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
338 var x = f64(value);338 var x = f64(value);
339339
340 // Errol doesn't handle these special cases.340 // Errol doesn't handle these special cases.
...@@ -423,7 +423,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,...@@ -423,7 +423,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
423423
424// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.424// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
425// By default floats are printed at full precision (no rounding).425// By default floats are printed at full precision (no rounding).
426pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {426pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
427 var x = f64(value);427 var x = f64(value);
428428
429 // Errol doesn't handle these special cases.429 // Errol doesn't handle these special cases.
...@@ -512,7 +512,7 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com...@@ -512,7 +512,7 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
512 // Remaining fractional portion, zero-padding if insufficient.512 // Remaining fractional portion, zero-padding if insufficient.
513 debug.assert(precision >= printed);513 debug.assert(precision >= printed);
514 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {514 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
515 try output(context, float_decimal.digits[num_digits_whole_no_pad..num_digits_whole_no_pad + precision - printed]);515 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
516 return;516 return;
517 } else {517 } else {
518 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);518 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
...@@ -568,7 +568,7 @@ pub fn formatBytes(...@@ -568,7 +568,7 @@ pub fn formatBytes(
568 comptime radix: usize,568 comptime radix: usize,
569 context: var,569 context: var,
570 comptime Errors: type,570 comptime Errors: type,
571 output: fn(@typeOf(context), []const u8) Errors!void,571 output: fn (@typeOf(context), []const u8) Errors!void,
572) Errors!void {572) Errors!void {
573 if (value == 0) {573 if (value == 0) {
574 return output(context, "0B");574 return output(context, "0B");
...@@ -604,7 +604,7 @@ pub fn formatInt(...@@ -604,7 +604,7 @@ pub fn formatInt(
604 width: usize,604 width: usize,
605 context: var,605 context: var,
606 comptime Errors: type,606 comptime Errors: type,
607 output: fn(@typeOf(context), []const u8) Errors!void,607 output: fn (@typeOf(context), []const u8) Errors!void,
608) Errors!void {608) Errors!void {
609 if (@typeOf(value).is_signed) {609 if (@typeOf(value).is_signed) {
610 return formatIntSigned(value, base, uppercase, width, context, Errors, output);610 return formatIntSigned(value, base, uppercase, width, context, Errors, output);
...@@ -613,7 +613,7 @@ pub fn formatInt(...@@ -613,7 +613,7 @@ pub fn formatInt(
613 }613 }
614}614}
615615
616fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {616fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
617 const uint = @IntType(false, @typeOf(value).bit_count);617 const uint = @IntType(false, @typeOf(value).bit_count);
618 if (value < 0) {618 if (value < 0) {
619 const minus_sign: u8 = '-';619 const minus_sign: u8 = '-';
...@@ -632,7 +632,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context:...@@ -632,7 +632,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context:
632 }632 }
633}633}
634634
635fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {635fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
636 // max_int_digits accounts for the minus sign. when printing an unsigned636 // max_int_digits accounts for the minus sign. when printing an unsigned
637 // number we don't need to do that.637 // number we don't need to do that.
638 var buf: [max_int_digits - 1]u8 = undefined;638 var buf: [max_int_digits - 1]u8 = undefined;
...@@ -661,7 +661,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, contex...@@ -661,7 +661,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, contex
661 mem.set(u8, buf[0..index], '0');661 mem.set(u8, buf[0..index], '0');
662 return output(context, buf);662 return output(context, buf);
663 } else {663 } else {
664 const padded_buf = buf[index - padding..];664 const padded_buf = buf[index - padding ..];
665 mem.set(u8, padded_buf[0..padding], '0');665 mem.set(u8, padded_buf[0..padding], '0');
666 return output(context, padded_buf);666 return output(context, padded_buf);
667 }667 }
...@@ -760,7 +760,7 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {...@@ -760,7 +760,7 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
760pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {760pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
761 var context = BufPrintContext{ .remaining = buf };761 var context = BufPrintContext{ .remaining = buf };
762 try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);762 try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);
763 return buf[0..buf.len - context.remaining.len];763 return buf[0 .. buf.len - context.remaining.len];
764}764}
765765
766pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {766pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
std/hash/crc.zig+1-1
...@@ -61,7 +61,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {...@@ -61,7 +61,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
61 pub fn update(self: &Self, input: []const u8) void {61 pub fn update(self: &Self, input: []const u8) void {
62 var i: usize = 0;62 var i: usize = 0;
63 while (i + 8 <= input.len) : (i += 8) {63 while (i + 8 <= input.len) : (i += 8) {
64 const p = input[i..i + 8];64 const p = input[i .. i + 8];
6565
66 // Unrolling this way gives ~50Mb/s increase66 // Unrolling this way gives ~50Mb/s increase
67 self.crc ^= (u32(p[0]) << 0);67 self.crc ^= (u32(p[0]) << 0);
std/hash/siphash.zig+1-1
...@@ -76,7 +76,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -76,7 +76,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
7676
77 // Full middle blocks.77 // Full middle blocks.
78 while (off + 8 <= b.len) : (off += 8) {78 while (off + 8 <= b.len) : (off += 8) {
79 d.round(b[off..off + 8]);79 d.round(b[off .. off + 8]);
80 }80 }
8181
82 // Remainder for next pass.82 // Remainder for next pass.
std/hash_map.zig+1-1
...@@ -9,7 +9,7 @@ const builtin = @import("builtin");...@@ -9,7 +9,7 @@ const builtin = @import("builtin");
9const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast;9const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast;
10const debug_u32 = if (want_modification_safety) u32 else void;10const debug_u32 = if (want_modification_safety) u32 else void;
1111
12pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32, comptime eql: fn(a: K, b: K) bool) type {12pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u32, comptime eql: fn (a: K, b: K) bool) type {
13 return struct {13 return struct {
14 entries: []Entry,14 entries: []Entry,
15 size: usize,15 size: usize,
std/io.zig+3-3
...@@ -82,7 +82,7 @@ pub fn InStream(comptime ReadError: type) type {...@@ -82,7 +82,7 @@ pub fn InStream(comptime ReadError: type) type {
82 /// Return the number of bytes read. If the number read is smaller than buf.len, it82 /// Return the number of bytes read. If the number read is smaller than buf.len, it
83 /// means the stream reached the end. Reaching the end of a stream is not an error83 /// means the stream reached the end. Reaching the end of a stream is not an error
84 /// condition.84 /// condition.
85 readFn: fn(self: &Self, buffer: []u8) Error!usize,85 readFn: fn (self: &Self, buffer: []u8) Error!usize,
8686
87 /// Replaces `buffer` contents by reading from the stream until it is finished.87 /// Replaces `buffer` contents by reading from the stream until it is finished.
88 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and88 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
...@@ -208,7 +208,7 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -208,7 +208,7 @@ pub fn OutStream(comptime WriteError: type) type {
208 const Self = this;208 const Self = this;
209 pub const Error = WriteError;209 pub const Error = WriteError;
210210
211 writeFn: fn(self: &Self, bytes: []const u8) Error!void,211 writeFn: fn (self: &Self, bytes: []const u8) Error!void,
212212
213 pub fn print(self: &Self, comptime format: []const u8, args: ...) !void {213 pub fn print(self: &Self, comptime format: []const u8, args: ...) !void {
214 return std.fmt.format(self, Error, self.writeFn, format, args);214 return std.fmt.format(self, Error, self.writeFn, format, args);
...@@ -369,7 +369,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr...@@ -369,7 +369,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
369 while (src_index < bytes.len) {369 while (src_index < bytes.len) {
370 const dest_space_left = self.buffer.len - self.index;370 const dest_space_left = self.buffer.len - self.index;
371 const copy_amt = math.min(dest_space_left, bytes.len - src_index);371 const copy_amt = math.min(dest_space_left, bytes.len - src_index);
372 mem.copy(u8, self.buffer[self.index..], bytes[src_index..src_index + copy_amt]);372 mem.copy(u8, self.buffer[self.index..], bytes[src_index .. src_index + copy_amt]);
373 self.index += copy_amt;373 self.index += copy_amt;
374 assert(self.index <= self.buffer.len);374 assert(self.index <= self.buffer.len);
375 if (self.index == self.buffer.len) {375 if (self.index == self.buffer.len) {
std/io_test.zig+2-2
...@@ -41,8 +41,8 @@ test "write a file, read it, then delete it" {...@@ -41,8 +41,8 @@ test "write a file, read it, then delete it" {
41 defer allocator.free(contents);41 defer allocator.free(contents);
4242
43 assert(mem.eql(u8, contents[0.."begin".len], "begin"));43 assert(mem.eql(u8, contents[0.."begin".len], "begin"));
44 assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data));44 assert(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
45 assert(mem.eql(u8, contents[contents.len - "end".len..], "end"));45 assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
46 }46 }
47 try os.deleteFile(allocator, tmp_file_name);47 try os.deleteFile(allocator, tmp_file_name);
48}48}
std/json.zig+1-1
...@@ -77,7 +77,7 @@ pub const Token = struct {...@@ -77,7 +77,7 @@ pub const Token = struct {
7777
78 // Slice into the underlying input string.78 // Slice into the underlying input string.
79 pub fn slice(self: &const Token, input: []const u8, i: usize) []const u8 {79 pub fn slice(self: &const Token, input: []const u8, i: usize) []const u8 {
80 return input[i + self.offset - self.count..i + self.offset];80 return input[i + self.offset - self.count .. i + self.offset];
81 }81 }
82};82};
8383
std/mem.zig+6-6
...@@ -13,7 +13,7 @@ pub const Allocator = struct {...@@ -13,7 +13,7 @@ pub const Allocator = struct {
13 /// The returned newly allocated memory is undefined.13 /// The returned newly allocated memory is undefined.
14 /// `alignment` is guaranteed to be >= 114 /// `alignment` is guaranteed to be >= 1
15 /// `alignment` is guaranteed to be a power of 215 /// `alignment` is guaranteed to be a power of 2
16 allocFn: fn(self: &Allocator, byte_count: usize, alignment: u29) Error![]u8,16 allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) Error![]u8,
1717
18 /// If `new_byte_count > old_mem.len`:18 /// If `new_byte_count > old_mem.len`:
19 /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.19 /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.
...@@ -26,10 +26,10 @@ pub const Allocator = struct {...@@ -26,10 +26,10 @@ pub const Allocator = struct {
26 /// The returned newly allocated memory is undefined.26 /// The returned newly allocated memory is undefined.
27 /// `alignment` is guaranteed to be >= 127 /// `alignment` is guaranteed to be >= 1
28 /// `alignment` is guaranteed to be a power of 228 /// `alignment` is guaranteed to be a power of 2
29 reallocFn: fn(self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) Error![]u8,29 reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) Error![]u8,
3030
31 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`31 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
32 freeFn: fn(self: &Allocator, old_mem: []u8) void,32 freeFn: fn (self: &Allocator, old_mem: []u8) void,
3333
34 fn create(self: &Allocator, comptime T: type) !&T {34 fn create(self: &Allocator, comptime T: type) !&T {
35 if (@sizeOf(T) == 0) return &{};35 if (@sizeOf(T) == 0) return &{};
...@@ -282,7 +282,7 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us...@@ -282,7 +282,7 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us
282282
283 var i: usize = haystack.len - needle.len;283 var i: usize = haystack.len - needle.len;
284 while (true) : (i -= 1) {284 while (true) : (i -= 1) {
285 if (mem.eql(T, haystack[i..i + needle.len], needle)) return i;285 if (mem.eql(T, haystack[i .. i + needle.len], needle)) return i;
286 if (i == 0) return null;286 if (i == 0) return null;
287 }287 }
288}288}
...@@ -294,7 +294,7 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee...@@ -294,7 +294,7 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
294 var i: usize = start_index;294 var i: usize = start_index;
295 const end = haystack.len - needle.len;295 const end = haystack.len - needle.len;
296 while (i <= end) : (i += 1) {296 while (i <= end) : (i += 1) {
297 if (eql(T, haystack[i..i + needle.len], needle)) return i;297 if (eql(T, haystack[i .. i + needle.len], needle)) return i;
298 }298 }
299 return null;299 return null;
300}300}
...@@ -444,7 +444,7 @@ test "mem.startsWith" {...@@ -444,7 +444,7 @@ test "mem.startsWith" {
444}444}
445445
446pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {446pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
447 return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len..], needle);447 return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len ..], needle);
448}448}
449449
450test "mem.endsWith" {450test "mem.endsWith" {
std/os/darwin.zig+3-3
...@@ -437,7 +437,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -437,7 +437,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti
437 assert(sig != SIGKILL);437 assert(sig != SIGKILL);
438 assert(sig != SIGSTOP);438 assert(sig != SIGSTOP);
439 var cact = c.Sigaction{439 var cact = c.Sigaction{
440 .handler = @ptrCast(extern fn(c_int) void, act.handler),440 .handler = @ptrCast(extern fn (c_int) void, act.handler),
441 .sa_flags = @bitCast(c_int, act.flags),441 .sa_flags = @bitCast(c_int, act.flags),
442 .sa_mask = act.mask,442 .sa_mask = act.mask,
443 };443 };
...@@ -448,7 +448,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -448,7 +448,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti
448 }448 }
449 if (oact) |old| {449 if (oact) |old| {
450 old.* = Sigaction{450 old.* = Sigaction{
451 .handler = @ptrCast(extern fn(i32) void, coact.handler),451 .handler = @ptrCast(extern fn (i32) void, coact.handler),
452 .flags = @bitCast(u32, coact.sa_flags),452 .flags = @bitCast(u32, coact.sa_flags),
453 .mask = coact.sa_mask,453 .mask = coact.sa_mask,
454 };454 };
...@@ -468,7 +468,7 @@ pub const sockaddr = c.sockaddr;...@@ -468,7 +468,7 @@ pub const sockaddr = c.sockaddr;
468468
469/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.469/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
470pub const Sigaction = struct {470pub const Sigaction = struct {
471 handler: extern fn(i32) void,471 handler: extern fn (i32) void,
472 mask: sigset_t,472 mask: sigset_t,
473 flags: u32,473 flags: u32,
474};474};
std/os/index.zig+8-8
...@@ -399,7 +399,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)...@@ -399,7 +399,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)
399399
400pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {400pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {
401 for (envp_buf) |env| {401 for (envp_buf) |env| {
402 const env_buf = if (env) |ptr| ptr[0..cstr.len(ptr) + 1] else break;402 const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
403 allocator.free(env_buf);403 allocator.free(env_buf);
404 }404 }
405 allocator.free(envp_buf);405 allocator.free(envp_buf);
...@@ -449,7 +449,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:...@@ -449,7 +449,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:
449 while (it.next()) |search_path| {449 while (it.next()) |search_path| {
450 mem.copy(u8, path_buf, search_path);450 mem.copy(u8, path_buf, search_path);
451 path_buf[search_path.len] = '/';451 path_buf[search_path.len] = '/';
452 mem.copy(u8, path_buf[search_path.len + 1..], exe_path);452 mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path);
453 path_buf[search_path.len + exe_path.len + 1] = 0;453 path_buf[search_path.len + exe_path.len + 1] = 0;
454 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));454 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));
455 assert(err > 0);455 assert(err > 0);
...@@ -532,7 +532,7 @@ pub fn getEnvMap(allocator: &Allocator) !BufMap {...@@ -532,7 +532,7 @@ pub fn getEnvMap(allocator: &Allocator) !BufMap {
532532
533 var end_i: usize = line_i;533 var end_i: usize = line_i;
534 while (ptr[end_i] != 0) : (end_i += 1) {}534 while (ptr[end_i] != 0) : (end_i += 1) {}
535 const value = ptr[line_i + 1..end_i];535 const value = ptr[line_i + 1 .. end_i];
536536
537 try result.set(key, value);537 try result.set(key, value);
538 }538 }
...@@ -549,7 +549,7 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {...@@ -549,7 +549,7 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {
549549
550 var end_i: usize = line_i;550 var end_i: usize = line_i;
551 while (ptr[end_i] != 0) : (end_i += 1) {}551 while (ptr[end_i] != 0) : (end_i += 1) {}
552 const this_value = ptr[line_i + 1..end_i];552 const this_value = ptr[line_i + 1 .. end_i];
553553
554 return this_value;554 return this_value;
555 }555 }
...@@ -691,7 +691,7 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:...@@ -691,7 +691,7 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:
691 mem.copy(u8, existing_buf, existing_path);691 mem.copy(u8, existing_buf, existing_path);
692 existing_buf[existing_path.len] = 0;692 existing_buf[existing_path.len] = 0;
693693
694 const new_buf = full_buf[existing_path.len + 1..];694 const new_buf = full_buf[existing_path.len + 1 ..];
695 mem.copy(u8, new_buf, new_path);695 mem.copy(u8, new_buf, new_path);
696 new_buf[new_path.len] = 0;696 new_buf[new_path.len] = 0;
697697
...@@ -735,7 +735,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:...@@ -735,7 +735,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
735 tmp_path[dirname.len] = os.path.sep;735 tmp_path[dirname.len] = os.path.sep;
736 while (true) {736 while (true) {
737 try getRandomBytes(rand_buf[0..]);737 try getRandomBytes(rand_buf[0..]);
738 b64_fs_encoder.encode(tmp_path[dirname.len + 1..], rand_buf);738 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
739739
740 if (symLink(allocator, existing_path, tmp_path)) {740 if (symLink(allocator, existing_path, tmp_path)) {
741 return rename(allocator, tmp_path, new_path);741 return rename(allocator, tmp_path, new_path);
...@@ -914,7 +914,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)...@@ -914,7 +914,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
914 mem.copy(u8, old_buf, old_path);914 mem.copy(u8, old_buf, old_path);
915 old_buf[old_path.len] = 0;915 old_buf[old_path.len] = 0;
916916
917 const new_buf = full_buf[old_path.len + 1..];917 const new_buf = full_buf[old_path.len + 1 ..];
918 mem.copy(u8, new_buf, new_path);918 mem.copy(u8, new_buf, new_path);
919 new_buf[new_path.len] = 0;919 new_buf[new_path.len] = 0;
920920
...@@ -1141,7 +1141,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!...@@ -1141,7 +1141,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
1141 const full_entry_path = full_entry_buf.toSlice();1141 const full_entry_path = full_entry_buf.toSlice();
1142 mem.copy(u8, full_entry_path, full_path);1142 mem.copy(u8, full_entry_path, full_path);
1143 full_entry_path[full_path.len] = '/';1143 full_entry_path[full_path.len] = '/';
1144 mem.copy(u8, full_entry_path[full_path.len + 1..], entry.name);1144 mem.copy(u8, full_entry_path[full_path.len + 1 ..], entry.name);
11451145
1146 try deleteTree(allocator, full_entry_path);1146 try deleteTree(allocator, full_entry_path);
1147 }1147 }
std/os/linux/index.zig+7-7
...@@ -939,7 +939,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -939,7 +939,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
939 .handler = act.handler,939 .handler = act.handler,
940 .flags = act.flags | SA_RESTORER,940 .flags = act.flags | SA_RESTORER,
941 .mask = undefined,941 .mask = undefined,
942 .restorer = @ptrCast(extern fn() void, restore_rt),942 .restorer = @ptrCast(extern fn () void, restore_rt),
943 };943 };
944 var ksa_old: k_sigaction = undefined;944 var ksa_old: k_sigaction = undefined;
945 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);945 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
...@@ -962,22 +962,22 @@ const all_mask = []usize{@maxValue(usize)};...@@ -962,22 +962,22 @@ const all_mask = []usize{@maxValue(usize)};
962const app_mask = []usize{0xfffffffc7fffffff};962const app_mask = []usize{0xfffffffc7fffffff};
963963
964const k_sigaction = extern struct {964const k_sigaction = extern struct {
965 handler: extern fn(i32) void,965 handler: extern fn (i32) void,
966 flags: usize,966 flags: usize,
967 restorer: extern fn() void,967 restorer: extern fn () void,
968 mask: [2]u32,968 mask: [2]u32,
969};969};
970970
971/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.971/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
972pub const Sigaction = struct {972pub const Sigaction = struct {
973 handler: extern fn(i32) void,973 handler: extern fn (i32) void,
974 mask: sigset_t,974 mask: sigset_t,
975 flags: u32,975 flags: u32,
976};976};
977977
978pub const SIG_ERR = @intToPtr(extern fn(i32) void, @maxValue(usize));978pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
979pub const SIG_DFL = @intToPtr(extern fn(i32) void, 0);979pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
980pub const SIG_IGN = @intToPtr(extern fn(i32) void, 1);980pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
981pub const empty_sigset = []usize{0} ** sigset_t.len;981pub const empty_sigset = []usize{0} ** sigset_t.len;
982982
983pub fn raise(sig: i32) usize {983pub fn raise(sig: i32) usize {
std/os/linux/x86_64.zig+1-1
...@@ -463,7 +463,7 @@ pub fn syscall6(...@@ -463,7 +463,7 @@ pub fn syscall6(
463}463}
464464
465/// This matches the libc clone function.465/// This matches the libc clone function.
466pub extern fn clone(func: extern fn(arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: &i32, tls: usize, ctid: &i32) usize;466pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: &i32, tls: usize, ctid: &i32) usize;
467467
468pub nakedcc fn restore_rt() void {468pub nakedcc fn restore_rt() void {
469 return asm volatile ("syscall"469 return asm volatile ("syscall"
std/os/path.zig+3-3
...@@ -793,7 +793,7 @@ pub fn basenamePosix(path: []const u8) []const u8 {...@@ -793,7 +793,7 @@ pub fn basenamePosix(path: []const u8) []const u8 {
793 start_index -= 1;793 start_index -= 1;
794 }794 }
795795
796 return path[start_index + 1..end_index];796 return path[start_index + 1 .. end_index];
797}797}
798798
799pub fn basenameWindows(path: []const u8) []const u8 {799pub fn basenameWindows(path: []const u8) []const u8 {
...@@ -825,7 +825,7 @@ pub fn basenameWindows(path: []const u8) []const u8 {...@@ -825,7 +825,7 @@ pub fn basenameWindows(path: []const u8) []const u8 {
825 start_index -= 1;825 start_index -= 1;
826 }826 }
827827
828 return path[start_index + 1..end_index];828 return path[start_index + 1 .. end_index];
829}829}
830830
831test "os.path.basename" {831test "os.path.basename" {
...@@ -999,7 +999,7 @@ pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![...@@ -999,7 +999,7 @@ pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![
999 }999 }
1000 if (to_rest.len == 0) {1000 if (to_rest.len == 0) {
1001 // shave off the trailing slash1001 // shave off the trailing slash
1002 return result[0..result_index - 1];1002 return result[0 .. result_index - 1];
1003 }1003 }
10041004
1005 mem.copy(u8, result[result_index..], to_rest);1005 mem.copy(u8, result[result_index..], to_rest);
std/os/windows/index.zig+1-1
...@@ -369,7 +369,7 @@ pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;...@@ -369,7 +369,7 @@ pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
369pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;369pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;
370pub const HEAP_NO_SERIALIZE = 0x00000001;370pub const HEAP_NO_SERIALIZE = 0x00000001;
371371
372pub const PTHREAD_START_ROUTINE = extern fn(LPVOID) DWORD;372pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
373pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;373pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
374374
375test "import" {375test "import" {
std/os/windows/util.zig+1-1
...@@ -73,7 +73,7 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {...@@ -73,7 +73,7 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
73 }73 }
7474
75 const name_info = @ptrCast(&const windows.FILE_NAME_INFO, &name_info_bytes[0]);75 const name_info = @ptrCast(&const windows.FILE_NAME_INFO, &name_info_bytes[0]);
76 const name_bytes = name_info_bytes[size..size + usize(name_info.FileNameLength)];76 const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
77 const name_wide = ([]u16)(name_bytes);77 const name_wide = ([]u16)(name_bytes);
78 return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or78 return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or
79 mem.indexOf(u16, name_wide, []u16{ '-', 'p', 't', 'y' }) != null;79 mem.indexOf(u16, name_wide, []u16{ '-', 'p', 't', 'y' }) != null;
std/os/zen.zig+1-1
...@@ -153,7 +153,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {...@@ -153,7 +153,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
153 return syscall4(Syscall.map, v_addr, p_addr, size, usize(writable)) != 0;153 return syscall4(Syscall.map, v_addr, p_addr, size, usize(writable)) != 0;
154}154}
155155
156pub fn createThread(function: fn() void) u16 {156pub fn createThread(function: fn () void) u16 {
157 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));157 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
158}158}
159159
std/rand/index.zig+1-1
...@@ -28,7 +28,7 @@ pub const DefaultPrng = Xoroshiro128;...@@ -28,7 +28,7 @@ pub const DefaultPrng = Xoroshiro128;
28pub const DefaultCsprng = Isaac64;28pub const DefaultCsprng = Isaac64;
2929
30pub const Random = struct {30pub const Random = struct {
31 fillFn: fn(r: &Random, buf: []u8) void,31 fillFn: fn (r: &Random, buf: []u8) void,
3232
33 /// Read random bytes into the specified buffer until fill.33 /// Read random bytes into the specified buffer until fill.
34 pub fn bytes(r: &Random, buf: []u8) void {34 pub fn bytes(r: &Random, buf: []u8) void {
std/rand/ziggurat.zig+5-5
...@@ -56,11 +56,11 @@ pub const ZigTable = struct {...@@ -56,11 +56,11 @@ pub const ZigTable = struct {
56 f: [257]f64,56 f: [257]f64,
5757
58 // probability density function used as a fallback58 // probability density function used as a fallback
59 pdf: fn(f64) f64,59 pdf: fn (f64) f64,
60 // whether the distribution is symmetric60 // whether the distribution is symmetric
61 is_symmetric: bool,61 is_symmetric: bool,
62 // fallback calculation in the case we are in the 0 block62 // fallback calculation in the case we are in the 0 block
63 zero_case: fn(&Random, f64) f64,63 zero_case: fn (&Random, f64) f64,
64};64};
6565
66// zigNorInit66// zigNorInit
...@@ -68,9 +68,9 @@ fn ZigTableGen(...@@ -68,9 +68,9 @@ fn ZigTableGen(
68 comptime is_symmetric: bool,68 comptime is_symmetric: bool,
69 comptime r: f64,69 comptime r: f64,
70 comptime v: f64,70 comptime v: f64,
71 comptime f: fn(f64) f64,71 comptime f: fn (f64) f64,
72 comptime f_inv: fn(f64) f64,72 comptime f_inv: fn (f64) f64,
73 comptime zero_case: fn(&Random, f64) f64,73 comptime zero_case: fn (&Random, f64) f64,
74) ZigTable {74) ZigTable {
75 var tables: ZigTable = undefined;75 var tables: ZigTable = undefined;
7676
std/sort.zig+21-21
...@@ -5,7 +5,7 @@ const math = std.math;...@@ -5,7 +5,7 @@ const math = std.math;
5const builtin = @import("builtin");5const builtin = @import("builtin");
66
7/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).7/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).
8pub fn insertionSort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) void {8pub fn insertionSort(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &const T) bool) void {
9 {9 {
10 var i: usize = 1;10 var i: usize = 1;
11 while (i < items.len) : (i += 1) {11 while (i < items.len) : (i += 1) {
...@@ -108,7 +108,7 @@ const Pull = struct {...@@ -108,7 +108,7 @@ const Pull = struct {
108108
109/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required).109/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required).
110/// Currently implemented as block sort.110/// Currently implemented as block sort.
111pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) void {111pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &const T) bool) void {
112 // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c112 // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c
113 var cache: [512]T = undefined;113 var cache: [512]T = undefined;
114114
...@@ -257,7 +257,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -257,7 +257,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
257 // merge A2 and B2 into the cache257 // merge A2 and B2 into the cache
258 if (lessThan(items[B2.end - 1], items[A2.start])) {258 if (lessThan(items[B2.end - 1], items[A2.start])) {
259 // the two ranges are in reverse order, so copy them in reverse order into the cache259 // the two ranges are in reverse order, so copy them in reverse order into the cache
260 mem.copy(T, cache[A1.length() + B2.length()..], items[A2.start..A2.end]);260 mem.copy(T, cache[A1.length() + B2.length() ..], items[A2.start..A2.end]);
261 mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);261 mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);
262 } else if (lessThan(items[B2.start], items[A2.end - 1])) {262 } else if (lessThan(items[B2.start], items[A2.end - 1])) {
263 // these two ranges weren't already in order, so merge them into the cache263 // these two ranges weren't already in order, so merge them into the cache
...@@ -265,7 +265,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -265,7 +265,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
265 } else {265 } else {
266 // copy A2 and B2 into the cache in the same order266 // copy A2 and B2 into the cache in the same order
267 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);267 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);
268 mem.copy(T, cache[A1.length() + A2.length()..], items[B2.start..B2.end]);268 mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.end]);
269 }269 }
270 A2 = Range.init(A2.start, B2.end);270 A2 = Range.init(A2.start, B2.end);
271271
...@@ -275,7 +275,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -275,7 +275,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
275275
276 if (lessThan(cache[B3.end - 1], cache[A3.start])) {276 if (lessThan(cache[B3.end - 1], cache[A3.start])) {
277 // the two ranges are in reverse order, so copy them in reverse order into the items277 // the two ranges are in reverse order, so copy them in reverse order into the items
278 mem.copy(T, items[A1.start + A2.length()..], cache[A3.start..A3.end]);278 mem.copy(T, items[A1.start + A2.length() ..], cache[A3.start..A3.end]);
279 mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);279 mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);
280 } else if (lessThan(cache[B3.start], cache[A3.end - 1])) {280 } else if (lessThan(cache[B3.start], cache[A3.end - 1])) {
281 // these two ranges weren't already in order, so merge them back into the items281 // these two ranges weren't already in order, so merge them back into the items
...@@ -283,7 +283,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -283,7 +283,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
283 } else {283 } else {
284 // copy A3 and B3 into the items in the same order284 // copy A3 and B3 into the items in the same order
285 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);285 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);
286 mem.copy(T, items[A1.start + A1.length()..], cache[B3.start..B3.end]);286 mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.end]);
287 }287 }
288 }288 }
289289
...@@ -640,7 +640,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -640,7 +640,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
640 if (buffer2.length() > 0 or block_size <= cache.len) {640 if (buffer2.length() > 0 or block_size <= cache.len) {
641 // copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway641 // copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway
642 if (block_size <= cache.len) {642 if (block_size <= cache.len) {
643 mem.copy(T, cache[0..], items[blockA.start..blockA.start + block_size]);643 mem.copy(T, cache[0..], items[blockA.start .. blockA.start + block_size]);
644 } else {644 } else {
645 blockSwap(T, items, blockA.start, buffer2.start, block_size);645 blockSwap(T, items, blockA.start, buffer2.start, block_size);
646 }646 }
...@@ -651,7 +651,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -651,7 +651,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
651 blockSwap(T, items, B_split, blockA.start + block_size - B_remaining, B_remaining);651 blockSwap(T, items, B_split, blockA.start + block_size - B_remaining, B_remaining);
652 } else {652 } else {
653 // we are unable to use the 'buffer2' trick to speed up the rotation operation since buffer2 doesn't exist, so perform a normal rotation653 // we are unable to use the 'buffer2' trick to speed up the rotation operation since buffer2 doesn't exist, so perform a normal rotation
654 mem.rotate(T, items[B_split..blockA.start + block_size], blockA.start - B_split);654 mem.rotate(T, items[B_split .. blockA.start + block_size], blockA.start - B_split);
655 }655 }
656656
657 // update the range for the remaining A blocks, and the range remaining from the B block after it was split657 // update the range for the remaining A blocks, and the range remaining from the B block after it was split
...@@ -741,7 +741,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -741,7 +741,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
741}741}
742742
743// merge operation without a buffer743// merge operation without a buffer
744fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn(&const T, &const T) bool) void {744fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn (&const T, &const T) bool) void {
745 if (A_arg.length() == 0 or B_arg.length() == 0) return;745 if (A_arg.length() == 0 or B_arg.length() == 0) return;
746746
747 // this just repeatedly binary searches into B and rotates A into position.747 // this just repeatedly binary searches into B and rotates A into position.
...@@ -783,7 +783,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const...@@ -783,7 +783,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const
783}783}
784784
785// merge operation using an internal buffer785// merge operation using an internal buffer
786fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T, &const T) bool, buffer: &const Range) void {786fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn (&const T, &const T) bool, buffer: &const Range) void {
787 // whenever we find a value to add to the final array, swap it with the value that's already in that spot787 // whenever we find a value to add to the final array, swap it with the value that's already in that spot
788 // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order788 // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order
789 var A_count: usize = 0;789 var A_count: usize = 0;
...@@ -819,7 +819,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s...@@ -819,7 +819,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s
819819
820// combine a linear search with a binary search to reduce the number of comparisons in situations820// combine a linear search with a binary search to reduce the number of comparisons in situations
821// where have some idea as to how many unique values there are and where the next value might be821// where have some idea as to how many unique values there are and where the next value might be
822fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {822fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn (&const T, &const T) bool, unique: usize) usize {
823 if (range.length() == 0) return range.start;823 if (range.length() == 0) return range.start;
824 const skip = math.max(range.length() / unique, usize(1));824 const skip = math.max(range.length() / unique, usize(1));
825825
...@@ -833,7 +833,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const...@@ -833,7 +833,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const
833 return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan);833 return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan);
834}834}
835835
836fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {836fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn (&const T, &const T) bool, unique: usize) usize {
837 if (range.length() == 0) return range.start;837 if (range.length() == 0) return range.start;
838 const skip = math.max(range.length() / unique, usize(1));838 const skip = math.max(range.length() / unique, usize(1));
839839
...@@ -847,7 +847,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons...@@ -847,7 +847,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons
847 return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan);847 return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan);
848}848}
849849
850fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {850fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn (&const T, &const T) bool, unique: usize) usize {
851 if (range.length() == 0) return range.start;851 if (range.length() == 0) return range.start;
852 const skip = math.max(range.length() / unique, usize(1));852 const skip = math.max(range.length() / unique, usize(1));
853853
...@@ -861,7 +861,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const...@@ -861,7 +861,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const
861 return binaryLast(T, items, value, Range.init(index - skip, index), lessThan);861 return binaryLast(T, items, value, Range.init(index - skip, index), lessThan);
862}862}
863863
864fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {864fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn (&const T, &const T) bool, unique: usize) usize {
865 if (range.length() == 0) return range.start;865 if (range.length() == 0) return range.start;
866 const skip = math.max(range.length() / unique, usize(1));866 const skip = math.max(range.length() / unique, usize(1));
867867
...@@ -875,7 +875,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const...@@ -875,7 +875,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const
875 return binaryLast(T, items, value, Range.init(index, index + skip), lessThan);875 return binaryLast(T, items, value, Range.init(index, index + skip), lessThan);
876}876}
877877
878fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool) usize {878fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn (&const T, &const T) bool) usize {
879 var start = range.start;879 var start = range.start;
880 var end = range.end - 1;880 var end = range.end - 1;
881 if (range.start >= range.end) return range.end;881 if (range.start >= range.end) return range.end;
...@@ -893,7 +893,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang...@@ -893,7 +893,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang
893 return start;893 return start;
894}894}
895895
896fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool) usize {896fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn (&const T, &const T) bool) usize {
897 var start = range.start;897 var start = range.start;
898 var end = range.end - 1;898 var end = range.end - 1;
899 if (range.start >= range.end) return range.end;899 if (range.start >= range.end) return range.end;
...@@ -911,7 +911,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range...@@ -911,7 +911,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range
911 return start;911 return start;
912}912}
913913
914fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn(&const T, &const T) bool, into: []T) void {914fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn (&const T, &const T) bool, into: []T) void {
915 var A_index: usize = A.start;915 var A_index: usize = A.start;
916 var B_index: usize = B.start;916 var B_index: usize = B.start;
917 const A_last = A.end;917 const A_last = A.end;
...@@ -941,7 +941,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less...@@ -941,7 +941,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less
941 }941 }
942}942}
943943
944fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T, &const T) bool, cache: []T) void {944fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn (&const T, &const T) bool, cache: []T) void {
945 // A fits into the cache, so use that instead of the internal buffer945 // A fits into the cache, so use that instead of the internal buffer
946 var A_index: usize = 0;946 var A_index: usize = 0;
947 var B_index: usize = B.start;947 var B_index: usize = B.start;
...@@ -969,7 +969,7 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range,...@@ -969,7 +969,7 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range,
969 mem.copy(T, items[insert_index..], cache[A_index..A_last]);969 mem.copy(T, items[insert_index..], cache[A_index..A_last]);
970}970}
971971
972fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool, order: &[8]u8, x: usize, y: usize) void {972fn swap(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &const T) bool, order: &[8]u8, x: usize, y: usize) void {
973 if (lessThan(items[y], items[x]) or ((order.*)[x] > (order.*)[y] and !lessThan(items[x], items[y]))) {973 if (lessThan(items[y], items[x]) or ((order.*)[x] > (order.*)[y] and !lessThan(items[x], items[y]))) {
974 mem.swap(T, &items[x], &items[y]);974 mem.swap(T, &items[x], &items[y]);
975 mem.swap(u8, &(order.*)[x], &(order.*)[y]);975 mem.swap(u8, &(order.*)[x], &(order.*)[y]);
...@@ -1345,7 +1345,7 @@ fn fuzzTest(rng: &std.rand.Random) void {...@@ -1345,7 +1345,7 @@ fn fuzzTest(rng: &std.rand.Random) void {
1345 }1345 }
1346}1346}
13471347
1348pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) T {1348pub fn min(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &const T) bool) T {
1349 var i: usize = 0;1349 var i: usize = 0;
1350 var smallest = items[0];1350 var smallest = items[0];
1351 for (items[1..]) |item| {1351 for (items[1..]) |item| {
...@@ -1356,7 +1356,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const...@@ -1356,7 +1356,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const
1356 return smallest;1356 return smallest;
1357}1357}
13581358
1359pub fn max(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) T {1359pub fn max(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &const T) bool) T {
1360 var i: usize = 0;1360 var i: usize = 0;
1361 var biggest = items[0];1361 var biggest = items[0];
1362 for (items[1..]) |item| {1362 for (items[1..]) |item| {
std/special/build_runner.zig+1-1
...@@ -71,7 +71,7 @@ pub fn main() !void {...@@ -71,7 +71,7 @@ pub fn main() !void {
71 }71 }
72 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {72 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
73 const option_name = option_contents[0..name_end];73 const option_name = option_contents[0..name_end];
74 const option_value = option_contents[name_end + 1..];74 const option_value = option_contents[name_end + 1 ..];
75 if (builder.addUserInputOption(option_name, option_value))75 if (builder.addUserInputOption(option_name, option_value))
76 return usageAndErr(&builder, false, try stderr_stream);76 return usageAndErr(&builder, false, try stderr_stream);
77 } else {77 } else {
std/unicode.zig+2-2
...@@ -151,7 +151,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {...@@ -151,7 +151,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
151 return false;151 return false;
152 }152 }
153153
154 if (utf8Decode(s[i..i + cp_len])) |_| {} else |_| {154 if (utf8Decode(s[i .. i + cp_len])) |_| {} else |_| {
155 return false;155 return false;
156 }156 }
157 i += cp_len;157 i += cp_len;
...@@ -216,7 +216,7 @@ const Utf8Iterator = struct {...@@ -216,7 +216,7 @@ const Utf8Iterator = struct {
216 const cp_len = utf8ByteSequenceLength(it.bytes[it.i]) catch unreachable;216 const cp_len = utf8ByteSequenceLength(it.bytes[it.i]) catch unreachable;
217217
218 it.i += cp_len;218 it.i += cp_len;
219 return it.bytes[it.i - cp_len..it.i];219 return it.bytes[it.i - cp_len .. it.i];
220 }220 }
221221
222 pub fn nextCodepoint(it: &Utf8Iterator) ?u32 {222 pub fn nextCodepoint(it: &Utf8Iterator) ?u32 {
std/zig/tokenizer.zig+1-1
...@@ -1116,7 +1116,7 @@ pub const Tokenizer = struct {...@@ -1116,7 +1116,7 @@ pub const Tokenizer = struct {
1116 if (self.index + length > self.buffer.len) {1116 if (self.index + length > self.buffer.len) {
1117 return u3(self.buffer.len - self.index);1117 return u3(self.buffer.len - self.index);
1118 }1118 }
1119 const bytes = self.buffer[self.index..self.index + length];1119 const bytes = self.buffer[self.index .. self.index + length];
1120 switch (length) {1120 switch (length) {
1121 2 => {1121 2 => {
1122 const value = std.unicode.utf8Decode2(bytes) catch return length;1122 const value = std.unicode.utf8Decode2(bytes) catch return length;
test/cases/align.zig+5-5
...@@ -18,8 +18,8 @@ fn noop4() align(4) void {}...@@ -18,8 +18,8 @@ fn noop4() align(4) void {}
1818
19test "function alignment" {19test "function alignment" {
20 assert(derp() == 1234);20 assert(derp() == 1234);
21 assert(@typeOf(noop1) == fn() align(1) void);21 assert(@typeOf(noop1) == fn () align(1) void);
22 assert(@typeOf(noop4) == fn() align(4) void);22 assert(@typeOf(noop4) == fn () align(4) void);
23 noop1();23 noop1();
24 noop4();24 noop4();
25}25}
...@@ -127,7 +127,7 @@ test "implicitly decreasing fn alignment" {...@@ -127,7 +127,7 @@ test "implicitly decreasing fn alignment" {
127 testImplicitlyDecreaseFnAlign(alignedBig, 5678);127 testImplicitlyDecreaseFnAlign(alignedBig, 5678);
128}128}
129129
130fn testImplicitlyDecreaseFnAlign(ptr: fn() align(1) i32, answer: i32) void {130fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
131 assert(ptr() == answer);131 assert(ptr() == answer);
132}132}
133133
...@@ -141,10 +141,10 @@ fn alignedBig() align(16) i32 {...@@ -141,10 +141,10 @@ fn alignedBig() align(16) i32 {
141test "@alignCast functions" {141test "@alignCast functions" {
142 assert(fnExpectsOnly1(simple4) == 0x19);142 assert(fnExpectsOnly1(simple4) == 0x19);
143}143}
144fn fnExpectsOnly1(ptr: fn() align(1) i32) i32 {144fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
145 return fnExpects4(@alignCast(4, ptr));145 return fnExpects4(@alignCast(4, ptr));
146}146}
147fn fnExpects4(ptr: fn() align(4) i32) i32 {147fn fnExpects4(ptr: fn () align(4) i32) i32 {
148 return ptr();148 return ptr();
149}149}
150fn simple4() align(4) i32 {150fn simple4() align(4) i32 {
test/cases/bugs/920.zig+3-3
...@@ -7,12 +7,12 @@ const ZigTable = struct {...@@ -7,12 +7,12 @@ const ZigTable = struct {
7 x: [257]f64,7 x: [257]f64,
8 f: [257]f64,8 f: [257]f64,
99
10 pdf: fn(f64) f64,10 pdf: fn (f64) f64,
11 is_symmetric: bool,11 is_symmetric: bool,
12 zero_case: fn(&Random, f64) f64,12 zero_case: fn (&Random, f64) f64,
13};13};
1414
15fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn(f64) f64, comptime f_inv: fn(f64) f64, comptime zero_case: fn(&Random, f64) f64) ZigTable {15fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn (f64) f64, comptime f_inv: fn (f64) f64, comptime zero_case: fn (&Random, f64) f64) ZigTable {
16 var tables: ZigTable = undefined;16 var tables: ZigTable = undefined;
1717
18 tables.is_symmetric = is_symmetric;18 tables.is_symmetric = is_symmetric;
test/cases/coroutines.zig+1-1
...@@ -154,7 +154,7 @@ test "async function with dot syntax" {...@@ -154,7 +154,7 @@ test "async function with dot syntax" {
154test "async fn pointer in a struct field" {154test "async fn pointer in a struct field" {
155 var data: i32 = 1;155 var data: i32 = 1;
156 const Foo = struct {156 const Foo = struct {
157 bar: async<&std.mem.Allocator> fn(&i32) void,157 bar: async<&std.mem.Allocator> fn (&i32) void,
158 };158 };
159 var foo = Foo{ .bar = simpleAsyncFn2 };159 var foo = Foo{ .bar = simpleAsyncFn2 };
160 const p = (async<std.debug.global_allocator> foo.bar(&data)) catch unreachable;160 const p = (async<std.debug.global_allocator> foo.bar(&data)) catch unreachable;
test/cases/error.zig+1-1
...@@ -193,7 +193,7 @@ fn entry() void {...@@ -193,7 +193,7 @@ fn entry() void {
193 foo2(bar2);193 foo2(bar2);
194}194}
195195
196fn foo2(f: fn() error!void) void {196fn foo2(f: fn () error!void) void {
197 const x = f();197 const x = f();
198}198}
199199
test/cases/eval.zig+1-1
...@@ -215,7 +215,7 @@ test "inlined block and runtime block phi" {...@@ -215,7 +215,7 @@ test "inlined block and runtime block phi" {
215215
216const CmdFn = struct {216const CmdFn = struct {
217 name: []const u8,217 name: []const u8,
218 func: fn(i32) i32,218 func: fn (i32) i32,
219};219};
220220
221const cmd_fns = []CmdFn{221const cmd_fns = []CmdFn{
test/cases/fn.zig+1-1
...@@ -66,7 +66,7 @@ test "implicit cast function unreachable return" {...@@ -66,7 +66,7 @@ test "implicit cast function unreachable return" {
66 wantsFnWithVoid(fnWithUnreachable);66 wantsFnWithVoid(fnWithUnreachable);
67}67}
6868
69fn wantsFnWithVoid(f: fn() void) void {}69fn wantsFnWithVoid(f: fn () void) void {}
7070
71fn fnWithUnreachable() noreturn {71fn fnWithUnreachable() noreturn {
72 unreachable;72 unreachable;
test/cases/fn_in_struct_in_comptime.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn get_foo() fn(&u8) usize {3fn get_foo() fn (&u8) usize {
4 comptime {4 comptime {
5 return struct {5 return struct {
6 fn func(ptr: &u8) usize {6 fn func(ptr: &u8) usize {
test/cases/generics.zig+1-1
...@@ -133,7 +133,7 @@ fn getFirstByte(comptime T: type, mem: []const T) u8 {...@@ -133,7 +133,7 @@ fn getFirstByte(comptime T: type, mem: []const T) u8 {
133 return getByte(@ptrCast(&const u8, &mem[0]));133 return getByte(@ptrCast(&const u8, &mem[0]));
134}134}
135135
136const foos = []fn(var) bool{136const foos = []fn (var) bool{
137 foo1,137 foo1,
138 foo2,138 foo2,
139};139};
test/cases/misc.zig+1-1
...@@ -511,7 +511,7 @@ test "@typeId" {...@@ -511,7 +511,7 @@ test "@typeId" {
511 assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);511 assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);
512 assert(@typeId(AUnionEnum) == Tid.Union);512 assert(@typeId(AUnionEnum) == Tid.Union);
513 assert(@typeId(AUnion) == Tid.Union);513 assert(@typeId(AUnion) == Tid.Union);
514 assert(@typeId(fn() void) == Tid.Fn);514 assert(@typeId(fn () void) == Tid.Fn);
515 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);515 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);
516 assert(@typeId(@typeOf(x: {516 assert(@typeId(@typeOf(x: {
517 break :x this;517 break :x this;
test/cases/struct.zig+2-2
...@@ -105,7 +105,7 @@ test "fn call of struct field" {...@@ -105,7 +105,7 @@ test "fn call of struct field" {
105}105}
106106
107const Foo = struct {107const Foo = struct {
108 ptr: fn() i32,108 ptr: fn () i32,
109};109};
110110
111fn aFunc() i32 {111fn aFunc() i32 {
...@@ -302,7 +302,7 @@ test "packed array 24bits" {...@@ -302,7 +302,7 @@ test "packed array 24bits" {
302302
303 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);303 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);
304 bytes[bytes.len - 1] = 0xaa;304 bytes[bytes.len - 1] = 0xaa;
305 const ptr = &([]FooArray24Bits)(bytes[0..bytes.len - 1])[0];305 const ptr = &([]FooArray24Bits)(bytes[0 .. bytes.len - 1])[0];
306 assert(ptr.a == 0);306 assert(ptr.a == 0);
307 assert(ptr.b[0].field == 0);307 assert(ptr.b[0].field == 0);
308 assert(ptr.b[1].field == 0);308 assert(ptr.b[1].field == 0);
test/cases/type_info.zig+1-1
...@@ -196,7 +196,7 @@ fn testStruct() void {...@@ -196,7 +196,7 @@ fn testStruct() void {
196 assert(!struct_info.Struct.defs[0].data.Fn.is_extern);196 assert(!struct_info.Struct.defs[0].data.Fn.is_extern);
197 assert(struct_info.Struct.defs[0].data.Fn.lib_name == null);197 assert(struct_info.Struct.defs[0].data.Fn.lib_name == null);
198 assert(struct_info.Struct.defs[0].data.Fn.return_type == void);198 assert(struct_info.Struct.defs[0].data.Fn.return_type == void);
199 assert(struct_info.Struct.defs[0].data.Fn.fn_type == fn(&const TestStruct) void);199 assert(struct_info.Struct.defs[0].data.Fn.fn_type == fn (&const TestStruct) void);
200}200}
201201
202const TestStruct = packed struct {202const TestStruct = packed struct {
test/cases/var_args.zig+1-1
...@@ -58,7 +58,7 @@ fn extraFn(extra: u32, args: ...) usize {...@@ -58,7 +58,7 @@ fn extraFn(extra: u32, args: ...) usize {
58 return args.len;58 return args.len;
59}59}
6060
61const foos = []fn(...) bool{61const foos = []fn (...) bool{
62 foo1,62 foo1,
63 foo2,63 foo2,
64};64};