authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-02-25 21:29:56+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-01 13:57:41-05:00
log00be934569d25e3b041091ff63a4cf6c456d1403
tree0e041a8f62b213acec0016cdb041fec59f50a07d
parent3c1432701129bacf95b944f0f86af2d96ae72c69

short std.builtin enum literals in std lib


19 files changed, 97 insertions(+), 103 deletions(-)

lib/std/build.zig+4-4
...@@ -1898,10 +1898,10 @@ pub const LibExeObjStep = struct {...@@ -1898,10 +1898,10 @@ pub const LibExeObjStep = struct {
1898 }1898 }
18991899
1900 switch (self.build_mode) {1900 switch (self.build_mode) {
1901 builtin.Mode.Debug => {},1901 .Debug => {},
1902 builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,1902 .ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
1903 builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,1903 .ReleaseFast => zig_args.append("--release-fast") catch unreachable,
1904 builtin.Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,1904 .ReleaseSmall => zig_args.append("--release-small") catch unreachable,
1905 }1905 }
19061906
1907 try zig_args.append("--cache-dir");1907 try zig_args.append("--cache-dir");
lib/std/crypto/benchmark.zig+1-1
...@@ -120,7 +120,7 @@ fn usage() void {...@@ -120,7 +120,7 @@ fn usage() void {
120}120}
121121
122fn mode(comptime x: comptime_int) comptime_int {122fn mode(comptime x: comptime_int) comptime_int {
123 return if (builtin.mode == builtin.Mode.Debug) x / 64 else x;123 return if (builtin.mode == .Debug) x / 64 else x;
124}124}
125125
126// TODO(#1358): Replace with builtin formatted padding when available.126// TODO(#1358): Replace with builtin formatted padding when available.
lib/std/elf.zig+2-2
...@@ -370,8 +370,8 @@ pub const Elf = struct {...@@ -370,8 +370,8 @@ pub const Elf = struct {
370 };370 };
371371
372 elf.endian = switch (try in.readByte()) {372 elf.endian = switch (try in.readByte()) {
373 1 => builtin.Endian.Little,373 1 => .Little,
374 2 => builtin.Endian.Big,374 2 => .Big,
375 else => return error.InvalidFormat,375 else => return error.InvalidFormat,
376 };376 };
377377
lib/std/hash/auto_hash.zig+3-5
...@@ -25,13 +25,13 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {...@@ -25,13 +25,13 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
25 const info = @typeInfo(@TypeOf(key));25 const info = @typeInfo(@TypeOf(key));
2626
27 switch (info.Pointer.size) {27 switch (info.Pointer.size) {
28 builtin.TypeInfo.Pointer.Size.One => switch (strat) {28 .One => switch (strat) {
29 .Shallow => hash(hasher, @ptrToInt(key), .Shallow),29 .Shallow => hash(hasher, @ptrToInt(key), .Shallow),
30 .Deep => hash(hasher, key.*, .Shallow),30 .Deep => hash(hasher, key.*, .Shallow),
31 .DeepRecursive => hash(hasher, key.*, .DeepRecursive),31 .DeepRecursive => hash(hasher, key.*, .DeepRecursive),
32 },32 },
3333
34 builtin.TypeInfo.Pointer.Size.Slice => switch (strat) {34 .Slice => switch (strat) {
35 .Shallow => {35 .Shallow => {
36 hashPointer(hasher, key.ptr, .Shallow);36 hashPointer(hasher, key.ptr, .Shallow);
37 hash(hasher, key.len, .Shallow);37 hash(hasher, key.len, .Shallow);
...@@ -40,9 +40,7 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {...@@ -40,9 +40,7 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
40 .DeepRecursive => hashArray(hasher, key, .DeepRecursive),40 .DeepRecursive => hashArray(hasher, key, .DeepRecursive),
41 },41 },
4242
43 builtin.TypeInfo.Pointer.Size.Many,43 .Many, .C, => switch (strat) {
44 builtin.TypeInfo.Pointer.Size.C,
45 => switch (strat) {
46 .Shallow => hash(hasher, @ptrToInt(key), .Shallow),44 .Shallow => hash(hasher, @ptrToInt(key), .Shallow),
47 else => @compileError(45 else => @compileError(
48 \\ unknown-length pointers and C pointers cannot be hashed deeply.46 \\ unknown-length pointers and C pointers cannot be hashed deeply.
lib/std/hash/benchmark.zig+1-1
...@@ -168,7 +168,7 @@ fn usage() void {...@@ -168,7 +168,7 @@ fn usage() void {
168}168}
169169
170fn mode(comptime x: comptime_int) comptime_int {170fn mode(comptime x: comptime_int) comptime_int {
171 return if (builtin.mode == builtin.Mode.Debug) x / 64 else x;171 return if (builtin.mode == .Debug) x / 64 else x;
172}172}
173173
174pub fn main() !void {174pub fn main() !void {
lib/std/hash/cityhash.zig+4-4
...@@ -11,7 +11,7 @@ pub const CityHash32 = struct {...@@ -11,7 +11,7 @@ pub const CityHash32 = struct {
11 fn fetch32(ptr: [*]const u8) u32 {11 fn fetch32(ptr: [*]const u8) u32 {
12 var v: u32 = undefined;12 var v: u32 = undefined;
13 @memcpy(@ptrCast([*]u8, &v), ptr, 4);13 @memcpy(@ptrCast([*]u8, &v), ptr, 4);
14 if (builtin.endian == builtin.Endian.Big)14 if (builtin.endian == .Big)
15 return @byteSwap(u32, v);15 return @byteSwap(u32, v);
16 return v;16 return v;
17 }17 }
...@@ -174,7 +174,7 @@ pub const CityHash64 = struct {...@@ -174,7 +174,7 @@ pub const CityHash64 = struct {
174 fn fetch32(ptr: [*]const u8) u32 {174 fn fetch32(ptr: [*]const u8) u32 {
175 var v: u32 = undefined;175 var v: u32 = undefined;
176 @memcpy(@ptrCast([*]u8, &v), ptr, 4);176 @memcpy(@ptrCast([*]u8, &v), ptr, 4);
177 if (builtin.endian == builtin.Endian.Big)177 if (builtin.endian == .Big)
178 return @byteSwap(u32, v);178 return @byteSwap(u32, v);
179 return v;179 return v;
180 }180 }
...@@ -182,7 +182,7 @@ pub const CityHash64 = struct {...@@ -182,7 +182,7 @@ pub const CityHash64 = struct {
182 fn fetch64(ptr: [*]const u8) u64 {182 fn fetch64(ptr: [*]const u8) u64 {
183 var v: u64 = undefined;183 var v: u64 = undefined;
184 @memcpy(@ptrCast([*]u8, &v), ptr, 8);184 @memcpy(@ptrCast([*]u8, &v), ptr, 8);
185 if (builtin.endian == builtin.Endian.Big)185 if (builtin.endian == .Big)
186 return @byteSwap(u64, v);186 return @byteSwap(u64, v);
187 return v;187 return v;
188 }188 }
...@@ -369,7 +369,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -369,7 +369,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
369 key[i] = @intCast(u8, i);369 key[i] = @intCast(u8, i);
370370
371 var h = hash_fn(key[0..i], 256 - i);371 var h = hash_fn(key[0..i], 256 - i);
372 if (builtin.endian == builtin.Endian.Big)372 if (builtin.endian == .Big)
373 h = @byteSwap(@TypeOf(h), h);373 h = @byteSwap(@TypeOf(h), h);
374 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);374 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
375 }375 }
lib/std/hash/murmur.zig+8-8
...@@ -17,7 +17,7 @@ pub const Murmur2_32 = struct {...@@ -17,7 +17,7 @@ pub const Murmur2_32 = struct {
17 var h1: u32 = seed ^ len;17 var h1: u32 = seed ^ len;
18 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {18 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
19 var k1: u32 = v;19 var k1: u32 = v;
20 if (builtin.endian == builtin.Endian.Big)20 if (builtin.endian == .Big)
21 k1 = @byteSwap(u32, k1);21 k1 = @byteSwap(u32, k1);
22 k1 *%= m;22 k1 *%= m;
23 k1 ^= k1 >> 24;23 k1 ^= k1 >> 24;
...@@ -102,7 +102,7 @@ pub const Murmur2_64 = struct {...@@ -102,7 +102,7 @@ pub const Murmur2_64 = struct {
102 var h1: u64 = seed ^ (len *% m);102 var h1: u64 = seed ^ (len *% m);
103 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {103 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104 var k1: u64 = v;104 var k1: u64 = v;
105 if (builtin.endian == builtin.Endian.Big)105 if (builtin.endian == .Big)
106 k1 = @byteSwap(u64, k1);106 k1 = @byteSwap(u64, k1);
107 k1 *%= m;107 k1 *%= m;
108 k1 ^= k1 >> 47;108 k1 ^= k1 >> 47;
...@@ -115,7 +115,7 @@ pub const Murmur2_64 = struct {...@@ -115,7 +115,7 @@ pub const Murmur2_64 = struct {
115 if (rest > 0) {115 if (rest > 0) {
116 var k1: u64 = 0;116 var k1: u64 = 0;
117 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));117 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
118 if (builtin.endian == builtin.Endian.Big)118 if (builtin.endian == .Big)
119 k1 = @byteSwap(u64, k1);119 k1 = @byteSwap(u64, k1);
120 h1 ^= k1;120 h1 ^= k1;
121 h1 *%= m;121 h1 *%= m;
...@@ -182,7 +182,7 @@ pub const Murmur3_32 = struct {...@@ -182,7 +182,7 @@ pub const Murmur3_32 = struct {
182 var h1: u32 = seed;182 var h1: u32 = seed;
183 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {183 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
184 var k1: u32 = v;184 var k1: u32 = v;
185 if (builtin.endian == builtin.Endian.Big)185 if (builtin.endian == .Big)
186 k1 = @byteSwap(u32, k1);186 k1 = @byteSwap(u32, k1);
187 k1 *%= c1;187 k1 *%= c1;
188 k1 = rotl32(k1, 15);188 k1 = rotl32(k1, 15);
...@@ -294,7 +294,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -294,7 +294,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
294 key[i] = @truncate(u8, i);294 key[i] = @truncate(u8, i);
295295
296 var h = hash_fn(key[0..i], 256 - i);296 var h = hash_fn(key[0..i], 256 - i);
297 if (builtin.endian == builtin.Endian.Big)297 if (builtin.endian == .Big)
298 h = @byteSwap(@TypeOf(h), h);298 h = @byteSwap(@TypeOf(h), h);
299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300 }300 }
...@@ -308,7 +308,7 @@ test "murmur2_32" {...@@ -308,7 +308,7 @@ test "murmur2_32" {
308 var v1: u64 = 0x1234567812345678;308 var v1: u64 = 0x1234567812345678;
309 var v0le: u32 = v0;309 var v0le: u32 = v0;
310 var v1le: u64 = v1;310 var v1le: u64 = v1;
311 if (builtin.endian == builtin.Endian.Big) {311 if (builtin.endian == .Big) {
312 v0le = @byteSwap(u32, v0le);312 v0le = @byteSwap(u32, v0le);
313 v1le = @byteSwap(u64, v1le);313 v1le = @byteSwap(u64, v1le);
314 }314 }
...@@ -322,7 +322,7 @@ test "murmur2_64" {...@@ -322,7 +322,7 @@ test "murmur2_64" {
322 var v1: u64 = 0x1234567812345678;322 var v1: u64 = 0x1234567812345678;
323 var v0le: u32 = v0;323 var v0le: u32 = v0;
324 var v1le: u64 = v1;324 var v1le: u64 = v1;
325 if (builtin.endian == builtin.Endian.Big) {325 if (builtin.endian == .Big) {
326 v0le = @byteSwap(u32, v0le);326 v0le = @byteSwap(u32, v0le);
327 v1le = @byteSwap(u64, v1le);327 v1le = @byteSwap(u64, v1le);
328 }328 }
...@@ -336,7 +336,7 @@ test "murmur3_32" {...@@ -336,7 +336,7 @@ test "murmur3_32" {
336 var v1: u64 = 0x1234567812345678;336 var v1: u64 = 0x1234567812345678;
337 var v0le: u32 = v0;337 var v0le: u32 = v0;
338 var v1le: u64 = v1;338 var v1le: u64 = v1;
339 if (builtin.endian == builtin.Endian.Big) {339 if (builtin.endian == .Big) {
340 v0le = @byteSwap(u32, v0le);340 v0le = @byteSwap(u32, v0le);
341 v1le = @byteSwap(u64, v1le);341 v1le = @byteSwap(u64, v1le);
342 }342 }
lib/std/hash_map.zig+1-1
...@@ -10,7 +10,7 @@ const Wyhash = std.hash.Wyhash;...@@ -10,7 +10,7 @@ const Wyhash = std.hash.Wyhash;
10const Allocator = mem.Allocator;10const Allocator = mem.Allocator;
11const builtin = @import("builtin");11const builtin = @import("builtin");
1212
13const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast;13const want_modification_safety = builtin.mode != .ReleaseFast;
14const debug_u32 = if (want_modification_safety) u32 else void;14const debug_u32 = if (want_modification_safety) u32 else void;
1515
16pub fn AutoHashMap(comptime K: type, comptime V: type) type {16pub fn AutoHashMap(comptime K: type, comptime V: type) type {
lib/std/io.zig+14-14
...@@ -348,11 +348,11 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -348,11 +348,11 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
348 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;348 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
349 const shift = u7_bit_count - n;349 const shift = u7_bit_count - n;
350 switch (endian) {350 switch (endian) {
351 builtin.Endian.Big => {351 .Big => {
352 out_buffer = @as(Buf, self.bit_buffer >> shift);352 out_buffer = @as(Buf, self.bit_buffer >> shift);
353 self.bit_buffer <<= n;353 self.bit_buffer <<= n;
354 },354 },
355 builtin.Endian.Little => {355 .Little => {
356 const value = (self.bit_buffer << shift) >> shift;356 const value = (self.bit_buffer << shift) >> shift;
357 out_buffer = @as(Buf, value);357 out_buffer = @as(Buf, value);
358 self.bit_buffer >>= n;358 self.bit_buffer >>= n;
...@@ -376,7 +376,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -376,7 +376,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
376 };376 };
377377
378 switch (endian) {378 switch (endian) {
379 builtin.Endian.Big => {379 .Big => {
380 if (n >= u8_bit_count) {380 if (n >= u8_bit_count) {
381 out_buffer <<= @intCast(u3, u8_bit_count - 1);381 out_buffer <<= @intCast(u3, u8_bit_count - 1);
382 out_buffer <<= 1;382 out_buffer <<= 1;
...@@ -392,7 +392,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {...@@ -392,7 +392,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
392 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));392 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
393 self.bit_count = shift;393 self.bit_count = shift;
394 },394 },
395 builtin.Endian.Little => {395 .Little => {
396 if (n >= u8_bit_count) {396 if (n >= u8_bit_count) {
397 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);397 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
398 out_bits.* += u8_bit_count;398 out_bits.* += u8_bit_count;
...@@ -666,8 +666,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {...@@ -666,8 +666,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
666666
667 const high_byte_shift = @intCast(BufShift, buf_bit_count - u8_bit_count);667 const high_byte_shift = @intCast(BufShift, buf_bit_count - u8_bit_count);
668 var in_buffer = switch (endian) {668 var in_buffer = switch (endian) {
669 builtin.Endian.Big => buf_value << @intCast(BufShift, buf_bit_count - bits),669 .Big => buf_value << @intCast(BufShift, buf_bit_count - bits),
670 builtin.Endian.Little => buf_value,670 .Little => buf_value,
671 };671 };
672 var in_bits = bits;672 var in_bits = bits;
673673
...@@ -675,13 +675,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {...@@ -675,13 +675,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
675 const bits_remaining = u8_bit_count - self.bit_count;675 const bits_remaining = u8_bit_count - self.bit_count;
676 const n = @intCast(u3, if (bits_remaining > bits) bits else bits_remaining);676 const n = @intCast(u3, if (bits_remaining > bits) bits else bits_remaining);
677 switch (endian) {677 switch (endian) {
678 builtin.Endian.Big => {678 .Big => {
679 const shift = @intCast(BufShift, high_byte_shift + self.bit_count);679 const shift = @intCast(BufShift, high_byte_shift + self.bit_count);
680 const v = @intCast(u8, in_buffer >> shift);680 const v = @intCast(u8, in_buffer >> shift);
681 self.bit_buffer |= v;681 self.bit_buffer |= v;
682 in_buffer <<= n;682 in_buffer <<= n;
683 },683 },
684 builtin.Endian.Little => {684 .Little => {
685 const v = @truncate(u8, in_buffer) << @intCast(u3, self.bit_count);685 const v = @truncate(u8, in_buffer) << @intCast(u3, self.bit_count);
686 self.bit_buffer |= v;686 self.bit_buffer |= v;
687 in_buffer >>= n;687 in_buffer >>= n;
...@@ -701,13 +701,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {...@@ -701,13 +701,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
701 //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer701 //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer
702 while (in_bits >= u8_bit_count) {702 while (in_bits >= u8_bit_count) {
703 switch (endian) {703 switch (endian) {
704 builtin.Endian.Big => {704 .Big => {
705 const v = @intCast(u8, in_buffer >> high_byte_shift);705 const v = @intCast(u8, in_buffer >> high_byte_shift);
706 try self.out_stream.writeByte(v);706 try self.out_stream.writeByte(v);
707 in_buffer <<= @intCast(u3, u8_bit_count - 1);707 in_buffer <<= @intCast(u3, u8_bit_count - 1);
708 in_buffer <<= 1;708 in_buffer <<= 1;
709 },709 },
710 builtin.Endian.Little => {710 .Little => {
711 const v = @truncate(u8, in_buffer);711 const v = @truncate(u8, in_buffer);
712 try self.out_stream.writeByte(v);712 try self.out_stream.writeByte(v);
713 in_buffer >>= @intCast(u3, u8_bit_count - 1);713 in_buffer >>= @intCast(u3, u8_bit_count - 1);
...@@ -720,8 +720,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {...@@ -720,8 +720,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
720 if (in_bits > 0) {720 if (in_bits > 0) {
721 self.bit_count = @intCast(u4, in_bits);721 self.bit_count = @intCast(u4, in_bits);
722 self.bit_buffer = switch (endian) {722 self.bit_buffer = switch (endian) {
723 builtin.Endian.Big => @truncate(u8, in_buffer >> high_byte_shift),723 .Big => @truncate(u8, in_buffer >> high_byte_shift),
724 builtin.Endian.Little => @truncate(u8, in_buffer),724 .Little => @truncate(u8, in_buffer),
725 };725 };
726 }726 }
727 }727 }
...@@ -858,10 +858,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -858,10 +858,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
858 var result = @as(U, 0);858 var result = @as(U, 0);
859 for (buffer) |byte, i| {859 for (buffer) |byte, i| {
860 switch (endian) {860 switch (endian) {
861 builtin.Endian.Big => {861 .Big => {
862 result = (result << u8_bit_count) | byte;862 result = (result << u8_bit_count) | byte;
863 },863 },
864 builtin.Endian.Little => {864 .Little => {
865 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);865 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
866 },866 },
867 }867 }
lib/std/math/pow.zig+1-1
...@@ -32,7 +32,7 @@ const expect = std.testing.expect;...@@ -32,7 +32,7 @@ const expect = std.testing.expect;
32/// - pow(-inf, y) = pow(-0, -y)32/// - pow(-inf, y) = pow(-0, -y)
33/// - pow(x, y) = nan for finite x < 0 and finite non-integer y33/// - pow(x, y) = nan for finite x < 0 and finite non-integer y
34pub fn pow(comptime T: type, x: T, y: T) T {34pub fn pow(comptime T: type, x: T, y: T) T {
35 if (@typeInfo(T) == builtin.TypeId.Int) {35 if (@typeInfo(T) == .Int) {
36 return math.powi(T, x, y) catch unreachable;36 return math.powi(T, x, y) catch unreachable;
37 }37 }
3838
lib/std/math/powi.zig+1-1
...@@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{...@@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
25}!T) {25}!T) {
26 const info = @typeInfo(T);26 const info = @typeInfo(T);
2727
28 comptime assert(@typeInfo(T) == builtin.TypeId.Int);28 comptime assert(@typeInfo(T) == .Int);
2929
30 // powi(x, +-0) = 1 for any x30 // powi(x, +-0) = 1 for any x
31 if (y == 0 or y == -0) {31 if (y == 0 or y == -0) {
lib/std/mem.zig+48-48
...@@ -746,12 +746,12 @@ test "mem.indexOf" {...@@ -746,12 +746,12 @@ test "mem.indexOf" {
746pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType {746pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType {
747 var result: ReturnType = 0;747 var result: ReturnType = 0;
748 switch (endian) {748 switch (endian) {
749 builtin.Endian.Big => {749 .Big => {
750 for (bytes) |b| {750 for (bytes) |b| {
751 result = (result << 8) | b;751 result = (result << 8) | b;
752 }752 }
753 },753 },
754 builtin.Endian.Little => {754 .Little => {
755 const ShiftType = math.Log2Int(ReturnType);755 const ShiftType = math.Log2Int(ReturnType);
756 for (bytes) |b, index| {756 for (bytes) |b, index| {
757 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));757 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));
...@@ -779,13 +779,13 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)...@@ -779,13 +779,13 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)
779}779}
780780
781pub const readIntLittle = switch (builtin.endian) {781pub const readIntLittle = switch (builtin.endian) {
782 builtin.Endian.Little => readIntNative,782 .Little => readIntNative,
783 builtin.Endian.Big => readIntForeign,783 .Big => readIntForeign,
784};784};
785785
786pub const readIntBig = switch (builtin.endian) {786pub const readIntBig = switch (builtin.endian) {
787 builtin.Endian.Little => readIntForeign,787 .Little => readIntForeign,
788 builtin.Endian.Big => readIntNative,788 .Big => readIntNative,
789};789};
790790
791/// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0791/// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0
...@@ -809,13 +809,13 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {...@@ -809,13 +809,13 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
809}809}
810810
811pub const readIntSliceLittle = switch (builtin.endian) {811pub const readIntSliceLittle = switch (builtin.endian) {
812 builtin.Endian.Little => readIntSliceNative,812 .Little => readIntSliceNative,
813 builtin.Endian.Big => readIntSliceForeign,813 .Big => readIntSliceForeign,
814};814};
815815
816pub const readIntSliceBig = switch (builtin.endian) {816pub const readIntSliceBig = switch (builtin.endian) {
817 builtin.Endian.Little => readIntSliceForeign,817 .Little => readIntSliceForeign,
818 builtin.Endian.Big => readIntSliceNative,818 .Big => readIntSliceNative,
819};819};
820820
821/// Reads an integer from memory with bit count specified by T.821/// Reads an integer from memory with bit count specified by T.
...@@ -892,13 +892,13 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(T.bit_count, 8)]u8, va...@@ -892,13 +892,13 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(T.bit_count, 8)]u8, va
892}892}
893893
894pub const writeIntLittle = switch (builtin.endian) {894pub const writeIntLittle = switch (builtin.endian) {
895 builtin.Endian.Little => writeIntNative,895 .Little => writeIntNative,
896 builtin.Endian.Big => writeIntForeign,896 .Big => writeIntForeign,
897};897};
898898
899pub const writeIntBig = switch (builtin.endian) {899pub const writeIntBig = switch (builtin.endian) {
900 builtin.Endian.Little => writeIntForeign,900 .Little => writeIntForeign,
901 builtin.Endian.Big => writeIntNative,901 .Big => writeIntNative,
902};902};
903903
904/// Writes an integer to memory, storing it in twos-complement.904/// Writes an integer to memory, storing it in twos-complement.
...@@ -950,13 +950,13 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {...@@ -950,13 +950,13 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
950}950}
951951
952pub const writeIntSliceNative = switch (builtin.endian) {952pub const writeIntSliceNative = switch (builtin.endian) {
953 builtin.Endian.Little => writeIntSliceLittle,953 .Little => writeIntSliceLittle,
954 builtin.Endian.Big => writeIntSliceBig,954 .Big => writeIntSliceBig,
955};955};
956956
957pub const writeIntSliceForeign = switch (builtin.endian) {957pub const writeIntSliceForeign = switch (builtin.endian) {
958 builtin.Endian.Little => writeIntSliceBig,958 .Little => writeIntSliceBig,
959 builtin.Endian.Big => writeIntSliceLittle,959 .Big => writeIntSliceLittle,
960};960};
961961
962/// Writes a twos-complement integer to memory, with the specified endianness.962/// Writes a twos-complement integer to memory, with the specified endianness.
...@@ -967,10 +967,10 @@ pub const writeIntSliceForeign = switch (builtin.endian) {...@@ -967,10 +967,10 @@ pub const writeIntSliceForeign = switch (builtin.endian) {
967/// use writeInt instead.967/// use writeInt instead.
968pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void {968pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void {
969 comptime assert(T.bit_count % 8 == 0);969 comptime assert(T.bit_count % 8 == 0);
970 switch (endian) {970 return switch (endian) {
971 builtin.Endian.Little => return writeIntSliceLittle(T, buffer, value),971 .Little => writeIntSliceLittle(T, buffer, value),
972 builtin.Endian.Big => return writeIntSliceBig(T, buffer, value),972 .Big => writeIntSliceBig(T, buffer, value),
973 }973 };
974}974}
975975
976test "writeIntBig and writeIntLittle" {976test "writeIntBig and writeIntLittle" {
...@@ -1506,54 +1506,54 @@ test "rotate" {...@@ -1506,54 +1506,54 @@ test "rotate" {
1506/// Converts a little-endian integer to host endianness.1506/// Converts a little-endian integer to host endianness.
1507pub fn littleToNative(comptime T: type, x: T) T {1507pub fn littleToNative(comptime T: type, x: T) T {
1508 return switch (builtin.endian) {1508 return switch (builtin.endian) {
1509 builtin.Endian.Little => x,1509 .Little => x,
1510 builtin.Endian.Big => @byteSwap(T, x),1510 .Big => @byteSwap(T, x),
1511 };1511 };
1512}1512}
15131513
1514/// Converts a big-endian integer to host endianness.1514/// Converts a big-endian integer to host endianness.
1515pub fn bigToNative(comptime T: type, x: T) T {1515pub fn bigToNative(comptime T: type, x: T) T {
1516 return switch (builtin.endian) {1516 return switch (builtin.endian) {
1517 builtin.Endian.Little => @byteSwap(T, x),1517 .Little => @byteSwap(T, x),
1518 builtin.Endian.Big => x,1518 .Big => x,
1519 };1519 };
1520}1520}
15211521
1522/// Converts an integer from specified endianness to host endianness.1522/// Converts an integer from specified endianness to host endianness.
1523pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {1523pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {
1524 return switch (endianness_of_x) {1524 return switch (endianness_of_x) {
1525 builtin.Endian.Little => littleToNative(T, x),1525 .Little => littleToNative(T, x),
1526 builtin.Endian.Big => bigToNative(T, x),1526 .Big => bigToNative(T, x),
1527 };1527 };
1528}1528}
15291529
1530/// Converts an integer which has host endianness to the desired endianness.1530/// Converts an integer which has host endianness to the desired endianness.
1531pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {1531pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {
1532 return switch (desired_endianness) {1532 return switch (desired_endianness) {
1533 builtin.Endian.Little => nativeToLittle(T, x),1533 .Little => nativeToLittle(T, x),
1534 builtin.Endian.Big => nativeToBig(T, x),1534 .Big => nativeToBig(T, x),
1535 };1535 };
1536}1536}
15371537
1538/// Converts an integer which has host endianness to little endian.1538/// Converts an integer which has host endianness to little endian.
1539pub fn nativeToLittle(comptime T: type, x: T) T {1539pub fn nativeToLittle(comptime T: type, x: T) T {
1540 return switch (builtin.endian) {1540 return switch (builtin.endian) {
1541 builtin.Endian.Little => x,1541 .Little => x,
1542 builtin.Endian.Big => @byteSwap(T, x),1542 .Big => @byteSwap(T, x),
1543 };1543 };
1544}1544}
15451545
1546/// Converts an integer which has host endianness to big endian.1546/// Converts an integer which has host endianness to big endian.
1547pub fn nativeToBig(comptime T: type, x: T) T {1547pub fn nativeToBig(comptime T: type, x: T) T {
1548 return switch (builtin.endian) {1548 return switch (builtin.endian) {
1549 builtin.Endian.Little => @byteSwap(T, x),1549 .Little => @byteSwap(T, x),
1550 builtin.Endian.Big => x,1550 .Big => x,
1551 };1551 };
1552}1552}
15531553
1554fn AsBytesReturnType(comptime P: type) type {1554fn AsBytesReturnType(comptime P: type) type {
1555 if (comptime !trait.isSingleItemPtr(P))1555 if (comptime !trait.isSingleItemPtr(P))
1556 @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P));1556 @compileError("expected single item pointer, passed " ++ @typeName(P));
15571557
1558 const size = @as(usize, @sizeOf(meta.Child(P)));1558 const size = @as(usize, @sizeOf(meta.Child(P)));
1559 const alignment = comptime meta.alignment(P);1559 const alignment = comptime meta.alignment(P);
...@@ -1578,8 +1578,8 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) {...@@ -1578,8 +1578,8 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) {
1578test "asBytes" {1578test "asBytes" {
1579 const deadbeef = @as(u32, 0xDEADBEEF);1579 const deadbeef = @as(u32, 0xDEADBEEF);
1580 const deadbeef_bytes = switch (builtin.endian) {1580 const deadbeef_bytes = switch (builtin.endian) {
1581 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",1581 .Big => "\xDE\xAD\xBE\xEF",
1582 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1582 .Little => "\xEF\xBE\xAD\xDE",
1583 };1583 };
15841584
1585 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));1585 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
...@@ -1617,21 +1617,21 @@ pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 {...@@ -1617,21 +1617,21 @@ pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 {
1617test "toBytes" {1617test "toBytes" {
1618 var my_bytes = toBytes(@as(u32, 0x12345678));1618 var my_bytes = toBytes(@as(u32, 0x12345678));
1619 switch (builtin.endian) {1619 switch (builtin.endian) {
1620 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),1620 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
1621 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),1621 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
1622 }1622 }
16231623
1624 my_bytes[0] = '\x99';1624 my_bytes[0] = '\x99';
1625 switch (builtin.endian) {1625 switch (builtin.endian) {
1626 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),1626 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
1627 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),1627 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
1628 }1628 }
1629}1629}
16301630
1631fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {1631fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
1632 const size = @as(usize, @sizeOf(T));1632 const size = @as(usize, @sizeOf(T));
16331633
1634 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or1634 if (comptime !trait.is(.Pointer)(B) or
1635 (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8))1635 (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8))
1636 {1636 {
1637 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));1637 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
...@@ -1651,15 +1651,15 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @Typ...@@ -1651,15 +1651,15 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @Typ
1651test "bytesAsValue" {1651test "bytesAsValue" {
1652 const deadbeef = @as(u32, 0xDEADBEEF);1652 const deadbeef = @as(u32, 0xDEADBEEF);
1653 const deadbeef_bytes = switch (builtin.endian) {1653 const deadbeef_bytes = switch (builtin.endian) {
1654 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",1654 .Big => "\xDE\xAD\xBE\xEF",
1655 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1655 .Little => "\xEF\xBE\xAD\xDE",
1656 };1656 };
16571657
1658 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);1658 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
16591659
1660 var codeface_bytes: [4]u8 = switch (builtin.endian) {1660 var codeface_bytes: [4]u8 = switch (builtin.endian) {
1661 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",1661 .Big => "\xC0\xDE\xFA\xCE",
1662 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",1662 .Little => "\xCE\xFA\xDE\xC0",
1663 }.*;1663 }.*;
1664 var codeface = bytesAsValue(u32, &codeface_bytes);1664 var codeface = bytesAsValue(u32, &codeface_bytes);
1665 testing.expect(codeface.* == 0xC0DEFACE);1665 testing.expect(codeface.* == 0xC0DEFACE);
...@@ -1692,8 +1692,8 @@ pub fn bytesToValue(comptime T: type, bytes: var) T {...@@ -1692,8 +1692,8 @@ pub fn bytesToValue(comptime T: type, bytes: var) T {
1692}1692}
1693test "bytesToValue" {1693test "bytesToValue" {
1694 const deadbeef_bytes = switch (builtin.endian) {1694 const deadbeef_bytes = switch (builtin.endian) {
1695 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",1695 .Big => "\xDE\xAD\xBE\xEF",
1696 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1696 .Little => "\xEF\xBE\xAD\xDE",
1697 };1697 };
16981698
1699 const deadbeef = bytesToValue(u32, deadbeef_bytes);1699 const deadbeef = bytesToValue(u32, deadbeef_bytes);
lib/std/special/compiler_rt/ashlti3.zig+1-1
...@@ -24,7 +24,7 @@ const twords = extern union {...@@ -24,7 +24,7 @@ const twords = extern union {
24 all: i128,24 all: i128,
25 s: S,25 s: S,
2626
27 const S = if (builtin.endian == builtin.Endian.Little)27 const S = if (builtin.endian == .Little)
28 struct {28 struct {
29 low: u64,29 low: u64,
30 high: u64,30 high: u64,
lib/std/special/compiler_rt/ashrti3.zig+1-1
...@@ -25,7 +25,7 @@ const twords = extern union {...@@ -25,7 +25,7 @@ const twords = extern union {
25 all: i128,25 all: i128,
26 s: S,26 s: S,
2727
28 const S = if (builtin.endian == builtin.Endian.Little)28 const S = if (builtin.endian == .Little)
29 struct {29 struct {
30 low: i64,30 low: i64,
31 high: i64,31 high: i64,
lib/std/special/compiler_rt/lshrti3.zig+1-1
...@@ -24,7 +24,7 @@ const twords = extern union {...@@ -24,7 +24,7 @@ const twords = extern union {
24 all: i128,24 all: i128,
25 s: S,25 s: S,
2626
27 const S = if (builtin.endian == builtin.Endian.Little)27 const S = if (builtin.endian == .Little)
28 struct {28 struct {
29 low: u64,29 low: u64,
30 high: u64,30 high: u64,
lib/std/special/compiler_rt/multi3.zig+1-1
...@@ -45,7 +45,7 @@ const twords = extern union {...@@ -45,7 +45,7 @@ const twords = extern union {
45 all: i128,45 all: i128,
46 s: S,46 s: S,
4747
48 const S = if (builtin.endian == builtin.Endian.Little)48 const S = if (builtin.endian == .Little)
49 struct {49 struct {
50 low: u64,50 low: u64,
51 high: u64,51 high: u64,
lib/std/special/compiler_rt/udivmod.zig+2-2
...@@ -2,8 +2,8 @@ const builtin = @import("builtin");...@@ -2,8 +2,8 @@ const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
33
4const low = switch (builtin.endian) {4const low = switch (builtin.endian) {
5 builtin.Endian.Big => 1,5 .Big => 1,
6 builtin.Endian.Little => 0,6 .Little => 0,
7};7};
8const high = 1 - low;8const high = 1 - low;
99
lib/std/testing.zig+1-5
...@@ -63,15 +63,11 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {...@@ -63,15 +63,11 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
6363
64 .Pointer => |pointer| {64 .Pointer => |pointer| {
65 switch (pointer.size) {65 switch (pointer.size) {
66 .One,66 .One, .Many, .C => {
67 .Many,
68 .C,
69 => {
70 if (actual != expected) {67 if (actual != expected) {
71 std.debug.panic("expected {*}, found {*}", .{ expected, actual });68 std.debug.panic("expected {*}, found {*}", .{ expected, actual });
72 }69 }
73 },70 },
74
75 .Slice => {71 .Slice => {
76 if (actual.ptr != expected.ptr) {72 if (actual.ptr != expected.ptr) {
77 std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr });73 std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr });
lib/std/valgrind.zig+2-2
...@@ -8,7 +8,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:...@@ -8,7 +8,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
8 }8 }
99
10 switch (builtin.arch) {10 switch (builtin.arch) {
11 builtin.Arch.i386 => {11 .i386 => {
12 return asm volatile (12 return asm volatile (
13 \\ roll $3, %%edi ; roll $13, %%edi13 \\ roll $3, %%edi ; roll $13, %%edi
14 \\ roll $29, %%edi ; roll $19, %%edi14 \\ roll $29, %%edi ; roll $19, %%edi
...@@ -19,7 +19,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:...@@ -19,7 +19,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
19 : "cc", "memory"19 : "cc", "memory"
20 );20 );
21 },21 },
22 builtin.Arch.x86_64 => {22 .x86_64 => {
23 return asm volatile (23 return asm volatile (
24 \\ rolq $3, %%rdi ; rolq $13, %%rdi24 \\ rolq $3, %%rdi ; rolq $13, %%rdi
25 \\ rolq $61, %%rdi ; rolq $51, %%rdi25 \\ rolq $61, %%rdi ; rolq $51, %%rdi