authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-10 05:27:17+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 09:55:07+00:00
log51595d6b75d8ac2443a2c142c71f2a617c12fe96
tree0e3045793aa36cc8569181cc790d270c4f056806
parentbaabc6013ea4f44082e69375214e76b5d803c5cb
signaturelock-open Commit is signed but in an unrecognized format.

lib: correct unnecessary uses of 'var'


174 files changed, 738 insertions(+), 711 deletions(-)

lib/build_runner.zig+1-1
...@@ -24,7 +24,7 @@ pub fn main() !void {...@@ -24,7 +24,7 @@ pub fn main() !void {
24 };24 };
25 const arena = thread_safe_arena.allocator();25 const arena = thread_safe_arena.allocator();
2626
27 var args = try process.argsAlloc(arena);27 const args = try process.argsAlloc(arena);
2828
29 // skip my own exe name29 // skip my own exe name
30 var arg_idx: usize = 1;30 var arg_idx: usize = 1;
lib/compiler_rt/absvdi2_test.zig+1-1
...@@ -3,7 +3,7 @@ const testing = @import("std").testing;...@@ -3,7 +3,7 @@ const testing = @import("std").testing;
3const __absvdi2 = @import("absvdi2.zig").__absvdi2;3const __absvdi2 = @import("absvdi2.zig").__absvdi2;
44
5fn test__absvdi2(a: i64, expected: i64) !void {5fn test__absvdi2(a: i64, expected: i64) !void {
6 var result = __absvdi2(a);6 const result = __absvdi2(a);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/absvsi2_test.zig+1-1
...@@ -3,7 +3,7 @@ const testing = @import("std").testing;...@@ -3,7 +3,7 @@ const testing = @import("std").testing;
3const __absvsi2 = @import("absvsi2.zig").__absvsi2;3const __absvsi2 = @import("absvsi2.zig").__absvsi2;
44
5fn test__absvsi2(a: i32, expected: i32) !void {5fn test__absvsi2(a: i32, expected: i32) !void {
6 var result = __absvsi2(a);6 const result = __absvsi2(a);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/absvti2_test.zig+1-1
...@@ -3,7 +3,7 @@ const testing = @import("std").testing;...@@ -3,7 +3,7 @@ const testing = @import("std").testing;
3const __absvti2 = @import("absvti2.zig").__absvti2;3const __absvti2 = @import("absvti2.zig").__absvti2;
44
5fn test__absvti2(a: i128, expected: i128) !void {5fn test__absvti2(a: i128, expected: i128) !void {
6 var result = __absvti2(a);6 const result = __absvti2(a);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/addo.zig+1-1
...@@ -18,7 +18,7 @@ comptime {...@@ -18,7 +18,7 @@ comptime {
18inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {18inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
19 @setRuntimeSafety(builtin.is_test);19 @setRuntimeSafety(builtin.is_test);
20 overflow.* = 0;20 overflow.* = 0;
21 var sum: ST = a +% b;21 const sum: ST = a +% b;
22 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract22 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
23 // Let sum = a +% b == a + b + carry == wraparound addition.23 // Let sum = a +% b == a + b + carry == wraparound addition.
24 // Overflow in a+b+carry occurs, iff a and b have opposite signs24 // Overflow in a+b+carry occurs, iff a and b have opposite signs
lib/compiler_rt/addodi4_test.zig+2-2
...@@ -6,8 +6,8 @@ const math = std.math;...@@ -6,8 +6,8 @@ const math = std.math;
6fn test__addodi4(a: i64, b: i64) !void {6fn test__addodi4(a: i64, b: i64) !void {
7 var result_ov: c_int = undefined;7 var result_ov: c_int = undefined;
8 var expected_ov: c_int = undefined;8 var expected_ov: c_int = undefined;
9 var result = addv.__addodi4(a, b, &result_ov);9 const result = addv.__addodi4(a, b, &result_ov);
10 var expected: i64 = simple_addodi4(a, b, &expected_ov);10 const expected: i64 = simple_addodi4(a, b, &expected_ov);
11 try testing.expectEqual(expected, result);11 try testing.expectEqual(expected, result);
12 try testing.expectEqual(expected_ov, result_ov);12 try testing.expectEqual(expected_ov, result_ov);
13}13}
lib/compiler_rt/addosi4_test.zig+2-2
...@@ -4,8 +4,8 @@ const testing = @import("std").testing;...@@ -4,8 +4,8 @@ const testing = @import("std").testing;
4fn test__addosi4(a: i32, b: i32) !void {4fn test__addosi4(a: i32, b: i32) !void {
5 var result_ov: c_int = undefined;5 var result_ov: c_int = undefined;
6 var expected_ov: c_int = undefined;6 var expected_ov: c_int = undefined;
7 var result = addv.__addosi4(a, b, &result_ov);7 const result = addv.__addosi4(a, b, &result_ov);
8 var expected: i32 = simple_addosi4(a, b, &expected_ov);8 const expected: i32 = simple_addosi4(a, b, &expected_ov);
9 try testing.expectEqual(expected, result);9 try testing.expectEqual(expected, result);
10 try testing.expectEqual(expected_ov, result_ov);10 try testing.expectEqual(expected_ov, result_ov);
11}11}
lib/compiler_rt/addoti4_test.zig+2-2
...@@ -6,8 +6,8 @@ const math = std.math;...@@ -6,8 +6,8 @@ const math = std.math;
6fn test__addoti4(a: i128, b: i128) !void {6fn test__addoti4(a: i128, b: i128) !void {
7 var result_ov: c_int = undefined;7 var result_ov: c_int = undefined;
8 var expected_ov: c_int = undefined;8 var expected_ov: c_int = undefined;
9 var result = addv.__addoti4(a, b, &result_ov);9 const result = addv.__addoti4(a, b, &result_ov);
10 var expected: i128 = simple_addoti4(a, b, &expected_ov);10 const expected: i128 = simple_addoti4(a, b, &expected_ov);
11 try testing.expectEqual(expected, result);11 try testing.expectEqual(expected, result);
12 try testing.expectEqual(expected_ov, result_ov);12 try testing.expectEqual(expected_ov, result_ov);
13}13}
lib/compiler_rt/bswapdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");...@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__bswapdi2(a: u64, expected: u64) !void {4fn test__bswapdi2(a: u64, expected: u64) !void {
5 var result = bswap.__bswapdi2(a);5 const result = bswap.__bswapdi2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/bswapsi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");...@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__bswapsi2(a: u32, expected: u32) !void {4fn test__bswapsi2(a: u32, expected: u32) !void {
5 var result = bswap.__bswapsi2(a);5 const result = bswap.__bswapsi2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/bswapti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");...@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__bswapti2(a: u128, expected: u128) !void {4fn test__bswapti2(a: u128, expected: u128) !void {
5 var result = bswap.__bswapti2(a);5 const result = bswap.__bswapti2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/ceil.zig+1-1
...@@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 {...@@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 {
3232
33pub fn ceilf(x: f32) callconv(.C) f32 {33pub fn ceilf(x: f32) callconv(.C) f32 {
34 var u: u32 = @bitCast(x);34 var u: u32 = @bitCast(x);
35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;35 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
36 var m: u32 = undefined;36 var m: u32 = undefined;
3737
38 // TODO: Shouldn't need this explicit check.38 // TODO: Shouldn't need this explicit check.
lib/compiler_rt/clzdi2_test.zig+2-2
...@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__clzdi2(a: u64, expected: i64) !void {4fn test__clzdi2(a: u64, expected: i64) !void {
5 var x: i64 = @bitCast(a);5 const x: i64 = @bitCast(a);
6 var result = clz.__clzdi2(x);6 const result = clz.__clzdi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/clzti2_test.zig+2-2
...@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__clzti2(a: u128, expected: i64) !void {4fn test__clzti2(a: u128, expected: i64) !void {
5 var x: i128 = @bitCast(a);5 const x: i128 = @bitCast(a);
6 var result = clz.__clzti2(x);6 const result = clz.__clzti2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/cmpdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__cmpdi2(a: i64, b: i64, expected: i64) !void {4fn test__cmpdi2(a: i64, b: i64, expected: i64) !void {
5 var result = cmp.__cmpdi2(a, b);5 const result = cmp.__cmpdi2(a, b);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/cmpsi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__cmpsi2(a: i32, b: i32, expected: i32) !void {4fn test__cmpsi2(a: i32, b: i32, expected: i32) !void {
5 var result = cmp.__cmpsi2(a, b);5 const result = cmp.__cmpsi2(a, b);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/cmpti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__cmpti2(a: i128, b: i128, expected: i128) !void {4fn test__cmpti2(a: i128, b: i128, expected: i128) !void {
5 var result = cmp.__cmpti2(a, b);5 const result = cmp.__cmpti2(a, b);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/ctzdi2_test.zig+2-2
...@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzdi2(a: u64, expected: i32) !void {4fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x: i64 = @bitCast(a);5 const x: i64 = @bitCast(a);
6 var result = ctz.__ctzdi2(x);6 const result = ctz.__ctzdi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/ctzsi2_test.zig+2-2
...@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzsi2(a: u32, expected: i32) !void {4fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x: i32 = @bitCast(a);5 const x: i32 = @bitCast(a);
6 var result = ctz.__ctzsi2(x);6 const result = ctz.__ctzsi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/ctzti2_test.zig+2-2
...@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ctzti2(a: u128, expected: i32) !void {4fn test__ctzti2(a: u128, expected: i32) !void {
5 var x: i128 = @bitCast(a);5 const x: i128 = @bitCast(a);
6 var result = ctz.__ctzti2(x);6 const result = ctz.__ctzti2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/divc3_test.zig+20-20
...@@ -19,20 +19,20 @@ test {...@@ -19,20 +19,20 @@ test {
1919
20fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {20fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
21 {21 {
22 var a: T = 1.0;22 const a: T = 1.0;
23 var b: T = 0.0;23 const b: T = 0.0;
24 var c: T = -1.0;24 const c: T = -1.0;
25 var d: T = 0.0;25 const d: T = 0.0;
2626
27 const result = f(a, b, c, d);27 const result = f(a, b, c, d);
28 try expect(result.real == -1.0);28 try expect(result.real == -1.0);
29 try expect(result.imag == 0.0);29 try expect(result.imag == 0.0);
30 }30 }
31 {31 {
32 var a: T = 1.0;32 const a: T = 1.0;
33 var b: T = 0.0;33 const b: T = 0.0;
34 var c: T = -4.0;34 const c: T = -4.0;
35 var d: T = 0.0;35 const d: T = 0.0;
3636
37 const result = f(a, b, c, d);37 const result = f(a, b, c, d);
38 try expect(result.real == -0.25);38 try expect(result.real == -0.25);
...@@ -41,10 +41,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)...@@ -41,10 +41,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
41 {41 {
42 // if the first operand is an infinity and the second operand is a finite number, then the42 // if the first operand is an infinity and the second operand is a finite number, then the
43 // result of the / operator is an infinity;43 // result of the / operator is an infinity;
44 var a: T = -math.inf(T);44 const a: T = -math.inf(T);
45 var b: T = 0.0;45 const b: T = 0.0;
46 var c: T = -4.0;46 const c: T = -4.0;
47 var d: T = 1.0;47 const d: T = 1.0;
4848
49 const result = f(a, b, c, d);49 const result = f(a, b, c, d);
50 try expect(result.real == math.inf(T));50 try expect(result.real == math.inf(T));
...@@ -53,10 +53,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)...@@ -53,10 +53,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
53 {53 {
54 // if the first operand is a finite number and the second operand is an infinity, then the54 // if the first operand is a finite number and the second operand is an infinity, then the
55 // result of the / operator is a zero;55 // result of the / operator is a zero;
56 var a: T = 17.2;56 const a: T = 17.2;
57 var b: T = 0.0;57 const b: T = 0.0;
58 var c: T = -math.inf(T);58 const c: T = -math.inf(T);
59 var d: T = 0.0;59 const d: T = 0.0;
6060
61 const result = f(a, b, c, d);61 const result = f(a, b, c, d);
62 try expect(result.real == -0.0);62 try expect(result.real == -0.0);
...@@ -65,10 +65,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)...@@ -65,10 +65,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
65 {65 {
66 // if the first operand is a nonzero finite number or an infinity and the second operand is66 // if the first operand is a nonzero finite number or an infinity and the second operand is
67 // a zero, then the result of the / operator is an infinity67 // a zero, then the result of the / operator is an infinity
68 var a: T = 1.1;68 const a: T = 1.1;
69 var b: T = 0.1;69 const b: T = 0.1;
70 var c: T = 0.0;70 const c: T = 0.0;
71 var d: T = 0.0;71 const d: T = 0.0;
7272
73 const result = f(a, b, c, d);73 const result = f(a, b, c, d);
74 try expect(result.real == math.inf(T));74 try expect(result.real == math.inf(T));
lib/compiler_rt/divxf3.zig+2-2
...@@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
162 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).162 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
163 // Right shift the quotient if it falls in the [1,2) range and adjust the163 // Right shift the quotient if it falls in the [1,2) range and adjust the
164 // exponent accordingly.164 // exponent accordingly.
165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {165 const quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
166 quotientExponent -= 1;166 quotientExponent -= 1;
167 break :b @intCast(quotient128);167 break :b @intCast(quotient128);
168 } else @intCast(quotient128 >> 1);168 } else @intCast(quotient128 >> 1);
...@@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {...@@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
177 //177 //
178 // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we178 // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
179 // already have the correct result. The exact halfway case cannot occur.179 // already have the correct result. The exact halfway case cannot occur.
180 var residual: u64 = -%(quotient *% q63b);180 const residual: u64 = -%(quotient *% q63b);
181181
182 const writtenExponent = quotientExponent + exponentBias;182 const writtenExponent = quotientExponent + exponentBias;
183 if (writtenExponent >= maxExponent) {183 if (writtenExponent >= maxExponent) {
lib/compiler_rt/emutls.zig+11-11
...@@ -57,8 +57,8 @@ const simple_allocator = struct {...@@ -57,8 +57,8 @@ const simple_allocator = struct {
5757
58 /// Resize a slice.58 /// Resize a slice.
59 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {59 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {
60 var c_ptr: *anyopaque = @ptrCast(slice.ptr);60 const c_ptr: *anyopaque = @ptrCast(slice.ptr);
61 var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));61 const new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
62 return new_array[0..len];62 return new_array[0..len];
63 }63 }
6464
...@@ -78,7 +78,7 @@ const ObjectArray = struct {...@@ -78,7 +78,7 @@ const ObjectArray = struct {
7878
79 /// create a new ObjectArray with n slots. must call deinit() to deallocate.79 /// create a new ObjectArray with n slots. must call deinit() to deallocate.
80 pub fn init(n: usize) *ObjectArray {80 pub fn init(n: usize) *ObjectArray {
81 var array = simple_allocator.alloc(ObjectArray);81 const array = simple_allocator.alloc(ObjectArray);
8282
83 array.* = ObjectArray{83 array.* = ObjectArray{
84 .slots = simple_allocator.allocSlice(?ObjectPointer, n),84 .slots = simple_allocator.allocSlice(?ObjectPointer, n),
...@@ -166,7 +166,7 @@ const current_thread_storage = struct {...@@ -166,7 +166,7 @@ const current_thread_storage = struct {
166 const size = @max(16, index);166 const size = @max(16, index);
167167
168 // create a new array and store it.168 // create a new array and store it.
169 var array: *ObjectArray = ObjectArray.init(size);169 const array: *ObjectArray = ObjectArray.init(size);
170 current_thread_storage.setspecific(array);170 current_thread_storage.setspecific(array);
171 return array;171 return array;
172 }172 }
...@@ -304,13 +304,13 @@ const emutls_control = extern struct {...@@ -304,13 +304,13 @@ const emutls_control = extern struct {
304test "simple_allocator" {304test "simple_allocator" {
305 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;305 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
306306
307 var data1: *[64]u8 = simple_allocator.alloc([64]u8);307 const data1: *[64]u8 = simple_allocator.alloc([64]u8);
308 defer simple_allocator.free(data1);308 defer simple_allocator.free(data1);
309 for (data1) |*c| {309 for (data1) |*c| {
310 c.* = 0xff;310 c.* = 0xff;
311 }311 }
312312
313 var data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64);313 const data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64);
314 defer simple_allocator.free(data2);314 defer simple_allocator.free(data2);
315 for (data2[0..63]) |*c| {315 for (data2[0..63]) |*c| {
316 c.* = 0xff;316 c.* = 0xff;
...@@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" {...@@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" {
324 try expect(ctl.object.index == 0);324 try expect(ctl.object.index == 0);
325325
326 // retrieve a variable from ctl326 // retrieve a variable from ctl
327 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));327 const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
328 try expect(ctl.object.index != 0); // index has been allocated for this ctl328 try expect(ctl.object.index != 0); // index has been allocated for this ctl
329 try expect(x.* == 0); // storage has been zeroed329 try expect(x.* == 0); // storage has been zeroed
330330
...@@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" {...@@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" {
332 x.* = 1234;332 x.* = 1234;
333333
334 // retrieve a variable from ctl (same ctl)334 // retrieve a variable from ctl (same ctl)
335 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));335 const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
336336
337 try expect(y.* == 1234); // same content that x.*337 try expect(y.* == 1234); // same content that x.*
338 try expect(x == y); // same pointer338 try expect(x == y); // same pointer
...@@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" {...@@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" {
345 var ctl = emutls_control.init(usize, &value);345 var ctl = emutls_control.init(usize, &value);
346 try expect(ctl.object.index == 0);346 try expect(ctl.object.index == 0);
347347
348 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));348 const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
349 try expect(ctl.object.index != 0);349 try expect(ctl.object.index != 0);
350 try expect(x.* == 5678); // storage initialized with default value350 try expect(x.* == 5678); // storage initialized with default value
351351
...@@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" {...@@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" {
354354
355 try expect(value == 5678); // the default value didn't change355 try expect(value == 5678); // the default value didn't change
356356
357 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));357 const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
358 try expect(y.* == 9012); // the modified storage persists358 try expect(y.* == 9012); // the modified storage persists
359}359}
360360
...@@ -364,7 +364,7 @@ test "test default_value with differents sizes" {...@@ -364,7 +364,7 @@ test "test default_value with differents sizes" {
364 const testType = struct {364 const testType = struct {
365 fn _testType(comptime T: type, value: T) !void {365 fn _testType(comptime T: type, value: T) !void {
366 var ctl = emutls_control.init(T, &value);366 var ctl = emutls_control.init(T, &value);
367 var x = ctl.get_typed_pointer(T);367 const x = ctl.get_typed_pointer(T);
368 try expect(x.* == value);368 try expect(x.* == value);
369 }369 }
370 }._testType;370 }._testType;
lib/compiler_rt/exp.zig+1-1
...@@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {...@@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117 const P5: f64 = 4.13813679705723846039e-08;117 const P5: f64 = 4.13813679705723846039e-08;
118118
119 var x = x_;119 var x = x_;
120 var ux: u64 = @bitCast(x);120 const ux: u64 = @bitCast(x);
121 var hx = ux >> 32;121 var hx = ux >> 32;
122 const sign: i32 = @intCast(hx >> 31);122 const sign: i32 = @intCast(hx >> 31);
123 hx &= 0x7FFFFFFF;123 hx &= 0x7FFFFFFF;
lib/compiler_rt/exp2.zig+1-1
...@@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {...@@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
38 const P3: f32 = 0x1.c6b348p-5;38 const P3: f32 = 0x1.c6b348p-5;
39 const P4: f32 = 0x1.3b2c9cp-7;39 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u: u32 = @bitCast(x);41 const u: u32 = @bitCast(x);
42 const ix = u & 0x7FFFFFFF;42 const ix = u & 0x7FFFFFFF;
4343
44 // |x| > 12644 // |x| > 126
lib/compiler_rt/ffsdi2_test.zig+2-2
...@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ffsdi2(a: u64, expected: i32) !void {4fn test__ffsdi2(a: u64, expected: i32) !void {
5 var x = @as(i64, @bitCast(a));5 const x = @as(i64, @bitCast(a));
6 var result = ffs.__ffsdi2(x);6 const result = ffs.__ffsdi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/ffssi2_test.zig+2-2
...@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ffssi2(a: u32, expected: i32) !void {4fn test__ffssi2(a: u32, expected: i32) !void {
5 var x = @as(i32, @bitCast(a));5 const x = @as(i32, @bitCast(a));
6 var result = ffs.__ffssi2(x);6 const result = ffs.__ffssi2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/ffsti2_test.zig+2-2
...@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");...@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ffsti2(a: u128, expected: i32) !void {4fn test__ffsti2(a: u128, expected: i32) !void {
5 var x = @as(i128, @bitCast(a));5 const x = @as(i128, @bitCast(a));
6 var result = ffs.__ffsti2(x);6 const result = ffs.__ffsti2(x);
7 try testing.expectEqual(expected, result);7 try testing.expectEqual(expected, result);
8}8}
99
lib/compiler_rt/float_from_int.zig+3-3
...@@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {...@@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
18 const max_exp = exp_bias;18 const max_exp = exp_bias;
1919
20 // Sign20 // Sign
21 var abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x;21 const abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x;
22 const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0;22 const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0;
23 var result: uT = sign_bit;23 var result: uT = sign_bit;
2424
25 // Compute significand25 // Compute significand
26 var exp = int_bits - @clz(abs_val) - 1;26 const exp = int_bits - @clz(abs_val) - 1;
27 if (int_bits <= fractional_bits or exp <= fractional_bits) {27 if (int_bits <= fractional_bits or exp <= fractional_bits) {
28 const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp));28 const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp));
2929
...@@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {...@@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
31 result = @as(uT, @intCast(abs_val)) << shift_amt;31 result = @as(uT, @intCast(abs_val)) << shift_amt;
32 result ^= implicit_bit; // Remove implicit integer bit32 result ^= implicit_bit; // Remove implicit integer bit
33 } else {33 } else {
34 var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);34 const shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);
35 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;35 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
37 // Shift down result and remove implicit integer bit37 // Shift down result and remove implicit integer bit
lib/compiler_rt/fma.zig+16-16
...@@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {...@@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {
59 }59 }
6060
61 const x1 = math.frexp(x);61 const x1 = math.frexp(x);
62 var ex = x1.exponent;62 const ex = x1.exponent;
63 var xs = x1.significand;63 const xs = x1.significand;
64 const x2 = math.frexp(y);64 const x2 = math.frexp(y);
65 var ey = x2.exponent;65 const ey = x2.exponent;
66 var ys = x2.significand;66 const ys = x2.significand;
67 const x3 = math.frexp(z);67 const x3 = math.frexp(z);
68 var ez = x3.exponent;68 const ez = x3.exponent;
69 var zs = x3.significand;69 var zs = x3.significand;
7070
71 var spread = ex + ey - ez;71 var spread = ex + ey - ez;
...@@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {...@@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {
118 }118 }
119119
120 const x1 = math.frexp(x);120 const x1 = math.frexp(x);
121 var ex = x1.exponent;121 const ex = x1.exponent;
122 var xs = x1.significand;122 const xs = x1.significand;
123 const x2 = math.frexp(y);123 const x2 = math.frexp(y);
124 var ey = x2.exponent;124 const ey = x2.exponent;
125 var ys = x2.significand;125 const ys = x2.significand;
126 const x3 = math.frexp(z);126 const x3 = math.frexp(z);
127 var ez = x3.exponent;127 const ez = x3.exponent;
128 var zs = x3.significand;128 var zs = x3.significand;
129129
130 var spread = ex + ey - ez;130 var spread = ex + ey - ez;
...@@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd {...@@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd {
181 var p = a * split;181 var p = a * split;
182 var ha = a - p;182 var ha = a - p;
183 ha += p;183 ha += p;
184 var la = a - ha;184 const la = a - ha;
185185
186 p = b * split;186 p = b * split;
187 var hb = b - p;187 var hb = b - p;
188 hb += p;188 hb += p;
189 var lb = b - hb;189 const lb = b - hb;
190190
191 p = ha * hb;191 p = ha * hb;
192 var q = ha * lb + la * hb;192 const q = ha * lb + la * hb;
193193
194 ret.hi = p + q;194 ret.hi = p + q;
195 ret.lo = p - ret.hi + q + la * lb;195 ret.lo = p - ret.hi + q + la * lb;
...@@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 {...@@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 {
301 var p = a * split;301 var p = a * split;
302 var ha = a - p;302 var ha = a - p;
303 ha += p;303 ha += p;
304 var la = a - ha;304 const la = a - ha;
305305
306 p = b * split;306 p = b * split;
307 var hb = b - p;307 var hb = b - p;
308 hb += p;308 hb += p;
309 var lb = b - hb;309 const lb = b - hb;
310310
311 p = ha * hb;311 p = ha * hb;
312 var q = ha * lb + la * hb;312 const q = ha * lb + la * hb;
313313
314 ret.hi = p + q;314 ret.hi = p + q;
315 ret.lo = p - ret.hi + q + la * lb;315 ret.lo = p - ret.hi + q + la * lb;
lib/compiler_rt/fmod.zig+8-8
...@@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
81 if (expB == 0) expB = normalize(f80, &bRep);81 if (expB == 0) expB = normalize(f80, &bRep);
8282
83 var highA: u64 = 0;83 var highA: u64 = 0;
84 var highB: u64 = 0;84 const highB: u64 = 0;
85 var lowA: u64 = @truncate(aRep);85 var lowA: u64 = @truncate(aRep);
86 var lowB: u64 = @truncate(bRep);86 const lowB: u64 = @truncate(bRep);
8787
88 while (expA > expB) : (expA -= 1) {88 while (expA > expB) : (expA -= 1) {
89 var high = highA -% highB;89 var high = highA -% highB;
90 var low = lowA -% lowB;90 const low = lowA -% lowB;
91 if (lowA < lowB) {91 if (lowA < lowB) {
92 high -%= 1;92 high -%= 1;
93 }93 }
...@@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
104 }104 }
105105
106 var high = highA -% highB;106 var high = highA -% highB;
107 var low = lowA -% lowB;107 const low = lowA -% lowB;
108 if (lowA < lowB) {108 if (lowA < lowB) {
109 high -%= 1;109 high -%= 1;
110 }110 }
...@@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
194194
195 // OR in extra non-stored mantissa digit195 // OR in extra non-stored mantissa digit
196 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;196 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
197 var highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;197 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
198 var lowA: u64 = aPtr_u64[low_index];198 var lowA: u64 = aPtr_u64[low_index];
199 var lowB: u64 = bPtr_u64[low_index];199 const lowB: u64 = bPtr_u64[low_index];
200200
201 while (expA > expB) : (expA -= 1) {201 while (expA > expB) : (expA -= 1) {
202 var high = highA -% highB;202 var high = highA -% highB;
203 var low = lowA -% lowB;203 const low = lowA -% lowB;
204 if (lowA < lowB) {204 if (lowA < lowB) {
205 high -%= 1;205 high -%= 1;
206 }206 }
...@@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
217 }217 }
218218
219 var high = highA -% highB;219 var high = highA -% highB;
220 var low = lowA -% lowB;220 const low = lowA -% lowB;
221 if (lowA < lowB) {221 if (lowA < lowB) {
222 high -= 1;222 high -= 1;
223 }223 }
lib/compiler_rt/mulc3.zig+1-1
...@@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple...@@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple
25 const zero: T = 0.0;25 const zero: T = 0.0;
26 const one: T = 1.0;26 const one: T = 1.0;
2727
28 var z = Complex(T){28 const z: Complex(T) = .{
29 .real = ac - bd,29 .real = ac - bd,
30 .imag = ad + bc,30 .imag = ad + bc,
31 };31 };
lib/compiler_rt/mulc3_test.zig+16-16
...@@ -19,20 +19,20 @@ test {...@@ -19,20 +19,20 @@ test {
1919
20fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {20fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
21 {21 {
22 var a: T = 1.0;22 const a: T = 1.0;
23 var b: T = 0.0;23 const b: T = 0.0;
24 var c: T = -1.0;24 const c: T = -1.0;
25 var d: T = 0.0;25 const d: T = 0.0;
2626
27 const result = f(a, b, c, d);27 const result = f(a, b, c, d);
28 try expect(result.real == -1.0);28 try expect(result.real == -1.0);
29 try expect(result.imag == 0.0);29 try expect(result.imag == 0.0);
30 }30 }
31 {31 {
32 var a: T = 1.0;32 const a: T = 1.0;
33 var b: T = 0.0;33 const b: T = 0.0;
34 var c: T = -4.0;34 const c: T = -4.0;
35 var d: T = 0.0;35 const d: T = 0.0;
3636
37 const result = f(a, b, c, d);37 const result = f(a, b, c, d);
38 try expect(result.real == -4.0);38 try expect(result.real == -4.0);
...@@ -41,10 +41,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)...@@ -41,10 +41,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
41 {41 {
42 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,42 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
43 // then the result of the * operator is an infinity;43 // then the result of the * operator is an infinity;
44 var a: T = math.inf(T);44 const a: T = math.inf(T);
45 var b: T = -math.inf(T);45 const b: T = -math.inf(T);
46 var c: T = 1.0;46 const c: T = 1.0;
47 var d: T = 0.0;47 const d: T = 0.0;
4848
49 const result = f(a, b, c, d);49 const result = f(a, b, c, d);
50 try expect(result.real == math.inf(T));50 try expect(result.real == math.inf(T));
...@@ -53,10 +53,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)...@@ -53,10 +53,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
53 {53 {
54 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,54 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
55 // then the result of the * operator is an infinity;55 // then the result of the * operator is an infinity;
56 var a: T = math.inf(T);56 const a: T = math.inf(T);
57 var b: T = -1.0;57 const b: T = -1.0;
58 var c: T = 1.0;58 const c: T = 1.0;
59 var d: T = math.inf(T);59 const d: T = math.inf(T);
6060
61 const result = f(a, b, c, d);61 const result = f(a, b, c, d);
62 try expect(result.real == math.inf(T));62 try expect(result.real == math.inf(T));
lib/compiler_rt/mulo.zig+2-2
...@@ -20,7 +20,7 @@ comptime {...@@ -20,7 +20,7 @@ comptime {
20inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {20inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
21 overflow.* = 0;21 overflow.* = 0;
22 const min = math.minInt(ST);22 const min = math.minInt(ST);
23 var res: ST = a *% b;23 const res: ST = a *% b;
24 // Hacker's Delight section Overflow subsection Multiplication24 // Hacker's Delight section Overflow subsection Multiplication
25 // case a=-2^{31}, b=-1 problem, because25 // case a=-2^{31}, b=-1 problem, because
26 // on some machines a*b = -2^{31} with overflow26 // on some machines a*b = -2^{31} with overflow
...@@ -41,7 +41,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int)...@@ -41,7 +41,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int)
41 };41 };
42 const min = math.minInt(ST);42 const min = math.minInt(ST);
43 const max = math.maxInt(ST);43 const max = math.maxInt(ST);
44 var res: EST = @as(EST, a) * @as(EST, b);44 const res: EST = @as(EST, a) * @as(EST, b);
45 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}45 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}
46 if (res < min or max < res)46 if (res < min or max < res)
47 overflow.* = 1;47 overflow.* = 1;
lib/compiler_rt/negdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");...@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__negdi2(a: i64, expected: i64) !void {4fn test__negdi2(a: i64, expected: i64) !void {
5 var result = neg.__negdi2(a);5 const result = neg.__negdi2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/negsi2_test.zig+1-1
...@@ -5,7 +5,7 @@ const testing = std.testing;...@@ -5,7 +5,7 @@ const testing = std.testing;
5const print = std.debug.print;5const print = std.debug.print;
66
7fn test__negsi2(a: i32, expected: i32) !void {7fn test__negsi2(a: i32, expected: i32) !void {
8 var result = neg.__negsi2(a);8 const result = neg.__negsi2(a);
9 try testing.expectEqual(expected, result);9 try testing.expectEqual(expected, result);
10}10}
1111
lib/compiler_rt/negti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");...@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__negti2(a: i128, expected: i128) !void {4fn test__negti2(a: i128, expected: i128) !void {
5 var result = neg.__negti2(a);5 const result = neg.__negti2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/negvdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const negv = @import("negv.zig");...@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__negvdi2(a: i64, expected: i64) !void {4fn test__negvdi2(a: i64, expected: i64) !void {
5 var result = negv.__negvdi2(a);5 const result = negv.__negvdi2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/negvsi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const negv = @import("negv.zig");...@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__negvsi2(a: i32, expected: i32) !void {4fn test__negvsi2(a: i32, expected: i32) !void {
5 var result = negv.__negvsi2(a);5 const result = negv.__negvsi2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/negvti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const negv = @import("negv.zig");...@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__negvti2(a: i128, expected: i128) !void {4fn test__negvti2(a: i128, expected: i128) !void {
5 var result = negv.__negvti2(a);5 const result = negv.__negvti2(a);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/paritydi2_test.zig+3-3
...@@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 {...@@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 {
13}13}
1414
15fn test__paritydi2(a: i64) !void {15fn test__paritydi2(a: i64) !void {
16 var x = parity.__paritydi2(a);16 const x = parity.__paritydi2(a);
17 var expected: i64 = paritydi2Naive(a);17 const expected: i64 = paritydi2Naive(a);
18 try testing.expectEqual(expected, x);18 try testing.expectEqual(expected, x);
19}19}
2020
...@@ -30,7 +30,7 @@ test "paritydi2" {...@@ -30,7 +30,7 @@ test "paritydi2" {
30 var rnd = RndGen.init(42);30 var rnd = RndGen.init(42);
31 var i: u32 = 0;31 var i: u32 = 0;
32 while (i < 10_000) : (i += 1) {32 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i64);33 const rand_num = rnd.random().int(i64);
34 try test__paritydi2(rand_num);34 try test__paritydi2(rand_num);
35 }35 }
36}36}
lib/compiler_rt/paritysi2_test.zig+3-3
...@@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 {...@@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 {
13}13}
1414
15fn test__paritysi2(a: i32) !void {15fn test__paritysi2(a: i32) !void {
16 var x = parity.__paritysi2(a);16 const x = parity.__paritysi2(a);
17 var expected: i32 = paritysi2Naive(a);17 const expected: i32 = paritysi2Naive(a);
18 try testing.expectEqual(expected, x);18 try testing.expectEqual(expected, x);
19}19}
2020
...@@ -30,7 +30,7 @@ test "paritysi2" {...@@ -30,7 +30,7 @@ test "paritysi2" {
30 var rnd = RndGen.init(42);30 var rnd = RndGen.init(42);
31 var i: u32 = 0;31 var i: u32 = 0;
32 while (i < 10_000) : (i += 1) {32 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i32);33 const rand_num = rnd.random().int(i32);
34 try test__paritysi2(rand_num);34 try test__paritysi2(rand_num);
35 }35 }
36}36}
lib/compiler_rt/parityti2_test.zig+3-3
...@@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 {...@@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 {
13}13}
1414
15fn test__parityti2(a: i128) !void {15fn test__parityti2(a: i128) !void {
16 var x = parity.__parityti2(a);16 const x = parity.__parityti2(a);
17 var expected: i128 = parityti2Naive(a);17 const expected: i128 = parityti2Naive(a);
18 try testing.expectEqual(expected, x);18 try testing.expectEqual(expected, x);
19}19}
2020
...@@ -30,7 +30,7 @@ test "parityti2" {...@@ -30,7 +30,7 @@ test "parityti2" {
30 var rnd = RndGen.init(42);30 var rnd = RndGen.init(42);
31 var i: u32 = 0;31 var i: u32 = 0;
32 while (i < 10_000) : (i += 1) {32 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i128);33 const rand_num = rnd.random().int(i128);
34 try test__parityti2(rand_num);34 try test__parityti2(rand_num);
35 }35 }
36}36}
lib/compiler_rt/popcountdi2_test.zig+1-1
...@@ -29,7 +29,7 @@ test "popcountdi2" {...@@ -29,7 +29,7 @@ test "popcountdi2" {
29 var rnd = RndGen.init(42);29 var rnd = RndGen.init(42);
30 var i: u32 = 0;30 var i: u32 = 0;
31 while (i < 10_000) : (i += 1) {31 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i64);32 const rand_num = rnd.random().int(i64);
33 try test__popcountdi2(rand_num);33 try test__popcountdi2(rand_num);
34 }34 }
35}35}
lib/compiler_rt/popcountsi2_test.zig+1-1
...@@ -29,7 +29,7 @@ test "popcountsi2" {...@@ -29,7 +29,7 @@ test "popcountsi2" {
29 var rnd = RndGen.init(42);29 var rnd = RndGen.init(42);
30 var i: u32 = 0;30 var i: u32 = 0;
31 while (i < 10_000) : (i += 1) {31 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i32);32 const rand_num = rnd.random().int(i32);
33 try test__popcountsi2(rand_num);33 try test__popcountsi2(rand_num);
34 }34 }
35}35}
lib/compiler_rt/popcountti2_test.zig+1-1
...@@ -29,7 +29,7 @@ test "popcountti2" {...@@ -29,7 +29,7 @@ test "popcountti2" {
29 var rnd = RndGen.init(42);29 var rnd = RndGen.init(42);
30 var i: u32 = 0;30 var i: u32 = 0;
31 while (i < 10_000) : (i += 1) {31 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i128);32 const rand_num = rnd.random().int(i128);
33 try test__popcountti2(rand_num);33 try test__popcountti2(rand_num);
34 }34 }
35}35}
lib/compiler_rt/powiXf2_test.zig+5-5
...@@ -9,27 +9,27 @@ const testing = std.testing;...@@ -9,27 +9,27 @@ const testing = std.testing;
9const math = std.math;9const math = std.math;
1010
11fn test__powihf2(a: f16, b: i32, expected: f16) !void {11fn test__powihf2(a: f16, b: i32, expected: f16) !void {
12 var result = powiXf2.__powihf2(a, b);12 const result = powiXf2.__powihf2(a, b);
13 try testing.expectEqual(expected, result);13 try testing.expectEqual(expected, result);
14}14}
1515
16fn test__powisf2(a: f32, b: i32, expected: f32) !void {16fn test__powisf2(a: f32, b: i32, expected: f32) !void {
17 var result = powiXf2.__powisf2(a, b);17 const result = powiXf2.__powisf2(a, b);
18 try testing.expectEqual(expected, result);18 try testing.expectEqual(expected, result);
19}19}
2020
21fn test__powidf2(a: f64, b: i32, expected: f64) !void {21fn test__powidf2(a: f64, b: i32, expected: f64) !void {
22 var result = powiXf2.__powidf2(a, b);22 const result = powiXf2.__powidf2(a, b);
23 try testing.expectEqual(expected, result);23 try testing.expectEqual(expected, result);
24}24}
2525
26fn test__powitf2(a: f128, b: i32, expected: f128) !void {26fn test__powitf2(a: f128, b: i32, expected: f128) !void {
27 var result = powiXf2.__powitf2(a, b);27 const result = powiXf2.__powitf2(a, b);
28 try testing.expectEqual(expected, result);28 try testing.expectEqual(expected, result);
29}29}
3030
31fn test__powixf2(a: f80, b: i32, expected: f80) !void {31fn test__powixf2(a: f80, b: i32, expected: f80) !void {
32 var result = powiXf2.__powixf2(a, b);32 const result = powiXf2.__powixf2(a, b);
33 try testing.expectEqual(expected, result);33 try testing.expectEqual(expected, result);
34}34}
3535
lib/compiler_rt/subo.zig+1-1
...@@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {...@@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
2727
28inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {28inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
29 overflow.* = 0;29 overflow.* = 0;
30 var sum: ST = a -% b;30 const sum: ST = a -% b;
31 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract31 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
32 // Let sum = a -% b == a - b - carry == wraparound subtraction.32 // Let sum = a -% b == a - b - carry == wraparound subtraction.
33 // Overflow in a-b-carry occurs, iff a and b have opposite signs33 // Overflow in a-b-carry occurs, iff a and b have opposite signs
lib/compiler_rt/subodi4_test.zig+2-2
...@@ -6,8 +6,8 @@ const math = std.math;...@@ -6,8 +6,8 @@ const math = std.math;
6fn test__subodi4(a: i64, b: i64) !void {6fn test__subodi4(a: i64, b: i64) !void {
7 var result_ov: c_int = undefined;7 var result_ov: c_int = undefined;
8 var expected_ov: c_int = undefined;8 var expected_ov: c_int = undefined;
9 var result = subo.__subodi4(a, b, &result_ov);9 const result = subo.__subodi4(a, b, &result_ov);
10 var expected: i64 = simple_subodi4(a, b, &expected_ov);10 const expected: i64 = simple_subodi4(a, b, &expected_ov);
11 try testing.expectEqual(expected, result);11 try testing.expectEqual(expected, result);
12 try testing.expectEqual(expected_ov, result_ov);12 try testing.expectEqual(expected_ov, result_ov);
13}13}
lib/compiler_rt/subosi4_test.zig+2-2
...@@ -4,8 +4,8 @@ const testing = @import("std").testing;...@@ -4,8 +4,8 @@ const testing = @import("std").testing;
4fn test__subosi4(a: i32, b: i32) !void {4fn test__subosi4(a: i32, b: i32) !void {
5 var result_ov: c_int = undefined;5 var result_ov: c_int = undefined;
6 var expected_ov: c_int = undefined;6 var expected_ov: c_int = undefined;
7 var result = subo.__subosi4(a, b, &result_ov);7 const result = subo.__subosi4(a, b, &result_ov);
8 var expected: i32 = simple_subosi4(a, b, &expected_ov);8 const expected: i32 = simple_subosi4(a, b, &expected_ov);
9 try testing.expectEqual(expected, result);9 try testing.expectEqual(expected, result);
10 try testing.expectEqual(expected_ov, result_ov);10 try testing.expectEqual(expected_ov, result_ov);
11}11}
lib/compiler_rt/suboti4_test.zig+2-2
...@@ -6,8 +6,8 @@ const math = std.math;...@@ -6,8 +6,8 @@ const math = std.math;
6fn test__suboti4(a: i128, b: i128) !void {6fn test__suboti4(a: i128, b: i128) !void {
7 var result_ov: c_int = undefined;7 var result_ov: c_int = undefined;
8 var expected_ov: c_int = undefined;8 var expected_ov: c_int = undefined;
9 var result = subo.__suboti4(a, b, &result_ov);9 const result = subo.__suboti4(a, b, &result_ov);
10 var expected: i128 = simple_suboti4(a, b, &expected_ov);10 const expected: i128 = simple_suboti4(a, b, &expected_ov);
11 try testing.expectEqual(expected, result);11 try testing.expectEqual(expected, result);
12 try testing.expectEqual(expected_ov, result_ov);12 try testing.expectEqual(expected_ov, result_ov);
13}13}
lib/compiler_rt/ucmpdi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void {4fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void {
5 var result = cmp.__ucmpdi2(a, b);5 const result = cmp.__ucmpdi2(a, b);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/ucmpsi2_test.zig+1-1
...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void {4fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void {
5 var result = cmp.__ucmpsi2(a, b);5 const result = cmp.__ucmpsi2(a, b);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/ucmpti2_test.zig+1-1
...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");...@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
2const testing = @import("std").testing;2const testing = @import("std").testing;
33
4fn test__ucmpti2(a: u128, b: u128, expected: i32) !void {4fn test__ucmpti2(a: u128, b: u128, expected: i32) !void {
5 var result = cmp.__ucmpti2(a, b);5 const result = cmp.__ucmpti2(a, b);
6 try testing.expectEqual(expected, result);6 try testing.expectEqual(expected, result);
7}7}
88
lib/compiler_rt/udivmod.zig+4-4
...@@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {...@@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
52 if (rhat >= b) break;52 if (rhat >= b) break;
53 }53 }
5454
55 var un21 = un64 *% b +% un1 -% q1 *% v;55 const un21 = un64 *% b +% un1 -% q1 *% v;
5656
57 // Compute the second quotient digit57 // Compute the second quotient digit
58 var q0 = un21 / vn1;58 var q0 = un21 / vn1;
...@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {...@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
101 return 0;101 return 0;
102 }102 }
103103
104 var a: [2]HalfT = @bitCast(a_);104 const a: [2]HalfT = @bitCast(a_);
105 var b: [2]HalfT = @bitCast(b_);105 const b: [2]HalfT = @bitCast(b_);
106 var q: [2]HalfT = undefined;106 var q: [2]HalfT = undefined;
107 var r: [2]HalfT = undefined;107 var r: [2]HalfT = undefined;
108108
...@@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {...@@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
125 }125 }
126126
127 // 0 <= shift <= 63127 // 0 <= shift <= 63
128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);128 const shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
129 var af: T = @bitCast(a);129 var af: T = @bitCast(a);
130 var bf = @as(T, @bitCast(b)) << shift;130 var bf = @as(T, @bitCast(b)) << shift;
131 q = @bitCast(@as(T, 0));131 q = @bitCast(@as(T, 0));
lib/compiler_rt/udivmodei4.zig+2-2
...@@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)...@@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)
116 @setRuntimeSafety(builtin.is_test);116 @setRuntimeSafety(builtin.is_test);
117 const u = u_p[0 .. bits / 32];117 const u = u_p[0 .. bits / 32];
118 const v = v_p[0 .. bits / 32];118 const v = v_p[0 .. bits / 32];
119 var q = r_q[0 .. bits / 32];119 const q = r_q[0 .. bits / 32];
120 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;120 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
121}121}
122122
...@@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)...@@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)
124 @setRuntimeSafety(builtin.is_test);124 @setRuntimeSafety(builtin.is_test);
125 const u = u_p[0 .. bits / 32];125 const u = u_p[0 .. bits / 32];
126 const v = v_p[0 .. bits / 32];126 const v = v_p[0 .. bits / 32];
127 var r = r_p[0 .. bits / 32];127 const r = r_p[0 .. bits / 32];
128 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;128 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
129}129}
130130
lib/std/Build/Cache.zig+1-1
...@@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {...@@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
141 var i: u8 = 1; // Start at 1 to skip over checking the null prefix.141 var i: u8 = 1; // Start at 1 to skip over checking the null prefix.
142 while (i < prefixes_slice.len) : (i += 1) {142 while (i < prefixes_slice.len) : (i += 1) {
143 const p = prefixes_slice[i].path.?;143 const p = prefixes_slice[i].path.?;
144 var sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) {144 const sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) {
145 error.NotASubPath => continue,145 error.NotASubPath => continue,
146 else => |e| return e,146 else => |e| return e,
147 };147 };
lib/std/Build/Cache/DepTokenizer.zig+3-3
...@@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {...@@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
950950
951fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {951fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
952 var buf: [80]u8 = undefined;952 var buf: [80]u8 = undefined;
953 var text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });953 const text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });
954 try out.writeAll(text);954 try out.writeAll(text);
955 var i: usize = text.len;955 var i: usize = text.len;
956 const end = 79;956 const end = 79;
...@@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void {...@@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void {
983 try printDecValue(out, offset, 8);983 try printDecValue(out, offset, 8);
984 try out.writeAll(":");984 try out.writeAll(":");
985 try out.writeAll(" ");985 try out.writeAll(" ");
986 var end1 = @min(offset + n, offset + 8);986 const end1 = @min(offset + n, offset + 8);
987 for (bytes[offset..end1]) |b| {987 for (bytes[offset..end1]) |b| {
988 try out.writeAll(" ");988 try out.writeAll(" ");
989 try printHexValue(out, b, 2);989 try printHexValue(out, b, 2);
990 }990 }
991 var end2 = offset + n;991 const end2 = offset + n;
992 if (end2 > end1) {992 if (end2 > end1) {
993 try out.writeAll(" ");993 try out.writeAll(" ");
994 for (bytes[end1..end2]) |b| {994 for (bytes[end1..end2]) |b| {
lib/std/Build/Step/CheckObject.zig+1-1
...@@ -293,7 +293,7 @@ const Check = struct {...@@ -293,7 +293,7 @@ const Check = struct {
293293
294/// Creates a new empty sequence of actions.294/// Creates a new empty sequence of actions.
295pub fn checkStart(self: *CheckObject) void {295pub fn checkStart(self: *CheckObject) void {
296 var new_check = Check.create(self.step.owner.allocator);296 const new_check = Check.create(self.step.owner.allocator);
297 self.checks.append(new_check) catch @panic("OOM");297 self.checks.append(new_check) catch @panic("OOM");
298}298}
299299
lib/std/Build/Step/ConfigHeader.zig+2-2
...@@ -307,8 +307,8 @@ fn render_cmake(...@@ -307,8 +307,8 @@ fn render_cmake(
307 values: std.StringArrayHashMap(Value),307 values: std.StringArrayHashMap(Value),
308 src_path: []const u8,308 src_path: []const u8,
309) !void {309) !void {
310 var build = step.owner;310 const build = step.owner;
311 var allocator = build.allocator;311 const allocator = build.allocator;
312312
313 var values_copy = try values.clone();313 var values_copy = try values.clone();
314 defer values_copy.deinit();314 defer values_copy.deinit();
lib/std/Build/Step/Run.zig+1-1
...@@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void {...@@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void {
301 const env_map = getEnvMapInternal(self);301 const env_map = getEnvMapInternal(self);
302302
303 const key = "PATH";303 const key = "PATH";
304 var prev_path = env_map.get(key);304 const prev_path = env_map.get(key);
305305
306 if (prev_path) |pp| {306 if (prev_path) |pp| {
307 const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });307 const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });
lib/std/Progress.zig+1
...@@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any...@@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
397397
398test "basic functionality" {398test "basic functionality" {
399 var disable = true;399 var disable = true;
400 _ = &disable;
400 if (disable) {401 if (disable) {
401 // This test is disabled because it uses time.sleep() and is therefore slow. It also402 // This test is disabled because it uses time.sleep() and is therefore slow. It also
402 // prints bogus progress data to stderr.403 // prints bogus progress data to stderr.
lib/std/Thread/WaitGroup.zig+1-1
...@@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void {...@@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void {
25}25}
2626
27pub fn wait(self: *WaitGroup) void {27pub fn wait(self: *WaitGroup) void {
28 var state = self.state.fetchAdd(is_waiting, .Acquire);28 const state = self.state.fetchAdd(is_waiting, .Acquire);
29 assert(state & is_waiting == 0);29 assert(state & is_waiting == 0);
3030
31 if ((state / one_pending) > 0) {31 if ((state / one_pending) > 0) {
lib/std/array_hash_map.zig+3-3
...@@ -2076,11 +2076,11 @@ test "iterator hash map" {...@@ -2076,11 +2076,11 @@ test "iterator hash map" {
2076 try reset_map.putNoClobber(1, 22);2076 try reset_map.putNoClobber(1, 22);
2077 try reset_map.putNoClobber(2, 33);2077 try reset_map.putNoClobber(2, 33);
20782078
2079 var keys = [_]i32{2079 const keys = [_]i32{
2080 0, 2, 1,2080 0, 2, 1,
2081 };2081 };
20822082
2083 var values = [_]i32{2083 const values = [_]i32{
2084 11, 33, 22,2084 11, 33, 22,
2085 };2085 };
20862086
...@@ -2116,7 +2116,7 @@ test "iterator hash map" {...@@ -2116,7 +2116,7 @@ test "iterator hash map" {
2116 }2116 }
21172117
2118 it.reset();2118 it.reset();
2119 var entry = it.next().?;2119 const entry = it.next().?;
2120 try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*);2120 try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*);
2121 try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*);2121 try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*);
2122}2122}
lib/std/array_list.zig+2-2
...@@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
979 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {979 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
980 if (self.capacity >= new_capacity) return;980 if (self.capacity >= new_capacity) return;
981981
982 var better_capacity = growCapacity(self.capacity, new_capacity);982 const better_capacity = growCapacity(self.capacity, new_capacity);
983 return self.ensureTotalCapacityPrecise(allocator, better_capacity);983 return self.ensureTotalCapacityPrecise(allocator, better_capacity);
984 }984 }
985985
...@@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" {...@@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
1159 }1159 }
11601160
1161 {1161 {
1162 var list = ArrayListUnmanaged(i32){};1162 const list = ArrayListUnmanaged(i32){};
11631163
1164 try testing.expect(list.items.len == 0);1164 try testing.expect(list.items.len == 0);
1165 try testing.expect(list.capacity == 0);1165 try testing.expect(list.capacity == 0);
lib/std/atomic/Atomic.zig+1-1
...@@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type {...@@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type {
125 @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores");125 @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores");
126 }126 }
127127
128 comptime var success_is_stronger = switch (failure) {128 const success_is_stronger = switch (failure) {
129 .SeqCst => success == .SeqCst,129 .SeqCst => success == .SeqCst,
130 .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"),130 .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"),
131 .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire,131 .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire,
lib/std/atomic/queue.zig+2-2
...@@ -175,11 +175,11 @@ const puts_per_thread = 500;...@@ -175,11 +175,11 @@ const puts_per_thread = 500;
175const put_thread_count = 3;175const put_thread_count = 3;
176176
177test "std.atomic.Queue" {177test "std.atomic.Queue" {
178 var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);178 const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
179 defer std.heap.page_allocator.free(plenty_of_memory);179 defer std.heap.page_allocator.free(plenty_of_memory);
180180
181 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);181 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);
182 var a = fixed_buffer_allocator.threadSafeAllocator();182 const a = fixed_buffer_allocator.threadSafeAllocator();
183183
184 var queue = Queue(i32).init();184 var queue = Queue(i32).init();
185 var context = Context{185 var context = Context{
lib/std/atomic/stack.zig+2-2
...@@ -85,11 +85,11 @@ const puts_per_thread = 500;...@@ -85,11 +85,11 @@ const puts_per_thread = 500;
85const put_thread_count = 3;85const put_thread_count = 3;
8686
87test "std.atomic.stack" {87test "std.atomic.stack" {
88 var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);88 const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
89 defer std.heap.page_allocator.free(plenty_of_memory);89 defer std.heap.page_allocator.free(plenty_of_memory);
9090
91 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);91 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);
92 var a = fixed_buffer_allocator.threadSafeAllocator();92 const a = fixed_buffer_allocator.threadSafeAllocator();
9393
94 var stack = Stack(i32).init();94 var stack = Stack(i32).init();
95 var context = Context{95 var context = Context{
lib/std/base64.zig+11-11
...@@ -239,7 +239,7 @@ pub const Base64Decoder = struct {...@@ -239,7 +239,7 @@ pub const Base64Decoder = struct {
239 if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter;239 if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter;
240 std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little);240 std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little);
241 }241 }
242 var remaining = source[fast_src_idx..];242 const remaining = source[fast_src_idx..];
243 for (remaining, fast_src_idx..) |c, src_idx| {243 for (remaining, fast_src_idx..) |c, src_idx| {
244 const d = decoder.char_to_index[c];244 const d = decoder.char_to_index[c];
245 if (d == invalid_char) {245 if (d == invalid_char) {
...@@ -259,7 +259,7 @@ pub const Base64Decoder = struct {...@@ -259,7 +259,7 @@ pub const Base64Decoder = struct {
259 return error.InvalidPadding;259 return error.InvalidPadding;
260 }260 }
261 if (leftover_idx == null) return;261 if (leftover_idx == null) return;
262 var leftover = source[leftover_idx.?..];262 const leftover = source[leftover_idx.?..];
263 if (decoder.pad_char) |pad_char| {263 if (decoder.pad_char) |pad_char| {
264 const padding_len = acc_len / 2;264 const padding_len = acc_len / 2;
265 var padding_chars: usize = 0;265 var padding_chars: usize = 0;
...@@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct {...@@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct {
338 if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding;338 if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding;
339 return dest_idx;339 return dest_idx;
340 }340 }
341 var leftover = source[leftover_idx.?..];341 const leftover = source[leftover_idx.?..];
342 if (decoder.pad_char) |pad_char| {342 if (decoder.pad_char) |pad_char| {
343 var padding_chars: usize = 0;343 var padding_chars: usize = 0;
344 for (leftover) |c| {344 for (leftover) |c| {
...@@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
483 // Base64Decoder483 // Base64Decoder
484 {484 {
485 var buffer: [0x100]u8 = undefined;485 var buffer: [0x100]u8 = undefined;
486 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];486 const decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
487 try codecs.Decoder.decode(decoded, expected_encoded);487 try codecs.Decoder.decode(decoded, expected_encoded);
488 try testing.expectEqualSlices(u8, expected_decoded, decoded);488 try testing.expectEqualSlices(u8, expected_decoded, decoded);
489 }489 }
...@@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
492 {492 {
493 const decoder_ignore_nothing = codecs.decoderWithIgnore("");493 const decoder_ignore_nothing = codecs.decoderWithIgnore("");
494 var buffer: [0x100]u8 = undefined;494 var buffer: [0x100]u8 = undefined;
495 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];495 const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
496 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);496 const written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
497 try testing.expect(written <= decoded.len);497 try testing.expect(written <= decoded.len);
498 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);498 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
499 }499 }
...@@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
502fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {502fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {
503 const decoder_ignore_space = codecs.decoderWithIgnore(" ");503 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
504 var buffer: [0x100]u8 = undefined;504 var buffer: [0x100]u8 = undefined;
505 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];505 const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
506 var written = try decoder_ignore_space.decode(decoded, encoded);506 const written = try decoder_ignore_space.decode(decoded, encoded);
507 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);507 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
508}508}
509509
...@@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void...@@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void
511 const decoder_ignore_space = codecs.decoderWithIgnore(" ");511 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
512 var buffer: [0x100]u8 = undefined;512 var buffer: [0x100]u8 = undefined;
513 if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| {513 if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| {
514 var decoded = buffer[0..decoded_size];514 const decoded = buffer[0..decoded_size];
515 if (codecs.Decoder.decode(decoded, encoded)) |_| {515 if (codecs.Decoder.decode(decoded, encoded)) |_| {
516 return error.ExpectedError;516 return error.ExpectedError;
517 } else |err| if (err != expected_err) return err;517 } else |err| if (err != expected_err) return err;
...@@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void...@@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void
525fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {525fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
526 const decoder_ignore_space = codecs.decoderWithIgnore(" ");526 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
527 var buffer: [0x100]u8 = undefined;527 var buffer: [0x100]u8 = undefined;
528 var decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1];528 const decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1];
529 if (decoder_ignore_space.decode(decoded, encoded)) |_| {529 if (decoder_ignore_space.decode(decoded, encoded)) |_| {
530 return error.ExpectedError;530 return error.ExpectedError;
531 } else |err| if (err != error.NoSpaceLeft) return err;531 } else |err| if (err != error.NoSpaceLeft) return err;
...@@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {...@@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
534fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {534fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
535 const decoder_ignore_space = codecs.decoderWithIgnore(" ");535 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
536 var buffer: [0x100]u8 = undefined;536 var buffer: [0x100]u8 = undefined;
537 var decoded = buffer[0..4];537 const decoded = buffer[0..4];
538 if (decoder_ignore_space.decode(decoded, encoded)) |_| {538 if (decoder_ignore_space.decode(decoded, encoded)) |_| {
539 return error.ExpectedError;539 return error.ExpectedError;
540 } else |err| if (err != error.NoSpaceLeft) return err;540 } else |err| if (err != error.NoSpaceLeft) return err;
lib/std/buf_map.zig+1-2
...@@ -15,8 +15,7 @@ pub const BufMap = struct {...@@ -15,8 +15,7 @@ pub const BufMap = struct {
15 /// That allocator will be used for both backing allocations15 /// That allocator will be used for both backing allocations
16 /// and string deduplication.16 /// and string deduplication.
17 pub fn init(allocator: Allocator) BufMap {17 pub fn init(allocator: Allocator) BufMap {
18 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };18 return .{ .hash_map = BufMapHashMap.init(allocator) };
19 return self;
20 }19 }
2120
22 /// Free the backing storage of the map, as well as all21 /// Free the backing storage of the map, as well as all
lib/std/buf_set.zig+4-5
...@@ -17,8 +17,7 @@ pub const BufSet = struct {...@@ -17,8 +17,7 @@ pub const BufSet = struct {
17 /// be used internally for both backing allocations and17 /// be used internally for both backing allocations and
18 /// string duplication.18 /// string duplication.
19 pub fn init(a: Allocator) BufSet {19 pub fn init(a: Allocator) BufSet {
20 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };20 return .{ .hash_map = BufSetHashMap.init(a) };
21 return self;
22 }21 }
2322
24 /// Free a BufSet along with all stored keys.23 /// Free a BufSet along with all stored keys.
...@@ -76,8 +75,8 @@ pub const BufSet = struct {...@@ -76,8 +75,8 @@ pub const BufSet = struct {
76 self: *const BufSet,75 self: *const BufSet,
77 new_allocator: Allocator,76 new_allocator: Allocator,
78 ) Allocator.Error!BufSet {77 ) Allocator.Error!BufSet {
79 var cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator);78 const cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator);
80 var cloned = BufSet{ .hash_map = cloned_hashmap };79 const cloned = BufSet{ .hash_map = cloned_hashmap };
81 var it = cloned.hash_map.keyIterator();80 var it = cloned.hash_map.keyIterator();
82 while (it.next()) |key_ptr| {81 while (it.next()) |key_ptr| {
83 key_ptr.* = try cloned.copy(key_ptr.*);82 key_ptr.* = try cloned.copy(key_ptr.*);
...@@ -134,7 +133,7 @@ test "BufSet clone" {...@@ -134,7 +133,7 @@ test "BufSet clone" {
134}133}
135134
136test "BufSet.clone with arena" {135test "BufSet.clone with arena" {
137 var allocator = std.testing.allocator;136 const allocator = std.testing.allocator;
138 var arena = std.heap.ArenaAllocator.init(allocator);137 var arena = std.heap.ArenaAllocator.init(allocator);
139 defer arena.deinit();138 defer arena.deinit();
140139
lib/std/builtin.zig+3-4
...@@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr...@@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
777 }777 }
778778
779 var fmt: [256]u8 = undefined;779 var fmt: [256]u8 = undefined;
780 var slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg});780 const slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg});
781781 const len = try std.unicode.utf8ToUtf16Le(utf16, slice);
782 var len = try std.unicode.utf8ToUtf16Le(utf16, slice);
783782
784 utf16[len] = 0;783 utf16[len] = 0;
785784
...@@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr...@@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
790 };789 };
791790
792 var exit_size: usize = 0;791 var exit_size: usize = 0;
793 var exit_data = ExitData.create_exit_data(msg, &exit_size) catch null;792 const exit_data = ExitData.create_exit_data(msg, &exit_size) catch null;
794793
795 if (exit_data) |data| {794 if (exit_data) |data| {
796 if (uefi.system_table.std_err) |out| {795 if (uefi.system_table.std_err) |out| {
lib/std/child_process.zig+1-1
...@@ -847,7 +847,7 @@ pub const ChildProcess = struct {...@@ -847,7 +847,7 @@ pub const ChildProcess = struct {
847 }847 }
848848
849 windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {849 windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
850 var original_err = switch (no_path_err) {850 const original_err = switch (no_path_err) {
851 error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e,851 error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e,
852 error.UnrecoverableInvalidExe => return error.InvalidExe,852 error.UnrecoverableInvalidExe => return error.InvalidExe,
853 else => |e| return e,853 else => |e| return e,
lib/std/coff.zig+1-1
...@@ -1075,7 +1075,7 @@ pub const Coff = struct {...@@ -1075,7 +1075,7 @@ pub const Coff = struct {
1075 var stream = std.io.fixedBufferStream(data);1075 var stream = std.io.fixedBufferStream(data);
1076 const reader = stream.reader();1076 const reader = stream.reader();
1077 try stream.seekTo(pe_pointer_offset);1077 try stream.seekTo(pe_pointer_offset);
1078 var coff_header_offset = try reader.readInt(u32, .little);1078 const coff_header_offset = try reader.readInt(u32, .little);
1079 try stream.seekTo(coff_header_offset);1079 try stream.seekTo(coff_header_offset);
1080 var buf: [4]u8 = undefined;1080 var buf: [4]u8 = undefined;
1081 try reader.readNoEof(&buf);1081 try reader.readNoEof(&buf);
lib/std/compress/deflate/bits_utils.zig+2-2
...@@ -15,7 +15,7 @@ test "bitReverse" {...@@ -15,7 +15,7 @@ test "bitReverse" {
15 out: u16,15 out: u16,
16 };16 };
1717
18 var reverse_bits_tests = [_]ReverseBitsTest{18 const reverse_bits_tests = [_]ReverseBitsTest{
19 .{ .in = 1, .bit_count = 1, .out = 1 },19 .{ .in = 1, .bit_count = 1, .out = 1 },
20 .{ .in = 1, .bit_count = 2, .out = 2 },20 .{ .in = 1, .bit_count = 2, .out = 2 },
21 .{ .in = 1, .bit_count = 3, .out = 4 },21 .{ .in = 1, .bit_count = 3, .out = 4 },
...@@ -27,7 +27,7 @@ test "bitReverse" {...@@ -27,7 +27,7 @@ test "bitReverse" {
27 };27 };
2828
29 for (reverse_bits_tests) |h| {29 for (reverse_bits_tests) |h| {
30 var v = bitReverse(u16, h.in, h.bit_count);30 const v = bitReverse(u16, h.in, h.bit_count);
31 try std.testing.expectEqual(h.out, v);31 try std.testing.expectEqual(h.out, v);
32 }32 }
33}33}
lib/std/compress/deflate/compressor.zig+25-25
...@@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel {...@@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel {
156// up to length 'max'. Both slices must be at least 'max'156// up to length 'max'. Both slices must be at least 'max'
157// bytes in size.157// bytes in size.
158fn matchLen(a: []u8, b: []u8, max: u32) u32 {158fn matchLen(a: []u8, b: []u8, max: u32) u32 {
159 var bounded_a = a[0..max];159 const bounded_a = a[0..max];
160 var bounded_b = b[0..max];160 const bounded_b = b[0..max];
161 for (bounded_a, 0..) |av, i| {161 for (bounded_a, 0..) |av, i| {
162 if (bounded_b[i] != av) {162 if (bounded_b[i] != av) {
163 return @as(u32, @intCast(i));163 return @as(u32, @intCast(i));
...@@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 {...@@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 {
191 @as(u32, b[0]) << 24;191 @as(u32, b[0]) << 24;
192192
193 dst[0] = (hb *% hash_mul) >> (32 - hash_bits);193 dst[0] = (hb *% hash_mul) >> (32 - hash_bits);
194 var end = b.len - min_match_length + 1;194 const end = b.len - min_match_length + 1;
195 var i: u32 = 1;195 var i: u32 = 1;
196 while (i < end) : (i += 1) {196 while (i < end) : (i += 1) {
197 hb = (hb << 8) | @as(u32, b[i + 3]);197 hb = (hb << 8) | @as(u32, b[i + 3]);
...@@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
305 }305 }
306 self.hash_offset += window_size;306 self.hash_offset += window_size;
307 if (self.hash_offset > max_hash_offset) {307 if (self.hash_offset > max_hash_offset) {
308 var delta = self.hash_offset - 1;308 const delta = self.hash_offset - 1;
309 self.hash_offset -= delta;309 self.hash_offset -= delta;
310 self.chain_head -|= delta;310 self.chain_head -|= delta;
311311
...@@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type {
369 }369 }
370 // Add all to window.370 // Add all to window.
371 @memcpy(self.window[0..b.len], b);371 @memcpy(self.window[0..b.len], b);
372 var n = b.len;372 const n = b.len;
373373
374 // Calculate 256 hashes at the time (more L1 cache hits)374 // Calculate 256 hashes at the time (more L1 cache hits)
375 var loops = (n + 256 - min_match_length) / 256;375 const loops = (n + 256 - min_match_length) / 256;
376 var j: usize = 0;376 var j: usize = 0;
377 while (j < loops) : (j += 1) {377 while (j < loops) : (j += 1) {
378 var index = j * 256;378 const index = j * 256;
379 var end = index + 256 + min_match_length - 1;379 var end = index + 256 + min_match_length - 1;
380 if (end > n) {380 if (end > n) {
381 end = n;381 end = n;
382 }382 }
383 var to_check = self.window[index..end];383 const to_check = self.window[index..end];
384 var dst_size = to_check.len - min_match_length + 1;384 const dst_size = to_check.len - min_match_length + 1;
385385
386 if (dst_size <= 0) {386 if (dst_size <= 0) {
387 continue;387 continue;
388 }388 }
389389
390 var dst = self.hash_match[0..dst_size];390 const dst = self.hash_match[0..dst_size];
391 _ = self.bulk_hasher(to_check, dst);391 _ = self.bulk_hasher(to_check, dst);
392 var new_h: u32 = 0;392 var new_h: u32 = 0;
393 for (dst, 0..) |val, i| {393 for (dst, 0..) |val, i| {
394 var di = i + index;394 const di = i + index;
395 new_h = val;395 new_h = val;
396 var hh = &self.hash_head[new_h & hash_mask];396 const hh = &self.hash_head[new_h & hash_mask];
397 // Get previous value with the same hash.397 // Get previous value with the same hash.
398 // Our chain should point to the previous value.398 // Our chain should point to the previous value.
399 self.hash_prev[di & window_mask] = hh.*;399 self.hash_prev[di & window_mask] = hh.*;
...@@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type {
447 }447 }
448448
449 var w_end = win[pos + length];449 var w_end = win[pos + length];
450 var w_pos = win[pos..];450 const w_pos = win[pos..];
451 var min_index = pos -| window_size;451 const min_index = pos -| window_size;
452452
453 var i = prev_head;453 var i = prev_head;
454 while (tries > 0) : (tries -= 1) {454 while (tries > 0) : (tries -= 1) {
455 if (w_end == win[i + length]) {455 if (w_end == win[i + length]) {
456 var n = matchLen(win[i..], w_pos, min_match_look);456 const n = matchLen(win[i..], w_pos, min_match_look);
457457
458 if (n > length and (n > min_match_length or pos - i <= 4096)) {458 if (n > length and (n > min_match_length or pos - i <= 4096)) {
459 length = n;459 length = n;
...@@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
565 while (true) {565 while (true) {
566 assert(self.index <= self.window_end);566 assert(self.index <= self.window_end);
567567
568 var lookahead = self.window_end -| self.index;568 const lookahead = self.window_end -| self.index;
569 if (lookahead < min_match_length + max_match_length) {569 if (lookahead < min_match_length + max_match_length) {
570 if (!self.sync) {570 if (!self.sync) {
571 break;571 break;
...@@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type {
590 if (self.index < self.max_insert_index) {590 if (self.index < self.max_insert_index) {
591 // Update the hash591 // Update the hash
592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);
593 var hh = &self.hash_head[self.hash & hash_mask];593 const hh = &self.hash_head[self.hash & hash_mask];
594 self.chain_head = @as(u32, @intCast(hh.*));594 self.chain_head = @as(u32, @intCast(hh.*));
595 self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head));595 self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head));
596 hh.* = @as(u32, @intCast(self.index + self.hash_offset));596 hh.* = @as(u32, @intCast(self.index + self.hash_offset));
597 }597 }
598 var prev_length = self.length;598 const prev_length = self.length;
599 var prev_offset = self.offset;599 const prev_offset = self.offset;
600 self.length = min_match_length - 1;600 self.length = min_match_length - 1;
601 self.offset = 0;601 self.offset = 0;
602 var min_index = self.index -| window_size;602 const min_index = self.index -| window_size;
603603
604 if (self.hash_offset <= self.chain_head and604 if (self.hash_offset <= self.chain_head and
605 self.chain_head - self.hash_offset >= min_index and605 self.chain_head - self.hash_offset >= min_index and
...@@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
610 prev_length < self.compression_level.lazy))610 prev_length < self.compression_level.lazy))
611 {611 {
612 {612 {
613 var fmatch = self.findMatch(613 const fmatch = self.findMatch(
614 self.index,614 self.index,
615 self.chain_head -| self.hash_offset,615 self.chain_head -| self.hash_offset,
616 min_match_length - 1,616 min_match_length - 1,
...@@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
658 self.hash = hash4(self.window[index .. index + min_match_length]);658 self.hash = hash4(self.window[index .. index + min_match_length]);
659 // Get previous value with the same hash.659 // Get previous value with the same hash.
660 // Our chain should point to the previous value.660 // Our chain should point to the previous value.
661 var hh = &self.hash_head[self.hash & hash_mask];661 const hh = &self.hash_head[self.hash & hash_mask];
662 self.hash_prev[index & window_mask] = hh.*;662 self.hash_prev[index & window_mask] = hh.*;
663 // Set the head of the hash chain to us.663 // Set the head of the hash chain to us.
664 hh.* = @as(u32, @intCast(index + self.hash_offset));664 hh.* = @as(u32, @intCast(index + self.hash_offset));
...@@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
740 // compressed form of data to its underlying writer.740 // compressed form of data to its underlying writer.
741 while (buf.len > 0) {741 while (buf.len > 0) {
742 try self.step();742 try self.step();
743 var filled = self.fill(buf);743 const filled = self.fill(buf);
744 buf = buf[filled..];744 buf = buf[filled..];
745 }745 }
746746
...@@ -1097,12 +1097,12 @@ test "bulkHash4" {...@@ -1097,12 +1097,12 @@ test "bulkHash4" {
1097 while (j < out.len) : (j += 1) {1097 while (j < out.len) : (j += 1) {
1098 var y = out[0..j];1098 var y = out[0..j];
10991099
1100 var dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1);1100 const dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1);
1101 defer testing.allocator.free(dst);1101 defer testing.allocator.free(dst);
11021102
1103 _ = bulkHash4(y, dst);1103 _ = bulkHash4(y, dst);
1104 for (dst, 0..) |got, i| {1104 for (dst, 0..) |got, i| {
1105 var want = hash4(y[i..]);1105 const want = hash4(y[i..]);
1106 try testing.expectEqual(want, got);1106 try testing.expectEqual(want, got);
1107 }1107 }
1108 }1108 }
lib/std/compress/deflate/compressor_test.zig+16-16
...@@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {...@@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
27 var whole_buf = std.ArrayList(u8).init(testing.allocator);27 var whole_buf = std.ArrayList(u8).init(testing.allocator);
28 defer whole_buf.deinit();28 defer whole_buf.deinit();
2929
30 var multi_writer = io.multiWriter(.{30 const multi_writer = io.multiWriter(.{
31 divided_buf.writer(),31 divided_buf.writer(),
32 whole_buf.writer(),32 whole_buf.writer(),
33 }).writer();33 }).writer();
...@@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {...@@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
48 defer decomp.deinit();48 defer decomp.deinit();
4949
50 // Write first half of the input and flush()50 // Write first half of the input and flush()
51 var half: usize = (input.len + 1) / 2;51 const half: usize = (input.len + 1) / 2;
52 var half_len: usize = half - 0;52 var half_len: usize = half - 0;
53 {53 {
54 _ = try comp.writer().writeAll(input[0..half]);54 _ = try comp.writer().writeAll(input[0..half]);
...@@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {...@@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
57 try comp.flush();57 try comp.flush();
5858
59 // Read back59 // Read back
60 var decompressed = try testing.allocator.alloc(u8, half_len);60 const decompressed = try testing.allocator.alloc(u8, half_len);
61 defer testing.allocator.free(decompressed);61 defer testing.allocator.free(decompressed);
6262
63 var read = try decomp.reader().readAll(decompressed); // read at least half63 const read = try decomp.reader().readAll(decompressed); // read at least half
64 try testing.expectEqual(half_len, read);64 try testing.expectEqual(half_len, read);
65 try testing.expectEqualSlices(u8, input[0..half], decompressed);65 try testing.expectEqualSlices(u8, input[0..half], decompressed);
66 }66 }
...@@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {...@@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
74 try comp.close();74 try comp.close();
7575
76 // Read back76 // Read back
77 var decompressed = try testing.allocator.alloc(u8, half_len);77 const decompressed = try testing.allocator.alloc(u8, half_len);
78 defer testing.allocator.free(decompressed);78 defer testing.allocator.free(decompressed);
7979
80 var read = try decomp.reader().readAll(decompressed);80 var read = try decomp.reader().readAll(decompressed);
...@@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {...@@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
94 try comp.close();94 try comp.close();
9595
96 // stream should work for ordinary reader too (reading whole_buf in one go)96 // stream should work for ordinary reader too (reading whole_buf in one go)
97 var whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader();97 const whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader();
98 var decomp = try decompressor(testing.allocator, whole_buf_reader, null);98 var decomp = try decompressor(testing.allocator, whole_buf_reader, null);
99 defer decomp.deinit();99 defer decomp.deinit();
100100
101 var decompressed = try testing.allocator.alloc(u8, input.len);101 const decompressed = try testing.allocator.alloc(u8, input.len);
102 defer testing.allocator.free(decompressed);102 defer testing.allocator.free(decompressed);
103103
104 _ = try decomp.reader().readAll(decompressed);104 _ = try decomp.reader().readAll(decompressed);
...@@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li...@@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li
125 var decomp = try decompressor(testing.allocator, fib.reader(), null);125 var decomp = try decompressor(testing.allocator, fib.reader(), null);
126 defer decomp.deinit();126 defer decomp.deinit();
127127
128 var decompressed = try testing.allocator.alloc(u8, input.len);128 const decompressed = try testing.allocator.alloc(u8, input.len);
129 defer testing.allocator.free(decompressed);129 defer testing.allocator.free(decompressed);
130130
131 var read: usize = try decomp.reader().readAll(decompressed);131 const read: usize = try decomp.reader().readAll(decompressed);
132 try testing.expectEqual(input.len, read);132 try testing.expectEqual(input.len, read);
133 try testing.expectEqualSlices(u8, input, decompressed);133 try testing.expectEqualSlices(u8, input, decompressed);
134134
...@@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void {...@@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void {
153}153}
154154
155test "deflate/inflate" {155test "deflate/inflate" {
156 var limits = [_]u32{0} ** 11;156 const limits = [_]u32{0} ** 11;
157157
158 var test0 = [_]u8{};158 var test0 = [_]u8{};
159 var test1 = [_]u8{0x11};159 var test1 = [_]u8{0x11};
...@@ -313,7 +313,7 @@ test "decompressor dictionary" {...@@ -313,7 +313,7 @@ test "decompressor dictionary" {
313 try comp.writer().writeAll(text);313 try comp.writer().writeAll(text);
314 try comp.close();314 try comp.close();
315315
316 var decompressed = try testing.allocator.alloc(u8, text.len);316 const decompressed = try testing.allocator.alloc(u8, text.len);
317 defer testing.allocator.free(decompressed);317 defer testing.allocator.free(decompressed);
318318
319 var decomp = try decompressor(319 var decomp = try decompressor(
...@@ -432,7 +432,7 @@ test "deflate/inflate string" {...@@ -432,7 +432,7 @@ test "deflate/inflate string" {
432 };432 };
433433
434 inline for (deflate_inflate_string_tests) |t| {434 inline for (deflate_inflate_string_tests) |t| {
435 var golden = @embedFile("testdata/" ++ t.filename);435 const golden = @embedFile("testdata/" ++ t.filename);
436 try testToFromWithLimit(golden, t.limit);436 try testToFromWithLimit(golden, t.limit);
437 }437 }
438}438}
...@@ -466,14 +466,14 @@ test "inflate reset" {...@@ -466,14 +466,14 @@ test "inflate reset" {
466 var decomp = try decompressor(testing.allocator, fib.reader(), null);466 var decomp = try decompressor(testing.allocator, fib.reader(), null);
467 defer decomp.deinit();467 defer decomp.deinit();
468468
469 var decompressed_0: []u8 = try decomp.reader()469 const decompressed_0: []u8 = try decomp.reader()
470 .readAllAlloc(testing.allocator, math.maxInt(usize));470 .readAllAlloc(testing.allocator, math.maxInt(usize));
471 defer testing.allocator.free(decompressed_0);471 defer testing.allocator.free(decompressed_0);
472472
473 fib = io.fixedBufferStream(compressed_strings[1].items);473 fib = io.fixedBufferStream(compressed_strings[1].items);
474 try decomp.reset(fib.reader(), null);474 try decomp.reset(fib.reader(), null);
475475
476 var decompressed_1: []u8 = try decomp.reader()476 const decompressed_1: []u8 = try decomp.reader()
477 .readAllAlloc(testing.allocator, math.maxInt(usize));477 .readAllAlloc(testing.allocator, math.maxInt(usize));
478 defer testing.allocator.free(decompressed_1);478 defer testing.allocator.free(decompressed_1);
479479
...@@ -513,14 +513,14 @@ test "inflate reset dictionary" {...@@ -513,14 +513,14 @@ test "inflate reset dictionary" {
513 var decomp = try decompressor(testing.allocator, fib.reader(), dict);513 var decomp = try decompressor(testing.allocator, fib.reader(), dict);
514 defer decomp.deinit();514 defer decomp.deinit();
515515
516 var decompressed_0: []u8 = try decomp.reader()516 const decompressed_0: []u8 = try decomp.reader()
517 .readAllAlloc(testing.allocator, math.maxInt(usize));517 .readAllAlloc(testing.allocator, math.maxInt(usize));
518 defer testing.allocator.free(decompressed_0);518 defer testing.allocator.free(decompressed_0);
519519
520 fib = io.fixedBufferStream(compressed_strings[1].items);520 fib = io.fixedBufferStream(compressed_strings[1].items);
521 try decomp.reset(fib.reader(), dict);521 try decomp.reset(fib.reader(), dict);
522522
523 var decompressed_1: []u8 = try decomp.reader()523 const decompressed_1: []u8 = try decomp.reader()
524 .readAllAlloc(testing.allocator, math.maxInt(usize));524 .readAllAlloc(testing.allocator, math.maxInt(usize));
525 defer testing.allocator.free(decompressed_1);525 defer testing.allocator.free(decompressed_1);
526526
lib/std/compress/deflate/decompressor.zig+25-25
...@@ -136,11 +136,11 @@ const HuffmanDecoder = struct {...@@ -136,11 +136,11 @@ const HuffmanDecoder = struct {
136136
137 self.min = min;137 self.min = min;
138 if (max > huffman_chunk_bits) {138 if (max > huffman_chunk_bits) {
139 var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));139 const num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
140 self.link_mask = @as(u32, @intCast(num_links - 1));140 self.link_mask = @as(u32, @intCast(num_links - 1));
141141
142 // create link tables142 // create link tables
143 var link = next_code[huffman_chunk_bits + 1] >> 1;143 const link = next_code[huffman_chunk_bits + 1] >> 1;
144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);
145 self.sub_chunks = ArrayList(u32).init(self.allocator);145 self.sub_chunks = ArrayList(u32).init(self.allocator);
146 self.initialized = true;146 self.initialized = true;
...@@ -148,7 +148,7 @@ const HuffmanDecoder = struct {...@@ -148,7 +148,7 @@ const HuffmanDecoder = struct {
148 while (j < huffman_num_chunks) : (j += 1) {148 while (j < huffman_num_chunks) : (j += 1) {
149 var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16)));149 var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16)));
150 reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits));150 reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits));
151 var off = j - @as(u32, @intCast(link));151 const off = j - @as(u32, @intCast(link));
152 if (sanity) {152 if (sanity) {
153 // check we are not overwriting an existing chunk153 // check we are not overwriting an existing chunk
154 assert(self.chunks[reverse] == 0);154 assert(self.chunks[reverse] == 0);
...@@ -168,9 +168,9 @@ const HuffmanDecoder = struct {...@@ -168,9 +168,9 @@ const HuffmanDecoder = struct {
168 if (n == 0) {168 if (n == 0) {
169 continue;169 continue;
170 }170 }
171 var ncode = next_code[n];171 const ncode = next_code[n];
172 next_code[n] += 1;172 next_code[n] += 1;
173 var chunk = @as(u16, @intCast((li << huffman_value_shift) | n));173 const chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
174 var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16)));174 var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16)));
175 reverse >>= @as(u4, @intCast(16 - n));175 reverse >>= @as(u4, @intCast(16 - n));
176 if (n <= huffman_chunk_bits) {176 if (n <= huffman_chunk_bits) {
...@@ -187,14 +187,14 @@ const HuffmanDecoder = struct {...@@ -187,14 +187,14 @@ const HuffmanDecoder = struct {
187 self.chunks[off] = chunk;187 self.chunks[off] = chunk;
188 }188 }
189 } else {189 } else {
190 var j = reverse & (huffman_num_chunks - 1);190 const j = reverse & (huffman_num_chunks - 1);
191 if (sanity) {191 if (sanity) {
192 // Expect an indirect chunk192 // Expect an indirect chunk
193 assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1);193 assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1);
194 // Longer codes should have been194 // Longer codes should have been
195 // associated with a link table above.195 // associated with a link table above.
196 }196 }
197 var value = self.chunks[j] >> huffman_value_shift;197 const value = self.chunks[j] >> huffman_value_shift;
198 var link_tab = self.links[value];198 var link_tab = self.links[value];
199 reverse >>= huffman_chunk_bits;199 reverse >>= huffman_chunk_bits;
200 var off = reverse;200 var off = reverse;
...@@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
354 fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self {354 fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self {
355 fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator);355 fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator);
356356
357 var bits = try allocator.create([max_num_lit + max_num_dist]u32);357 const bits = try allocator.create([max_num_lit + max_num_dist]u32);
358 var codebits = try allocator.create([num_codes]u32);358 const codebits = try allocator.create([num_codes]u32);
359359
360 var dd = ddec.DictDecoder{};360 var dd = ddec.DictDecoder{};
361 try dd.init(allocator, max_match_offset, dict);361 try dd.init(allocator, max_match_offset, dict);
...@@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
416 }416 }
417 self.final = self.b & 1 == 1;417 self.final = self.b & 1 == 1;
418 self.b >>= 1;418 self.b >>= 1;
419 var typ = self.b & 3;419 const typ = self.b & 3;
420 self.b >>= 2;420 self.b >>= 2;
421 self.nb -= 1 + 2;421 self.nb -= 1 + 2;
422 switch (typ) {422 switch (typ) {
...@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {
494 while (self.nb < 5 + 5 + 4) {494 while (self.nb < 5 + 5 + 4) {
495 try self.moreBits();495 try self.moreBits();
496 }496 }
497 var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;497 const nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
498 if (nlit > max_num_lit) {498 if (nlit > max_num_lit) {
499 corrupt_input_error_offset = self.roffset;499 corrupt_input_error_offset = self.roffset;
500 self.err = InflateError.CorruptInput;500 self.err = InflateError.CorruptInput;
501 return InflateError.CorruptInput;501 return InflateError.CorruptInput;
502 }502 }
503 self.b >>= 5;503 self.b >>= 5;
504 var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;504 const ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
505 if (ndist > max_num_dist) {505 if (ndist > max_num_dist) {
506 corrupt_input_error_offset = self.roffset;506 corrupt_input_error_offset = self.roffset;
507 self.err = InflateError.CorruptInput;507 self.err = InflateError.CorruptInput;
508 return InflateError.CorruptInput;508 return InflateError.CorruptInput;
509 }509 }
510 self.b >>= 5;510 self.b >>= 5;
511 var nclen = @as(u32, @intCast(self.b & 0xF)) + 4;511 const nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
512 // num_codes is 19, so nclen is always valid.512 // num_codes is 19, so nclen is always valid.
513 self.b >>= 4;513 self.b >>= 4;
514 self.nb -= 5 + 5 + 4;514 self.nb -= 5 + 5 + 4;
...@@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
536 // HLIT + 257 code lengths, HDIST + 1 code lengths,536 // HLIT + 257 code lengths, HDIST + 1 code lengths,
537 // using the code length Huffman code.537 // using the code length Huffman code.
538 i = 0;538 i = 0;
539 var n = nlit + ndist;539 const n = nlit + ndist;
540 while (i < n) {540 while (i < n) {
541 var x = try self.huffSym(&self.hd1);541 const x = try self.huffSym(&self.hd1);
542 if (x < 16) {542 if (x < 16) {
543 // Actual length.543 // Actual length.
544 self.bits[i] = x;544 self.bits[i] = x;
...@@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
618 switch (self.step_state) {618 switch (self.step_state) {
619 .init => {619 .init => {
620 // Read literal and/or (length, distance) according to RFC section 3.2.3.620 // Read literal and/or (length, distance) according to RFC section 3.2.3.
621 var v = try self.huffSym(self.hl.?);621 const v = try self.huffSym(self.hl.?);
622 var n: u32 = 0; // number of bits extra622 var n: u32 = 0; // number of bits extra
623 var length: u32 = 0;623 var length: u32 = 0;
624 switch (v) {624 switch (v) {
...@@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
699 switch (dist) {699 switch (dist) {
700 0...3 => dist += 1,700 0...3 => dist += 1,
701 4...max_num_dist - 1 => { // 4...29701 4...max_num_dist - 1 => { // 4...29
702 var nb = @as(u32, @intCast(dist - 2)) >> 1;702 const nb = @as(u32, @intCast(dist - 2)) >> 1;
703 // have 1 bit in bottom of dist, need nb more.703 // have 1 bit in bottom of dist, need nb more.
704 var extra = (dist & 1) << @as(u5, @intCast(nb));704 var extra = (dist & 1) << @as(u5, @intCast(nb));
705 while (self.nb < nb) {705 while (self.nb < nb) {
...@@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type {
757 self.b = 0;757 self.b = 0;
758758
759 // Length then ones-complement of length.759 // Length then ones-complement of length.
760 var nr: u32 = 4;760 const nr: u32 = 4;
761 self.inner_reader.readNoEof(self.buf[0..nr]) catch {761 self.inner_reader.readNoEof(self.buf[0..nr]) catch {
762 self.err = InflateError.UnexpectedEndOfStream;762 self.err = InflateError.UnexpectedEndOfStream;
763 return InflateError.UnexpectedEndOfStream;763 return InflateError.UnexpectedEndOfStream;
764 };764 };
765 self.roffset += @as(u64, @intCast(nr));765 self.roffset += @as(u64, @intCast(nr));
766 var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;766 const n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;767 const nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
768 if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) {768 if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) {
769 corrupt_input_error_offset = self.roffset;769 corrupt_input_error_offset = self.roffset;
770 self.err = InflateError.CorruptInput;770 self.err = InflateError.CorruptInput;
...@@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
789 buf = buf[0..self.copy_len];789 buf = buf[0..self.copy_len];
790 }790 }
791791
792 var cnt = try self.inner_reader.read(buf);792 const cnt = try self.inner_reader.read(buf);
793 if (cnt < buf.len) {793 if (cnt < buf.len) {
794 self.err = InflateError.UnexpectedEndOfStream;794 self.err = InflateError.UnexpectedEndOfStream;
795 }795 }
...@@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
819 }819 }
820820
821 fn moreBits(self: *Self) InflateError!void {821 fn moreBits(self: *Self) InflateError!void {
822 var c = self.inner_reader.readByte() catch |e| {822 const c = self.inner_reader.readByte() catch |e| {
823 if (e == error.EndOfStream) {823 if (e == error.EndOfStream) {
824 return InflateError.UnexpectedEndOfStream;824 return InflateError.UnexpectedEndOfStream;
825 }825 }
...@@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
845 var b = self.b;845 var b = self.b;
846 while (true) {846 while (true) {
847 while (nb < n) {847 while (nb < n) {
848 var c = self.inner_reader.readByte() catch |e| {848 const c = self.inner_reader.readByte() catch |e| {
849 self.b = b;849 self.b = b;
850 self.nb = nb;850 self.nb = nb;
851 if (e == error.EndOfStream) {851 if (e == error.EndOfStream) {
...@@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" {...@@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" {
1053 defer decomp.deinit();1053 defer decomp.deinit();
10541054
1055 var got: [700]u8 = undefined;1055 var got: [700]u8 = undefined;
1056 var got_len = try decomp.reader().read(&got);1056 const got_len = try decomp.reader().read(&got);
1057 try testing.expectEqual(@as(usize, 616), got_len);1057 try testing.expectEqual(@as(usize, 616), got_len);
1058 try testing.expectEqualSlices(u8, expected, got[0..expected.len]);1058 try testing.expectEqualSlices(u8, expected, got[0..expected.len]);
1059}1059}
...@@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void {...@@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void {
1117 const reader = fib.reader();1117 const reader = fib.reader();
1118 var decomp = try decompressor(allocator, reader, null);1118 var decomp = try decompressor(allocator, reader, null);
1119 defer decomp.deinit();1119 defer decomp.deinit();
1120 var output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));1120 const output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));
1121 defer std.testing.allocator.free(output);1121 defer std.testing.allocator.free(output);
1122}1122}
lib/std/compress/deflate/deflate_fast.zig+32-32
...@@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table....@@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table.
30const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;30const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;
3131
32fn load32(b: []u8, i: i32) u32 {32fn load32(b: []u8, i: i32) u32 {
33 var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];33 const s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
34 return @as(u32, @intCast(s[0])) |34 return @as(u32, @intCast(s[0])) |
35 @as(u32, @intCast(s[1])) << 8 |35 @as(u32, @intCast(s[1])) << 8 |
36 @as(u32, @intCast(s[2])) << 16 |36 @as(u32, @intCast(s[2])) << 16 |
...@@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 {...@@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 {
38}38}
3939
40fn load64(b: []u8, i: i32) u64 {40fn load64(b: []u8, i: i32) u64 {
41 var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];41 const s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
42 return @as(u64, @intCast(s[0])) |42 return @as(u64, @intCast(s[0])) |
43 @as(u64, @intCast(s[1])) << 8 |43 @as(u64, @intCast(s[1])) << 8 |
44 @as(u64, @intCast(s[2])) << 16 |44 @as(u64, @intCast(s[2])) << 16 |
...@@ -117,7 +117,7 @@ pub const DeflateFast = struct {...@@ -117,7 +117,7 @@ pub const DeflateFast = struct {
117 // s_limit is when to stop looking for offset/length copies. The input_margin117 // s_limit is when to stop looking for offset/length copies. The input_margin
118 // lets us use a fast path for emitLiteral in the main loop, while we are118 // lets us use a fast path for emitLiteral in the main loop, while we are
119 // looking for copies.119 // looking for copies.
120 var s_limit = @as(i32, @intCast(src.len - input_margin));120 const s_limit = @as(i32, @intCast(src.len - input_margin));
121121
122 // next_emit is where in src the next emitLiteral should start from.122 // next_emit is where in src the next emitLiteral should start from.
123 var next_emit: i32 = 0;123 var next_emit: i32 = 0;
...@@ -147,18 +147,18 @@ pub const DeflateFast = struct {...@@ -147,18 +147,18 @@ pub const DeflateFast = struct {
147 var candidate: TableEntry = undefined;147 var candidate: TableEntry = undefined;
148 while (true) {148 while (true) {
149 s = next_s;149 s = next_s;
150 var bytes_between_hash_lookups = skip >> 5;150 const bytes_between_hash_lookups = skip >> 5;
151 next_s = s + bytes_between_hash_lookups;151 next_s = s + bytes_between_hash_lookups;
152 skip += bytes_between_hash_lookups;152 skip += bytes_between_hash_lookups;
153 if (next_s > s_limit) {153 if (next_s > s_limit) {
154 break :outer;154 break :outer;
155 }155 }
156 candidate = self.table[next_hash & table_mask];156 candidate = self.table[next_hash & table_mask];
157 var now = load32(src, next_s);157 const now = load32(src, next_s);
158 self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv };158 self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv };
159 next_hash = hash(now);159 next_hash = hash(now);
160160
161 var offset = s - (candidate.offset - self.cur);161 const offset = s - (candidate.offset - self.cur);
162 if (offset > max_match_offset or cv != candidate.val) {162 if (offset > max_match_offset or cv != candidate.val) {
163 // Out of range or not matched.163 // Out of range or not matched.
164 cv = now;164 cv = now;
...@@ -187,8 +187,8 @@ pub const DeflateFast = struct {...@@ -187,8 +187,8 @@ pub const DeflateFast = struct {
187 // Extend the 4-byte match as long as possible.187 // Extend the 4-byte match as long as possible.
188 //188 //
189 s += 4;189 s += 4;
190 var t = candidate.offset - self.cur + 4;190 const t = candidate.offset - self.cur + 4;
191 var l = self.matchLen(s, t, src);191 const l = self.matchLen(s, t, src);
192192
193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)
194 dst[tokens_count.*] = token.matchToken(194 dst[tokens_count.*] = token.matchToken(
...@@ -209,20 +209,20 @@ pub const DeflateFast = struct {...@@ -209,20 +209,20 @@ pub const DeflateFast = struct {
209 // are faster as one load64 call (with some shifts) instead of209 // are faster as one load64 call (with some shifts) instead of
210 // three load32 calls.210 // three load32 calls.
211 var x = load64(src, s - 1);211 var x = load64(src, s - 1);
212 var prev_hash = hash(@as(u32, @truncate(x)));212 const prev_hash = hash(@as(u32, @truncate(x)));
213 self.table[prev_hash & table_mask] = TableEntry{213 self.table[prev_hash & table_mask] = TableEntry{
214 .offset = self.cur + s - 1,214 .offset = self.cur + s - 1,
215 .val = @as(u32, @truncate(x)),215 .val = @as(u32, @truncate(x)),
216 };216 };
217 x >>= 8;217 x >>= 8;
218 var curr_hash = hash(@as(u32, @truncate(x)));218 const curr_hash = hash(@as(u32, @truncate(x)));
219 candidate = self.table[curr_hash & table_mask];219 candidate = self.table[curr_hash & table_mask];
220 self.table[curr_hash & table_mask] = TableEntry{220 self.table[curr_hash & table_mask] = TableEntry{
221 .offset = self.cur + s,221 .offset = self.cur + s,
222 .val = @as(u32, @truncate(x)),222 .val = @as(u32, @truncate(x)),
223 };223 };
224224
225 var offset = s - (candidate.offset - self.cur);225 const offset = s - (candidate.offset - self.cur);
226 if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) {226 if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) {
227 cv = @as(u32, @truncate(x >> 8));227 cv = @as(u32, @truncate(x >> 8));
228 next_hash = hash(cv);228 next_hash = hash(cv);
...@@ -261,7 +261,7 @@ pub const DeflateFast = struct {...@@ -261,7 +261,7 @@ pub const DeflateFast = struct {
261 // If we are inside the current block261 // If we are inside the current block
262 if (t >= 0) {262 if (t >= 0) {
263 var b = src[@as(usize, @intCast(t))..];263 var b = src[@as(usize, @intCast(t))..];
264 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];264 const a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
265 b = b[0..a.len];265 b = b[0..a.len];
266 // Extend the match to be as long as possible.266 // Extend the match to be as long as possible.
267 for (a, 0..) |_, i| {267 for (a, 0..) |_, i| {
...@@ -273,7 +273,7 @@ pub const DeflateFast = struct {...@@ -273,7 +273,7 @@ pub const DeflateFast = struct {
273 }273 }
274274
275 // We found a match in the previous block.275 // We found a match in the previous block.
276 var tp = @as(i32, @intCast(self.prev_len)) + t;276 const tp = @as(i32, @intCast(self.prev_len)) + t;
277 if (tp < 0) {277 if (tp < 0) {
278 return 0;278 return 0;
279 }279 }
...@@ -293,7 +293,7 @@ pub const DeflateFast = struct {...@@ -293,7 +293,7 @@ pub const DeflateFast = struct {
293293
294 // If we reached our limit, we matched everything we are294 // If we reached our limit, we matched everything we are
295 // allowed to in the previous block and we return.295 // allowed to in the previous block and we return.
296 var n = @as(i32, @intCast(b.len));296 const n = @as(i32, @intCast(b.len));
297 if (@as(u32, @intCast(s + n)) == s1) {297 if (@as(u32, @intCast(s + n)) == s1) {
298 return n;298 return n;
299 }299 }
...@@ -366,7 +366,7 @@ test "best speed match 1/3" {...@@ -366,7 +366,7 @@ test "best speed match 1/3" {
366 .cur = 0,366 .cur = 0,
367 };367 };
368 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };368 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };
369 var got: i32 = e.matchLen(3, -3, &current);369 const got: i32 = e.matchLen(3, -3, &current);
370 try expectEqual(@as(i32, 6), got);370 try expectEqual(@as(i32, 6), got);
371 }371 }
372 {372 {
...@@ -379,7 +379,7 @@ test "best speed match 1/3" {...@@ -379,7 +379,7 @@ test "best speed match 1/3" {
379 .cur = 0,379 .cur = 0,
380 };380 };
381 var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 };381 var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 };
382 var got: i32 = e.matchLen(3, -3, &current);382 const got: i32 = e.matchLen(3, -3, &current);
383 try expectEqual(@as(i32, 3), got);383 try expectEqual(@as(i32, 3), got);
384 }384 }
385 {385 {
...@@ -392,7 +392,7 @@ test "best speed match 1/3" {...@@ -392,7 +392,7 @@ test "best speed match 1/3" {
392 .cur = 0,392 .cur = 0,
393 };393 };
394 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };394 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };
395 var got: i32 = e.matchLen(3, -3, &current);395 const got: i32 = e.matchLen(3, -3, &current);
396 try expectEqual(@as(i32, 2), got);396 try expectEqual(@as(i32, 2), got);
397 }397 }
398 {398 {
...@@ -405,7 +405,7 @@ test "best speed match 1/3" {...@@ -405,7 +405,7 @@ test "best speed match 1/3" {
405 .cur = 0,405 .cur = 0,
406 };406 };
407 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };407 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
408 var got: i32 = e.matchLen(0, -1, &current);408 const got: i32 = e.matchLen(0, -1, &current);
409 try expectEqual(@as(i32, 4), got);409 try expectEqual(@as(i32, 4), got);
410 }410 }
411 {411 {
...@@ -418,7 +418,7 @@ test "best speed match 1/3" {...@@ -418,7 +418,7 @@ test "best speed match 1/3" {
418 .cur = 0,418 .cur = 0,
419 };419 };
420 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };420 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
421 var got: i32 = e.matchLen(4, -7, &current);421 const got: i32 = e.matchLen(4, -7, &current);
422 try expectEqual(@as(i32, 5), got);422 try expectEqual(@as(i32, 5), got);
423 }423 }
424 {424 {
...@@ -431,7 +431,7 @@ test "best speed match 1/3" {...@@ -431,7 +431,7 @@ test "best speed match 1/3" {
431 .cur = 0,431 .cur = 0,
432 };432 };
433 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };433 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
434 var got: i32 = e.matchLen(0, -1, &current);434 const got: i32 = e.matchLen(0, -1, &current);
435 try expectEqual(@as(i32, 0), got);435 try expectEqual(@as(i32, 0), got);
436 }436 }
437 {437 {
...@@ -444,7 +444,7 @@ test "best speed match 1/3" {...@@ -444,7 +444,7 @@ test "best speed match 1/3" {
444 .cur = 0,444 .cur = 0,
445 };445 };
446 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };446 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
447 var got: i32 = e.matchLen(1, 0, &current);447 const got: i32 = e.matchLen(1, 0, &current);
448 try expectEqual(@as(i32, 0), got);448 try expectEqual(@as(i32, 0), got);
449 }449 }
450}450}
...@@ -462,7 +462,7 @@ test "best speed match 2/3" {...@@ -462,7 +462,7 @@ test "best speed match 2/3" {
462 .cur = 0,462 .cur = 0,
463 };463 };
464 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };464 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
465 var got: i32 = e.matchLen(1, -5, &current);465 const got: i32 = e.matchLen(1, -5, &current);
466 try expectEqual(@as(i32, 0), got);466 try expectEqual(@as(i32, 0), got);
467 }467 }
468 {468 {
...@@ -475,7 +475,7 @@ test "best speed match 2/3" {...@@ -475,7 +475,7 @@ test "best speed match 2/3" {
475 .cur = 0,475 .cur = 0,
476 };476 };
477 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };477 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
478 var got: i32 = e.matchLen(1, -1, &current);478 const got: i32 = e.matchLen(1, -1, &current);
479 try expectEqual(@as(i32, 0), got);479 try expectEqual(@as(i32, 0), got);
480 }480 }
481 {481 {
...@@ -488,7 +488,7 @@ test "best speed match 2/3" {...@@ -488,7 +488,7 @@ test "best speed match 2/3" {
488 .cur = 0,488 .cur = 0,
489 };489 };
490 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };490 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
491 var got: i32 = e.matchLen(1, 0, &current);491 const got: i32 = e.matchLen(1, 0, &current);
492 try expectEqual(@as(i32, 3), got);492 try expectEqual(@as(i32, 3), got);
493 }493 }
494 {494 {
...@@ -501,7 +501,7 @@ test "best speed match 2/3" {...@@ -501,7 +501,7 @@ test "best speed match 2/3" {
501 .cur = 0,501 .cur = 0,
502 };502 };
503 var current = [_]u8{ 3, 4, 5 };503 var current = [_]u8{ 3, 4, 5 };
504 var got: i32 = e.matchLen(0, -3, &current);504 const got: i32 = e.matchLen(0, -3, &current);
505 try expectEqual(@as(i32, 3), got);505 try expectEqual(@as(i32, 3), got);
506 }506 }
507}507}
...@@ -564,11 +564,11 @@ test "best speed match 2/2" {...@@ -564,11 +564,11 @@ test "best speed match 2/2" {
564 };564 };
565565
566 for (cases) |c| {566 for (cases) |c| {
567 var previous = try testing.allocator.alloc(u8, c.previous);567 const previous = try testing.allocator.alloc(u8, c.previous);
568 defer testing.allocator.free(previous);568 defer testing.allocator.free(previous);
569 @memset(previous, 0);569 @memset(previous, 0);
570570
571 var current = try testing.allocator.alloc(u8, c.current);571 const current = try testing.allocator.alloc(u8, c.current);
572 defer testing.allocator.free(current);572 defer testing.allocator.free(current);
573 @memset(current, 0);573 @memset(current, 0);
574574
...@@ -579,7 +579,7 @@ test "best speed match 2/2" {...@@ -579,7 +579,7 @@ test "best speed match 2/2" {
579 .allocator = undefined,579 .allocator = undefined,
580 .cur = 0,580 .cur = 0,
581 };581 };
582 var got: i32 = e.matchLen(c.s, c.t, current);582 const got: i32 = e.matchLen(c.s, c.t, current);
583 try expectEqual(@as(i32, c.expected), got);583 try expectEqual(@as(i32, c.expected), got);
584 }584 }
585}585}
...@@ -609,10 +609,10 @@ test "best speed shift offsets" {...@@ -609,10 +609,10 @@ test "best speed shift offsets" {
609 // Second part should pick up matches from the first block.609 // Second part should pick up matches from the first block.
610 tokens_count = 0;610 tokens_count = 0;
611 enc.encode(&tokens, &tokens_count, &test_data);611 enc.encode(&tokens, &tokens_count, &test_data);
612 var want_first_tokens = tokens_count;612 const want_first_tokens = tokens_count;
613 tokens_count = 0;613 tokens_count = 0;
614 enc.encode(&tokens, &tokens_count, &test_data);614 enc.encode(&tokens, &tokens_count, &test_data);
615 var want_second_tokens = tokens_count;615 const want_second_tokens = tokens_count;
616616
617 try expect(want_first_tokens > want_second_tokens);617 try expect(want_first_tokens > want_second_tokens);
618618
...@@ -657,7 +657,7 @@ test "best speed reset" {...@@ -657,7 +657,7 @@ test "best speed reset" {
657 const ArrayList = std.ArrayList;657 const ArrayList = std.ArrayList;
658658
659 const input_size = 65536;659 const input_size = 65536;
660 var input = try testing.allocator.alloc(u8, input_size);660 const input = try testing.allocator.alloc(u8, input_size);
661 defer testing.allocator.free(input);661 defer testing.allocator.free(input);
662662
663 var i: usize = 0;663 var i: usize = 0;
...@@ -699,7 +699,7 @@ test "best speed reset" {...@@ -699,7 +699,7 @@ test "best speed reset" {
699 // Reset until we are right before the wraparound.699 // Reset until we are right before the wraparound.
700 // Each reset adds max_match_offset to the offset.700 // Each reset adds max_match_offset to the offset.
701 i = 0;701 i = 0;
702 var limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset;702 const limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset;
703 while (i < limit) : (i += 1) {703 while (i < limit) : (i += 1) {
704 // skip ahead to where we are close to wrap around...704 // skip ahead to where we are close to wrap around...
705 comp.reset(discard.writer());705 comp.reset(discard.writer());
lib/std/compress/deflate/deflate_fast_test.zig+9-9
...@@ -39,18 +39,18 @@ test "best speed" {...@@ -39,18 +39,18 @@ test "best speed" {
39 var tc_15 = [_]u32{ 65536, 129 };39 var tc_15 = [_]u32{ 65536, 129 };
40 var tc_16 = [_]u32{ 65536, 65536, 256 };40 var tc_16 = [_]u32{ 65536, 65536, 256 };
41 var tc_17 = [_]u32{ 65536, 65536, 65536 };41 var tc_17 = [_]u32{ 65536, 65536, 65536 };
42 var test_cases = [_][]u32{42 const test_cases = [_][]u32{
43 &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10,43 &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10,
44 &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17,44 &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17,
45 };45 };
4646
47 for (test_cases) |tc| {47 for (test_cases) |tc| {
48 var firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 };48 const firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 };
4949
50 for (firsts) |first_n| {50 for (firsts) |first_n| {
51 tc[0] = first_n;51 tc[0] = first_n;
5252
53 var to_flush = [_]bool{ false, true };53 const to_flush = [_]bool{ false, true };
54 for (to_flush) |flush| {54 for (to_flush) |flush| {
55 var compressed = ArrayList(u8).init(testing.allocator);55 var compressed = ArrayList(u8).init(testing.allocator);
56 defer compressed.deinit();56 defer compressed.deinit();
...@@ -75,14 +75,14 @@ test "best speed" {...@@ -75,14 +75,14 @@ test "best speed" {
7575
76 try comp.close();76 try comp.close();
7777
78 var decompressed = try testing.allocator.alloc(u8, want.items.len);78 const decompressed = try testing.allocator.alloc(u8, want.items.len);
79 defer testing.allocator.free(decompressed);79 defer testing.allocator.free(decompressed);
8080
81 var fib = io.fixedBufferStream(compressed.items);81 var fib = io.fixedBufferStream(compressed.items);
82 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);82 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
83 defer decomp.deinit();83 defer decomp.deinit();
8484
85 var read = try decomp.reader().readAll(decompressed);85 const read = try decomp.reader().readAll(decompressed);
86 _ = decomp.close();86 _ = decomp.close();
8787
88 try testing.expectEqual(want.items.len, read);88 try testing.expectEqual(want.items.len, read);
...@@ -109,7 +109,7 @@ test "best speed max match offset" {...@@ -109,7 +109,7 @@ test "best speed max match offset" {
109 for (extras) |extra| {109 for (extras) |extra| {
110 var offset_adj: i32 = -5;110 var offset_adj: i32 = -5;
111 while (offset_adj <= 5) : (offset_adj += 1) {111 while (offset_adj <= 5) : (offset_adj += 1) {
112 var offset = deflate_const.max_match_offset + offset_adj;112 const offset = deflate_const.max_match_offset + offset_adj;
113113
114 // Make src to be a []u8 of the form114 // Make src to be a []u8 of the form
115 // fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1})115 // fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1})
...@@ -119,7 +119,7 @@ test "best speed max match offset" {...@@ -119,7 +119,7 @@ test "best speed max match offset" {
119 // zeros1 is between 0 and 30 zeros.119 // zeros1 is between 0 and 30 zeros.
120 // The difference between the two abc's will be offset, which120 // The difference between the two abc's will be offset, which
121 // is max_match_offset plus or minus a small adjustment.121 // is max_match_offset plus or minus a small adjustment.
122 var src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));122 const src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));
123 var src = try testing.allocator.alloc(u8, src_len);123 var src = try testing.allocator.alloc(u8, src_len);
124 defer testing.allocator.free(src);124 defer testing.allocator.free(src);
125125
...@@ -143,13 +143,13 @@ test "best speed max match offset" {...@@ -143,13 +143,13 @@ test "best speed max match offset" {
143 try comp.writer().writeAll(src);143 try comp.writer().writeAll(src);
144 _ = try comp.close();144 _ = try comp.close();
145145
146 var decompressed = try testing.allocator.alloc(u8, src.len);146 const decompressed = try testing.allocator.alloc(u8, src.len);
147 defer testing.allocator.free(decompressed);147 defer testing.allocator.free(decompressed);
148148
149 var fib = io.fixedBufferStream(compressed.items);149 var fib = io.fixedBufferStream(compressed.items);
150 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);150 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
151 defer decomp.deinit();151 defer decomp.deinit();
152 var read = try decomp.reader().readAll(decompressed);152 const read = try decomp.reader().readAll(decompressed);
153 _ = decomp.close();153 _ = decomp.close();
154154
155 try testing.expectEqual(src.len, read);155 try testing.expectEqual(src.len, read);
lib/std/compress/deflate/dict_decoder.zig+7-7
...@@ -123,7 +123,7 @@ pub const DictDecoder = struct {...@@ -123,7 +123,7 @@ pub const DictDecoder = struct {
123 // This invariant must be kept: 0 < dist <= histSize()123 // This invariant must be kept: 0 < dist <= histSize()
124 pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 {124 pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 {
125 assert(0 < dist and dist <= self.histSize());125 assert(0 < dist and dist <= self.histSize());
126 var dst_base = self.wr_pos;126 const dst_base = self.wr_pos;
127 var dst_pos = dst_base;127 var dst_pos = dst_base;
128 var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist));128 var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist));
129 var end_pos = dst_pos + length;129 var end_pos = dst_pos + length;
...@@ -175,12 +175,12 @@ pub const DictDecoder = struct {...@@ -175,12 +175,12 @@ pub const DictDecoder = struct {
175 // This invariant must be kept: 0 < dist <= histSize()175 // This invariant must be kept: 0 < dist <= histSize()
176 pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 {176 pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 {
177 var dst_pos = self.wr_pos;177 var dst_pos = self.wr_pos;
178 var end_pos = dst_pos + length;178 const end_pos = dst_pos + length;
179 if (dst_pos < dist or end_pos > self.hist.len) {179 if (dst_pos < dist or end_pos > self.hist.len) {
180 return 0;180 return 0;
181 }181 }
182 var dst_base = dst_pos;182 const dst_base = dst_pos;
183 var src_pos = dst_pos - dist;183 const src_pos = dst_pos - dist;
184184
185 // Copy possibly overlapping section before destination position.185 // Copy possibly overlapping section before destination position.
186 while (dst_pos < end_pos) {186 while (dst_pos < end_pos) {
...@@ -195,7 +195,7 @@ pub const DictDecoder = struct {...@@ -195,7 +195,7 @@ pub const DictDecoder = struct {
195 // emitted to the user. The data returned by readFlush must be fully consumed195 // emitted to the user. The data returned by readFlush must be fully consumed
196 // before calling any other DictDecoder methods.196 // before calling any other DictDecoder methods.
197 pub fn readFlush(self: *Self) []u8 {197 pub fn readFlush(self: *Self) []u8 {
198 var to_read = self.hist[self.rd_pos..self.wr_pos];198 const to_read = self.hist[self.rd_pos..self.wr_pos];
199 self.rd_pos = self.wr_pos;199 self.rd_pos = self.wr_pos;
200 if (self.wr_pos == self.hist.len) {200 if (self.wr_pos == self.hist.len) {
201 self.wr_pos = 0;201 self.wr_pos = 0;
...@@ -279,7 +279,7 @@ test "dictionary decoder" {...@@ -279,7 +279,7 @@ test "dictionary decoder" {
279 length: u32, // Length of copy or insertion279 length: u32, // Length of copy or insertion
280 };280 };
281281
282 var poem_refs = [_]PoemRefs{282 const poem_refs = [_]PoemRefs{
283 .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 },283 .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 },
284 .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 },284 .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 },
285 .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 },285 .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 },
...@@ -368,7 +368,7 @@ test "dictionary decoder" {...@@ -368,7 +368,7 @@ test "dictionary decoder" {
368 fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void {368 fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void {
369 var string = str;369 var string = str;
370 while (string.len > 0) {370 while (string.len > 0) {
371 var cnt = DictDecoder.copy(dst_dd.writeSlice(), string);371 const cnt = DictDecoder.copy(dst_dd.writeSlice(), string);
372 dst_dd.writeMark(cnt);372 dst_dd.writeMark(cnt);
373 string = string[cnt..];373 string = string[cnt..];
374 if (dst_dd.availWrite() == 0) {374 if (dst_dd.availWrite() == 0) {
lib/std/compress/deflate/huffman_bit_writer.zig+43-43
...@@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
134 self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits));134 self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits));
135 self.nbits += nb;135 self.nbits += nb;
136 if (self.nbits >= 48) {136 if (self.nbits >= 48) {
137 var bits = self.bits;137 const bits = self.bits;
138 self.bits >>= 48;138 self.bits >>= 48;
139 self.nbits -= 48;139 self.nbits -= 48;
140 var n = self.nbytes;140 var n = self.nbytes;
...@@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
224 while (size != bad_code) : (in_index += 1) {224 while (size != bad_code) : (in_index += 1) {
225 // INVARIANT: We have seen "count" copies of size that have not yet225 // INVARIANT: We have seen "count" copies of size that have not yet
226 // had output generated for them.226 // had output generated for them.
227 var next_size = codegen[in_index];227 const next_size = codegen[in_index];
228 if (next_size == size) {228 if (next_size == size) {
229 count += 1;229 count += 1;
230 continue;230 continue;
...@@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
295 while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) {295 while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) {
296 num_codegens -= 1;296 num_codegens -= 1;
297 }297 }
298 var header = 3 + 5 + 5 + 4 + (3 * num_codegens) +298 const header = 3 + 5 + 5 + 4 + (3 * num_codegens) +
299 self.codegen_encoding.bitLength(self.codegen_freq[0..]) +299 self.codegen_encoding.bitLength(self.codegen_freq[0..]) +
300 self.codegen_freq[16] * 2 +300 self.codegen_freq[16] * 2 +
301 self.codegen_freq[17] * 3 +301 self.codegen_freq[17] * 3 +
302 self.codegen_freq[18] * 7;302 self.codegen_freq[18] * 7;
303 var size = header +303 const size = header +
304 lit_enc.bitLength(self.literal_freq) +304 lit_enc.bitLength(self.literal_freq) +
305 off_enc.bitLength(self.offset_freq) +305 off_enc.bitLength(self.offset_freq) +
306 extra_bits;306 extra_bits;
...@@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
339 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));339 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
340 self.nbits += @as(u32, @intCast(c.len));340 self.nbits += @as(u32, @intCast(c.len));
341 if (self.nbits >= 48) {341 if (self.nbits >= 48) {
342 var bits = self.bits;342 const bits = self.bits;
343 self.bits >>= 48;343 self.bits >>= 48;
344 self.nbits -= 48;344 self.nbits -= 48;
345 var n = self.nbytes;345 var n = self.nbytes;
...@@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
386386
387 var i: u32 = 0;387 var i: u32 = 0;
388 while (i < num_codegens) : (i += 1) {388 while (i < num_codegens) : (i += 1) {
389 var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));389 const value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
390 try self.writeBits(@as(u32, @intCast(value)), 3);390 try self.writeBits(@as(u32, @intCast(value)), 3);
391 }391 }
392392
393 i = 0;393 i = 0;
394 while (true) {394 while (true) {
395 var code_word: u32 = @as(u32, @intCast(self.codegen[i]));395 const code_word: u32 = @as(u32, @intCast(self.codegen[i]));
396 i += 1;396 i += 1;
397 if (code_word == bad_code) {397 if (code_word == bad_code) {
398 break;398 break;
...@@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
458 return;458 return;
459 }459 }
460460
461 var lit_and_off = self.indexTokens(tokens);461 const lit_and_off = self.indexTokens(tokens);
462 var num_literals = lit_and_off.num_literals;462 const num_literals = lit_and_off.num_literals;
463 var num_offsets = lit_and_off.num_offsets;463 const num_offsets = lit_and_off.num_offsets;
464464
465 var extra_bits: u32 = 0;465 var extra_bits: u32 = 0;
466 var ret = storedSizeFits(input);466 const ret = storedSizeFits(input);
467 var stored_size = ret.size;467 const stored_size = ret.size;
468 var storable = ret.storable;468 const storable = ret.storable;
469469
470 if (storable) {470 if (storable) {
471 // We only bother calculating the costs of the extra bits required by471 // We only bother calculating the costs of the extra bits required by
...@@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
504 &self.offset_encoding,504 &self.offset_encoding,
505 );505 );
506 self.codegen_encoding.generate(self.codegen_freq[0..], 7);506 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
507 var dynamic_size = self.dynamicSize(507 const dynamic_size = self.dynamicSize(
508 &self.literal_encoding,508 &self.literal_encoding,
509 &self.offset_encoding,509 &self.offset_encoding,
510 extra_bits,510 extra_bits,
511 );511 );
512 var dyn_size = dynamic_size.size;512 const dyn_size = dynamic_size.size;
513 num_codegens = dynamic_size.num_codegens;513 num_codegens = dynamic_size.num_codegens;
514514
515 if (dyn_size < size) {515 if (dyn_size < size) {
...@@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
551 return;551 return;
552 }552 }
553553
554 var total_tokens = self.indexTokens(tokens);554 const total_tokens = self.indexTokens(tokens);
555 var num_literals = total_tokens.num_literals;555 const num_literals = total_tokens.num_literals;
556 var num_offsets = total_tokens.num_offsets;556 const num_offsets = total_tokens.num_offsets;
557557
558 // Generate codegen and codegenFrequencies, which indicates how to encode558 // Generate codegen and codegenFrequencies, which indicates how to encode
559 // the literal_encoding and the offset_encoding.559 // the literal_encoding and the offset_encoding.
...@@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
564 &self.offset_encoding,564 &self.offset_encoding,
565 );565 );
566 self.codegen_encoding.generate(self.codegen_freq[0..], 7);566 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
567 var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0);567 const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0);
568 var size = dynamic_size.size;568 const size = dynamic_size.size;
569 var num_codegens = dynamic_size.num_codegens;569 const num_codegens = dynamic_size.num_codegens;
570570
571 // Store bytes, if we don't get a reasonable improvement.571 // Store bytes, if we don't get a reasonable improvement.
572572
573 var stored_size = storedSizeFits(input);573 const stored_size = storedSizeFits(input);
574 var ssize = stored_size.size;574 const ssize = stored_size.size;
575 var storable = stored_size.storable;575 const storable = stored_size.storable;
576 if (storable and ssize < (size + (size >> 4))) {576 if (storable and ssize < (size + (size >> 4))) {
577 try self.writeStoredHeader(input.?.len, eof);577 try self.writeStoredHeader(input.?.len, eof);
578 try self.writeBytes(input.?);578 try self.writeBytes(input.?);
...@@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
611 self.literal_freq[token.literal(t)] += 1;611 self.literal_freq[token.literal(t)] += 1;
612 continue;612 continue;
613 }613 }
614 var length = token.length(t);614 const length = token.length(t);
615 var offset = token.offset(t);615 const offset = token.offset(t);
616 self.literal_freq[length_codes_start + token.lengthCode(length)] += 1;616 self.literal_freq[length_codes_start + token.lengthCode(length)] += 1;
617 self.offset_freq[token.offsetCode(offset)] += 1;617 self.offset_freq[token.offsetCode(offset)] += 1;
618 }618 }
...@@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
660 continue;660 continue;
661 }661 }
662 // Write the length662 // Write the length
663 var length = token.length(t);663 const length = token.length(t);
664 var length_code = token.lengthCode(length);664 const length_code = token.lengthCode(length);
665 try self.writeCode(le_codes[length_code + length_codes_start]);665 try self.writeCode(le_codes[length_code + length_codes_start]);
666 var extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));666 const extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));
667 if (extra_length_bits > 0) {667 if (extra_length_bits > 0) {
668 var extra_length = @as(u32, @intCast(length - length_base[length_code]));668 const extra_length = @as(u32, @intCast(length - length_base[length_code]));
669 try self.writeBits(extra_length, extra_length_bits);669 try self.writeBits(extra_length, extra_length_bits);
670 }670 }
671 // Write the offset671 // Write the offset
672 var offset = token.offset(t);672 const offset = token.offset(t);
673 var offset_code = token.offsetCode(offset);673 const offset_code = token.offsetCode(offset);
674 try self.writeCode(oe_codes[offset_code]);674 try self.writeCode(oe_codes[offset_code]);
675 var extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));675 const extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));
676 if (extra_offset_bits > 0) {676 if (extra_offset_bits > 0) {
677 var extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));677 const extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));
678 try self.writeBits(extra_offset, extra_offset_bits);678 try self.writeBits(extra_offset, extra_offset_bits);
679 }679 }
680 }680 }
...@@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
718 &self.huff_offset,718 &self.huff_offset,
719 );719 );
720 self.codegen_encoding.generate(self.codegen_freq[0..], 7);720 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
721 var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0);721 const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0);
722 var size = dynamic_size.size;722 const size = dynamic_size.size;
723 num_codegens = dynamic_size.num_codegens;723 num_codegens = dynamic_size.num_codegens;
724724
725 // Store bytes, if we don't get a reasonable improvement.725 // Store bytes, if we don't get a reasonable improvement.
726726
727 var stored_size_ret = storedSizeFits(input);727 const stored_size_ret = storedSizeFits(input);
728 var ssize = stored_size_ret.size;728 const ssize = stored_size_ret.size;
729 var storable = stored_size_ret.storable;729 const storable = stored_size_ret.storable;
730730
731 if (storable and ssize < (size + (size >> 4))) {731 if (storable and ssize < (size + (size >> 4))) {
732 try self.writeStoredHeader(input.len, eof);732 try self.writeStoredHeader(input.len, eof);
...@@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {...@@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
736736
737 // Huffman.737 // Huffman.
738 try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof);738 try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof);
739 var encoding = self.literal_encoding.codes[0..257];739 const encoding = self.literal_encoding.codes[0..257];
740 var n = self.nbytes;740 var n = self.nbytes;
741 for (input) |t| {741 for (input) |t| {
742 // Bitwriting inlined, ~30% speedup742 // Bitwriting inlined, ~30% speedup
743 var c = encoding[t];743 const c = encoding[t];
744 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));744 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
745 self.nbits += @as(u32, @intCast(c.len));745 self.nbits += @as(u32, @intCast(c.len));
746 if (self.nbits < 48) {746 if (self.nbits < 48) {
747 continue;747 continue;
748 }748 }
749 // Store 6 bytes749 // Store 6 bytes
750 var bits = self.bits;750 const bits = self.bits;
751 self.bits >>= 48;751 self.bits >>= 48;
752 self.nbits -= 48;752 self.nbits -= 48;
753 var bytes = self.bytes[n..][0..6];753 var bytes = self.bytes[n..][0..6];
...@@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const...@@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const
16791679
1680 try bw.flush();1680 try bw.flush();
16811681
1682 var b = buf.items;1682 const b = buf.items;
1683 try expect(b.len > 0);1683 try expect(b.len > 0);
1684 try expect(b[0] & 1 == 1);1684 try expect(b[0] & 1 == 1);
1685}1685}
lib/std/compress/deflate/huffman_code.zig+8-8
...@@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct {...@@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct {
96 mem.sort(LiteralNode, self.lfs, {}, byFreq);96 mem.sort(LiteralNode, self.lfs, {}, byFreq);
9797
98 // Get the number of literals for each bit count98 // Get the number of literals for each bit count
99 var bit_count = self.bitCounts(list, max_bits);99 const bit_count = self.bitCounts(list, max_bits);
100 // And do the assignment100 // And do the assignment
101 self.assignEncodingAndSize(bit_count, list);101 self.assignEncodingAndSize(bit_count, list);
102 }102 }
...@@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct {...@@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct {
128 // that should be encoded in i bits.128 // that should be encoded in i bits.
129 fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 {129 fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 {
130 var max_bits = max_bits_to_use;130 var max_bits = max_bits_to_use;
131 var n = list.len;131 const n = list.len;
132132
133 assert(max_bits < max_bits_limit);133 assert(max_bits < max_bits_limit);
134134
...@@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct {...@@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct {
184 continue;184 continue;
185 }185 }
186186
187 var prev_freq = l.last_freq;187 const prev_freq = l.last_freq;
188 if (l.next_char_freq < l.next_pair_freq) {188 if (l.next_char_freq < l.next_pair_freq) {
189 // The next item on this row is a leaf node.189 // The next item on this row is a leaf node.
190 var next = leaf_counts[level][level] + 1;190 const next = leaf_counts[level][level] + 1;
191 l.last_freq = l.next_char_freq;191 l.last_freq = l.next_char_freq;
192 // Lower leaf_counts are the same of the previous node.192 // Lower leaf_counts are the same of the previous node.
193 leaf_counts[level][level] = next;193 leaf_counts[level][level] = next;
...@@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct {...@@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct {
236236
237 var bit_count = self.bit_count[0 .. max_bits + 1];237 var bit_count = self.bit_count[0 .. max_bits + 1];
238 var bits: u32 = 1;238 var bits: u32 = 1;
239 var counts = &leaf_counts[max_bits];239 const counts = &leaf_counts[max_bits];
240 {240 {
241 var level = max_bits;241 var level = max_bits;
242 while (level > 0) : (level -= 1) {242 while (level > 0) : (level -= 1) {
...@@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct {...@@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct {
267 // are encoded using "bits" bits, and get the values267 // are encoded using "bits" bits, and get the values
268 // code, code + 1, .... The code values are268 // code, code + 1, .... The code values are
269 // assigned in literal order (not frequency order).269 // assigned in literal order (not frequency order).
270 var chunk = list[list.len - @as(u32, @intCast(bits)) ..];270 const chunk = list[list.len - @as(u32, @intCast(bits)) ..];
271271
272 self.lns = chunk;272 self.lns = chunk;
273 mem.sort(LiteralNode, self.lns, {}, byLiteral);273 mem.sort(LiteralNode, self.lns, {}, byLiteral);
...@@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder {...@@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder {
303303
304// Generates a HuffmanCode corresponding to the fixed literal table304// Generates a HuffmanCode corresponding to the fixed literal table
305pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {305pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
306 var h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies);306 const h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies);
307 var codes = h.codes;307 var codes = h.codes;
308 var ch: u16 = 0;308 var ch: u16 = 0;
309309
...@@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {...@@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
338}338}
339339
340pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {340pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {
341 var h = try newHuffmanEncoder(allocator, 30);341 const h = try newHuffmanEncoder(allocator, 30);
342 var codes = h.codes;342 var codes = h.codes;
343 for (codes, 0..) |_, ch| {343 for (codes, 0..) |_, ch| {
344 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 };344 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 };
lib/std/compress/zstandard.zig+1-1
...@@ -268,7 +268,7 @@ test "zstandard decompression" {...@@ -268,7 +268,7 @@ test "zstandard decompression" {
268 const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3");268 const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3");
269 const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19");269 const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19");
270270
271 var buffer = try std.testing.allocator.alloc(u8, uncompressed.len);271 const buffer = try std.testing.allocator.alloc(u8, uncompressed.len);
272 defer std.testing.allocator.free(buffer);272 defer std.testing.allocator.free(buffer);
273273
274 const res3 = try decompress.decode(buffer, compressed3, true);274 const res3 = try decompress.decode(buffer, compressed3, true);
lib/std/compress/zstandard/decode/huffman.zig+1-1
...@@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: *...@@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: *
5454
55 const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse55 const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse
56 return error.MalformedHuffmanTree;56 return error.MalformedHuffmanTree;
57 var huff_data = src[start_index..compressed_size];57 const huff_data = src[start_index..compressed_size];
58 var huff_bits: readers.ReverseBitReader = undefined;58 var huff_bits: readers.ReverseBitReader = undefined;
59 huff_bits.init(huff_data) catch return error.MalformedHuffmanTree;59 huff_bits.init(huff_data) catch return error.MalformedHuffmanTree;
6060
lib/std/compress/zstandard/decompress.zig+2-2
...@@ -304,7 +304,7 @@ pub fn decodeZstandardFrame(...@@ -304,7 +304,7 @@ pub fn decodeZstandardFrame(
304304
305 var frame_context = context: {305 var frame_context = context: {
306 var fbs = std.io.fixedBufferStream(src[consumed_count..]);306 var fbs = std.io.fixedBufferStream(src[consumed_count..]);
307 var source = fbs.reader();307 const source = fbs.reader();
308 const frame_header = try decodeZstandardHeader(source);308 const frame_header = try decodeZstandardHeader(source);
309 consumed_count += fbs.pos;309 consumed_count += fbs.pos;
310 break :context FrameContext.init(310 break :context FrameContext.init(
...@@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList(...@@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList(
447447
448 var frame_context = context: {448 var frame_context = context: {
449 var fbs = std.io.fixedBufferStream(src[consumed_count..]);449 var fbs = std.io.fixedBufferStream(src[consumed_count..]);
450 var source = fbs.reader();450 const source = fbs.reader();
451 const frame_header = try decodeZstandardHeader(source);451 const frame_header = try decodeZstandardHeader(source);
452 consumed_count += fbs.pos;452 consumed_count += fbs.pos;
453 break :context try FrameContext.init(frame_header, window_size_max, verify_checksum);453 break :context try FrameContext.init(frame_header, window_size_max, verify_checksum);
lib/std/crypto/25519/curve25519.zig+1-1
...@@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" {...@@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" {
129 const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e";129 const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e";
130 var sk: [32]u8 = undefined;130 var sk: [32]u8 = undefined;
131 _ = std.fmt.hexToBytes(&sk, skh) catch unreachable;131 _ = std.fmt.hexToBytes(&sk, skh) catch unreachable;
132 var edp = try crypto.ecc.Edwards25519.basePoint.mul(sk);132 const edp = try crypto.ecc.Edwards25519.basePoint.mul(sk);
133 const xp = try Curve25519.fromEdwards25519(edp);133 const xp = try Curve25519.fromEdwards25519(edp);
134 const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378";134 const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378";
135 var expected: [32]u8 = undefined;135 var expected: [32]u8 = undefined;
lib/std/crypto/25519/field.zig+1-1
...@@ -416,7 +416,7 @@ pub const Fe = struct {...@@ -416,7 +416,7 @@ pub const Fe = struct {
416416
417 /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square417 /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square
418 pub fn sqrt(x2: Fe) NotSquareError!Fe {418 pub fn sqrt(x2: Fe) NotSquareError!Fe {
419 var x2_copy = x2;419 const x2_copy = x2;
420 const x = x2.uncheckedSqrt();420 const x = x2.uncheckedSqrt();
421 const check = x.sq().sub(x2_copy);421 const check = x.sq().sub(x2_copy);
422 if (check.isZero()) {422 if (check.isZero()) {
lib/std/crypto/Certificate.zig+1-1
...@@ -982,7 +982,7 @@ pub const rsa = struct {...@@ -982,7 +982,7 @@ pub const rsa = struct {
982 if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits982 if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits
983 return error.InvalidSignature;983 return error.InvalidSignature;
984 }984 }
985 var mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];985 const mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];
986 var dbMask = try MGF1(Hash, mgf_out, h, mgf_len);986 var dbMask = try MGF1(Hash, mgf_out, h, mgf_len);
987987
988 // 8. Let DB = maskedDB \xor dbMask.988 // 8. Let DB = maskedDB \xor dbMask.
lib/std/crypto/aes.zig+1-1
...@@ -47,7 +47,7 @@ test "ctr" {...@@ -47,7 +47,7 @@ test "ctr" {
47 };47 };
4848
49 var out: [exp_out.len]u8 = undefined;49 var out: [exp_out.len]u8 = undefined;
50 var ctx = Aes128.initEnc(key);50 const ctx = Aes128.initEnc(key);
51 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big);51 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big);
52 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);52 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
53}53}
lib/std/crypto/aes_ocb.zig+1-1
...@@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type {
95 var ktop_: Block = undefined;95 var ktop_: Block = undefined;
96 aes_enc_ctx.encrypt(&ktop_, &nx);96 aes_enc_ctx.encrypt(&ktop_, &nx);
97 const ktop = mem.readInt(u128, &ktop_, .big);97 const ktop = mem.readInt(u128, &ktop_, .big);
98 var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));98 const stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
99 var offset: Block = undefined;99 var offset: Block = undefined;
100 mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big);100 mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big);
101 return offset;101 return offset;
lib/std/crypto/argon2.zig+1-1
...@@ -565,7 +565,7 @@ const PhcFormatHasher = struct {...@@ -565,7 +565,7 @@ const PhcFormatHasher = struct {
565 const expected_hash = hash_result.hash.constSlice();565 const expected_hash = hash_result.hash.constSlice();
566 var hash_buf: [max_hash_len]u8 = undefined;566 var hash_buf: [max_hash_len]u8 = undefined;
567 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;567 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
568 var hash = hash_buf[0..expected_hash.len];568 const hash = hash_buf[0..expected_hash.len];
569569
570 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode);570 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode);
571 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;571 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
lib/std/crypto/ascon.zig+1-2
...@@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {...@@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {
4242
43 /// Initialize the state from u64 words in native endianness.43 /// Initialize the state from u64 words in native endianness.
44 pub fn initFromWords(initial_state: [5]u64) Self {44 pub fn initFromWords(initial_state: [5]u64) Self {
45 var state = Self{ .st = initial_state };45 return .{ .st = initial_state };
46 return state;
47 }46 }
4847
49 /// Initialize the state for Ascon XOF48 /// Initialize the state for Ascon XOF
lib/std/crypto/bcrypt.zig+1-1
...@@ -431,7 +431,7 @@ pub fn bcrypt(...@@ -431,7 +431,7 @@ pub fn bcrypt(
431 const trimmed_len = @min(password.len, password_buf.len - 1);431 const trimmed_len = @min(password.len, password_buf.len - 1);
432 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);432 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
433 password_buf[trimmed_len] = 0;433 password_buf[trimmed_len] = 0;
434 var passwordZ = password_buf[0 .. trimmed_len + 1];434 const passwordZ = password_buf[0 .. trimmed_len + 1];
435 state.expand(salt[0..], passwordZ);435 state.expand(salt[0..], passwordZ);
436436
437 const rounds: u64 = @as(u64, 1) << params.rounds_log;437 const rounds: u64 = @as(u64, 1) << params.rounds_log;
lib/std/crypto/blake3.zig+1-1
...@@ -241,7 +241,7 @@ const Output = struct {...@@ -241,7 +241,7 @@ const Output = struct {
241 var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN);241 var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN);
242 var output_block_counter: usize = 0;242 var output_block_counter: usize = 0;
243 while (out_block_it.next()) |out_block| {243 while (out_block_it.next()) |out_block| {
244 var words = compress(244 const words = compress(
245 self.input_chaining_value,245 self.input_chaining_value,
246 self.block_words,246 self.block_words,
247 self.block_len,247 self.block_len,
lib/std/crypto/ecdsa.zig+1-1
...@@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
201 const scalar_encoded_length = Curve.scalar.encoded_length;201 const scalar_encoded_length = Curve.scalar.encoded_length;
202 const h_len = @max(Hash.digest_length, scalar_encoded_length);202 const h_len = @max(Hash.digest_length, scalar_encoded_length);
203 var h: [h_len]u8 = [_]u8{0} ** h_len;203 var h: [h_len]u8 = [_]u8{0} ** h_len;
204 var h_slice = h[h_len - Hash.digest_length .. h_len];204 const h_slice = h[h_len - Hash.digest_length .. h_len];
205 self.h.final(h_slice);205 self.h.final(h_slice);
206206
207 std.debug.assert(h.len >= scalar_encoded_length);207 std.debug.assert(h.len >= scalar_encoded_length);
lib/std/crypto/pbkdf2.zig+2-4
...@@ -255,10 +255,8 @@ test "Very large dk_len" {...@@ -255,10 +255,8 @@ test "Very large dk_len" {
255 const c = 1;255 const c = 1;
256 const dk_len = 1 << 33;256 const dk_len = 1 << 33;
257257
258 var dk = try std.testing.allocator.alloc(u8, dk_len);258 const dk = try std.testing.allocator.alloc(u8, dk_len);
259 defer {259 defer std.testing.allocator.free(dk);
260 std.testing.allocator.free(dk);
261 }
262260
263 // Just verify this doesn't crash with an overflow261 // Just verify this doesn't crash with an overflow
264 try pbkdf2(dk, p, s, c, HmacSha1);262 try pbkdf2(dk, p, s, c, HmacSha1);
lib/std/crypto/pcurves/common.zig+1-1
...@@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type {
7171
72 /// Unpack a field element.72 /// Unpack a field element.
73 pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe {73 pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe {
74 var s = if (endian == .little) s_ else orderSwap(s_);74 const s = if (endian == .little) s_ else orderSwap(s_);
75 try rejectNonCanonical(s, .little);75 try rejectNonCanonical(s, .little);
76 var limbs_z: NonMontgomeryDomainFieldElement = undefined;76 var limbs_z: NonMontgomeryDomainFieldElement = undefined;
77 fiat.fromBytes(&limbs_z, s);77 fiat.fromBytes(&limbs_z, s);
lib/std/crypto/poly1305.zig+3-3
...@@ -90,8 +90,8 @@ pub const Poly1305 = struct {...@@ -90,8 +90,8 @@ pub const Poly1305 = struct {
90 h2 = t2 & 3;90 h2 = t2 & 3;
9191
92 // Add c*(4+1)92 // Add c*(4+1)
93 var cclo = t2 & ~@as(u64, 3);93 const cclo = t2 & ~@as(u64, 3);
94 var cchi = t3;94 const cchi = t3;
95 v = @addWithOverflow(h0, cclo);95 v = @addWithOverflow(h0, cclo);
96 h0 = v[0];96 h0 = v[0];
97 v = add(h1, cchi, v[1]);97 v = add(h1, cchi, v[1]);
...@@ -163,7 +163,7 @@ pub const Poly1305 = struct {...@@ -163,7 +163,7 @@ pub const Poly1305 = struct {
163163
164 var h0 = st.h[0];164 var h0 = st.h[0];
165 var h1 = st.h[1];165 var h1 = st.h[1];
166 var h2 = st.h[2];166 const h2 = st.h[2];
167167
168 // H - (2^130 - 5)168 // H - (2^130 - 5)
169 var v = @subWithOverflow(h0, 0xfffffffffffffffb);169 var v = @subWithOverflow(h0, 0xfffffffffffffffb);
lib/std/crypto/salsa20.zig+3-3
...@@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" {...@@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" {
605 crypto.random.bytes(&msg);605 crypto.random.bytes(&msg);
606 crypto.random.bytes(&nonce);606 crypto.random.bytes(&nonce);
607607
608 var kp1 = try Box.KeyPair.create(null);608 const kp1 = try Box.KeyPair.create(null);
609 var kp2 = try Box.KeyPair.create(null);609 const kp2 = try Box.KeyPair.create(null);
610 try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key);610 try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key);
611 try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key);611 try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key);
612}612}
...@@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" {...@@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" {
617 var boxed: [msg.len + SealedBox.seal_length]u8 = undefined;617 var boxed: [msg.len + SealedBox.seal_length]u8 = undefined;
618 crypto.random.bytes(&msg);618 crypto.random.bytes(&msg);
619619
620 var kp = try Box.KeyPair.create(null);620 const kp = try Box.KeyPair.create(null);
621 try SealedBox.seal(boxed[0..], msg[0..], kp.public_key);621 try SealedBox.seal(boxed[0..], msg[0..], kp.public_key);
622 try SealedBox.open(msg2[0..], boxed[0..], kp);622 try SealedBox.open(msg2[0..], boxed[0..], kp);
623}623}
lib/std/crypto/scrypt.zig+7-7
...@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {...@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {
87}87}
8888
89fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {89fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
90 var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);90 const x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 var y: []align(16) u32 = @alignCast(xy[32 * r ..]);91 const y: []align(16) u32 = @alignCast(xy[32 * r ..]);
9292
93 for (x, 0..) |*v1, j| {93 for (x, 0..) |*v1, j| {
94 v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little);94 v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little);
...@@ -191,9 +191,9 @@ pub fn kdf(...@@ -191,9 +191,9 @@ pub fn kdf(
191 params.r > max_int / 256 or191 params.r > max_int / 256 or
192 n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters;192 n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters;
193193
194 var xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);194 const xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);
195 defer allocator.free(xy);195 defer allocator.free(xy);
196 var v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);196 const v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);
197 defer allocator.free(v);197 defer allocator.free(v);
198 var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r);198 var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r);
199 defer allocator.free(dk);199 defer allocator.free(dk);
...@@ -263,7 +263,7 @@ const crypt_format = struct {...@@ -263,7 +263,7 @@ const crypt_format = struct {
263 const value = self.constSlice();263 const value = self.constSlice();
264 const len = Codec.encodedLen(value.len);264 const len = Codec.encodedLen(value.len);
265 if (len > buf.len) return EncodingError.NoSpaceLeft;265 if (len > buf.len) return EncodingError.NoSpaceLeft;
266 var encoded = buf[0..len];266 const encoded = buf[0..len];
267 Codec.encode(encoded, value);267 Codec.encode(encoded, value);
268 return encoded;268 return encoded;
269 }269 }
...@@ -439,7 +439,7 @@ const PhcFormatHasher = struct {...@@ -439,7 +439,7 @@ const PhcFormatHasher = struct {
439 const expected_hash = hash_result.hash.constSlice();439 const expected_hash = hash_result.hash.constSlice();
440 var hash_buf: [max_hash_len]u8 = undefined;440 var hash_buf: [max_hash_len]u8 = undefined;
441 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;441 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
442 var hash = hash_buf[0..expected_hash.len];442 const hash = hash_buf[0..expected_hash.len];
443 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params);443 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params);
444 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;444 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
445 }445 }
...@@ -487,7 +487,7 @@ const CryptFormatHasher = struct {...@@ -487,7 +487,7 @@ const CryptFormatHasher = struct {
487 const expected_hash = hash_result.hash.constSlice();487 const expected_hash = hash_result.hash.constSlice();
488 var hash_buf: [max_hash_len]u8 = undefined;488 var hash_buf: [max_hash_len]u8 = undefined;
489 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;489 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
490 var hash = hash_buf[0..expected_hash.len];490 const hash = hash_buf[0..expected_hash.len];
491 try kdf(allocator, hash, password, hash_result.salt, params);491 try kdf(allocator, hash, password, hash_result.salt, params);
492 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;492 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
493 }493 }
lib/std/crypto/tls/Client.zig+3-3
...@@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
491 try all_extd.ensure(4);491 try all_extd.ensure(4);
492 const et = all_extd.decode(tls.ExtensionType);492 const et = all_extd.decode(tls.ExtensionType);
493 const ext_size = all_extd.decode(u16);493 const ext_size = all_extd.decode(u16);
494 var extd = try all_extd.sub(ext_size);494 const extd = try all_extd.sub(ext_size);
495 _ = extd;495 _ = extd;
496 switch (et) {496 switch (et) {
497 .server_name => {},497 .server_name => {},
...@@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
516 while (!certs_decoder.eof()) {516 while (!certs_decoder.eof()) {
517 try certs_decoder.ensure(3);517 try certs_decoder.ensure(3);
518 const cert_size = certs_decoder.decode(u24);518 const cert_size = certs_decoder.decode(u24);
519 var certd = try certs_decoder.sub(cert_size);519 const certd = try certs_decoder.sub(cert_size);
520520
521 const subject_cert: Certificate = .{521 const subject_cert: Certificate = .{
522 .buffer = certd.buf,522 .buffer = certd.buf,
...@@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
552552
553 try certs_decoder.ensure(2);553 try certs_decoder.ensure(2);
554 const total_ext_size = certs_decoder.decode(u16);554 const total_ext_size = certs_decoder.decode(u16);
555 var all_extd = try certs_decoder.sub(total_ext_size);555 const all_extd = try certs_decoder.sub(total_ext_size);
556 _ = all_extd;556 _ = all_extd;
557 }557 }
558 },558 },
lib/std/debug.zig+4-4
...@@ -812,7 +812,7 @@ pub fn writeStackTraceWindows(...@@ -812,7 +812,7 @@ pub fn writeStackTraceWindows(
812 var addr_buf: [1024]usize = undefined;812 var addr_buf: [1024]usize = undefined;
813 const n = walkStackWindows(addr_buf[0..], context);813 const n = walkStackWindows(addr_buf[0..], context);
814 const addrs = addr_buf[0..n];814 const addrs = addr_buf[0..n];
815 var start_i: usize = if (start_addr) |saddr| blk: {815 const start_i: usize = if (start_addr) |saddr| blk: {
816 for (addrs, 0..) |addr, i| {816 for (addrs, 0..) |addr, i| {
817 if (addr == saddr) break :blk i;817 if (addr == saddr) break :blk i;
818 }818 }
...@@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo(...@@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo(
1158 var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue;1158 var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue;
1159 defer zlib_stream.deinit();1159 defer zlib_stream.deinit();
11601160
1161 var decompressed_section = try allocator.alloc(u8, chdr.ch_size);1161 const decompressed_section = try allocator.alloc(u8, chdr.ch_size);
1162 errdefer allocator.free(decompressed_section);1162 errdefer allocator.free(decompressed_section);
11631163
1164 const read = zlib_stream.reader().readAll(decompressed_section) catch continue;1164 const read = zlib_stream.reader().readAll(decompressed_section) catch continue;
...@@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) {
2046 };2046 };
20472047
2048 try DW.openDwarfDebugInfo(&di, allocator);2048 try DW.openDwarfDebugInfo(&di, allocator);
2049 var info = OFileInfo{2049 const info = OFileInfo{
2050 .di = di,2050 .di = di,
2051 .addr_table = addr_table,2051 .addr_table = addr_table,
2052 };2052 };
...@@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) {
21222122
2123 // Check if its debug infos are already in the cache2123 // Check if its debug infos are already in the cache
2124 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);2124 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
2125 var o_file_info = self.ofiles.getPtr(o_file_path) orelse2125 const o_file_info = self.ofiles.getPtr(o_file_path) orelse
2126 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {2126 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
2127 error.FileNotFound,2127 error.FileNotFound,
2128 error.MissingDebugInfo,2128 error.MissingDebugInfo,
lib/std/dwarf.zig+5-5
...@@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en...@@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en
622 return parseFormValue(allocator, in_stream, child_form_id, endian, is_64);622 return parseFormValue(allocator, in_stream, child_form_id, endian, is_64);
623 }623 }
624 const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));624 const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
625 var frame = try allocator.create(F);625 const frame = try allocator.create(F);
626 defer allocator.destroy(frame);626 defer allocator.destroy(frame);
627 return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 });627 return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 });
628 },628 },
...@@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct {...@@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct {
1034 // specified by DW_AT.low_pc or to some other value encoded1034 // specified by DW_AT.low_pc or to some other value encoded
1035 // in the list itself.1035 // in the list itself.
1036 // If no starting value is specified use zero.1036 // If no starting value is specified use zero.
1037 var base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) {1037 const base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) {
1038 error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/111351038 error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135
1039 else => return err,1039 else => return err,
1040 };1040 };
...@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {...@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {
1438 if (opcode == LNS.extended_op) {1438 if (opcode == LNS.extended_op) {
1439 const op_size = try leb.readULEB128(u64, in);1439 const op_size = try leb.readULEB128(u64, in);
1440 if (op_size < 1) return badDwarf();1440 if (op_size < 1) return badDwarf();
1441 var sub_op = try in.readByte();1441 const sub_op = try in.readByte();
1442 switch (sub_op) {1442 switch (sub_op) {
1443 LNE.end_sequence => {1443 LNE.end_sequence => {
1444 prog.end_sequence = true;1444 prog.end_sequence = true;
...@@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo...@@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
2308 else => return badDwarf(),2308 else => return badDwarf(),
2309 };2309 };
23102310
2311 var base = switch (enc & EH.PE.rel_mask) {2311 const base = switch (enc & EH.PE.rel_mask) {
2312 EH.PE.pcrel => ctx.pc_rel_base,2312 EH.PE.pcrel => ctx.pc_rel_base,
2313 EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified,2313 EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified,
2314 EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified,2314 EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified,
...@@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct {...@@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct {
2624 var has_aug_data = false;2624 var has_aug_data = false;
26252625
2626 var aug_str_len: usize = 0;2626 var aug_str_len: usize = 0;
2627 var aug_str_start = stream.pos;2627 const aug_str_start = stream.pos;
2628 var aug_byte = try reader.readByte();2628 var aug_byte = try reader.readByte();
2629 while (aug_byte != 0) : (aug_byte = try reader.readByte()) {2629 while (aug_byte != 0) : (aug_byte = try reader.readByte()) {
2630 switch (aug_byte) {2630 switch (aug_byte) {
lib/std/dwarf/expressions.zig+4-4
...@@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
443 OP.xderef_type,443 OP.xderef_type,
444 => {444 => {
445 if (self.stack.items.len == 0) return error.InvalidExpression;445 if (self.stack.items.len == 0) return error.InvalidExpression;
446 var addr = try self.stack.items[self.stack.items.len - 1].asIntegral();446 const addr = try self.stack.items[self.stack.items.len - 1].asIntegral();
447 const addr_space_identifier: ?usize = switch (opcode) {447 const addr_space_identifier: ?usize = switch (opcode) {
448 OP.xderef,448 OP.xderef,
449 OP.xderef_size,449 OP.xderef_size,
...@@ -1350,7 +1350,7 @@ test "DWARF expressions" {...@@ -1350,7 +1350,7 @@ test "DWARF expressions" {
13501350
1351 // Arithmetic and Logical Operations1351 // Arithmetic and Logical Operations
1352 {1352 {
1353 var context = ExpressionContext{};1353 const context = ExpressionContext{};
13541354
1355 stack_machine.reset();1355 stack_machine.reset();
1356 program.clearRetainingCapacity();1356 program.clearRetainingCapacity();
...@@ -1474,7 +1474,7 @@ test "DWARF expressions" {...@@ -1474,7 +1474,7 @@ test "DWARF expressions" {
14741474
1475 // Control Flow Operations1475 // Control Flow Operations
1476 {1476 {
1477 var context = ExpressionContext{};1477 const context = ExpressionContext{};
1478 const expected = .{1478 const expected = .{
1479 .{ OP.le, 1, 1, 0 },1479 .{ OP.le, 1, 1, 0 },
1480 .{ OP.ge, 1, 0, 1 },1480 .{ OP.ge, 1, 0, 1 },
...@@ -1531,7 +1531,7 @@ test "DWARF expressions" {...@@ -1531,7 +1531,7 @@ test "DWARF expressions" {
15311531
1532 // Type conversions1532 // Type conversions
1533 {1533 {
1534 var context = ExpressionContext{};1534 const context = ExpressionContext{};
1535 stack_machine.reset();1535 stack_machine.reset();
1536 program.clearRetainingCapacity();1536 program.clearRetainingCapacity();
15371537
lib/std/enums.zig+4-1
...@@ -123,6 +123,7 @@ pub fn directEnumArray(...@@ -123,6 +123,7 @@ pub fn directEnumArray(
123test "std.enums.directEnumArray" {123test "std.enums.directEnumArray" {
124 const E = enum(i4) { a = 4, b = 6, c = 2 };124 const E = enum(i4) { a = 4, b = 6, c = 2 };
125 var runtime_false: bool = false;125 var runtime_false: bool = false;
126 _ = &runtime_false;
126 const array = directEnumArray(E, bool, 4, .{127 const array = directEnumArray(E, bool, 4, .{
127 .a = true,128 .a = true,
128 .b = runtime_false,129 .b = runtime_false,
...@@ -165,6 +166,7 @@ pub fn directEnumArrayDefault(...@@ -165,6 +166,7 @@ pub fn directEnumArrayDefault(
165test "std.enums.directEnumArrayDefault" {166test "std.enums.directEnumArrayDefault" {
166 const E = enum(i4) { a = 4, b = 6, c = 2 };167 const E = enum(i4) { a = 4, b = 6, c = 2 };
167 var runtime_false: bool = false;168 var runtime_false: bool = false;
169 _ = &runtime_false;
168 const array = directEnumArrayDefault(E, bool, false, 4, .{170 const array = directEnumArrayDefault(E, bool, false, 4, .{
169 .a = true,171 .a = true,
170 .b = runtime_false,172 .b = runtime_false,
...@@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" {...@@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" {
179test "std.enums.directEnumArrayDefault slice" {181test "std.enums.directEnumArrayDefault slice" {
180 const E = enum(i4) { a = 4, b = 6, c = 2 };182 const E = enum(i4) { a = 4, b = 6, c = 2 };
181 var runtime_b = "b";183 var runtime_b = "b";
184 _ = &runtime_b;
182 const array = directEnumArrayDefault(E, []const u8, "default", 4, .{185 const array = directEnumArrayDefault(E, []const u8, "default", 4, .{
183 .a = "a",186 .a = "a",
184 .b = runtime_b,187 .b = runtime_b,
...@@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {...@@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
196 return comptime blk: {199 return comptime blk: {
197 const V = @TypeOf(value);200 const V = @TypeOf(value);
198 if (V == E) break :blk value;201 if (V == E) break :blk value;
199 var name: ?[]const u8 = switch (@typeInfo(V)) {202 const name: ?[]const u8 = switch (@typeInfo(V)) {
200 .EnumLiteral, .Enum => @tagName(value),203 .EnumLiteral, .Enum => @tagName(value),
201 .Pointer => if (std.meta.trait.isZigString(V)) value else null,204 .Pointer => if (std.meta.trait.isZigString(V)) value else null,
202 else => null,205 else => null,
lib/std/event/group.zig+1-1
...@@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type {...@@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type {
66 /// `func` must be async and have return type `ReturnType`.66 /// `func` must be async and have return type `ReturnType`.
67 /// Thread-safe.67 /// Thread-safe.
68 pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void {68 pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void {
69 var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));69 const frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
70 errdefer self.allocator.destroy(frame);70 errdefer self.allocator.destroy(frame);
71 const node = try self.allocator.create(AllocStack.Node);71 const node = try self.allocator.create(AllocStack.Node);
72 errdefer self.allocator.destroy(node);72 errdefer self.allocator.destroy(node);
lib/std/event/loop.zig+1-1
...@@ -753,7 +753,7 @@ pub const Loop = struct {...@@ -753,7 +753,7 @@ pub const Loop = struct {
753 }753 }
754 };754 };
755755
756 var run_frame = try alloc.create(@Frame(Wrapper.run));756 const run_frame = try alloc.create(@Frame(Wrapper.run));
757 run_frame.* = async Wrapper.run(args, self, alloc);757 run_frame.* = async Wrapper.run(args, self, alloc);
758 }758 }
759759
lib/std/event/rwlock.zig+4-4
...@@ -228,7 +228,7 @@ test "std.event.RwLock" {...@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228}228}
229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
230 var read_nodes: [100]Loop.NextTickNode = undefined;230 var read_nodes: [100]Loop.NextTickNode = undefined;
231 for (read_nodes) |*read_node| {231 for (&read_nodes) |*read_node| {
232 const frame = allocator.create(@Frame(readRunner)) catch @panic("memory");232 const frame = allocator.create(@Frame(readRunner)) catch @panic("memory");
233 read_node.data = frame;233 read_node.data = frame;
234 frame.* = async readRunner(lock);234 frame.* = async readRunner(lock);
...@@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {...@@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
236 }236 }
237237
238 var write_nodes: [shared_it_count]Loop.NextTickNode = undefined;238 var write_nodes: [shared_it_count]Loop.NextTickNode = undefined;
239 for (write_nodes) |*write_node| {239 for (&write_nodes) |*write_node| {
240 const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory");240 const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory");
241 write_node.data = frame;241 write_node.data = frame;
242 frame.* = async writeRunner(lock);242 frame.* = async writeRunner(lock);
243 Loop.instance.?.onNextTick(write_node);243 Loop.instance.?.onNextTick(write_node);
244 }244 }
245245
246 for (write_nodes) |*write_node| {246 for (&write_nodes) |*write_node| {
247 const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data));247 const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data));
248 await casted;248 await casted;
249 allocator.destroy(casted);249 allocator.destroy(casted);
250 }250 }
251 for (read_nodes) |*read_node| {251 for (&read_nodes) |*read_node| {
252 const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data));252 const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data));
253 await casted;253 await casted;
254 allocator.destroy(casted);254 allocator.destroy(casted);
lib/std/fmt.zig+11-9
...@@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal(...@@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal(
1296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);1296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
12971297
1298 // exp < 0 means the leading is always 0 as errol result is normalized.1298 // exp < 0 means the leading is always 0 as errol result is normalized.
1299 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;1299 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13001300
1301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.1301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1302 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);1302 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
13031303
1304 if (num_digits_whole > 0) {1304 if (num_digits_whole > 0) {
1305 // We may have to zero pad, for instance 1e4 requires zero padding.1305 // We may have to zero pad, for instance 1e4 requires zero padding.
...@@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal(...@@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal(
1354 }1354 }
1355 } else {1355 } else {
1356 // exp < 0 means the leading is always 0 as errol result is normalized.1356 // exp < 0 means the leading is always 0 as errol result is normalized.
1357 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;1357 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13581358
1359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.1359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1360 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);1360 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
13611361
1362 if (num_digits_whole > 0) {1362 if (num_digits_whole > 0) {
1363 // We may have to zero pad, for instance 1e4 requires zero padding.1363 // We may have to zero pad, for instance 1e4 requires zero padding.
...@@ -2218,6 +2218,7 @@ test "slice" {...@@ -2218,6 +2218,7 @@ test "slice" {
2218 }2218 }
2219 {2219 {
2220 var runtime_zero: usize = 0;2220 var runtime_zero: usize = 0;
2221 _ = &runtime_zero;
2221 const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero];2222 const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero];
2222 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});2223 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});
2223 }2224 }
...@@ -2232,6 +2233,7 @@ test "slice" {...@@ -2232,6 +2233,7 @@ test "slice" {
2232 {2233 {
2233 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };2234 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };
2234 var runtime_zero: usize = 0;2235 var runtime_zero: usize = 0;
2236 _ = &runtime_zero;
2235 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]});2237 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]});
2236 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]});2238 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]});
2237 try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]});2239 try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]});
...@@ -2794,14 +2796,14 @@ test "padding" {...@@ -2794,14 +2796,14 @@ test "padding" {
2794}2796}
27952797
2796test "decimal float padding" {2798test "decimal float padding" {
2797 var number: f32 = 3.1415;2799 const number: f32 = 3.1415;
2798 try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number});2800 try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number});
2799 try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number});2801 try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number});
2800 try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number});2802 try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number});
2801}2803}
28022804
2803test "sci float padding" {2805test "sci float padding" {
2804 var number: f32 = 3.1415;2806 const number: f32 = 3.1415;
2805 try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number});2807 try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number});
2806 try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number});2808 try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number});
2807 try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number});2809 try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number});
...@@ -2825,7 +2827,7 @@ test "named arguments" {...@@ -2825,7 +2827,7 @@ test "named arguments" {
2825}2827}
28262828
2827test "runtime width specifier" {2829test "runtime width specifier" {
2828 var width: usize = 9;2830 const width: usize = 9;
2829 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });2831 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
2830 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });2832 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
2831 try expectFmt(" hello", "{s:[1]}", .{ "hello", width });2833 try expectFmt(" hello", "{s:[1]}", .{ "hello", width });
...@@ -2833,8 +2835,8 @@ test "runtime width specifier" {...@@ -2833,8 +2835,8 @@ test "runtime width specifier" {
2833}2835}
28342836
2835test "runtime precision specifier" {2837test "runtime precision specifier" {
2836 var number: f32 = 3.1415;2838 const number: f32 = 3.1415;
2837 var precision: usize = 2;2839 const precision: usize = 2;
2838 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });2840 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });
2839 try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision });2841 try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision });
2840}2842}
lib/std/fmt/errol.zig+2-2
...@@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {...@@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
367 var lo = ((fpprev(val) - n) + mid) / 2.0;367 var lo = ((fpprev(val) - n) + mid) / 2.0;
368 var hi = ((fpnext(val) - n) + mid) / 2.0;368 var hi = ((fpnext(val) - n) + mid) / 2.0;
369369
370 var buf_index = u64toa(u, buffer);370 const buf_index = u64toa(u, buffer);
371 var exp = @as(i32, @intCast(buf_index));371 const exp: i32 = @intCast(buf_index);
372 var j = buf_index;372 var j = buf_index;
373 buffer[j] = 0;373 buffer[j] = 0;
374374
lib/std/fmt/parse_float/parse.zig+2-2
...@@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
105 // parse initial digits before dot105 // parse initial digits before dot
106 var mantissa: MantissaT = 0;106 var mantissa: MantissaT = 0;
107 tryParseDigits(MantissaT, stream, &mantissa, info.base);107 tryParseDigits(MantissaT, stream, &mantissa, info.base);
108 var int_end = stream.offsetTrue();108 const int_end = stream.offsetTrue();
109 var n_digits = @as(isize, @intCast(stream.offsetTrue()));109 var n_digits = @as(isize, @intCast(stream.offsetTrue()));
110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
111 if (info.base == 16) n_digits -= 2;111 if (info.base == 16) n_digits -= 2;
...@@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool...@@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
188 // than 19 digits. That means we must have a decimal188 // than 19 digits. That means we must have a decimal
189 // point, and at least 1 fractional digit.189 // point, and at least 1 fractional digit.
190 stream.advance(1);190 stream.advance(1);
191 var marker = stream.offsetTrue();191 const marker = stream.offsetTrue();
192 tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);192 tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);
193 break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue()));193 break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue()));
194 }194 }
lib/std/fs.zig+2-2
...@@ -1689,7 +1689,7 @@ pub const Dir = struct {...@@ -1689,7 +1689,7 @@ pub const Dir = struct {
1689 }1689 }
1690 if (builtin.os.tag == .windows) {1690 if (builtin.os.tag == .windows) {
1691 var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined;1691 var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined;
1692 var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);1692 const dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
1693 if (builtin.link_libc) {1693 if (builtin.link_libc) {
1694 return os.chdirW(dir_path);1694 return os.chdirW(dir_path);
1695 }1695 }
...@@ -1810,7 +1810,7 @@ pub const Dir = struct {...@@ -1810,7 +1810,7 @@ pub const Dir = struct {
1810 const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |1810 const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |
1811 w.SYNCHRONIZE | w.FILE_TRAVERSE;1811 w.SYNCHRONIZE | w.FILE_TRAVERSE;
1812 const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags;1812 const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags;
1813 var dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{1813 const dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{
1814 .no_follow = args.no_follow,1814 .no_follow = args.no_follow,
1815 .create_disposition = w.FILE_OPEN,1815 .create_disposition = w.FILE_OPEN,
1816 });1816 });
lib/std/fs/get_app_data_dir.zig+4
...@@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi...@@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
57 },57 },
58 .haiku => {58 .haiku => {
59 var dir_path_ptr: [*:0]u8 = undefined;59 var dir_path_ptr: [*:0]u8 = undefined;
60 if (true) {
61 _ = &dir_path_ptr;
62 @compileError("TODO: init dir_path_ptr");
63 }
60 // TODO look into directory_which64 // TODO look into directory_which
61 const be_user_settings = 0xbbe;65 const be_user_settings = 0xbbe;
62 const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);66 const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);
lib/std/fs/test.zig+1-1
...@@ -80,7 +80,7 @@ const TestContext = struct {...@@ -80,7 +80,7 @@ const TestContext = struct {
80 transform_fn: *const PathType.TransformFn,80 transform_fn: *const PathType.TransformFn,
8181
82 pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {82 pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {
83 var tmp = tmpIterableDir(.{});83 const tmp = tmpIterableDir(.{});
84 return .{84 return .{
85 .path_type = path_type,85 .path_type = path_type,
86 .arena = ArenaAllocator.init(allocator),86 .arena = ArenaAllocator.init(allocator),
lib/std/fs/watch.zig+3-3
...@@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type {...@@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type {
116 },116 },
117 };117 };
118118
119 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);119 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
120 self.channel.init(buf);120 self.channel.init(buf);
121 self.os_data.putter_frame = async self.linuxEventPutter();121 self.os_data.putter_frame = async self.linuxEventPutter();
122 return self;122 return self;
...@@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type {...@@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type {
132 },132 },
133 };133 };
134134
135 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);135 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
136 self.channel.init(buf);136 self.channel.init(buf);
137 return self;137 return self;
138 },138 },
...@@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type {...@@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type {
147 },147 },
148 };148 };
149149
150 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);150 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
151 self.channel.init(buf);151 self.channel.init(buf);
152 return self;152 return self;
153 },153 },
lib/std/hash/auto_hash.zig+1
...@@ -280,6 +280,7 @@ test "hash slice shallow" {...@@ -280,6 +280,7 @@ test "hash slice shallow" {
280 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };280 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
281 // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices281 // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices
282 var runtime_zero: usize = 0;282 var runtime_zero: usize = 0;
283 _ = &runtime_zero;
283 const a = array1[runtime_zero..];284 const a = array1[runtime_zero..];
284 const b = array2[runtime_zero..];285 const b = array2[runtime_zero..];
285 const c = array1[runtime_zero..3];286 const c = array1[runtime_zero..3];
lib/std/hash/cityhash.zig+1-1
...@@ -271,7 +271,7 @@ pub const CityHash64 = struct {...@@ -271,7 +271,7 @@ pub const CityHash64 = struct {
271 var b1: u64 = b;271 var b1: u64 = b;
272 a1 +%= w;272 a1 +%= w;
273 b1 = rotr64(b1 +% a1 +% z, 21);273 b1 = rotr64(b1 +% a1 +% z, 21);
274 var c: u64 = a1;274 const c: u64 = a1;
275 a1 +%= x;275 a1 +%= x;
276 a1 +%= y;276 a1 +%= y;
277 b1 +%= rotr64(a1, 44);277 b1 +%= rotr64(a1, 44);
lib/std/hash/murmur.zig+25-31
...@@ -134,7 +134,7 @@ pub const Murmur2_64 = struct {...@@ -134,7 +134,7 @@ pub const Murmur2_64 = struct {
134 const m: u64 = 0xc6a4a7935bd1e995;134 const m: u64 = 0xc6a4a7935bd1e995;
135 const len: u64 = 4;135 const len: u64 = 4;
136 var h1: u64 = seed ^ (len *% m);136 var h1: u64 = seed ^ (len *% m);
137 var k1: u64 = v;137 const k1: u64 = v;
138 h1 ^= k1;138 h1 ^= k1;
139 h1 *%= m;139 h1 *%= m;
140 h1 ^= h1 >> 47;140 h1 ^= h1 >> 47;
...@@ -282,16 +282,14 @@ pub const Murmur3_32 = struct {...@@ -282,16 +282,14 @@ pub const Murmur3_32 = struct {
282const verify = @import("verify.zig");282const verify = @import("verify.zig");
283283
284test "murmur2_32" {284test "murmur2_32" {
285 var v0: u32 = 0x12345678;285 const v0: u32 = 0x12345678;
286 var v1: u64 = 0x1234567812345678;286 const v1: u64 = 0x1234567812345678;
287 var v0le: u32 = v0;287 const v0le: u32, const v1le: u64 = switch (native_endian) {
288 var v1le: u64 = v1;288 .little => .{ v0, v1 },
289 if (native_endian == .big) {289 .big => .{ @byteSwap(v0), @byteSwap(v1) },
290 v0le = @byteSwap(v0le);290 };
291 v1le = @byteSwap(v1le);291 try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
292 }292 try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
293 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
294 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
295}293}
296294
297test "murmur2_32 smhasher" {295test "murmur2_32 smhasher" {
...@@ -306,16 +304,14 @@ test "murmur2_32 smhasher" {...@@ -306,16 +304,14 @@ test "murmur2_32 smhasher" {
306}304}
307305
308test "murmur2_64" {306test "murmur2_64" {
309 var v0: u32 = 0x12345678;307 const v0: u32 = 0x12345678;
310 var v1: u64 = 0x1234567812345678;308 const v1: u64 = 0x1234567812345678;
311 var v0le: u32 = v0;309 const v0le: u32, const v1le: u64 = switch (native_endian) {
312 var v1le: u64 = v1;310 .little => .{ v0, v1 },
313 if (native_endian == .big) {311 .big => .{ @byteSwap(v0), @byteSwap(v1) },
314 v0le = @byteSwap(v0le);312 };
315 v1le = @byteSwap(v1le);313 try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
316 }314 try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
317 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
318 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
319}315}
320316
321test "mumur2_64 smhasher" {317test "mumur2_64 smhasher" {
...@@ -330,16 +326,14 @@ test "mumur2_64 smhasher" {...@@ -330,16 +326,14 @@ test "mumur2_64 smhasher" {
330}326}
331327
332test "murmur3_32" {328test "murmur3_32" {
333 var v0: u32 = 0x12345678;329 const v0: u32 = 0x12345678;
334 var v1: u64 = 0x1234567812345678;330 const v1: u64 = 0x1234567812345678;
335 var v0le: u32 = v0;331 const v0le: u32, const v1le: u64 = switch (native_endian) {
336 var v1le: u64 = v1;332 .little => .{ v0, v1 },
337 if (native_endian == .big) {333 .big => .{ @byteSwap(v0), @byteSwap(v1) },
338 v0le = @byteSwap(v0le);334 };
339 v1le = @byteSwap(v1le);335 try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
340 }336 try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
341 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
342 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
343}337}
344338
345test "mumur3_32 smhasher" {339test "mumur3_32 smhasher" {
lib/std/hash_map.zig+4-4
...@@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged(...@@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged(
14841484
1485 var i: Size = 0;1485 var i: Size = 0;
1486 var metadata = self.metadata.?;1486 var metadata = self.metadata.?;
1487 var keys_ptr = self.keys();1487 const keys_ptr = self.keys();
1488 var values_ptr = self.values();1488 const values_ptr = self.values();
1489 while (i < self.capacity()) : (i += 1) {1489 while (i < self.capacity()) : (i += 1) {
1490 if (metadata[i].isUsed()) {1490 if (metadata[i].isUsed()) {
1491 other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx);1491 other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx);
...@@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged(...@@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged(
1521 const old_capacity = self.capacity();1521 const old_capacity = self.capacity();
1522 var i: Size = 0;1522 var i: Size = 0;
1523 var metadata = self.metadata.?;1523 var metadata = self.metadata.?;
1524 var keys_ptr = self.keys();1524 const keys_ptr = self.keys();
1525 var values_ptr = self.values();1525 const values_ptr = self.values();
1526 while (i < old_capacity) : (i += 1) {1526 while (i < old_capacity) : (i += 1) {
1527 if (metadata[i].isUsed()) {1527 if (metadata[i].isUsed()) {
1528 map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx);1528 map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx);
lib/std/heap.zig+9-9
...@@ -81,10 +81,10 @@ const CAllocator = struct {...@@ -81,10 +81,10 @@ const CAllocator = struct {
81 // Thin wrapper around regular malloc, overallocate to account for81 // Thin wrapper around regular malloc, overallocate to account for
82 // alignment padding and store the original malloc()'ed pointer before82 // alignment padding and store the original malloc()'ed pointer before
83 // the aligned address.83 // the aligned address.
84 var unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));84 const unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));
85 const unaligned_addr = @intFromPtr(unaligned_ptr);85 const unaligned_addr = @intFromPtr(unaligned_ptr);
86 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);86 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);
87 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);87 const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
88 getHeader(aligned_ptr).* = unaligned_ptr;88 getHeader(aligned_ptr).* = unaligned_ptr;
8989
90 return aligned_ptr;90 return aligned_ptr;
...@@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" {...@@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" {
661 const X = 0xeeeeeeeeeeeeeeee;661 const X = 0xeeeeeeeeeeeeeeee;
662 const Y = 0xffffffffffffffff;662 const Y = 0xffffffffffffffff;
663663
664 var x = try allocator.create(u64);664 const x = try allocator.create(u64);
665 x.* = X;665 x.* = X;
666 try testing.expectError(error.OutOfMemory, allocator.create(u64));666 try testing.expectError(error.OutOfMemory, allocator.create(u64));
667667
668 fba.reset();668 fba.reset();
669 var y = try allocator.create(u64);669 const y = try allocator.create(u64);
670 y.* = Y;670 y.* = Y;
671671
672 // we expect Y to have overwritten X.672 // we expect Y to have overwritten X.
...@@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" {
691 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);691 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
692 const allocator = fixed_buffer_allocator.allocator();692 const allocator = fixed_buffer_allocator.allocator();
693693
694 var slice0 = try allocator.alloc(u8, 5);694 const slice0 = try allocator.alloc(u8, 5);
695 try testing.expect(slice0.len == 5);695 try testing.expect(slice0.len == 5);
696 var slice1 = try allocator.realloc(slice0, 10);696 const slice1 = try allocator.realloc(slice0, 10);
697 try testing.expect(slice1.ptr == slice0.ptr);697 try testing.expect(slice1.ptr == slice0.ptr);
698 try testing.expect(slice1.len == 10);698 try testing.expect(slice1.len == 10);
699 try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11));699 try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11));
...@@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" {
706 var slice0 = try allocator.alloc(u8, 2);706 var slice0 = try allocator.alloc(u8, 2);
707 slice0[0] = 1;707 slice0[0] = 1;
708 slice0[1] = 2;708 slice0[1] = 2;
709 var slice1 = try allocator.alloc(u8, 2);709 const slice1 = try allocator.alloc(u8, 2);
710 var slice2 = try allocator.realloc(slice0, 4);710 const slice2 = try allocator.realloc(slice0, 4);
711 try testing.expect(slice0.ptr != slice2.ptr);711 try testing.expect(slice0.ptr != slice2.ptr);
712 try testing.expect(slice1.ptr != slice2.ptr);712 try testing.expect(slice1.ptr != slice2.ptr);
713 try testing.expect(slice2[0] == 1);713 try testing.expect(slice2[0] == 1);
...@@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {...@@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {
757 allocator.free(slice);757 allocator.free(slice);
758758
759 // Zero-length allocation759 // Zero-length allocation
760 var empty = try allocator.alloc(u8, 0);760 const empty = try allocator.alloc(u8, 0);
761 allocator.free(empty);761 allocator.free(empty);
762 // Allocation with zero-sized types762 // Allocation with zero-sized types
763 const zero_bit_ptr = try allocator.create(u0);763 const zero_bit_ptr = try allocator.create(u0);
lib/std/heap/arena_allocator.zig+1-1
...@@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" {...@@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" {
257 rounds -= 1;257 rounds -= 1;
258 _ = arena_allocator.reset(.retain_capacity);258 _ = arena_allocator.reset(.retain_capacity);
259 var alloced_bytes: usize = 0;259 var alloced_bytes: usize = 0;
260 var total_size: usize = random.intRangeAtMost(usize, 256, 16384);260 const total_size: usize = random.intRangeAtMost(usize, 256, 16384);
261 while (alloced_bytes < total_size) {261 while (alloced_bytes < total_size) {
262 const size = random.intRangeAtMost(usize, 16, 256);262 const size = random.intRangeAtMost(usize, 16, 256);
263 const alignment = 32;263 const alignment = 32;
lib/std/heap/general_purpose_allocator.zig+3-3
...@@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
512 var buckets = &self.buckets[bucket_index];512 var buckets = &self.buckets[bucket_index];
513 const slot_count = @divExact(page_size, size_class);513 const slot_count = @divExact(page_size, size_class);
514 if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) {514 if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) {
515 var new_bucket = try self.createBucket(size_class);515 const new_bucket = try self.createBucket(size_class);
516 errdefer self.freeBucket(new_bucket, size_class);516 errdefer self.freeBucket(new_bucket, size_class);
517 const node = try self.bucket_node_pool.create();517 const node = try self.bucket_node_pool.create();
518 node.key = new_bucket;518 node.key = new_bucket;
...@@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
526 const slot_index = bucket.alloc_cursor;526 const slot_index = bucket.alloc_cursor;
527 bucket.alloc_cursor += 1;527 bucket.alloc_cursor += 1;
528528
529 var used_bits_byte = bucket.usedBits(slot_index / 8);529 const used_bits_byte = bucket.usedBits(slot_index / 8);
530 const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary530 const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary
531 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);531 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);
532 bucket.used_count += 1;532 bucket.used_count += 1;
...@@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
915 if (bucket.used_count == 0) {915 if (bucket.used_count == 0) {
916 var entry = self.buckets[bucket_index].getEntryFor(bucket);916 var entry = self.buckets[bucket_index].getEntryFor(bucket);
917 // save the node for destruction/insertion into in empty_buckets917 // save the node for destruction/insertion into in empty_buckets
918 var node = entry.node.?;918 const node = entry.node.?;
919 entry.set(null);919 entry.set(null);
920 if (self.cur_buckets[bucket_index] == bucket) {920 if (self.cur_buckets[bucket_index] == bucket) {
921 self.cur_buckets[bucket_index] = null;921 self.cur_buckets[bucket_index] = null;
lib/std/heap/memory_pool.zig+1-1
...@@ -172,7 +172,7 @@ test "memory pool: preheating (success)" {...@@ -172,7 +172,7 @@ test "memory pool: preheating (success)" {
172}172}
173173
174test "memory pool: preheating (failure)" {174test "memory pool: preheating (failure)" {
175 var failer = std.testing.failing_allocator;175 const failer = std.testing.failing_allocator;
176 try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5));176 try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5));
177}177}
178178
lib/std/http/Client.zig+1-1
...@@ -144,7 +144,7 @@ pub const ConnectionPool = struct {...@@ -144,7 +144,7 @@ pub const ConnectionPool = struct {
144 pool.mutex.lock();144 pool.mutex.lock();
145 defer pool.mutex.unlock();145 defer pool.mutex.unlock();
146146
147 var next = pool.free.first;147 const next = pool.free.first;
148 _ = next;148 _ = next;
149 while (pool.free_len > new_size) {149 while (pool.free_len > new_size) {
150 const popped = pool.free.popFirst() orelse unreachable;150 const popped = pool.free.popFirst() orelse unreachable;
lib/std/http/protocol.zig+6-9
...@@ -765,10 +765,9 @@ test "HeadersParser.read length" {...@@ -765,10 +765,9 @@ test "HeadersParser.read length" {
765 var r = HeadersParser.initDynamic(256);765 var r = HeadersParser.initDynamic(256);
766 defer r.header_bytes.deinit(std.testing.allocator);766 defer r.header_bytes.deinit(std.testing.allocator);
767 const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello";767 const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello";
768 var fbs = std.io.fixedBufferStream(data);
769768
770 var conn = MockBufferedConnection{769 var conn: MockBufferedConnection = .{
771 .conn = fbs,770 .conn = std.io.fixedBufferStream(data),
772 };771 };
773772
774 while (true) { // read headers773 while (true) { // read headers
...@@ -796,10 +795,9 @@ test "HeadersParser.read chunked" {...@@ -796,10 +795,9 @@ test "HeadersParser.read chunked" {
796 var r = HeadersParser.initDynamic(256);795 var r = HeadersParser.initDynamic(256);
797 defer r.header_bytes.deinit(std.testing.allocator);796 defer r.header_bytes.deinit(std.testing.allocator);
798 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\n\r\n";797 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\n\r\n";
799 var fbs = std.io.fixedBufferStream(data);
800798
801 var conn = MockBufferedConnection{799 var conn: MockBufferedConnection = .{
802 .conn = fbs,800 .conn = std.io.fixedBufferStream(data),
803 };801 };
804802
805 while (true) { // read headers803 while (true) { // read headers
...@@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" {...@@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" {
826 var r = HeadersParser.initDynamic(256);824 var r = HeadersParser.initDynamic(256);
827 defer r.header_bytes.deinit(std.testing.allocator);825 defer r.header_bytes.deinit(std.testing.allocator);
828 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\nContent-Type: text/plain\r\n\r\n";826 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\nContent-Type: text/plain\r\n\r\n";
829 var fbs = std.io.fixedBufferStream(data);
830827
831 var conn = MockBufferedConnection{828 var conn: MockBufferedConnection = .{
832 .conn = fbs,829 .conn = std.io.fixedBufferStream(data),
833 };830 };
834831
835 while (true) { // read headers832 while (true) { // read headers
lib/std/io/Reader/test.zig+8-8
...@@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th...@@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th
91 const reader = fis.reader();91 const reader = fis.reader();
9292
93 {93 {
94 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);94 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
95 defer a.free(result);95 defer a.free(result);
96 try std.testing.expectEqualStrings("0000", result);96 try std.testing.expectEqualStrings("0000", result);
97 }97 }
9898
99 {99 {
100 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);100 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
101 defer a.free(result);101 defer a.free(result);
102 try std.testing.expectEqualStrings("1234", result);102 try std.testing.expectEqualStrings("1234", result);
103 }103 }
...@@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" {...@@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" {
112 const reader = fis.reader();112 const reader = fis.reader();
113113
114 {114 {
115 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);115 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
116 defer a.free(result);116 defer a.free(result);
117 try std.testing.expectEqualStrings("", result);117 try std.testing.expectEqualStrings("", result);
118 }118 }
...@@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi...@@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi
126126
127 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5));127 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5));
128128
129 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);129 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
130 defer a.free(result);130 defer a.free(result);
131 try std.testing.expectEqualStrings("67", result);131 try std.testing.expectEqualStrings("67", result);
132}132}
...@@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt...@@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt
219 const reader = fis.reader();219 const reader = fis.reader();
220220
221 {221 {
222 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;222 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
223 defer a.free(result);223 defer a.free(result);
224 try std.testing.expectEqualStrings("0000", result);224 try std.testing.expectEqualStrings("0000", result);
225 }225 }
226226
227 {227 {
228 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;228 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
229 defer a.free(result);229 defer a.free(result);
230 try std.testing.expectEqualStrings("1234", result);230 try std.testing.expectEqualStrings("1234", result);
231 }231 }
...@@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" {...@@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" {
240 const reader = fis.reader();240 const reader = fis.reader();
241241
242 {242 {
243 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;243 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
244 defer a.free(result);244 defer a.free(result);
245 try std.testing.expectEqualStrings("", result);245 try std.testing.expectEqualStrings("", result);
246 }246 }
...@@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi...@@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi
254254
255 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5));255 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5));
256256
257 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;257 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
258 defer a.free(result);258 defer a.free(result);
259 try std.testing.expectEqualStrings("67", result);259 try std.testing.expectEqualStrings("67", result);
260}260}
lib/std/io/buffered_reader.zig+15-10
...@@ -131,8 +131,9 @@ test "io.BufferedReader Block" {...@@ -131,8 +131,9 @@ test "io.BufferedReader Block" {
131131
132 // len out == block132 // len out == block
133 {133 {
134 var block_reader = BlockReader.init(block, 2);134 var test_buf_reader: BufferedReader(4, BlockReader) = .{
135 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };135 .unbuffered_reader = BlockReader.init(block, 2),
136 };
136 var out_buf: [4]u8 = undefined;137 var out_buf: [4]u8 = undefined;
137 _ = try test_buf_reader.read(&out_buf);138 _ = try test_buf_reader.read(&out_buf);
138 try testing.expectEqualSlices(u8, &out_buf, block);139 try testing.expectEqualSlices(u8, &out_buf, block);
...@@ -143,8 +144,9 @@ test "io.BufferedReader Block" {...@@ -143,8 +144,9 @@ test "io.BufferedReader Block" {
143144
144 // len out < block145 // len out < block
145 {146 {
146 var block_reader = BlockReader.init(block, 2);147 var test_buf_reader: BufferedReader(4, BlockReader) = .{
147 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };148 .unbuffered_reader = BlockReader.init(block, 2),
149 };
148 var out_buf: [3]u8 = undefined;150 var out_buf: [3]u8 = undefined;
149 _ = try test_buf_reader.read(&out_buf);151 _ = try test_buf_reader.read(&out_buf);
150 try testing.expectEqualSlices(u8, &out_buf, "012");152 try testing.expectEqualSlices(u8, &out_buf, "012");
...@@ -157,8 +159,9 @@ test "io.BufferedReader Block" {...@@ -157,8 +159,9 @@ test "io.BufferedReader Block" {
157159
158 // len out > block160 // len out > block
159 {161 {
160 var block_reader = BlockReader.init(block, 2);162 var test_buf_reader: BufferedReader(4, BlockReader) = .{
161 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };163 .unbuffered_reader = BlockReader.init(block, 2),
164 };
162 var out_buf: [5]u8 = undefined;165 var out_buf: [5]u8 = undefined;
163 _ = try test_buf_reader.read(&out_buf);166 _ = try test_buf_reader.read(&out_buf);
164 try testing.expectEqualSlices(u8, &out_buf, "01230");167 try testing.expectEqualSlices(u8, &out_buf, "01230");
...@@ -169,8 +172,9 @@ test "io.BufferedReader Block" {...@@ -169,8 +172,9 @@ test "io.BufferedReader Block" {
169172
170 // len out == 0173 // len out == 0
171 {174 {
172 var block_reader = BlockReader.init(block, 2);175 var test_buf_reader: BufferedReader(4, BlockReader) = .{
173 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };176 .unbuffered_reader = BlockReader.init(block, 2),
177 };
174 var out_buf: [0]u8 = undefined;178 var out_buf: [0]u8 = undefined;
175 _ = try test_buf_reader.read(&out_buf);179 _ = try test_buf_reader.read(&out_buf);
176 try testing.expectEqualSlices(u8, &out_buf, "");180 try testing.expectEqualSlices(u8, &out_buf, "");
...@@ -178,8 +182,9 @@ test "io.BufferedReader Block" {...@@ -178,8 +182,9 @@ test "io.BufferedReader Block" {
178182
179 // len bufreader buf > block183 // len bufreader buf > block
180 {184 {
181 var block_reader = BlockReader.init(block, 2);185 var test_buf_reader: BufferedReader(5, BlockReader) = .{
182 var test_buf_reader = BufferedReader(5, BlockReader){ .unbuffered_reader = block_reader };186 .unbuffered_reader = BlockReader.init(block, 2),
187 };
183 var out_buf: [4]u8 = undefined;188 var out_buf: [4]u8 = undefined;
184 _ = try test_buf_reader.read(&out_buf);189 _ = try test_buf_reader.read(&out_buf);
185 try testing.expectEqualSlices(u8, &out_buf, block);190 try testing.expectEqualSlices(u8, &out_buf, block);
lib/std/io/test.zig+2-2
...@@ -167,13 +167,13 @@ test "updateTimes" {...@@ -167,13 +167,13 @@ test "updateTimes" {
167 file.close();167 file.close();
168 tmp.dir.deleteFile(tmp_file_name) catch {};168 tmp.dir.deleteFile(tmp_file_name) catch {};
169 }169 }
170 var stat_old = try file.stat();170 const stat_old = try file.stat();
171 // Set atime and mtime to 5s before171 // Set atime and mtime to 5s before
172 try file.updateTimes(172 try file.updateTimes(
173 stat_old.atime - 5 * std.time.ns_per_s,173 stat_old.atime - 5 * std.time.ns_per_s,
174 stat_old.mtime - 5 * std.time.ns_per_s,174 stat_old.mtime - 5 * std.time.ns_per_s,
175 );175 );
176 var stat_new = try file.stat();176 const stat_new = try file.stat();
177 try expect(stat_new.atime < stat_old.atime);177 try expect(stat_new.atime < stat_old.atime);
178 try expect(stat_new.mtime < stat_old.mtime);178 try expect(stat_new.mtime < stat_old.mtime);
179}179}
lib/std/json/dynamic_test.zig+9-9
...@@ -190,15 +190,15 @@ test "Value.jsonStringify" {...@@ -190,15 +190,15 @@ test "Value.jsonStringify" {
190 var obj = ObjectMap.init(testing.allocator);190 var obj = ObjectMap.init(testing.allocator);
191 defer obj.deinit();191 defer obj.deinit();
192 try obj.putNoClobber("a", .{ .string = "b" });192 try obj.putNoClobber("a", .{ .string = "b" });
193 var array = [_]Value{193 const array = [_]Value{
194 Value.null,194 .null,
195 Value{ .bool = true },195 .{ .bool = true },
196 Value{ .integer = 42 },196 .{ .integer = 42 },
197 Value{ .number_string = "43" },197 .{ .number_string = "43" },
198 Value{ .float = 42 },198 .{ .float = 42 },
199 Value{ .string = "weeee" },199 .{ .string = "weeee" },
200 Value{ .array = Array.fromOwnedSlice(undefined, &vals) },200 .{ .array = Array.fromOwnedSlice(undefined, &vals) },
201 Value{ .object = obj },201 .{ .object = obj },
202 };202 };
203 var buffer: [0x1000]u8 = undefined;203 var buffer: [0x1000]u8 = undefined;
204 var fbs = std.io.fixedBufferStream(&buffer);204 var fbs = std.io.fixedBufferStream(&buffer);
lib/std/json/static_test.zig+9-9
...@@ -533,7 +533,7 @@ test "parse into struct with misc fields" {...@@ -533,7 +533,7 @@ test "parse into struct with misc fields" {
533 string: []const u8,533 string: []const u8,
534 };534 };
535 };535 };
536 var document_str =536 const document_str =
537 \\{537 \\{
538 \\ "int": 420,538 \\ "int": 420,
539 \\ "float": 3.14,539 \\ "float": 3.14,
...@@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" {...@@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" {
588 data: [:99]const i32,588 data: [:99]const i32,
589 simple_data: []const i32,589 simple_data: []const i32,
590 };590 };
591 var document_str =591 const document_str =
592 \\{592 \\{
593 \\ "language": "zig",593 \\ "language": "zig",
594 \\ "language_without_sentinel": "zig again!",594 \\ "language_without_sentinel": "zig again!",
...@@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" {...@@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" {
634 language: []const u8,634 language: []const u8,
635 };635 };
636636
637 var str =637 const str =
638 \\{638 \\{
639 \\ "int": 420,639 \\ "int": 420,
640 \\ "float": 3.14,640 \\ "float": 3.14,
...@@ -685,7 +685,7 @@ test "parse into tuple" {...@@ -685,7 +685,7 @@ test "parse into tuple" {
685 std.meta.Tuple(&.{ u8, []const u8, u8 }),685 std.meta.Tuple(&.{ u8, []const u8, u8 }),
686 Union,686 Union,
687 });687 });
688 var str =688 const str =
689 \\[689 \\[
690 \\ 420,690 \\ 420,
691 \\ 3.14,691 \\ 3.14,
...@@ -789,7 +789,7 @@ test "parse into vector" {...@@ -789,7 +789,7 @@ test "parse into vector" {
789 vec_i32: @Vector(4, i32),789 vec_i32: @Vector(4, i32),
790 vec_f32: @Vector(2, f32),790 vec_f32: @Vector(2, f32),
791 };791 };
792 var s =792 const s =
793 \\{793 \\{
794 \\ "vec_f32": [1.5, 2.5],794 \\ "vec_f32": [1.5, 2.5],
795 \\ "vec_i32": [4, 5, 6, 7]795 \\ "vec_i32": [4, 5, 6, 7]
...@@ -821,7 +821,7 @@ test "json parse partial" {...@@ -821,7 +821,7 @@ test "json parse partial" {
821 num: u32,821 num: u32,
822 yes: bool,822 yes: bool,
823 };823 };
824 var str =824 const str =
825 \\{825 \\{
826 \\ "outer": {826 \\ "outer": {
827 \\ "key1": {827 \\ "key1": {
...@@ -835,7 +835,7 @@ test "json parse partial" {...@@ -835,7 +835,7 @@ test "json parse partial" {
835 \\ }835 \\ }
836 \\}836 \\}
837 ;837 ;
838 var allocator = testing.allocator;838 const allocator = testing.allocator;
839 var scanner = JsonScanner.initCompleteInput(allocator, str);839 var scanner = JsonScanner.initCompleteInput(allocator, str);
840 defer scanner.deinit();840 defer scanner.deinit();
841841
...@@ -876,13 +876,13 @@ test "json parse allocate when streaming" {...@@ -876,13 +876,13 @@ test "json parse allocate when streaming" {
876 not_const: []u8,876 not_const: []u8,
877 is_const: []const u8,877 is_const: []const u8,
878 };878 };
879 var str =879 const str =
880 \\{880 \\{
881 \\ "not_const": "non const string",881 \\ "not_const": "non const string",
882 \\ "is_const": "const string"882 \\ "is_const": "const string"
883 \\}883 \\}
884 ;884 ;
885 var allocator = testing.allocator;885 const allocator = testing.allocator;
886 var arena = ArenaAllocator.init(allocator);886 var arena = ArenaAllocator.init(allocator);
887 defer arena.deinit();887 defer arena.deinit();
888888
lib/std/math.zig+2-1
...@@ -427,6 +427,7 @@ test "clamp" {...@@ -427,6 +427,7 @@ test "clamp" {
427427
428 // Mix of comptime and non-comptime428 // Mix of comptime and non-comptime
429 var i: i32 = 1;429 var i: i32 = 1;
430 _ = &i;
430 try testing.expect(std.math.clamp(i, 0, 1) == 1);431 try testing.expect(std.math.clamp(i, 0, 1) == 1);
431}432}
432433
...@@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {...@@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
1113 comptime assert(info.signedness == .unsigned);1114 comptime assert(info.signedness == .unsigned);
1114 const PromotedType = std.meta.Int(info.signedness, info.bits + 1);1115 const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
1115 const overflowBit = @as(PromotedType, 1) << info.bits;1116 const overflowBit = @as(PromotedType, 1) << info.bits;
1116 var x = ceilPowerOfTwoPromote(T, value);1117 const x = ceilPowerOfTwoPromote(T, value);
1117 if (overflowBit & x != 0) {1118 if (overflowBit & x != 0) {
1118 return error.Overflow;1119 return error.Overflow;
1119 }1120 }
lib/std/math/atan.zig+2-2
...@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {...@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {
143 };143 };
144144
145 var x = x_;145 var x = x_;
146 var ux = @as(u64, @bitCast(x));146 const ux: u64 = @bitCast(x);
147 var ix = @as(u32, @intCast(ux >> 32));147 var ix: u32 = @intCast(ux >> 32);
148 const sign = ix >> 31;148 const sign = ix >> 31;
149 ix &= 0x7FFFFFFF;149 ix &= 0x7FFFFFFF;
150150
lib/std/math/atan2.zig+8-8
...@@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 {...@@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 {
104 }104 }
105105
106 // z = atan(|y / x|) with correct underflow106 // z = atan(|y / x|) with correct underflow
107 var z = z: {107 const z = z: {
108 if ((m & 2) != 0 and iy + (26 << 23) < ix) {108 if ((m & 2) != 0 and iy + (26 << 23) < ix) {
109 break :z 0.0;109 break :z 0.0;
110 } else {110 } else {
...@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {
129 return x + y;129 return x + y;
130 }130 }
131131
132 var ux = @as(u64, @bitCast(x));132 const ux: u64 = @bitCast(x);
133 var ix = @as(u32, @intCast(ux >> 32));133 var ix: u32 = @intCast(ux >> 32);
134 var lx = @as(u32, @intCast(ux & 0xFFFFFFFF));134 const lx: u32 = @intCast(ux & 0xFFFFFFFF);
135135
136 var uy = @as(u64, @bitCast(y));136 const uy: u64 = @bitCast(y);
137 var iy = @as(u32, @intCast(uy >> 32));137 var iy: u32 = @intCast(uy >> 32);
138 var ly = @as(u32, @intCast(uy & 0xFFFFFFFF));138 const ly: u32 = @intCast(uy & 0xFFFFFFFF);
139139
140 // x = 1.0140 // x = 1.0
141 if ((ix -% 0x3FF00000) | lx == 0) {141 if ((ix -% 0x3FF00000) | lx == 0) {
...@@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 {
194 }194 }
195195
196 // z = atan(|y / x|) with correct underflow196 // z = atan(|y / x|) with correct underflow
197 var z = z: {197 const z = z: {
198 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {198 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {
199 break :z 0.0;199 break :z 0.0;
200 } else {200 } else {
lib/std/math/big/int.zig+5-5
...@@ -797,7 +797,7 @@ pub const Mutable = struct {...@@ -797,7 +797,7 @@ pub const Mutable = struct {
797 // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones797 // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones
798 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;798 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;
799799
800 var bytes = std.mem.sliceAsBytes(r.limbs);800 const bytes = std.mem.sliceAsBytes(r.limbs);
801 var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb));801 var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb));
802802
803 var k: usize = 0;803 var k: usize = 0;
...@@ -1407,7 +1407,7 @@ pub const Mutable = struct {...@@ -1407,7 +1407,7 @@ pub const Mutable = struct {
1407 }1407 }
14081408
1409 // Avoid copying u to s by swapping u and s1409 // Avoid copying u to s by swapping u and s
1410 var tmp_s = s;1410 const tmp_s = s;
1411 s = u;1411 s = u;
1412 u = tmp_s;1412 u = tmp_s;
1413 }1413 }
...@@ -1911,7 +1911,7 @@ pub const Mutable = struct {...@@ -1911,7 +1911,7 @@ pub const Mutable = struct {
1911 var positive = true;1911 var positive = true;
1912 if (signedness == .signed) {1912 if (signedness == .signed) {
1913 const total_bits = bit_offset + bit_count;1913 const total_bits = bit_offset + bit_count;
1914 var last_byte = switch (endian) {1914 const last_byte = switch (endian) {
1915 .little => ((total_bits + 7) / 8) - 1,1915 .little => ((total_bits + 7) / 8) - 1,
1916 .big => buffer.len - ((total_bits + 7) / 8),1916 .big => buffer.len - ((total_bits + 7) / 8),
1917 };1917 };
...@@ -3161,7 +3161,7 @@ pub const Managed = struct {...@@ -3161,7 +3161,7 @@ pub const Managed = struct {
31613161
3162 /// r = a ^ b3162 /// r = a ^ b
3163 pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void {3163 pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void {
3164 var cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive());3164 const cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive());
3165 try r.ensureCapacity(cap);3165 try r.ensureCapacity(cap);
31663166
3167 var m = r.toMutable();3167 var m = r.toMutable();
...@@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {...@@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
4178 // most significant bit set.4178 // most significant bit set.
4179 // Square the result if the current bit is zero, square and multiply by a if4179 // Square the result if the current bit is zero, square and multiply by a if
4180 // it is one.4180 // it is one.
4181 var exp_bits = 32 - 1 - b_leading_zeros;4181 const exp_bits = 32 - 1 - b_leading_zeros;
4182 var exp = b << @as(u5, @intCast(1 + b_leading_zeros));4182 var exp = b << @as(u5, @intCast(1 + b_leading_zeros));
41834183
4184 var i: usize = 0;4184 var i: usize = 0;
lib/std/math/big/int_test.zig+28-9
...@@ -300,20 +300,18 @@ test "big.int twos complement limit set" {...@@ -300,20 +300,18 @@ test "big.int twos complement limit set" {
300 };300 };
301301
302 inline for (test_types) |T| {302 inline for (test_types) |T| {
303 // To work around 'control flow attempts to use compile-time variable at runtime'303 const int_info = @typeInfo(T).Int;
304 const U = T;
305 const int_info = @typeInfo(U).Int;
306304
307 var a = try Managed.init(testing.allocator);305 var a = try Managed.init(testing.allocator);
308 defer a.deinit();306 defer a.deinit();
309307
310 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);308 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
311 var max: U = maxInt(U);309 const max: T = maxInt(T);
312 try testing.expect(max == try a.to(U));310 try testing.expect(max == try a.to(T));
313311
314 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);312 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
315 var min: U = minInt(U);313 const min: T = minInt(T);
316 try testing.expect(min == try a.to(U));314 try testing.expect(min == try a.to(T));
317 }315 }
318}316}
319317
...@@ -519,6 +517,9 @@ test "big.int add multi-single" {...@@ -519,6 +517,9 @@ test "big.int add multi-single" {
519test "big.int add multi-multi" {517test "big.int add multi-multi" {
520 var op1: u128 = 0xefefefef7f7f7f7f;518 var op1: u128 = 0xefefefef7f7f7f7f;
521 var op2: u128 = 0xfefefefe9f9f9f9f;519 var op2: u128 = 0xfefefefe9f9f9f9f;
520 // These must be runtime-known to prevent this comparison being tautological, as the
521 // compiler uses `std.math.big.int` internally to add these values at comptime.
522 _ = .{ &op1, &op2 };
522 var a = try Managed.initSet(testing.allocator, op1);523 var a = try Managed.initSet(testing.allocator, op1);
523 defer a.deinit();524 defer a.deinit();
524 var b = try Managed.initSet(testing.allocator, op2);525 var b = try Managed.initSet(testing.allocator, op2);
...@@ -833,6 +834,7 @@ test "big.int sub multi-single" {...@@ -833,6 +834,7 @@ test "big.int sub multi-single" {
833test "big.int sub multi-multi" {834test "big.int sub multi-multi" {
834 var op1: u128 = 0xefefefefefefefefefefefef;835 var op1: u128 = 0xefefefefefefefefefefefef;
835 var op2: u128 = 0xabababababababababababab;836 var op2: u128 = 0xabababababababababababab;
837 _ = .{ &op1, &op2 };
836838
837 var a = try Managed.initSet(testing.allocator, op1);839 var a = try Managed.initSet(testing.allocator, op1);
838 defer a.deinit();840 defer a.deinit();
...@@ -920,6 +922,8 @@ test "big.int mul multi-multi" {...@@ -920,6 +922,8 @@ test "big.int mul multi-multi" {
920922
921 var op1: u256 = 0x998888efefefefefefefef;923 var op1: u256 = 0x998888efefefefefefefef;
922 var op2: u256 = 0x333000abababababababab;924 var op2: u256 = 0x333000abababababababab;
925 _ = .{ &op1, &op2 };
926
923 var a = try Managed.initSet(testing.allocator, op1);927 var a = try Managed.initSet(testing.allocator, op1);
924 defer a.deinit();928 defer a.deinit();
925 var b = try Managed.initSet(testing.allocator, op2);929 var b = try Managed.initSet(testing.allocator, op2);
...@@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" {...@@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" {
10421046
1043 var op1: u256 = 0x998888efefefefefefefef;1047 var op1: u256 = 0x998888efefefefefefefef;
1044 var op2: u256 = 0x333000abababababababab;1048 var op2: u256 = 0x333000abababababababab;
1049 _ = .{ &op1, &op2 };
1050
1045 var a = try Managed.initSet(testing.allocator, op1);1051 var a = try Managed.initSet(testing.allocator, op1);
1046 defer a.deinit();1052 defer a.deinit();
1047 var b = try Managed.initSet(testing.allocator, op2);1053 var b = try Managed.initSet(testing.allocator, op2);
...@@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" {...@@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" {
1164test "big.int div multi-single no rem" {1170test "big.int div multi-single no rem" {
1165 var op1: u128 = 0xffffeeeeddddcccc;1171 var op1: u128 = 0xffffeeeeddddcccc;
1166 var op2: u128 = 34;1172 var op2: u128 = 34;
1173 _ = .{ &op1, &op2 };
11671174
1168 var a = try Managed.initSet(testing.allocator, op1);1175 var a = try Managed.initSet(testing.allocator, op1);
1169 defer a.deinit();1176 defer a.deinit();
...@@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" {...@@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" {
1183test "big.int div multi-single with rem" {1190test "big.int div multi-single with rem" {
1184 var op1: u128 = 0xffffeeeeddddcccf;1191 var op1: u128 = 0xffffeeeeddddcccf;
1185 var op2: u128 = 34;1192 var op2: u128 = 34;
1193 _ = .{ &op1, &op2 };
11861194
1187 var a = try Managed.initSet(testing.allocator, op1);1195 var a = try Managed.initSet(testing.allocator, op1);
1188 defer a.deinit();1196 defer a.deinit();
...@@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" {...@@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" {
1202test "big.int div multi>2-single" {1210test "big.int div multi>2-single" {
1203 var op1: u128 = 0xfefefefefefefefefefefefefefefefe;1211 var op1: u128 = 0xfefefefefefefefefefefefefefefefe;
1204 var op2: u128 = 0xefab8;1212 var op2: u128 = 0xefab8;
1213 _ = .{ &op1, &op2 };
12051214
1206 var a = try Managed.initSet(testing.allocator, op1);1215 var a = try Managed.initSet(testing.allocator, op1);
1207 defer a.deinit();1216 defer a.deinit();
...@@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" {...@@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" {
2106 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;2115 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21072116
2108 var x: SignedDoubleLimb = 1;2117 var x: SignedDoubleLimb = 1;
2118 _ = &x;
2119
2109 const shift = @bitSizeOf(SignedDoubleLimb) - 1;2120 const shift = @bitSizeOf(SignedDoubleLimb) - 1;
21102121
2111 var a = try Managed.initSet(testing.allocator, x);2122 var a = try Managed.initSet(testing.allocator, x);
...@@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" {...@@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" {
2119 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;2130 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21202131
2121 var x: SignedDoubleLimb = -1;2132 var x: SignedDoubleLimb = -1;
2133 _ = &x;
2134
2122 const shift = @bitSizeOf(SignedDoubleLimb) - 1;2135 const shift = @bitSizeOf(SignedDoubleLimb) - 1;
21232136
2124 var a = try Managed.initSet(testing.allocator, x);2137 var a = try Managed.initSet(testing.allocator, x);
...@@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" {...@@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" {
21302143
2131test "big.int bitNotWrap unsigned simple" {2144test "big.int bitNotWrap unsigned simple" {
2132 var x: u10 = 123;2145 var x: u10 = 123;
2146 _ = &x;
2147
2133 var a = try Managed.initSet(testing.allocator, x);2148 var a = try Managed.initSet(testing.allocator, x);
2134 defer a.deinit();2149 defer a.deinit();
21352150
...@@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" {...@@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" {
21492164
2150test "big.int bitNotWrap signed simple" {2165test "big.int bitNotWrap signed simple" {
2151 var x: i11 = -456;2166 var x: i11 = -456;
2167 _ = &x;
2168
2152 var a = try Managed.initSet(testing.allocator, -456);2169 var a = try Managed.initSet(testing.allocator, -456);
2153 defer a.deinit();2170 defer a.deinit();
21542171
...@@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" {...@@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" {
2306test "big.int bitwise xor multi-limb" {2323test "big.int bitwise xor multi-limb" {
2307 var x: DoubleLimb = maxInt(Limb) + 1;2324 var x: DoubleLimb = maxInt(Limb) + 1;
2308 var y: DoubleLimb = maxInt(Limb);2325 var y: DoubleLimb = maxInt(Limb);
2326 _ = .{ &x, &y };
2327
2309 var a = try Managed.initSet(testing.allocator, x);2328 var a = try Managed.initSet(testing.allocator, x);
2310 defer a.deinit();2329 defer a.deinit();
2311 var b = try Managed.initSet(testing.allocator, y);2330 var b = try Managed.initSet(testing.allocator, y);
...@@ -2548,7 +2567,7 @@ test "big.int gcd one large" {...@@ -2548,7 +2567,7 @@ test "big.int gcd one large" {
25482567
2549test "big.int mutable to managed" {2568test "big.int mutable to managed" {
2550 const allocator = testing.allocator;2569 const allocator = testing.allocator;
2551 var limbs_buf = try allocator.alloc(Limb, 8);2570 const limbs_buf = try allocator.alloc(Limb, 8);
2552 defer allocator.free(limbs_buf);2571 defer allocator.free(limbs_buf);
25532572
2554 var a = Mutable.init(limbs_buf, 0xdeadbeef);2573 var a = Mutable.init(limbs_buf, 0xdeadbeef);
...@@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" {...@@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" {
2965 // (2) should correctly interpret bytes based on the provided endianness2984 // (2) should correctly interpret bytes based on the provided endianness
2966 // (3) should ignore any bits from bit_count to 8 * abi_size2985 // (3) should ignore any bits from bit_count to 8 * abi_size
29672986
2968 var bit_count: usize = 12 * 8 + 1;2987 const bit_count: usize = 12 * 8 + 1;
2969 var buffer: []const u8 = undefined;2988 var buffer: []const u8 = undefined;
29702989
2971 buffer = &([_]u8{0} ** 13);2990 buffer = &([_]u8{0} ** 13);
lib/std/math/cbrt.zig+2-2
...@@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 {...@@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 {
102102
103 // cbrt to 23 bits103 // cbrt to 23 bits
104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)
105 var r = (t * t) * (t / x);105 const r = (t * t) * (t / x);
106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));
107107
108 // Round t away from 0 to 23 bits108 // Round t away from 0 to 23 bits
...@@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 {...@@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 {
113 // one step newton to 53 bits113 // one step newton to 53 bits
114 const s = t * t;114 const s = t * t;
115 var q = x / s;115 var q = x / s;
116 var w = t + t;116 const w = t + t;
117 q = (q - t) / (w + q);117 q = (q - t) / (w + q);
118118
119 return t + t * q;119 return t + t * q;
lib/std/math/complex/atan.zig+2-2
...@@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) {...@@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) {
55 }55 }
5656
57 var t = 0.5 * math.atan2(f32, 2.0 * x, a);57 var t = 0.5 * math.atan2(f32, 2.0 * x, a);
58 var w = redupif32(t);58 const w = redupif32(t);
5959
60 t = y - 1.0;60 t = y - 1.0;
61 a = x2 + t * t;61 a = x2 + t * t;
...@@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {...@@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {
104 }104 }
105105
106 var t = 0.5 * math.atan2(f64, 2.0 * x, a);106 var t = 0.5 * math.atan2(f64, 2.0 * x, a);
107 var w = redupif64(t);107 const w = redupif64(t);
108108
109 t = y - 1.0;109 t = y - 1.0;
110 a = x2 + t * t;110 a = x2 + t * t;
lib/std/math/ilogb.zig+2-2
...@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {...@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {
3838
39 const absMask = signBit - 1;39 const absMask = signBit - 1;
4040
41 var u = @as(Z, @bitCast(x)) & absMask;41 const u = @as(Z, @bitCast(x)) & absMask;
42 var e = @as(i32, @intCast(u >> significandBits));42 const e: i32 = @intCast(u >> significandBits);
4343
44 if (e == 0) {44 if (e == 0) {
45 if (u == 0) {45 if (u == 0) {
lib/std/math/log1p.zig+4-4
...@@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 {...@@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 {
33 const Lg3: f32 = 0x91e9ee.0p-25;33 const Lg3: f32 = 0x91e9ee.0p-25;
34 const Lg4: f32 = 0xf89e26.0p-26;34 const Lg4: f32 = 0xf89e26.0p-26;
3535
36 const u = @as(u32, @bitCast(x));36 const u: u32 = @bitCast(x);
37 var ix = u;37 const ix = u;
38 var k: i32 = 1;38 var k: i32 = 1;
39 var f: f32 = undefined;39 var f: f32 = undefined;
40 var c: f32 = undefined;40 var c: f32 = undefined;
...@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {...@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {
112 const Lg6: f64 = 1.531383769920937332e-01;112 const Lg6: f64 = 1.531383769920937332e-01;
113 const Lg7: f64 = 1.479819860511658591e-01;113 const Lg7: f64 = 1.479819860511658591e-01;
114114
115 var ix = @as(u64, @bitCast(x));115 const ix: u64 = @bitCast(x);
116 var hx = @as(u32, @intCast(ix >> 32));116 const hx: u32 = @intCast(ix >> 32);
117 var k: i32 = 1;117 var k: i32 = 1;
118 var c: f64 = undefined;118 var c: f64 = undefined;
119 var f: f64 = undefined;119 var f: f64 = undefined;
lib/std/math/sqrt.zig+1-1
...@@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {...@@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
50 }50 }
5151
52 while (one != 0) {52 while (one != 0) {
53 var c = op >= res + one;53 const c = op >= res + one;
54 if (c) op -= res + one;54 if (c) op -= res + one;
55 res >>= 1;55 res >>= 1;
56 if (c) res += one;56 if (c) res += one;
lib/std/mem.zig+13-12
...@@ -403,11 +403,11 @@ test "zeroes" {...@@ -403,11 +403,11 @@ test "zeroes" {
403 b: u32,403 b: u32,
404 };404 };
405405
406 var c = zeroes(C_union);406 const c = zeroes(C_union);
407 try testing.expectEqual(@as(u8, 0), c.a);407 try testing.expectEqual(@as(u8, 0), c.a);
408 try testing.expectEqual(@as(u32, 0), c.b);408 try testing.expectEqual(@as(u32, 0), c.b);
409409
410 comptime var comptime_union = zeroes(C_union);410 const comptime_union = comptime zeroes(C_union);
411 try testing.expectEqual(@as(u8, 0), comptime_union.a);411 try testing.expectEqual(@as(u8, 0), comptime_union.a);
412 try testing.expectEqual(@as(u32, 0), comptime_union.b);412 try testing.expectEqual(@as(u32, 0), comptime_union.b);
413413
...@@ -3399,7 +3399,7 @@ test "reverseIterator" {...@@ -3399,7 +3399,7 @@ test "reverseIterator" {
3399 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);3399 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);
3400 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());3400 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());
34013401
3402 var mut_slice: []i32 = &array;3402 const mut_slice: []i32 = &array;
3403 var mut_it = reverseIterator(mut_slice);3403 var mut_it = reverseIterator(mut_slice);
3404 mut_it.nextPtr().?.* += 1;3404 mut_it.nextPtr().?.* += 1;
3405 mut_it.nextPtr().?.* += 2;3405 mut_it.nextPtr().?.* += 2;
...@@ -3419,7 +3419,7 @@ test "reverseIterator" {...@@ -3419,7 +3419,7 @@ test "reverseIterator" {
3419 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);3419 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);
3420 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());3420 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());
34213421
3422 var mut_ptr_to_array: *[2]i32 = &array;3422 const mut_ptr_to_array: *[2]i32 = &array;
3423 var mut_it = reverseIterator(mut_ptr_to_array);3423 var mut_it = reverseIterator(mut_ptr_to_array);
3424 mut_it.nextPtr().?.* += 1;3424 mut_it.nextPtr().?.* += 1;
3425 mut_it.nextPtr().?.* += 2;3425 mut_it.nextPtr().?.* += 2;
...@@ -3581,7 +3581,7 @@ test "replacementSize" {...@@ -3581,7 +3581,7 @@ test "replacementSize" {
35813581
3582/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.3582/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
3583pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T {3583pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T {
3584 var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement));3584 const output = try allocator.alloc(T, replacementSize(T, input, needle, replacement));
3585 _ = replace(T, input, needle, replacement, output);3585 _ = replace(T, input, needle, replacement, output);
3586 return output;3586 return output;
3587}3587}
...@@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {...@@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {
3693test "alignPointer" {3693test "alignPointer" {
3694 const S = struct {3694 const S = struct {
3695 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {3695 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {
3696 var ptr = @as(T, @ptrFromInt(base));3696 const ptr: T = @ptrFromInt(base);
3697 var aligned = alignPointer(ptr, align_to);3697 const aligned = alignPointer(ptr, align_to);
3698 try testing.expectEqual(expected, @intFromPtr(aligned));3698 try testing.expectEqual(expected, @intFromPtr(aligned));
3699 }3699 }
3700 };3700 };
...@@ -3848,7 +3848,7 @@ test "bytesAsValue" {...@@ -3848,7 +3848,7 @@ test "bytesAsValue" {
3848 .big => "\xC0\xDE\xFA\xCE",3848 .big => "\xC0\xDE\xFA\xCE",
3849 .little => "\xCE\xFA\xDE\xC0",3849 .little => "\xCE\xFA\xDE\xC0",
3850 }.*;3850 }.*;
3851 var codeface = bytesAsValue(u32, &codeface_bytes);3851 const codeface = bytesAsValue(u32, &codeface_bytes);
3852 try testing.expect(codeface.* == 0xC0DEFACE);3852 try testing.expect(codeface.* == 0xC0DEFACE);
3853 codeface.* = 0;3853 codeface.* = 0;
3854 for (codeface_bytes) |b|3854 for (codeface_bytes) |b|
...@@ -3941,6 +3941,7 @@ test "bytesAsSlice" {...@@ -3941,6 +3941,7 @@ test "bytesAsSlice" {
3941 {3941 {
3942 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };3942 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
3943 var runtime_zero: usize = 0;3943 var runtime_zero: usize = 0;
3944 _ = &runtime_zero;
3944 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);3945 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
3945 try testing.expect(slice.len == 2);3946 try testing.expect(slice.len == 2);
3946 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);3947 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
...@@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" {...@@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" {
3957 {3958 {
3958 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };3959 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
3959 var runtime_zero: usize = 0;3960 var runtime_zero: usize = 0;
3961 _ = &runtime_zero;
3960 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);3962 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
3961 try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);3963 try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
3962 }3964 }
...@@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" {...@@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" {
3967 a: u8,3969 a: u8,
3968 };3970 };
39693971
3970 var b = [1]u8{9};3972 const b: [1]u8 = .{9};
3971 var f = bytesAsSlice(F, &b);3973 const f = bytesAsSlice(F, &b);
3972 try testing.expect(f[0].a == 9);3974 try testing.expect(f[0].a == 9);
3973}3975}
39743976
...@@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward");...@@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward");
4120/// result eventually gets discarded.4122/// result eventually gets discarded.
4121// TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/61684123// TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/6168
4122pub fn doNotOptimizeAway(val: anytype) void {4124pub fn doNotOptimizeAway(val: anytype) void {
4123 var a: u8 = 0;4125 if (@inComptime()) return;
4124 if (@typeInfo(@TypeOf(.{a})).Struct.fields[0].is_comptime) return;
41254126
4126 const max_gp_register_bits = @bitSizeOf(c_long);4127 const max_gp_register_bits = @bitSizeOf(c_long);
4127 const t = @typeInfo(@TypeOf(val));4128 const t = @typeInfo(@TypeOf(val));
lib/std/meta.zig+9-7
...@@ -738,7 +738,7 @@ test "std.meta.TagPayload" {...@@ -738,7 +738,7 @@ test "std.meta.TagPayload" {
738 },738 },
739 };739 };
740 const MovedEvent = TagPayload(Event, Event.Moved);740 const MovedEvent = TagPayload(Event, Event.Moved);
741 var e: Event = undefined;741 const e: Event = .{ .Moved = undefined };
742 try testing.expect(MovedEvent == @TypeOf(e.Moved));742 try testing.expect(MovedEvent == @TypeOf(e.Moved));
743}743}
744744
...@@ -839,9 +839,9 @@ test "std.meta.eql" {...@@ -839,9 +839,9 @@ test "std.meta.eql" {
839 try testing.expect(eql(u_1, u_3));839 try testing.expect(eql(u_1, u_3));
840 try testing.expect(!eql(u_1, u_2));840 try testing.expect(!eql(u_1, u_2));
841841
842 var a1 = "abcdef".*;842 const a1 = "abcdef".*;
843 var a2 = "abcdef".*;843 const a2 = "abcdef".*;
844 var a3 = "ghijkl".*;844 const a3 = "ghijkl".*;
845845
846 try testing.expect(eql(a1, a2));846 try testing.expect(eql(a1, a2));
847 try testing.expect(!eql(a1, a3));847 try testing.expect(!eql(a1, a3));
...@@ -859,9 +859,9 @@ test "std.meta.eql" {...@@ -859,9 +859,9 @@ test "std.meta.eql" {
859 try testing.expect(!eql(EU.tst(false), EU.tst(true)));859 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
860860
861 const V = @Vector(4, u32);861 const V = @Vector(4, u32);
862 var v1: V = @splat(1);862 const v1: V = @splat(1);
863 var v2: V = @splat(1);863 const v2: V = @splat(1);
864 var v3: V = @splat(2);864 const v3: V = @splat(2);
865865
866 try testing.expect(eql(v1, v2));866 try testing.expect(eql(v1, v2));
867 try testing.expect(!eql(v1, v3));867 try testing.expect(!eql(v1, v3));
...@@ -879,6 +879,8 @@ test "intToEnum with error return" {...@@ -879,6 +879,8 @@ test "intToEnum with error return" {
879879
880 var zero: u8 = 0;880 var zero: u8 = 0;
881 var one: u16 = 1;881 var one: u16 = 1;
882 _ = &zero;
883 _ = &one;
882 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);884 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
883 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);885 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
884 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);886 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);
lib/std/meta/trait.zig+5-2
...@@ -225,6 +225,7 @@ test "isSingleItemPtr" {...@@ -225,6 +225,7 @@ test "isSingleItemPtr" {
225 try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));225 try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
226 try comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));226 try comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
227 var runtime_zero: usize = 0;227 var runtime_zero: usize = 0;
228 _ = &runtime_zero;
228 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));229 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
229}230}
230231
...@@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool {...@@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool {
253test "isSlice" {254test "isSlice" {
254 const array = [_]u8{0} ** 10;255 const array = [_]u8{0} ** 10;
255 var runtime_zero: usize = 0;256 var runtime_zero: usize = 0;
257 _ = &runtime_zero;
256 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));258 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
257 try testing.expect(!isSlice(@TypeOf(array)));259 try testing.expect(!isSlice(@TypeOf(array)));
258 try testing.expect(!isSlice(@TypeOf(&array[0])));260 try testing.expect(!isSlice(@TypeOf(&array[0])));
...@@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool {...@@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool {
341}343}
342344
343test "isConstPtr" {345test "isConstPtr" {
344 var t = @as(u8, 0);346 var t: u8 = 0;
345 const c = @as(u8, 0);347 t = t;
348 const c: u8 = 0;
346 try testing.expect(isConstPtr(*const @TypeOf(t)));349 try testing.expect(isConstPtr(*const @TypeOf(t)));
347 try testing.expect(isConstPtr(@TypeOf(&c)));350 try testing.expect(isConstPtr(@TypeOf(&c)));
348 try testing.expect(!isConstPtr(*@TypeOf(t)));351 try testing.expect(!isConstPtr(*@TypeOf(t)));
lib/std/net.zig+4-4
...@@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream {...@@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream {
662fn if_nametoindex(name: []const u8) !u32 {662fn if_nametoindex(name: []const u8) !u32 {
663 if (builtin.target.os.tag == .linux) {663 if (builtin.target.os.tag == .linux) {
664 var ifr: os.ifreq = undefined;664 var ifr: os.ifreq = undefined;
665 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);665 const sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
666 defer os.closeSocket(sockfd);666 defer os.closeSocket(sockfd);
667667
668 @memcpy(ifr.ifrn.name[0..name.len], name);668 @memcpy(ifr.ifrn.name[0..name.len], name);
...@@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns(...@@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns(
1375 rc: ResolvConf,1375 rc: ResolvConf,
1376 port: u16,1376 port: u16,
1377) !void {1377) !void {
1378 var ctx = dpc_ctx{1378 const ctx = dpc_ctx{
1379 .addrs = addrs,1379 .addrs = addrs,
1380 .canon = canon,1380 .canon = canon,
1381 .port = port,1381 .port = port,
...@@ -1591,8 +1591,8 @@ fn resMSendRc(...@@ -1591,8 +1591,8 @@ fn resMSendRc(
1591 }};1591 }};
1592 const retry_interval = timeout / attempts;1592 const retry_interval = timeout / attempts;
1593 var next: u32 = 0;1593 var next: u32 = 0;
1594 var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp()));1594 var t2: u64 = @bitCast(std.time.milliTimestamp());
1595 var t0 = t2;1595 const t0 = t2;
1596 var t1 = t2 - retry_interval;1596 var t1 = t2 - retry_interval;
15971597
1598 var servfail_retry: usize = undefined;1598 var servfail_retry: usize = undefined;
lib/std/net/test.zig+5-5
...@@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" {...@@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" {
33 "::ffff:123.5.123.5",33 "::ffff:123.5.123.5",
34 };34 };
35 for (ips, 0..) |ip, i| {35 for (ips, 0..) |ip, i| {
36 var addr = net.Address.parseIp6(ip, 0) catch unreachable;36 const addr = net.Address.parseIp6(ip, 0) catch unreachable;
37 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;37 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
38 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));38 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
3939
40 if (builtin.os.tag == .linux) {40 if (builtin.os.tag == .linux) {
41 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;41 const addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
42 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;42 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
43 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));43 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
44 }44 }
...@@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" {...@@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" {
80 "123.255.0.91",80 "123.255.0.91",
81 "127.0.0.1",81 "127.0.0.1",
82 }) |ip| {82 }) |ip| {
83 var addr = net.Address.parseIp4(ip, 0) catch unreachable;83 const addr = net.Address.parseIp4(ip, 0) catch unreachable;
84 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;84 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
85 try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));85 try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
86 }86 }
...@@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" {...@@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" {
303 var server = net.StreamServer.init(.{});303 var server = net.StreamServer.init(.{});
304 defer server.deinit();304 defer server.deinit();
305305
306 var socket_path = try generateFileName("socket.unix");306 const socket_path = try generateFileName("socket.unix");
307 defer testing.allocator.free(socket_path);307 defer testing.allocator.free(socket_path);
308308
309 var socket_addr = try net.Address.initUnix(socket_path);309 const socket_addr = try net.Address.initUnix(socket_path);
310 defer std.fs.cwd().deleteFile(socket_path) catch {};310 defer std.fs.cwd().deleteFile(socket_path) catch {};
311 try server.listen(socket_addr);311 try server.listen(socket_addr);
312312
lib/std/os.zig+6-6
...@@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr...@@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr
4642 const path_w = try windows.sliceToPrefixedFileW(dirfd, path);4642 const path_w = try windows.sliceToPrefixedFileW(dirfd, path);
4643 return faccessatW(dirfd, path_w.span().ptr, mode, flags);4643 return faccessatW(dirfd, path_w.span().ptr, mode, flags);
4644 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {4644 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
4645 var resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path };4645 const resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path };
46464646
4647 const file = blk: {4647 const file = blk: {
4648 break :blk fstatat(dirfd, path, flags);4648 break :blk fstatat(dirfd, path, flags);
...@@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {...@@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
4775 }4775 }
4776 }4776 }
47774777
4778 var fds: [2]fd_t = try pipe();4778 const fds: [2]fd_t = try pipe();
4779 errdefer {4779 errdefer {
4780 close(fds[0]);4780 close(fds[0]);
4781 close(fds[1]);4781 close(fds[1]);
...@@ -6709,7 +6709,7 @@ pub fn dn_expand(...@@ -6709,7 +6709,7 @@ pub fn dn_expand(
6709 // loop invariants: p<end, dest<dend6709 // loop invariants: p<end, dest<dend
6710 if ((p[0] & 0xc0) != 0) {6710 if ((p[0] & 0xc0) != 0) {
6711 if (p + 1 == end) return error.InvalidDnsPacket;6711 if (p + 1 == end) return error.InvalidDnsPacket;
6712 var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];6712 const j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
6713 if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr);6713 if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr);
6714 if (j >= msg.len) return error.InvalidDnsPacket;6714 if (j >= msg.len) return error.InvalidDnsPacket;
6715 p = msg.ptr + j;6715 p = msg.ptr + j;
...@@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError;...@@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError;
7285pub const TimerFdSetError = TimerFdGetError || error{Canceled};7285pub const TimerFdSetError = TimerFdGetError || error{Canceled};
72867286
7287pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {7287pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
7288 var rc = linux.timerfd_create(clokid, flags);7288 const rc = linux.timerfd_create(clokid, flags);
7289 return switch (errno(rc)) {7289 return switch (errno(rc)) {
7290 .SUCCESS => @as(fd_t, @intCast(rc)),7290 .SUCCESS => @as(fd_t, @intCast(rc)),
7291 .INVAL => unreachable,7291 .INVAL => unreachable,
...@@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {...@@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
7299}7299}
73007300
7301pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void {7301pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void {
7302 var rc = linux.timerfd_settime(fd, flags, new_value, old_value);7302 const rc = linux.timerfd_settime(fd, flags, new_value, old_value);
7303 return switch (errno(rc)) {7303 return switch (errno(rc)) {
7304 .SUCCESS => {},7304 .SUCCESS => {},
7305 .BADF => error.InvalidHandle,7305 .BADF => error.InvalidHandle,
...@@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec,...@@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec,
73127312
7313pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec {7313pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec {
7314 var curr_value: linux.itimerspec = undefined;7314 var curr_value: linux.itimerspec = undefined;
7315 var rc = linux.timerfd_gettime(fd, &curr_value);7315 const rc = linux.timerfd_gettime(fd, &curr_value);
7316 return switch (errno(rc)) {7316 return switch (errno(rc)) {
7317 .SUCCESS => return curr_value,7317 .SUCCESS => return curr_value,
7318 .BADF => error.InvalidHandle,7318 .BADF => error.InvalidHandle,
lib/std/os/linux.zig+1
...@@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
1326 next_unsent = i + 1;1326 next_unsent = i + 1;
1327 break;1327 break;
1328 }1328 }
1329 size += iov.iov_len;
1329 }1330 }
1330 }1331 }
1331 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)1332 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)
lib/std/os/linux/io_uring.zig+20-19
...@@ -137,7 +137,7 @@ pub const IO_Uring = struct {...@@ -137,7 +137,7 @@ pub const IO_Uring = struct {
137 // We must therefore use wrapping addition and subtraction to avoid a runtime crash.137 // We must therefore use wrapping addition and subtraction to avoid a runtime crash.
138 const next = self.sq.sqe_tail +% 1;138 const next = self.sq.sqe_tail +% 1;
139 if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull;139 if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull;
140 var sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];140 const sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];
141 self.sq.sqe_tail = next;141 self.sq.sqe_tail = next;
142 return sqe;142 return sqe;
143 }143 }
...@@ -279,7 +279,7 @@ pub const IO_Uring = struct {...@@ -279,7 +279,7 @@ pub const IO_Uring = struct {
279 const ready = self.cq_ready();279 const ready = self.cq_ready();
280 const count = @min(cqes.len, ready);280 const count = @min(cqes.len, ready);
281 var head = self.cq.head.*;281 var head = self.cq.head.*;
282 var tail = head +% count;282 const tail = head +% count;
283 // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop.283 // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop.
284 var i: usize = 0;284 var i: usize = 0;
285 // Do not use "less-than" operator since head and tail may wrap:285 // Do not use "less-than" operator since head and tail may wrap:
...@@ -1916,7 +1916,7 @@ test "splice/read" {...@@ -1916,7 +1916,7 @@ test "splice/read" {
1916 var buffer_read = [_]u8{98} ** 20;1916 var buffer_read = [_]u8{98} ** 20;
1917 _ = try file_src.write(&buffer_write);1917 _ = try file_src.write(&buffer_write);
19181918
1919 var fds = try os.pipe();1919 const fds = try os.pipe();
1920 const pipe_offset: u64 = std.math.maxInt(u64);1920 const pipe_offset: u64 = std.math.maxInt(u64);
19211921
1922 const sqe_splice_to_pipe = try ring.splice(0x11111111, fd_src, 0, fds[1], pipe_offset, buffer_write.len);1922 const sqe_splice_to_pipe = try ring.splice(0x11111111, fd_src, 0, fds[1], pipe_offset, buffer_write.len);
...@@ -2045,6 +2045,7 @@ test "openat" {...@@ -2045,6 +2045,7 @@ test "openat" {
2045 // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/120142045 // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/12014
2046 const path_addr = if (builtin.zig_backend == .stage2_llvm) p: {2046 const path_addr = if (builtin.zig_backend == .stage2_llvm) p: {
2047 var workaround = path;2047 var workaround = path;
2048 _ = &workaround;
2048 break :p @intFromPtr(workaround);2049 break :p @intFromPtr(workaround);
2049 } else @intFromPtr(path);2050 } else @intFromPtr(path);
20502051
...@@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" {...@@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" {
2199 var iovecs_recv = [_]os.iovec{2200 var iovecs_recv = [_]os.iovec{
2200 os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len },2201 os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len },
2201 };2202 };
2202 var addr = [_]u8{0} ** 4;2203 const addr = [_]u8{0} ** 4;
2203 var address_recv = net.Address.initIp4(addr, 0);2204 var address_recv = net.Address.initIp4(addr, 0);
2204 var msg_recv: os.msghdr = os.msghdr{2205 var msg_recv: os.msghdr = os.msghdr{
2205 .name = &address_recv.any,2206 .name = &address_recv.any,
...@@ -2676,7 +2677,7 @@ test "shutdown" {...@@ -2676,7 +2677,7 @@ test "shutdown" {
2676 var slen: os.socklen_t = address.getOsSockLen();2677 var slen: os.socklen_t = address.getOsSockLen();
2677 try os.getsockname(server, &address.any, &slen);2678 try os.getsockname(server, &address.any, &slen);
26782679
2679 var shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD);2680 const shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD);
2680 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);2681 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);
2681 try testing.expectEqual(@as(i32, server), shutdown_sqe.fd);2682 try testing.expectEqual(@as(i32, server), shutdown_sqe.fd);
26822683
...@@ -2702,7 +2703,7 @@ test "shutdown" {...@@ -2702,7 +2703,7 @@ test "shutdown" {
2702 const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);2703 const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
2703 defer os.close(server);2704 defer os.close(server);
27042705
2705 var shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) {2706 const shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) {
2706 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),2707 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
2707 };2708 };
2708 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);2709 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);
...@@ -2740,7 +2741,7 @@ test "renameat" {...@@ -2740,7 +2741,7 @@ test "renameat" {
27402741
2741 // Submit renameat2742 // Submit renameat
27422743
2743 var sqe = try ring.renameat(2744 const sqe = try ring.renameat(
2744 0x12121212,2745 0x12121212,
2745 tmp.dir.fd,2746 tmp.dir.fd,
2746 old_path,2747 old_path,
...@@ -2807,7 +2808,7 @@ test "unlinkat" {...@@ -2807,7 +2808,7 @@ test "unlinkat" {
28072808
2808 // Submit unlinkat2809 // Submit unlinkat
28092810
2810 var sqe = try ring.unlinkat(2811 const sqe = try ring.unlinkat(
2811 0x12121212,2812 0x12121212,
2812 tmp.dir.fd,2813 tmp.dir.fd,
2813 path,2814 path,
...@@ -2854,7 +2855,7 @@ test "mkdirat" {...@@ -2854,7 +2855,7 @@ test "mkdirat" {
28542855
2855 // Submit mkdirat2856 // Submit mkdirat
28562857
2857 var sqe = try ring.mkdirat(2858 const sqe = try ring.mkdirat(
2858 0x12121212,2859 0x12121212,
2859 tmp.dir.fd,2860 tmp.dir.fd,
2860 path,2861 path,
...@@ -2902,7 +2903,7 @@ test "symlinkat" {...@@ -2902,7 +2903,7 @@ test "symlinkat" {
29022903
2903 // Submit symlinkat2904 // Submit symlinkat
29042905
2905 var sqe = try ring.symlinkat(2906 const sqe = try ring.symlinkat(
2906 0x12121212,2907 0x12121212,
2907 path,2908 path,
2908 tmp.dir.fd,2909 tmp.dir.fd,
...@@ -2953,7 +2954,7 @@ test "linkat" {...@@ -2953,7 +2954,7 @@ test "linkat" {
29532954
2954 // Submit linkat2955 // Submit linkat
29552956
2956 var sqe = try ring.linkat(2957 const sqe = try ring.linkat(
2957 0x12121212,2958 0x12121212,
2958 tmp.dir.fd,2959 tmp.dir.fd,
2959 first_path,2960 first_path,
...@@ -3032,7 +3033,7 @@ test "provide_buffers: read" {...@@ -3032,7 +3033,7 @@ test "provide_buffers: read" {
30323033
3033 var i: usize = 0;3034 var i: usize = 0;
3034 while (i < buffers.len) : (i += 1) {3035 while (i < buffers.len) : (i += 1) {
3035 var sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3036 const sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3036 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);3037 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
3037 try testing.expectEqual(@as(i32, fd), sqe.fd);3038 try testing.expectEqual(@as(i32, fd), sqe.fd);
3038 try testing.expectEqual(@as(u64, 0), sqe.addr);3039 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3058,7 +3059,7 @@ test "provide_buffers: read" {...@@ -3058,7 +3059,7 @@ test "provide_buffers: read" {
3058 // This read should fail3059 // This read should fail
30593060
3060 {3061 {
3061 var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3062 const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3062 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);3063 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
3063 try testing.expectEqual(@as(i32, fd), sqe.fd);3064 try testing.expectEqual(@as(i32, fd), sqe.fd);
3064 try testing.expectEqual(@as(u64, 0), sqe.addr);3065 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3097,7 +3098,7 @@ test "provide_buffers: read" {...@@ -3097,7 +3098,7 @@ test "provide_buffers: read" {
3097 // Final read which should work3098 // Final read which should work
30983099
3099 {3100 {
3100 var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3101 const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3101 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);3102 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
3102 try testing.expectEqual(@as(i32, fd), sqe.fd);3103 try testing.expectEqual(@as(i32, fd), sqe.fd);
3103 try testing.expectEqual(@as(u64, 0), sqe.addr);3104 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3158,7 +3159,7 @@ test "remove_buffers" {...@@ -3158,7 +3159,7 @@ test "remove_buffers" {
3158 // Remove 3 buffers3159 // Remove 3 buffers
31593160
3160 {3161 {
3161 var sqe = try ring.remove_buffers(0xbababababa, 3, group_id);3162 const sqe = try ring.remove_buffers(0xbababababa, 3, group_id);
3162 try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode);3163 try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode);
3163 try testing.expectEqual(@as(i32, 3), sqe.fd);3164 try testing.expectEqual(@as(i32, 3), sqe.fd);
3164 try testing.expectEqual(@as(u64, 0), sqe.addr);3165 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" {
32703271
3271 var i: usize = 0;3272 var i: usize = 0;
3272 while (i < buffers.len) : (i += 1) {3273 while (i < buffers.len) : (i += 1) {
3273 var sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3274 const sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3274 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);3275 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
3275 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);3276 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
3276 try testing.expectEqual(@as(u64, 0), sqe.addr);3277 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" {
3299 // This recv should fail3300 // This recv should fail
33003301
3301 {3302 {
3302 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3303 const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3303 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);3304 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
3304 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);3305 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
3305 try testing.expectEqual(@as(u64, 0), sqe.addr);3306 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" {
3349 @memset(mem.sliceAsBytes(&buffers), 1);3350 @memset(mem.sliceAsBytes(&buffers), 1);
33503351
3351 {3352 {
3352 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3353 const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3353 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);3354 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
3354 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);3355 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
3355 try testing.expectEqual(@as(u64, 0), sqe.addr);3356 try testing.expectEqual(@as(u64, 0), sqe.addr);
...@@ -3477,7 +3478,7 @@ test "accept multishot" {...@@ -3477,7 +3478,7 @@ test "accept multishot" {
3477 var nr: usize = 4; // number of clients to connect3478 var nr: usize = 4; // number of clients to connect
3478 while (nr > 0) : (nr -= 1) {3479 while (nr > 0) : (nr -= 1) {
3479 // connect client3480 // connect client
3480 var client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);3481 const client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
3481 errdefer os.closeSocket(client);3482 errdefer os.closeSocket(client);
3482 try os.connect(client, &address.any, address.getOsSockLen());3483 try os.connect(client, &address.any, address.getOsSockLen());
34833484
lib/std/os/plan9.zig+1-1
...@@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize {...@@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize {
278 bloc = @intFromPtr(&ExecData.end);278 bloc = @intFromPtr(&ExecData.end);
279 bloc_max = @intFromPtr(&ExecData.end);279 bloc_max = @intFromPtr(&ExecData.end);
280 }280 }
281 var bl = std.mem.alignForward(usize, bloc, std.mem.page_size);281 const bl = std.mem.alignForward(usize, bloc, std.mem.page_size);
282 const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size);282 const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size);
283 if (bl + n_aligned > bloc_max) {283 if (bl + n_aligned > bloc_max) {
284 // we need to allocate284 // we need to allocate
lib/std/os/test.zig+15-15
...@@ -58,7 +58,7 @@ test "chdir smoke test" {...@@ -58,7 +58,7 @@ test "chdir smoke test" {
58 {58 {
59 // Create a tmp directory59 // Create a tmp directory
60 var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined;60 var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
61 var tmp_dir_path = path: {61 const tmp_dir_path = path: {
62 var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf);62 var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf);
63 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" });63 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" });
64 };64 };
...@@ -72,7 +72,7 @@ test "chdir smoke test" {...@@ -72,7 +72,7 @@ test "chdir smoke test" {
7272
73 // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase73 // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase
74 var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;74 var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
75 var resolved_cwd = path: {75 const resolved_cwd = path: {
76 var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf);76 var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf);
77 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd});77 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd});
78 };78 };
...@@ -523,7 +523,7 @@ test "pipe" {...@@ -523,7 +523,7 @@ test "pipe" {
523 if (native_os == .windows or native_os == .wasi)523 if (native_os == .windows or native_os == .wasi)
524 return error.SkipZigTest;524 return error.SkipZigTest;
525525
526 var fds = try os.pipe();526 const fds = try os.pipe();
527 try expect((try os.write(fds[1], "hello")) == 5);527 try expect((try os.write(fds[1], "hello")) == 5);
528 var buf: [16]u8 = undefined;528 var buf: [16]u8 = undefined;
529 try expect((try os.read(fds[0], buf[0..])) == 5);529 try expect((try os.read(fds[0], buf[0..])) == 5);
...@@ -533,7 +533,7 @@ test "pipe" {...@@ -533,7 +533,7 @@ test "pipe" {
533}533}
534534
535test "argsAlloc" {535test "argsAlloc" {
536 var args = try std.process.argsAlloc(std.testing.allocator);536 const args = try std.process.argsAlloc(std.testing.allocator);
537 std.process.argsFree(std.testing.allocator, args);537 std.process.argsFree(std.testing.allocator, args);
538}538}
539539
...@@ -1087,7 +1087,7 @@ test "timerfd" {...@@ -1087,7 +1087,7 @@ test "timerfd" {
1087 return error.SkipZigTest;1087 return error.SkipZigTest;
10881088
1089 const linux = os.linux;1089 const linux = os.linux;
1090 var tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC);1090 const tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC);
1091 defer os.close(tfd);1091 defer os.close(tfd);
10921092
1093 // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call.1093 // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call.
...@@ -1097,8 +1097,8 @@ test "timerfd" {...@@ -1097,8 +1097,8 @@ test "timerfd" {
1097 var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }};1097 var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }};
1098 try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting1098 try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting
10991099
1100 var git = try os.timerfd_gettime(tfd);1100 const git = try os.timerfd_gettime(tfd);
1101 var expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };1101 const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
1102 try expectEqual(expect_disarmed_timer, git);1102 try expectEqual(expect_disarmed_timer, git);
1103}1103}
11041104
...@@ -1128,11 +1128,11 @@ test "read with empty buffer" {...@@ -1128,11 +1128,11 @@ test "read with empty buffer" {
1128 break :blk try fs.realpathAlloc(allocator, relative_path);1128 break :blk try fs.realpathAlloc(allocator, relative_path);
1129 };1129 };
11301130
1131 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });1131 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1132 var file = try fs.cwd().createFile(file_path, .{ .read = true });1132 var file = try fs.cwd().createFile(file_path, .{ .read = true });
1133 defer file.close();1133 defer file.close();
11341134
1135 var bytes = try allocator.alloc(u8, 0);1135 const bytes = try allocator.alloc(u8, 0);
11361136
1137 _ = try os.read(file.handle, bytes);1137 _ = try os.read(file.handle, bytes);
1138}1138}
...@@ -1153,11 +1153,11 @@ test "pread with empty buffer" {...@@ -1153,11 +1153,11 @@ test "pread with empty buffer" {
1153 break :blk try fs.realpathAlloc(allocator, relative_path);1153 break :blk try fs.realpathAlloc(allocator, relative_path);
1154 };1154 };
11551155
1156 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });1156 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1157 var file = try fs.cwd().createFile(file_path, .{ .read = true });1157 var file = try fs.cwd().createFile(file_path, .{ .read = true });
1158 defer file.close();1158 defer file.close();
11591159
1160 var bytes = try allocator.alloc(u8, 0);1160 const bytes = try allocator.alloc(u8, 0);
11611161
1162 _ = try os.pread(file.handle, bytes, 0);1162 _ = try os.pread(file.handle, bytes, 0);
1163}1163}
...@@ -1178,11 +1178,11 @@ test "write with empty buffer" {...@@ -1178,11 +1178,11 @@ test "write with empty buffer" {
1178 break :blk try fs.realpathAlloc(allocator, relative_path);1178 break :blk try fs.realpathAlloc(allocator, relative_path);
1179 };1179 };
11801180
1181 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });1181 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1182 var file = try fs.cwd().createFile(file_path, .{});1182 var file = try fs.cwd().createFile(file_path, .{});
1183 defer file.close();1183 defer file.close();
11841184
1185 var bytes = try allocator.alloc(u8, 0);1185 const bytes = try allocator.alloc(u8, 0);
11861186
1187 _ = try os.write(file.handle, bytes);1187 _ = try os.write(file.handle, bytes);
1188}1188}
...@@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" {...@@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" {
1203 break :blk try fs.realpathAlloc(allocator, relative_path);1203 break :blk try fs.realpathAlloc(allocator, relative_path);
1204 };1204 };
12051205
1206 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });1206 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1207 var file = try fs.cwd().createFile(file_path, .{});1207 var file = try fs.cwd().createFile(file_path, .{});
1208 defer file.close();1208 defer file.close();
12091209
1210 var bytes = try allocator.alloc(u8, 0);1210 const bytes = try allocator.alloc(u8, 0);
12111211
1212 _ = try os.pwrite(file.handle, bytes, 0);1212 _ = try os.pwrite(file.handle, bytes, 0);
1213}1213}
lib/std/os/uefi.zig+3-4
...@@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct {...@@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct {
149pub const FileHandle = *opaque {};149pub const FileHandle = *opaque {};
150150
151test "GUID formatting" {151test "GUID formatting" {
152 var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };152 const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
153 const guid: Guid = @bitCast(bytes);
153154
154 var guid = @as(Guid, @bitCast(bytes));155 const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
155
156 var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
157 defer std.testing.allocator.free(str);156 defer std.testing.allocator.free(str);
158157
159 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));158 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
lib/std/os/uefi/device_path.zig+2-2
...@@ -213,7 +213,7 @@ pub const DevicePath = union(Type) {...@@ -213,7 +213,7 @@ pub const DevicePath = union(Type) {
213 // multiple adr entries can optionally follow213 // multiple adr entries can optionally follow
214 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {214 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
215 // self.length is a minimum of 8 with one adr which is size 4.215 // self.length is a minimum of 8 with one adr which is size 4.
216 var entries = (self.length - 4) / @sizeOf(u32);216 const entries = (self.length - 4) / @sizeOf(u32);
217 return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries];217 return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries];
218 }218 }
219 };219 };
...@@ -431,7 +431,7 @@ pub const DevicePath = union(Type) {...@@ -431,7 +431,7 @@ pub const DevicePath = union(Type) {
431 device_product_id: u16 align(1),431 device_product_id: u16 align(1),
432432
433 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {433 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {
434 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);434 const serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
435 return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len];435 return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len];
436 }436 }
437 };437 };
lib/std/os/uefi/pool_allocator.zig+1-1
...@@ -34,7 +34,7 @@ const UefiPoolAllocator = struct {...@@ -34,7 +34,7 @@ const UefiPoolAllocator = struct {
34 const unaligned_addr = @intFromPtr(unaligned_ptr);34 const unaligned_addr = @intFromPtr(unaligned_ptr);
35 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align);35 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align);
3636
37 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);37 const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
38 getHeader(aligned_ptr).* = unaligned_ptr;38 getHeader(aligned_ptr).* = unaligned_ptr;
3939
40 return aligned_ptr;40 return aligned_ptr;
lib/std/os/uefi/protocol/device_path.zig+2-3
...@@ -43,7 +43,7 @@ pub const DevicePath = extern struct {...@@ -43,7 +43,7 @@ pub const DevicePath = extern struct {
4343
44 /// Creates a file device path from the existing device path and a file path.44 /// Creates a file device path from the existing device path and a file path.
45 pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath {45 pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath {
46 var path_size = self.size();46 const path_size = self.size();
4747
48 // 2 * (path.len + 1) for the path and its null terminator, which are u16s48 // 2 * (path.len + 1) for the path and its null terminator, which are u16s
49 // DevicePath for the extra node before the end49 // DevicePath for the extra node before the end
...@@ -82,8 +82,7 @@ pub const DevicePath = extern struct {...@@ -82,8 +82,7 @@ pub const DevicePath = extern struct {
82 // Got the associated union type for self.type, now82 // Got the associated union type for self.type, now
83 // we need to initialize it and its subtype83 // we need to initialize it and its subtype
84 if (self.type == enum_value) {84 if (self.type == enum_value) {
85 var subtype = self.initSubtype(ufield.type);85 const subtype = self.initSubtype(ufield.type);
86
87 if (subtype) |sb| {86 if (subtype) |sb| {
88 // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } }87 // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } }
89 return @unionInit(uefi.DevicePath, ufield.name, sb);88 return @unionInit(uefi.DevicePath, ufield.name, sb);
lib/std/os/windows.zig+3-3
...@@ -1166,7 +1166,7 @@ test "QueryObjectName" {...@@ -1166,7 +1166,7 @@ test "QueryObjectName" {
1166 const handle = tmp.dir.fd;1166 const handle = tmp.dir.fd;
1167 var out_buffer: [PATH_MAX_WIDE]u16 = undefined;1167 var out_buffer: [PATH_MAX_WIDE]u16 = undefined;
11681168
1169 var result_path = try QueryObjectName(handle, &out_buffer);1169 const result_path = try QueryObjectName(handle, &out_buffer);
1170 const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1;1170 const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1;
1171 //insufficient size1171 //insufficient size
1172 try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));1172 try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
...@@ -2045,8 +2045,8 @@ pub fn eqlIgnoreCaseUtf8(a: []const u8, b: []const u8) bool {...@@ -2045,8 +2045,8 @@ pub fn eqlIgnoreCaseUtf8(a: []const u8, b: []const u8) bool {
2045 };2045 };
20462046
2047 while (true) {2047 while (true) {
2048 var a_cp = a_utf8_it.nextCodepoint() orelse break;2048 const a_cp = a_utf8_it.nextCodepoint() orelse break;
2049 var b_cp = b_utf8_it.nextCodepoint() orelse return false;2049 const b_cp = b_utf8_it.nextCodepoint() orelse return false;
20502050
2051 if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) {2051 if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) {
2052 if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) {2052 if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) {
lib/std/pdb.zig+1-1
...@@ -897,7 +897,7 @@ const Msf = struct {...@@ -897,7 +897,7 @@ const Msf = struct {
897 return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment.897 return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment.
898898
899 try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr);899 try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr);
900 var dir_blocks = try allocator.alloc(u32, dir_block_count);900 const dir_blocks = try allocator.alloc(u32, dir_block_count);
901 for (dir_blocks) |*b| {901 for (dir_blocks) |*b| {
902 b.* = try in.readInt(u32, .little);902 b.* = try in.readInt(u32, .little);
903 }903 }
lib/std/priority_dequeue.zig+5-5
...@@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar...@@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
82 };82 };
8383
84 fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer {84 fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer {
85 var child_index = index;85 const child_index = index;
86 var parent_index = parentIndex(child_index);86 const parent_index = parentIndex(child_index);
87 const parent = self.items[parent_index];87 const parent = self.items[parent_index];
8888
89 const min_layer = self.nextIsMinLayer();89 const min_layer = self.nextIsMinLayer();
...@@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar...@@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
115 fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void {115 fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void {
116 var child_index = start_index;116 var child_index = start_index;
117 while (child_index > 2) {117 while (child_index > 2) {
118 var grandparent_index = grandparentIndex(child_index);118 const grandparent_index = grandparentIndex(child_index);
119 const child = self.items[child_index];119 const child = self.items[child_index];
120 const grandparent = self.items[grandparent_index];120 const grandparent = self.items[grandparent_index];
121121
...@@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar...@@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
286 }286 }
287287
288 fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex {288 fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex {
289 var item1 = self.getItem(index1);289 const item1 = self.getItem(index1);
290 var item2 = self.getItem(index2);290 const item2 = self.getItem(index2);
291 return self.bestItem(item1, item2, target_order);291 return self.bestItem(item1, item2, target_order);
292 }292 }
293293
lib/std/priority_queue.zig+1-1
...@@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" {...@@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" {
470 break idx;470 break idx;
471 idx += 1;471 idx += 1;
472 } else unreachable;472 } else unreachable;
473 var sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 };473 const sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 };
474 try expectEqual(queue.removeIndex(two_idx), 2);474 try expectEqual(queue.removeIndex(two_idx), 2);
475475
476 var i: usize = 0;476 var i: usize = 0;
lib/std/process.zig+12-12
...@@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {...@@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {
298 return result;298 return result;
299 }299 }
300300
301 var environ = try allocator.alloc([*:0]u8, environ_count);301 const environ = try allocator.alloc([*:0]u8, environ_count);
302 defer allocator.free(environ);302 defer allocator.free(environ);
303 var environ_buf = try allocator.alloc(u8, environ_buf_size);303 const environ_buf = try allocator.alloc(u8, environ_buf_size);
304 defer allocator.free(environ_buf);304 defer allocator.free(environ_buf);
305305
306 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);306 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);
...@@ -412,7 +412,7 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool...@@ -412,7 +412,7 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool
412}412}
413413
414test "os.getEnvVarOwned" {414test "os.getEnvVarOwned" {
415 var ga = std.testing.allocator;415 const ga = std.testing.allocator;
416 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));416 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
417}417}
418418
...@@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct {...@@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct {
477 return &[_][:0]u8{};477 return &[_][:0]u8{};
478 }478 }
479479
480 var argv = try allocator.alloc([*:0]u8, count);480 const argv = try allocator.alloc([*:0]u8, count);
481 defer allocator.free(argv);481 defer allocator.free(argv);
482482
483 var argv_buf = try allocator.alloc(u8, buf_size);483 const argv_buf = try allocator.alloc(u8, buf_size);
484484
485 switch (w.args_get(argv.ptr, argv_buf.ptr)) {485 switch (w.args_get(argv.ptr, argv_buf.ptr)) {
486 .SUCCESS => {},486 .SUCCESS => {},
...@@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {...@@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
551551
552 /// cmd_line_utf8 MUST remain valid and constant while using this instance552 /// cmd_line_utf8 MUST remain valid and constant while using this instance
553 pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {553 pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {
554 var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);554 const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
555 errdefer allocator.free(buffer);555 errdefer allocator.free(buffer);
556556
557 return Self{557 return Self{
...@@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {...@@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
564564
565 /// cmd_line_utf8 will be free'd (with the allocator) on deinit()565 /// cmd_line_utf8 will be free'd (with the allocator) on deinit()
566 pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {566 pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {
567 var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);567 const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
568 errdefer allocator.free(buffer);568 errdefer allocator.free(buffer);
569569
570 return Self{570 return Self{
...@@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {...@@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
577577
578 /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer578 /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer
579 pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self {579 pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self {
580 var utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0);580 const utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0);
581 var cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) {581 const cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) {
582 error.ExpectedSecondSurrogateHalf,582 error.ExpectedSecondSurrogateHalf,
583 error.DanglingSurrogateHalf,583 error.DanglingSurrogateHalf,
584 error.UnexpectedSecondSurrogateHalf,584 error.UnexpectedSecondSurrogateHalf,
...@@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {...@@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
588 };588 };
589 errdefer allocator.free(cmd_line);589 errdefer allocator.free(cmd_line);
590590
591 var buffer = try allocator.alloc(u8, cmd_line.len + 1);591 const buffer = try allocator.alloc(u8, cmd_line.len + 1);
592 errdefer allocator.free(buffer);592 errdefer allocator.free(buffer);
593593
594 return Self{594 return Self{
...@@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {...@@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
681 0 => {681 0 => {
682 self.emitBackslashes(backslash_count);682 self.emitBackslashes(backslash_count);
683 self.buffer[self.end] = 0;683 self.buffer[self.end] = 0;
684 var token = self.buffer[self.start..self.end :0];684 const token = self.buffer[self.start..self.end :0];
685 self.end += 1;685 self.end += 1;
686 self.start = self.end;686 self.start = self.end;
687 return token;687 return token;
...@@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {...@@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
713 self.emitCharacter(character);713 self.emitCharacter(character);
714 } else {714 } else {
715 self.buffer[self.end] = 0;715 self.buffer[self.end] = 0;
716 var token = self.buffer[self.start..self.end :0];716 const token = self.buffer[self.start..self.end :0];
717 self.end += 1;717 self.end += 1;
718 self.start = self.end;718 self.start = self.end;
719 return token;719 return token;
lib/std/rand/test.zig+2-2
...@@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" {...@@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" {
332 while (i < num_numbers) : (i += 1) {332 while (i < num_numbers) : (i += 1) {
333 const rand_f32 = random.float(f32);333 const rand_f32 = random.float(f32);
334 const rand_f64 = random.float(f64);334 const rand_f64 = random.float(f64);
335 var f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));335 const f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));
336 if (f32_put.found_existing) {336 if (f32_put.found_existing) {
337 f32_put.value_ptr.* += 1;337 f32_put.value_ptr.* += 1;
338 } else {338 } else {
339 f32_put.value_ptr.* = 1;339 f32_put.value_ptr.* = 1;
340 }340 }
341 var f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));341 const f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));
342 if (f64_put.found_existing) {342 if (f64_put.found_existing) {
343 f64_put.value_ptr.* += 1;343 f64_put.value_ptr.* += 1;
344 } else {344 } else {
lib/std/sort.zig+1-1
...@@ -387,7 +387,7 @@ test "sort fuzz testing" {...@@ -387,7 +387,7 @@ test "sort fuzz testing" {
387 var i: usize = 0;387 var i: usize = 0;
388 while (i < test_case_count) : (i += 1) {388 while (i < test_case_count) : (i += 1) {
389 const array_size = random.intRangeLessThan(usize, 0, 1000);389 const array_size = random.intRangeLessThan(usize, 0, 1000);
390 var array = try testing.allocator.alloc(i32, array_size);390 const array = try testing.allocator.alloc(i32, array_size);
391 defer testing.allocator.free(array);391 defer testing.allocator.free(array);
392 // populate with random data392 // populate with random data
393 for (array) |*item| {393 for (array) |*item| {
lib/std/sort/block.zig+2-2
...@@ -302,8 +302,8 @@ pub fn block(...@@ -302,8 +302,8 @@ pub fn block(
302 } else {302 } else {
303 iterator.begin();303 iterator.begin();
304 while (!iterator.finished()) {304 while (!iterator.finished()) {
305 var A = iterator.nextRange();305 const A = iterator.nextRange();
306 var B = iterator.nextRange();306 const B = iterator.nextRange();
307307
308 if (lessThan(context, items[B.end - 1], items[A.start])) {308 if (lessThan(context, items[B.end - 1], items[A.start])) {
309 // the two ranges are in reverse order, so a simple rotation should fix it309 // the two ranges are in reverse order, so a simple rotation should fix it
lib/std/sort/pdq.zig+4-4
...@@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint {...@@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint {
276 // max_swaps is the maximum number of swaps allowed in this function276 // max_swaps is the maximum number of swaps allowed in this function
277 const max_swaps = 4 * 3;277 const max_swaps = 4 * 3;
278278
279 var len = b - a;279 const len = b - a;
280 var i = a + len / 4 * 1;280 const i = a + len / 4 * 1;
281 var j = a + len / 4 * 2;281 const j = a + len / 4 * 2;
282 var k = a + len / 4 * 3;282 const k = a + len / 4 * 3;
283 var swaps: usize = 0;283 var swaps: usize = 0;
284284
285 if (len >= 8) {285 if (len >= 8) {
lib/std/tar.zig+1-1
...@@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
218 if (file_size == 0 and unstripped_file_name.len == 0) return;218 if (file_size == 0 and unstripped_file_name.len == 0) return;
219 const file_name = try stripComponents(unstripped_file_name, options.strip_components);219 const file_name = try stripComponents(unstripped_file_name, options.strip_components);
220220
221 var file = dir.createFile(file_name, .{}) catch |err| switch (err) {221 const file = dir.createFile(file_name, .{}) catch |err| switch (err) {
222 error.FileNotFound => again: {222 error.FileNotFound => again: {
223 const code = code: {223 const code = code: {
224 if (std.fs.path.dirname(file_name)) |dir_name| {224 if (std.fs.path.dirname(file_name)) |dir_name| {
lib/std/testing.zig+10-10
...@@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type {...@@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type {
399399
400 pub fn write(self: Self, writer: anytype) !void {400 pub fn write(self: Self, writer: anytype) !void {
401 for (self.expected, 0..) |value, i| {401 for (self.expected, 0..) |value, i| {
402 var full_index = self.start_index + i;402 const full_index = self.start_index + i;
403 const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;403 const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;
404 if (diff) try self.ttyconf.setColor(writer, .red);404 if (diff) try self.ttyconf.setColor(writer, .red);
405 if (@typeInfo(T) == .Pointer) {405 if (@typeInfo(T) == .Pointer) {
...@@ -424,7 +424,7 @@ const BytesDiffer = struct {...@@ -424,7 +424,7 @@ const BytesDiffer = struct {
424 // to avoid having to calculate diffs twice per chunk424 // to avoid having to calculate diffs twice per chunk
425 var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 };425 var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 };
426 for (chunk, 0..) |byte, i| {426 for (chunk, 0..) |byte, i| {
427 var absolute_byte_index = (expected_iterator.index - chunk.len) + i;427 const absolute_byte_index = (expected_iterator.index - chunk.len) + i;
428 const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true;428 const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true;
429 if (diff) diffs.set(i);429 if (diff) diffs.set(i);
430 try self.writeByteDiff(writer, "{X:0>2} ", byte, diff);430 try self.writeByteDiff(writer, "{X:0>2} ", byte, diff);
...@@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {...@@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {
565 var sub_path: [TmpDir.sub_path_len]u8 = undefined;565 var sub_path: [TmpDir.sub_path_len]u8 = undefined;
566 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);566 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
567567
568 var cwd = std.fs.cwd();568 const cwd = std.fs.cwd();
569 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch569 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
570 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");570 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
571 defer cache_dir.close();571 defer cache_dir.close();
572 var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch572 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
573 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");573 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
574 var dir = parent_dir.makeOpenPath(&sub_path, opts) catch574 const dir = parent_dir.makeOpenPath(&sub_path, opts) catch
575 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");575 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
576576
577 return .{577 return .{
...@@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir {...@@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir {
587 var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined;587 var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined;
588 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);588 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
589589
590 var cwd = std.fs.cwd();590 const cwd = std.fs.cwd();
591 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch591 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
592 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");592 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
593 defer cache_dir.close();593 defer cache_dir.close();
594 var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch594 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
595 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");595 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
596 var dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch596 const dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch
597 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");597 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
598598
599 return .{599 return .{
...@@ -618,8 +618,8 @@ test "expectEqual nested array" {...@@ -618,8 +618,8 @@ test "expectEqual nested array" {
618}618}
619619
620test "expectEqual vector" {620test "expectEqual vector" {
621 var a: @Vector(4, u32) = @splat(4);621 const a: @Vector(4, u32) = @splat(4);
622 var b: @Vector(4, u32) = @splat(4);622 const b: @Vector(4, u32) = @splat(4);
623623
624 try expectEqual(a, b);624 try expectEqual(a, b);
625}625}
lib/std/treap.zig+1-1
...@@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" {...@@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" {
379 const key = node.key;379 const key = node.key;
380380
381 // find the entry by-key and by-node after having been inserted.381 // find the entry by-key and by-node after having been inserted.
382 var entry = treap.getEntryFor(node.key);382 const entry = treap.getEntryFor(node.key);
383 try testing.expectEqual(entry.key, key);383 try testing.expectEqual(entry.key, key);
384 try testing.expectEqual(entry.node, node);384 try testing.expectEqual(entry.node, node);
385 try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node);385 try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node);
lib/std/unicode.zig+1-1
...@@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool {...@@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool {
242 s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,242 s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
243 };243 };
244244
245 var n = remaining.len;245 const n = remaining.len;
246 var i: usize = 0;246 var i: usize = 0;
247 while (i < n) {247 while (i < n) {
248 const first_byte = remaining[i];248 const first_byte = remaining[i];
lib/std/zig/Parse.zig+1-2
...@@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {...@@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
3516 var saw_const = false;3516 var saw_const = false;
3517 var saw_volatile = false;3517 var saw_volatile = false;
3518 var saw_allowzero = false;3518 var saw_allowzero = false;
3519 var saw_addrspace = false;
3520 while (true) {3519 while (true) {
3521 switch (p.token_tags[p.tok_i]) {3520 switch (p.token_tags[p.tok_i]) {
3522 .keyword_align => {3521 .keyword_align => {
...@@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {...@@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
3557 saw_allowzero = true;3556 saw_allowzero = true;
3558 },3557 },
3559 .keyword_addrspace => {3558 .keyword_addrspace => {
3560 if (saw_addrspace) {3559 if (result.addrspace_node != 0) {
3561 try p.warn(.extra_addrspace_qualifier);3560 try p.warn(.extra_addrspace_qualifier);
3562 }3561 }
3563 result.addrspace_node = try p.parseAddrSpace();3562 result.addrspace_node = try p.parseAddrSpace();
lib/std/zig/c_translation.zig+8-7
...@@ -129,6 +129,7 @@ test "cast" {...@@ -129,6 +129,7 @@ test "cast" {
129 try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2))));129 try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2))));
130130
131 var foo: c_int = -1;131 var foo: c_int = -1;
132 _ = &foo;
132 try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));133 try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
133 try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));134 try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
134 try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));135 try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
...@@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" {...@@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" {
601 a: u32 = 0,602 a: u32 = 0,
602 b: u32 = 0,603 b: u32 = 0,
603 };604 };
604 var x = S{};605 const x = S{};
605 var y = S{};606 const y = S{};
606 var ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b");607 const ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b");
607 try testing.expectEqual(&x, ptr);608 try testing.expectEqual(&x, ptr);
608}609}
609610
610test "CAST_OR_CALL casting" {611test "CAST_OR_CALL casting" {
611 var arg = @as(c_int, 1000);612 const arg: c_int = 1000;
612 var casted = Macros.CAST_OR_CALL(u8, arg);613 const casted = Macros.CAST_OR_CALL(u8, arg);
613 try testing.expectEqual(cast(u8, arg), casted);614 try testing.expectEqual(cast(u8, arg), casted);
614615
615 const S = struct {616 const S = struct {
616 x: u32 = 0,617 x: u32 = 0,
617 };618 };
618 var s = S{};619 var s: S = .{};
619 var casted_ptr = Macros.CAST_OR_CALL(*u8, &s);620 const casted_ptr = Macros.CAST_OR_CALL(*u8, &s);
620 try testing.expectEqual(cast(*u8, &s), casted_ptr);621 try testing.expectEqual(cast(*u8, &s), casted_ptr);
621}622}
622623
lib/std/zig/perf_test.zig+1-1
...@@ -32,7 +32,7 @@ pub fn main() !void {...@@ -32,7 +32,7 @@ pub fn main() !void {
3232
33fn testOnce() usize {33fn testOnce() usize {
34 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);34 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
35 var allocator = fixed_buf_alloc.allocator();35 const allocator = fixed_buf_alloc.allocator();
36 _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure");36 _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure");
37 return fixed_buf_alloc.end_index;37 return fixed_buf_alloc.end_index;
38}38}
lib/std/zig/render.zig+1-1
...@@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {...@@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
3495 /// Turns all one-shot indents into regular indents3495 /// Turns all one-shot indents into regular indents
3496 /// Returns number of indents that must now be manually popped3496 /// Returns number of indents that must now be manually popped
3497 pub fn lockOneShotIndent(self: *Self) usize {3497 pub fn lockOneShotIndent(self: *Self) usize {
3498 var locked_count = self.indent_one_shot_count;3498 const locked_count = self.indent_one_shot_count;
3499 self.indent_one_shot_count = 0;3499 self.indent_one_shot_count = 0;
3500 return locked_count;3500 return locked_count;
3501 }3501 }
lib/std/zig/string_literal.zig+1-1
...@@ -288,7 +288,7 @@ test "parse" {...@@ -288,7 +288,7 @@ test "parse" {
288288
289 var fixed_buf_mem: [64]u8 = undefined;289 var fixed_buf_mem: [64]u8 = undefined;
290 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem);290 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem);
291 var alloc = fixed_buf_alloc.allocator();291 const alloc = fixed_buf_alloc.allocator();
292292
293 try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\""));293 try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\""));
294 try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\"")));294 try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\"")));
lib/std/zig/system/NativeTargetInfo.zig+1-1
...@@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {...@@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
189 // native CPU architecture as being different than the current target), we use this:189 // native CPU architecture as being different than the current target), we use this:
190 const cpu_arch = cross_target.getCpuArch();190 const cpu_arch = cross_target.getCpuArch();
191191
192 var cpu = switch (cross_target.cpu_model) {192 const cpu = switch (cross_target.cpu_model) {
193 .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target),193 .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target),
194 .baseline => Target.Cpu.baseline(cpu_arch),194 .baseline => Target.Cpu.baseline(cpu_arch),
195 .determined_by_cpu_arch => if (cross_target.cpu_arch == null)195 .determined_by_cpu_arch => if (cross_target.cpu_arch == null)