From 6fdeaac338f3a4a1f3455653ce29bf6ce4bbe335 Mon Sep 17 00:00:00 2001 From: Nathan Michaels Date: Mon, 28 Oct 2019 03:57:23 -0400 Subject: Add some documentation for standard library things. (#3540) * Add some documentation for standard library things. Added a bunch of descriptions for array_list. Added some usage notes for failing_allocator. Documented some of mem.Allocator. --- lib/std/array_list.zig | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 31ae02b291..a57839ec3b 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -5,6 +5,10 @@ const testing = std.testing; const mem = std.mem; const Allocator = mem.Allocator; +/// List of items. +/// +/// This is a wrapper around an array of T values. Initialize with +/// `init`. pub fn ArrayList(comptime T: type) type { return AlignedArrayList(T, null); } @@ -37,18 +41,24 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { }; } + /// Release all allocated memory. pub fn deinit(self: Self) void { self.allocator.free(self.items); } + /// Return contents as a slice. Only valid while the list + /// doesn't change size. pub fn toSlice(self: Self) Slice { return self.items[0..self.len]; } + /// Return list as const slice. Only valid while the list + /// doesn't change size. pub fn toSliceConst(self: Self) SliceConst { return self.items[0..self.len]; } + /// Safely access index i of the list. pub fn at(self: Self, i: usize) T { return self.toSliceConst()[i]; } @@ -66,10 +76,13 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { self.items[i] = item; } + /// Return length of the list. pub fn count(self: Self) usize { return self.len; } + /// Return the maximum number of items the list can hold + /// without allocating more memory. pub fn capacity(self: Self) usize { return self.items.len; } @@ -93,6 +106,8 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return result; } + /// Insert `item` at index `n`. Moves `list[n .. list.count()]` + /// to make room. pub fn insert(self: *Self, n: usize, item: T) !void { try self.ensureCapacity(self.len + 1); self.len += 1; @@ -101,6 +116,8 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { self.items[n] = item; } + /// Insert slice `items` at index `n`. Moves + /// `list[n .. list.count()]` to make room. pub fn insertSlice(self: *Self, n: usize, items: SliceConst) !void { try self.ensureCapacity(self.len + items.len); self.len += items.len; @@ -109,16 +126,22 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { mem.copy(T, self.items[n .. n + items.len], items); } + /// Extend the list by 1 element. Allocates more memory as + /// necessary. pub fn append(self: *Self, item: T) !void { const new_item_ptr = try self.addOne(); new_item_ptr.* = item; } + /// Extend the list by 1 element, but asserting `self.capacity` + /// is sufficient to hold an additional item. pub fn appendAssumeCapacity(self: *Self, item: T) void { const new_item_ptr = self.addOneAssumeCapacity(); new_item_ptr.* = item; } + /// Remove the element at index `i` from the list and return + /// its value. Asserts the array has at least one item. pub fn orderedRemove(self: *Self, i: usize) T { const newlen = self.len - 1; if (newlen == i) return self.pop(); @@ -149,17 +172,22 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return self.swapRemove(i); } + /// Append the slice of items to the list. Allocates more + /// memory as necessary. pub fn appendSlice(self: *Self, items: SliceConst) !void { try self.ensureCapacity(self.len + items.len); mem.copy(T, self.items[self.len..], items); self.len += items.len; } + /// Adjust the list's length to `new_len`. Doesn't initialize + /// added items if any. pub fn resize(self: *Self, new_len: usize) !void { try self.ensureCapacity(new_len); self.len = new_len; } + /// Reduce allocated capacity to `new_len`. pub fn shrink(self: *Self, new_len: usize) void { assert(new_len <= self.len); self.len = new_len; @@ -178,6 +206,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { self.items = try self.allocator.realloc(self.items, better_capacity); } + /// Increase length by 1, returning pointer to the new item. pub fn addOne(self: *Self) !*T { const new_length = self.len + 1; try self.ensureCapacity(new_length); @@ -191,11 +220,14 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return result; } + /// Remove and return the last element from the list. Asserts + /// the list has at least one item. pub fn pop(self: *Self) T { self.len -= 1; return self.items[self.len]; } + /// Like `pop` but returns `null` if empty. pub fn popOrNull(self: *Self) ?T { if (self.len == 0) return null; return self.pop(); @@ -218,6 +250,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { } }; + /// Return an iterator over the list. pub fn iterator(self: *const Self) Iterator { return Iterator{ .list = self, -- cgit v1.2.3 From e0db54e89d6f4e9f56800ddb1017e30be1b7d58a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 6 Nov 2019 23:25:57 -0500 Subject: update the codebase to use `@as` --- build.zig | 2 +- lib/std/array_list.zig | 16 +- lib/std/ascii.zig | 22 +-- lib/std/atomic/queue.zig | 4 +- lib/std/atomic/stack.zig | 6 +- lib/std/bloom_filter.zig | 6 +- lib/std/c/darwin.zig | 2 +- lib/std/child_process.zig | 2 +- lib/std/crypto/aes.zig | 20 +-- lib/std/crypto/blake2.zig | 16 +- lib/std/crypto/chacha20.zig | 8 +- lib/std/crypto/gimli.zig | 8 +- lib/std/crypto/md5.zig | 8 +- lib/std/crypto/poly1305.zig | 12 +- lib/std/crypto/sha1.zig | 30 ++-- lib/std/crypto/sha2.zig | 38 ++--- lib/std/crypto/sha3.zig | 2 +- lib/std/crypto/x25519.zig | 20 +-- lib/std/debug.zig | 23 +-- lib/std/debug/leb128.zig | 4 +- lib/std/dynamic_library.zig | 4 +- lib/std/elf.zig | 24 +-- lib/std/event/fs.zig | 4 +- lib/std/fifo.zig | 26 ++-- lib/std/fmt.zig | 102 ++++++------ lib/std/fmt/errol.zig | 4 +- lib/std/fmt/parse_float.zig | 14 +- lib/std/fs/file.zig | 6 +- lib/std/hash/auto_hash.zig | 14 +- lib/std/hash/cityhash.zig | 8 +- lib/std/hash/crc.zig | 8 +- lib/std/hash/murmur.zig | 2 +- lib/std/hash/siphash.zig | 14 +- lib/std/hash_map.zig | 2 +- lib/std/heap.zig | 2 +- lib/std/http/headers.zig | 10 +- lib/std/io.zig | 4 +- lib/std/io/out_stream.zig | 4 +- lib/std/io/test.zig | 40 ++--- lib/std/json.zig | 4 +- lib/std/math.zig | 136 ++++++++-------- lib/std/math/acos.zig | 4 +- lib/std/math/acosh.zig | 4 +- lib/std/math/asin.zig | 4 +- lib/std/math/asinh.zig | 4 +- lib/std/math/atan.zig | 4 +- lib/std/math/atanh.zig | 4 +- lib/std/math/big/int.zig | 2 +- lib/std/math/cbrt.zig | 10 +- lib/std/math/ceil.zig | 6 +- lib/std/math/complex/ldexp.zig | 2 +- lib/std/math/complex/sqrt.zig | 4 +- lib/std/math/complex/tanh.zig | 2 +- lib/std/math/copysign.zig | 6 +- lib/std/math/cos.zig | 4 +- lib/std/math/cosh.zig | 4 +- lib/std/math/exp.zig | 4 +- lib/std/math/exp2.zig | 6 +- lib/std/math/expm1.zig | 4 +- lib/std/math/expo2.zig | 2 +- lib/std/math/fabs.zig | 8 +- lib/std/math/floor.zig | 10 +- lib/std/math/fma.zig | 2 +- lib/std/math/frexp.zig | 4 +- lib/std/math/hypot.zig | 2 +- lib/std/math/ilogb.zig | 6 +- lib/std/math/isfinite.zig | 12 +- lib/std/math/isinf.zig | 48 +++--- lib/std/math/isnan.zig | 8 +- lib/std/math/isnormal.zig | 12 +- lib/std/math/ln.zig | 10 +- lib/std/math/log.zig | 10 +- lib/std/math/log10.zig | 8 +- lib/std/math/log1p.zig | 6 +- lib/std/math/log2.zig | 8 +- lib/std/math/modf.zig | 8 +- lib/std/math/round.zig | 4 +- lib/std/math/scalbn.zig | 4 +- lib/std/math/signbit.zig | 6 +- lib/std/math/sin.zig | 6 +- lib/std/math/sinh.zig | 4 +- lib/std/math/sqrt.zig | 6 +- lib/std/math/tan.zig | 4 +- lib/std/math/tanh.zig | 4 +- lib/std/math/trunc.zig | 8 +- lib/std/mem.zig | 20 +-- lib/std/meta.zig | 2 +- lib/std/meta/trait.zig | 4 +- lib/std/net.zig | 14 +- lib/std/os.zig | 10 +- lib/std/os/bits/dragonfly.zig | 2 +- lib/std/os/bits/linux.zig | 10 +- lib/std/os/linux.zig | 188 +++++++++++------------ lib/std/os/linux/arm-eabi.zig | 4 +- lib/std/os/linux/arm64.zig | 2 +- lib/std/os/linux/mipsel.zig | 6 +- lib/std/os/linux/riscv64.zig | 2 +- lib/std/os/linux/vdso.zig | 4 +- lib/std/os/linux/x86_64.zig | 2 +- lib/std/os/test.zig | 2 +- lib/std/os/windows.zig | 2 +- lib/std/os/zen.zig | 4 +- lib/std/packed_int_array.zig | 18 +-- lib/std/pdb.zig | 2 +- lib/std/priority_queue.zig | 60 ++++---- lib/std/rand.zig | 8 +- lib/std/rand/ziggurat.zig | 2 +- lib/std/segmented_list.zig | 10 +- lib/std/sort.zig | 8 +- lib/std/special/c.zig | 6 +- lib/std/special/compiler_rt.zig | 34 ++-- lib/std/special/compiler_rt/addXf3.zig | 26 ++-- lib/std/special/compiler_rt/addXf3_test.zig | 8 +- lib/std/special/compiler_rt/comparedf2.zig | 20 +-- lib/std/special/compiler_rt/comparesf2.zig | 20 +-- lib/std/special/compiler_rt/comparetf2.zig | 20 +-- lib/std/special/compiler_rt/divdf3.zig | 66 ++++---- lib/std/special/compiler_rt/divsf3.zig | 22 +-- lib/std/special/compiler_rt/divti3_test.zig | 8 +- lib/std/special/compiler_rt/extendXfYf2.zig | 14 +- lib/std/special/compiler_rt/extendXfYf2_test.zig | 8 +- lib/std/special/compiler_rt/fixdfdi_test.zig | 2 +- lib/std/special/compiler_rt/fixdfsi_test.zig | 2 +- lib/std/special/compiler_rt/fixdfti_test.zig | 2 +- lib/std/special/compiler_rt/fixint.zig | 6 +- lib/std/special/compiler_rt/fixint_test.zig | 26 ++-- lib/std/special/compiler_rt/fixsfdi_test.zig | 2 +- lib/std/special/compiler_rt/fixsfsi_test.zig | 2 +- lib/std/special/compiler_rt/fixsfti_test.zig | 2 +- lib/std/special/compiler_rt/fixtfdi_test.zig | 2 +- lib/std/special/compiler_rt/fixtfsi_test.zig | 2 +- lib/std/special/compiler_rt/fixtfti_test.zig | 2 +- lib/std/special/compiler_rt/fixuint.zig | 8 +- lib/std/special/compiler_rt/fixunstfsi_test.zig | 2 +- lib/std/special/compiler_rt/fixunstfti_test.zig | 2 +- lib/std/special/compiler_rt/floatsiXf.zig | 10 +- lib/std/special/compiler_rt/floattidf.zig | 2 +- lib/std/special/compiler_rt/floattisf.zig | 2 +- lib/std/special/compiler_rt/floattitf.zig | 2 +- lib/std/special/compiler_rt/floatunsidf.zig | 6 +- lib/std/special/compiler_rt/floatuntidf.zig | 4 +- lib/std/special/compiler_rt/floatuntisf.zig | 4 +- lib/std/special/compiler_rt/floatuntitf.zig | 4 +- lib/std/special/compiler_rt/mulXf3.zig | 50 +++--- lib/std/special/compiler_rt/mulXf3_test.zig | 18 +-- lib/std/special/compiler_rt/muldi3.zig | 2 +- lib/std/special/compiler_rt/mulodi4.zig | 2 +- lib/std/special/compiler_rt/mulodi4_test.zig | 48 +++--- lib/std/special/compiler_rt/muloti4.zig | 2 +- lib/std/special/compiler_rt/muloti4_test.zig | 62 ++++---- lib/std/special/compiler_rt/multi3.zig | 2 +- lib/std/special/compiler_rt/negXf2.zig | 2 +- lib/std/special/compiler_rt/popcountdi2_test.zig | 6 +- lib/std/special/compiler_rt/truncXfYf2.zig | 2 +- lib/std/special/compiler_rt/truncXfYf2_test.zig | 20 +-- lib/std/special/compiler_rt/udivmod.zig | 6 +- lib/std/target.zig | 2 +- lib/std/thread.zig | 2 +- lib/std/time.zig | 8 +- lib/std/unicode.zig | 10 +- lib/std/valgrind.zig | 2 +- lib/std/zig/parse_string_literal.zig | 2 +- lib/std/zig/parser_test.zig | 2 +- lib/std/zig/render.zig | 6 +- lib/std/zig/tokenizer.zig | 2 +- test/compare_output.zig | 50 +++--- test/compile_errors.zig | 52 +++---- test/stage1/behavior.zig | 10 +- test/stage1/behavior/align.zig | 4 +- test/stage1/behavior/array.zig | 4 +- test/stage1/behavior/asm.zig | 16 +- test/stage1/behavior/async_fn.zig | 10 +- test/stage1/behavior/atomics.zig | 6 +- test/stage1/behavior/bitreverse.zig | 28 ++-- test/stage1/behavior/bool.zig | 8 +- test/stage1/behavior/bugs/1322.zig | 4 +- test/stage1/behavior/bugs/1421.zig | 2 +- test/stage1/behavior/bugs/2114.zig | 8 +- test/stage1/behavior/bugs/3046.zig | 2 +- test/stage1/behavior/byteswap.zig | 24 +-- test/stage1/behavior/cast.zig | 12 +- test/stage1/behavior/defer.zig | 2 +- test/stage1/behavior/enum.zig | 4 +- test/stage1/behavior/error.zig | 4 +- test/stage1/behavior/eval.zig | 36 ++--- test/stage1/behavior/floatop.zig | 4 +- test/stage1/behavior/fn.zig | 4 +- test/stage1/behavior/if.zig | 4 +- test/stage1/behavior/import.zig | 4 +- test/stage1/behavior/math.zig | 24 +-- test/stage1/behavior/misc.zig | 6 +- test/stage1/behavior/popcount.zig | 2 +- test/stage1/behavior/pub_enum.zig | 2 +- test/stage1/behavior/shuffle.zig | 26 ++-- test/stage1/behavior/slicetobytes.zig | 2 +- test/stage1/behavior/struct.zig | 16 +- test/stage1/behavior/switch.zig | 8 +- test/stage1/behavior/try.zig | 6 +- test/stage1/behavior/type_info.zig | 46 +++--- test/stage1/behavior/union.zig | 24 +-- test/stage1/behavior/var_args.zig | 10 +- test/stage1/behavior/vector.zig | 50 +++--- test/stage1/behavior/void.zig | 2 +- test/stage1/behavior/while.zig | 16 +- test/tests.zig | 4 +- test/translate_c.zig | 62 ++++---- 206 files changed, 1287 insertions(+), 1282 deletions(-) (limited to 'lib/std/array_list.zig') diff --git a/build.zig b/build.zig index ca78bdf197..7cd6d1b7bb 100644 --- a/build.zig +++ b/build.zig @@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { ) catch unreachable; for (dep.system_libs.toSliceConst()) |lib| { const static_bare_name = if (mem.eql(u8, lib, "curses")) - ([]const u8)("libncurses.a") + @as([]const u8,"libncurses.a") else b.fmt("lib{}.a", lib); const static_lib_name = fs.path.join( diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index a57839ec3b..59fd2a10e5 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" { try list.append(7); //remove from middle - testing.expectEqual(i32(4), list.orderedRemove(3)); - testing.expectEqual(i32(5), list.at(3)); - testing.expectEqual(usize(6), list.len); + testing.expectEqual(@as(i32, 4), list.orderedRemove(3)); + testing.expectEqual(@as(i32, 5), list.at(3)); + testing.expectEqual(@as(usize, 6), list.len); //remove from end - testing.expectEqual(i32(7), list.orderedRemove(5)); - testing.expectEqual(usize(5), list.len); + testing.expectEqual(@as(i32, 7), list.orderedRemove(5)); + testing.expectEqual(@as(usize, 5), list.len); //remove from front - testing.expectEqual(i32(1), list.orderedRemove(0)); - testing.expectEqual(i32(2), list.at(0)); - testing.expectEqual(usize(4), list.len); + testing.expectEqual(@as(i32, 1), list.orderedRemove(0)); + testing.expectEqual(@as(i32, 2), list.at(0)); + testing.expectEqual(@as(usize, 4), list.len); } test "std.ArrayList.swapRemove" { diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig index 2bc11ba3f2..71f52bfd17 100644 --- a/lib/std/ascii.zig +++ b/lib/std/ascii.zig @@ -129,26 +129,26 @@ const combinedTable = init: { comptime var i = 0; inline while (i < 128) : (i += 1) { table[i] = - u8(alpha[i]) << @enumToInt(tIndex.Alpha) | - u8(hex[i]) << @enumToInt(tIndex.Hex) | - u8(space[i]) << @enumToInt(tIndex.Space) | - u8(digit[i]) << @enumToInt(tIndex.Digit) | - u8(lower[i]) << @enumToInt(tIndex.Lower) | - u8(upper[i]) << @enumToInt(tIndex.Upper) | - u8(punct[i]) << @enumToInt(tIndex.Punct) | - u8(graph[i]) << @enumToInt(tIndex.Graph); + @as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) | + @as(u8, hex[i]) << @enumToInt(tIndex.Hex) | + @as(u8, space[i]) << @enumToInt(tIndex.Space) | + @as(u8, digit[i]) << @enumToInt(tIndex.Digit) | + @as(u8, lower[i]) << @enumToInt(tIndex.Lower) | + @as(u8, upper[i]) << @enumToInt(tIndex.Upper) | + @as(u8, punct[i]) << @enumToInt(tIndex.Punct) | + @as(u8, graph[i]) << @enumToInt(tIndex.Graph); } mem.set(u8, table[128..256], 0); break :init table; }; fn inTable(c: u8, t: tIndex) bool { - return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0; + return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0; } pub fn isAlNum(c: u8) bool { - return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) | - u8(1) << @enumToInt(tIndex.Digit))) != 0; + return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) | + @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0; } pub fn isAlpha(c: u8) bool { diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index dbc011bed3..173355eb3b 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -214,8 +214,8 @@ test "std.atomic.Queue" { std.debug.panic( "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", context.get_count, - u32(puts_per_thread), - u32(put_thread_count), + @as(u32, puts_per_thread), + @as(u32, put_thread_count), ); } } diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index dd288adbf1..664191eb77 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type { root: ?*Node, lock: @typeOf(lock_init), - const lock_init = if (builtin.single_threaded) {} else u8(0); + const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); pub const Self = @This(); @@ -141,8 +141,8 @@ test "std.atomic.stack" { std.debug.panic( "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", context.get_count, - u32(puts_per_thread), - u32(put_thread_count), + @as(u32, puts_per_thread), + @as(u32, put_thread_count), ); } } diff --git a/lib/std/bloom_filter.zig b/lib/std/bloom_filter.zig index c36c5e9dfa..2734e7d54f 100644 --- a/lib/std/bloom_filter.zig +++ b/lib/std/bloom_filter.zig @@ -171,7 +171,7 @@ test "std.BloomFilter" { testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); } testing.expectEqual(BF.Index(0), bf.popCount()); - testing.expectEqual(f64(0), bf.estimateItems()); + testing.expectEqual(@as(f64, 0), bf.estimateItems()); // fill in a few items bf.incrementCell(42); bf.incrementCell(255); @@ -197,7 +197,7 @@ test "std.BloomFilter" { testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); } testing.expectEqual(BF.Index(0), bf.popCount()); - testing.expectEqual(f64(0), bf.estimateItems()); + testing.expectEqual(@as(f64, 0), bf.estimateItems()); // Lets add a string bf.add("foo"); @@ -219,7 +219,7 @@ test "std.BloomFilter" { testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); } testing.expectEqual(BF.Index(0), bf.popCount()); - testing.expectEqual(f64(0), bf.estimateItems()); + testing.expectEqual(@as(f64, 0), bf.estimateItems()); comptime var teststrings = [_][]const u8{ "foo", diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index eaccb1dcfd..4d40e8aee5 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; pub fn sigaddset(set: *sigset_t, signo: u5) void { - set.* |= u32(1) << (signo - 1); + set.* |= @as(u32, 1) << (signo - 1); } pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 5fae9447a9..e6d81aeb4f 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void { // Child of fork calls this to report an error to the fork parent. // Then the child exits. fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { - writeIntFd(fd, ErrInt(@errorToInt(err))) catch {}; + writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {}; os.exit(1); } diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index 4e7a4f2e13..ddccd0b1b3 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -6,7 +6,7 @@ const testing = std.testing; // Apply sbox0 to each byte in w. fn subw(w: u32) u32 { - return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]); + return @as(u32, sbox0[w >> 24]) << 24 | @as(u32, sbox0[w >> 16 & 0xff]) << 16 | @as(u32, sbox0[w >> 8 & 0xff]) << 8 | @as(u32, sbox0[w & 0xff]); } fn rotw(w: u32) u32 { @@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { } // Last round uses s-box directly and XORs to produce output. - s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]); - s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | u32(sbox0[t0 & 0xff]); - s2 = u32(sbox0[t2 >> 24]) << 24 | u32(sbox0[t3 >> 16 & 0xff]) << 16 | u32(sbox0[t0 >> 8 & 0xff]) << 8 | u32(sbox0[t1 & 0xff]); - s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 0xff]); + s0 = @as(u32, sbox0[t0 >> 24]) << 24 | @as(u32, sbox0[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t3 & 0xff]); + s1 = @as(u32, sbox0[t1 >> 24]) << 24 | @as(u32, sbox0[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t0 & 0xff]); + s2 = @as(u32, sbox0[t2 >> 24]) << 24 | @as(u32, sbox0[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t1 & 0xff]); + s3 = @as(u32, sbox0[t3 >> 24]) << 24 | @as(u32, sbox0[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t2 & 0xff]); s0 ^= xk[k + 0]; s1 ^= xk[k + 1]; @@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { } // Last round uses s-box directly and XORs to produce output. - s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]); - s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | u32(sbox1[t2 & 0xff]); - s2 = u32(sbox1[t2 >> 24]) << 24 | u32(sbox1[t1 >> 16 & 0xff]) << 16 | u32(sbox1[t0 >> 8 & 0xff]) << 8 | u32(sbox1[t3 & 0xff]); - s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 0xff]); + s0 = @as(u32, sbox1[t0 >> 24]) << 24 | @as(u32, sbox1[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t1 & 0xff]); + s1 = @as(u32, sbox1[t1 >> 24]) << 24 | @as(u32, sbox1[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t2 & 0xff]); + s2 = @as(u32, sbox1[t2 >> 24]) << 24 | @as(u32, sbox1[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t3 & 0xff]); + s3 = @as(u32, sbox1[t3 >> 24]) << 24 | @as(u32, sbox1[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t0 & 0xff]); s0 ^= xk[k + 0]; s1 ^= xk[k + 1]; @@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void { while (i < enc.len) : (i += 1) { var t = enc[i - 1]; if (i % nk == 0) { - t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24); + t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24); } else if (nk > 6 and i % nk == 4) { t = subw(t); } diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig index 6bb2764b92..d6b1e49724 100644 --- a/lib/std/crypto/blake2.zig +++ b/lib/std/crypto/blake2.zig @@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type { inline while (j < 10) : (j += 1) { inline for (rounds) |r| { v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; - v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16)); + v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16)); v[r.c] = v[r.c] +% v[r.d]; - v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12)); + v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12)); v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; - v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8)); + v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8)); v[r.c] = v[r.c] +% v[r.d]; - v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7)); + v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7)); } } @@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type { inline while (j < 12) : (j += 1) { inline for (rounds) |r| { v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; - v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32)); + v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32)); v[r.c] = v[r.c] +% v[r.d]; - v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24)); + v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24)); v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; - v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16)); + v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16)); v[r.c] = v[r.c] +% v[r.d]; - v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63)); + v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63)); } } diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index 0d997e0d14..d5d03f2bfa 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void { // two-round cycles inline for (rounds) |r| { x[r.a] +%= x[r.b]; - x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(16)); + x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 16)); x[r.c] +%= x[r.d]; - x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(12)); + x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 12)); x[r.a] +%= x[r.b]; - x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(8)); + x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 8)); x[r.c] +%= x[r.d]; - x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(7)); + x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 7)); } } diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig index 0a0a5056c6..0d18afd705 100644 --- a/lib/std/crypto/gimli.zig +++ b/lib/std/crypto/gimli.zig @@ -34,9 +34,9 @@ pub const State = struct { pub fn permute(self: *Self) void { const state = &self.data; - var round = u32(24); + var round = @as(u32, 24); while (round > 0) : (round -= 1) { - var column = usize(0); + var column = @as(usize, 0); while (column < 4) : (column += 1) { const x = math.rotl(u32, state[column], 24); const y = math.rotl(u32, state[4 + column], 9); @@ -61,7 +61,7 @@ pub const State = struct { } pub fn squeeze(self: *Self, out: []u8) void { - var i = usize(0); + var i = @as(usize, 0); while (i + RATE <= out.len) : (i += RATE) { self.permute(); mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]); @@ -79,7 +79,7 @@ test "permute" { var state = State{ .data = blk: { var input: [12]u32 = undefined; - var i = u32(0); + var i = @as(u32, 0); while (i < 12) : (i += 1) { input[i] = i * i * i + i *% 0x9e3779b9; } diff --git a/lib/std/crypto/md5.zig b/lib/std/crypto/md5.zig index ddbb39a9df..db6150699d 100644 --- a/lib/std/crypto/md5.zig +++ b/lib/std/crypto/md5.zig @@ -126,10 +126,10 @@ pub const Md5 = struct { while (i < 16) : (i += 1) { // NOTE: Performing or's separately improves perf by ~10% s[i] = 0; - s[i] |= u32(b[i * 4 + 0]); - s[i] |= u32(b[i * 4 + 1]) << 8; - s[i] |= u32(b[i * 4 + 2]) << 16; - s[i] |= u32(b[i * 4 + 3]) << 24; + s[i] |= @as(u32, b[i * 4 + 0]); + s[i] |= @as(u32, b[i * 4 + 1]) << 8; + s[i] |= @as(u32, b[i * 4 + 2]) << 16; + s[i] |= @as(u32, b[i * 4 + 3]) << 24; } var v: [4]u32 = [_]u32{ diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index bd0b33e586..78881ba049 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -87,11 +87,11 @@ pub const Poly1305 = struct { // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff fn polyBlock(ctx: *Self) void { // s = h + c, without carry propagation - const s0 = u64(ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe - const s1 = u64(ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe - const s2 = u64(ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe - const s3 = u64(ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe - const s4 = u64(ctx.h[4]) + ctx.c[4]; // s4 <= 5 + const s0 = @as(u64, ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe + const s1 = @as(u64, ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe + const s2 = @as(u64, ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe + const s3 = @as(u64, ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe + const s4 = @as(u64, ctx.h[4]) + ctx.c[4]; // s4 <= 5 // Local all the things! const r0 = ctx.r[0]; // r0 <= 0fffffff @@ -197,7 +197,7 @@ pub const Poly1305 = struct { // check if we should subtract 2^130-5 by performing the // corresponding carry propagation. - const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004 + const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004 const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000 const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000 const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000 diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig index c5160a1f37..c17ef2daf7 100644 --- a/lib/std/crypto/sha1.zig +++ b/lib/std/crypto/sha1.zig @@ -146,10 +146,10 @@ pub const Sha1 = struct { Rp(0, 1, 2, 3, 4, 15), }; inline for (round0a) |r| { - s[r.i] = (u32(b[r.i * 4 + 0]) << 24) | (u32(b[r.i * 4 + 1]) << 16) | (u32(b[r.i * 4 + 2]) << 8) | (u32(b[r.i * 4 + 3]) << 0); + s[r.i] = (@as(u32, b[r.i * 4 + 0]) << 24) | (@as(u32, b[r.i * 4 + 1]) << 16) | (@as(u32, b[r.i * 4 + 2]) << 8) | (@as(u32, b[r.i * 4 + 3]) << 0); - v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); - v[r.b] = math.rotl(u32, v[r.b], u32(30)); + v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); + v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); } const round0b = comptime [_]RoundParam{ @@ -160,10 +160,10 @@ pub const Sha1 = struct { }; inline for (round0b) |r| { const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; - s[r.i & 0xf] = math.rotl(u32, t, u32(1)); + s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); - v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); - v[r.b] = math.rotl(u32, v[r.b], u32(30)); + v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); + v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); } const round1 = comptime [_]RoundParam{ @@ -190,10 +190,10 @@ pub const Sha1 = struct { }; inline for (round1) |r| { const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; - s[r.i & 0xf] = math.rotl(u32, t, u32(1)); + s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); - v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); - v[r.b] = math.rotl(u32, v[r.b], u32(30)); + v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); + v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); } const round2 = comptime [_]RoundParam{ @@ -220,10 +220,10 @@ pub const Sha1 = struct { }; inline for (round2) |r| { const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; - s[r.i & 0xf] = math.rotl(u32, t, u32(1)); + s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); - v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d])); - v[r.b] = math.rotl(u32, v[r.b], u32(30)); + v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d])); + v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); } const round3 = comptime [_]RoundParam{ @@ -250,10 +250,10 @@ pub const Sha1 = struct { }; inline for (round3) |r| { const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; - s[r.i & 0xf] = math.rotl(u32, t, u32(1)); + s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); - v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); - v[r.b] = math.rotl(u32, v[r.b], u32(30)); + v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); + v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); } d.s[0] +%= v[0]; diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig index b40a39d579..77698176bd 100644 --- a/lib/std/crypto/sha2.zig +++ b/lib/std/crypto/sha2.zig @@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type { var i: usize = 0; while (i < 16) : (i += 1) { s[i] = 0; - s[i] |= u32(b[i * 4 + 0]) << 24; - s[i] |= u32(b[i * 4 + 1]) << 16; - s[i] |= u32(b[i * 4 + 2]) << 8; - s[i] |= u32(b[i * 4 + 3]) << 0; + s[i] |= @as(u32, b[i * 4 + 0]) << 24; + s[i] |= @as(u32, b[i * 4 + 1]) << 16; + s[i] |= @as(u32, b[i * 4 + 2]) << 8; + s[i] |= @as(u32, b[i * 4 + 3]) << 0; } while (i < 64) : (i += 1) { - s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10)); + s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], @as(u32, 7)) ^ math.rotr(u32, s[i - 15], @as(u32, 18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], @as(u32, 17)) ^ math.rotr(u32, s[i - 2], @as(u32, 19)) ^ (s[i - 2] >> 10)); } var v: [8]u32 = [_]u32{ @@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type { Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2), }; inline for (round0) |r| { - v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], u32(6)) ^ math.rotr(u32, v[r.e], u32(11)) ^ math.rotr(u32, v[r.e], u32(25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; + v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], @as(u32, 6)) ^ math.rotr(u32, v[r.e], @as(u32, 11)) ^ math.rotr(u32, v[r.e], @as(u32, 25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; v[r.d] = v[r.d] +% v[r.h]; - v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], u32(2)) ^ math.rotr(u32, v[r.a], u32(13)) ^ math.rotr(u32, v[r.a], u32(22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); + v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], @as(u32, 2)) ^ math.rotr(u32, v[r.a], @as(u32, 13)) ^ math.rotr(u32, v[r.a], @as(u32, 22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); } d.s[0] +%= v[0]; @@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type { var i: usize = 0; while (i < 16) : (i += 1) { s[i] = 0; - s[i] |= u64(b[i * 8 + 0]) << 56; - s[i] |= u64(b[i * 8 + 1]) << 48; - s[i] |= u64(b[i * 8 + 2]) << 40; - s[i] |= u64(b[i * 8 + 3]) << 32; - s[i] |= u64(b[i * 8 + 4]) << 24; - s[i] |= u64(b[i * 8 + 5]) << 16; - s[i] |= u64(b[i * 8 + 6]) << 8; - s[i] |= u64(b[i * 8 + 7]) << 0; + s[i] |= @as(u64, b[i * 8 + 0]) << 56; + s[i] |= @as(u64, b[i * 8 + 1]) << 48; + s[i] |= @as(u64, b[i * 8 + 2]) << 40; + s[i] |= @as(u64, b[i * 8 + 3]) << 32; + s[i] |= @as(u64, b[i * 8 + 4]) << 24; + s[i] |= @as(u64, b[i * 8 + 5]) << 16; + s[i] |= @as(u64, b[i * 8 + 6]) << 8; + s[i] |= @as(u64, b[i * 8 + 7]) << 0; } while (i < 80) : (i += 1) { - s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6)); + s[i] = s[i - 16] +% s[i - 7] +% + (math.rotr(u64, s[i - 15], @as(u64, 1)) ^ math.rotr(u64, s[i - 15], @as(u64, 8)) ^ (s[i - 15] >> 7)) +% + (math.rotr(u64, s[i - 2], @as(u64, 19)) ^ math.rotr(u64, s[i - 2], @as(u64, 61)) ^ (s[i - 2] >> 6)); } var v: [8]u64 = [_]u64{ @@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type { Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817), }; inline for (round0) |r| { - v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], u64(14)) ^ math.rotr(u64, v[r.e], u64(18)) ^ math.rotr(u64, v[r.e], u64(41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; + v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], @as(u64, 14)) ^ math.rotr(u64, v[r.e], @as(u64, 18)) ^ math.rotr(u64, v[r.e], @as(u64, 41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; v[r.d] = v[r.d] +% v[r.h]; - v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], u64(28)) ^ math.rotr(u64, v[r.a], u64(34)) ^ math.rotr(u64, v[r.a], u64(39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); + v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], @as(u64, 28)) ^ math.rotr(u64, v[r.a], @as(u64, 34)) ^ math.rotr(u64, v[r.a], @as(u64, 39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); } d.s[0] +%= v[0]; diff --git a/lib/std/crypto/sha3.zig b/lib/std/crypto/sha3.zig index 659e7a254f..d417ef07e2 100644 --- a/lib/std/crypto/sha3.zig +++ b/lib/std/crypto/sha3.zig @@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void { } x = 0; inline while (x < 5) : (x += 1) { - t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], usize(1)); + t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], @as(usize, 1)); y = 0; inline while (y < 5) : (y += 1) { s[x + y * 5] ^= t[0]; diff --git a/lib/std/crypto/x25519.zig b/lib/std/crypto/x25519.zig index 7f9220c3f4..223d65f8f4 100644 --- a/lib/std/crypto/x25519.zig +++ b/lib/std/crypto/x25519.zig @@ -256,15 +256,15 @@ const Fe = struct { var t: [10]i64 = undefined; t[0] = readIntSliceLittle(u32, s[0..4]); - t[1] = u32(readIntSliceLittle(u24, s[4..7])) << 6; - t[2] = u32(readIntSliceLittle(u24, s[7..10])) << 5; - t[3] = u32(readIntSliceLittle(u24, s[10..13])) << 3; - t[4] = u32(readIntSliceLittle(u24, s[13..16])) << 2; + t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6; + t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5; + t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3; + t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2; t[5] = readIntSliceLittle(u32, s[16..20]); - t[6] = u32(readIntSliceLittle(u24, s[20..23])) << 7; - t[7] = u32(readIntSliceLittle(u24, s[23..26])) << 5; - t[8] = u32(readIntSliceLittle(u24, s[26..29])) << 4; - t[9] = (u32(readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2; + t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7; + t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5; + t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4; + t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2; carry1(h, t[0..]); } @@ -500,7 +500,7 @@ const Fe = struct { if (i + 1 < 10) { t[i + 1] += c[i]; } - t[i] -= c[i] * (i32(1) << shift); + t[i] -= c[i] * (@as(i32, 1) << shift); } fn toBytes(s: []u8, h: *const Fe) void { @@ -511,7 +511,7 @@ const Fe = struct { t[i] = h.b[i]; } - var q = (19 * t[9] + ((i32(1) << 24))) >> 25; + var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25; { var i: usize = 0; while (i < 5) : (i += 1) { diff --git a/lib/std/debug.zig b/lib/std/debug.zig index cd0c3863ff..02305086cc 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { const word = try stream.readIntLittle(u32); var bit_i: u5 = 0; while (true) : (bit_i += 1) { - if (word & (u32(1) << bit_i) != 0) { + if (word & (@as(u32, 1) << bit_i) != 0) { try list.append(word_i * 32 + bit_i); } if (bit_i == maxInt(u5)) break; @@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo // TODO the noasyncs here are workarounds fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 { - return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32)); + return if (is_64) try noasync in_stream.readIntLittle(u64) else @as(u64, try noasync in_stream.readIntLittle(u32)); } // TODO the noasyncs here are workarounds fn parseFormValueTargetAddrSize(in_stream: var) !u64 { if (@sizeOf(usize) == 4) { - return u64(try noasync in_stream.readIntLittle(u32)); + // TODO this cast should not be needed + return @as(u64, try noasync in_stream.readIntLittle(u32)); } else if (@sizeOf(usize) == 8) { return noasync in_stream.readIntLittle(u64); } else { @@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u // special opcodes const adjusted_opcode = opcode - opcode_base; const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); - const inc_line = i32(line_base) + i32(adjusted_opcode % line_range); + const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range); prog.line += inc_line; prog.address += inc_addr; if (try prog.checkLineMatch()) |info| return info; @@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr if (unit_length == 0) { return error.MissingDebugInfo; } - const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); + const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); const version = try di.dwarf_in_stream.readInt(u16, di.endian); // TODO support 3 and 5 @@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr // special opcodes const adjusted_opcode = opcode - opcode_base; const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); - const inc_line = i32(line_base) + i32(adjusted_opcode % line_range); + const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range); prog.line += inc_line; prog.address += inc_addr; if (try prog.checkLineMatch()) |info| return info; @@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void { var is_64: bool = undefined; const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); if (unit_length == 0) return; - const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); + const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); const version = try di.dwarf_in_stream.readInt(u16, di.endian); if (version < 2 or version > 5) return error.InvalidDebugInfo; @@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void { var is_64: bool = undefined; const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); if (unit_length == 0) return; - const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); + const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); const version = try di.dwarf_in_stream.readInt(u16, di.endian); if (version < 2 or version > 5) return error.InvalidDebugInfo; @@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 { } else { if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; ptr.* += 4; - return u64(first_32_bits); + // TODO this cast should not be needed + return @as(u64, first_32_bits); } } @@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) return in_stream.readIntLittle(u64); } else { if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; - return u64(first_32_bits); + // TODO this cast should not be needed + return @as(u64, first_32_bits); } } diff --git a/lib/std/debug/leb128.zig b/lib/std/debug/leb128.zig index cb59c5b0d2..ee1d1ac9ee 100644 --- a/lib/std/debug/leb128.zig +++ b/lib/std/debug/leb128.zig @@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T { var shift: usize = 0; while (true) { - const byte = u8(try in_stream.readByte()); + const byte: u8 = try in_stream.readByte(); if (shift > T.bit_count) return error.Overflow; var operand: UT = undefined; - if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) { + if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) { if (byte != 0x7f) return error.Overflow; } diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 3413788019..0e8792ca90 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -215,8 +215,8 @@ pub const ElfLib = struct { var i: usize = 0; while (i < self.hashtab[1]) : (i += 1) { - if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; - if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; + if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; + if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; if (0 == self.syms[i].st_shndx) continue; if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue; if (maybe_versym) |versym| { diff --git a/lib/std/elf.zig b/lib/std/elf.zig index b3aea3e5c6..3bb4054bfe 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -441,9 +441,9 @@ pub const Elf = struct { elf.program_header_offset = try in.readInt(u64, elf.endian); elf.section_header_offset = try in.readInt(u64, elf.endian); } else { - elf.entry_addr = u64(try in.readInt(u32, elf.endian)); - elf.program_header_offset = u64(try in.readInt(u32, elf.endian)); - elf.section_header_offset = u64(try in.readInt(u32, elf.endian)); + elf.entry_addr = @as(u64, try in.readInt(u32, elf.endian)); + elf.program_header_offset = @as(u64, try in.readInt(u32, elf.endian)); + elf.section_header_offset = @as(u64, try in.readInt(u32, elf.endian)); } // skip over flags @@ -458,13 +458,13 @@ pub const Elf = struct { const ph_entry_count = try in.readInt(u16, elf.endian); const sh_entry_size = try in.readInt(u16, elf.endian); const sh_entry_count = try in.readInt(u16, elf.endian); - elf.string_section_index = usize(try in.readInt(u16, elf.endian)); + elf.string_section_index = @as(usize, try in.readInt(u16, elf.endian)); if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat; - const sh_byte_count = u64(sh_entry_size) * u64(sh_entry_count); + const sh_byte_count = @as(u64, sh_entry_size) * @as(u64, sh_entry_count); const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count); - const ph_byte_count = u64(ph_entry_size) * u64(ph_entry_count); + const ph_byte_count = @as(u64, ph_entry_size) * @as(u64, ph_entry_count); const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count); const stream_end = try seekable_stream.getEndPos(); @@ -499,14 +499,14 @@ pub const Elf = struct { // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ? elf_section.name = try in.readInt(u32, elf.endian); elf_section.sh_type = try in.readInt(u32, elf.endian); - elf_section.flags = u64(try in.readInt(u32, elf.endian)); - elf_section.addr = u64(try in.readInt(u32, elf.endian)); - elf_section.offset = u64(try in.readInt(u32, elf.endian)); - elf_section.size = u64(try in.readInt(u32, elf.endian)); + elf_section.flags = @as(u64, try in.readInt(u32, elf.endian)); + elf_section.addr = @as(u64, try in.readInt(u32, elf.endian)); + elf_section.offset = @as(u64, try in.readInt(u32, elf.endian)); + elf_section.size = @as(u64, try in.readInt(u32, elf.endian)); elf_section.link = try in.readInt(u32, elf.endian); elf_section.info = try in.readInt(u32, elf.endian); - elf_section.addr_align = u64(try in.readInt(u32, elf.endian)); - elf_section.ent_size = u64(try in.readInt(u32, elf.endian)); + elf_section.addr_align = @as(u64, try in.readInt(u32, elf.endian)); + elf_section.ent_size = @as(u64, try in.readInt(u32, elf.endian)); } } diff --git a/lib/std/event/fs.zig b/lib/std/event/fs.zig index d86bcbaed5..1035a51b81 100644 --- a/lib/std/event/fs.zig +++ b/lib/std/event/fs.zig @@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize { windows.ERROR.IO_PENDING => unreachable, windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, - windows.ERROR.HANDLE_EOF => return usize(bytes_transferred), + windows.ERROR.HANDLE_EOF => return @as(usize, bytes_transferred), else => |err| return windows.unexpectedError(err), } } - return usize(bytes_transferred); + return @as(usize, bytes_transferred); } /// iovecs must live until preadv frame completes diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig index b47dda34de..73f9b2dee7 100644 --- a/lib/std/fifo.zig +++ b/lib/std/fifo.zig @@ -257,7 +257,7 @@ test "ByteFifo" { defer fifo.deinit(); try fifo.write("HELLO"); - testing.expectEqual(usize(5), fifo.readableLength()); + testing.expectEqual(@as(usize, 5), fifo.readableLength()); testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0)); { @@ -265,34 +265,34 @@ test "ByteFifo" { while (i < 5) : (i += 1) { try fifo.write([_]u8{try fifo.peekItem(i)}); } - testing.expectEqual(usize(10), fifo.readableLength()); + testing.expectEqual(@as(usize, 10), fifo.readableLength()); testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); } { - testing.expectEqual(u8('H'), try fifo.readItem()); - testing.expectEqual(u8('E'), try fifo.readItem()); - testing.expectEqual(u8('L'), try fifo.readItem()); - testing.expectEqual(u8('L'), try fifo.readItem()); - testing.expectEqual(u8('O'), try fifo.readItem()); + testing.expectEqual(@as(u8, 'H'), try fifo.readItem()); + testing.expectEqual(@as(u8, 'E'), try fifo.readItem()); + testing.expectEqual(@as(u8, 'L'), try fifo.readItem()); + testing.expectEqual(@as(u8, 'L'), try fifo.readItem()); + testing.expectEqual(@as(u8, 'O'), try fifo.readItem()); } - testing.expectEqual(usize(5), fifo.readableLength()); + testing.expectEqual(@as(usize, 5), fifo.readableLength()); { // Writes that wrap around - testing.expectEqual(usize(11), fifo.writableLength()); - testing.expectEqual(usize(6), fifo.writableSlice(0).len); + testing.expectEqual(@as(usize, 11), fifo.writableLength()); + testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len); fifo.writeAssumeCapacity("6 buf.len) (width - buf.len) else return; const pad_byte: u8 = options.fill; while (leftover_padding > 0) : (leftover_padding -= 1) { - try output(context, (*const [1]u8)(&pad_byte)[0..1]); + try output(context, @as(*const [1]u8, &pad_byte)[0..1]); } } @@ -668,7 +668,7 @@ pub fn formatFloatScientific( try output(context, float_decimal.digits[0..1]); try output(context, "."); if (float_decimal.digits.len > 1) { - const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len; + const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; try output(context, float_decimal.digits[1..num_digits]); } else { @@ -703,7 +703,7 @@ pub fn formatFloatDecimal( comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void, ) Errors!void { - var x = f64(value); + var x = @as(f64, value); // Errol doesn't handle these special cases. if (math.signbit(x)) { @@ -921,14 +921,14 @@ fn formatIntSigned( const uint = @IntType(false, @typeOf(value).bit_count); if (value < 0) { const minus_sign: u8 = '-'; - try output(context, (*const [1]u8)(&minus_sign)[0..]); + try output(context, @as(*const [1]u8, &minus_sign)[0..]); const new_value = @intCast(uint, -(value + 1)) + 1; return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); } else if (options.width == null or options.width.? == 0) { return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output); } else { const plus_sign: u8 = '+'; - try output(context, (*const [1]u8)(&plus_sign)[0..]); + try output(context, @as(*const [1]u8, &plus_sign)[0..]); const new_value = @intCast(uint, value); return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); } @@ -966,7 +966,7 @@ fn formatIntUnsigned( const zero_byte: u8 = options.fill; var leftover_padding = padding - index; while (true) { - try output(context, (*const [1]u8)(&zero_byte)[0..]); + try output(context, @as(*const [1]u8, &zero_byte)[0..]); leftover_padding -= 1; if (leftover_padding == 0) break; } @@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { fn digitToChar(digit: u8, uppercase: bool) u8 { return switch (digit) { 0...9 => digit + '0', - 10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10), + 10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10), else => unreachable, }; } @@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { test "bufPrintInt" { var buffer: [100]u8 = undefined; const buf = buffer[0..]; - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, FormatOptions{}), "-BC614E")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, FormatOptions{}), "12345678")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, FormatOptions{ .width = 6 }), " 666")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 1 }), "1234")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, FormatOptions{ .width = 3 }), "+42")); - testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, FormatOptions{ .width = 3 }), "-42")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42")); + testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42")); } fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 { @@ -1208,8 +1208,8 @@ test "int.specifier" { } test "int.padded" { - try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1)); - try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", u8(1)); + try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1)); + try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1)); } test "buffer" { @@ -1287,8 +1287,8 @@ test "filesize" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024)); - try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", usize(63 * 1024 * 1024)); + try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024)); + try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024)); } test "struct" { @@ -1327,8 +1327,8 @@ test "float.scientific" { } try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34)); try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34)); - try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10)); - try testFmt("f64: 9.99996e-40", "f64: {e}", f64(9.999960e-40)); + try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10)); + try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40)); } test "float.scientific.precision" { @@ -1336,12 +1336,12 @@ test "float.scientific.precision" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42)); - try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563)))); - try testFmt("f64: 7.81250e-03", "f64: {e:.5}", f64(@bitCast(f32, u32(1006632960)))); + try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42)); + try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563)))); + try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960)))); // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. - try testFmt("f64: 1.00001e+05", "f64: {e:.5}", f64(@bitCast(f32, u32(1203982400)))); + try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400)))); } test "float.special" { @@ -1364,21 +1364,21 @@ test "float.decimal" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29)); + try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29)); try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234)); try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567)); // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). // -11.12339... is rounded back up to -11.1234 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234)); try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345)); - try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235)); - try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0)); - try testFmt("f64: 6", "f64: {d:.0}", f64(5.700)); - try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999)); - try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0)); - try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003)); - try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45)); - try testFmt("f64: 0.00000", "f64: {d:.5}", f64(9.999960e-40)); + try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235)); + try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0)); + try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700)); + try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999)); + try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0)); + try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003)); + try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45)); + try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40)); } test "float.libc.sanity" { @@ -1386,22 +1386,22 @@ test "float.libc.sanity" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781)))); - try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389)))); - try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278)))); - try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133)))); - try testFmt("f64: 10.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1092616192)))); + try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781)))); + try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389)))); + try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278)))); + try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133)))); + try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192)))); // libc differences // // This is 0.015625 exactly according to gdb. We thus round down, // however glibc rounds up for some reason. This occurs for all // floats of the form x.yyyy25 on a precision point. - try testFmt("f64: 0.01563", "f64: {d:.5}", f64(@bitCast(f32, u32(1015021568)))); + try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568)))); // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 // also rounds to 630 so I'm inclined to believe libc is not // optimal here. - try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1518338049)))); + try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049)))); } test "custom" { @@ -1677,17 +1677,17 @@ test "formatType max_depth" { } test "positional" { - try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2)); - try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2)); - try testFmt("0 0", "{0} {0}", usize(0)); - try testFmt("0 1", "{} {1}", usize(0), usize(1)); - try testFmt("1 0 0 1", "{1} {} {0} {}", usize(0), usize(1)); + try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); + try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); + try testFmt("0 0", "{0} {0}", @as(usize, 0)); + try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1)); + try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1)); } test "positional with specifier" { - try testFmt("10.0", "{0d:.1}", f64(9.999)); + try testFmt("10.0", "{0d:.1}", @as(f64, 9.999)); } test "positional/alignment/width/precision" { - try testFmt("10.0", "{0d: >3.1}", f64(9.999)); + try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999)); } diff --git a/lib/std/fmt/errol.zig b/lib/std/fmt/errol.zig index a835195fc7..e697b7d42f 100644 --- a/lib/std/fmt/errol.zig +++ b/lib/std/fmt/errol.zig @@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void { /// @buf: The output buffer. /// &return: The exponent. fn errolInt(val: f64, buffer: []u8) FloatDecimal { - const pow19 = u128(1e19); + const pow19 = @as(u128, 1e19); assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); @@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 { const bits = @bitCast(u64, from); assert((bits & ((1 << 52) - 1)) == 0); - return u128(1) << @truncate(u7, (bits >> 52) -% 1023); + return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023); } /// Given two different integers with the same length in terms of the number diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig index 9a35e27c21..aa3ac6d458 100644 --- a/lib/std/fmt/parse_float.zig +++ b/lib/std/fmt/parse_float.zig @@ -59,29 +59,29 @@ const Z96 = struct { // d += s inline fn add(d: *Z96, s: Z96) void { - var w = u64(d.d0) + u64(s.d0); + var w = @as(u64, d.d0) + @as(u64, s.d0); d.d0 = @truncate(u32, w); w >>= 32; - w += u64(d.d1) + u64(s.d1); + w += @as(u64, d.d1) + @as(u64, s.d1); d.d1 = @truncate(u32, w); w >>= 32; - w += u64(d.d2) + u64(s.d2); + w += @as(u64, d.d2) + @as(u64, s.d2); d.d2 = @truncate(u32, w); } // d -= s inline fn sub(d: *Z96, s: Z96) void { - var w = u64(d.d0) -% u64(s.d0); + var w = @as(u64, d.d0) -% @as(u64, s.d0); d.d0 = @truncate(u32, w); w >>= 32; - w += u64(d.d1) -% u64(s.d1); + w += @as(u64, d.d1) -% @as(u64, s.d1); d.d1 = @truncate(u32, w); w >>= 32; - w += u64(d.d2) -% u64(s.d2); + w += @as(u64, d.d2) -% @as(u64, s.d2); d.d2 = @truncate(u32, w); } }; @@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T { break :blk if (n.negative) f64_minus_zero else f64_plus_zero; } else if (s.d2 != 0) { const binexs2 = @intCast(u64, binary_exponent) << 52; - const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2; + const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2; break :blk if (n.negative) rr | (1 << 63) else rr; } else { break :blk 0; diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index 431b89bebf..117e49369a 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -272,9 +272,9 @@ pub const File = struct { return Stat{ .size = @bitCast(u64, st.size), .mode = st.mode, - .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, - .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, - .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, + .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, + .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, + .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, }; } diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 3a4abcbcd9..1df434116c 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -306,7 +306,7 @@ test "hash struct deep" { test "testHash optional" { const a: ?u32 = 123; const b: ?u32 = null; - testing.expectEqual(testHash(a), testHash(u32(123))); + testing.expectEqual(testHash(a), testHash(@as(u32, 123))); testing.expect(testHash(a) != testHash(b)); testing.expectEqual(testHash(b), 0); } @@ -315,9 +315,9 @@ test "testHash array" { const a = [_]u32{ 1, 2, 3 }; const h = testHash(a); var hasher = Wyhash.init(0); - autoHash(&hasher, u32(1)); - autoHash(&hasher, u32(2)); - autoHash(&hasher, u32(3)); + autoHash(&hasher, @as(u32, 1)); + autoHash(&hasher, @as(u32, 2)); + autoHash(&hasher, @as(u32, 3)); testing.expectEqual(h, hasher.final()); } @@ -330,9 +330,9 @@ test "testHash struct" { const f = Foo{}; const h = testHash(f); var hasher = Wyhash.init(0); - autoHash(&hasher, u32(1)); - autoHash(&hasher, u32(2)); - autoHash(&hasher, u32(3)); + autoHash(&hasher, @as(u32, 1)); + autoHash(&hasher, @as(u32, 2)); + autoHash(&hasher, @as(u32, 3)); testing.expectEqual(h, hasher.final()); } diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 43e5b7a385..d31ee17105 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -214,7 +214,7 @@ pub const CityHash64 = struct { } fn hashLen0To16(str: []const u8) u64 { - const len: u64 = u64(str.len); + const len: u64 = @as(u64, str.len); if (len >= 8) { const mul: u64 = k2 +% len *% 2; const a: u64 = fetch64(str.ptr) +% k2; @@ -240,7 +240,7 @@ pub const CityHash64 = struct { } fn hashLen17To32(str: []const u8) u64 { - const len: u64 = u64(str.len); + const len: u64 = @as(u64, str.len); const mul: u64 = k2 +% len *% 2; const a: u64 = fetch64(str.ptr) *% k1; const b: u64 = fetch64(str.ptr + 8); @@ -251,7 +251,7 @@ pub const CityHash64 = struct { } fn hashLen33To64(str: []const u8) u64 { - const len: u64 = u64(str.len); + const len: u64 = @as(u64, str.len); const mul: u64 = k2 +% len *% 2; const a: u64 = fetch64(str.ptr) *% k2; const b: u64 = fetch64(str.ptr + 8); @@ -305,7 +305,7 @@ pub const CityHash64 = struct { return hashLen33To64(str); } - var len: u64 = u64(str.len); + var len: u64 = @as(u64, str.len); var x: u64 = fetch64(str.ptr + str.len - 40); var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56); diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig index cdcaf55610..6176ded81d 100644 --- a/lib/std/hash/crc.zig +++ b/lib/std/hash/crc.zig @@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type { const p = input[i .. i + 8]; // Unrolling this way gives ~50Mb/s increase - self.crc ^= (u32(p[0]) << 0); - self.crc ^= (u32(p[1]) << 8); - self.crc ^= (u32(p[2]) << 16); - self.crc ^= (u32(p[3]) << 24); + self.crc ^= (@as(u32, p[0]) << 0); + self.crc ^= (@as(u32, p[1]) << 8); + self.crc ^= (@as(u32, p[2]) << 16); + self.crc ^= (@as(u32, p[3]) << 24); self.crc = lookup_tables[0][p[7]] ^ diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index a0c8f91338..f70190d311 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -98,7 +98,7 @@ pub const Murmur2_64 = struct { pub fn hashWithSeed(str: []const u8, seed: u64) u64 { const m: u64 = 0xc6a4a7935bd1e995; - const len = u64(str.len); + const len = @as(u64, str.len); var h1: u64 = seed ^ (len *% m); for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { var k1: u64 = v; diff --git a/lib/std/hash/siphash.zig b/lib/std/hash/siphash.zig index 3d67ba685b..c3a9184fa4 100644 --- a/lib/std/hash/siphash.zig +++ b/lib/std/hash/siphash.zig @@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round } const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3; - return (u128(b2) << 64) | b1; + return (@as(u128, b2) << 64) | b1; } fn round(self: *Self, b: []const u8) void { @@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round fn sipRound(d: *Self) void { d.v0 +%= d.v1; - d.v1 = math.rotl(u64, d.v1, u64(13)); + d.v1 = math.rotl(u64, d.v1, @as(u64, 13)); d.v1 ^= d.v0; - d.v0 = math.rotl(u64, d.v0, u64(32)); + d.v0 = math.rotl(u64, d.v0, @as(u64, 32)); d.v2 +%= d.v3; - d.v3 = math.rotl(u64, d.v3, u64(16)); + d.v3 = math.rotl(u64, d.v3, @as(u64, 16)); d.v3 ^= d.v2; d.v0 +%= d.v3; - d.v3 = math.rotl(u64, d.v3, u64(21)); + d.v3 = math.rotl(u64, d.v3, @as(u64, 21)); d.v3 ^= d.v0; d.v2 +%= d.v1; - d.v1 = math.rotl(u64, d.v1, u64(17)); + d.v1 = math.rotl(u64, d.v1, @as(u64, 17)); d.v1 ^= d.v2; - d.v2 = math.rotl(u64, d.v2, u64(32)); + d.v2 = math.rotl(u64, d.v2, @as(u64, 32)); } pub fn hash(key: []const u8, input: []const u8) T { diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 7c872de5ca..aae3b60831 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 } fn keyToIndex(hm: Self, key: K) usize { - return hm.constrainIndex(usize(hash(key))); + return hm.constrainIndex(@as(usize, hash(key))); } fn constrainIndex(hm: Self, i: usize) usize { diff --git a/lib/std/heap.zig b/lib/std/heap.zig index ccdab8d332..c9e9e3533d 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -896,7 +896,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo const large_align = u29(mem.page_size << 2); var align_mask: usize = undefined; - _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask); + _ = @shlWithOverflow(usize, ~@as(usize, 0), USizeShift(@ctz(u29, large_align)), &align_mask); var slice = try allocator.alignedAlloc(u8, large_align, 500); testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index 7ee035ce80..a860186e47 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -399,7 +399,7 @@ test "Headers.iterator" { } count += 1; } - testing.expectEqual(i32(2), count); + testing.expectEqual(@as(i32, 2), count); } test "Headers.contains" { @@ -420,10 +420,10 @@ test "Headers.delete" { try h.append("cookie", "somevalue", null); testing.expectEqual(false, h.delete("not-present")); - testing.expectEqual(usize(3), h.count()); + testing.expectEqual(@as(usize, 3), h.count()); testing.expectEqual(true, h.delete("foo")); - testing.expectEqual(usize(2), h.count()); + testing.expectEqual(@as(usize, 2), h.count()); { const e = h.at(0); testing.expectEqualSlices(u8, "baz", e.name); @@ -448,7 +448,7 @@ test "Headers.orderedRemove" { try h.append("cookie", "somevalue", null); h.orderedRemove(0); - testing.expectEqual(usize(2), h.count()); + testing.expectEqual(@as(usize, 2), h.count()); { const e = h.at(0); testing.expectEqualSlices(u8, "baz", e.name); @@ -471,7 +471,7 @@ test "Headers.swapRemove" { try h.append("cookie", "somevalue", null); h.swapRemove(0); - testing.expectEqual(usize(2), h.count()); + testing.expectEqual(@as(usize, 2), h.count()); { const e = h.at(0); testing.expectEqualSlices(u8, "cookie", e.name); diff --git a/lib/std/io.zig b/lib/std/io.zig index 95280b888f..4fcee6ec14 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -353,7 +353,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { const Buf = @IntType(false, buf_bit_count); const BufShift = math.Log2Int(Buf); - out_bits.* = usize(0); + out_bits.* = @as(usize, 0); if (U == u0 or bits == 0) return 0; var out_buffer = Buf(0); @@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { var self = @fieldParentPtr(Self, "stream", self_stream); var out_bits: usize = undefined; - var out_bits_total = usize(0); + var out_bits_total = @as(usize, 0); //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced if (self.bit_count > 0) { for (buffer) |*b, i| { diff --git a/lib/std/io/out_stream.zig b/lib/std/io/out_stream.zig index 42c40337a8..c0cd6e48a1 100644 --- a/lib/std/io/out_stream.zig +++ b/lib/std/io/out_stream.zig @@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type { } pub fn writeByte(self: *Self, byte: u8) Error!void { - const slice = (*const [1]u8)(&byte)[0..]; + const slice = @as(*const [1]u8, &byte)[0..]; return self.writeFn(self, slice); } pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void { - const slice = (*const [1]u8)(&byte)[0..]; + const slice = @as(*const [1]u8, &byte)[0..]; var i: usize = 0; while (i < n) : (i += 1) { try self.writeFn(self, slice); diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index e93b74169b..1fa7fc594c 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -228,8 +228,8 @@ test "BitOutStream" { try bit_stream_be.writeBits(u2(1), 1); try bit_stream_be.writeBits(u5(2), 2); - try bit_stream_be.writeBits(u128(3), 3); - try bit_stream_be.writeBits(u8(4), 4); + try bit_stream_be.writeBits(@as(u128, 3), 3); + try bit_stream_be.writeBits(@as(u8, 4), 4); try bit_stream_be.writeBits(u9(5), 5); try bit_stream_be.writeBits(u1(1), 1); @@ -242,33 +242,33 @@ test "BitOutStream" { expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); mem_out_be.pos = 0; - try bit_stream_be.writeBits(u32(0b110011010000101), 16); + try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16); expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); - try bit_stream_be.writeBits(u0(0), 0); + try bit_stream_be.writeBits(@as(u0, 0), 0); var mem_out_le = io.SliceOutStream.init(mem_le[0..]); var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream); - try bit_stream_le.writeBits(u2(1), 1); - try bit_stream_le.writeBits(u5(2), 2); - try bit_stream_le.writeBits(u128(3), 3); - try bit_stream_le.writeBits(u8(4), 4); - try bit_stream_le.writeBits(u9(5), 5); - try bit_stream_le.writeBits(u1(1), 1); + try bit_stream_le.writeBits(@as(u2, 1), 1); + try bit_stream_le.writeBits(@as(u5, 2), 2); + try bit_stream_le.writeBits(@as(u128, 3), 3); + try bit_stream_le.writeBits(@as(u8, 4), 4); + try bit_stream_le.writeBits(@as(u9, 5), 5); + try bit_stream_le.writeBits(@as(u1, 1), 1); expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); mem_out_le.pos = 0; - try bit_stream_le.writeBits(u15(0b110011010000101), 15); + try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15); try bit_stream_le.flushBits(); expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); mem_out_le.pos = 0; - try bit_stream_le.writeBits(u32(0b1100110100001011), 16); + try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16); expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); - try bit_stream_le.writeBits(u0(0), 0); + try bit_stream_le.writeBits(@as(u0, 0), 0); } test "BitStreams with File Stream" { @@ -282,12 +282,12 @@ test "BitStreams with File Stream" { const OutError = File.WriteError; var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); - try bit_stream.writeBits(u2(1), 1); - try bit_stream.writeBits(u5(2), 2); - try bit_stream.writeBits(u128(3), 3); - try bit_stream.writeBits(u8(4), 4); - try bit_stream.writeBits(u9(5), 5); - try bit_stream.writeBits(u1(1), 1); + try bit_stream.writeBits(@as(u2, 1), 1); + try bit_stream.writeBits(@as(u5, 2), 2); + try bit_stream.writeBits(@as(u128, 3), 3); + try bit_stream.writeBits(@as(u8, 4), 4); + try bit_stream.writeBits(@as(u9, 5), 5); + try bit_stream.writeBits(@as(u1, 1), 1); try bit_stream.flushBits(); } { @@ -603,7 +603,7 @@ test "c out stream" { } const out_stream = &io.COutStream.init(out_file).stream; - try out_stream.print("hi: {}\n", i32(123)); + try out_stream.print("hi: {}\n", @as(i32, 123)); } test "File seek ops" { diff --git a/lib/std/json.zig b/lib/std/json.zig index 6cd032806e..ecf0bf822b 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1343,7 +1343,7 @@ test "write json then parse it" { try jw.emitBool(true); try jw.objectField("int"); - try jw.emitNumber(i32(1234)); + try jw.emitNumber(@as(i32, 1234)); try jw.objectField("array"); try jw.beginArray(); @@ -1352,7 +1352,7 @@ test "write json then parse it" { try jw.emitNull(); try jw.arrayElem(); - try jw.emitNumber(f64(12.34)); + try jw.emitNumber(@as(f64, 12.34)); try jw.endArray(); diff --git a/lib/std/math.zig b/lib/std/math.zig index 9b56d0b8ce..7c672c7ae8 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079; pub const sqrt1_2 = 0.707106781186547524400844362104849039; // From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128) -pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001)); -pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000)); -pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); -pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000)); +pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001)); +pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000)); +pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); +pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000)); pub const f128_toint = 1.0 / f128_epsilon; // float.h details @@ -69,28 +69,28 @@ pub const f16_max = 65504; pub const f16_epsilon = 0.0009765625; // 2**-10 pub const f16_toint = 1.0 / f16_epsilon; -pub const nan_u16 = u16(0x7C01); +pub const nan_u16 = @as(u16, 0x7C01); pub const nan_f16 = @bitCast(f16, nan_u16); -pub const inf_u16 = u16(0x7C00); +pub const inf_u16 = @as(u16, 0x7C00); pub const inf_f16 = @bitCast(f16, inf_u16); -pub const nan_u32 = u32(0x7F800001); +pub const nan_u32 = @as(u32, 0x7F800001); pub const nan_f32 = @bitCast(f32, nan_u32); -pub const inf_u32 = u32(0x7F800000); +pub const inf_u32 = @as(u32, 0x7F800000); pub const inf_f32 = @bitCast(f32, inf_u32); -pub const nan_u64 = u64(0x7FF << 52) | 1; +pub const nan_u64 = @as(u64, 0x7FF << 52) | 1; pub const nan_f64 = @bitCast(f64, nan_u64); -pub const inf_u64 = u64(0x7FF << 52); +pub const inf_u64 = @as(u64, 0x7FF << 52); pub const inf_f64 = @bitCast(f64, inf_u64); -pub const nan_u128 = u128(0x7fff0000000000000000000000000001); +pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001); pub const nan_f128 = @bitCast(f128, nan_u128); -pub const inf_u128 = u128(0x7fff0000000000000000000000000000); +pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000); pub const inf_f128 = @bitCast(f128, inf_u128); pub const nan = @import("math/nan.zig").nan; @@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type { }, else => {}, } - return @typeOf(A(0) + B(0)); + return @typeOf(@as(A, 0) + @as(B, 0)); } /// Returns the smaller number. When one of the parameter's type's full range fits in the other, @@ -273,7 +273,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { } test "math.min" { - testing.expect(min(i32(-1), i32(2)) == -1); + testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1); { var a: u16 = 999; var b: u32 = 10; @@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) { } test "math.max" { - testing.expect(max(i32(-1), i32(2)) == 2); + testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2); } pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) { @@ -352,10 +352,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { } test "math.shl" { - testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000); - testing.expect(shl(u8, 0b11111111, usize(8)) == 0); - testing.expect(shl(u8, 0b11111111, usize(9)) == 0); - testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111); + testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000); + testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0); + testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0); + testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111); testing.expect(shl(u8, 0b11111111, 3) == 0b11111000); testing.expect(shl(u8, 0b11111111, 8) == 0); testing.expect(shl(u8, 0b11111111, 9) == 0); @@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T { } test "math.shr" { - testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111); - testing.expect(shr(u8, 0b11111111, usize(8)) == 0); - testing.expect(shr(u8, 0b11111111, usize(9)) == 0); - testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100); + testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111); + testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0); + testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0); + testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100); testing.expect(shr(u8, 0b11111111, 3) == 0b00011111); testing.expect(shr(u8, 0b11111111, 8) == 0); testing.expect(shr(u8, 0b11111111, 9) == 0); @@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T { } test "math.rotr" { - testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001); - testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000); - testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001); - testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000); - testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010); + testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001); + testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000); + testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001); + testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000); + testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010); } /// Rotates left. Only unsigned values can be rotated. @@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T { } test "math.rotl" { - testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001); - testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010); - testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001); - testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000); - testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000); + testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001); + testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010); + testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001); + testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000); + testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000); } pub fn Log2Int(comptime T: type) type { @@ -532,8 +532,8 @@ test "math.absInt" { comptime testAbsInt(); } fn testAbsInt() void { - testing.expect((absInt(i32(-10)) catch unreachable) == 10); - testing.expect((absInt(i32(10)) catch unreachable) == 10); + testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10); + testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10); } pub const absFloat = fabs; @@ -679,14 +679,14 @@ pub fn absCast(x: var) t: { } test "math.absCast" { - testing.expect(absCast(i32(-999)) == 999); - testing.expect(@typeOf(absCast(i32(-999))) == u32); + testing.expect(absCast(@as(i32, -999)) == 999); + testing.expect(@typeOf(absCast(@as(i32, -999))) == u32); - testing.expect(absCast(i32(999)) == 999); - testing.expect(@typeOf(absCast(i32(999))) == u32); + testing.expect(absCast(@as(i32, 999)) == 999); + testing.expect(@typeOf(absCast(@as(i32, 999))) == u32); - testing.expect(absCast(i32(minInt(i32))) == -minInt(i32)); - testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32); + testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32)); + testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32); testing.expect(absCast(-999) == 999); } @@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { } test "math.negateCast" { - testing.expect((negateCast(u32(999)) catch unreachable) == -999); - testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32); + testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); + testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); - testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32)); - testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32); + testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32)); + testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); - testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10))); + testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10))); } /// Cast an integer to a different integer type. If the value doesn't fit, @@ -729,13 +729,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { } test "math.cast" { - testing.expectError(error.Overflow, cast(u8, u32(300))); - testing.expectError(error.Overflow, cast(i8, i32(-200))); + testing.expectError(error.Overflow, cast(u8, @as(u32, 300))); + testing.expectError(error.Overflow, cast(i8, @as(i32, -200))); testing.expectError(error.Overflow, cast(u8, i8(-1))); testing.expectError(error.Overflow, cast(u64, i8(-1))); - testing.expect((try cast(u8, u32(255))) == u8(255)); - testing.expect(@typeOf(try cast(u8, u32(255))) == u8); + testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255)); + testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8); } pub const AlignCastError = error{UnalignedMemory}; @@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" { } fn testCeilPowerOfTwoPromote() void { - testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1)); - testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2)); - testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63)); - testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64)); - testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65)); - testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7)); - testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8)); - testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9)); - testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9)); + testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1)); + testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2)); + testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63)); + testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64)); + testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65)); + testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7)); + testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8)); + testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9)); + testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); } test "math.ceilPowerOfTwo" { @@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" { } fn testCeilPowerOfTwo() !void { - testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1)); - testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2)); - testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63)); - testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64)); - testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65)); - testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7)); - testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8)); - testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9)); + testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1)); + testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2)); + testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63)); + testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64)); + testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65)); + testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7)); + testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8)); + testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9)); testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9)); } @@ -944,7 +944,7 @@ test "max value type" { pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) { const ResultInt = @IntType(T.is_signed, T.bit_count * 2); - return ResultInt(a) * ResultInt(b); + return @as(ResultInt, a) * @as(ResultInt, b); } test "math.mulWide" { diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig index de07da8fe0..94b6fc3f8f 100644 --- a/lib/std/math/acos.zig +++ b/lib/std/math/acos.zig @@ -149,8 +149,8 @@ fn acos64(x: f64) f64 { } test "math.acos" { - expect(acos(f32(0.0)) == acos32(0.0)); - expect(acos(f64(0.0)) == acos64(0.0)); + expect(acos(@as(f32, 0.0)) == acos32(0.0)); + expect(acos(@as(f64, 0.0)) == acos64(0.0)); } test "math.acos32" { diff --git a/lib/std/math/acosh.zig b/lib/std/math/acosh.zig index 503c0433fc..065e4d39de 100644 --- a/lib/std/math/acosh.zig +++ b/lib/std/math/acosh.zig @@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 { } test "math.acosh" { - expect(acosh(f32(1.5)) == acosh32(1.5)); - expect(acosh(f64(1.5)) == acosh64(1.5)); + expect(acosh(@as(f32, 1.5)) == acosh32(1.5)); + expect(acosh(@as(f64, 1.5)) == acosh64(1.5)); } test "math.acosh32" { diff --git a/lib/std/math/asin.zig b/lib/std/math/asin.zig index 2db9f86ff1..d354f8ceed 100644 --- a/lib/std/math/asin.zig +++ b/lib/std/math/asin.zig @@ -142,8 +142,8 @@ fn asin64(x: f64) f64 { } test "math.asin" { - expect(asin(f32(0.0)) == asin32(0.0)); - expect(asin(f64(0.0)) == asin64(0.0)); + expect(asin(@as(f32, 0.0)) == asin32(0.0)); + expect(asin(@as(f64, 0.0)) == asin64(0.0)); } test "math.asin32" { diff --git a/lib/std/math/asinh.zig b/lib/std/math/asinh.zig index 0fb51d1b43..b915df3171 100644 --- a/lib/std/math/asinh.zig +++ b/lib/std/math/asinh.zig @@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 { } test "math.asinh" { - expect(asinh(f32(0.0)) == asinh32(0.0)); - expect(asinh(f64(0.0)) == asinh64(0.0)); + expect(asinh(@as(f32, 0.0)) == asinh32(0.0)); + expect(asinh(@as(f64, 0.0)) == asinh64(0.0)); } test "math.asinh32" { diff --git a/lib/std/math/atan.zig b/lib/std/math/atan.zig index 5790eba8cf..ea639872be 100644 --- a/lib/std/math/atan.zig +++ b/lib/std/math/atan.zig @@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 { } test "math.atan" { - expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2))); - expect(atan(f64(0.2)) == atan64(0.2)); + expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2))); + expect(atan(@as(f64, 0.2)) == atan64(0.2)); } test "math.atan32" { diff --git a/lib/std/math/atanh.zig b/lib/std/math/atanh.zig index 8ba29be761..ae588f4fb8 100644 --- a/lib/std/math/atanh.zig +++ b/lib/std/math/atanh.zig @@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 { } test "math.atanh" { - expect(atanh(f32(0.0)) == atanh_32(0.0)); - expect(atanh(f64(0.0)) == atanh_64(0.0)); + expect(atanh(@as(f32, 0.0)) == atanh_32(0.0)); + expect(atanh(@as(f64, 0.0)) == atanh_64(0.0)); } test "math.atanh_32" { diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index bfdc768375..fa2424de07 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -261,7 +261,7 @@ pub const Int = struct { /// the minus sign. This is used for determining the number of characters needed to print the /// value. It is inexact and may exceed the given value by ~1-2 bytes. pub fn sizeInBase(self: Int, base: usize) usize { - const bit_count = usize(@boolToInt(!self.isPositive())) + self.bitCountAbs(); + const bit_count = @as(usize, @boolToInt(!self.isPositive())) + self.bitCountAbs(); return (bit_count / math.log2(base)) + 1; } diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig index 5241e31323..c9e205a495 100644 --- a/lib/std/math/cbrt.zig +++ b/lib/std/math/cbrt.zig @@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 { // first step newton to 16 bits var t: f64 = @bitCast(f32, u); var r: f64 = t * t * t; - t = t * (f64(x) + x + r) / (x + r + r); + t = t * (@as(f64, x) + x + r) / (x + r + r); // second step newton to 47 bits r = t * t * t; - t = t * (f64(x) + x + r) / (x + r + r); + t = t * (@as(f64, x) + x + r) / (x + r + r); return @floatCast(f32, t); } @@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 { } u &= 1 << 63; - u |= u64(hx) << 32; + u |= @as(u64, hx) << 32; var t = @bitCast(f64, u); // cbrt to 23 bits @@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 { } test "math.cbrt" { - expect(cbrt(f32(0.0)) == cbrt32(0.0)); - expect(cbrt(f64(0.0)) == cbrt64(0.0)); + expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0)); + expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0)); } test "math.cbrt32" { diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig index 5f86093a6d..b5a2238621 100644 --- a/lib/std/math/ceil.zig +++ b/lib/std/math/ceil.zig @@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 { if (e >= 23) { return x; } else if (e >= 0) { - m = u32(0x007FFFFF) >> @intCast(u5, e); + m = @as(u32, 0x007FFFFF) >> @intCast(u5, e); if (u & m == 0) { return x; } @@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 { } test "math.ceil" { - expect(ceil(f32(0.0)) == ceil32(0.0)); - expect(ceil(f64(0.0)) == ceil64(0.0)); + expect(ceil(@as(f32, 0.0)) == ceil32(0.0)); + expect(ceil(@as(f64, 0.0)) == ceil64(0.0)); } test "math.ceil32" { diff --git a/lib/std/math/complex/ldexp.zig b/lib/std/math/complex/ldexp.zig index d6f810793f..d74ac86148 100644 --- a/lib/std/math/complex/ldexp.zig +++ b/lib/std/math/complex/ldexp.zig @@ -59,7 +59,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 { expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k; const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20); - return @bitCast(f64, (u64(high_word) << 32) | lx); + return @bitCast(f64, (@as(u64, high_word) << 32) | lx); } fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) { diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig index 36f4c28e29..7e17f422bb 100644 --- a/lib/std/math/complex/sqrt.zig +++ b/lib/std/math/complex/sqrt.zig @@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) { // y = nan special case is handled fine below // double-precision avoids overflow with correct rounding. - const dx = f64(x); - const dy = f64(y); + const dx = @as(f64, x); + const dy = @as(f64, y); if (dx >= 0) { const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5); diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig index 6895e8a769..fc7f4e9ea8 100644 --- a/lib/std/math/complex/tanh.zig +++ b/lib/std/math/complex/tanh.zig @@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) { return Complex(f64).new(x, r); } - const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx); + const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx); const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y); return Complex(f64).new(xx, math.copysign(f64, 0, r)); } diff --git a/lib/std/math/copysign.zig b/lib/std/math/copysign.zig index e4d90c395e..e874da0bb9 100644 --- a/lib/std/math/copysign.zig +++ b/lib/std/math/copysign.zig @@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 { const uy = @bitCast(u16, y); const h1 = ux & (maxInt(u16) / 2); - const h2 = uy & (u16(1) << 15); + const h2 = uy & (@as(u16, 1) << 15); return @bitCast(f16, h1 | h2); } @@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 { const uy = @bitCast(u32, y); const h1 = ux & (maxInt(u32) / 2); - const h2 = uy & (u32(1) << 31); + const h2 = uy & (@as(u32, 1) << 31); return @bitCast(f32, h1 | h2); } @@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 { const uy = @bitCast(u64, y); const h1 = ux & (maxInt(u64) / 2); - const h2 = uy & (u64(1) << 63); + const h2 = uy & (@as(u64, 1) << 63); return @bitCast(f64, h1 | h2); } diff --git a/lib/std/math/cos.zig b/lib/std/math/cos.zig index 5261a25f80..68e13e41bf 100644 --- a/lib/std/math/cos.zig +++ b/lib/std/math/cos.zig @@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T { } test "math.cos" { - expect(cos(f32(0.0)) == cos_(f32, 0.0)); - expect(cos(f64(0.0)) == cos_(f64, 0.0)); + expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0)); + expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0)); } test "math.cos32" { diff --git a/lib/std/math/cosh.zig b/lib/std/math/cosh.zig index 75c5c15ec1..62bedeaa49 100644 --- a/lib/std/math/cosh.zig +++ b/lib/std/math/cosh.zig @@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 { } test "math.cosh" { - expect(cosh(f32(1.5)) == cosh32(1.5)); - expect(cosh(f64(1.5)) == cosh64(1.5)); + expect(cosh(@as(f32, 1.5)) == cosh32(1.5)); + expect(cosh(@as(f64, 1.5)) == cosh64(1.5)); } test "math.cosh32" { diff --git a/lib/std/math/exp.zig b/lib/std/math/exp.zig index 718bbcd476..e1297b11bc 100644 --- a/lib/std/math/exp.zig +++ b/lib/std/math/exp.zig @@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 { } test "math.exp" { - assert(exp(f32(0.0)) == exp32(0.0)); - assert(exp(f64(0.0)) == exp64(0.0)); + assert(exp(@as(f32, 0.0)) == exp32(0.0)); + assert(exp(@as(f64, 0.0)) == exp64(0.0)); } test "math.exp32" { diff --git a/lib/std/math/exp2.zig b/lib/std/math/exp2.zig index 57f6620d77..f3e51e542e 100644 --- a/lib/std/math/exp2.zig +++ b/lib/std/math/exp2.zig @@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 { const k = i_0 / tblsiz; // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the // intended result but should confirm how GCC/Clang handle this to ensure. - const uk = @bitCast(f64, u64(0x3FF + k) << 52); + const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52); i_0 &= tblsiz - 1; uf -= redux; @@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 { } test "math.exp2" { - expect(exp2(f32(0.8923)) == exp2_32(0.8923)); - expect(exp2(f64(0.8923)) == exp2_64(0.8923)); + expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923)); + expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923)); } test "math.exp2_32" { diff --git a/lib/std/math/expm1.zig b/lib/std/math/expm1.zig index 5e347f86f6..871fa38449 100644 --- a/lib/std/math/expm1.zig +++ b/lib/std/math/expm1.zig @@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 { } test "math.exp1m" { - expect(expm1(f32(0.0)) == expm1_32(0.0)); - expect(expm1(f64(0.0)) == expm1_64(0.0)); + expect(expm1(@as(f32, 0.0)) == expm1_32(0.0)); + expect(expm1(@as(f64, 0.0)) == expm1_64(0.0)); } test "math.expm1_32" { diff --git a/lib/std/math/expo2.zig b/lib/std/math/expo2.zig index c00098a5a7..590f36bb18 100644 --- a/lib/std/math/expo2.zig +++ b/lib/std/math/expo2.zig @@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 { const kln2 = 0x1.62066151ADD8BP+10; const u = (0x3FF + k / 2) << 20; - const scale = @bitCast(f64, u64(u) << 32); + const scale = @bitCast(f64, @as(u64, u) << 32); return math.exp(x - kln2) * scale * scale; } diff --git a/lib/std/math/fabs.zig b/lib/std/math/fabs.zig index 6469f38835..e0eadd0d00 100644 --- a/lib/std/math/fabs.zig +++ b/lib/std/math/fabs.zig @@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 { } test "math.fabs" { - expect(fabs(f16(1.0)) == fabs16(1.0)); - expect(fabs(f32(1.0)) == fabs32(1.0)); - expect(fabs(f64(1.0)) == fabs64(1.0)); - expect(fabs(f128(1.0)) == fabs128(1.0)); + expect(fabs(@as(f16, 1.0)) == fabs16(1.0)); + expect(fabs(@as(f32, 1.0)) == fabs32(1.0)); + expect(fabs(@as(f64, 1.0)) == fabs64(1.0)); + expect(fabs(@as(f128, 1.0)) == fabs128(1.0)); } test "math.fabs16" { diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig index e5ff2b1fc1..f2cabe8f02 100644 --- a/lib/std/math/floor.zig +++ b/lib/std/math/floor.zig @@ -40,7 +40,7 @@ fn floor16(x: f16) f16 { } if (e >= 0) { - m = u16(1023) >> @intCast(u4, e); + m = @as(u16, 1023) >> @intCast(u4, e); if (u & m == 0) { return x; } @@ -74,7 +74,7 @@ fn floor32(x: f32) f32 { } if (e >= 0) { - m = u32(0x007FFFFF) >> @intCast(u5, e); + m = @as(u32, 0x007FFFFF) >> @intCast(u5, e); if (u & m == 0) { return x; } @@ -123,9 +123,9 @@ fn floor64(x: f64) f64 { } test "math.floor" { - expect(floor(f16(1.3)) == floor16(1.3)); - expect(floor(f32(1.3)) == floor32(1.3)); - expect(floor(f64(1.3)) == floor64(1.3)); + expect(floor(@as(f16, 1.3)) == floor16(1.3)); + expect(floor(@as(f32, 1.3)) == floor32(1.3)); + expect(floor(@as(f64, 1.3)) == floor64(1.3)); } test "math.floor16" { diff --git a/lib/std/math/fma.zig b/lib/std/math/fma.zig index 19c306fa2a..014593cda5 100644 --- a/lib/std/math/fma.zig +++ b/lib/std/math/fma.zig @@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T { } fn fma32(x: f32, y: f32, z: f32) f32 { - const xy = f64(x) * y; + const xy = @as(f64, x) * y; const xy_z = xy + z; const u = @bitCast(u64, xy_z); const e = (u >> 52) & 0x7FF; diff --git a/lib/std/math/frexp.zig b/lib/std/math/frexp.zig index 2759cd6492..93705ae6a4 100644 --- a/lib/std/math/frexp.zig +++ b/lib/std/math/frexp.zig @@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result { } test "math.frexp" { - const a = frexp(f32(1.3)); + const a = frexp(@as(f32, 1.3)); const b = frexp32(1.3); expect(a.significand == b.significand and a.exponent == b.exponent); - const c = frexp(f64(1.3)); + const c = frexp(@as(f64, 1.3)); const d = frexp64(1.3); expect(c.significand == d.significand and c.exponent == d.exponent); } diff --git a/lib/std/math/hypot.zig b/lib/std/math/hypot.zig index c15da1495e..59116014b3 100644 --- a/lib/std/math/hypot.zig +++ b/lib/std/math/hypot.zig @@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 { yy *= 0x1.0p-90; } - return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y)); + return z * math.sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y)); } fn sq(hi: *f64, lo: *f64, x: f64) void { diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig index fe4158a6dd..8d23bb09a0 100644 --- a/lib/std/math/ilogb.zig +++ b/lib/std/math/ilogb.zig @@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 { } // NOTE: Should these be exposed publicly? -const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1); +const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1); const fp_ilogb0 = fp_ilogbnan; fn ilogb32(x: f32) i32 { @@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 { } test "math.ilogb" { - expect(ilogb(f32(0.2)) == ilogb32(0.2)); - expect(ilogb(f64(0.2)) == ilogb64(0.2)); + expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2)); + expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2)); } test "math.ilogb32" { diff --git a/lib/std/math/isfinite.zig b/lib/std/math/isfinite.zig index 99eba668f9..3d23a0f3bf 100644 --- a/lib/std/math/isfinite.zig +++ b/lib/std/math/isfinite.zig @@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool { } test "math.isFinite" { - expect(isFinite(f16(0.0))); - expect(isFinite(f16(-0.0))); - expect(isFinite(f32(0.0))); - expect(isFinite(f32(-0.0))); - expect(isFinite(f64(0.0))); - expect(isFinite(f64(-0.0))); + expect(isFinite(@as(f16, 0.0))); + expect(isFinite(@as(f16, -0.0))); + expect(isFinite(@as(f32, 0.0))); + expect(isFinite(@as(f32, -0.0))); + expect(isFinite(@as(f64, 0.0))); + expect(isFinite(@as(f64, -0.0))); expect(!isFinite(math.inf(f16))); expect(!isFinite(-math.inf(f16))); expect(!isFinite(math.inf(f32))); diff --git a/lib/std/math/isinf.zig b/lib/std/math/isinf.zig index 37934f4cf4..d691068be5 100644 --- a/lib/std/math/isinf.zig +++ b/lib/std/math/isinf.zig @@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool { } test "math.isInf" { - expect(!isInf(f16(0.0))); - expect(!isInf(f16(-0.0))); - expect(!isInf(f32(0.0))); - expect(!isInf(f32(-0.0))); - expect(!isInf(f64(0.0))); - expect(!isInf(f64(-0.0))); - expect(!isInf(f128(0.0))); - expect(!isInf(f128(-0.0))); + expect(!isInf(@as(f16, 0.0))); + expect(!isInf(@as(f16, -0.0))); + expect(!isInf(@as(f32, 0.0))); + expect(!isInf(@as(f32, -0.0))); + expect(!isInf(@as(f64, 0.0))); + expect(!isInf(@as(f64, -0.0))); + expect(!isInf(@as(f128, 0.0))); + expect(!isInf(@as(f128, -0.0))); expect(isInf(math.inf(f16))); expect(isInf(-math.inf(f16))); expect(isInf(math.inf(f32))); @@ -93,14 +93,14 @@ test "math.isInf" { } test "math.isPositiveInf" { - expect(!isPositiveInf(f16(0.0))); - expect(!isPositiveInf(f16(-0.0))); - expect(!isPositiveInf(f32(0.0))); - expect(!isPositiveInf(f32(-0.0))); - expect(!isPositiveInf(f64(0.0))); - expect(!isPositiveInf(f64(-0.0))); - expect(!isPositiveInf(f128(0.0))); - expect(!isPositiveInf(f128(-0.0))); + expect(!isPositiveInf(@as(f16, 0.0))); + expect(!isPositiveInf(@as(f16, -0.0))); + expect(!isPositiveInf(@as(f32, 0.0))); + expect(!isPositiveInf(@as(f32, -0.0))); + expect(!isPositiveInf(@as(f64, 0.0))); + expect(!isPositiveInf(@as(f64, -0.0))); + expect(!isPositiveInf(@as(f128, 0.0))); + expect(!isPositiveInf(@as(f128, -0.0))); expect(isPositiveInf(math.inf(f16))); expect(!isPositiveInf(-math.inf(f16))); expect(isPositiveInf(math.inf(f32))); @@ -112,14 +112,14 @@ test "math.isPositiveInf" { } test "math.isNegativeInf" { - expect(!isNegativeInf(f16(0.0))); - expect(!isNegativeInf(f16(-0.0))); - expect(!isNegativeInf(f32(0.0))); - expect(!isNegativeInf(f32(-0.0))); - expect(!isNegativeInf(f64(0.0))); - expect(!isNegativeInf(f64(-0.0))); - expect(!isNegativeInf(f128(0.0))); - expect(!isNegativeInf(f128(-0.0))); + expect(!isNegativeInf(@as(f16, 0.0))); + expect(!isNegativeInf(@as(f16, -0.0))); + expect(!isNegativeInf(@as(f32, 0.0))); + expect(!isNegativeInf(@as(f32, -0.0))); + expect(!isNegativeInf(@as(f64, 0.0))); + expect(!isNegativeInf(@as(f64, -0.0))); + expect(!isNegativeInf(@as(f128, 0.0))); + expect(!isNegativeInf(@as(f128, -0.0))); expect(!isNegativeInf(math.inf(f16))); expect(isNegativeInf(-math.inf(f16))); expect(!isNegativeInf(math.inf(f32))); diff --git a/lib/std/math/isnan.zig b/lib/std/math/isnan.zig index cf8cd2e1c2..ac865f0d0c 100644 --- a/lib/std/math/isnan.zig +++ b/lib/std/math/isnan.zig @@ -20,8 +20,8 @@ test "math.isNan" { expect(isNan(math.nan(f32))); expect(isNan(math.nan(f64))); expect(isNan(math.nan(f128))); - expect(!isNan(f16(1.0))); - expect(!isNan(f32(1.0))); - expect(!isNan(f64(1.0))); - expect(!isNan(f128(1.0))); + expect(!isNan(@as(f16, 1.0))); + expect(!isNan(@as(f32, 1.0))); + expect(!isNan(@as(f64, 1.0))); + expect(!isNan(@as(f128, 1.0))); } diff --git a/lib/std/math/isnormal.zig b/lib/std/math/isnormal.zig index f8611ef805..01d919d417 100644 --- a/lib/std/math/isnormal.zig +++ b/lib/std/math/isnormal.zig @@ -29,10 +29,10 @@ test "math.isNormal" { expect(!isNormal(math.nan(f16))); expect(!isNormal(math.nan(f32))); expect(!isNormal(math.nan(f64))); - expect(!isNormal(f16(0))); - expect(!isNormal(f32(0))); - expect(!isNormal(f64(0))); - expect(isNormal(f16(1.0))); - expect(isNormal(f32(1.0))); - expect(isNormal(f64(1.0))); + expect(!isNormal(@as(f16, 0))); + expect(!isNormal(@as(f32, 0))); + expect(!isNormal(@as(f64, 0))); + expect(isNormal(@as(f16, 1.0))); + expect(isNormal(@as(f32, 1.0))); + expect(isNormal(@as(f64, 1.0))); } diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig index c5d4c9ff25..362e44a869 100644 --- a/lib/std/math/ln.zig +++ b/lib/std/math/ln.zig @@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) { }; }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(ln_64(f64(x)))); + return @typeOf(1)(math.floor(ln_64(@as(f64, x)))); }, TypeId.Int => { - return T(math.floor(ln_64(f64(x)))); + return T(math.floor(ln_64(@as(f64, x)))); }, else => @compileError("ln not implemented for " ++ @typeName(T)), } @@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 { hx += 0x3FF00000 - 0x3FE6A09E; k += @intCast(i32, hx >> 20) - 0x3FF; hx = (hx & 0x000FFFFF) + 0x3FE6A09E; - ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); + ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); x = @bitCast(f64, ix); const f = x - 1.0; @@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 { } test "math.ln" { - expect(ln(f32(0.2)) == ln_32(0.2)); - expect(ln(f64(0.2)) == ln_64(0.2)); + expect(ln(@as(f32, 0.2)) == ln_32(0.2)); + expect(ln(@as(f64, 0.2)) == ln_64(0.2)); } test "math.ln32" { diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index 77f3639fd2..84dbcf939d 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T { const float_base = math.lossyCast(f64, base); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base)); + return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base)); }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base))); + return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); }, builtin.TypeId.Int => { // TODO implement integer log without using float math @@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T { builtin.TypeId.Float => { switch (T) { - f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)), + f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)), f64 => return math.ln(x) / math.ln(float_base), else => @compileError("log not implemented for " ++ @typeName(T)), } @@ -67,6 +67,6 @@ test "math.log float_special" { expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974))); expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974))); - expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993))); - expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993))); + expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993))); + expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993))); } diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index 9b0bc3ac52..a4b3fef26b 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { }; }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(log10_64(f64(x)))); + return @typeOf(1)(math.floor(log10_64(@as(f64, x)))); }, TypeId.Int => { return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); @@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 { hx += 0x3FF00000 - 0x3FE6A09E; k += @intCast(i32, hx >> 20) - 0x3FF; hx = (hx & 0x000FFFFF) + 0x3FE6A09E; - ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); + ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); x = @bitCast(f64, ix); const f = x - 1.0; @@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 { // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) var hi = f - hfsq; var hii = @bitCast(u64, hi); - hii &= u64(maxInt(u64)) << 32; + hii &= @as(u64, maxInt(u64)) << 32; hi = @bitCast(f64, hii); const lo = f - hi - hfsq + s * (hfsq + R); @@ -178,7 +178,7 @@ pub fn log10_64(x_: f64) f64 { test "math.log10" { testing.expect(log10(f32(0.2)) == log10_32(0.2)); - testing.expect(log10(f64(0.2)) == log10_64(0.2)); + testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2)); } test "math.log10_32" { diff --git a/lib/std/math/log1p.zig b/lib/std/math/log1p.zig index bae6deb536..047e089a91 100644 --- a/lib/std/math/log1p.zig +++ b/lib/std/math/log1p.zig @@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 { // u into [sqrt(2)/2, sqrt(2)] iu = (iu & 0x000FFFFF) + 0x3FE6A09E; - const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF); + const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF); f = @bitCast(f64, iq) - 1; } @@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 { } test "math.log1p" { - expect(log1p(f32(0.0)) == log1p_32(0.0)); - expect(log1p(f64(0.0)) == log1p_64(0.0)); + expect(log1p(@as(f32, 0.0)) == log1p_32(0.0)); + expect(log1p(@as(f64, 0.0)) == log1p_64(0.0)); } test "math.log1p_32" { diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index 88450a7ffd..47b214d6cf 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 { hx += 0x3FF00000 - 0x3FE6A09E; k += @intCast(i32, hx >> 20) - 0x3FF; hx = (hx & 0x000FFFFF) + 0x3FE6A09E; - ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); + ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); x = @bitCast(f64, ix); const f = x - 1.0; @@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 { // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) var hi = f - hfsq; var hii = @bitCast(u64, hi); - hii &= u64(maxInt(u64)) << 32; + hii &= @as(u64, maxInt(u64)) << 32; hi = @bitCast(f64, hii); const lo = f - hi - hfsq + s * (hfsq + R); @@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 { } test "math.log2" { - expect(log2(f32(0.2)) == log2_32(0.2)); - expect(log2(f64(0.2)) == log2_64(0.2)); + expect(log2(@as(f32, 0.2)) == log2_32(0.2)); + expect(log2(@as(f64, 0.2)) == log2_64(0.2)); } test "math.log2_32" { diff --git a/lib/std/math/modf.zig b/lib/std/math/modf.zig index 92194d4c75..6567cbc9ed 100644 --- a/lib/std/math/modf.zig +++ b/lib/std/math/modf.zig @@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result { return result; } - const mask = u32(0x007FFFFF) >> @intCast(u5, e); + const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e); if (u & mask == 0) { result.ipart = x; result.fpart = @bitCast(f32, us); @@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result { return result; } - const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e); + const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e); if (u & mask == 0) { result.ipart = x; result.fpart = @bitCast(f64, us); @@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result { } test "math.modf" { - const a = modf(f32(1.0)); + const a = modf(@as(f32, 1.0)); const b = modf32(1.0); // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still. expect(a.ipart == b.ipart and a.fpart == b.fpart); - const c = modf(f64(1.0)); + const c = modf(@as(f64, 1.0)); const d = modf64(1.0); expect(a.ipart == b.ipart and a.fpart == b.fpart); } diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig index 0b80a46ce5..adedbf2e94 100644 --- a/lib/std/math/round.zig +++ b/lib/std/math/round.zig @@ -91,8 +91,8 @@ fn round64(x_: f64) f64 { } test "math.round" { - expect(round(f32(1.3)) == round32(1.3)); - expect(round(f64(1.3)) == round64(1.3)); + expect(round(@as(f32, 1.3)) == round32(1.3)); + expect(round(@as(f64, 1.3)) == round64(1.3)); } test "math.round32" { diff --git a/lib/std/math/scalbn.zig b/lib/std/math/scalbn.zig index d5716d621c..e3c457ade5 100644 --- a/lib/std/math/scalbn.zig +++ b/lib/std/math/scalbn.zig @@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 { } test "math.scalbn" { - expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4)); - expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4)); + expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4)); + expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4)); } test "math.scalbn32" { diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig index e5c5909292..f20753f2ff 100644 --- a/lib/std/math/signbit.zig +++ b/lib/std/math/signbit.zig @@ -29,9 +29,9 @@ fn signbit64(x: f64) bool { } test "math.signbit" { - expect(signbit(f16(4.0)) == signbit16(4.0)); - expect(signbit(f32(4.0)) == signbit32(4.0)); - expect(signbit(f64(4.0)) == signbit64(4.0)); + expect(signbit(@as(f16, 4.0)) == signbit16(4.0)); + expect(signbit(@as(f32, 4.0)) == signbit32(4.0)); + expect(signbit(@as(f64, 4.0)) == signbit64(4.0)); } test "math.signbit16" { diff --git a/lib/std/math/sin.zig b/lib/std/math/sin.zig index ee07b4f85e..3baa730123 100644 --- a/lib/std/math/sin.zig +++ b/lib/std/math/sin.zig @@ -88,9 +88,9 @@ test "math.sin" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - expect(sin(f32(0.0)) == sin_(f32, 0.0)); - expect(sin(f64(0.0)) == sin_(f64, 0.0)); - expect(comptime (math.sin(f64(2))) == math.sin(f64(2))); + expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0)); + expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0)); + expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2))); } test "math.sin32" { diff --git a/lib/std/math/sinh.zig b/lib/std/math/sinh.zig index 73ee65ea6f..c9718e3ce2 100644 --- a/lib/std/math/sinh.zig +++ b/lib/std/math/sinh.zig @@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 { } test "math.sinh" { - expect(sinh(f32(1.5)) == sinh32(1.5)); - expect(sinh(f64(1.5)) == sinh64(1.5)); + expect(sinh(@as(f32, 1.5)) == sinh32(1.5)); + expect(sinh(@as(f64, 1.5)) == sinh64(1.5)); } test "math.sinh32" { diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index 30af5915d4..1b74c34eda 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ } test "math.sqrt" { - expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0)); - expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0)); - expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0)); + expect(sqrt(@as(f16, 0.0)) == @sqrt(f16, 0.0)); + expect(sqrt(@as(f32, 0.0)) == @sqrt(f32, 0.0)); + expect(sqrt(@as(f64, 0.0)) == @sqrt(f64, 0.0)); } test "math.sqrt16" { diff --git a/lib/std/math/tan.zig b/lib/std/math/tan.zig index 049c85df12..1a027cf403 100644 --- a/lib/std/math/tan.zig +++ b/lib/std/math/tan.zig @@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T { } test "math.tan" { - expect(tan(f32(0.0)) == tan_(f32, 0.0)); - expect(tan(f64(0.0)) == tan_(f64, 0.0)); + expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0)); + expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0)); } test "math.tan32" { diff --git a/lib/std/math/tanh.zig b/lib/std/math/tanh.zig index 48d26d091e..ced5f58bcc 100644 --- a/lib/std/math/tanh.zig +++ b/lib/std/math/tanh.zig @@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 { } test "math.tanh" { - expect(tanh(f32(1.5)) == tanh32(1.5)); - expect(tanh(f64(1.5)) == tanh64(1.5)); + expect(tanh(@as(f32, 1.5)) == tanh32(1.5)); + expect(tanh(@as(f64, 1.5)) == tanh64(1.5)); } test "math.tanh32" { diff --git a/lib/std/math/trunc.zig b/lib/std/math/trunc.zig index 219bcd4914..56a842345c 100644 --- a/lib/std/math/trunc.zig +++ b/lib/std/math/trunc.zig @@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 { e = 1; } - m = u32(maxInt(u32)) >> @intCast(u5, e); + m = @as(u32, maxInt(u32)) >> @intCast(u5, e); if (u & m == 0) { return x; } else { @@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 { e = 1; } - m = u64(maxInt(u64)) >> @intCast(u6, e); + m = @as(u64, maxInt(u64)) >> @intCast(u6, e); if (u & m == 0) { return x; } else { @@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 { } test "math.trunc" { - expect(trunc(f32(1.3)) == trunc32(1.3)); - expect(trunc(f64(1.3)) == trunc64(1.3)); + expect(trunc(@as(f32, 1.3)) == trunc32(1.3)); + expect(trunc(@as(f64, 1.3)) == trunc64(1.3)); } test "math.trunc32" { diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 8924828378..19e9634d5a 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -118,7 +118,7 @@ pub const Allocator = struct { } else @alignOf(T); if (n == 0) { - return ([*]align(a) T)(undefined)[0..0]; + return @as([*]align(a) T, undefined)[0..0]; } const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory; @@ -170,7 +170,7 @@ pub const Allocator = struct { } if (new_n == 0) { self.free(old_mem); - return ([*]align(new_alignment) T)(undefined)[0..0]; + return @as([*]align(new_alignment) T, undefined)[0..0]; } const old_byte_slice = @sliceToBytes(old_mem); @@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin. builtin.Endian.Little => { const ShiftType = math.Log2Int(ReturnType); for (bytes) |b, index| { - result = result | (ReturnType(b) << @intCast(ShiftType, index * 8)); + result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8)); } }, } @@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type { if (comptime !trait.isSingleItemPtr(P)) @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P)); - const size = usize(@sizeOf(meta.Child(P))); + const size = @as(usize, @sizeOf(meta.Child(P))); const alignment = comptime meta.alignment(P); if (alignment == 0) { @@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { } test "asBytes" { - const deadbeef = u32(0xDEADBEEF); + const deadbeef = @as(u32, 0xDEADBEEF); const deadbeef_bytes = switch (builtin.endian) { builtin.Endian.Big => "\xDE\xAD\xBE\xEF", builtin.Endian.Little => "\xEF\xBE\xAD\xDE", @@ -1361,7 +1361,7 @@ test "asBytes" { testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); - var codeface = u32(0xC0DEFACE); + var codeface = @as(u32, 0xC0DEFACE); for (asBytes(&codeface).*) |*b| b.* = 0; testing.expect(codeface == 0); @@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { } test "toBytes" { - var my_bytes = toBytes(u32(0x12345678)); + var my_bytes = toBytes(@as(u32, 0x12345678)); switch (builtin.endian) { builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")), builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")), @@ -1406,7 +1406,7 @@ test "toBytes" { } fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { - const size = usize(@sizeOf(T)); + const size = @as(usize, @sizeOf(T)); if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) { @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B)); @@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ } test "bytesAsValue" { - const deadbeef = u32(0xDEADBEEF); + const deadbeef = @as(u32, 0xDEADBEEF); const deadbeef_bytes = switch (builtin.endian) { builtin.Endian.Big => "\xDE\xAD\xBE\xEF", builtin.Endian.Little => "\xEF\xBE\xAD\xDE", @@ -1472,7 +1472,7 @@ test "bytesToValue" { }; const deadbeef = bytesToValue(u32, deadbeef_bytes); - testing.expect(deadbeef == u32(0xDEADBEEF)); + testing.expect(deadbeef == @as(u32, 0xDEADBEEF)); } fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { diff --git a/lib/std/meta.zig b/lib/std/meta.zig index b29eb60201..ded5aa4b1a 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -505,7 +505,7 @@ test "std.meta.eql" { const EU = struct { fn tst(err: bool) !u8 { if (err) return error.Error; - return u8(5); + return @as(u8, 5); } }; diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index 43be7f3dfb..8857b4aa9e 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool { } test "std.meta.trait.isConstPtr" { - var t = u8(0); - const c = u8(0); + var t = @as(u8, 0); + const c = @as(u8, 0); testing.expect(isConstPtr(*const @typeOf(t))); testing.expect(isConstPtr(@typeOf(&c))); testing.expect(!isConstPtr(*@typeOf(t))); diff --git a/lib/std/net.zig b/lib/std/net.zig index 95036707b6..fcb64d029a 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -611,7 +611,7 @@ fn linuxLookupName( // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary. mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr); } - if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; + if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL; prefixlen = prefixMatch(sa6.addr, da6.addr); } else |_| {} @@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 { // address. However the definition of the source prefix length is // not clear and thus this limiting is not yet implemented. var i: u8 = 0; - while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {} + while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {} return i; } @@ -1194,23 +1194,23 @@ fn dnsParse( if (r.len < 12) return error.InvalidDnsPacket; if ((r[3] & 15) != 0) return; var p = r.ptr + 12; - var qdcount = r[4] * usize(256) + r[5]; - var ancount = r[6] * usize(256) + r[7]; + var qdcount = r[4] * @as(usize, 256) + r[5]; + var ancount = r[6] * @as(usize, 256) + r[7]; if (qdcount + ancount > 64) return error.InvalidDnsPacket; while (qdcount != 0) { qdcount -= 1; while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) return error.InvalidDnsPacket; - p += usize(5) + @boolToInt(p[0] != 0); + p += @as(usize, 5) + @boolToInt(p[0] != 0); } while (ancount != 0) { ancount -= 1; while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) return error.InvalidDnsPacket; - p += usize(1) + @boolToInt(p[0] != 0); - const len = p[8] * usize(256) + p[9]; + p += @as(usize, 1) + @boolToInt(p[0] != 0); + const len = p[8] * @as(usize, 256) + p[9]; if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket; try callback(ctx, p[1], p[10 .. 10 + len], r); p += 10 + len; diff --git a/lib/std/os.zig b/lib/std/os.zig index 6803006bf1..c0f02c9a0b 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { var index: usize = 0; while (index < bytes.len) { - const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len)); + const amt_to_write = math.min(bytes.len - index, @as(usize, max_bytes_len)); const rc = system.write(fd, bytes.ptr + index, amt_to_write); switch (errno(rc)) { 0 => { @@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool { } if (builtin.os == .linux) { var wsz: linux.winsize = undefined; - return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; + return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; } unreachable; } @@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool { } const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]); - const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)]; + const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)]; const name_wide = @bytesToSlice(u16, name_bytes); return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null; @@ -2897,7 +2897,7 @@ pub fn res_mkquery( // Construct query template - ID will be filled later var q: [280]u8 = undefined; @memset(&q, 0, n); - q[2] = u8(op) * 8 + 1; + q[2] = @as(u8, op) * 8 + 1; q[5] = 1; mem.copy(u8, q[13..], name); var i: usize = 13; @@ -3143,7 +3143,7 @@ pub fn dn_expand( // loop invariants: p= msg.len) return error.InvalidDnsPacket; p = msg.ptr + j; diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index 87d89df7d8..042857b750 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -315,7 +315,7 @@ pub const dirent = extern struct { d_name: [256]u8, pub fn reclen(self: dirent) u16 { - return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7); + return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7); } }; diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 0fd528b0c0..e101337c3a 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400; pub const EPOLLERR = 0x008; pub const EPOLLHUP = 0x010; pub const EPOLLRDHUP = 0x2000; -pub const EPOLLEXCLUSIVE = (u32(1) << 28); -pub const EPOLLWAKEUP = (u32(1) << 29); -pub const EPOLLONESHOT = (u32(1) << 30); -pub const EPOLLET = (u32(1) << 31); +pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28); +pub const EPOLLWAKEUP = (@as(u32, 1) << 29); +pub const EPOLLONESHOT = (@as(u32, 1) << 30); +pub const EPOLLET = (@as(u32, 1) << 31); pub const CLOCK_REALTIME = 0; pub const CLOCK_MONOTONIC = 1; @@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool { } pub fn CAP_TO_MASK(cap: u8) u32 { - return u32(1) << u5(cap & 31); + return @as(u32, 1) << u5(cap & 31); } pub fn CAP_TO_INDEX(cap: u8) u8 { diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index a7dedefb43..618a21f456 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 { pub fn dup2(old: i32, new: i32) usize { if (@hasDecl(@This(), "SYS_dup2")) { - return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new))); + return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new))); } else { if (old == new) { if (std.debug.runtime_safety) { - const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD); + const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD); if (@bitCast(isize, rc) < 0) return rc; } return @intCast(usize, old); } else { - return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0); + return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0); } } } pub fn dup3(old: i32, new: i32, flags: u32) usize { - return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags); + return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags); } // TODO https://github.com/ziglang/zig/issues/265 @@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize { // TODO https://github.com/ziglang/zig/issues/265 pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize { - return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags); + return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); } pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize { @@ -120,7 +120,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { return syscall3( SYS_getdents, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @ptrToInt(dirp), std.math.min(len, maxInt(c_int)), ); @@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { return syscall3( SYS_getdents64, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @ptrToInt(dirp), std.math.min(len, maxInt(c_int)), ); @@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize { } pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize { - return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask); + return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask); } pub fn inotify_rm_watch(fd: i32, wd: i32) usize { - return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd))); + return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd))); } // TODO https://github.com/ziglang/zig/issues/265 @@ -152,13 +152,13 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz if (@hasDecl(@This(), "SYS_readlink")) { return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } else { - return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); + return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } } // TODO https://github.com/ziglang/zig/issues/265 pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { - return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); + return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } // TODO https://github.com/ziglang/zig/issues/265 @@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize { if (@hasDecl(@This(), "SYS_mkdir")) { return syscall2(SYS_mkdir, @ptrToInt(path), mode); } else { - return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode); + return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode); } } // TODO https://github.com/ziglang/zig/issues/265 pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { - return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); + return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode); } // TODO https://github.com/ziglang/zig/issues/265 @@ -194,7 +194,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of if (@hasDecl(@This(), "SYS_mmap2")) { // Make sure the offset is also specified in multiples of page size if ((offset & (MMAP2_UNIT - 1)) != 0) - return @bitCast(usize, isize(-EINVAL)); + return @bitCast(usize, @as(isize, -EINVAL)); return syscall6( SYS_mmap2, @@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of length, prot, flags, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @truncate(usize, offset / MMAP2_UNIT), ); } else { @@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of length, prot, flags, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), offset, ); } @@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { } pub fn read(fd: i32, buf: [*]u8, count: usize) usize { - return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); + return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); } pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { return syscall5( SYS_preadv, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, @truncate(usize, offset), @@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { return syscall6( SYS_preadv2, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, @truncate(usize, offset), @@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k } pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { - return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); + return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); } pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { - return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); + return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); } pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { return syscall5( SYS_pwritev, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, @truncate(usize, offset), @@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { return syscall6( SYS_pwritev2, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count, @truncate(usize, offset), @@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize { if (@hasDecl(@This(), "SYS_rmdir")) { return syscall1(SYS_rmdir, @ptrToInt(path)); } else { - return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); + return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); } } @@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { if (@hasDecl(@This(), "SYS_symlink")) { return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); } else { - return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); + return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); } } // TODO https://github.com/ziglang/zig/issues/265 pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { - return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath)); + return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath)); } // TODO https://github.com/ziglang/zig/issues/265 pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { - return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); + return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); } // TODO https://github.com/ziglang/zig/issues/265 @@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize { if (@hasDecl(@This(), "SYS_access")) { return syscall2(SYS_access, @ptrToInt(path), mode); } else { - return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0); + return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0); } } // TODO https://github.com/ziglang/zig/issues/265 pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize { - return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags); + return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags); } pub fn pipe(fd: *[2]i32) usize { @@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize { } pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { - return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); + return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); } pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { - return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); + return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); } // TODO https://github.com/ziglang/zig/issues/265 @@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize { if (@hasDecl(@This(), "SYS_rename")) { return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); } else if (@hasDecl(@This(), "SYS_renameat")) { - return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); + return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); } else { - return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0); + return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0); } } @@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const if (@hasDecl(@This(), "SYS_renameat")) { return syscall4( SYS_renameat, - @bitCast(usize, isize(oldfd)), + @bitCast(usize, @as(isize, oldfd)), @ptrToInt(old), - @bitCast(usize, isize(newfd)), + @bitCast(usize, @as(isize, newfd)), @ptrToInt(new), ); } else { return syscall5( SYS_renameat2, - @bitCast(usize, isize(oldfd)), + @bitCast(usize, @as(isize, oldfd)), @ptrToInt(old), - @bitCast(usize, isize(newfd)), + @bitCast(usize, @as(isize, newfd)), @ptrToInt(new), 0, ); @@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { return syscall5( SYS_renameat2, - @bitCast(usize, isize(oldfd)), + @bitCast(usize, @as(isize, oldfd)), @ptrToInt(oldpath), - @bitCast(usize, isize(newfd)), + @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath), flags, ); @@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { } else { return syscall4( SYS_openat, - @bitCast(usize, isize(AT_FDCWD)), + @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), flags, perm, @@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize { // TODO https://github.com/ziglang/zig/issues/265 pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { // dirfd could be negative, for example AT_FDCWD is -100 - return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode); + return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode); } /// See also `clone` (from the arch-specific include) @@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize { } pub fn close(fd: i32) usize { - return syscall1(SYS_close, @bitCast(usize, isize(fd))); + return syscall1(SYS_close, @bitCast(usize, @as(isize, fd))); } /// Can only be called on 32 bit systems. For 64 bit see `lseek`. pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { return syscall5( SYS__llseek, - @bitCast(usize, isize(fd)), + @bitCast(usize, @as(isize, fd)), @truncate(usize, offset >> 32), @truncate(usize, offset), @ptrToInt(result), @@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { /// Can only be called on 64 bit systems. For 32 bit see `llseek`. pub fn lseek(fd: i32, offset: i64, whence: usize) usize { - return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence); + return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence); } pub fn exit(status: i32) noreturn { - _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); + _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status))); unreachable; } pub fn exit_group(status: i32) noreturn { - _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status))); + _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status))); unreachable; } @@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { } pub fn kill(pid: i32, sig: i32) usize { - return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig))); + return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); } // TODO https://github.com/ziglang/zig/issues/265 @@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize { if (@hasDecl(@This(), "SYS_unlink")) { return syscall1(SYS_unlink, @ptrToInt(path)); } else { - return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0); + return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0); } } // TODO https://github.com/ziglang/zig/issues/265 pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { - return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags); + return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); } pub fn waitpid(pid: i32, status: *u32, flags: u32) usize { - return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0); + return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); } var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); @@ -519,12 +519,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); const rc = f(clk_id, tp); switch (rc) { - 0, @bitCast(usize, isize(-EINVAL)) => return rc, + 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc, else => {}, } } } - return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); + return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); } extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { @@ -537,15 +537,15 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); return f(clk, ts); } - return @bitCast(usize, isize(-ENOSYS)); + return @bitCast(usize, @as(isize, -ENOSYS)); } pub fn clock_getres(clk_id: i32, tp: *timespec) usize { - return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); + return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); } pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { - return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); + return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); } pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { @@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize { pub fn getuid() u32 { if (@hasDecl(@This(), "SYS_getuid32")) { - return u32(syscall0(SYS_getuid32)); + return @as(u32, syscall0(SYS_getuid32)); } else { - return u32(syscall0(SYS_getuid)); + return @as(u32, syscall0(SYS_getuid)); } } pub fn getgid() u32 { if (@hasDecl(@This(), "SYS_getgid32")) { - return u32(syscall0(SYS_getgid32)); + return @as(u32, syscall0(SYS_getgid32)); } else { - return u32(syscall0(SYS_getgid)); + return @as(u32, syscall0(SYS_getgid)); } } pub fn geteuid() u32 { if (@hasDecl(@This(), "SYS_geteuid32")) { - return u32(syscall0(SYS_geteuid32)); + return @as(u32, syscall0(SYS_geteuid32)); } else { - return u32(syscall0(SYS_geteuid)); + return @as(u32, syscall0(SYS_geteuid)); } } pub fn getegid() u32 { if (@hasDecl(@This(), "SYS_getegid32")) { - return u32(syscall0(SYS_getegid32)); + return @as(u32, syscall0(SYS_getegid32)); } else { - return u32(syscall0(SYS_getegid)); + return @as(u32, syscall0(SYS_getegid)); } } @@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { } pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { - return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); + return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); } pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { - return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); + return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); } pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { @@ -755,15 +755,15 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { } pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { - return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); + return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); } pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { - return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); + return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); } pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { - return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); + return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); } pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { @@ -781,7 +781,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize // batch-send all messages up to the current message if (next_unsent < i) { const batch_size = i - next_unsent; - const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); + const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); if (getErrno(r) != 0) return next_unsent; if (r < batch_size) return next_unsent + r; } @@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize } if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR) const batch_size = kvlen - next_unsent; - const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); + const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); if (getErrno(r) != 0) return r; return next_unsent + r; } return kvlen; } - return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags); + return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags); } pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { - return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len); + return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); } pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { - return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); + return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); } pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { - return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); + return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); } pub fn shutdown(fd: i32, how: i32) usize { - return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how))); + return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); } pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { - return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len)); + return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); } pub fn listen(fd: i32, backlog: u32) usize { - return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog); + return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog); } pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { - return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); + return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); } pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { @@ -843,14 +843,14 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { } pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize { - return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags); + return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); } pub fn fstat(fd: i32, stat_buf: *Stat) usize { if (@hasDecl(@This(), "SYS_fstat64")) { - return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); } else { - return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); } } @@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { // TODO https://github.com/ziglang/zig/issues/265 pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { if (@hasDecl(@This(), "SYS_fstatat64")) { - return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); } else { - return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); } } @@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S if (@hasDecl(@This(), "SYS_statx")) { return syscall5( SYS_statx, - @bitCast(usize, isize(dirfd)), + @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mask, @ptrToInt(statx_buf), ); } - return @bitCast(usize, isize(-ENOSYS)); + return @bitCast(usize, @as(isize, -ENOSYS)); } // TODO https://github.com/ziglang/zig/issues/265 @@ -959,7 +959,7 @@ pub fn sched_yield() usize { } pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize { - const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set)); + const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); if (@bitCast(isize, rc) < 0) return rc; if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); return 0; @@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize { } pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { - return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev)); + return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev)); } pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { @@ -984,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { return syscall6( SYS_epoll_pwait, - @bitCast(usize, isize(epoll_fd)), + @bitCast(usize, @as(isize, epoll_fd)), @ptrToInt(events), @intCast(usize, maxevents), - @bitCast(usize, isize(timeout)), + @bitCast(usize, @as(isize, timeout)), @ptrToInt(sigmask), @sizeOf(sigset_t), ); @@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize { } pub fn timerfd_create(clockid: i32, flags: u32) usize { - return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags); + return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags); } pub const itimerspec = extern struct { @@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct { }; pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { - return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value)); + return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value)); } pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { - return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); + return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); } pub fn unshare(flags: usize) usize { @@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { } pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { - return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); + return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); } pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize { - return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args); + return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args); } test "" { diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig index c7371fc28d..c457e10beb 100644 --- a/lib/std/os/linux/arm-eabi.zig +++ b/lib/std/os/linux/arm-eabi.zig @@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize { pub nakedcc fn restore() void { return asm volatile ("svc #0" : - : [number] "{r7}" (usize(SYS_sigreturn)) + : [number] "{r7}" (@as(usize, SYS_sigreturn)) : "memory" ); } @@ -108,7 +108,7 @@ pub nakedcc fn restore() void { pub nakedcc fn restore_rt() void { return asm volatile ("svc #0" : - : [number] "{r7}" (usize(SYS_rt_sigreturn)) + : [number] "{r7}" (@as(usize, SYS_rt_sigreturn)) : "memory" ); } diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig index b8d8a1636b..ac2bb3bfdf 100644 --- a/lib/std/os/linux/arm64.zig +++ b/lib/std/os/linux/arm64.zig @@ -93,7 +93,7 @@ pub const restore = restore_rt; pub nakedcc fn restore_rt() void { return asm volatile ("svc #0" : - : [number] "{x8}" (usize(SYS_rt_sigreturn)) + : [number] "{x8}" (@as(usize, SYS_rt_sigreturn)) : "memory", "cc" ); } diff --git a/lib/std/os/linux/mipsel.zig b/lib/std/os/linux/mipsel.zig index 791bec6a12..60408c1e84 100644 --- a/lib/std/os/linux/mipsel.zig +++ b/lib/std/os/linux/mipsel.zig @@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize { \\ sw $3, 4($4) \\ 2: : [ret] "={$2}" (-> usize) - : [number] "{$2}" (usize(SYS_pipe)) + : [number] "{$2}" (@as(usize, SYS_pipe)) : "memory", "cc", "$7" ); } @@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a pub nakedcc fn restore() void { return asm volatile ("syscall" : - : [number] "{$2}" (usize(SYS_sigreturn)) + : [number] "{$2}" (@as(usize, SYS_sigreturn)) : "memory", "cc", "$7" ); } @@ -155,7 +155,7 @@ pub nakedcc fn restore() void { pub nakedcc fn restore_rt() void { return asm volatile ("syscall" : - : [number] "{$2}" (usize(SYS_rt_sigreturn)) + : [number] "{$2}" (@as(usize, SYS_rt_sigreturn)) : "memory", "cc", "$7" ); } diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index 64facede89..b7c59a9039 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -92,7 +92,7 @@ pub const restore = restore_rt; pub nakedcc fn restore_rt() void { return asm volatile ("ecall" : - : [number] "{x17}" (usize(SYS_rt_sigreturn)) + : [number] "{x17}" (@as(usize, SYS_rt_sigreturn)) : "memory" ); } diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig index 86d54bfbf8..d3e00b8673 100644 --- a/lib/std/os/linux/vdso.zig +++ b/lib/std/os/linux/vdso.zig @@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { var i: usize = 0; while (i < hashtab[1]) : (i += 1) { - if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; - if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; + if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; + if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; if (0 == syms[i].st_shndx) continue; if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue; if (maybe_versym) |versym| { diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig index e0e4687c9f..d037b3c6ae 100644 --- a/lib/std/os/linux/x86_64.zig +++ b/lib/std/os/linux/x86_64.zig @@ -93,7 +93,7 @@ pub const restore = restore_rt; pub nakedcc fn restore_rt() void { return asm volatile ("syscall" : - : [number] "{rax}" (usize(SYS_rt_sigreturn)) + : [number] "{rax}" (@as(usize, SYS_rt_sigreturn)) : "rcx", "r11", "memory" ); } diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 1d61548396..741f108eea 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 { var counter = data.?; // Count how many libraries are loaded - counter.* += usize(1); + counter.* += @as(usize, 1); // The image should contain at least a PT_LOAD segment if (info.dlpi_phnum < 1) return -1; diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index c8c99c6a59..4342512941 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 { } pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 { - const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime); + const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime); return fromSysTime(hns); } diff --git a/lib/std/os/zen.zig b/lib/std/os/zen.zig index 9d111d98ae..190b7ffe08 100644 --- a/lib/std/os/zen.zig +++ b/lib/std/os/zen.zig @@ -138,7 +138,7 @@ pub const Syscall = enum(usize) { //////////////////// pub fn exit(status: i32) noreturn { - _ = syscall1(Syscall.exit, @bitCast(usize, isize(status))); + _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status))); unreachable; } @@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { } pub fn createThread(function: fn () void) u16 { - return u16(syscall1(Syscall.createThread, @ptrToInt(function))); + return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function))); } ///////////////////////// diff --git a/lib/std/packed_int_array.zig b/lib/std/packed_int_array.zig index 5cbab2d33b..c22d701bf2 100644 --- a/lib/std/packed_int_array.zig +++ b/lib/std/packed_int_array.zig @@ -331,7 +331,7 @@ test "PackedIntArray" { var data = PackedArray(undefined); //write values, counting up - var i = usize(0); + var i = @as(usize, 0); var count = I(0); while (i < data.len()) : (i += 1) { data.set(i, count); @@ -352,7 +352,7 @@ test "PackedIntArray" { test "PackedIntArray init" { const PackedArray = PackedIntArray(u3, 8); var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 }); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i); } @@ -375,7 +375,7 @@ test "PackedIntSlice" { var data = P.init(&buffer, int_count); //write values, counting up - var i = usize(0); + var i = @as(usize, 0); var count = I(0); while (i < data.len()) : (i += 1) { data.set(i, count); @@ -406,7 +406,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" { const limit = (1 << bits); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_array.len()) : (i += 1) { packed_array.set(i, @intCast(Int, i % limit)); } @@ -466,7 +466,7 @@ test "PackedIntSlice accumulating bit offsets" { var packed_array = PackedArray(undefined); var packed_slice = packed_array.slice(0, packed_array.len()); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_array.len() - 1) : (i += 1) { packed_slice = packed_slice.slice(1, packed_slice.len()); } @@ -476,7 +476,7 @@ test "PackedIntSlice accumulating bit offsets" { var packed_array = PackedArray(undefined); var packed_slice = packed_array.slice(0, packed_array.len()); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_array.len() - 1) : (i += 1) { packed_slice = packed_slice.slice(1, packed_slice.len()); } @@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" { var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9); const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_slice_cast_2.len()) : (i += 1) { const val = switch (builtin.endian) { .Big => 0b01, @@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" { testing.expect(packed_array_be.bytes[0] == 0b00000001); testing.expect(packed_array_be.bytes[1] == 0b00100011); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_array_be.len()) : (i += 1) { testing.expect(packed_array_be.get(i) == i); } @@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" { testing.expect(packed_array_be.bytes[3] == 0b00000001); testing.expect(packed_array_be.bytes[4] == 0b00000000); - var i = usize(0); + var i = @as(usize, 0); while (i < packed_array_be.len()) : (i += 1) { testing.expect(packed_array_be.get(i) == i); } diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index 7a2b2c6b6b..8e4a9b5d6a 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -532,7 +532,7 @@ const Msf = struct { const stream_sizes = try allocator.alloc(u32, stream_count); defer allocator.free(stream_sizes); - // Microsoft's implementation uses u32(-1) for inexistant streams. + // Microsoft's implementation uses @as(u32, -1) for inexistant streams. // These streams are not used, but still participate in the file // and must be taken into account when resolving stream indices. const Nil = 0xFFFFFFFF; diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig index a081e03c5f..bf54f6937f 100644 --- a/lib/std/priority_queue.zig +++ b/lib/std/priority_queue.zig @@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" { try queue.add(23); try queue.add(25); try queue.add(13); - expectEqual(u32(7), queue.remove()); - expectEqual(u32(12), queue.remove()); - expectEqual(u32(13), queue.remove()); - expectEqual(u32(23), queue.remove()); - expectEqual(u32(25), queue.remove()); - expectEqual(u32(54), queue.remove()); + expectEqual(@as(u32, 7), queue.remove()); + expectEqual(@as(u32, 12), queue.remove()); + expectEqual(@as(u32, 13), queue.remove()); + expectEqual(@as(u32, 23), queue.remove()); + expectEqual(@as(u32, 25), queue.remove()); + expectEqual(@as(u32, 54), queue.remove()); } test "std.PriorityQueue: add and remove same min heap" { @@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" { try queue.add(2); try queue.add(1); try queue.add(1); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(2), queue.remove()); - expectEqual(u32(2), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 2), queue.remove()); + expectEqual(@as(u32, 2), queue.remove()); } test "std.PriorityQueue: removeOrNull on empty" { @@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" { try queue.add(9); try queue.add(3); try queue.add(2); - expectEqual(u32(2), queue.remove()); - expectEqual(u32(3), queue.remove()); - expectEqual(u32(9), queue.remove()); + expectEqual(@as(u32, 2), queue.remove()); + expectEqual(@as(u32, 3), queue.remove()); + expectEqual(@as(u32, 9), queue.remove()); } test "std.PriorityQueue: peek" { @@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" { try queue.add(9); try queue.add(3); try queue.add(2); - expectEqual(u32(2), queue.peek().?); - expectEqual(u32(2), queue.peek().?); + expectEqual(@as(u32, 2), queue.peek().?); + expectEqual(@as(u32, 2), queue.peek().?); } test "std.PriorityQueue: sift up with odd indices" { @@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" { try queue.add(23); try queue.add(25); try queue.add(13); - expectEqual(u32(54), queue.remove()); - expectEqual(u32(25), queue.remove()); - expectEqual(u32(23), queue.remove()); - expectEqual(u32(13), queue.remove()); - expectEqual(u32(12), queue.remove()); - expectEqual(u32(7), queue.remove()); + expectEqual(@as(u32, 54), queue.remove()); + expectEqual(@as(u32, 25), queue.remove()); + expectEqual(@as(u32, 23), queue.remove()); + expectEqual(@as(u32, 13), queue.remove()); + expectEqual(@as(u32, 12), queue.remove()); + expectEqual(@as(u32, 7), queue.remove()); } test "std.PriorityQueue: add and remove same max heap" { @@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" { try queue.add(2); try queue.add(1); try queue.add(1); - expectEqual(u32(2), queue.remove()); - expectEqual(u32(2), queue.remove()); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(1), queue.remove()); - expectEqual(u32(1), queue.remove()); + expectEqual(@as(u32, 2), queue.remove()); + expectEqual(@as(u32, 2), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); + expectEqual(@as(u32, 1), queue.remove()); } test "std.PriorityQueue: iterator" { @@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" { _ = map.remove(e); } - expectEqual(usize(0), map.count()); + expectEqual(@as(usize, 0), map.count()); } diff --git a/lib/std/rand.zig b/lib/std/rand.zig index e14a60e2ae..2cd1583f63 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct { const r = s0 +% s1; s1 ^= s0; - self.s[0] = math.rotl(u64, s0, u8(55)) ^ s1 ^ (s1 << 14); - self.s[1] = math.rotl(u64, s1, u8(36)); + self.s[0] = math.rotl(u64, s0, @as(u8, 55)) ^ s1 ^ (s1 << 14); + self.s[1] = math.rotl(u64, s1, @as(u8, 36)); return r; } @@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct { inline for (table) |entry| { var b: usize = 0; while (b < 64) : (b += 1) { - if ((entry & (u64(1) << @intCast(u6, b))) != 0) { + if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) { s0 ^= self.s[0]; s1 ^= self.s[1]; } @@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void { testRangeBias(r, start, end, false); } fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void { - const count = @intCast(usize, i32(end) - i32(start)); + const count = @intCast(usize, @as(i32, end) - @as(i32, start)); var values_buffer = [_]bool{false} ** 0x100; const values = values_buffer[0..count]; var i: usize = 0; diff --git a/lib/std/rand/ziggurat.zig b/lib/std/rand/ziggurat.zig index 995248415b..c29d3eeb2b 100644 --- a/lib/std/rand/ziggurat.zig +++ b/lib/std/rand/ziggurat.zig @@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 { // We manually construct a float from parts as we can avoid an extra random lookup here by // using the unused exponent for the lookup table entry. const bits = random.scalar(u64); - const i = usize(bits & 0xff); + const i = @as(usize, bits & 0xff); const u = blk: { if (tables.is_symmetric) { diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig index 3bbbde782e..7db1535755 100644 --- a/lib/std/segmented_list.zig +++ b/lib/std/segmented_list.zig @@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type /// Grows or shrinks capacity to match usage. pub fn setCapacity(self: *Self, new_capacity: usize) !void { if (prealloc_item_count != 0) { - if (new_capacity <= usize(1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) { + if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) { return self.shrinkCapacity(new_capacity); } } @@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type fn shelfSize(shelf_index: ShelfIndex) usize { if (prealloc_item_count == 0) { - return usize(1) << shelf_index; + return @as(usize, 1) << shelf_index; } - return usize(1) << (shelf_index + (prealloc_exp + 1)); + return @as(usize, 1) << (shelf_index + (prealloc_exp + 1)); } fn shelfIndex(list_index: usize) ShelfIndex { @@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize { if (prealloc_item_count == 0) { - return (list_index + 1) - (usize(1) << shelf_index); + return (list_index + 1) - (@as(usize, 1) << shelf_index); } - return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index)); + return list_index + prealloc_item_count - (@as(usize, 1) << ((prealloc_exp + 1) + shelf_index)); } fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void { diff --git a/lib/std/sort.zig b/lib/std/sort.zig index 378a92992f..c5758dd6e7 100644 --- a/lib/std/sort.zig +++ b/lib/std/sort.zig @@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s // where have some idea as to how many unique values there are and where the next value might be fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { if (range.length() == 0) return range.start; - const skip = math.max(range.length() / unique, usize(1)); + const skip = math.max(range.length() / unique, @as(usize, 1)); var index = range.start + skip; while (lessThan(items[index - 1], value)) : (index += skip) { @@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { if (range.length() == 0) return range.start; - const skip = math.max(range.length() / unique, usize(1)); + const skip = math.max(range.length() / unique, @as(usize, 1)); var index = range.end - skip; while (index > range.start and !lessThan(items[index - 1], value)) : (index -= skip) { @@ -841,7 +841,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessT fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { if (range.length() == 0) return range.start; - const skip = math.max(range.length() / unique, usize(1)); + const skip = math.max(range.length() / unique, @as(usize, 1)); var index = range.start + skip; while (!lessThan(value, items[index - 1])) : (index += skip) { @@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { if (range.length() == 0) return range.start; - const skip = math.max(range.length() / unique, usize(1)); + const skip = math.max(range.length() / unique, @as(usize, 1)); var index = range.end - skip; while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) { diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig index 473d2d4e33..145c8897d5 100644 --- a/lib/std/special/c.zig +++ b/lib/std/special/c.zig @@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int { r += 1; n -= 1; } - return c_int(l[0]) - c_int(r[0]); + return @as(c_int, l[0]) - @as(c_int, r[0]); } extern fn strerror(errnum: c_int) [*]const u8 { @@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { // scale result up if (ex > 0) { ux -%= 1 << digits; - ux |= uint(@bitCast(u32, ex)) << digits; + ux |= @as(uint, @bitCast(u32, ex)) << digits; } else { ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1)); } @@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 { export fn sqrtf(x: f32) f32 { const tiny: f32 = 1.0e-30; - const sign: i32 = @bitCast(i32, u32(0x80000000)); + const sign: i32 = @bitCast(i32, @as(u32, 0x80000000)); var ix: i32 = @bitCast(i32, x); if ((ix & 0x7F800000) == 0x7F800000) { diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 0a09f616e9..1fbb618b1e 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 { // special cases if (d == 0) return 0; // ?! if (n == 0) return 0; - var sr = @bitCast(c_uint, c_int(@clz(u32, d)) - c_int(@clz(u32, n))); + var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n))); // 0 <= sr <= n_uword_bits - 1 or sr large if (sr > n_uword_bits - 1) { // d > r @@ -1414,10 +1414,10 @@ test "test_divsi3" { [_]i32{ -2, 1, -2 }, [_]i32{ -2, -1, 2 }, - [_]i32{ @bitCast(i32, u32(0x80000000)), 1, @bitCast(i32, u32(0x80000000)) }, - [_]i32{ @bitCast(i32, u32(0x80000000)), -1, @bitCast(i32, u32(0x80000000)) }, - [_]i32{ @bitCast(i32, u32(0x80000000)), -2, 0x40000000 }, - [_]i32{ @bitCast(i32, u32(0x80000000)), 2, @bitCast(i32, u32(0xC0000000)) }, + [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) }, + [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) }, + [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 }, + [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) }, }; for (cases) |case| { @@ -1443,8 +1443,8 @@ test "test_divmodsi4" { [_]i32{ 19, 5, 3, 4 }, [_]i32{ 19, -5, -3, 4 }, - [_]i32{ @bitCast(i32, u32(0x80000000)), 8, @bitCast(i32, u32(0xf0000000)), 0 }, - [_]i32{ @bitCast(i32, u32(0x80000007)), 8, @bitCast(i32, u32(0xf0000001)), -1 }, + [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 }, + [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 }, }; for (cases) |case| { @@ -1467,10 +1467,10 @@ test "test_divdi3" { [_]i64{ -2, 1, -2 }, [_]i64{ -2, -1, 2 }, - [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)) }, - [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)) }, - [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -2, 0x4000000000000000 }, - [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0xC000000000000000)) }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) }, }; for (cases) |case| { @@ -1492,12 +1492,12 @@ test "test_moddi3" { [_]i64{ -5, 3, -2 }, [_]i64{ -5, -3, -2 }, - [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 1, 0 }, - [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -1, 0 }, - [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 2, 0 }, - [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -2, 0 }, - [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 3, -2 }, - [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -3, -2 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 }, + [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 }, }; for (cases) |case| { diff --git a/lib/std/special/compiler_rt/addXf3.zig b/lib/std/special/compiler_rt/addXf3.zig index 1654c1f08b..e3dd1819c3 100644 --- a/lib/std/special/compiler_rt/addXf3.zig +++ b/lib/std/special/compiler_rt/addXf3.zig @@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 { } pub extern fn __subsf3(a: f32, b: f32) f32 { - const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (u32(1) << 31)); + const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31)); return addXf3(f32, a, neg_b); } pub extern fn __subdf3(a: f64, b: f64) f64 { - const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (u64(1) << 63)); + const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63)); return addXf3(f64, a, neg_b); } pub extern fn __subtf3(a: f128, b: f128) f128 { - const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127)); + const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127)); return addXf3(f128, a, neg_b); } // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { const Z = @IntType(false, T.bit_count); - const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); + const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); const significandBits = std.math.floatMantissaBits(T); - const implicitBit = Z(1) << significandBits; + const implicitBit = @as(Z, 1) << significandBits; const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit); significand.* <<= @intCast(S, shift); @@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 fn addXf3(comptime T: type, a: T, b: T) T { const Z = @IntType(false, T.bit_count); - const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); + const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); const typeWidth = T.bit_count; const significandBits = std.math.floatMantissaBits(T); const exponentBits = std.math.floatExponentBits(T); - const signBit = (Z(1) << (significandBits + exponentBits)); + const signBit = (@as(Z, 1) << (significandBits + exponentBits)); const maxExponent = ((1 << exponentBits) - 1); const exponentBias = (maxExponent >> 1); - const implicitBit = (Z(1) << significandBits); + const implicitBit = (@as(Z, 1) << significandBits); const quietBit = implicitBit >> 1; const significandMask = implicitBit - 1; @@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T { const infRep = @bitCast(Z, std.math.inf(T)); // Detect if a or b is zero, infinity, or NaN. - if (aAbs -% Z(1) >= infRep - Z(1) or - bAbs -% Z(1) >= infRep - Z(1)) + if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or + bAbs -% @as(Z, 1) >= infRep - @as(Z, 1)) { // NaN + anything = qNaN if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit); @@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { const @"align" = @intCast(Z, aExponent - bExponent); if (@"align" != 0) { if (@"align" < typeWidth) { - const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0; + const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0; bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky; } else { bSignificand = 1; // sticky; b is known to be non-zero. @@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { if (subtraction) { aSignificand -= bSignificand; // If a == -b, return +zero. - if (aSignificand == 0) return @bitCast(T, Z(0)); + if (aSignificand == 0) return @bitCast(T, @as(Z, 0)); // If partial cancellation occured, we need to left-shift the result // and adjust the exponent: @@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { // Result is denormal before rounding; the exponent is zero and we // need to shift the significand. const shift = @intCast(Z, 1 - aExponent); - const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0; + const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) @as(Z, 1) else 0; aSignificand = aSignificand >> @intCast(S, shift | sticky); aExponent = 0; } diff --git a/lib/std/special/compiler_rt/addXf3_test.zig b/lib/std/special/compiler_rt/addXf3_test.zig index 099b737976..af991b37e9 100644 --- a/lib/std/special/compiler_rt/addXf3_test.zig +++ b/lib/std/special/compiler_rt/addXf3_test.zig @@ -3,8 +3,8 @@ // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c -const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64); -const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64); +const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64); +const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); const __addtf3 = @import("addXf3.zig").__addtf3; @@ -34,7 +34,7 @@ test "addtf3" { test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); // NaN + any = NaN - test__addtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); + test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); // inf + inf = inf test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0); @@ -75,7 +75,7 @@ test "subtf3" { test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); // NaN + any = NaN - test__subtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); + test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); // inf - any = inf test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); diff --git a/lib/std/special/compiler_rt/comparedf2.zig b/lib/std/special/compiler_rt/comparedf2.zig index f97e2474be..95dc878630 100644 --- a/lib/std/special/compiler_rt/comparedf2.zig +++ b/lib/std/special/compiler_rt/comparedf2.zig @@ -13,19 +13,19 @@ const srep_t = i64; const typeWidth = rep_t.bit_count; const significandBits = std.math.floatMantissaBits(fp_t); const exponentBits = std.math.floatExponentBits(fp_t); -const signBit = (rep_t(1) << (significandBits + exponentBits)); +const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); const absMask = signBit - 1; -const implicitBit = rep_t(1) << significandBits; +const implicitBit = @as(rep_t, 1) << significandBits; const significandMask = implicitBit - 1; const exponentMask = absMask ^ significandMask; const infRep = @bitCast(rep_t, std.math.inf(fp_t)); // TODO https://github.com/ziglang/zig/issues/641 // and then make the return types of some of these functions the enum instead of c_int -const LE_LESS = c_int(-1); -const LE_EQUAL = c_int(0); -const LE_GREATER = c_int(1); -const LE_UNORDERED = c_int(1); +const LE_LESS = @as(c_int, -1); +const LE_EQUAL = @as(c_int, 0); +const LE_GREATER = @as(c_int, 1); +const LE_UNORDERED = @as(c_int, 1); pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { @setRuntimeSafety(is_test); @@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { // TODO https://github.com/ziglang/zig/issues/641 // and then make the return types of some of these functions the enum instead of c_int -const GE_LESS = c_int(-1); -const GE_EQUAL = c_int(0); -const GE_GREATER = c_int(1); -const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED +const GE_LESS = @as(c_int, -1); +const GE_EQUAL = @as(c_int, 0); +const GE_GREATER = @as(c_int, 1); +const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED pub extern fn __gedf2(a: fp_t, b: fp_t) c_int { @setRuntimeSafety(is_test); diff --git a/lib/std/special/compiler_rt/comparesf2.zig b/lib/std/special/compiler_rt/comparesf2.zig index e99e0bb3dd..4468da4fbe 100644 --- a/lib/std/special/compiler_rt/comparesf2.zig +++ b/lib/std/special/compiler_rt/comparesf2.zig @@ -13,19 +13,19 @@ const srep_t = i32; const typeWidth = rep_t.bit_count; const significandBits = std.math.floatMantissaBits(fp_t); const exponentBits = std.math.floatExponentBits(fp_t); -const signBit = (rep_t(1) << (significandBits + exponentBits)); +const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); const absMask = signBit - 1; -const implicitBit = rep_t(1) << significandBits; +const implicitBit = @as(rep_t, 1) << significandBits; const significandMask = implicitBit - 1; const exponentMask = absMask ^ significandMask; const infRep = @bitCast(rep_t, std.math.inf(fp_t)); // TODO https://github.com/ziglang/zig/issues/641 // and then make the return types of some of these functions the enum instead of c_int -const LE_LESS = c_int(-1); -const LE_EQUAL = c_int(0); -const LE_GREATER = c_int(1); -const LE_UNORDERED = c_int(1); +const LE_LESS = @as(c_int, -1); +const LE_EQUAL = @as(c_int, 0); +const LE_GREATER = @as(c_int, 1); +const LE_UNORDERED = @as(c_int, 1); pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { @setRuntimeSafety(is_test); @@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { // TODO https://github.com/ziglang/zig/issues/641 // and then make the return types of some of these functions the enum instead of c_int -const GE_LESS = c_int(-1); -const GE_EQUAL = c_int(0); -const GE_GREATER = c_int(1); -const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED +const GE_LESS = @as(c_int, -1); +const GE_EQUAL = @as(c_int, 0); +const GE_GREATER = @as(c_int, 1); +const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED pub extern fn __gesf2(a: fp_t, b: fp_t) c_int { @setRuntimeSafety(is_test); diff --git a/lib/std/special/compiler_rt/comparetf2.zig b/lib/std/special/compiler_rt/comparetf2.zig index 05e5974558..e973018455 100644 --- a/lib/std/special/compiler_rt/comparetf2.zig +++ b/lib/std/special/compiler_rt/comparetf2.zig @@ -1,9 +1,9 @@ // TODO https://github.com/ziglang/zig/issues/641 // and then make the return types of some of these functions the enum instead of c_int -const LE_LESS = c_int(-1); -const LE_EQUAL = c_int(0); -const LE_GREATER = c_int(1); -const LE_UNORDERED = c_int(1); +const LE_LESS = @as(c_int, -1); +const LE_EQUAL = @as(c_int, 0); +const LE_GREATER = @as(c_int, 1); +const LE_UNORDERED = @as(c_int, 1); const rep_t = u128; const srep_t = i128; @@ -11,9 +11,9 @@ const srep_t = i128; const typeWidth = rep_t.bit_count; const significandBits = 112; const exponentBits = (typeWidth - significandBits - 1); -const signBit = (rep_t(1) << (significandBits + exponentBits)); +const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); const absMask = signBit - 1; -const implicitBit = rep_t(1) << significandBits; +const implicitBit = @as(rep_t, 1) << significandBits; const significandMask = implicitBit - 1; const exponentMask = absMask ^ significandMask; const infRep = exponentMask; @@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int { // TODO https://github.com/ziglang/zig/issues/641 // and then make the return types of some of these functions the enum instead of c_int -const GE_LESS = c_int(-1); -const GE_EQUAL = c_int(0); -const GE_GREATER = c_int(1); -const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED +const GE_LESS = @as(c_int, -1); +const GE_EQUAL = @as(c_int, 0); +const GE_GREATER = @as(c_int, 1); +const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED pub extern fn __getf2(a: f128, b: f128) c_int { @setRuntimeSafety(is_test); diff --git a/lib/std/special/compiler_rt/divdf3.zig b/lib/std/special/compiler_rt/divdf3.zig index 072feaec67..9937b09497 100644 --- a/lib/std/special/compiler_rt/divdf3.zig +++ b/lib/std/special/compiler_rt/divdf3.zig @@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { const significandBits = std.math.floatMantissaBits(f64); const exponentBits = std.math.floatExponentBits(f64); - const signBit = (Z(1) << (significandBits + exponentBits)); + const signBit = (@as(Z, 1) << (significandBits + exponentBits)); const maxExponent = ((1 << exponentBits) - 1); const exponentBias = (maxExponent >> 1); - const implicitBit = (Z(1) << significandBits); + const implicitBit = (@as(Z, 1) << significandBits); const quietBit = implicitBit >> 1; const significandMask = implicitBit - 1; @@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This // is accurate to about 3.5 binary digits. const q31b: u32 = @truncate(u32, bSignificand >> 21); - var recip32 = u32(0x7504f333) -% q31b; + var recip32 = @as(u32, 0x7504f333) -% q31b; // Now refine the reciprocal estimate using a Newton-Raphson iteration: // @@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { // with each iteration, so after three iterations, we have about 28 binary // digits of accuracy. var correction32: u32 = undefined; - correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1); - recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31); - correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1); - recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31); - correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1); - recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31); + correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1); + recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31); + correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1); + recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31); + correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1); + recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31); // recip32 might have overflowed to exactly zero in the preceding // computation if the high word of b is exactly 1.0. This would sabotage @@ -119,10 +119,10 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { const q63blo: u32 = @truncate(u32, bSignificand << 11); var correction: u64 = undefined; var reciprocal: u64 = undefined; - correction = ~(u64(recip32) *% q31b +% (u64(recip32) *% q63blo >> 32)) +% 1; + correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1; const cHi = @truncate(u32, correction >> 32); const cLo = @truncate(u32, correction); - reciprocal = u64(recip32) *% cHi +% (u64(recip32) *% cLo >> 32); + reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32); // We already adjusted the 32-bit estimate, now we need to adjust the final // 64-bit reciprocal estimate downward to ensure that it is strictly smaller @@ -195,7 +195,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { // Clear the implicit bit var absResult = quotient & significandMask; // Insert the exponent - absResult |= @bitCast(Z, SignedZ(writtenExponent)) << significandBits; + absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits; // Round absResult +%= round; // Insert the sign and return @@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { switch (Z) { u32 => { // 32x32 --> 64 bit multiply - const product = u64(a) * u64(b); + const product = @as(u64, a) * @as(u64, b); hi.* = @truncate(u32, product >> 32); lo.* = @truncate(u32, product); }, @@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; }, u128 => { - const Word_LoMask = u64(0x00000000ffffffff); - const Word_HiMask = u64(0xffffffff00000000); - const Word_FullMask = u64(0xffffffffffffffff); + const Word_LoMask = @as(u64, 0x00000000ffffffff); + const Word_HiMask = @as(u64, 0xffffffff00000000); + const Word_FullMask = @as(u64, 0xffffffffffffffff); const S = struct { fn Word_1(x: u128) u64 { return @truncate(u32, x >> 96); @@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { const product43: u64 = S.Word_4(a) * S.Word_3(b); const product44: u64 = S.Word_4(a) * S.Word_4(b); - const sum0: u128 = u128(product44); - const sum1: u128 = u128(product34) +% - u128(product43); - const sum2: u128 = u128(product24) +% - u128(product33) +% - u128(product42); - const sum3: u128 = u128(product14) +% - u128(product23) +% - u128(product32) +% - u128(product41); - const sum4: u128 = u128(product13) +% - u128(product22) +% - u128(product31); - const sum5: u128 = u128(product12) +% - u128(product21); - const sum6: u128 = u128(product11); + const sum0: u128 = @as(u128, product44); + const sum1: u128 = @as(u128, product34) +% + @as(u128, product43); + const sum2: u128 = @as(u128, product24) +% + @as(u128, product33) +% + @as(u128, product42); + const sum3: u128 = @as(u128, product14) +% + @as(u128, product23) +% + @as(u128, product32) +% + @as(u128, product41); + const sum4: u128 = @as(u128, product13) +% + @as(u128, product22) +% + @as(u128, product31); + const sum5: u128 = @as(u128, product12) +% + @as(u128, product21); + const sum6: u128 = @as(u128, product11); const r0: u128 = (sum0 & Word_FullMask) +% ((sum1 & Word_LoMask) << 32); @@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { @setRuntimeSafety(builtin.is_test); const Z = @IntType(false, T.bit_count); const significandBits = std.math.floatMantissaBits(T); - const implicitBit = Z(1) << significandBits; + const implicitBit = @as(Z, 1) << significandBits; const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); significand.* <<= @intCast(std.math.Log2Int(Z), shift); diff --git a/lib/std/special/compiler_rt/divsf3.zig b/lib/std/special/compiler_rt/divsf3.zig index 447653fbe1..4ee2eed36c 100644 --- a/lib/std/special/compiler_rt/divsf3.zig +++ b/lib/std/special/compiler_rt/divsf3.zig @@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { const significandBits = std.math.floatMantissaBits(f32); const exponentBits = std.math.floatExponentBits(f32); - const signBit = (Z(1) << (significandBits + exponentBits)); + const signBit = (@as(Z, 1) << (significandBits + exponentBits)); const maxExponent = ((1 << exponentBits) - 1); const exponentBias = (maxExponent >> 1); - const implicitBit = (Z(1) << significandBits); + const implicitBit = (@as(Z, 1) << significandBits); const quietBit = implicitBit >> 1; const significandMask = implicitBit - 1; @@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This // is accurate to about 3.5 binary digits. const q31b = bSignificand << 8; - var reciprocal = u32(0x7504f333) -% q31b; + var reciprocal = @as(u32, 0x7504f333) -% q31b; // Now refine the reciprocal estimate using a Newton-Raphson iteration: // @@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { // with each iteration, so after three iterations, we have about 28 binary // digits of accuracy. var correction: u32 = undefined; - correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1); - reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31); - correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1); - reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31); - correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1); - reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31); + correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1); + reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31); + correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1); + reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31); + correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1); + reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31); // Exhaustive testing shows that the error in reciprocal after three steps // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our @@ -127,7 +127,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { // is the error in the reciprocal of b scaled by the maximum // possible value of a. As a consequence of this error bound, // either q or nextafter(q) is the correctly rounded - var quotient: Z = @truncate(u32, u64(reciprocal) *% (aSignificand << 1) >> 32); + var quotient: Z = @truncate(u32, @as(u64, reciprocal) *% (aSignificand << 1) >> 32); // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). // In either case, we are going to compute a residual of the form @@ -189,7 +189,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { @setRuntimeSafety(builtin.is_test); const Z = @IntType(false, T.bit_count); const significandBits = std.math.floatMantissaBits(T); - const implicitBit = Z(1) << significandBits; + const implicitBit = @as(Z, 1) << significandBits; const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); significand.* <<= @intCast(std.math.Log2Int(Z), shift); diff --git a/lib/std/special/compiler_rt/divti3_test.zig b/lib/std/special/compiler_rt/divti3_test.zig index e1c1babae7..8601cfae03 100644 --- a/lib/std/special/compiler_rt/divti3_test.zig +++ b/lib/std/special/compiler_rt/divti3_test.zig @@ -14,8 +14,8 @@ test "divti3" { test__divti3(-2, 1, -2); test__divti3(-2, -1, 2); - test__divti3(@bitCast(i128, u128(0x8 << 124)), 1, @bitCast(i128, u128(0x8 << 124))); - test__divti3(@bitCast(i128, u128(0x8 << 124)), -1, @bitCast(i128, u128(0x8 << 124))); - test__divti3(@bitCast(i128, u128(0x8 << 124)), -2, @bitCast(i128, u128(0x4 << 124))); - test__divti3(@bitCast(i128, u128(0x8 << 124)), 2, @bitCast(i128, u128(0xc << 124))); + test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124))); + test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124))); + test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124))); + test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124))); } diff --git a/lib/std/special/compiler_rt/extendXfYf2.zig b/lib/std/special/compiler_rt/extendXfYf2.zig index e10667843f..3bdc5164e2 100644 --- a/lib/std/special/compiler_rt/extendXfYf2.zig +++ b/lib/std/special/compiler_rt/extendXfYf2.zig @@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t const dstInfExp = (1 << dstExpBits) - 1; const dstExpBias = dstInfExp >> 1; - const dstMinNormal: dst_rep_t = dst_rep_t(1) << dstSigBits; + const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits; // Break a into a sign and representation of the absolute value const aRep: src_rep_t = @bitCast(src_rep_t, a); @@ -61,7 +61,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t // a is a normal number. // Extend to the destination type by shifting the significand and // exponent into the proper position and rebiasing the exponent. - absResult = dst_rep_t(aAbs) << (dstSigBits - srcSigBits); + absResult = @as(dst_rep_t, aAbs) << (dstSigBits - srcSigBits); absResult += (dstExpBias - srcExpBias) << dstSigBits; } else if (aAbs >= srcInfinity) { // a is NaN or infinity. @@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t // bit (if needed) and right-aligning the rest of the trailing NaN // payload field. absResult = dstInfExp << dstSigBits; - absResult |= dst_rep_t(aAbs & srcQNaN) << (dstSigBits - srcSigBits); - absResult |= dst_rep_t(aAbs & srcNaNCode) << (dstSigBits - srcSigBits); + absResult |= @as(dst_rep_t, aAbs & srcQNaN) << (dstSigBits - srcSigBits); + absResult |= @as(dst_rep_t, aAbs & srcNaNCode) << (dstSigBits - srcSigBits); } else if (aAbs != 0) { // a is denormal. // renormalize the significand and clear the leading bit, then insert // the correct adjusted exponent in the destination type. const scale: u32 = @clz(src_rep_t, aAbs) - - @clz(src_rep_t, src_rep_t(srcMinNormal)); - absResult = dst_rep_t(aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); + @clz(src_rep_t, @as(src_rep_t, srcMinNormal)); + absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); absResult ^= dstMinNormal; const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits; @@ -87,7 +87,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t } // Apply the signbit to (dst_t)abs(a). - const result: dst_rep_t align(@alignOf(dst_t)) = absResult | dst_rep_t(sign) << (dstBits - srcBits); + const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits); return @bitCast(dst_t, result); } diff --git a/lib/std/special/compiler_rt/extendXfYf2_test.zig b/lib/std/special/compiler_rt/extendXfYf2_test.zig index 6f8111c8fb..aa2faae901 100644 --- a/lib/std/special/compiler_rt/extendXfYf2_test.zig +++ b/lib/std/special/compiler_rt/extendXfYf2_test.zig @@ -134,11 +134,11 @@ test "extendsftf2" { } fn makeQNaN64() f64 { - return @bitCast(f64, u64(0x7ff8000000000000)); + return @bitCast(f64, @as(u64, 0x7ff8000000000000)); } fn makeInf64() f64 { - return @bitCast(f64, u64(0x7ff0000000000000)); + return @bitCast(f64, @as(u64, 0x7ff0000000000000)); } fn makeNaN64(rand: u64) f64 { @@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 { } fn makeQNaN32() f32 { - return @bitCast(f32, u32(0x7fc00000)); + return @bitCast(f32, @as(u32, 0x7fc00000)); } fn makeNaN32(rand: u32) f32 { @@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 { } fn makeInf32() f32 { - return @bitCast(f32, u32(0x7f800000)); + return @bitCast(f32, @as(u32, 0x7f800000)); } diff --git a/lib/std/special/compiler_rt/fixdfdi_test.zig b/lib/std/special/compiler_rt/fixdfdi_test.zig index 1ba8a4f87d..e06d641824 100644 --- a/lib/std/special/compiler_rt/fixdfdi_test.zig +++ b/lib/std/special/compiler_rt/fixdfdi_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixdfdi(a: f64, expected: i64) void { const x = __fixdfdi(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixdfsi_test.zig b/lib/std/special/compiler_rt/fixdfsi_test.zig index fa5ff72e8f..da53468c7d 100644 --- a/lib/std/special/compiler_rt/fixdfsi_test.zig +++ b/lib/std/special/compiler_rt/fixdfsi_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixdfsi(a: f64, expected: i32) void { const x = __fixdfsi(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixdfti_test.zig b/lib/std/special/compiler_rt/fixdfti_test.zig index 4ab2c04cd1..b0c9049ba8 100644 --- a/lib/std/special/compiler_rt/fixdfti_test.zig +++ b/lib/std/special/compiler_rt/fixdfti_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixdfti(a: f64, expected: i128) void { const x = __fixdfti(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixint.zig b/lib/std/special/compiler_rt/fixint.zig index fd31798cc2..426ee1d58a 100644 --- a/lib/std/special/compiler_rt/fixint.zig +++ b/lib/std/special/compiler_rt/fixint.zig @@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { const typeWidth = rep_t.bit_count; const exponentBits = (typeWidth - significandBits - 1); - const signBit = (rep_t(1) << (significandBits + exponentBits)); + const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); const maxExponent = ((1 << exponentBits) - 1); const exponentBias = (maxExponent >> 1); - const implicitBit = (rep_t(1) << significandBits); + const implicitBit = (@as(rep_t, 1) << significandBits); const significandMask = (implicitBit - 1); // Break a into sign, exponent, significand @@ -51,7 +51,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { // If the value is too large for the integer type, saturate. if (@intCast(usize, exponent) >= fixint_t.bit_count) { - return if (negative) fixint_t(minInt(fixint_t)) else fixint_t(maxInt(fixint_t)); + return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t)); } // If 0 <= exponent < significandBits, right shift else left shift diff --git a/lib/std/special/compiler_rt/fixint_test.zig b/lib/std/special/compiler_rt/fixint_test.zig index a876e17263..d5f7b3898d 100644 --- a/lib/std/special/compiler_rt/fixint_test.zig +++ b/lib/std/special/compiler_rt/fixint_test.zig @@ -81,8 +81,8 @@ test "fixint.i3" { test "fixint.i32" { test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); - test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32)); - test__fixint(f64, i32, f64(math.minInt(i32)) + 1, math.minInt(i32) + 1); + test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32)); + test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1); test__fixint(f64, i32, -2.0, -2); test__fixint(f64, i32, -1.9, -1); test__fixint(f64, i32, -1.1, -1); @@ -96,8 +96,8 @@ test "fixint.i32" { test__fixint(f64, i32, 0.1, 0); test__fixint(f64, i32, 0.9, 0); test__fixint(f64, i32, 1.0, 1); - test__fixint(f64, i32, f64(math.maxInt(i32)) - 1, math.maxInt(i32) - 1); - test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32)); + test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1); + test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32)); test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); } @@ -105,9 +105,9 @@ test "fixint.i32" { test "fixint.i64" { test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); - test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64)); - test__fixint(f64, i64, f64(math.minInt(i64)) + 1, math.minInt(i64)); - test__fixint(f64, i64, f64(math.minInt(i64) / 2), math.minInt(i64) / 2); + test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64)); + test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64)); + test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2); test__fixint(f64, i64, -2.0, -2); test__fixint(f64, i64, -1.9, -1); test__fixint(f64, i64, -1.1, -1); @@ -121,8 +121,8 @@ test "fixint.i64" { test__fixint(f64, i64, 0.1, 0); test__fixint(f64, i64, 0.9, 0); test__fixint(f64, i64, 1.0, 1); - test__fixint(f64, i64, f64(math.maxInt(i64)) - 1, math.maxInt(i64)); - test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64)); + test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64)); + test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64)); test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); } @@ -130,8 +130,8 @@ test "fixint.i64" { test "fixint.i128" { test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); - test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128)); - test__fixint(f64, i128, f64(math.minInt(i128)) + 1, math.minInt(i128)); + test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128)); + test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128)); test__fixint(f64, i128, -2.0, -2); test__fixint(f64, i128, -1.9, -1); test__fixint(f64, i128, -1.1, -1); @@ -145,8 +145,8 @@ test "fixint.i128" { test__fixint(f64, i128, 0.1, 0); test__fixint(f64, i128, 0.9, 0); test__fixint(f64, i128, 1.0, 1); - test__fixint(f64, i128, f64(math.maxInt(i128)) - 1, math.maxInt(i128)); - test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128)); + test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128)); + test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128)); test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); } diff --git a/lib/std/special/compiler_rt/fixsfdi_test.zig b/lib/std/special/compiler_rt/fixsfdi_test.zig index bfd715425c..02844946a7 100644 --- a/lib/std/special/compiler_rt/fixsfdi_test.zig +++ b/lib/std/special/compiler_rt/fixsfdi_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixsfdi(a: f32, expected: i64) void { const x = __fixsfdi(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixsfsi_test.zig b/lib/std/special/compiler_rt/fixsfsi_test.zig index 30406fea22..69d8309de0 100644 --- a/lib/std/special/compiler_rt/fixsfsi_test.zig +++ b/lib/std/special/compiler_rt/fixsfsi_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixsfsi(a: f32, expected: i32) void { const x = __fixsfsi(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixsfti_test.zig b/lib/std/special/compiler_rt/fixsfti_test.zig index 7136f7cfe8..cecfeda557 100644 --- a/lib/std/special/compiler_rt/fixsfti_test.zig +++ b/lib/std/special/compiler_rt/fixsfti_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixsfti(a: f32, expected: i128) void { const x = __fixsfti(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixtfdi_test.zig b/lib/std/special/compiler_rt/fixtfdi_test.zig index 7c63547642..b45001e18e 100644 --- a/lib/std/special/compiler_rt/fixtfdi_test.zig +++ b/lib/std/special/compiler_rt/fixtfdi_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixtfdi(a: f128, expected: i64) void { const x = __fixtfdi(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixtfsi_test.zig b/lib/std/special/compiler_rt/fixtfsi_test.zig index da769089df..c6f6623995 100644 --- a/lib/std/special/compiler_rt/fixtfsi_test.zig +++ b/lib/std/special/compiler_rt/fixtfsi_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixtfsi(a: f128, expected: i32) void { const x = __fixtfsi(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixtfti_test.zig b/lib/std/special/compiler_rt/fixtfti_test.zig index 02dba7fd61..b36c5beb4e 100644 --- a/lib/std/special/compiler_rt/fixtfti_test.zig +++ b/lib/std/special/compiler_rt/fixtfti_test.zig @@ -6,7 +6,7 @@ const warn = std.debug.warn; fn test__fixtfti(a: f128, expected: i128) void { const x = __fixtfti(a); - //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); + //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); testing.expect(x == expected); } diff --git a/lib/std/special/compiler_rt/fixuint.zig b/lib/std/special/compiler_rt/fixuint.zig index 55a113b368..977d3c16c9 100644 --- a/lib/std/special/compiler_rt/fixuint.zig +++ b/lib/std/special/compiler_rt/fixuint.zig @@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t }; const typeWidth = rep_t.bit_count; const exponentBits = (typeWidth - significandBits - 1); - const signBit = (rep_t(1) << (significandBits + exponentBits)); + const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); const maxExponent = ((1 << exponentBits) - 1); const exponentBias = (maxExponent >> 1); - const implicitBit = (rep_t(1) << significandBits); + const implicitBit = (@as(rep_t, 1) << significandBits); const significandMask = (implicitBit - 1); // Break a into sign, exponent, significand @@ -31,7 +31,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t const absMask = signBit - 1; const aAbs: rep_t = aRep & absMask; - const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1); + const sign = if ((aRep & signBit) != 0) @as(i32, -1) else @as(i32, 1); const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias; const significand: rep_t = (aAbs & significandMask) | implicitBit; @@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t if (sign == -1 or exponent < 0) return 0; // If the value is too large for the integer type, saturate. - if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~fixuint_t(0); + if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0); // If 0 <= exponent < significandBits, right shift to get the result. // Otherwise, shift left. diff --git a/lib/std/special/compiler_rt/fixunstfsi_test.zig b/lib/std/special/compiler_rt/fixunstfsi_test.zig index e709636912..286567629a 100644 --- a/lib/std/special/compiler_rt/fixunstfsi_test.zig +++ b/lib/std/special/compiler_rt/fixunstfsi_test.zig @@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void { testing.expect(x == expected); } -const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); +const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); test "fixunstfsi" { test__fixunstfsi(inf128, 0xffffffff); diff --git a/lib/std/special/compiler_rt/fixunstfti_test.zig b/lib/std/special/compiler_rt/fixunstfti_test.zig index 833e4779dd..62a9bbfecf 100644 --- a/lib/std/special/compiler_rt/fixunstfti_test.zig +++ b/lib/std/special/compiler_rt/fixunstfti_test.zig @@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void { testing.expect(x == expected); } -const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); +const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); test "fixunstfti" { test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); diff --git a/lib/std/special/compiler_rt/floatsiXf.zig b/lib/std/special/compiler_rt/floatsiXf.zig index 7e05a3ebf7..714681834d 100644 --- a/lib/std/special/compiler_rt/floatsiXf.zig +++ b/lib/std/special/compiler_rt/floatsiXf.zig @@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T { @setRuntimeSafety(builtin.is_test); const Z = @IntType(false, T.bit_count); - const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); + const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); if (a == 0) { - return T(0.0); + return @as(T, 0.0); } const significandBits = std.math.floatMantissaBits(T); const exponentBits = std.math.floatExponentBits(T); const exponentBias = ((1 << exponentBits - 1) - 1); - const implicitBit = Z(1) << significandBits; - const signBit = Z(1 << Z.bit_count - 1); + const implicitBit = @as(Z, 1) << significandBits; + const signBit = @as(Z, 1 << Z.bit_count - 1); const sign = a >> 31; // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31). const abs_a = (a ^ sign) -% sign; // The exponent is the width of abs(a) - const exp = Z(31 - @clz(i32, abs_a)); + const exp = @as(Z, 31 - @clz(i32, abs_a)); const sign_bit = if (sign < 0) signBit else 0; diff --git a/lib/std/special/compiler_rt/floattidf.zig b/lib/std/special/compiler_rt/floattidf.zig index 42ef6df7e4..1e83674598 100644 --- a/lib/std/special/compiler_rt/floattidf.zig +++ b/lib/std/special/compiler_rt/floattidf.zig @@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 { a += 1; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits - if ((a & (u128(1) << DBL_MANT_DIG)) != 0) { + if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { a >>= 1; e += 1; } diff --git a/lib/std/special/compiler_rt/floattisf.zig b/lib/std/special/compiler_rt/floattisf.zig index f397d130ef..0c02bfff1f 100644 --- a/lib/std/special/compiler_rt/floattisf.zig +++ b/lib/std/special/compiler_rt/floattisf.zig @@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 { a += 1; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits - if ((a & (u128(1) << FLT_MANT_DIG)) != 0) { + if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { a >>= 1; e += 1; } diff --git a/lib/std/special/compiler_rt/floattitf.zig b/lib/std/special/compiler_rt/floattitf.zig index b05282e293..aac22e36d0 100644 --- a/lib/std/special/compiler_rt/floattitf.zig +++ b/lib/std/special/compiler_rt/floattitf.zig @@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 { a += 1; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits - if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) { + if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) { a >>= 1; e += 1; } diff --git a/lib/std/special/compiler_rt/floatunsidf.zig b/lib/std/special/compiler_rt/floatunsidf.zig index efeb4c2672..d744009aea 100644 --- a/lib/std/special/compiler_rt/floatunsidf.zig +++ b/lib/std/special/compiler_rt/floatunsidf.zig @@ -2,7 +2,7 @@ const builtin = @import("builtin"); const std = @import("std"); const maxInt = std.math.maxInt; -const implicitBit = u64(1) << 52; +const implicitBit = @as(u64, 1) << 52; pub extern fn __floatunsidf(arg: u32) f64 { @setRuntimeSafety(builtin.is_test); @@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 { if (arg == 0) return 0.0; // The exponent is the width of abs(a) - const exp = u64(31) - @clz(u32, arg); + const exp = @as(u64, 31) - @clz(u32, arg); // Shift a into the significand field and clear the implicit bit const shift = @intCast(u6, 52 - exp); - const mant = u64(arg) << shift ^ implicitBit; + const mant = @as(u64, arg) << shift ^ implicitBit; return @bitCast(f64, mant | (exp + 1023) << 52); } diff --git a/lib/std/special/compiler_rt/floatuntidf.zig b/lib/std/special/compiler_rt/floatuntidf.zig index 2cd38c7308..5d3a201058 100644 --- a/lib/std/special/compiler_rt/floatuntidf.zig +++ b/lib/std/special/compiler_rt/floatuntidf.zig @@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd; const shift_amt_u7 = @intCast(u7, shift_amt); a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) | - @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); + @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); }, } // finish @@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { a += 1; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits - if ((a & (u128(1) << DBL_MANT_DIG)) != 0) { + if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { a >>= 1; e += 1; } diff --git a/lib/std/special/compiler_rt/floatuntisf.zig b/lib/std/special/compiler_rt/floatuntisf.zig index 1b42b267d9..e450ad9a48 100644 --- a/lib/std/special/compiler_rt/floatuntisf.zig +++ b/lib/std/special/compiler_rt/floatuntisf.zig @@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd; const shift_amt_u7 = @intCast(u7, shift_amt); a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) | - @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); + @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); }, } // finish @@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { a += 1; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits - if ((a & (u128(1) << FLT_MANT_DIG)) != 0) { + if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { a >>= 1; e += 1; } diff --git a/lib/std/special/compiler_rt/floatuntitf.zig b/lib/std/special/compiler_rt/floatuntitf.zig index eddcf92efd..f92942e034 100644 --- a/lib/std/special/compiler_rt/floatuntitf.zig +++ b/lib/std/special/compiler_rt/floatuntitf.zig @@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; const shift_amt_u7 = @intCast(u7, shift_amt); a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) | - @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); + @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); }, } // finish @@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { a += 1; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits - if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) { + if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) { a >>= 1; e += 1; } diff --git a/lib/std/special/compiler_rt/mulXf3.zig b/lib/std/special/compiler_rt/mulXf3.zig index 51d40ad26f..11ee0b49a4 100644 --- a/lib/std/special/compiler_rt/mulXf3.zig +++ b/lib/std/special/compiler_rt/mulXf3.zig @@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T { const significandBits = std.math.floatMantissaBits(T); const exponentBits = std.math.floatExponentBits(T); - const signBit = (Z(1) << (significandBits + exponentBits)); + const signBit = (@as(Z, 1) << (significandBits + exponentBits)); const maxExponent = ((1 << exponentBits) - 1); const exponentBias = (maxExponent >> 1); - const implicitBit = (Z(1) << significandBits); + const implicitBit = (@as(Z, 1) << significandBits); const quietBit = implicitBit >> 1; const significandMask = implicitBit - 1; @@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { // a zero of the appropriate sign. Mathematically there is no need to // handle this case separately, but we make it a special case to // simplify the shift logic. - const shift: u32 = @truncate(u32, Z(1) -% @bitCast(u32, productExponent)); + const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent)); if (shift >= typeWidth) return @bitCast(T, productSign); // Otherwise, shift the significand of the result so that the round @@ -131,7 +131,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { } else { // Result is normal before rounding; insert the exponent. productHi &= significandMask; - productHi |= Z(@bitCast(u32, productExponent)) << significandBits; + productHi |= @as(Z, @bitCast(u32, productExponent)) << significandBits; } // Insert the sign of the result: @@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { switch (Z) { u32 => { // 32x32 --> 64 bit multiply - const product = u64(a) * u64(b); + const product = @as(u64, a) * @as(u64, b); hi.* = @truncate(u32, product >> 32); lo.* = @truncate(u32, product); }, @@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; }, u128 => { - const Word_LoMask = u64(0x00000000ffffffff); - const Word_HiMask = u64(0xffffffff00000000); - const Word_FullMask = u64(0xffffffffffffffff); + const Word_LoMask = @as(u64, 0x00000000ffffffff); + const Word_HiMask = @as(u64, 0xffffffff00000000); + const Word_FullMask = @as(u64, 0xffffffffffffffff); const S = struct { fn Word_1(x: u128) u64 { return @truncate(u32, x >> 96); @@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { const product43: u64 = S.Word_4(a) * S.Word_3(b); const product44: u64 = S.Word_4(a) * S.Word_4(b); - const sum0: u128 = u128(product44); - const sum1: u128 = u128(product34) +% - u128(product43); - const sum2: u128 = u128(product24) +% - u128(product33) +% - u128(product42); - const sum3: u128 = u128(product14) +% - u128(product23) +% - u128(product32) +% - u128(product41); - const sum4: u128 = u128(product13) +% - u128(product22) +% - u128(product31); - const sum5: u128 = u128(product12) +% - u128(product21); - const sum6: u128 = u128(product11); + const sum0: u128 = @as(u128, product44); + const sum1: u128 = @as(u128, product34) +% + @as(u128, product43); + const sum2: u128 = @as(u128, product24) +% + @as(u128, product33) +% + @as(u128, product42); + const sum3: u128 = @as(u128, product14) +% + @as(u128, product23) +% + @as(u128, product32) +% + @as(u128, product41); + const sum4: u128 = @as(u128, product13) +% + @as(u128, product22) +% + @as(u128, product31); + const sum5: u128 = @as(u128, product12) +% + @as(u128, product21); + const sum6: u128 = @as(u128, product11); const r0: u128 = (sum0 & Word_FullMask) +% ((sum1 & Word_LoMask) << 32); @@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { @setRuntimeSafety(builtin.is_test); const Z = @IntType(false, T.bit_count); const significandBits = std.math.floatMantissaBits(T); - const implicitBit = Z(1) << significandBits; + const implicitBit = @as(Z, 1) << significandBits; const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); significand.* <<= @intCast(std.math.Log2Int(Z), shift); diff --git a/lib/std/special/compiler_rt/mulXf3_test.zig b/lib/std/special/compiler_rt/mulXf3_test.zig index 1c0c0fc043..57dc385321 100644 --- a/lib/std/special/compiler_rt/mulXf3_test.zig +++ b/lib/std/special/compiler_rt/mulXf3_test.zig @@ -2,8 +2,8 @@ // // https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c -const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64); -const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64); +const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64); +const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); const __multf3 = @import("mulXf3.zig").__multf3; @@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { } fn makeNaN128(rand: u64) f128 { - const int_result = u128(0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; + const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; const float_result = @bitCast(f128, int_result); return float_result; } @@ -55,15 +55,15 @@ test "multf3" { // any * any test__multf3( - @bitCast(f128, u128(0x40042eab345678439abcdefea5678234)), - @bitCast(f128, u128(0x3ffeedcb34a235253948765432134675)), + @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)), + @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)), 0x400423e7f9e3c9fc, 0xd906c2c2a85777c4, ); test__multf3( - @bitCast(f128, u128(0x3fcd353e45674d89abacc3a2ebf3ff50)), - @bitCast(f128, u128(0x3ff6ed8764648369535adf4be3214568)), + @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)), + @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)), 0x3fc52a163c6223fc, 0xc94c4bf0430768b4, ); @@ -76,8 +76,8 @@ test "multf3" { ); test__multf3( - @bitCast(f128, u128(0x3f154356473c82a9fabf2d22ace345df)), - @bitCast(f128, u128(0x3e38eda98765476743ab21da23d45679)), + @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)), + @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)), 0x3d4f37c1a3137cae, 0xfc6807048bc2836a, ); diff --git a/lib/std/special/compiler_rt/muldi3.zig b/lib/std/special/compiler_rt/muldi3.zig index 7700777c16..3efc5a9ac6 100644 --- a/lib/std/special/compiler_rt/muldi3.zig +++ b/lib/std/special/compiler_rt/muldi3.zig @@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 { @setRuntimeSafety(builtin.is_test); const bits_in_word_2 = @sizeOf(i32) * 8 / 2; - const lower_mask = (~u32(0)) >> bits_in_word_2; + const lower_mask = (~@as(u32, 0)) >> bits_in_word_2; var r: dwords = undefined; r.s.low = (a & lower_mask) *% (b & lower_mask); diff --git a/lib/std/special/compiler_rt/mulodi4.zig b/lib/std/special/compiler_rt/mulodi4.zig index 82e9ef3253..21c7fd1f97 100644 --- a/lib/std/special/compiler_rt/mulodi4.zig +++ b/lib/std/special/compiler_rt/mulodi4.zig @@ -6,7 +6,7 @@ const minInt = std.math.minInt; pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 { @setRuntimeSafety(builtin.is_test); - const min = @bitCast(i64, u64(1 << (i64.bit_count - 1))); + const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1))); const max = ~min; overflow.* = 0; diff --git a/lib/std/special/compiler_rt/mulodi4_test.zig b/lib/std/special/compiler_rt/mulodi4_test.zig index 7575c77044..803d60e8fa 100644 --- a/lib/std/special/compiler_rt/mulodi4_test.zig +++ b/lib/std/special/compiler_rt/mulodi4_test.zig @@ -52,34 +52,34 @@ test "mulodi4" { test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1); - test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, u64(0x8000000000000001)), 0); - test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 0); + test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); + test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0); - test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, u64(0x8000000000000001)), 1); - test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 1); + test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); + test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); - test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -2, @bitCast(i64, u64(0x8000000000000000)), 1); - test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); - test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)), 1); - test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); - test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 0, 0, 0); - test__mulodi4(0, @bitCast(i64, u64(0x8000000000000000)), 0, 0); - test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)), 0); - test__mulodi4(1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 0); - test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0x8000000000000000)), 1); - test__mulodi4(2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); + test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); + test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0); + test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0); + test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); + test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); - test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -2, @bitCast(i64, u64(0x8000000000000001)), 1); - test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 1); - test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); - test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); - test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 0, 0, 0); - test__mulodi4(0, @bitCast(i64, u64(0x8000000000000001)), 0, 0); - test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 1, @bitCast(i64, u64(0x8000000000000001)), 0); - test__mulodi4(1, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 0); - test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 2, @bitCast(i64, u64(0x8000000000000000)), 1); - test__mulodi4(2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000000)), 1); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); + test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); + test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0); + test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); + test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0); + test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); + test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); } diff --git a/lib/std/special/compiler_rt/muloti4.zig b/lib/std/special/compiler_rt/muloti4.zig index ccde8e3e6c..ad6ad43808 100644 --- a/lib/std/special/compiler_rt/muloti4.zig +++ b/lib/std/special/compiler_rt/muloti4.zig @@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig"); pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 { @setRuntimeSafety(builtin.is_test); - const min = @bitCast(i128, u128(1 << (i128.bit_count - 1))); + const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1))); const max = ~min; overflow.* = 0; diff --git a/lib/std/special/compiler_rt/muloti4_test.zig b/lib/std/special/compiler_rt/muloti4_test.zig index 00144a8839..f94a13e04f 100644 --- a/lib/std/special/compiler_rt/muloti4_test.zig +++ b/lib/std/special/compiler_rt/muloti4_test.zig @@ -39,38 +39,38 @@ test "muloti4" { test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); - test__muloti4(@bitCast(i128, u128(0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, u128(0x000000000000000000B504F333F9DE5B)), @bitCast(i128, u128(0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); - test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); - test__muloti4(-2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); + test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); + test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); - test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); - test__muloti4(-1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); - test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); - test__muloti4(0, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); - test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); - test__muloti4(1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); - test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); - test__muloti4(2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); + test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); + test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); + test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); + test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); + test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); + test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); + test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); - test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); - test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0, 0); - test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0); - test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 0); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); - test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); + test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); + test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0); + test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); + test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); + test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); - test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); - test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0, 0); - test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); - test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); - test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); - test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); + test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); + test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0); + test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); + test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); + test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); + test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); } diff --git a/lib/std/special/compiler_rt/multi3.zig b/lib/std/special/compiler_rt/multi3.zig index 799b1f575d..f3b74b85d9 100644 --- a/lib/std/special/compiler_rt/multi3.zig +++ b/lib/std/special/compiler_rt/multi3.zig @@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 { fn __mulddi3(a: u64, b: u64) i128 { const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2; - const lower_mask = ~u64(0) >> bits_in_dword_2; + const lower_mask = ~@as(u64, 0) >> bits_in_dword_2; var r: twords = undefined; r.s.low = (a & lower_mask) *% (b & lower_mask); var t: u64 = r.s.low >> bits_in_dword_2; diff --git a/lib/std/special/compiler_rt/negXf2.zig b/lib/std/special/compiler_rt/negXf2.zig index b71a503c1d..c4be085d62 100644 --- a/lib/std/special/compiler_rt/negXf2.zig +++ b/lib/std/special/compiler_rt/negXf2.zig @@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T { const significandBits = std.math.floatMantissaBits(T); const exponentBits = std.math.floatExponentBits(T); - const signBit = (Z(1) << (significandBits + exponentBits)); + const signBit = (@as(Z, 1) << (significandBits + exponentBits)); return @bitCast(T, @bitCast(Z, a) ^ signBit); } diff --git a/lib/std/special/compiler_rt/popcountdi2_test.zig b/lib/std/special/compiler_rt/popcountdi2_test.zig index bedcbcd1de..fe02786e15 100644 --- a/lib/std/special/compiler_rt/popcountdi2_test.zig +++ b/lib/std/special/compiler_rt/popcountdi2_test.zig @@ -20,8 +20,8 @@ test "popcountdi2" { test__popcountdi2(0); test__popcountdi2(1); test__popcountdi2(2); - test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFD))); - test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFE))); - test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFF))); + test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD))); + test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE))); + test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF))); // TODO some fuzz testing } diff --git a/lib/std/special/compiler_rt/truncXfYf2.zig b/lib/std/special/compiler_rt/truncXfYf2.zig index e4c4aa38a7..d231c0d416 100644 --- a/lib/std/special/compiler_rt/truncXfYf2.zig +++ b/lib/std/special/compiler_rt/truncXfYf2.zig @@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t // destination format. We can convert by simply right-shifting with // rounding and adjusting the exponent. absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits)); - absResult -%= dst_rep_t(srcExpBias - dstExpBias) << dstSigBits; + absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits; const roundBits: src_rep_t = aAbs & roundMask; if (roundBits > halfway) { diff --git a/lib/std/special/compiler_rt/truncXfYf2_test.zig b/lib/std/special/compiler_rt/truncXfYf2_test.zig index eccf7efb7e..d1dd837ddc 100644 --- a/lib/std/special/compiler_rt/truncXfYf2_test.zig +++ b/lib/std/special/compiler_rt/truncXfYf2_test.zig @@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void { test "trunctfsf2" { // qnan - test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000); + test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000); // nan - test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); + test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); // inf - test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000); + test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000); // zero test__trunctfsf2(0.0, 0x0); @@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void { test "trunctfdf2" { // qnan - test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000); + test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000); // nan - test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); + test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); // inf - test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000); + test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000); // zero test__trunctfdf2(0.0, 0x0); @@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void { test "truncdfsf2" { // nan & qnan - test__truncdfsf2(@bitCast(f64, u64(0x7ff8000000000000)), 0x7fc00000); - test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000001)), 0x7fc00000); + test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000); + test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000); // inf - test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000000)), 0x7f800000); - test__truncdfsf2(@bitCast(f64, u64(0xfff0000000000000)), 0xff800000); + test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000); + test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000); test__truncdfsf2(0.0, 0x0); test__truncdfsf2(1.0, 0x3f800000); diff --git a/lib/std/special/compiler_rt/udivmod.zig b/lib/std/special/compiler_rt/udivmod.zig index c3066153f3..96fb7b3bdd 100644 --- a/lib/std/special/compiler_rt/udivmod.zig +++ b/lib/std/special/compiler_rt/udivmod.zig @@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: // K K // --- // K 0 - sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high]))); + sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); // 0 <= sr <= SingleInt.bit_count - 2 or sr large if (sr > SingleInt.bit_count - 2) { if (maybe_rem) |rem| { @@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: // K X // --- // 0 K - sr = 1 + SingleInt.bit_count + c_uint(@clz(SingleInt, d[low])) - c_uint(@clz(SingleInt, n[high])); + sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high])); // 2 <= sr <= DoubleInt.bit_count - 1 // q.all = a << (DoubleInt.bit_count - sr); // r.all = a >> sr; @@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: // K X // --- // K K - sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high]))); + sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); // 0 <= sr <= SingleInt.bit_count - 1 or sr large if (sr > SingleInt.bit_count - 1) { if (maybe_rem) |rem| { diff --git a/lib/std/target.zig b/lib/std/target.zig index d297312b4e..d84ef47347 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -581,7 +581,7 @@ pub const Target = union(enum) { }; pub fn getExternalExecutor(self: Target) Executor { - if (@TagType(Target)(self) == .Native) return .native; + if (@as(@TagType(Target),self) == .Native) return .native; // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture. if (self.getOs() == builtin.os) { diff --git a/lib/std/thread.zig b/lib/std/thread.zig index fbfb1afd1e..4e15354055 100644 --- a/lib/std/thread.zig +++ b/lib/std/thread.zig @@ -344,7 +344,7 @@ pub const Thread = struct { pub fn cpuCount() CpuCountError!usize { if (builtin.os == .linux) { const cpu_set = try os.sched_getaffinity(0); - return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast + return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast } if (builtin.os == .windows) { var system_info: windows.SYSTEM_INFO = undefined; diff --git a/lib/std/time.zig b/lib/std/time.zig index 04dbb908e2..716c999577 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 { const hns_per_ms = (ns_per_s / 100) / ms_per_s; const epoch_adj = epoch.windows * ms_per_s; - const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime; return @divFloor(ft64, hns_per_ms) - -epoch_adj; } if (builtin.os == .wasi and !builtin.link_libc) { @@ -142,10 +142,10 @@ pub const Timer = struct { // seccomp is going to block us it will at least do so consistently var ts: os.timespec = undefined; os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported; - self.resolution = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); + self.resolution = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported; - self.start_time = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); + self.start_time = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); } return self; @@ -185,7 +185,7 @@ pub const Timer = struct { } var ts: os.timespec = undefined; os.clock_gettime(monotonic_clock_id, &ts) catch unreachable; - return @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); + return @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); } }; diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 2e96147166..5509f5f9dd 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 { return switch (bytes.len) { - 1 => u32(bytes[0]), + 1 => @as(u32, bytes[0]), 2 => utf8Decode2(bytes), 3 => utf8Decode3(bytes), 4 => utf8Decode4(bytes), @@ -226,7 +226,7 @@ pub const Utf8Iterator = struct { const slice = it.nextCodepointSlice() orelse return null; switch (slice.len) { - 1 => return u32(slice[0]), + 1 => return @as(u32, slice[0]), 2 => return utf8Decode2(slice) catch unreachable, 3 => return utf8Decode3(slice) catch unreachable, 4 => return utf8Decode4(slice) catch unreachable, @@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct { assert(it.i <= it.bytes.len); if (it.i == it.bytes.len) return null; const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); - if (c0 & ~u32(0x03ff) == 0xd800) { + if (c0 & ~@as(u32, 0x03ff) == 0xd800) { // surrogate pair it.i += 2; if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); - if (c1 & ~u32(0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; + if (c1 & ~@as(u32, 0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; it.i += 2; return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff)); - } else if (c0 & ~u32(0x03ff) == 0xdc00) { + } else if (c0 & ~@as(u32, 0x03ff) == 0xdc00) { return error.UnexpectedSecondSurrogateHalf; } else { it.i += 2; diff --git a/lib/std/valgrind.zig b/lib/std/valgrind.zig index 0d7f79dfa2..a8ebbbd8a4 100644 --- a/lib/std/valgrind.zig +++ b/lib/std/valgrind.zig @@ -76,7 +76,7 @@ pub const ClientRequest = extern enum { InnerThreads = 6402, }; pub fn ToolBase(base: [2]u8) u32 { - return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16); + return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16); } pub fn IsTool(base: [2]u8, code: usize) bool { return ToolBase(base) == (code & 0xffff0000); diff --git a/lib/std/zig/parse_string_literal.zig b/lib/std/zig/parse_string_literal.zig index acae0b64c7..a6bdff4a02 100644 --- a/lib/std/zig/parse_string_literal.zig +++ b/lib/std/zig/parse_string_literal.zig @@ -19,7 +19,7 @@ pub fn parseStringLiteral( bytes: []const u8, bad_index: *usize, // populated if error.InvalidCharacter is returned ) ParseStringLiteralError![]u8 { - const first_index = if (bytes[0] == 'c') usize(2) else usize(1); + const first_index = if (bytes[0] == 'c') @as(usize, 2) else @as(usize, 1); assert(bytes[bytes.len - 1] == '"'); var list = std.ArrayList(u8).init(allocator); diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 28bd287c8a..28497ad6f1 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" { \\test "" { \\ const result = while (returnError()) |value| { \\ break value; - \\ } else |err| i32(2); + \\ } else |err| @as(i32, 2); \\ expect(result == 2); \\} \\ diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 996cfc29e4..81ba8e941c 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -410,8 +410,8 @@ fn renderExpression( switch (prefix_op_node.op) { ast.Node.PrefixOp.Op.PtrType => |ptr_info| { const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) { - Token.Id.AsteriskAsterisk => usize(1), - else => usize(0), + Token.Id.AsteriskAsterisk => @as(usize, 1), + else => @as(usize, 0), }; try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // * if (ptr_info.allowzero_token) |allowzero_token| { @@ -2097,7 +2097,7 @@ fn renderTokenOffset( while (true) { assert(loc.line != 0); - const newline_count = if (loc.line == 1) u8(1) else u8(2); + const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2); try stream.writeByteNTimes('\n', newline_count); try stream.writeByteNTimes(' ', indent); try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")); diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig index 19488ba873..b401b25ade 100644 --- a/lib/std/zig/tokenizer.zig +++ b/lib/std/zig/tokenizer.zig @@ -350,7 +350,7 @@ pub const Tokenizer = struct { }; } else { // Skip the UTF-8 BOM if present - const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0); + const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else @as(usize, 0); return Tokenizer{ .buffer = buffer, .index = src_start, diff --git a/test/compare_output.zig b/test/compare_output.zig index cbc74c8be2..4c0cc23632 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() void { \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; - \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; + \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable; \\} , "Hello, world!\n 12 12 a\n"); @@ -166,54 +166,54 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ _ = c.printf(c"\n"); \\ \\ _ = c.printf(c"0.0: %.013a\n", - \\ f64(0.0)); + \\ @as(f64, 0.0)); \\ _ = c.printf(c"0e0: %.013a\n", - \\ f64(0e0)); + \\ @as(f64, 0e0)); \\ _ = c.printf(c"0.0e0: %.013a\n", - \\ f64(0.0e0)); + \\ @as(f64, 0.0e0)); \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n", - \\ f64(000000000000000000000000000000000000000000000000000000000.0e0)); + \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0)); \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n", - \\ f64(0.000000000000000000000000000000000000000000000000000000000e0)); + \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0)); \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n", - \\ f64(0.0e000000000000000000000000000000000000000000000000000000000)); + \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000)); \\ _ = c.printf(c"1.0: %.013a\n", - \\ f64(1.0)); + \\ @as(f64, 1.0)); \\ _ = c.printf(c"10.0: %.013a\n", - \\ f64(10.0)); + \\ @as(f64, 10.0)); \\ _ = c.printf(c"10.5: %.013a\n", - \\ f64(10.5)); + \\ @as(f64, 10.5)); \\ _ = c.printf(c"10.5e5: %.013a\n", - \\ f64(10.5e5)); + \\ @as(f64, 10.5e5)); \\ _ = c.printf(c"10.5e+5: %.013a\n", - \\ f64(10.5e+5)); + \\ @as(f64, 10.5e+5)); \\ _ = c.printf(c"50.0e-2: %.013a\n", - \\ f64(50.0e-2)); + \\ @as(f64, 50.0e-2)); \\ _ = c.printf(c"50e-2: %.013a\n", - \\ f64(50e-2)); + \\ @as(f64, 50e-2)); \\ \\ _ = c.printf(c"\n"); \\ \\ _ = c.printf(c"0x1.0: %.013a\n", - \\ f64(0x1.0)); + \\ @as(f64, 0x1.0)); \\ _ = c.printf(c"0x10.0: %.013a\n", - \\ f64(0x10.0)); + \\ @as(f64, 0x10.0)); \\ _ = c.printf(c"0x100.0: %.013a\n", - \\ f64(0x100.0)); + \\ @as(f64, 0x100.0)); \\ _ = c.printf(c"0x103.0: %.013a\n", - \\ f64(0x103.0)); + \\ @as(f64, 0x103.0)); \\ _ = c.printf(c"0x103.7: %.013a\n", - \\ f64(0x103.7)); + \\ @as(f64, 0x103.7)); \\ _ = c.printf(c"0x103.70: %.013a\n", - \\ f64(0x103.70)); + \\ @as(f64, 0x103.70)); \\ _ = c.printf(c"0x103.70p4: %.013a\n", - \\ f64(0x103.70p4)); + \\ @as(f64, 0x103.70p4)); \\ _ = c.printf(c"0x103.70p5: %.013a\n", - \\ f64(0x103.70p5)); + \\ @as(f64, 0x103.70p5)); \\ _ = c.printf(c"0x103.70p+5: %.013a\n", - \\ f64(0x103.70p+5)); + \\ @as(f64, 0x103.70p+5)); \\ _ = c.printf(c"0x103.70p-5: %.013a\n", - \\ f64(0x103.70p-5)); + \\ @as(f64, 0x103.70p-5)); \\ \\ return 0; \\} @@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ const x: f64 = small; \\ const y = @floatToInt(i32, x); \\ const z = @intToFloat(f64, y); - \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4)); + \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4)); \\ return 0; \\} , "3.25\n3\n3.00\n-0.40\n"); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 6cdc5d1cda..c7f286ce3f 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -186,7 +186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "shift amount has to be an integer type", \\export fn entry() void { - \\ const x = 1 << &u8(10); + \\ const x = 1 << &@as(u8, 10); \\} , "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'", @@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "bit shifting only works on integer types", \\export fn entry() void { - \\ const x = &u8(1) << 10; + \\ const x = &@as(u8, 1) << 10; \\} , "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'", @@ -241,7 +241,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: []align(true) i32 = undefined; \\} \\export fn entry2() void { - \\ var x: *align(f64(12.34)) i32 = undefined; + \\ var x: *align(@as(f64, 12.34)) i32 = undefined; \\} , "tmp.zig:2:20: error: expected type 'u29', found 'bool'", @@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "@truncate undefined value", \\export fn entry() void { - \\ var z = @truncate(u8, u16(undefined)); + \\ var z = @truncate(u8, @as(u16, undefined)); \\} , "tmp.zig:2:30: error: use of undefined value here causes undefined behavior", @@ -1686,7 +1686,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "non float passed to @floatToInt", \\export fn entry() void { - \\ const x = @floatToInt(i32, i32(54)); + \\ const x = @floatToInt(i32, @as(i32, 54)); \\} , "tmp.zig:2:35: error: expected float type, found 'i32'", @@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "error when evaluating return type", \\const Foo = struct { - \\ map: i32(i32), + \\ map: @as(i32, i32), \\ \\ fn init() Foo { \\ return undefined; @@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "var not allowed in structs", \\export fn entry() void { - \\ var s = (struct{v: var}){.v=i32(10)}; + \\ var s = (struct{v: var}){.v=@as(i32, 10)}; \\} , "tmp.zig:2:23: error: invalid token: 'var'", @@ -2657,7 +2657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "cast negative integer literal to usize", \\export fn entry() void { - \\ const x = usize(-10); + \\ const x = @as(usize, -10); \\} , "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'", @@ -3384,7 +3384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const x : i32 = if (b) h: { break :h 1; }; \\} \\fn g(b: bool) void { - \\ const y = if (b) h: { break :h i32(1); }; + \\ const y = if (b) h: { break :h @as(i32, 1); }; \\} \\export fn entry() void { f(true); g(true); } , @@ -3520,7 +3520,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "cast unreachable", \\fn f() i32 { - \\ return i32(return 1); + \\ return @as(i32, return 1); \\} \\export fn entry() void { _ = f(); } , @@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ switch (n) { \\ Number.One => 1, \\ Number.Two => 2, - \\ Number.Three => i32(3), + \\ Number.Three => @as(i32, 3), \\ } \\} \\ @@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ switch (n) { \\ Number.One => 1, \\ Number.Two => 2, - \\ Number.Three => i32(3), + \\ Number.Three => @as(i32, 3), \\ Number.Four => 4, \\ Number.Two => 2, \\ } @@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ switch (n) { \\ Number.One => 1, \\ Number.Two => 2, - \\ Number.Three => i32(3), + \\ Number.Three => @as(i32, 3), \\ Number.Four => 4, \\ Number.Two => 2, \\ else => 10, @@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "switch expression - duplicate or overlapping integer value", \\fn foo(x: u8) u8 { \\ return switch (x) { - \\ 0 ... 100 => u8(0), + \\ 0 ... 100 => @as(u8, 0), \\ 101 ... 200 => 1, \\ 201, 203 ... 207 => 2, \\ 206 ... 255 => 3, @@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "array concatenation with wrong type", \\const src = "aoeu"; - \\const derp = usize(1234); + \\const derp = @as(usize, 1234); \\const a = derp ++ "foo"; \\ \\export fn entry() usize { return @sizeOf(@typeOf(a)); } @@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "division by zero", \\const lit_int_x = 1 / 0; \\const lit_float_x = 1.0 / 0.0; - \\const int_x = u32(1) / u32(0); + \\const int_x = @as(u32, 1) / @as(u32, 0); \\const float_x = f32(1.0) / f32(0.0); \\ \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } @@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var bytes: [ext()]u8 = undefined; \\export fn f() void { \\ for (bytes) |*b, i| { - \\ b.* = u8(i); + \\ b.* = @as(u8, i); \\ } \\} , @@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\fn foo() i32 { - \\ return add(i32(1234)); + \\ return add(@as(i32, 1234)); \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } @@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "pass integer literal to var args", \\fn add(args: ...) i32 { - \\ var sum = i32(0); + \\ var sum = @as(i32, 0); \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { \\ sum += args[i]; \\ }} @@ -5581,7 +5581,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "explicit cast float literal to integer when there is a fraction component", \\export fn entry() i32 { - \\ return i32(12.34); + \\ return @as(i32, 12.34); \\} , "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", @@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "@shlExact shifts out 1 bits", \\comptime { - \\ const x = @shlExact(u8(0b01010101), 2); + \\ const x = @shlExact(@as(u8, 0b01010101), 2); \\} , "tmp.zig:2:15: error: operation caused overflow", @@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "@shrExact shifts out 1 bits", \\comptime { - \\ const x = @shrExact(u8(0b10101010), 2); + \\ const x = @shrExact(@as(u8, 0b10101010), 2); \\} , "tmp.zig:2:15: error: exact shift shifted out 1 bits", @@ -5699,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( "@alignCast expects pointer or slice", \\export fn entry() void { - \\ @alignCast(4, u32(3)); + \\ @alignCast(4, @as(u32, 3)); \\} , "tmp.zig:2:22: error: expected pointer or slice, found 'u32'", @@ -5744,7 +5744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const Derp = @OpaqueType(); \\extern fn bar(d: *Derp) void; \\export fn foo() void { - \\ var x = u8(1); + \\ var x = @as(u8, 1); \\ bar(@ptrCast(*c_void, &x)); \\} , @@ -5800,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "wrong types given to atomic order args in cmpxchg", \\export fn entry() void { \\ var x: i32 = 1234; - \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {} + \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} \\} , "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'", @@ -5810,7 +5810,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "wrong types given to @export", \\extern fn entry() void { } \\comptime { - \\ @export("entry", entry, u32(1234)); + \\ @export("entry", entry, @as(u32, 1234)); \\} , "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 95d2dbac93..49b757451b 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -1,7 +1,7 @@ comptime { - _ = @import("behavior/align.zig"); + //_ = @import("behavior/align.zig"); _ = @import("behavior/alignof.zig"); - _ = @import("behavior/array.zig"); + //_ = @import("behavior/array.zig"); _ = @import("behavior/asm.zig"); _ = @import("behavior/async_fn.zig"); _ = @import("behavior/atomics.zig"); @@ -50,7 +50,7 @@ comptime { _ = @import("behavior/bugs/920.zig"); _ = @import("behavior/byteswap.zig"); _ = @import("behavior/byval_arg_var.zig"); - _ = @import("behavior/cast.zig"); + //_ = @import("behavior/cast.zig"); _ = @import("behavior/const_slice_child.zig"); _ = @import("behavior/defer.zig"); _ = @import("behavior/enum.zig"); @@ -59,7 +59,7 @@ comptime { _ = @import("behavior/eval.zig"); _ = @import("behavior/field_parent_ptr.zig"); _ = @import("behavior/floatop.zig"); - _ = @import("behavior/fn.zig"); + //_ = @import("behavior/fn.zig"); _ = @import("behavior/fn_in_struct_in_comptime.zig"); _ = @import("behavior/fn_delegation.zig"); _ = @import("behavior/for.zig"); @@ -73,7 +73,7 @@ comptime { _ = @import("behavior/ir_block_deps.zig"); _ = @import("behavior/math.zig"); _ = @import("behavior/merge_error_sets.zig"); - _ = @import("behavior/misc.zig"); + //_ = @import("behavior/misc.zig"); _ = @import("behavior/muladd.zig"); _ = @import("behavior/namespace_depends_on_compile_var.zig"); _ = @import("behavior/new_stack_call.zig"); diff --git a/test/stage1/behavior/align.zig b/test/stage1/behavior/align.zig index bb40270cda..7f9ccaff1e 100644 --- a/test/stage1/behavior/align.zig +++ b/test/stage1/behavior/align.zig @@ -7,7 +7,7 @@ var foo: u8 align(4) = 100; test "global variable alignment" { expect(@typeOf(&foo).alignment == 4); expect(@typeOf(&foo) == *align(4) u8); - const slice = (*[1]u8)(&foo)[0..]; + const slice = @as(*[1]u8, &foo)[0..]; expect(@typeOf(slice) == []align(4) u8); } @@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { test "implicitly decreasing slice alignment" { const a: u32 align(4) = 3; const b: u32 align(8) = 4; - expect(addUnalignedSlice((*const [1]u32)(&a)[0..], (*const [1]u32)(&b)[0..]) == 7); + expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7); } fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { return a[0] + b[0]; diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig index 462977066e..f9ca1efdb9 100644 --- a/test/stage1/behavior/array.zig +++ b/test/stage1/behavior/array.zig @@ -12,7 +12,7 @@ test "arrays" { } i = 0; - var accumulator = u32(0); + var accumulator = @as(u32, 0); while (i < 5) { accumulator += array[i]; @@ -149,7 +149,7 @@ test "implicit cast single-item pointer" { fn testImplicitCastSingleItemPtr() void { var byte: u8 = 100; - const slice = (*[1]u8)(&byte)[0..]; + const slice = @as(*[1]u8, &byte)[0..]; slice[0] += 1; expect(byte == 101); } diff --git a/test/stage1/behavior/asm.zig b/test/stage1/behavior/asm.zig index 3fe0654a6a..9278d45d5d 100644 --- a/test/stage1/behavior/asm.zig +++ b/test/stage1/behavior/asm.zig @@ -45,42 +45,42 @@ test "alternative constraints" { test "sized integer/float in asm input" { asm volatile ("" : - : [_] "m" (usize(3)) + : [_] "m" (@as(usize, 3)) : "" ); asm volatile ("" : - : [_] "m" (i15(-3)) + : [_] "m" (@as(i15, -3)) : "" ); asm volatile ("" : - : [_] "m" (u3(3)) + : [_] "m" (@as(u3, 3)) : "" ); asm volatile ("" : - : [_] "m" (i3(3)) + : [_] "m" (@as(i3, 3)) : "" ); asm volatile ("" : - : [_] "m" (u121(3)) + : [_] "m" (@as(u121, 3)) : "" ); asm volatile ("" : - : [_] "m" (i121(3)) + : [_] "m" (@as(i121, 3)) : "" ); asm volatile ("" : - : [_] "m" (f32(3.17)) + : [_] "m" (@as(f32, 3.17)) : "" ); asm volatile ("" : - : [_] "m" (f64(3.17)) + : [_] "m" (@as(f64, 3.17)) : "" ); } diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig index 8445bcb5b2..99efa0e7be 100644 --- a/test/stage1/behavior/async_fn.zig +++ b/test/stage1/behavior/async_fn.zig @@ -191,7 +191,7 @@ async fn testSuspendBlock() void { // Test to make sure that @frame() works as advertised (issue #1296) // var our_handle: anyframe = @frame(); - expect(a_promise == anyframe(@frame())); + expect(a_promise == @as(anyframe, @frame())); global_result = true; } @@ -543,7 +543,7 @@ test "pass string literal to async function" { fn hello(msg: []const u8) void { frame = @frame(); suspend; - expectEqual(([]const u8)("hello"), msg); + expectEqual(@as([]const u8, "hello"), msg); ok = true; } }; @@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" { return await @asyncCall(frame, {}, amain, x - 1); } }; - _ = async S.amain(u32(1)); + _ = async S.amain(@as(u32, 1)); resume S.global_frame; expect(S.global_ok); } @@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" { }; }; var res: S.Foo = undefined; - var frame: @typeOf(async S.amain(u32(1))) = undefined; - _ = @asyncCall(&frame, &res, S.amain, u32(1)); + var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined; + _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1)); resume S.global_frame; expect(S.global_ok); expect(res.x == 1); diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig index 8c4a186032..d49589bdcc 100644 --- a/test/stage1/behavior/atomics.zig +++ b/test/stage1/behavior/atomics.zig @@ -98,12 +98,12 @@ test "cmpxchg with ignored result" { _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic); - expectEqual(i32(5678), x); + expectEqual(@as(i32, 5678), x); } -var a_global_variable = u32(1234); +var a_global_variable = @as(u32, 1234); test "cmpxchg on a global variable" { _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic); - expectEqual(u32(42), a_global_variable); + expectEqual(@as(u32, 42), a_global_variable); } diff --git a/test/stage1/behavior/bitreverse.zig b/test/stage1/behavior/bitreverse.zig index 2b0eb71fb6..8de2d5d2ca 100644 --- a/test/stage1/behavior/bitreverse.zig +++ b/test/stage1/behavior/bitreverse.zig @@ -46,24 +46,24 @@ fn testBitReverse() void { expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); // using comptime_ints, signed, positive - expect(@bitReverse(u8, u8(0)) == 0); - expect(@bitReverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49))); - expect(@bitReverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48))); - expect(@bitReverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48))); - expect(@bitReverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48))); - expect(@bitReverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48))); - expect(@bitReverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48))); - expect(@bitReverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48))); - expect(@bitReverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48))); - expect(@bitReverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48))); + expect(@bitReverse(u8, @as(u8, 0)) == 0); + expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49))); + expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48))); + expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48))); + expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48))); + expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48))); + expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48))); + expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48))); + expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48))); + expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48))); // using signed, negative. Compare to runtime ints returned from llvm. var neg8: i8 = -18; - expect(@bitReverse(i8, i8(-18)) == @bitReverse(i8, neg8)); + expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8)); var neg16: i16 = -32694; - expect(@bitReverse(i16, i16(-32694)) == @bitReverse(i16, neg16)); + expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16)); var neg24: i24 = -6773785; - expect(@bitReverse(i24, i24(-6773785)) == @bitReverse(i24, neg24)); + expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24)); var neg32: i32 = -16773785; - expect(@bitReverse(i32, i32(-16773785)) == @bitReverse(i32, neg32)); + expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32)); } diff --git a/test/stage1/behavior/bool.zig b/test/stage1/behavior/bool.zig index dfc2279005..ef9383244e 100644 --- a/test/stage1/behavior/bool.zig +++ b/test/stage1/behavior/bool.zig @@ -8,14 +8,14 @@ test "bool literals" { test "cast bool to int" { const t = true; const f = false; - expect(@boolToInt(t) == u32(1)); - expect(@boolToInt(f) == u32(0)); + expect(@boolToInt(t) == @as(u32, 1)); + expect(@boolToInt(f) == @as(u32, 0)); nonConstCastBoolToInt(t, f); } fn nonConstCastBoolToInt(t: bool, f: bool) void { - expect(@boolToInt(t) == u32(1)); - expect(@boolToInt(f) == u32(0)); + expect(@boolToInt(t) == @as(u32, 1)); + expect(@boolToInt(f) == @as(u32, 0)); } test "bool cmp" { diff --git a/test/stage1/behavior/bugs/1322.zig b/test/stage1/behavior/bugs/1322.zig index f1d61baa3a..3231a985e7 100644 --- a/test/stage1/behavior/bugs/1322.zig +++ b/test/stage1/behavior/bugs/1322.zig @@ -13,7 +13,7 @@ const C = struct {}; test "tagged union with all void fields but a meaningful tag" { var a: A = A{ .b = B{ .c = C{} } }; - std.testing.expect(@TagType(B)(a.b) == @TagType(B).c); + std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c); a = A{ .b = B.None }; - std.testing.expect(@TagType(B)(a.b) == @TagType(B).None); + std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None); } diff --git a/test/stage1/behavior/bugs/1421.zig b/test/stage1/behavior/bugs/1421.zig index 48cf1ae2a6..da0ba41680 100644 --- a/test/stage1/behavior/bugs/1421.zig +++ b/test/stage1/behavior/bugs/1421.zig @@ -10,5 +10,5 @@ const S = struct { test "functions with return type required to be comptime are generic" { const ti = S.method(); - expect(builtin.TypeId(ti) == builtin.TypeId.Struct); + expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct); } diff --git a/test/stage1/behavior/bugs/2114.zig b/test/stage1/behavior/bugs/2114.zig index e266279564..5b664e64ef 100644 --- a/test/stage1/behavior/bugs/2114.zig +++ b/test/stage1/behavior/bugs/2114.zig @@ -12,8 +12,8 @@ test "fixed" { } fn testClz() void { - expect(ctz(u128(0x40000000000000000000000000000000)) == 126); - expect(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1)) == u128(0x80000000000000000000000000000000)); - expect(ctz(u128(0x80000000000000000000000000000000)) == 127); - expect(ctz(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1))) == 127); + expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126); + expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); + expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127); + expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127); } diff --git a/test/stage1/behavior/bugs/3046.zig b/test/stage1/behavior/bugs/3046.zig index 709198fd58..b62474f9ba 100644 --- a/test/stage1/behavior/bugs/3046.zig +++ b/test/stage1/behavior/bugs/3046.zig @@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined; test "fixed" { some_struct = SomeStruct{ - .field = couldFail() catch |_| i32(0), + .field = couldFail() catch |_| @as(i32, 0), }; expect(some_struct.field == 1); } diff --git a/test/stage1/behavior/byteswap.zig b/test/stage1/behavior/byteswap.zig index 5408b893f5..c799ba4849 100644 --- a/test/stage1/behavior/byteswap.zig +++ b/test/stage1/behavior/byteswap.zig @@ -11,24 +11,24 @@ test "@byteSwap integers" { t(u24, 0x123456, 0x563412); t(u32, 0x12345678, 0x78563412); t(u40, 0x123456789a, 0x9a78563412); - t(i48, 0x123456789abc, @bitCast(i48, u48(0xbc9a78563412))); + t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412))); t(u56, 0x123456789abcde, 0xdebc9a78563412); t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412); - t(u0, u0(0), 0); - t(i8, i8(-50), -50); - t(i16, @bitCast(i16, u16(0x1234)), @bitCast(i16, u16(0x3412))); - t(i24, @bitCast(i24, u24(0x123456)), @bitCast(i24, u24(0x563412))); - t(i32, @bitCast(i32, u32(0x12345678)), @bitCast(i32, u32(0x78563412))); - t(u40, @bitCast(i40, u40(0x123456789a)), u40(0x9a78563412)); - t(i48, @bitCast(i48, u48(0x123456789abc)), @bitCast(i48, u48(0xbc9a78563412))); - t(i56, @bitCast(i56, u56(0x123456789abcde)), @bitCast(i56, u56(0xdebc9a78563412))); - t(i64, @bitCast(i64, u64(0x123456789abcdef1)), @bitCast(i64, u64(0xf1debc9a78563412))); + t(u0, @as(u0, 0), 0); + t(i8, @as(i8, -50), -50); + t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412))); + t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412))); + t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412))); + t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412)); + t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412))); + t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412))); + t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412))); t( i128, - @bitCast(i128, u128(0x123456789abcdef11121314151617181)), - @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)), + @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), + @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)), ); } fn t(comptime I: type, input: I, expected_output: I) void { diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index e5650bc3fc..c4fcbce0c1 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -4,7 +4,7 @@ const mem = std.mem; const maxInt = std.math.maxInt; test "int to ptr cast" { - const x = usize(13); + const x = @as(usize, 13); const y = @intToPtr(*u8, x); const z = @ptrToInt(y); expect(z == 13); @@ -90,7 +90,7 @@ const A = struct { a: i32, }; fn castToOptionalTypeError(z: i32) void { - const x = i32(1); + const x = @as(i32, 1); const y: anyerror!?i32 = x; expect((try y).? == 1); @@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" { } fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { if (c) { - return if (b) null else usize(0); + return if (b) null else @as(usize, 0); } - return usize(3); + return @as(usize, 3); } test "peer type resolution: [0]u8 and []const u8" { @@ -256,7 +256,7 @@ test "@floatToInt" { } fn testFloatToInts() void { - const x = i32(1e4); + const x = @as(i32, 1e4); expect(x == 10000); const y = @floatToInt(i32, f32(1e4)); expect(y == 10000); @@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { } test "*usize to *void" { - var i = usize(0); + var i = @as(usize, 0); var v = @ptrCast(*void, &i); v.* = {}; } diff --git a/test/stage1/behavior/defer.zig b/test/stage1/behavior/defer.zig index 6c0e2a432a..5a643609fd 100644 --- a/test/stage1/behavior/defer.zig +++ b/test/stage1/behavior/defer.zig @@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void { } test "defer and labeled break" { - var i = usize(0); + var i = @as(usize, 0); blk: { defer i += 1; diff --git a/test/stage1/behavior/enum.zig b/test/stage1/behavior/enum.zig index 6084dad3cb..f20523487d 100644 --- a/test/stage1/behavior/enum.zig +++ b/test/stage1/behavior/enum.zig @@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { expect(1234 == switch (x) { MultipleChoice.A => 1, MultipleChoice.B => 2, - MultipleChoice.C => u32(1234), + MultipleChoice.C => @as(u32, 1234), MultipleChoice.D => 4, }); } @@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { MultipleChoice2.A => 1, MultipleChoice2.B => 2, MultipleChoice2.C => 3, - MultipleChoice2.D => u32(1234), + MultipleChoice2.D => @as(u32, 1234), MultipleChoice2.Unspecified1 => 5, MultipleChoice2.Unspecified2 => 6, MultipleChoice2.Unspecified3 => 7, diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig index 983f790cbe..8ee1b30907 100644 --- a/test/stage1/behavior/error.zig +++ b/test/stage1/behavior/error.zig @@ -51,7 +51,7 @@ test "error binary operator" { expect(b == 10); } fn errBinaryOperatorG(x: bool) anyerror!isize { - return if (x) error.ItBroke else isize(10); + return if (x) error.ItBroke else @as(isize, 10); } test "unwrap simple value from error" { @@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" { test "widen cast integer payload of error union function call" { const S = struct { fn errorable() !u64 { - var x = u64(try number()); + var x = @as(u64, try number()); return x; } diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index 58d662d768..fa899d0cb2 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -405,19 +405,19 @@ test "float literal at compile time not lossy" { } test "f32 at compile time is lossy" { - expect(f32(1 << 24) + 1 == 1 << 24); + expect(@as(f32, 1 << 24) + 1 == 1 << 24); } test "f64 at compile time is lossy" { - expect(f64(1 << 53) + 1 == 1 << 53); + expect(@as(f64, 1 << 53) + 1 == 1 << 53); } test "f128 at compile time is lossy" { - expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); + expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); } comptime { - expect(f128(1 << 113) == 10384593717069655257060992658440192); + expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192); } pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { @@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" { } test "comptime slice of undefined pointer of length 0" { - const slice1 = ([*]i32)(undefined)[0..0]; + const slice1 = @as([*]i32, undefined)[0..0]; expect(slice1.len == 0); - const slice2 = ([*]i32)(undefined)[100..100]; + const slice2 = @as([*]i32, undefined)[100..100]; expect(slice2.len == 0); } @@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void { comptime var i: usize = 0; inline while (i < 4) : (i += 1) { s[i] = 0; - s[i] |= u32(b[i * 4 + 0]) << 24; - s[i] |= u32(b[i * 4 + 1]) << 16; - s[i] |= u32(b[i * 4 + 2]) << 8; - s[i] |= u32(b[i * 4 + 3]) << 0; + s[i] |= @as(u32, b[i * 4 + 0]) << 24; + s[i] |= @as(u32, b[i * 4 + 1]) << 16; + s[i] |= @as(u32, b[i * 4 + 2]) << 8; + s[i] |= @as(u32, b[i * 4 + 3]) << 0; } } @@ -557,14 +557,14 @@ test "array concat of slices gives slice" { test "comptime shlWithOverflow" { const ct_shifted: u64 = comptime amt: { - var amt = u64(0); - _ = @shlWithOverflow(u64, ~u64(0), 16, &amt); + var amt = @as(u64, 0); + _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt); break :amt amt; }; const rt_shifted: u64 = amt: { - var amt = u64(0); - _ = @shlWithOverflow(u64, ~u64(0), 16, &amt); + var amt = @as(u64, 0); + _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt); break :amt amt; }; @@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void { } test "variable inside inline loop that has different types on different iterations" { - testVarInsideInlineLoop(true, u32(42)); + testVarInsideInlineLoop(true, @as(u32, 42)); } fn testVarInsideInlineLoop(args: ...) void { @@ -757,11 +757,11 @@ test "comptime bitwise operators" { expect(-3 | -1 == -1); expect(3 ^ -1 == -4); expect(-3 ^ -1 == 2); - expect(~i8(-1) == 0); - expect(~i128(-1) == 0); + expect(~@as(i8, -1) == 0); + expect(~@as(i128, -1) == 0); expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); - expect(~u128(0) == 0xffffffffffffffffffffffffffffffff); + expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff); } } diff --git a/test/stage1/behavior/floatop.zig b/test/stage1/behavior/floatop.zig index de2f6815a6..eb386d75f9 100644 --- a/test/stage1/behavior/floatop.zig +++ b/test/stage1/behavior/floatop.zig @@ -117,11 +117,11 @@ test "@ln" { fn testLn() void { { var a: f32 = e; - expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, u32(0x3f7fffff))); + expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, @as(u32, 0x3f7fffff))); } { var a: f64 = e; - expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, u64(0x3ff0000000000000))); + expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, @as(u64, 0x3ff0000000000000))); } } diff --git a/test/stage1/behavior/fn.zig b/test/stage1/behavior/fn.zig index 6b9c8b8fe7..1fc586f39f 100644 --- a/test/stage1/behavior/fn.zig +++ b/test/stage1/behavior/fn.zig @@ -29,7 +29,7 @@ test "mutable local variables" { var zero: i32 = 0; expect(zero == 0); - var i = i32(0); + var i = @as(i32, 0); while (i != 3) { i += 1; } @@ -43,7 +43,7 @@ test "separate block scopes" { } const c = x: { - const no_conflict = i32(10); + const no_conflict = @as(i32, 10); break :x no_conflict; }; expect(c == 10); diff --git a/test/stage1/behavior/if.zig b/test/stage1/behavior/if.zig index d299817f46..9e93ceb656 100644 --- a/test/stage1/behavior/if.zig +++ b/test/stage1/behavior/if.zig @@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 { } else if (c == 1) { return 1; } else { - return u8(2); + return @as(u8, 2); } } @@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" { var c = true; if (c) { answer = if (true) blk: { - break :blk i32(42); + break :blk @as(i32, 42); }; } expect(answer == 42); diff --git a/test/stage1/behavior/import.zig b/test/stage1/behavior/import.zig index aa6e9d82ba..2aa2ec4e60 100644 --- a/test/stage1/behavior/import.zig +++ b/test/stage1/behavior/import.zig @@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual; const a_namespace = @import("import/a_namespace.zig"); test "call fn via namespace lookup" { - expectEqual(i32(1234), a_namespace.foo()); + expectEqual(@as(i32, 1234), a_namespace.foo()); } test "importing the same thing gives the same import" { @@ -14,5 +14,5 @@ test "import in non-toplevel scope" { const S = struct { usingnamespace @import("import/a_namespace.zig"); }; - expectEqual(i32(1234), S.foo()); + expectEqual(@as(i32, 1234), S.foo()); } diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig index 1ff63e3e23..37a23fa325 100644 --- a/test/stage1/behavior/math.zig +++ b/test/stage1/behavior/math.zig @@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void { assertFalse(90 >> 1 >> 2 != 90 >> 3); assertFalse(100 - 1 + 1000 != 1099); assertFalse(5 * 4 / 2 % 3 != 1); - assertFalse(i32(i32(5)) != 5); + assertFalse(@as(i32, @as(i32, 5)) != 5); assertFalse(!!false); - assertFalse(i32(7) != --(i32(7))); + assertFalse(@as(i32, 7) != --(@as(i32, 7))); } fn assertFalse(b: bool) void { expect(!b); @@ -256,10 +256,10 @@ const DivResult = struct { test "binary not" { expect(comptime x: { - break :x ~u16(0b1010101010101010) == 0b0101010101010101; + break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101; }); expect(comptime x: { - break :x ~u64(2147483647) == 18446744071562067968; + break :x ~@as(u64, 2147483647) == 18446744071562067968; }); testBinaryNot(0b1010101010101010); } @@ -472,7 +472,7 @@ test "comptime_int multiplication" { test "comptime_int shifting" { comptime { - expect((u128(1) << 127) == 0x80000000000000000000000000000000); + expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000); } } @@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" { comptime { var a = 0xefffffffa0000001eeeeeeefaaaaaaab; - expect(u32(a & 0xffffffff) == 0xaaaaaaab); + expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab); a >>= 32; - expect(u32(a & 0xffffffff) == 0xeeeeeeef); + expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef); a >>= 32; - expect(u32(a & 0xffffffff) == 0xa0000001); + expect(@as(u32, a & 0xffffffff) == 0xa0000001); a >>= 32; - expect(u32(a & 0xffffffff) == 0xefffffff); + expect(@as(u32, a & 0xffffffff) == 0xefffffff); a >>= 32; expect(a == 0); @@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void { test "comptime float rem int" { comptime { - var x = f32(1) % 2; + var x = @as(f32, 1) % 2; expect(x == 1.0); } } @@ -568,8 +568,8 @@ test "remainder division" { } fn remdiv(comptime T: type) void { - expect(T(1) == T(1) % T(2)); - expect(T(1) == T(7) % T(3)); + expect(@as(T, 1) == @as(T, 1) % @as(T, 2)); + expect(@as(T, 1) == @as(T, 7) % @as(T, 3)); } test "@sqrt" { diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index 65ac83bcf0..75bf23622a 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -268,7 +268,7 @@ fn outer() i64 { } test "pointer dereferencing" { - var x = i32(3); + var x = @as(i32, 3); const y = &x; y.* += 1; @@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type { } test "double implicit cast in same expression" { - var x = i32(u16(nine())); + var x = @as(i32, @as(u16, nine())); expect(x == 9); } fn nine() u8 { @@ -761,7 +761,7 @@ test "nested optional field in struct" { fn maybe(x: bool) anyerror!?u32 { return switch (x) { - true => u32(42), + true => @as(u32, 42), else => null, }; } diff --git a/test/stage1/behavior/popcount.zig b/test/stage1/behavior/popcount.zig index 044864cede..884a7bdb6d 100644 --- a/test/stage1/behavior/popcount.zig +++ b/test/stage1/behavior/popcount.zig @@ -35,7 +35,7 @@ fn testPopCount() void { expect(@popCount(i8, x) == 2); } comptime { - expect(@popCount(u8, @bitCast(u8, i8(-120))) == 2); + expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2); } comptime { expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); diff --git a/test/stage1/behavior/pub_enum.zig b/test/stage1/behavior/pub_enum.zig index 6275be7a01..0613df94d9 100644 --- a/test/stage1/behavior/pub_enum.zig +++ b/test/stage1/behavior/pub_enum.zig @@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void { } test "cast with imported symbol" { - expect(other.size_t(42) == 42); + expect(@as(other.size_t, 42) == 42); } diff --git a/test/stage1/behavior/shuffle.zig b/test/stage1/behavior/shuffle.zig index a8daf6557a..1985c8dc76 100644 --- a/test/stage1/behavior/shuffle.zig +++ b/test/stage1/behavior/shuffle.zig @@ -7,39 +7,39 @@ test "@shuffle" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - const mask: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 3, ~i32(3) }; + const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; var res = @shuffle(i32, v, x, mask); - expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 })); + expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); // Implicit cast from array (of mask) - res = @shuffle(i32, v, x, [4]i32{ 0, ~i32(2), 3, ~i32(3) }); - expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 })); + res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }); + expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); // Undefined const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; res = @shuffle(i32, v, undefined, mask2); - expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 40, -2, 30, 2147483647 })); + expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 })); // Upcasting of b var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; - const mask3: @Vector(4, i32) = [4]i32{ ~i32(0), 2, ~i32(0), 3 }; + const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; res = @shuffle(i32, x, v2, mask3); - expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 2147483647, 4 })); + expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 })); // Upcasting of a var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; - const mask4: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 1, ~i32(3) }; + const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; res = @shuffle(i32, v3, x, mask4); - expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, -2, 4 })); + expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 })); // bool // Disabled because of #3317 if (@import("builtin").arch != .mipsel) { var x2: @Vector(4, bool) = [4]bool{ false, true, false, true }; var v4: @Vector(2, bool) = [2]bool{ true, false }; - const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 }; + const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; var res2 = @shuffle(bool, x2, v4, mask5); - expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); } // TODO re-enable when LLVM codegen is fixed @@ -47,9 +47,9 @@ test "@shuffle" { if (false) { var x2: @Vector(3, bool) = [3]bool{ false, true, false }; var v4: @Vector(2, bool) = [2]bool{ true, false }; - const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 }; + const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; var res2 = @shuffle(bool, x2, v4, mask5); - expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); } } }; diff --git a/test/stage1/behavior/slicetobytes.zig b/test/stage1/behavior/slicetobytes.zig index b86b38beaf..c0eb4a8f9b 100644 --- a/test/stage1/behavior/slicetobytes.zig +++ b/test/stage1/behavior/slicetobytes.zig @@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" { const S = struct { fn doTheTest() void { var foo: Foo = undefined; - var slice = @sliceToBytes(((*[1]Foo)(&foo))[0..1]); + var slice = @sliceToBytes(@as(*[1]Foo, &foo)[0..1]); slice[0] = 0x13; switch (builtin.endian) { builtin.Endian.Big => { diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index ede31c0162..76ecad6b43 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" { expect(s2.y == @intCast(u4, x2)); } -var x1 = u4(1); -var x2 = u8(2); +var x1 = @as(u4, 1); +var x2 = @as(u8, 2); const Nibbles = packed struct { x: u4, @@ -545,9 +545,9 @@ test "packed struct with fp fields" { s.data[1] = 2.0; s.data[2] = 3.0; s.frob(); - expectEqual(f32(6.0), s.data[0]); - expectEqual(f32(11.0), s.data[1]); - expectEqual(f32(20.0), s.data[2]); + expectEqual(@as(f32, 6.0), s.data[0]); + expectEqual(@as(f32, 11.0), s.data[1]); + expectEqual(@as(f32, 20.0), s.data[2]); } test "use within struct scope" { @@ -558,7 +558,7 @@ test "use within struct scope" { } }; }; - expectEqual(i32(42), S.inner()); + expectEqual(@as(i32, 42), S.inner()); } test "default struct initialization fields" { @@ -583,7 +583,7 @@ test "extern fn returns struct by value" { const S = struct { fn entry() void { var x = makeBar(10); - expectEqual(i32(10), x.handle); + expectEqual(@as(i32, 10), x.handle); } const ExternBar = extern struct { @@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" { const ArrayList = struct { fn toSlice(self: *ArrayList) []*Foo { - return ([*]*Foo)(undefined)[0..0]; + return @as([*]*Foo, undefined)[0..0]; } }; diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig index 936dbed786..1a18a5c440 100644 --- a/test/stage1/behavior/switch.zig +++ b/test/stage1/behavior/switch.zig @@ -68,7 +68,7 @@ test "switch statement" { } fn nonConstSwitch(foo: SwitchStatmentFoo) void { const val = switch (foo) { - SwitchStatmentFoo.A => i32(1), + SwitchStatmentFoo.A => @as(i32, 1), SwitchStatmentFoo.B => 2, SwitchStatmentFoo.C => 3, SwitchStatmentFoo.D => 4, @@ -127,7 +127,7 @@ test "switch with multiple expressions" { const x = switch (returnsFive()) { 1, 2, 3 => 1, 4, 5, 6 => 2, - else => i32(3), + else => @as(i32, 3), }; expect(x == 2); } @@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void { fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { return switch (x) { - 0 => u2(3), + 0 => @as(u2, 3), 1 => 2, 2 => 1, 3 => 0, @@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { fn testSwitchHandleAllCasesRange(x: u8) u8 { return switch (x) { - 0...100 => u8(0), + 0...100 => @as(u8, 0), 101...200 => 1, 201, 203 => 2, 202 => 4, diff --git a/test/stage1/behavior/try.zig b/test/stage1/behavior/try.zig index 9c700f6260..9e93183c3b 100644 --- a/test/stage1/behavior/try.zig +++ b/test/stage1/behavior/try.zig @@ -8,7 +8,7 @@ test "try on error union" { fn tryOnErrorUnionImpl() void { const x = if (returnsTen()) |val| val + 1 else |err| switch (err) { error.ItBroke, error.NoMem => 1, - error.CrappedOut => i32(2), + error.CrappedOut => @as(i32, 2), else => unreachable, }; expect(x == 11); @@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 { } test "try without vars" { - const result1 = if (failIfTrue(true)) 1 else |_| i32(2); + const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2); expect(result1 == 2); - const result2 = if (failIfTrue(false)) 1 else |_| i32(2); + const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2); expect(result2 == 1); } diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index aafce2990c..ed64e3e430 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -13,7 +13,7 @@ test "type info: tag type, void info" { fn testBasic() void { expect(@TagType(TypeInfo) == TypeId); const void_info = @typeInfo(void); - expect(TypeId(void_info) == TypeId.Void); + expect(@as(TypeId, void_info) == TypeId.Void); expect(void_info.Void == {}); } @@ -24,12 +24,12 @@ test "type info: integer, floating point type info" { fn testIntFloat() void { const u8_info = @typeInfo(u8); - expect(TypeId(u8_info) == TypeId.Int); + expect(@as(TypeId, u8_info) == TypeId.Int); expect(!u8_info.Int.is_signed); expect(u8_info.Int.bits == 8); const f64_info = @typeInfo(f64); - expect(TypeId(f64_info) == TypeId.Float); + expect(@as(TypeId, f64_info) == TypeId.Float); expect(f64_info.Float.bits == 64); } @@ -40,7 +40,7 @@ test "type info: pointer type info" { fn testPointer() void { const u32_ptr_info = @typeInfo(*u32); - expect(TypeId(u32_ptr_info) == TypeId.Pointer); + expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer); expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); expect(u32_ptr_info.Pointer.is_const == false); expect(u32_ptr_info.Pointer.is_volatile == false); @@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" { fn testUnknownLenPtr() void { const u32_ptr_info = @typeInfo([*]const volatile f64); - expect(TypeId(u32_ptr_info) == TypeId.Pointer); + expect(@as(TypeId,u32_ptr_info) == TypeId.Pointer); expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); expect(u32_ptr_info.Pointer.is_const == true); expect(u32_ptr_info.Pointer.is_volatile == true); @@ -70,7 +70,7 @@ test "type info: C pointer type info" { fn testCPtr() void { const ptr_info = @typeInfo([*c]align(4) const i8); - expect(TypeId(ptr_info) == TypeId.Pointer); + expect(@as(TypeId,ptr_info) == TypeId.Pointer); expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C); expect(ptr_info.Pointer.is_const); expect(!ptr_info.Pointer.is_volatile); @@ -85,7 +85,7 @@ test "type info: slice type info" { fn testSlice() void { const u32_slice_info = @typeInfo([]u32); - expect(TypeId(u32_slice_info) == TypeId.Pointer); + expect(@as(TypeId, u32_slice_info) == TypeId.Pointer); expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); expect(u32_slice_info.Pointer.is_const == false); expect(u32_slice_info.Pointer.is_volatile == false); @@ -100,7 +100,7 @@ test "type info: array type info" { fn testArray() void { const arr_info = @typeInfo([42]bool); - expect(TypeId(arr_info) == TypeId.Array); + expect(@as(TypeId, arr_info) == TypeId.Array); expect(arr_info.Array.len == 42); expect(arr_info.Array.child == bool); } @@ -112,7 +112,7 @@ test "type info: optional type info" { fn testOptional() void { const null_info = @typeInfo(?void); - expect(TypeId(null_info) == TypeId.Optional); + expect(@as(TypeId, null_info) == TypeId.Optional); expect(null_info.Optional.child == void); } @@ -129,18 +129,18 @@ fn testErrorSet() void { }; const error_set_info = @typeInfo(TestErrorSet); - expect(TypeId(error_set_info) == TypeId.ErrorSet); + expect(@as(TypeId, error_set_info) == TypeId.ErrorSet); expect(error_set_info.ErrorSet.?.len == 3); expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third)); const error_union_info = @typeInfo(TestErrorSet!usize); - expect(TypeId(error_union_info) == TypeId.ErrorUnion); + expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion); expect(error_union_info.ErrorUnion.error_set == TestErrorSet); expect(error_union_info.ErrorUnion.payload == usize); const global_info = @typeInfo(anyerror); - expect(TypeId(global_info) == TypeId.ErrorSet); + expect(@as(TypeId, global_info) == TypeId.ErrorSet); expect(global_info.ErrorSet == null); } @@ -158,7 +158,7 @@ fn testEnum() void { }; const os_info = @typeInfo(Os); - expect(TypeId(os_info) == TypeId.Enum); + expect(@as(TypeId, os_info) == TypeId.Enum); expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); expect(os_info.Enum.fields.len == 4); expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); @@ -174,7 +174,7 @@ test "type info: union info" { fn testUnion() void { const typeinfo_info = @typeInfo(TypeInfo); - expect(TypeId(typeinfo_info) == TypeId.Union); + expect(@as(TypeId, typeinfo_info) == TypeId.Union); expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); expect(typeinfo_info.Union.tag_type.? == TypeId); expect(typeinfo_info.Union.fields.len == 26); @@ -189,7 +189,7 @@ fn testUnion() void { }; const notag_union_info = @typeInfo(TestNoTagUnion); - expect(TypeId(notag_union_info) == TypeId.Union); + expect(@as(TypeId, notag_union_info) == TypeId.Union); expect(notag_union_info.Union.tag_type == null); expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); expect(notag_union_info.Union.fields.len == 2); @@ -214,7 +214,7 @@ test "type info: struct info" { fn testStruct() void { const struct_info = @typeInfo(TestStruct); - expect(TypeId(struct_info) == TypeId.Struct); + expect(@as(TypeId, struct_info) == TypeId.Struct); expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); expect(struct_info.Struct.fields.len == 3); expect(struct_info.Struct.fields[1].offset == null); @@ -244,7 +244,7 @@ test "type info: function type info" { fn testFunction() void { const fn_info = @typeInfo(@typeOf(foo)); - expect(TypeId(fn_info) == TypeId.Fn); + expect(@as(TypeId, fn_info) == TypeId.Fn); expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); expect(fn_info.Fn.is_generic); expect(fn_info.Fn.args.len == 2); @@ -253,7 +253,7 @@ fn testFunction() void { const test_instance: TestStruct = undefined; const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); - expect(TypeId(bound_fn_info) == TypeId.BoundFn); + expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); } @@ -275,7 +275,7 @@ test "type info: vectors" { fn testVector() void { const vec_info = @typeInfo(@Vector(4, i32)); - expect(TypeId(vec_info) == TypeId.Vector); + expect(@as(TypeId, vec_info) == TypeId.Vector); expect(vec_info.Vector.len == 4); expect(vec_info.Vector.child == i32); } @@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" { fn testAnyFrame() void { { const anyframe_info = @typeInfo(anyframe->i32); - expect(TypeId(anyframe_info) == .AnyFrame); + expect(@as(TypeId,anyframe_info) == .AnyFrame); expect(anyframe_info.AnyFrame.child.? == i32); } { const anyframe_info = @typeInfo(anyframe); - expect(TypeId(anyframe_info) == .AnyFrame); + expect(@as(TypeId,anyframe_info) == .AnyFrame); expect(anyframe_info.AnyFrame.child == null); } } @@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" { if (std.mem.eql(u8, decl.name, "bar1")) { expect(decl.data.Fn.lib_name == null); } else { - std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?); + std.testing.expectEqual(@as([]const u8,"cool"), decl.data.Fn.lib_name.?); } } } @@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" { test "data field is a compile-time value" { const S = struct { - const Bar = isize(-1); + const Bar = @as(isize, -1); }; comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize); } diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index 40adf601c4..40af5c4fd4 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -14,7 +14,7 @@ const Agg = struct { const v1 = Value{ .Int = 1234 }; const v2 = Value{ .Array = [_]u8{3} ** 9 }; -const err = (anyerror!Agg)(Agg{ +const err = @as(anyerror!Agg, Agg{ .val1 = v1, .val2 = v2, }); @@ -110,11 +110,11 @@ fn doTest() void { } fn bar(value: Payload) i32 { - expect(Letter(value) == Letter.A); + expect(@as(Letter,value) == Letter.A); return switch (value) { Payload.A => |x| return x - 1244, - Payload.B => |x| if (x == 12.34) i32(20) else 21, - Payload.C => |x| if (x) i32(30) else 31, + Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21, + Payload.C => |x| if (x) @as(i32, 30) else 31, }; } @@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) { test "simple union(enum(u32))" { var x = MultipleChoice.C; expect(x == MultipleChoice.C); - expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60); + expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60); } const MultipleChoice2 = union(enum(u32)) { @@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" { } fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { - expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60); + expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60); expect(1123 == switch (x) { MultipleChoice2.A => 1, MultipleChoice2.B => 2, - MultipleChoice2.C => |v| i32(1000) + v, + MultipleChoice2.C => |v| @as(i32, 1000) + v, MultipleChoice2.D => 4, MultipleChoice2.Unspecified1 => 5, MultipleChoice2.Unspecified2 => 6, @@ -208,12 +208,12 @@ test "cast union to tag type of union" { } fn testCastUnionToTagType(x: TheUnion) void { - expect(TheTag(x) == TheTag.B); + expect(@as(TheTag,x) == TheTag.B); } test "cast tag type of union to union" { var x: Value2 = Letter2.B; - expect(Letter2(x) == Letter2.B); + expect(@as(Letter2, x) == Letter2.B); } const Letter2 = enum { A, @@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) { fn testTaggedUnionInit(x: var) bool { const y = TaggedUnionWithAVoid{ .A = x }; - return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A; + return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A; } pub const UnionEnumNoPayloads = union(enum) { @@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" { var e = Expr{ .Literal = Literal{ .Bool = true } }; const Tag = @TagType(Expr); comptime expect(@TagType(Tag) == u0); - var t = Tag(e); + var t = @as(Tag, e); expect(t == Expr.Literal); } @@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci var e = Expr{ .Literal = Literal{ .Bool = true } }; comptime expect(@TagType(Tag) == comptime_int); - var t = Tag(e); + var t = @as(Tag, e); expect(t == Expr.Literal); expect(@enumToInt(t) == 33); comptime expect(@enumToInt(t) == 33); diff --git a/test/stage1/behavior/var_args.zig b/test/stage1/behavior/var_args.zig index 191893ff8b..19df436481 100644 --- a/test/stage1/behavior/var_args.zig +++ b/test/stage1/behavior/var_args.zig @@ -1,7 +1,7 @@ const expect = @import("std").testing.expect; fn add(args: ...) i32 { - var sum = i32(0); + var sum = @as(i32, 0); { comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { @@ -12,8 +12,8 @@ fn add(args: ...) i32 { } test "add arbitrary args" { - expect(add(i32(1), i32(2), i32(3), i32(4)) == 10); - expect(add(i32(1234)) == 1234); + expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10); + expect(add(@as(i32, 1234)) == 1234); expect(add() == 0); } @@ -26,8 +26,8 @@ test "send void arg to var args" { } test "pass args directly" { - expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10); - expect(addSomeStuff(i32(1234)) == 1234); + expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10); + expect(addSomeStuff(@as(i32, 1234)) == 1234); expect(addSomeStuff() == 0); } diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig index f747f7c184..f7b98b294f 100644 --- a/test/stage1/behavior/vector.zig +++ b/test/stage1/behavior/vector.zig @@ -20,11 +20,11 @@ test "vector wrap operators" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); - expect(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 })); - expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 2147483647, 2, 90, 160 })); + expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); + expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 })); + expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 })); var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; - expect(mem.eql(i32, ([4]i32)(-%z), [4]i32{ -1, -2, -3, -2147483648 })); + expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 })); } }; S.doTheTest(); @@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; - expect(mem.eql(bool, ([4]bool)(v == x), [4]bool{ false, false, true, false })); - expect(mem.eql(bool, ([4]bool)(v != x), [4]bool{ true, true, false, true })); - expect(mem.eql(bool, ([4]bool)(v < x), [4]bool{ false, true, false, false })); - expect(mem.eql(bool, ([4]bool)(v > x), [4]bool{ true, false, false, true })); - expect(mem.eql(bool, ([4]bool)(v <= x), [4]bool{ false, true, true, false })); - expect(mem.eql(bool, ([4]bool)(v >= x), [4]bool{ true, false, true, true })); + expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true })); + expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false })); + expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true })); + expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false })); + expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true })); } }; S.doTheTest(); @@ -53,10 +53,10 @@ test "vector int operators" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; - expect(mem.eql(i32, ([4]i32)(v + x), [4]i32{ 11, 22, 33, 44 })); - expect(mem.eql(i32, ([4]i32)(v - x), [4]i32{ 9, 18, 27, 36 })); - expect(mem.eql(i32, ([4]i32)(v * x), [4]i32{ 10, 40, 90, 160 })); - expect(mem.eql(i32, ([4]i32)(-v), [4]i32{ -10, -20, -30, -40 })); + expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 })); + expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 })); + expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 })); + expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 })); } }; S.doTheTest(); @@ -68,10 +68,10 @@ test "vector float operators" { fn doTheTest() void { var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 }; - expect(mem.eql(f32, ([4]f32)(v + x), [4]f32{ 11, 22, 33, 44 })); - expect(mem.eql(f32, ([4]f32)(v - x), [4]f32{ 9, 18, 27, 36 })); - expect(mem.eql(f32, ([4]f32)(v * x), [4]f32{ 10, 40, 90, 160 })); - expect(mem.eql(f32, ([4]f32)(-x), [4]f32{ -1, -2, -3, -4 })); + expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 })); + expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 })); + expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 })); + expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 })); } }; S.doTheTest(); @@ -83,9 +83,9 @@ test "vector bit operators" { fn doTheTest() void { var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; - expect(mem.eql(u8, ([4]u8)(v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); - expect(mem.eql(u8, ([4]u8)(v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); - expect(mem.eql(u8, ([4]u8)(v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); + expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); + expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); + expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); } }; S.doTheTest(); @@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" { { var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; var x: [4]u3 = v; - expect(mem.eql(u3, x, ([4]u3)(v))); + expect(mem.eql(u3, x, @as([4]u3, v))); } { var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; var x: [4]u2 = v; - expect(mem.eql(u2, x, ([4]u2)(v))); + expect(mem.eql(u2, x, @as([4]u2, v))); } { var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; var x: [4]u1 = v; - expect(mem.eql(u1, x, ([4]u1)(v))); + expect(mem.eql(u1, x, @as([4]u1, v))); } { var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; var x: [4]bool = v; - expect(mem.eql(bool, x, ([4]bool)(v))); + expect(mem.eql(bool, x, @as([4]bool, v))); } } }; diff --git a/test/stage1/behavior/void.zig b/test/stage1/behavior/void.zig index 19e879d157..80df9fe4f9 100644 --- a/test/stage1/behavior/void.zig +++ b/test/stage1/behavior/void.zig @@ -26,7 +26,7 @@ test "iterate over a void slice" { } fn times(n: usize) []const void { - return ([*]void)(undefined)[0..n]; + return @as([*]void, undefined)[0..n]; } test "void optional" { diff --git a/test/stage1/behavior/while.zig b/test/stage1/behavior/while.zig index 58ff713c23..0d0ef3a69f 100644 --- a/test/stage1/behavior/while.zig +++ b/test/stage1/behavior/while.zig @@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" { const result = while (returnNull()) |value| { break value; } else - i32(2); + @as(i32, 2); expect(result == 2); } @@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" { const result = while (returnOptional(10)) |value| { break value; } else - i32(2); + @as(i32, 2); expect(result == 10); } @@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" { const result = while (returnError()) |value| { break value; } else |err| - i32(2); + @as(i32, 2); expect(result == 2); } @@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" { const result = while (returnSuccess(10)) |value| { break value; } else |err| - i32(2); + @as(i32, 2); expect(result == 10); } test "while on bool with else result follow else prong" { const result = while (returnFalse()) { - break i32(10); + break @as(i32, 10); } else - i32(2); + @as(i32, 2); expect(result == 2); } test "while on bool with else result follow break prong" { const result = while (returnTrue()) { - break i32(10); + break @as(i32, 10); } else - i32(2); + @as(i32, 2); expect(result == 10); } diff --git a/test/tests.zig b/test/tests.zig index 84a9c979cd..2bb0f33487 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -411,7 +411,7 @@ pub fn addPkgTests( const ArchTag = @TagType(builtin.Arch); if (test_target.disable_native and test_target.target.getOs() == builtin.os and - ArchTag(test_target.target.getArch()) == ArchTag(builtin.arch)) + @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch)) { continue; } @@ -429,7 +429,7 @@ pub fn addPkgTests( "bare"; const triple_prefix = if (test_target.target == .Native) - ([]const u8)("native") + @as([]const u8,"native") else test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; diff --git a/test/translate_c.zig b/test/translate_c.zig index a79d12fbfb..54e4131155 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , \\pub fn foo() void { \\ var a: c_int = undefined; - \\ var b: u8 = u8(123); + \\ var b: u8 = @as(u8, 123); \\ const c: c_int = undefined; - \\ const d: c_uint = c_uint(440); + \\ const d: c_uint = @as(c_uint, 440); \\} ); @@ -561,7 +561,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("u integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ , - \\pub const SDL_INIT_VIDEO = c_uint(32); + \\pub const SDL_INIT_VIDEO = @as(c_uint, 32); ); cases.add("l integer suffix after hex literal", @@ -676,7 +676,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn log2(_arg_a: c_uint) c_int { \\ var a = _arg_a; \\ var i: c_int = 0; - \\ while (a > c_uint(0)) { + \\ while (a > @as(c_uint, 0)) { \\ a >>= @import("std").math.Log2Int(c_uint)(1); \\ } \\ return i; @@ -848,7 +848,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn log2(_arg_a: u32) c_int { \\ var a = _arg_a; \\ var i: c_int = 0; - \\ while (a > c_uint(0)) { + \\ while (a > @as(c_uint, 0)) { \\ a >>= u5(1); \\ } \\ return i; @@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , \\pub export fn float_to_int(a: f32) c_int { - \\ return c_int(a); + \\ return @as(c_int, a); \\} ); @@ -1103,35 +1103,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , \\pub export fn foo() void { - \\ var a: c_uint = c_uint(0); + \\ var a: c_uint = @as(c_uint, 0); \\ a +%= (x: { \\ const _ref = &a; - \\ _ref.* = (_ref.* +% c_uint(1)); + \\ _ref.* = (_ref.* +% @as(c_uint, 1)); \\ break :x _ref.*; \\ }); \\ a -%= (x: { \\ const _ref = &a; - \\ _ref.* = (_ref.* -% c_uint(1)); + \\ _ref.* = (_ref.* -% @as(c_uint, 1)); \\ break :x _ref.*; \\ }); \\ a *%= (x: { \\ const _ref = &a; - \\ _ref.* = (_ref.* *% c_uint(1)); + \\ _ref.* = (_ref.* *% @as(c_uint, 1)); \\ break :x _ref.*; \\ }); \\ a &= (x: { \\ const _ref = &a; - \\ _ref.* = (_ref.* & c_uint(1)); + \\ _ref.* = (_ref.* & @as(c_uint, 1)); \\ break :x _ref.*; \\ }); \\ a |= (x: { \\ const _ref = &a; - \\ _ref.* = (_ref.* | c_uint(1)); + \\ _ref.* = (_ref.* | @as(c_uint, 1)); \\ break :x _ref.*; \\ }); \\ a ^= (x: { \\ const _ref = &a; - \\ _ref.* = (_ref.* ^ c_uint(1)); + \\ _ref.* = (_ref.* ^ @as(c_uint, 1)); \\ break :x _ref.*; \\ }); \\ a >>= @import("std").math.Log2Int(c_uint)((x: { @@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , \\pub export fn foo() void { \\ var i: c_int = 0; - \\ var u: c_uint = c_uint(0); + \\ var u: c_uint = @as(c_uint, 0); \\ i += 1; \\ i -= 1; \\ u +%= 1; @@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , \\pub export fn foo() void { \\ var i: c_int = 0; - \\ var u: c_uint = c_uint(0); + \\ var u: c_uint = @as(c_uint, 0); \\ i += 1; \\ i -= 1; \\ u +%= 1; @@ -1646,7 +1646,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.addC( "u integer suffix after 0 (zero) in macro definition", "#define ZERO 0U", - "pub const ZERO = c_uint(0);", + "pub const ZERO = @as(c_uint, 0);", ); cases.addC( @@ -1688,7 +1688,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.addC( "bitwise not on u-suffixed 0 (zero) in macro definition", "#define NOT_ZERO (~0U)", - "pub const NOT_ZERO = ~c_uint(0);", + "pub const NOT_ZERO = ~@as(c_uint, 0);", ); cases.addC("implicit casts", @@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ fn_int(1094861636); \\ fn_f32(@intToFloat(f32, 3)); \\ fn_f64(@intToFloat(f64, 3)); - \\ fn_char(u8('3')); - \\ fn_char(u8('\x01')); - \\ fn_char(u8(0)); + \\ fn_char(@as(u8, '3')); + \\ fn_char(@as(u8, '\x01')); + \\ fn_char(@as(u8, 0)); \\ fn_f32(3.000000); \\ fn_f64(3.000000); \\ fn_bool(true); @@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ , \\pub export fn escapes() [*c]const u8 { - \\ var a: u8 = u8('\''); - \\ var b: u8 = u8('\\'); - \\ var c: u8 = u8('\x07'); - \\ var d: u8 = u8('\x08'); - \\ var e: u8 = u8('\x0c'); - \\ var f: u8 = u8('\n'); - \\ var g: u8 = u8('\r'); - \\ var h: u8 = u8('\t'); - \\ var i: u8 = u8('\x0b'); - \\ var j: u8 = u8('\x00'); - \\ var k: u8 = u8('\"'); + \\ var a: u8 = @as(u8, '\''); + \\ var b: u8 = @as(u8, '\\'); + \\ var c: u8 = @as(u8, '\x07'); + \\ var d: u8 = @as(u8, '\x08'); + \\ var e: u8 = @as(u8, '\x0c'); + \\ var f: u8 = @as(u8, '\n'); + \\ var g: u8 = @as(u8, '\r'); + \\ var h: u8 = @as(u8, '\t'); + \\ var i: u8 = @as(u8, '\x0b'); + \\ var j: u8 = @as(u8, '\x00'); + \\ var k: u8 = @as(u8, '\"'); \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; \\} \\ -- cgit v1.2.3 From 10e6cde083cf9ddd1ae72850d45c25b1258d0d7e Mon Sep 17 00:00:00 2001 From: MCRusher Date: Sat, 23 Nov 2019 22:54:33 -0500 Subject: Added initCapacity and relevant test Added ArrayList.initCapcity() as a way to preallocate a block of memory to reduce future allocations. Added a test "std.ArrayList.initCapacity" that ensures initCapacity adds no elements and increases capacity by at least the requested amount --- lib/std/array_list.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 59fd2a10e5..d7da5f7f8a 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -40,6 +40,14 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { .allocator = allocator, }; } + + /// Initialize with capacity to hold at least num elements. + /// Deinitialize with `deinit` or use `toOwnedSlice`. + pub fn initCapacity(allocator: *Allocator, num: usize) !Self { + var self = Self.init(allocator); + try self.ensureCapacity(num); + return self; + } /// Release all allocated memory. pub fn deinit(self: Self) void { @@ -271,6 +279,15 @@ test "std.ArrayList.init" { testing.expect(list.capacity() == 0); } +test "std.ArrayList.initCapacity" { + var bytes: [1024]u8 = undefined; + const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator; + var list = try ArrayList(i8).initCapacity(allocator, 200); + defer list.deinit(); + testing.expect(list.count() == 0); + testing.expect(list.capacity() >= 200); +} + test "std.ArrayList.basic" { var bytes: [1024]u8 = undefined; const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator; -- cgit v1.2.3 From bdf3680be1b39f4a92370817ef0a7e8a9fdaa373 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 25 Nov 2019 13:51:09 -0500 Subject: zig fmt --- lib/std/array_list.zig | 2 +- lib/std/builtin.zig | 2 ++ lib/std/child_process.zig | 2 +- lib/std/debug/failing_allocator.zig | 4 ++-- lib/std/event/fs.zig | 2 +- lib/std/fifo.zig | 2 +- lib/std/mutex.zig | 4 ++-- lib/std/net.zig | 2 +- lib/std/os.zig | 4 ++-- lib/std/os/bits/linux.zig | 1 - lib/std/os/uefi/protocols/hii.zig | 1 + lib/std/os/uefi/status.zig | 38 +++++++++++++++++++++++++++++++++ lib/std/os/uefi/tables/table_header.zig | 1 + lib/std/os/windows.zig | 5 ++--- lib/std/os/windows/ws2_32.zig | 10 +++------ 15 files changed, 58 insertions(+), 22 deletions(-) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 59fd2a10e5..26342d7833 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -58,7 +58,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return self.items[0..self.len]; } - /// Safely access index i of the list. + /// Safely access index i of the list. pub fn at(self: Self, i: usize) T { return self.toSliceConst()[i]; } diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index af045c5231..689c5cd898 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -144,6 +144,7 @@ pub const TypeInfo = union(enum) { alignment: comptime_int, child: type, is_allowzero: bool, + /// The type of the sentinel is the element type of the pointer, which is /// the value of the `child` field in this struct. However there is no way /// to refer to that type here, so we use `var`. @@ -164,6 +165,7 @@ pub const TypeInfo = union(enum) { pub const Array = struct { len: comptime_int, child: type, + /// The type of the sentinel is the element type of the array, which is /// the value of the `child` field in this struct. However there is no way /// to refer to that type here, so we use `var`. diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 866b3ad67e..36621758b2 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -259,7 +259,7 @@ pub const ChildProcess = struct { } fn handleWaitResult(self: *ChildProcess, status: u32) void { - // TODO https://github.com/ziglang/zig/issues/3190 + // TODO https://github.com/ziglang/zig/issues/3190 var term = self.cleanupAfterWait(status); self.term = term; } diff --git a/lib/std/debug/failing_allocator.zig b/lib/std/debug/failing_allocator.zig index 6afd7c4880..081a29cd97 100644 --- a/lib/std/debug/failing_allocator.zig +++ b/lib/std/debug/failing_allocator.zig @@ -5,10 +5,10 @@ const mem = std.mem; /// memory conditions are handled correctly. /// /// To use this, first initialize it and get an allocator with -/// +/// /// `const failing_allocator = &FailingAllocator.init(, /// ).allocator;` -/// +/// /// Then use `failing_allocator` anywhere you would have used a /// different allocator. pub const FailingAllocator = struct { diff --git a/lib/std/event/fs.zig b/lib/std/event/fs.zig index bc9cc596af..a4b6488344 100644 --- a/lib/std/event/fs.zig +++ b/lib/std/event/fs.zig @@ -1266,7 +1266,7 @@ pub fn Watch(comptime V: type) type { if (ev.mask & os.linux.IN_CLOSE_WRITE == os.linux.IN_CLOSE_WRITE) { const basename_ptr = ptr + @sizeOf(os.linux.inotify_event); // `ev.len` counts all bytes in `ev.name` including terminating null byte. - const basename_with_null = basename_ptr[0 .. ev.len]; + const basename_with_null = basename_ptr[0..ev.len]; const user_value = blk: { const held = self.os_data.table_lock.acquire(); defer held.release(); diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig index 12d1750df3..e078abcb2b 100644 --- a/lib/std/fifo.zig +++ b/lib/std/fifo.zig @@ -148,7 +148,7 @@ pub fn LinearFifo( var start = self.head + offset; if (start >= self.buf.len) { start -= self.buf.len; - return self.buf[start..self.count - offset]; + return self.buf[start .. self.count - offset]; } else { const end = math.min(self.head + self.count, self.buf.len); return self.buf[start..end]; diff --git a/lib/std/mutex.zig b/lib/std/mutex.zig index 706c699a87..669321c0f5 100644 --- a/lib/std/mutex.zig +++ b/lib/std/mutex.zig @@ -74,7 +74,7 @@ else pub fn release(self: Held) void { switch (@atomicRmw(State, &self.mutex.state, .Xchg, .Unlocked, .Release)) { .Locked => {}, - .Sleeping => self.mutex.parker.unpark(@ptrCast(*const u32, &self.mutex.state)), + .Sleeping => self.mutex.parker.unpark(@ptrCast(*const u32, &self.mutex.state)), .Unlocked => unreachable, // unlocking an unlocked mutex else => unreachable, // should never be anything else } @@ -112,7 +112,7 @@ else if (@atomicRmw(State, &self.state, .Xchg, .Sleeping, .Acquire) == .Unlocked) return Held{ .mutex = self }; state = .Sleeping; - self.parker.park(@ptrCast(*const u32, &self.state), @enumToInt(State.Sleeping)); + self.parker.park(@ptrCast(*const u32, &self.state), @enumToInt(State.Sleeping)); } } }; diff --git a/lib/std/net.zig b/lib/std/net.zig index 9a602c0105..7a7b2de026 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -1362,7 +1362,7 @@ pub const StreamServer = struct { pub const Connection = struct { file: fs.File, - address: Address + address: Address, }; /// If this function succeeds, the returned `Connection` is a caller-managed resource. diff --git a/lib/std/os.zig b/lib/std/os.zig index cda65b7ea7..7fcdb7f3ff 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2753,8 +2753,8 @@ pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t { /// Used to convert a slice to a null terminated slice on the stack. /// TODO https://github.com/ziglang/zig/issues/287 -pub fn toPosixPath(file_path: []const u8) ![PATH_MAX-1:0]u8 { - var path_with_null: [PATH_MAX-1:0]u8 = undefined; +pub fn toPosixPath(file_path: []const u8) ![PATH_MAX - 1:0]u8 { + var path_with_null: [PATH_MAX - 1:0]u8 = undefined; // >= rather than > to make room for the null byte if (file_path.len >= PATH_MAX) return error.NameTooLong; mem.copy(u8, &path_with_null, file_path); diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 3cafb8ba0b..118223d03c 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -1124,7 +1124,6 @@ pub const io_uring_params = extern struct { pub const IORING_FEAT_SINGLE_MMAP = 1 << 0; - // io_uring_params.flags /// io_context is polled diff --git a/lib/std/os/uefi/protocols/hii.zig b/lib/std/os/uefi/protocols/hii.zig index 5dd9095d14..55326b25b3 100644 --- a/lib/std/os/uefi/protocols/hii.zig +++ b/lib/std/os/uefi/protocols/hii.zig @@ -26,6 +26,7 @@ pub const HIIPackageHeader = packed struct { /// The header found at the start of each package list. pub const HIIPackageList = extern struct { package_list_guid: Guid, + /// The size of the package list (in bytes), including the header. package_list_length: u32, diff --git a/lib/std/os/uefi/status.zig b/lib/std/os/uefi/status.zig index 7c7f98b450..171f3cb05c 100644 --- a/lib/std/os/uefi/status.zig +++ b/lib/std/os/uefi/status.zig @@ -5,82 +5,120 @@ pub const success: usize = 0; /// The image failed to load. pub const load_error: usize = high_bit | 1; + /// A parameter was incorrect. pub const invalid_parameter: usize = high_bit | 2; + /// The operation is not supported. pub const unsupported: usize = high_bit | 3; + /// The buffer was not the proper size for the request. pub const bad_buffer_size: usize = high_bit | 4; + /// The buffer is not large enough to hold the requested data. The required buffer size is returned in the appropriate parameter when this error occurs. pub const buffer_too_small: usize = high_bit | 5; + /// There is no data pending upon return. pub const not_ready: usize = high_bit | 6; + /// The physical device reported an error while attempting the operation. pub const device_error: usize = high_bit | 7; + /// The device cannot be written to. pub const write_protected: usize = high_bit | 8; + /// A resource has run out. pub const out_of_resources: usize = high_bit | 9; + /// An inconstancy was detected on the file system causing the operating to fail. pub const volume_corrupted: usize = high_bit | 10; + /// There is no more space on the file system. pub const volume_full: usize = high_bit | 11; + /// The device does not contain any medium to perform the operation. pub const no_media: usize = high_bit | 12; + /// The medium in the device has changed since the last access. pub const media_changed: usize = high_bit | 13; + /// The item was not found. pub const not_found: usize = high_bit | 14; + /// Access was denied. pub const access_denied: usize = high_bit | 15; + /// The server was not found or did not respond to the request. pub const no_response: usize = high_bit | 16; + /// A mapping to a device does not exist. pub const no_mapping: usize = high_bit | 17; + /// The timeout time expired. pub const timeout: usize = high_bit | 18; + /// The protocol has not been started. pub const not_started: usize = high_bit | 19; + /// The protocol has already been started. pub const already_started: usize = high_bit | 20; + /// The operation was aborted. pub const aborted: usize = high_bit | 21; + /// An ICMP error occurred during the network operation. pub const icmp_error: usize = high_bit | 22; + /// A TFTP error occurred during the network operation. pub const tftp_error: usize = high_bit | 23; + /// A protocol error occurred during the network operation. pub const protocol_error: usize = high_bit | 24; + /// The function encountered an internal version that was incompatible with a version requested by the caller. pub const incompatible_version: usize = high_bit | 25; + /// The function was not performed due to a security violation. pub const security_violation: usize = high_bit | 26; + /// A CRC error was detected. pub const crc_error: usize = high_bit | 27; + /// Beginning or end of media was reached pub const end_of_media: usize = high_bit | 28; + /// The end of the file was reached. pub const end_of_file: usize = high_bit | 31; + /// The language specified was invalid. pub const invalid_language: usize = high_bit | 32; + /// The security status of the data is unknown or compromised and the data must be updated or replaced to restore a valid security status. pub const compromised_data: usize = high_bit | 33; + /// There is an address conflict address allocation pub const ip_address_conflict: usize = high_bit | 34; + /// A HTTP error occurred during the network operation. pub const http_error: usize = high_bit | 35; /// The string contained one or more characters that the device could not render and were skipped. pub const warn_unknown_glyph: usize = 1; + /// The handle was closed, but the file was not deleted. pub const warn_delete_failure: usize = 2; + /// The handle was closed, but the data to the file was not flushed properly. pub const warn_write_failure: usize = 3; + /// The resulting buffer was too small, and the data was truncated to the buffer size. pub const warn_buffer_too_small: usize = 4; + /// The data has not been updated within the timeframe set by localpolicy for this type of data. pub const warn_stale_data: usize = 5; + /// The resulting buffer contains UEFI-compliant file system. pub const warn_file_system: usize = 6; + /// The operation will be processed across a system reset. pub const warn_reset_required: usize = 7; diff --git a/lib/std/os/uefi/tables/table_header.zig b/lib/std/os/uefi/tables/table_header.zig index 527c7a61b9..d5d4094232 100644 --- a/lib/std/os/uefi/tables/table_header.zig +++ b/lib/std/os/uefi/tables/table_header.zig @@ -1,6 +1,7 @@ pub const TableHeader = extern struct { signature: u64, revision: u32, + /// The size, in bytes, of the entire table including the TableHeader header_size: u32, crc32: u32, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 4bf86bc4fd..5fc18accb8 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -192,7 +192,7 @@ pub const FindFirstFileError = error{ }; pub fn FindFirstFile(dir_path: []const u8, find_file_data: *WIN32_FIND_DATAW) FindFirstFileError!HANDLE { - const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, [_]u16{ '\\', '*'}); + const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, [_]u16{ '\\', '*' }); const handle = kernel32.FindFirstFileW(&dir_path_w, find_file_data); if (handle == INVALID_HANDLE_VALUE) { @@ -932,7 +932,7 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 { // TODO https://github.com/ziglang/zig/issues/2765 var result: [PATH_MAX_WIDE:0]u16 = undefined; - const start_index = if (mem.startsWith(u16, s, [_]u16{'\\', '?'})) 0 else blk: { + const start_index = if (mem.startsWith(u16, s, [_]u16{ '\\', '?' })) 0 else blk: { const prefix = [_]u16{ '\\', '?', '?', '\\' }; mem.copy(u16, result[0..], prefix); break :blk prefix.len; @@ -942,7 +942,6 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 { mem.copy(u16, result[start_index..], s); result[end_index] = 0; return result; - } pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len:0]u16 { diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig index c34077a9dc..0554f09705 100644 --- a/lib/std/os/windows/ws2_32.zig +++ b/lib/std/os/windows/ws2_32.zig @@ -106,12 +106,7 @@ pub const WSAOVERLAPPED = extern struct { hEvent: ?WSAEVENT, }; -pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn ( - dwError: DWORD, - cbTransferred: DWORD, - lpOverlapped: *WSAOVERLAPPED, - dwFlags: DWORD -) void; +pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn (dwError: DWORD, cbTransferred: DWORD, lpOverlapped: *WSAOVERLAPPED, dwFlags: DWORD) void; pub const WSA_INVALID_HANDLE = 6; pub const WSA_NOT_ENOUGH_MEMORY = 8; @@ -209,11 +204,12 @@ pub const WSA_QOS_ESDMODEOBJ = 11029; pub const WSA_QOS_ESHAPERATEOBJ = 11030; pub const WSA_QOS_RESERVED_PETYPE = 11031; - /// no parameters const IOC_VOID = 0x80000000; + /// copy out parameters const IOC_OUT = 0x40000000; + /// copy in parameters const IOC_IN = 0x80000000; -- cgit v1.2.3 From bf3ac6615051143a9ef41180cd74e88de5dd573d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 27 Nov 2019 03:30:39 -0500 Subject: remove type coercion from array values to references * Implements #3768. This is a sweeping breaking change that requires many (trivial) edits to Zig source code. Array values no longer coerced to slices; however one may use `&` to obtain a reference to an array value, which may then be coerced to a slice. * Adds `IrInstruction::dump`, for debugging purposes. It's useful to call to inspect the instruction when debugging Zig IR. * Fixes bugs with result location semantics. See the new behavior test cases, and compile error test cases. * Fixes bugs with `@typeInfo` not properly resolving const values. * Behavior tests are passing but std lib tests are not yet. There is more work to do before merging this branch. --- build.zig | 30 +- lib/std/array_list.zig | 15 +- lib/std/bloom_filter.zig | 6 +- lib/std/build.zig | 57 +-- lib/std/crypto/aes.zig | 4 +- lib/std/crypto/blake2.zig | 4 +- lib/std/crypto/chacha20.zig | 14 +- lib/std/crypto/gimli.zig | 8 +- lib/std/crypto/md5.zig | 2 +- lib/std/crypto/poly1305.zig | 2 +- lib/std/crypto/sha1.zig | 2 +- lib/std/crypto/sha2.zig | 4 +- lib/std/crypto/sha3.zig | 4 +- lib/std/crypto/test.zig | 4 +- lib/std/crypto/x25519.zig | 36 +- lib/std/debug.zig | 2 +- lib/std/elf.zig | 2 +- lib/std/event/loop.zig | 4 +- lib/std/fifo.zig | 10 +- lib/std/fmt.zig | 25 +- lib/std/fs.zig | 6 +- lib/std/fs/get_app_data_dir.zig | 6 +- lib/std/fs/path.zig | 122 +++--- lib/std/hash/cityhash.zig | 2 +- lib/std/hash/murmur.zig | 2 +- lib/std/hash_map.zig | 2 +- lib/std/http/headers.zig | 4 +- lib/std/io.zig | 2 +- lib/std/io/out_stream.zig | 10 +- lib/std/io/test.zig | 8 +- lib/std/mem.zig | 128 +++--- lib/std/meta/trait.zig | 2 +- lib/std/net.zig | 8 +- lib/std/os/test.zig | 2 +- lib/std/packed_int_array.zig | 24 +- lib/std/priority_queue.zig | 2 +- lib/std/process.zig | 16 +- lib/std/rand.zig | 2 +- lib/std/segmented_list.zig | 12 +- lib/std/sort.zig | 86 ++-- lib/std/unicode.zig | 12 +- lib/std/zig/tokenizer.zig | 122 +++--- src-self-hosted/dep_tokenizer.zig | 4 +- src-self-hosted/main.zig | 2 +- src-self-hosted/stage1.zig | 4 +- src/all_types.hpp | 3 + src/ir.cpp | 436 ++++++++------------- test/compare_output.zig | 4 +- test/stage1/behavior/array.zig | 44 +-- test/stage1/behavior/async_fn.zig | 12 +- test/stage1/behavior/await_struct.zig | 2 +- test/stage1/behavior/bugs/1607.zig | 4 +- test/stage1/behavior/bugs/1914.zig | 4 +- test/stage1/behavior/cast.zig | 49 ++- test/stage1/behavior/eval.zig | 6 +- test/stage1/behavior/for.zig | 10 +- test/stage1/behavior/generics.zig | 4 +- test/stage1/behavior/misc.zig | 6 +- test/stage1/behavior/ptrcast.zig | 2 +- test/stage1/behavior/shuffle.zig | 14 +- test/stage1/behavior/slice.zig | 6 +- test/stage1/behavior/struct.zig | 9 +- .../behavior/struct_contains_slice_of_itself.zig | 16 +- test/stage1/behavior/type.zig | 24 +- test/stage1/behavior/union.zig | 2 +- test/stage1/behavior/vector.zig | 54 +-- test/tests.zig | 32 +- 67 files changed, 729 insertions(+), 839 deletions(-) (limited to 'lib/std/array_list.zig') diff --git a/build.zig b/build.zig index fc03296158..707094d36b 100644 --- a/build.zig +++ b/build.zig @@ -20,10 +20,10 @@ pub fn build(b: *Builder) !void { const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe); const langref_out_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, "langref.html" }, + &[_][]const u8{ b.cache_root, "langref.html" }, ) catch unreachable; var docgen_cmd = docgen_exe.run(); - docgen_cmd.addArgs([_][]const u8{ + docgen_cmd.addArgs(&[_][]const u8{ rel_zig_exe, "doc" ++ fs.path.sep_str ++ "langref.html.in", langref_out_path, @@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void { const test_step = b.step("test", "Run all the tests"); // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library - const build_info = try b.exec([_][]const u8{ + const build_info = try b.exec(&[_][]const u8{ b.zig_exe, "BUILD_INFO", }); @@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void { test_stage2.setBuildMode(builtin.Mode.Debug); test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig"); - const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"}); + const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); exe.setBuildMode(mode); @@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void { .source_dir = "lib", .install_dir = .Lib, .install_subdir = "zig", - .exclude_extensions = [_][]const u8{ "test.zig", "README.md" }, + .exclude_extensions = &[_][]const u8{ "test.zig", "README.md" }, }); const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); @@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { } const lib_dir = fs.path.join( b.allocator, - [_][]const u8{ dep.prefix, "lib" }, + &[_][]const u8{ dep.prefix, "lib" }, ) catch unreachable; for (dep.system_libs.toSliceConst()) |lib| { const static_bare_name = if (mem.eql(u8, lib, "curses")) @@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { b.fmt("lib{}.a", lib); const static_lib_name = fs.path.join( b.allocator, - [_][]const u8{ lib_dir, static_bare_name }, + &[_][]const u8{ lib_dir, static_bare_name }, ) catch unreachable; const have_static = fileExists(static_lib_name) catch unreachable; if (have_static) { @@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool { } fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void { - lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{ + lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ cmake_binary_dir, "zig_cpp", b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()), @@ -199,22 +199,22 @@ const LibraryDep = struct { }; fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep { - const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" }); + const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" }); const is_static = mem.startsWith(u8, shared_mode, "static"); const libs_output = if (is_static) - try b.exec([_][]const u8{ + try b.exec(&[_][]const u8{ llvm_config_exe, "--libfiles", "--system-libs", }) else - try b.exec([_][]const u8{ + try b.exec(&[_][]const u8{ llvm_config_exe, "--libs", }); - const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" }); - const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" }); - const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" }); + const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" }); + const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" }); + const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" }); var result = LibraryDep{ .prefix = mem.tokenize(prefix_output, " \r\n").next().?, @@ -341,7 +341,7 @@ fn addCxxKnownPath( objname: []const u8, errtxt: ?[]const u8, ) !void { - const path_padded = try b.exec([_][]const u8{ + const path_padded = try b.exec(&[_][]const u8{ ctx.cxx_compiler, b.fmt("-print-file-name={}", objname), }); diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 26342d7833..6edc472c20 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { /// Deinitialize with `deinit` or use `toOwnedSlice`. pub fn init(allocator: *Allocator) Self { return Self{ - .items = [_]T{}, + .items = &[_]T{}, .len = 0, .allocator = allocator, }; @@ -306,18 +306,14 @@ test "std.ArrayList.basic" { testing.expect(list.pop() == 10); testing.expect(list.len == 9); - list.appendSlice([_]i32{ - 1, - 2, - 3, - }) catch unreachable; + list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable; testing.expect(list.len == 12); testing.expect(list.pop() == 3); testing.expect(list.pop() == 2); testing.expect(list.pop() == 1); testing.expect(list.len == 9); - list.appendSlice([_]i32{}) catch unreachable; + list.appendSlice(&[_]i32{}) catch unreachable; testing.expect(list.len == 9); // can only set on indices < self.len @@ -464,10 +460,7 @@ test "std.ArrayList.insertSlice" { try list.append(2); try list.append(3); try list.append(4); - try list.insertSlice(1, [_]i32{ - 9, - 8, - }); + try list.insertSlice(1, &[_]i32{ 9, 8 }); testing.expect(list.items[0] == 1); testing.expect(list.items[1] == 9); testing.expect(list.items[2] == 8); diff --git a/lib/std/bloom_filter.zig b/lib/std/bloom_filter.zig index 6c4d713076..f12f0d86af 100644 --- a/lib/std/bloom_filter.zig +++ b/lib/std/bloom_filter.zig @@ -62,7 +62,7 @@ pub fn BloomFilter( } pub fn getCell(self: Self, cell: Index) Cell { - return Io.get(self.data, cell, 0); + return Io.get(&self.data, cell, 0); } pub fn incrementCell(self: *Self, cell: Index) void { @@ -70,7 +70,7 @@ pub fn BloomFilter( // skip the 'get' operation Io.set(&self.data, cell, 0, cellMax); } else { - const old = Io.get(self.data, cell, 0); + const old = Io.get(&self.data, cell, 0); if (old != cellMax) { Io.set(&self.data, cell, 0, old + 1); } @@ -120,7 +120,7 @@ pub fn BloomFilter( } else if (newsize > n_items) { var copied: usize = 0; while (copied < r.data.len) : (copied += self.data.len) { - std.mem.copy(u8, r.data[copied .. copied + self.data.len], self.data); + std.mem.copy(u8, r.data[copied .. copied + self.data.len], &self.data); } } return r; diff --git a/lib/std/build.zig b/lib/std/build.zig index 9bac20df4b..fe980aaf89 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -186,7 +186,7 @@ pub const Builder = struct { pub fn resolveInstallPrefix(self: *Builder) void { if (self.dest_dir) |dest_dir| { const install_prefix = self.install_prefix orelse "/usr"; - self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable; + self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable; } else { const install_prefix = self.install_prefix orelse blk: { const p = self.cache_root; @@ -195,8 +195,8 @@ pub const Builder = struct { }; self.install_path = install_prefix; } - self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable; - self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable; + self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable; + self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable; } pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { @@ -803,7 +803,7 @@ pub const Builder = struct { } fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 { - return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable; + return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable; } pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 { @@ -818,7 +818,7 @@ pub const Builder = struct { if (fs.path.isAbsolute(name)) { return name; } - const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) }); + const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) }); return fs.realpathAlloc(self.allocator, full_path) catch continue; } } @@ -827,9 +827,9 @@ pub const Builder = struct { if (fs.path.isAbsolute(name)) { return name; } - var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter}); + var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter}); while (it.next()) |path| { - const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); + const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); return fs.realpathAlloc(self.allocator, full_path) catch continue; } } @@ -839,7 +839,7 @@ pub const Builder = struct { return name; } for (paths) |path| { - const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); + const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); return fs.realpathAlloc(self.allocator, full_path) catch continue; } } @@ -926,12 +926,12 @@ pub const Builder = struct { }; return fs.path.resolve( self.allocator, - [_][]const u8{ base_dir, dest_rel_path }, + &[_][]const u8{ base_dir, dest_rel_path }, ) catch unreachable; } fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg { - const stdout = try self.execAllowFail([_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore); + const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore); var list = ArrayList(PkgConfigPkg).init(self.allocator); var line_it = mem.tokenize(stdout, "\r\n"); while (line_it.next()) |line| { @@ -970,7 +970,7 @@ pub const Builder = struct { test "builder.findProgram compiles" { const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache"); - _ = builder.findProgram([_][]const u8{}, [_][]const u8{}) catch null; + _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null; } /// Deprecated. Use `builtin.Version`. @@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct { }; var code: u8 = undefined; - const stdout = if (self.builder.execAllowFail([_][]const u8{ + const stdout = if (self.builder.execAllowFail(&[_][]const u8{ "pkg-config", pkg_name, "--cflags", @@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct { pub fn getOutputPath(self: *LibExeObjStep) []const u8 { return fs.path.join( self.builder.allocator, - [_][]const u8{ self.output_dir.?, self.out_filename }, + &[_][]const u8{ self.output_dir.?, self.out_filename }, ) catch unreachable; } @@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct { assert(self.kind == Kind.Lib); return fs.path.join( self.builder.allocator, - [_][]const u8{ self.output_dir.?, self.out_lib_filename }, + &[_][]const u8{ self.output_dir.?, self.out_lib_filename }, ) catch unreachable; } @@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct { assert(!self.disable_gen_h); return fs.path.join( self.builder.allocator, - [_][]const u8{ self.output_dir.?, self.out_h_filename }, + &[_][]const u8{ self.output_dir.?, self.out_h_filename }, ) catch unreachable; } @@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct { assert(self.target.isWindows() or self.target.isUefi()); return fs.path.join( self.builder.allocator, - [_][]const u8{ self.output_dir.?, self.out_pdb_filename }, + &[_][]const u8{ self.output_dir.?, self.out_pdb_filename }, ) catch unreachable; } @@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct { const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage); defer self.builder.allocator.free(triplet); - const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" }); + const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" }); errdefer allocator.free(include_path); try self.include_dirs.append(IncludeDir{ .RawPath = include_path }); - const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" }); + const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" }); try self.lib_paths.append(lib_path); - self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" }); + self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" }); }, } } @@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct { if (self.build_options_contents.len() > 0) { const build_options_file = try fs.path.join( builder.allocator, - [_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) }, + &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) }, ); try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst()); try zig_args.append("--pkg-begin"); @@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct { try zig_args.append("--test-cmd"); try zig_args.append(bin_name); if (glibc_dir_arg) |dir| { - const full_dir = try fs.path.join(builder.allocator, [_][]const u8{ + const full_dir = try fs.path.join(builder.allocator, &[_][]const u8{ dir, try self.target.linuxTriple(builder.allocator), }); @@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct { const output_path = mem.trimRight(u8, output_path_nl, "\r\n"); if (self.output_dir) |output_dir| { - const full_dest = try fs.path.join(builder.allocator, [_][]const u8{ + const full_dest = try fs.path.join(builder.allocator, &[_][]const u8{ output_dir, fs.path.basename(output_path), }); @@ -2068,7 +2068,7 @@ pub const RunStep = struct { env_map.set(PATH, search_path) catch unreachable; return; }; - const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path); + const new_path = self.builder.fmt("{}" ++ &[1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path); env_map.set(PATH, new_path) catch unreachable; } @@ -2162,6 +2162,9 @@ const InstallArtifactStep = struct { if (self.artifact.isDynamicLibrary()) { builder.pushInstalledFile(.Lib, artifact.major_only_filename); builder.pushInstalledFile(.Lib, artifact.name_only_filename); + if (self.artifact.target.isWindows()) { + builder.pushInstalledFile(.Lib, artifact.out_lib_filename); + } } if (self.pdb_dir) |pdb_dir| { builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename); @@ -2254,7 +2257,7 @@ pub const InstallDirStep = struct { }; const rel_path = entry.path[full_src_dir.len + 1 ..]; - const dest_path = try fs.path.join(self.builder.allocator, [_][]const u8{ dest_prefix, rel_path }); + const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ dest_prefix, rel_path }); switch (entry.kind) { .Directory => try fs.makePath(self.builder.allocator, dest_path), .File => try self.builder.updateFile(entry.path, dest_path), @@ -2377,7 +2380,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj // sym link for libfoo.so.1 to libfoo.so.1.2.3 const major_only_path = fs.path.join( allocator, - [_][]const u8{ out_dir, filename_major_only }, + &[_][]const u8{ out_dir, filename_major_only }, ) catch unreachable; fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| { warn("Unable to symlink {} -> {}\n", major_only_path, out_basename); @@ -2386,7 +2389,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj // sym link for libfoo.so to libfoo.so.1 const name_only_path = fs.path.join( allocator, - [_][]const u8{ out_dir, filename_name_only }, + &[_][]const u8{ out_dir, filename_name_only }, ) catch unreachable; fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| { warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only); @@ -2399,7 +2402,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 { const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); defer allocator.free(appdata_path); - const path_file = try fs.path.join(allocator, [_][]const u8{ appdata_path, "vcpkg.path.txt" }); + const path_file = try fs.path.join(allocator, &[_][]const u8{ appdata_path, "vcpkg.path.txt" }); defer allocator.free(path_file); const file = fs.File.openRead(path_file) catch return null; diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index ddccd0b1b3..1cc166f943 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type { pub fn init(key: [keysize / 8]u8) Self { var ctx: Self = undefined; - expandKey(key, ctx.enc[0..], ctx.dec[0..]); + expandKey(&key, ctx.enc[0..], ctx.dec[0..]); return ctx; } @@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type { var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]); std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1); - n += xorBytes(dst[n..], src[n..], keystream); + n += xorBytes(dst[n..], src[n..], &keystream); } } }; diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig index d6b1e49724..aa866acbe4 100644 --- a/lib/std/crypto/blake2.zig +++ b/lib/std/crypto/blake2.zig @@ -256,7 +256,7 @@ test "blake2s256 aligned final" { var out: [Blake2s256.digest_length]u8 = undefined; var h = Blake2s256.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } @@ -490,6 +490,6 @@ test "blake2b512 aligned final" { var out: [Blake2b512.digest_length]u8 = undefined; var h = Blake2b512.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index d5d03f2bfa..10d2130659 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" { }; chaCha20IETF(result[0..], input[0..], 1, key, nonce); - testing.expectEqualSlices(u8, expected_result, result); + testing.expectEqualSlices(u8, &expected_result, &result); // Chacha20 is self-reversing. var plaintext: [114]u8 = undefined; chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce); - testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal); + testing.expect(mem.compare(u8, input, &plaintext) == mem.Compare.Equal); } // https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7 @@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" { const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }; chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); - testing.expectEqualSlices(u8, expected_result, result); + testing.expectEqualSlices(u8, &expected_result, &result); } test "crypto.chacha20 test vector 2" { @@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" { const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }; chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); - testing.expectEqualSlices(u8, expected_result, result); + testing.expectEqualSlices(u8, &expected_result, &result); } test "crypto.chacha20 test vector 3" { @@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" { const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 }; chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); - testing.expectEqualSlices(u8, expected_result, result); + testing.expectEqualSlices(u8, &expected_result, &result); } test "crypto.chacha20 test vector 4" { @@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" { const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 }; chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); - testing.expectEqualSlices(u8, expected_result, result); + testing.expectEqualSlices(u8, &expected_result, &result); } test "crypto.chacha20 test vector 5" { @@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" { }; chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); - testing.expectEqualSlices(u8, expected_result, result); + testing.expectEqualSlices(u8, &expected_result, &result); } diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig index 0d18afd705..1d835b231b 100644 --- a/lib/std/crypto/gimli.zig +++ b/lib/std/crypto/gimli.zig @@ -83,7 +83,7 @@ test "permute" { while (i < 12) : (i += 1) { input[i] = i * i * i + i *% 0x9e3779b9; } - testing.expectEqualSlices(u32, input, [_]u32{ + testing.expectEqualSlices(u32, &input, &[_]u32{ 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46, 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566, 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026, @@ -92,7 +92,7 @@ test "permute" { }, }; state.permute(); - testing.expectEqualSlices(u32, state.data, [_]u32{ + testing.expectEqualSlices(u32, &state.data, &[_]u32{ 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68, 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8, 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6, @@ -163,6 +163,6 @@ test "hash" { var msg: [58 / 2]u8 = undefined; try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C"); var md: [32]u8 = undefined; - hash(&md, msg); - htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", md); + hash(&md, &msg); + htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md); } diff --git a/lib/std/crypto/md5.zig b/lib/std/crypto/md5.zig index db6150699d..41ce802dd7 100644 --- a/lib/std/crypto/md5.zig +++ b/lib/std/crypto/md5.zig @@ -276,6 +276,6 @@ test "md5 aligned final" { var out: [Md5.digest_length]u8 = undefined; var h = Md5.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index 78881ba049..2395b1c7aa 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" { var mac: [16]u8 = undefined; Poly1305.create(mac[0..], msg, key); - std.testing.expectEqualSlices(u8, expected_mac, mac); + std.testing.expectEqualSlices(u8, expected_mac, &mac); } diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig index c17ef2daf7..b4d6e5c0cc 100644 --- a/lib/std/crypto/sha1.zig +++ b/lib/std/crypto/sha1.zig @@ -297,6 +297,6 @@ test "sha1 aligned final" { var out: [Sha1.digest_length]u8 = undefined; var h = Sha1.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig index 77698176bd..478cadd03c 100644 --- a/lib/std/crypto/sha2.zig +++ b/lib/std/crypto/sha2.zig @@ -343,7 +343,7 @@ test "sha256 aligned final" { var out: [Sha256.digest_length]u8 = undefined; var h = Sha256.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } @@ -723,6 +723,6 @@ test "sha512 aligned final" { var out: [Sha512.digest_length]u8 = undefined; var h = Sha512.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } diff --git a/lib/std/crypto/sha3.zig b/lib/std/crypto/sha3.zig index d417ef07e2..d7b2fbe256 100644 --- a/lib/std/crypto/sha3.zig +++ b/lib/std/crypto/sha3.zig @@ -229,7 +229,7 @@ test "sha3-256 aligned final" { var out: [Sha3_256.digest_length]u8 = undefined; var h = Sha3_256.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } @@ -300,6 +300,6 @@ test "sha3-512 aligned final" { var out: [Sha3_512.digest_length]u8 = undefined; var h = Sha3_512.init(); - h.update(block); + h.update(&block); h.final(out[0..]); } diff --git a/lib/std/crypto/test.zig b/lib/std/crypto/test.zig index a0ddad6c83..1ff326cf39 100644 --- a/lib/std/crypto/test.zig +++ b/lib/std/crypto/test.zig @@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu var h: [expected.len / 2]u8 = undefined; Hasher.hash(input, h[0..]); - assertEqual(expected, h); + assertEqual(expected, &h); } // Assert `expected` == `input` where `input` is a bytestring. @@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void { r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable; } - testing.expectEqualSlices(u8, expected_bytes, input); + testing.expectEqualSlices(u8, &expected_bytes, input); } diff --git a/lib/std/crypto/x25519.zig b/lib/std/crypto/x25519.zig index 73e0f033f2..16e3f073f8 100644 --- a/lib/std/crypto/x25519.zig +++ b/lib/std/crypto/x25519.zig @@ -63,7 +63,7 @@ pub const X25519 = struct { var pos: isize = 254; while (pos >= 0) : (pos -= 1) { // constant time conditional swap before ladder step - const b = scalarBit(e, @intCast(usize, pos)); + const b = scalarBit(&e, @intCast(usize, pos)); swap ^= b; // xor trick avoids swapping at the end of the loop Fe.cswap(x2, x3, swap); Fe.cswap(z2, z3, swap); @@ -117,7 +117,7 @@ pub const X25519 = struct { pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool { var base_point = [_]u8{9} ++ [_]u8{0} ** 31; - return create(public_key, private_key, base_point); + return create(public_key, private_key, &base_point); } }; @@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" { var pk_calculated: [32]u8 = undefined; try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50"); - std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk)); - std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected)); + std.testing.expect(X25519.createPublicKey(pk_calculated[0..], &sk)); + std.testing.expect(std.mem.eql(u8, &pk_calculated, &pk_expected)); } test "x25519 rfc7748 vector1" { @@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" { var output: [32]u8 = undefined; std.testing.expect(X25519.create(output[0..], secret_key, public_key)); - std.testing.expect(std.mem.eql(u8, output, expected_output)); + std.testing.expect(std.mem.eql(u8, &output, expected_output)); } test "x25519 rfc7748 vector2" { @@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" { var output: [32]u8 = undefined; std.testing.expect(X25519.create(output[0..], secret_key, public_key)); - std.testing.expect(std.mem.eql(u8, output, expected_output)); + std.testing.expect(std.mem.eql(u8, &output, expected_output)); } test "x25519 rfc7748 one iteration" { const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*; - const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79".*; + const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79"; var k: [32]u8 = initial_value; var u: [32]u8 = initial_value; @@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" { var i: usize = 0; while (i < 1) : (i += 1) { var output: [32]u8 = undefined; - std.testing.expect(X25519.create(output[0..], k, u)); + std.testing.expect(X25519.create(output[0..], &k, &u)); std.mem.copy(u8, u[0..], k[0..]); std.mem.copy(u8, k[0..], output[0..]); @@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" { return error.SkipZigTest; } - const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*; - const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51".*; + const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51"; - var k: [32]u8 = initial_value; - var u: [32]u8 = initial_value; + var k: [32]u8 = initial_value.*; + var u: [32]u8 = initial_value.*; var i: usize = 0; while (i < 1000) : (i += 1) { var output: [32]u8 = undefined; - std.testing.expect(X25519.create(output[0..], k, u)); + std.testing.expect(X25519.create(output[0..], &k, &u)); std.mem.copy(u8, u[0..], k[0..]); std.mem.copy(u8, k[0..], output[0..]); @@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" { return error.SkipZigTest; } - const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*; - const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24".*; + const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24"; - var k: [32]u8 = initial_value; - var u: [32]u8 = initial_value; + var k: [32]u8 = initial_value.*; + var u: [32]u8 = initial_value.*; var i: usize = 0; while (i < 1000000) : (i += 1) { var output: [32]u8 = undefined; - std.testing.expect(X25519.create(output[0..], k, u)); + std.testing.expect(X25519.create(output[0..], &k, &u)); std.mem.copy(u8, u[0..], k[0..]); std.mem.copy(u8, k[0..], output[0..]); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 6324c88d86..a6a3e148d4 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1916,7 +1916,7 @@ const LineNumberProgram = struct { return error.InvalidDebugInfo; } else self.include_dirs[file_entry.dir_index]; - const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name }); + const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name }); errdefer self.file_entries.allocator.free(file_name); return LineInfo{ .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0, diff --git a/lib/std/elf.zig b/lib/std/elf.zig index c6a4c0cc0b..dc1638c5cb 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -381,7 +381,7 @@ pub const Elf = struct { var magic: [4]u8 = undefined; try in.readNoEof(magic[0..]); - if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat; + if (!mem.eql(u8, &magic, "\x7fELF")) return error.InvalidFormat; elf.is_64 = switch (try in.readByte()) { 1 => false, diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index f47663a511..03478f65d5 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -237,7 +237,7 @@ pub const Loop = struct { var extra_thread_index: usize = 0; errdefer { // writing 8 bytes to an eventfd cannot fail - os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; + os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable; while (extra_thread_index != 0) { extra_thread_index -= 1; self.extra_threads[extra_thread_index].wait(); @@ -684,7 +684,7 @@ pub const Loop = struct { .linux => { self.posixFsRequest(&self.os_data.fs_end_request); // writing 8 bytes to an eventfd cannot fail - noasync os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; + noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable; return; }, .macosx, .freebsd, .netbsd, .dragonfly => { diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig index e078abcb2b..fdd746dfcc 100644 --- a/lib/std/fifo.zig +++ b/lib/std/fifo.zig @@ -70,7 +70,7 @@ pub fn LinearFifo( pub fn init(allocator: *Allocator) Self { return .{ .allocator = allocator, - .buf = [_]T{}, + .buf = &[_]T{}, .head = 0, .count = 0, }; @@ -143,7 +143,7 @@ pub fn LinearFifo( /// Returns a writable slice from the 'read' end of the fifo fn readableSliceMut(self: SliceSelfArg, offset: usize) []T { - if (offset > self.count) return [_]T{}; + if (offset > self.count) return &[_]T{}; var start = self.head + offset; if (start >= self.buf.len) { @@ -223,7 +223,7 @@ pub fn LinearFifo( /// Returns the first section of writable buffer /// Note that this may be of length 0 pub fn writableSlice(self: SliceSelfArg, offset: usize) []T { - if (offset > self.buf.len) return [_]T{}; + if (offset > self.buf.len) return &[_]T{}; const tail = self.head + offset + self.count; if (tail < self.buf.len) { @@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" { { var i: usize = 0; while (i < 5) : (i += 1) { - try fifo.write([_]u8{try fifo.peekItem(i)}); + try fifo.write(&[_]u8{try fifo.peekItem(i)}); } testing.expectEqual(@as(usize, 10), fifo.readableLength()); testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); @@ -426,7 +426,7 @@ test "LinearFifo" { }; defer fifo.deinit(); - try fifo.write([_]T{ 0, 1, 1, 0, 1 }); + try fifo.write(&[_]T{ 0, 1, 1, 0, 1 }); testing.expectEqual(@as(usize, 5), fifo.readableLength()); { diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index cbb11cba36..4a28daf4b7 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -451,13 +451,18 @@ pub fn formatType( }, }, .Array => |info| { - if (info.child == u8) { - return formatText(value, fmt, options, context, Errors, output); - } - if (value.len == 0) { - return format(context, Errors, output, "[0]{}", @typeName(T.Child)); - } - return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value)); + const Slice = @Type(builtin.TypeInfo{ + .Pointer = .{ + .size = .Slice, + .is_const = true, + .is_volatile = false, + .is_allowzero = false, + .alignment = @alignOf(info.child), + .child = info.child, + .sentinel = null, + }, + }); + return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth); }, .Fn => { return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value)); @@ -872,8 +877,8 @@ pub fn formatBytes( } const buf = switch (radix) { - 1000 => [_]u8{ suffix, 'B' }, - 1024 => [_]u8{ suffix, 'i', 'B' }, + 1000 => &[_]u8{ suffix, 'B' }, + 1024 => &[_]u8{ suffix, 'i', 'B' }, else => unreachable, }; return output(context, buf); @@ -969,7 +974,7 @@ fn formatIntUnsigned( if (leftover_padding == 0) break; } mem.set(u8, buf[0..index], options.fill); - return output(context, buf); + return output(context, &buf); } else { const padded_buf = buf[index - padding ..]; mem.set(u8, padded_buf[0..padding], options.fill); diff --git a/lib/std/fs.zig b/lib/std/fs.zig index f580cf2045..7116d2fd9e 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -60,7 +60,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: tmp_path[dirname.len] = path.sep; while (true) { try crypto.randomBytes(rand_buf[0..]); - b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf); + b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf); if (symLink(existing_path, tmp_path)) { return rename(tmp_path, new_path); @@ -226,7 +226,7 @@ pub const AtomicFile = struct { while (true) { try crypto.randomBytes(rand_buf[0..]); - b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf); + b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], &rand_buf); const file = File.openWriteNoClobberC(@ptrCast([*:0]u8, &tmp_path_buf), mode) catch |err| switch (err) { error.PathAlreadyExists => continue, @@ -290,7 +290,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void { /// have been modified regardless. /// TODO determine if we can remove the allocator requirement from this function pub fn makePath(allocator: *Allocator, full_path: []const u8) !void { - const resolved_path = try path.resolve(allocator, [_][]const u8{full_path}); + const resolved_path = try path.resolve(allocator, &[_][]const u8{full_path}); defer allocator.free(resolved_path); var end_index: usize = resolved_path.len; diff --git a/lib/std/fs/get_app_data_dir.zig b/lib/std/fs/get_app_data_dir.zig index 657971dd90..bbc9c4b7bb 100644 --- a/lib/std/fs/get_app_data_dir.zig +++ b/lib/std/fs/get_app_data_dir.zig @@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD error.OutOfMemory => return error.OutOfMemory, }; defer allocator.free(global_dir); - return fs.path.join(allocator, [_][]const u8{ global_dir, appname }); + return fs.path.join(allocator, &[_][]const u8{ global_dir, appname }); }, os.windows.E_OUTOFMEMORY => return error.OutOfMemory, else => return error.AppDataDirUnavailable, @@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD // TODO look in /etc/passwd return error.AppDataDirUnavailable; }; - return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname }); + return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname }); }, .linux, .freebsd, .netbsd, .dragonfly => { const home_dir = os.getenv("HOME") orelse { // TODO look in /etc/passwd return error.AppDataDirUnavailable; }; - return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname }); + return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname }); }, else => @compileError("Unsupported OS"), } diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig index e2f1b5ac65..c7ebb470c5 100644 --- a/lib/std/fs/path.zig +++ b/lib/std/fs/path.zig @@ -15,7 +15,9 @@ pub const sep_windows = '\\'; pub const sep_posix = '/'; pub const sep = if (builtin.os == .windows) sep_windows else sep_posix; -pub const sep_str = [1]u8{sep}; +pub const sep_str_windows = "\\"; +pub const sep_str_posix = "/"; +pub const sep_str = if (builtin.os == .windows) sep_str_windows else sep_str_posix; pub const delimiter_windows = ';'; pub const delimiter_posix = ':'; @@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void { } test "join" { - testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c"); - testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c"); - testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c"); + testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c"); + testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c"); + testJoinWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c"); - testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c"); - testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c"); + testJoinWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c"); + testJoinWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c"); testJoinWindows( - [_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" }, + &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" }, "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig", ); - testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c"); - testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c"); + testJoinPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c"); + testJoinPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c"); - testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c"); - testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c"); + testJoinPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c"); + testJoinPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c"); testJoinPosix( - [_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" }, + &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" }, "/home/andy/dev/zig/build/lib/zig/std/io.zig", ); - testJoinPosix([_][]const u8{ "a", "/c" }, "a/c"); - testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c"); + testJoinPosix(&[_][]const u8{ "a", "/c" }, "a/c"); + testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c"); } pub fn isAbsolute(path: []const u8) bool { @@ -246,7 +248,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { } const relative_path = WindowsPath{ .kind = WindowsPath.Kind.None, - .disk_designator = [_]u8{}, + .disk_designator = &[_]u8{}, .is_abs = false, }; if (path.len < "//a/b".len) { @@ -255,12 +257,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { inline for ("/\\") |this_sep| { const two_sep = [_]u8{ this_sep, this_sep }; - if (mem.startsWith(u8, path, two_sep)) { + if (mem.startsWith(u8, path, &two_sep)) { if (path[2] == this_sep) { return relative_path; } - var it = mem.tokenize(path, [_]u8{this_sep}); + var it = mem.tokenize(path, &[_]u8{this_sep}); _ = (it.next() orelse return relative_path); _ = (it.next() orelse return relative_path); return WindowsPath{ @@ -322,8 +324,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool { const sep1 = ns1[0]; const sep2 = ns2[0]; - var it1 = mem.tokenize(ns1, [_]u8{sep1}); - var it2 = mem.tokenize(ns2, [_]u8{sep2}); + var it1 = mem.tokenize(ns1, &[_]u8{sep1}); + var it2 = mem.tokenize(ns2, &[_]u8{sep2}); // TODO ASCII is wrong, we actually need full unicode support to compare paths. return asciiEqlIgnoreCase(it1.next().?, it2.next().?); @@ -343,8 +345,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8 const sep1 = p1[0]; const sep2 = p2[0]; - var it1 = mem.tokenize(p1, [_]u8{sep1}); - var it2 = mem.tokenize(p2, [_]u8{sep2}); + var it1 = mem.tokenize(p1, &[_]u8{sep1}); + var it2 = mem.tokenize(p2, &[_]u8{sep2}); // TODO ASCII is wrong, we actually need full unicode support to compare paths. return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?); @@ -637,10 +639,10 @@ test "resolve" { if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) { cwd[0] = asciiUpper(cwd[0]); } - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd)); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{"."}), cwd)); } else { - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd)); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd)); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "a/b/c/", "../../.." }), cwd)); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"."}), cwd)); } } @@ -653,8 +655,8 @@ test "resolveWindows" { const cwd = try process.getCwdAlloc(debug.global_allocator); const parsed_cwd = windowsParsePath(cwd); { - const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" }); - const expected = try join(debug.global_allocator, [_][]const u8{ + const result = testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" }); + const expected = try join(debug.global_allocator, &[_][]const u8{ parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig", }); @@ -664,8 +666,8 @@ test "resolveWindows" { testing.expect(mem.eql(u8, result, expected)); } { - const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" }); - const expected = try join(debug.global_allocator, [_][]const u8{ + const result = testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" }); + const expected = try join(debug.global_allocator, &[_][]const u8{ cwd, "usr\\local\\lib\\zig", }); @@ -676,32 +678,32 @@ test "resolveWindows" { } } - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//" }), "C:\\")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir")); - testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//" }), "C:\\")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//dir" }), "C:\\dir")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir")); + testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js")); } test "resolvePosix" { - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b/c", "..", "../" }), "/a")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c")); - - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "/../", "file/" }), "/file")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute")); - testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c" }), "/a/b/c")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b/c", "..", "../" }), "/a")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/", "..", ".." }), "/")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"/a/b/c/"}), "/a/b/c")); + + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "../", "file/" }), "/var/file")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "/../", "file/" }), "/file")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute")); + testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js")); } fn testResolveWindows(paths: []const []const u8) []u8 { @@ -856,12 +858,12 @@ pub fn basename(path: []const u8) []const u8 { pub fn basenamePosix(path: []const u8) []const u8 { if (path.len == 0) - return [_]u8{}; + return &[_]u8{}; var end_index: usize = path.len - 1; while (path[end_index] == '/') { if (end_index == 0) - return [_]u8{}; + return &[_]u8{}; end_index -= 1; } var start_index: usize = end_index; @@ -877,19 +879,19 @@ pub fn basenamePosix(path: []const u8) []const u8 { pub fn basenameWindows(path: []const u8) []const u8 { if (path.len == 0) - return [_]u8{}; + return &[_]u8{}; var end_index: usize = path.len - 1; while (true) { const byte = path[end_index]; if (byte == '/' or byte == '\\') { if (end_index == 0) - return [_]u8{}; + return &[_]u8{}; end_index -= 1; continue; } if (byte == ':' and end_index == 1) { - return [_]u8{}; + return &[_]u8{}; } break; } @@ -971,11 +973,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { } pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { - const resolved_from = try resolveWindows(allocator, [_][]const u8{from}); + const resolved_from = try resolveWindows(allocator, &[_][]const u8{from}); defer allocator.free(resolved_from); var clean_up_resolved_to = true; - const resolved_to = try resolveWindows(allocator, [_][]const u8{to}); + const resolved_to = try resolveWindows(allocator, &[_][]const u8{to}); defer if (clean_up_resolved_to) allocator.free(resolved_to); const parsed_from = windowsParsePath(resolved_from); @@ -1044,10 +1046,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) } pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { - const resolved_from = try resolvePosix(allocator, [_][]const u8{from}); + const resolved_from = try resolvePosix(allocator, &[_][]const u8{from}); defer allocator.free(resolved_from); - const resolved_to = try resolvePosix(allocator, [_][]const u8{to}); + const resolved_to = try resolvePosix(allocator, &[_][]const u8{to}); defer allocator.free(resolved_to); var from_it = mem.tokenize(resolved_from, "/"); diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index d31ee17105..5038c3758e 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); } - return @truncate(u32, hash_fn(hashes, 0)); + return @truncate(u32, hash_fn(&hashes, 0)); } fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 { diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index f70190d311..d3379a81f7 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); } - return @truncate(u32, hash_fn(hashes, 0)); + return @truncate(u32, hash_fn(&hashes, 0)); } test "murmur2_32" { diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 8b61531cf2..f08ec4b59e 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 pub fn init(allocator: *Allocator) Self { return Self{ - .entries = [_]Entry{}, + .entries = &[_]Entry{}, .allocator = allocator, .size = 0, .max_distance_from_start_index = 0, diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index a860186e47..1d573aebc0 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -514,8 +514,8 @@ test "Headers.getIndices" { try h.append("set-cookie", "y=2", null); testing.expect(null == h.getIndices("not-present")); - testing.expectEqualSlices(usize, [_]usize{0}, h.getIndices("foo").?.toSliceConst()); - testing.expectEqualSlices(usize, [_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst()); + testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst()); + testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst()); } test "Headers.get" { diff --git a/lib/std/io.zig b/lib/std/io.zig index 124d3cf253..09e428984c 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -1107,7 +1107,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v); } - try self.out_stream.write(buffer); + try self.out_stream.write(&buffer); } /// Serializes the passed value into the stream diff --git a/lib/std/io/out_stream.zig b/lib/std/io/out_stream.zig index c0cd6e48a1..77698b333c 100644 --- a/lib/std/io/out_stream.zig +++ b/lib/std/io/out_stream.zig @@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type { pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void { var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntNative(T, &bytes, value); - return self.writeFn(self, bytes); + return self.writeFn(self, &bytes); } /// Write a foreign-endian integer. pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void { var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntForeign(T, &bytes, value); - return self.writeFn(self, bytes); + return self.writeFn(self, &bytes); } pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void { var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntLittle(T, &bytes, value); - return self.writeFn(self, bytes); + return self.writeFn(self, &bytes); } pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void { var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntBig(T, &bytes, value); - return self.writeFn(self, bytes); + return self.writeFn(self, &bytes); } pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void { var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeInt(T, &bytes, value, endian); - return self.writeFn(self, bytes); + return self.writeFn(self, &bytes); } }; } diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index d2374f0a3f..c7471fd315 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -55,7 +55,7 @@ test "write a file, read it, then delete it" { defer allocator.free(contents); expect(mem.eql(u8, contents[0.."begin".len], "begin")); - expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data)); + expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data)); expect(mem.eql(u8, contents[contents.len - "end".len ..], "end")); } try fs.deleteFile(tmp_file_name); @@ -77,7 +77,7 @@ test "BufferOutStream" { test "SliceInStream" { const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 }; - var ss = io.SliceInStream.init(bytes); + var ss = io.SliceInStream.init(&bytes); var dest: [4]u8 = undefined; @@ -95,7 +95,7 @@ test "SliceInStream" { test "PeekStream" { const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; - var ss = io.SliceInStream.init(bytes); + var ss = io.SliceInStream.init(&bytes); var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream); var dest: [4]u8 = undefined; @@ -614,7 +614,7 @@ test "File seek ops" { fs.deleteFile(tmp_file_name) catch {}; } - try file.write([_]u8{0x55} ** 8192); + try file.write(&([_]u8{0x55} ** 8192)); // Seek to the end try file.seekFromEnd(0); diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 412bf9b649..cba1f9f177 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -624,23 +624,23 @@ test "comptime read/write int" { } test "readIntBig and readIntLittle" { - testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0); - testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0); + testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0); + testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0); - testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32); - testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12); + testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32); + testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12); - testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234); - testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412); + testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234); + testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412); - testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); - testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); + testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); + testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); - testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1); - testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2); + testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1); + testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2); - testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3); - testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4); + testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3); + testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4); } /// Writes an integer to memory, storing it in twos-complement. @@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" { var buf9: [9]u8 = undefined; writeIntBig(u0, &buf0, 0x0); - testing.expect(eql(u8, buf0[0..], [_]u8{})); + testing.expect(eql(u8, buf0[0..], &[_]u8{})); writeIntLittle(u0, &buf0, 0x0); - testing.expect(eql(u8, buf0[0..], [_]u8{})); + testing.expect(eql(u8, buf0[0..], &[_]u8{})); writeIntBig(u8, &buf1, 0x12); - testing.expect(eql(u8, buf1[0..], [_]u8{0x12})); + testing.expect(eql(u8, buf1[0..], &[_]u8{0x12})); writeIntLittle(u8, &buf1, 0x34); - testing.expect(eql(u8, buf1[0..], [_]u8{0x34})); + testing.expect(eql(u8, buf1[0..], &[_]u8{0x34})); writeIntBig(u16, &buf2, 0x1234); - testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 })); + testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 })); writeIntLittle(u16, &buf2, 0x5678); - testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 })); + testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 })); writeIntBig(u72, &buf9, 0x123456789abcdef024); - testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); + testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); writeIntLittle(u72, &buf9, 0xfedcba9876543210ec); - testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); + testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); writeIntBig(i8, &buf1, -1); - testing.expect(eql(u8, buf1[0..], [_]u8{0xff})); + testing.expect(eql(u8, buf1[0..], &[_]u8{0xff})); writeIntLittle(i8, &buf1, -2); - testing.expect(eql(u8, buf1[0..], [_]u8{0xfe})); + testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe})); writeIntBig(i16, &buf2, -3); - testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd })); + testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd })); writeIntLittle(i16, &buf2, -4); - testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff })); + testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff })); } /// Returns an iterator that iterates over the slices of `buffer` that are not @@ -1004,9 +1004,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons test "mem.join" { var buf: [1024]u8 = undefined; const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; - testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c")); - testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a")); - testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c")); + testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c")); + testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a")); + testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c")); } /// Copies each T from slices into a new slice that exactly holds all the elements. @@ -1037,13 +1037,13 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T test "concat" { var buf: [1024]u8 = undefined; const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; - testing.expect(eql(u8, try concat(a, u8, [_][]const u8{ "abc", "def", "ghi" }), "abcdefghi")); - testing.expect(eql(u32, try concat(a, u32, [_][]const u32{ - [_]u32{ 0, 1 }, - [_]u32{ 2, 3, 4 }, - [_]u32{}, - [_]u32{5}, - }), [_]u32{ 0, 1, 2, 3, 4, 5 })); + testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi")); + testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{ + &[_]u32{ 0, 1 }, + &[_]u32{ 2, 3, 4 }, + &[_]u32{}, + &[_]u32{5}, + }), &[_]u32{ 0, 1, 2, 3, 4, 5 })); } test "testStringEquality" { @@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void { var bytes: [8]u8 = undefined; writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, })); writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, })); writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x12, 0x34, 0x56, @@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void { })); writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x12, 0x34, 0x56, @@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void { })); writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x00, 0x00, 0x00, @@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void { })); writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x12, 0x34, 0x56, @@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void { })); writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x00, 0x00, 0x00, @@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void { })); writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little); - testing.expect(eql(u8, bytes, [_]u8{ + testing.expect(eql(u8, &bytes, &[_]u8{ 0x34, 0x12, 0x00, @@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void { } test "reverse" { - var arr = [_]i32{ - 5, - 3, - 1, - 2, - 4, - }; + var arr = [_]i32{ 5, 3, 1, 2, 4 }; reverse(i32, arr[0..]); - testing.expect(eql(i32, arr, [_]i32{ - 4, - 2, - 1, - 3, - 5, - })); + testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 })); } /// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1) @@ -1262,22 +1250,10 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void { } test "rotate" { - var arr = [_]i32{ - 5, - 3, - 1, - 2, - 4, - }; + var arr = [_]i32{ 5, 3, 1, 2, 4 }; rotate(i32, arr[0..], 2); - testing.expect(eql(i32, arr, [_]i32{ - 1, - 2, - 4, - 5, - 3, - })); + testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 })); } /// Converts a little-endian integer to host endianness. @@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { test "toBytes" { var my_bytes = toBytes(@as(u32, 0x12345678)); switch (builtin.endian) { - builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")), - builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")), + builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), + builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), } my_bytes[0] = '\x99'; switch (builtin.endian) { - builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x99\x34\x56\x78")), - builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x99\x56\x34\x12")), + builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), + builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), } } @@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA test "subArrayPtr" { const a1: [6]u8 = "abcdef".*; const sub1 = subArrayPtr(&a1, 2, 3); - testing.expect(eql(u8, sub1.*, "cde")); + testing.expect(eql(u8, sub1, "cde")); var a2: [6]u8 = "abcdef".*; var sub2 = subArrayPtr(&a2, 2, 3); testing.expect(eql(u8, sub2, "cde")); sub2[1] = 'X'; - testing.expect(eql(u8, a2, "abcXef")); + testing.expect(eql(u8, &a2, "abcXef")); } /// Round an address up to the nearest aligned address diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index 2388acbeb6..5da6e464b6 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" { } }; - const isVector = multiTrait([_]TraitFn{ + const isVector = multiTrait(&[_]TraitFn{ hasFn("add"), hasField("x"), hasField("y"), diff --git a/lib/std/net.zig b/lib/std/net.zig index 7a7b2de026..7502f1e262 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -291,7 +291,7 @@ pub const Address = extern union { }, os.AF_INET6 => { const port = mem.bigToNative(u16, self.in6.port); - if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { + if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { try std.fmt.format( context, Errors, @@ -339,7 +339,7 @@ pub const Address = extern union { unreachable; } - try std.fmt.format(context, Errors, output, "{}", self.un.path); + try std.fmt.format(context, Errors, output, "{}", &self.un.path); }, else => unreachable, } @@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch( } const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, ".")) - [_]u8{} + &[_]u8{} else rc.search.toSliceConst(); @@ -959,7 +959,7 @@ fn linuxLookupNameFromDns( for (afrrs) |afrr| { if (family != afrr.af) { - const len = os.res_mkquery(0, name, 1, afrr.rr, [_]u8{}, null, &qbuf[nq]); + const len = os.res_mkquery(0, name, 1, afrr.rr, &[_]u8{}, null, &qbuf[nq]); qp[nq] = qbuf[nq][0..len]; nq += 1; } diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 778a39eb3c..8fff83d8c7 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -137,7 +137,7 @@ test "getrandom" { try os.getrandom(&buf_b); // If this test fails the chance is significantly higher that there is a bug than // that two sets of 50 bytes were equal. - expect(!mem.eql(u8, buf_a, buf_b)); + expect(!mem.eql(u8, &buf_a, &buf_b)); } test "getcwd" { diff --git a/lib/std/packed_int_array.zig b/lib/std/packed_int_array.zig index 57660f23d9..bc29e985b5 100644 --- a/lib/std/packed_int_array.zig +++ b/lib/std/packed_int_array.zig @@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian, ///Return the Int stored at index pub fn get(self: Self, index: usize) Int { debug.assert(index < int_count); - return Io.get(self.bytes, index, 0); + return Io.get(&self.bytes, index, 0); } ///Copy int into the array at index @@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" { test "PackedInt(Array/Slice)Endian" { { const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8); - var packed_array_be = PackedArrayBe.init([_]u4{ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - }); + var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 }); testing.expect(packed_array_be.bytes[0] == 0b00000001); testing.expect(packed_array_be.bytes[1] == 0b00100011); @@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" { { const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8); - var packed_array_be = PackedArrayBe.init([_]u11{ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - }); + var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 }); testing.expect(packed_array_be.bytes[0] == 0b00000000); testing.expect(packed_array_be.bytes[1] == 0b00000000); testing.expect(packed_array_be.bytes[2] == 0b00000100); diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig index bf54f6937f..3351ac994b 100644 --- a/lib/std/priority_queue.zig +++ b/lib/std/priority_queue.zig @@ -22,7 +22,7 @@ pub fn PriorityQueue(comptime T: type) type { /// `fn lessThan(a: T, b: T) bool { return a < b; }` pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self { return Self{ - .items = [_]T{}, + .items = &[_]T{}, .len = 0, .allocator = allocator, .compareFn = compareFn, diff --git a/lib/std/process.zig b/lib/std/process.zig index e432be213f..0ce3cabc19 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void { } test "windows arg parsing" { - testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" }); - testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" }); - testWindowsCmdLine("a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" }); - testWindowsCmdLine("a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" }); - testWindowsCmdLine("a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" }); - testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" }); - - testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{ + testWindowsCmdLine("a b\tc d", &[_][]const u8{ "a", "b", "c", "d" }); + testWindowsCmdLine("\"abc\" d e", &[_][]const u8{ "abc", "d", "e" }); + testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); + testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" }); + testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" }); + testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" }); + + testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{ ".\\..\\zig-cache\\build", "bin\\zig.exe", ".\\..", diff --git a/lib/std/rand.zig b/lib/std/rand.zig index 1fea0526ed..f9fa4a2d66 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -54,7 +54,7 @@ pub const Random = struct { // use LE instead of native endian for better portability maybe? // TODO: endian portability is pointless if the underlying prng isn't endian portable. // TODO: document the endian portability of this library. - const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, rand_bytes); + const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes); const unsigned_result = @truncate(UnsignedT, byte_aligned_result); return @bitCast(T, unsigned_result); } diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig index e74b17dd5c..8c5ded3647 100644 --- a/lib/std/segmented_list.zig +++ b/lib/std/segmented_list.zig @@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type .allocator = allocator, .len = 0, .prealloc_segment = undefined, - .dynamic_segments = [_][*]T{}, + .dynamic_segments = &[_][*]T{}, }; } @@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type const len = @intCast(ShelfIndex, self.dynamic_segments.len); self.freeShelves(len, 0); self.allocator.free(self.dynamic_segments); - self.dynamic_segments = [_][*]T{}; + self.dynamic_segments = &[_][*]T{}; return; } @@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void { testing.expect(list.pop().? == 100); testing.expect(list.len == 99); - try list.pushMany([_]i32{ - 1, - 2, - 3, - }); + try list.pushMany(&[_]i32{ 1, 2, 3 }); testing.expect(list.len == 102); testing.expect(list.pop().? == 3); testing.expect(list.pop().? == 2); testing.expect(list.pop().? == 1); testing.expect(list.len == 99); - try list.pushMany([_]i32{}); + try list.pushMany(&[_]i32{}); testing.expect(list.len == 99); var i: i32 = 99; diff --git a/lib/std/sort.zig b/lib/std/sort.zig index 790fd46756..f8b8a39134 100644 --- a/lib/std/sort.zig +++ b/lib/std/sort.zig @@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool { test "std.sort" { const u8cases = [_][]const []const u8{ - [_][]const u8{ + &[_][]const u8{ "", "", }, - [_][]const u8{ + &[_][]const u8{ "a", "a", }, - [_][]const u8{ + &[_][]const u8{ "az", "az", }, - [_][]const u8{ + &[_][]const u8{ "za", "az", }, - [_][]const u8{ + &[_][]const u8{ "asdf", "adfs", }, - [_][]const u8{ + &[_][]const u8{ "one", "eno", }, @@ -1078,29 +1078,29 @@ test "std.sort" { } const i32cases = [_][]const []const i32{ - [_][]const i32{ - [_]i32{}, - [_]i32{}, + &[_][]const i32{ + &[_]i32{}, + &[_]i32{}, }, - [_][]const i32{ - [_]i32{1}, - [_]i32{1}, + &[_][]const i32{ + &[_]i32{1}, + &[_]i32{1}, }, - [_][]const i32{ - [_]i32{ 0, 1 }, - [_]i32{ 0, 1 }, + &[_][]const i32{ + &[_]i32{ 0, 1 }, + &[_]i32{ 0, 1 }, }, - [_][]const i32{ - [_]i32{ 1, 0 }, - [_]i32{ 0, 1 }, + &[_][]const i32{ + &[_]i32{ 1, 0 }, + &[_]i32{ 0, 1 }, }, - [_][]const i32{ - [_]i32{ 1, -1, 0 }, - [_]i32{ -1, 0, 1 }, + &[_][]const i32{ + &[_]i32{ 1, -1, 0 }, + &[_]i32{ -1, 0, 1 }, }, - [_][]const i32{ - [_]i32{ 2, 1, 3 }, - [_]i32{ 1, 2, 3 }, + &[_][]const i32{ + &[_]i32{ 2, 1, 3 }, + &[_]i32{ 1, 2, 3 }, }, }; @@ -1115,29 +1115,29 @@ test "std.sort" { test "std.sort descending" { const rev_cases = [_][]const []const i32{ - [_][]const i32{ - [_]i32{}, - [_]i32{}, + &[_][]const i32{ + &[_]i32{}, + &[_]i32{}, }, - [_][]const i32{ - [_]i32{1}, - [_]i32{1}, + &[_][]const i32{ + &[_]i32{1}, + &[_]i32{1}, }, - [_][]const i32{ - [_]i32{ 0, 1 }, - [_]i32{ 1, 0 }, + &[_][]const i32{ + &[_]i32{ 0, 1 }, + &[_]i32{ 1, 0 }, }, - [_][]const i32{ - [_]i32{ 1, 0 }, - [_]i32{ 1, 0 }, + &[_][]const i32{ + &[_]i32{ 1, 0 }, + &[_]i32{ 1, 0 }, }, - [_][]const i32{ - [_]i32{ 1, -1, 0 }, - [_]i32{ 1, 0, -1 }, + &[_][]const i32{ + &[_]i32{ 1, -1, 0 }, + &[_]i32{ 1, 0, -1 }, }, - [_][]const i32{ - [_]i32{ 2, 1, 3 }, - [_]i32{ 3, 2, 1 }, + &[_][]const i32{ + &[_]i32{ 2, 1, 3 }, + &[_]i32{ 3, 2, 1 }, }, }; @@ -1154,7 +1154,7 @@ test "another sort case" { var arr = [_]i32{ 5, 3, 1, 2, 4 }; sort(i32, arr[0..], asc(i32)); - testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 })); + testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 })); } test "sort fuzz testing" { diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 726b84f125..4af1b63a69 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -499,14 +499,14 @@ test "utf16leToUtf8" { { mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A'); mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a'); - const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); + const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le); testing.expect(mem.eql(u8, utf8, "Aa")); } { mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80); mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff); - const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); + const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le); testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); } @@ -514,7 +514,7 @@ test "utf16leToUtf8" { // the values just outside the surrogate half range mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff); mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000); - const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); + const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le); testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); } @@ -522,7 +522,7 @@ test "utf16leToUtf8" { // smallest surrogate pair mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800); mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00); - const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); + const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le); testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); } @@ -530,14 +530,14 @@ test "utf16leToUtf8" { // largest surrogate pair mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff); mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff); - const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); + const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le); testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); } { mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff); mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00); - const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); + const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le); testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); } } diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig index 0b2aea4cf6..e7d2b41784 100644 --- a/lib/std/zig/tokenizer.zig +++ b/lib/std/zig/tokenizer.zig @@ -1313,14 +1313,14 @@ pub const Tokenizer = struct { }; test "tokenizer" { - testTokenize("test", [_]Token.Id{Token.Id.Keyword_test}); + testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test}); } test "tokenizer - unknown length pointer and then c pointer" { testTokenize( \\[*]u8 \\[*c]u8 - , [_]Token.Id{ + , &[_]Token.Id{ Token.Id.LBracket, Token.Id.Asterisk, Token.Id.RBracket, @@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" { test "tokenizer - char literal with hex escape" { testTokenize( \\'\x1b' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); testTokenize( \\'\x1' - , [_]Token.Id{ .Invalid, .Invalid }); + , &[_]Token.Id{ .Invalid, .Invalid }); } test "tokenizer - char literal with unicode escapes" { // Valid unicode escapes testTokenize( \\'\u{3}' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); testTokenize( \\'\u{01}' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); testTokenize( \\'\u{2a}' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); testTokenize( \\'\u{3f9}' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); testTokenize( \\'\u{6E09aBc1523}' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); testTokenize( \\"\u{440}" - , [_]Token.Id{.StringLiteral}); + , &[_]Token.Id{.StringLiteral}); // Invalid unicode escapes testTokenize( \\'\u' - , [_]Token.Id{.Invalid}); + , &[_]Token.Id{.Invalid}); testTokenize( \\'\u{{' - , [_]Token.Id{ .Invalid, .Invalid }); + , &[_]Token.Id{ .Invalid, .Invalid }); testTokenize( \\'\u{}' - , [_]Token.Id{ .Invalid, .Invalid }); + , &[_]Token.Id{ .Invalid, .Invalid }); testTokenize( \\'\u{s}' - , [_]Token.Id{ .Invalid, .Invalid }); + , &[_]Token.Id{ .Invalid, .Invalid }); testTokenize( \\'\u{2z}' - , [_]Token.Id{ .Invalid, .Invalid }); + , &[_]Token.Id{ .Invalid, .Invalid }); testTokenize( \\'\u{4a' - , [_]Token.Id{.Invalid}); + , &[_]Token.Id{.Invalid}); // Test old-style unicode literals testTokenize( \\'\u0333' - , [_]Token.Id{ .Invalid, .Invalid }); + , &[_]Token.Id{ .Invalid, .Invalid }); testTokenize( \\'\U0333' - , [_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid }); + , &[_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid }); } test "tokenizer - char literal with unicode code point" { testTokenize( \\'💩' - , [_]Token.Id{.CharLiteral}); + , &[_]Token.Id{.CharLiteral}); } test "tokenizer - float literal e exponent" { - testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{ + testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{ Token.Id.Identifier, Token.Id.Equal, Token.Id.FloatLiteral, @@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" { } test "tokenizer - float literal p exponent" { - testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{ + testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{ Token.Id.Identifier, Token.Id.Equal, Token.Id.FloatLiteral, @@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" { } test "tokenizer - chars" { - testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral}); + testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral}); } test "tokenizer - invalid token characters" { - testTokenize("#", [_]Token.Id{Token.Id.Invalid}); - testTokenize("`", [_]Token.Id{Token.Id.Invalid}); - testTokenize("'c", [_]Token.Id{Token.Id.Invalid}); - testTokenize("'", [_]Token.Id{Token.Id.Invalid}); - testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid }); + testTokenize("#", &[_]Token.Id{Token.Id.Invalid}); + testTokenize("`", &[_]Token.Id{Token.Id.Invalid}); + testTokenize("'c", &[_]Token.Id{Token.Id.Invalid}); + testTokenize("'", &[_]Token.Id{Token.Id.Invalid}); + testTokenize("''", &[_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid }); } test "tokenizer - invalid literal/comment characters" { - testTokenize("\"\x00\"", [_]Token.Id{ + testTokenize("\"\x00\"", &[_]Token.Id{ Token.Id.StringLiteral, Token.Id.Invalid, }); - testTokenize("//\x00", [_]Token.Id{ + testTokenize("//\x00", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\x1f", [_]Token.Id{ + testTokenize("//\x1f", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\x7f", [_]Token.Id{ + testTokenize("//\x7f", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); } test "tokenizer - utf8" { - testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment}); - testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment}); + testTokenize("//\xc2\x80", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{Token.Id.LineComment}); } test "tokenizer - invalid utf8" { - testTokenize("//\x80", [_]Token.Id{ + testTokenize("//\x80", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xbf", [_]Token.Id{ + testTokenize("//\xbf", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xf8", [_]Token.Id{ + testTokenize("//\xf8", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xff", [_]Token.Id{ + testTokenize("//\xff", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xc2\xc0", [_]Token.Id{ + testTokenize("//\xc2\xc0", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xe0", [_]Token.Id{ + testTokenize("//\xe0", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xf0", [_]Token.Id{ + testTokenize("//\xf0", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{ + testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); @@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" { test "tokenizer - illegal unicode codepoints" { // unicode newline characters.U+0085, U+2028, U+2029 - testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment}); - testTokenize("//\xc2\x85", [_]Token.Id{ + testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("//\xc2\x85", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment}); - testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment}); - testTokenize("//\xe2\x80\xa8", [_]Token.Id{ + testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("//\xe2\x80\xa8", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xe2\x80\xa9", [_]Token.Id{ + testTokenize("//\xe2\x80\xa9", &[_]Token.Id{ Token.Id.LineComment, Token.Id.Invalid, }); - testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment}); + testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment}); } test "tokenizer - string identifier and builtin fns" { testTokenize( \\const @"if" = @import("std"); - , [_]Token.Id{ + , &[_]Token.Id{ Token.Id.Keyword_const, Token.Id.Identifier, Token.Id.Equal, @@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" { } test "tokenizer - pipe and then invalid" { - testTokenize("||=", [_]Token.Id{ + testTokenize("||=", &[_]Token.Id{ Token.Id.PipePipe, Token.Id.Equal, }); } test "tokenizer - line comment and doc comment" { - testTokenize("//", [_]Token.Id{Token.Id.LineComment}); - testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment}); - testTokenize("// /", [_]Token.Id{Token.Id.LineComment}); - testTokenize("/// a", [_]Token.Id{Token.Id.DocComment}); - testTokenize("///", [_]Token.Id{Token.Id.DocComment}); - testTokenize("////", [_]Token.Id{Token.Id.LineComment}); - testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment}); - testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment}); + testTokenize("//", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("// a / b", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("// /", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("/// a", &[_]Token.Id{Token.Id.DocComment}); + testTokenize("///", &[_]Token.Id{Token.Id.DocComment}); + testTokenize("////", &[_]Token.Id{Token.Id.LineComment}); + testTokenize("//!", &[_]Token.Id{Token.Id.ContainerDocComment}); + testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment}); } test "tokenizer - line comment followed by identifier" { @@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" { \\ Unexpected, \\ // another \\ Another, - , [_]Token.Id{ + , &[_]Token.Id{ Token.Id.Identifier, Token.Id.Comma, Token.Id.LineComment, @@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" { } test "tokenizer - UTF-8 BOM is recognized and skipped" { - testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{ + testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{ Token.Id.Identifier, Token.Id.Semicolon, }); } test "correctly parse pointer assignment" { - testTokenize("b.*=3;\n", [_]Token.Id{ + testTokenize("b.*=3;\n", &[_]Token.Id{ Token.Id.Identifier, Token.Id.PeriodAsterisk, Token.Id.Equal, diff --git a/src-self-hosted/dep_tokenizer.zig b/src-self-hosted/dep_tokenizer.zig index 1a6d54f639..9509aab702 100644 --- a/src-self-hosted/dep_tokenizer.zig +++ b/src-self-hosted/dep_tokenizer.zig @@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void { fn printCharValues(out: var, bytes: []const u8) !void { for (bytes) |b| { - try out.write([_]u8{printable_char_tab[b]}); + try out.write(&[_]u8{printable_char_tab[b]}); } } @@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void { std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {}; } else { try out.write("'"); - try out.write([_]u8{printable_char_tab[char]}); + try out.write(&[_]u8{printable_char_tab[char]}); try out.write("'"); } } diff --git a/src-self-hosted/main.zig b/src-self-hosted/main.zig index bf3fb4dea5..49b378e8fc 100644 --- a/src-self-hosted/main.zig +++ b/src-self-hosted/main.zig @@ -521,7 +521,7 @@ pub const usage_fmt = pub const args_fmt_spec = [_]Flag{ Flag.Bool("--help"), Flag.Bool("--check"), - Flag.Option("--color", [_][]const u8{ + Flag.Option("--color", &[_][]const u8{ "auto", "off", "on", diff --git a/src-self-hosted/stage1.zig b/src-self-hosted/stage1.zig index 96bf4b7fdf..f8caaf3da2 100644 --- a/src-self-hosted/stage1.zig +++ b/src-self-hosted/stage1.zig @@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { stderr = &stderr_file.outStream().stream; const args = args_list.toSliceConst(); - var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]); + var flags = try Args.parse(allocator, &self_hosted_main.args_fmt_spec, args[2..]); defer flags.deinit(); if (flags.present("help")) { @@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void while (try dir_it.next()) |entry| { if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) { - const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name }); + const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name }); try fmtPath(fmt, full_path, check_mode); } } diff --git a/src/all_types.hpp b/src/all_types.hpp index 5b062efc9a..a5fa7241e3 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -2650,6 +2650,9 @@ struct IrInstruction { IrInstructionId id; // true if this instruction was generated by zig and not from user code bool is_gen; + + // for debugging purposes, this is useful to call to inspect the instruction + void dump(); }; struct IrInstructionDeclVarSrc { diff --git a/src/ir.cpp b/src/ir.cpp index 2772108a21..1e32679bab 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -218,7 +218,8 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *dest_type); static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, - ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime); + ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, + bool non_null_comptime, bool allow_discard); static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime, bool allow_discard); @@ -10417,9 +10418,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } if (cur_type->id == ZigTypeIdErrorSet) { - if (prev_type->id == ZigTypeIdArray) { - convert_to_const_slice = true; - } if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -10754,25 +10752,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray && - cur_type->data.array.len != prev_type->data.array.len && - types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, - source_node, false).id == ConstCastResultIdOk) - { - convert_to_const_slice = true; - prev_inst = cur_inst; - continue; - } - - if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray && - cur_type->data.array.len != prev_type->data.array.len && - types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, - source_node, false).id == ConstCastResultIdOk) - { - convert_to_const_slice = true; - continue; - } - // *[N]T to []T // *[N]T to E![]T if (cur_type->id == ZigTypeIdPointer && @@ -10820,19 +10799,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - // [N]T to []T - if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) && - (prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const || - cur_type->data.array.len == 0) && - types_match_const_cast_only(ira, - prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type, - cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) - { - convert_to_const_slice = false; - continue; - } - - // *[N]T and *[M]T if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle && cur_type->data.pointer.child_type->id == ZigTypeIdArray && @@ -10876,19 +10842,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - // [N]T to []T - if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) && - (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const || - prev_type->data.array.len == 0) && - types_match_const_cast_only(ira, - cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type, - prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) - { - prev_inst = cur_inst; - convert_to_const_slice = false; - continue; - } - if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion && (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) { @@ -10924,18 +10877,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT free(errors); if (convert_to_const_slice) { - if (prev_inst->value->type->id == ZigTypeIdArray) { - ZigType *ptr_type = get_pointer_to_type_extra( - ira->codegen, prev_inst->value->type->data.array.child_type, - true, false, PtrLenUnknown, - 0, 0, 0, false); - ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); - if (err_set_type != nullptr) { - return get_error_union_type(ira->codegen, err_set_type, slice_type); - } else { - return slice_type; - } - } else if (prev_inst->value->type->id == ZigTypeIdPointer) { + if (prev_inst->value->type->id == ZigTypeIdPointer) { ZigType *array_type = prev_inst->value->type->data.pointer.child_type; src_assert(array_type->id == ZigTypeIdArray, source_node); ZigType *ptr_type = get_pointer_to_type_extra2( @@ -12021,52 +11963,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi return new_instruction; } -static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *array_arg, ZigType *wanted_type, ResultLoc *result_loc) -{ - assert(is_slice(wanted_type)); - // In this function we honor the const-ness of wanted_type, because - // we may be casting [0]T to []const T which is perfectly valid. - - IrInstruction *array_ptr = nullptr; - IrInstruction *array; - if (array_arg->value->type->id == ZigTypeIdPointer) { - array = ir_get_deref(ira, source_instr, array_arg, nullptr); - array_ptr = array_arg; - } else { - array = array_arg; - } - ZigType *array_type = array->value->type; - assert(array_type->id == ZigTypeIdArray); - - if (instr_is_comptime(array) || array_type->data.array.len == 0) { - IrInstruction *result = ir_const(ira, source_instr, wanted_type); - init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true); - result->value->type = wanted_type; - return result; - } - - IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); - init_const_usize(ira->codegen, start->value, 0); - - IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); - init_const_usize(ira->codegen, end->value, array_type->data.array.len); - - if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); - - if (result_loc == nullptr) result_loc = no_result_loc(); - IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, - true, false, true); - if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { - return result_loc_inst; - } - IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst); - result->value->data.rh_slice.id = RuntimeHintSliceIdLen; - result->value->data.rh_slice.len = array_type->data.array.len; - - return result; -} - static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) { assert(union_type->id == ZigTypeIdUnion); @@ -13101,44 +12997,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); } - // cast from [N]T to []const T - // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this - if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) { - ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry; - assert(ptr_type->id == ZigTypeIdPointer); - if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && - types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, - source_node, false).id == ConstCastResultIdOk) - { - return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type, nullptr); - } - } - - // cast from [N]T to ?[]const T - // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this - if (wanted_type->id == ZigTypeIdOptional && - is_slice(wanted_type->data.maybe.child_type) && - actual_type->id == ZigTypeIdArray) - { - ZigType *ptr_type = - wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index]->type_entry; - assert(ptr_type->id == ZigTypeIdPointer); - if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && - types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, - source_node, false).id == ConstCastResultIdOk) - { - IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); - if (type_is_invalid(cast1->value->type)) - return ira->codegen->invalid_instruction; - - IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value->type)) - return ira->codegen->invalid_instruction; - - return cast2; - } - } - // *[N]T to ?[]const T if (wanted_type->id == ZigTypeIdOptional && is_slice(wanted_type->data.maybe.child_type) && @@ -13284,20 +13142,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // *@Frame(func) to anyframe->T or anyframe + // *@Frame(func) to ?anyframe->T or ?anyframe + // *@Frame(func) to E!anyframe->T or E!anyframe if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle && !actual_type->data.pointer.is_const && - actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame && wanted_type->id == ZigTypeIdAnyFrame) + actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame) { - bool ok = true; - if (wanted_type->data.any_frame.result_type != nullptr) { - ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn; - ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type; - if (wanted_type->data.any_frame.result_type != fn_return_type) { - ok = false; + ZigType *anyframe_type; + if (wanted_type->id == ZigTypeIdAnyFrame) { + anyframe_type = wanted_type; + } else if (wanted_type->id == ZigTypeIdOptional && + wanted_type->data.maybe.child_type->id == ZigTypeIdAnyFrame) + { + anyframe_type = wanted_type->data.maybe.child_type; + } else if (wanted_type->id == ZigTypeIdErrorUnion && + wanted_type->data.error_union.payload_type->id == ZigTypeIdAnyFrame) + { + anyframe_type = wanted_type->data.error_union.payload_type; + } else { + anyframe_type = nullptr; + } + if (anyframe_type != nullptr) { + bool ok = true; + if (anyframe_type->data.any_frame.result_type != nullptr) { + ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn; + ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type; + if (anyframe_type->data.any_frame.result_type != fn_return_type) { + ok = false; + } + } + if (ok) { + IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type); + if (anyframe_type == wanted_type) + return cast1; + return ir_analyze_cast(ira, source_instr, wanted_type, cast1); } - } - if (ok) { - return ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, wanted_type); } } @@ -13322,30 +13201,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type); } - // cast from [N]T to E![]const T - if (wanted_type->id == ZigTypeIdErrorUnion && - is_slice(wanted_type->data.error_union.payload_type) && - actual_type->id == ZigTypeIdArray) - { - ZigType *ptr_type = - wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index]->type_entry; - assert(ptr_type->id == ZigTypeIdPointer); - if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && - types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, - source_node, false).id == ConstCastResultIdOk) - { - IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); - if (type_is_invalid(cast1->value->type)) - return ira->codegen->invalid_instruction; - - IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value->type)) - return ira->codegen->invalid_instruction; - - return cast2; - } - } - // cast from E to E!T if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorSet) @@ -13541,6 +13396,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); } + // T to ?E!T + if (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdErrorUnion && + actual_type->id != ZigTypeIdOptional) + { + IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type); + if (type_is_invalid(cast1->value->type)) + return ira->codegen->invalid_instruction; + return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); + } + ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node, buf_sprintf("expected type '%s', found '%s'", buf_ptr(&wanted_type->name), @@ -15283,10 +15148,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i ZigValue *out_array_val; size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); - if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { - result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel); - out_array_val = out_val; - } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) { + if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) { out_array_val = create_const_vals(1); out_array_val->special = ConstValSpecialStatic; out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); @@ -15314,6 +15176,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize; out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic; bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len); + } else if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { + result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel); + out_array_val = out_val; } else { result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel); @@ -16142,7 +16007,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su // when calling this function, at the callsite must check for result type noreturn and propagate it up static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, - ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime) + ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, + bool non_null_comptime, bool allow_discard) { Error err; if (result_loc->resolved_loc != nullptr) { @@ -16275,8 +16141,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe ira->src_implicit_return_type_list.append(value); } peer_parent->skipped = true; - return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, + IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, value_type, value, force_runtime || !is_comptime, true, true); + if (parent_result_loc != nullptr) { + peer_parent->parent->written = true; + } + return parent_result_loc; } if (peer_parent->resolved_type == nullptr) { @@ -16317,30 +16187,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe force_runtime, non_null_comptime); } - ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type, - result_cast->base.source_instruction->source_node, false); - if (const_cast_result.id == ConstCastResultIdInvalid) - return ira->codegen->invalid_instruction; - if (const_cast_result.id != ConstCastResultIdOk) { - // We will not be able to provide a result location for this value. Create - // a new result location. - return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, - force_runtime, non_null_comptime); - } - - // In this case we can pointer cast the result location. IrInstruction *casted_value; if (value != nullptr) { casted_value = ir_implicit_cast(ira, value, dest_type); + if (type_is_invalid(casted_value->value->type)) + return ira->codegen->invalid_instruction; + dest_type = casted_value->value->type; } else { casted_value = nullptr; } - if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) { - return casted_value; - } - - bool old_parent_result_loc_written = result_cast->parent->written; IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, dest_type, casted_value, force_runtime, non_null_comptime, true); if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || @@ -16378,26 +16234,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); - { - // we also need to check that this cast is OK. - ConstCastOnly const_cast_result = types_match_const_cast_only(ira, - parent_result_loc->value->type, ptr_type, - result_cast->base.source_instruction->source_node, false); - if (const_cast_result.id == ConstCastResultIdInvalid) - return ira->codegen->invalid_instruction; - if (const_cast_result.id != ConstCastResultIdOk) { - // We will not be able to provide a result location for this value. Create - // a new result location. - result_cast->parent->written = old_parent_result_loc_written; - return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, - force_runtime, non_null_comptime); + ConstCastOnly const_cast_result = types_match_const_cast_only(ira, + parent_result_loc->value->type, ptr_type, + result_cast->base.source_instruction->source_node, false); + if (const_cast_result.id == ConstCastResultIdInvalid) + return ira->codegen->invalid_instruction; + if (const_cast_result.id != ConstCastResultIdOk) { + if (allow_discard) { + return parent_result_loc; } + // We will not be able to provide a result location for this value. Create + // a new result location. + result_cast->parent->written = false; + return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, + force_runtime, non_null_comptime); } - result_loc->written = true; - result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, + return ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, ptr_type, result_cast->base.source_instruction, false); - return result_loc->resolved_loc; } case ResultLocIdBitCast: { ResultLocBitCast *result_bit_cast = reinterpret_cast(result_loc); @@ -16483,7 +16337,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s result_loc_pass1 = no_result_loc(); } IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, - value, force_runtime, non_null_comptime); + value, force_runtime, non_null_comptime, allow_discard); if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) return result_loc; @@ -16496,7 +16350,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && - value_type->id != ZigTypeIdNull) + value_type->id != ZigTypeIdNull && value == nullptr) { result_loc_pass1->written = false; return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); @@ -16514,9 +16368,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s return unwrapped_err_ptr; } } - } else if (is_slice(actual_elem_type) && value_type->id == ZigTypeIdArray) { - // need to allow EndExpr to do the implicit cast from array to slice - result_loc_pass1->written = false; } return result_loc; } @@ -17520,11 +17371,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { ir_reset_result(call_instruction->result_loc); result_loc = nullptr; - } else { - call_instruction->base.value.type = impl_fn_type_id->return_type; - IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type); - if (type_is_invalid(casted_value->value.type)) - return casted_value; } } } else if (call_instruction->is_async_call_builtin) { @@ -17687,11 +17533,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { ir_reset_result(call_instruction->result_loc); result_loc = nullptr; - } else { - call_instruction->base.value.type = return_type; - IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type); - if (type_is_invalid(casted_value->value.type)) - return casted_value; } } } else if (call_instruction->is_async_call_builtin) { @@ -21041,6 +20882,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, { // We're now done inferring the type. container_type->data.structure.resolve_status = ResolveStatusUnstarted; + } else if (container_type->id == ZigTypeIdVector) { + // OK } else { ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("type '%s' does not support array initialization", @@ -22434,17 +22277,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, return result; } -static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) +static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, + const char *name, size_t field_index) { + Error err; ensure_field_index(struct_value->type, name, field_index); - assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic); - return struct_value->data.x_struct.fields[field_index]; + ZigValue *val = struct_value->data.x_struct.fields[field_index]; + if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, val, UndefBad))) + return nullptr; + return val; } static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value, const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) { - ZigValue *field_val = get_const_field(ira, struct_value, name, field_index); + ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index); + if (field_val == nullptr) + return ErrorSemanticAnalyzeFail; IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type); IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, get_optional_type(ira->codegen, elem_type)); @@ -22455,23 +22304,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst return ErrorNone; } -static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) +static Error get_const_field_bool(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, + const char *name, size_t field_index, bool *out) { - ZigValue *value = get_const_field(ira, struct_value, name, field_index); + ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index); + if (value == nullptr) + return ErrorSemanticAnalyzeFail; assert(value->type == ira->codegen->builtin_types.entry_bool); - return value->data.x_bool; + *out = value->data.x_bool; + return ErrorNone; } -static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) +static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index) { - ZigValue *value = get_const_field(ira, struct_value, name, field_index); + ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index); + if (value == nullptr) + return nullptr; assert(value->type == ira->codegen->builtin_types.entry_num_lit_int); return &value->data.x_bigint; } -static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) +static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index) { - ZigValue *value = get_const_field(ira, struct_value, name, field_index); + ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index); + if (value == nullptr) + return ira->codegen->invalid_instruction->value->type; assert(value->type == ira->codegen->builtin_types.entry_type); return value->data.x_type; } @@ -22489,17 +22346,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi return ira->codegen->builtin_types.entry_bool; case ZigTypeIdUnreachable: return ira->codegen->builtin_types.entry_unreachable; - case ZigTypeIdInt: + case ZigTypeIdInt: { assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr)); - return get_int_type(ira->codegen, - get_const_field_bool(ira, payload, "is_signed", 0), - bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1))); + BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1); + if (bi == nullptr) + return ira->codegen->invalid_instruction->value->type; + bool is_signed; + if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed))) + return ira->codegen->invalid_instruction->value->type; + return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi)); + } case ZigTypeIdFloat: { assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr)); - uint32_t bits = bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 0)); + BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0); + if (bi == nullptr) + return ira->codegen->invalid_instruction->value->type; + uint32_t bits = bigint_as_u32(bi); switch (bits) { case 16: return ira->codegen->builtin_types.entry_f16; case 32: return ira->codegen->builtin_types.entry_f32; @@ -22515,27 +22380,51 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); assert(payload->special == ConstValSpecialStatic); assert(payload->type == type_info_pointer_type); - ZigValue *size_value = get_const_field(ira, payload, "size", 0); + ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0); assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); - ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4); + ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4); + if (type_is_invalid(elem_type)) + return ira->codegen->invalid_instruction->value->type; ZigValue *sentinel; if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6, elem_type, &sentinel))) { - return nullptr; + return ira->codegen->invalid_instruction->value->type; + } + BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3); + if (bi == nullptr) + return ira->codegen->invalid_instruction->value->type; + + bool is_const; + if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const))) + return ira->codegen->invalid_instruction->value->type; + + bool is_volatile; + if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2, + &is_volatile))) + { + return ira->codegen->invalid_instruction->value->type; + } + + bool is_allowzero; + if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5, + &is_allowzero))) + { + return ira->codegen->invalid_instruction->value->type; } + ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, elem_type, - get_const_field_bool(ira, payload, "is_const", 1), - get_const_field_bool(ira, payload, "is_volatile", 2), + is_const, + is_volatile, ptr_len, - bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)), + bigint_as_u32(bi), 0, // bit_offset_in_host 0, // host_int_bytes - get_const_field_bool(ira, payload, "is_allowzero", 5), + is_allowzero, VECTOR_INDEX_NONE, nullptr, sentinel); if (size_enum_index != 2) return ptr_type; @@ -22544,17 +22433,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi case ZigTypeIdArray: { assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); - ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1); + ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1); + if (type_is_invalid(elem_type)) + return ira->codegen->invalid_instruction->value->type; ZigValue *sentinel; if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2, elem_type, &sentinel))) { - return nullptr; + return ira->codegen->invalid_instruction->value->type; } - return get_array_type(ira->codegen, - elem_type, - bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)), - sentinel); + BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0); + if (bi == nullptr) + return ira->codegen->invalid_instruction->value->type; + return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel); } case ZigTypeIdComptimeFloat: return ira->codegen->builtin_types.entry_num_lit_float; @@ -22575,7 +22466,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi case ZigTypeIdEnumLiteral: ir_add_error(ira, instruction, buf_sprintf( "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId))); - return nullptr; + return ira->codegen->invalid_instruction->value->type; case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdBoundFn: @@ -22583,7 +22474,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi case ZigTypeIdStruct: ir_add_error(ira, instruction, buf_sprintf( "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId))); - return nullptr; + return ira->codegen->invalid_instruction->value->type; } zig_unreachable(); } @@ -22602,7 +22493,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT return ira->codegen->invalid_instruction; ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag)); ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload); - if (!type) + if (type_is_invalid(type)) return ira->codegen->invalid_instruction; return ir_const_type(ira, &instruction->base, type); } @@ -28332,3 +28223,18 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) { } return ErrorNone; } + +void IrInstruction::dump() { + IrInstruction *inst = this; + if (inst->source_node != nullptr) { + inst->source_node->src(); + } else { + fprintf(stderr, "(null source node)\n"); + } + IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc; + ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass); + if (pass == IrPassSrc) { + fprintf(stderr, "-> "); + ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen); + } +} diff --git a/test/compare_output.zig b/test/compare_output.zig index 1535d0ae52..03f71d380e 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ ); - tc.setCommandLineArgs([_][]const u8{ + tc.setCommandLineArgs(&[_][]const u8{ "first arg", "'a' 'b' \\", "bare", @@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ ); - tc.setCommandLineArgs([_][]const u8{ + tc.setCommandLineArgs(&[_][]const u8{ "first arg", "'a' 'b' \\", "bare", diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig index 47e74cd310..1d51f822d0 100644 --- a/test/stage1/behavior/array.zig +++ b/test/stage1/behavior/array.zig @@ -20,7 +20,7 @@ test "arrays" { } expect(accumulator == 15); - expect(getArrayLen(array) == 5); + expect(getArrayLen(&array) == 5); } fn getArrayLen(a: []const u32) usize { return a.len; @@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 { test "runtime initialize array elem and then implicit cast to slice" { var two: i32 = 2; - const x: []const i32 = [_]i32{two}; + const x: []const i32 = &[_]i32{two}; expect(x[0] == 2); } test "array literal as argument to function" { const S = struct { fn entry(two: i32) void { - foo([_]i32{ + foo(&[_]i32{ 1, 2, 3, }); - foo([_]i32{ + foo(&[_]i32{ 1, two, 3, }); - foo2(true, [_]i32{ + foo2(true, &[_]i32{ 1, 2, 3, }); - foo2(true, [_]i32{ + foo2(true, &[_]i32{ 1, two, 3, @@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" { const S = struct { fn entry(two: i32) void { const cases = [_][]const []const i32{ - [_][]const i32{[_]i32{1}}, - [_][]const i32{[_]i32{ 2, 3 }}, - [_][]const i32{ - [_]i32{4}, - [_]i32{ 5, 6, 7 }, + &[_][]const i32{&[_]i32{1}}, + &[_][]const i32{&[_]i32{ 2, 3 }}, + &[_][]const i32{ + &[_]i32{4}, + &[_]i32{ 5, 6, 7 }, }, }; - check(cases); + check(&cases); const cases2 = [_][]const i32{ - [_]i32{1}, + &[_]i32{1}, &[_]i32{ two, 3 }, }; expect(cases2.len == 2); @@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" { expect(cases2[1][1] == 3); const cases3 = [_][]const []const i32{ - [_][]const i32{[_]i32{1}}, + &[_][]const i32{&[_]i32{1}}, &[_][]const i32{&[_]i32{ two, 3 }}, - [_][]const i32{ - [_]i32{4}, - [_]i32{ 5, 6, 7 }, + &[_][]const i32{ + &[_]i32{4}, + &[_]i32{ 5, 6, 7 }, }, }; - check(cases3); + check(&cases3); } fn check(cases: []const []const []const i32) void { @@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" { test "anonymous list literal syntax" { const S = struct { fn doTheTest() void { - var array: [4]u8 = .{1, 2, 3, 4}; + var array: [4]u8 = .{ 1, 2, 3, 4 }; expect(array[0] == 1); expect(array[1] == 2); expect(array[2] == 3); @@ -335,8 +335,8 @@ test "anonymous literal in array" { }; fn doTheTest() void { var array: [2]Foo = .{ - .{.a = 3}, - .{.b = 3}, + .{ .a = 3 }, + .{ .b = 3 }, }; expect(array[0].a == 3); expect(array[0].b == 4); @@ -351,7 +351,7 @@ test "anonymous literal in array" { test "access the null element of a null terminated array" { const S = struct { fn doTheTest() void { - var array: [4:0]u8 = .{'a', 'o', 'e', 'u'}; + var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; comptime expect(array[4] == 0); var len: usize = 4; expect(array[len] == 0); diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig index 67411601da..78db00cc08 100644 --- a/test/stage1/behavior/async_fn.zig +++ b/test/stage1/behavior/async_fn.zig @@ -143,7 +143,7 @@ test "coroutine suspend, resume" { resume frame; seq('h'); - expect(std.mem.eql(u8, points, "abcdefgh")); + expect(std.mem.eql(u8, &points, "abcdefgh")); } fn amain() void { @@ -206,7 +206,7 @@ test "coroutine await" { resume await_a_promise; await_seq('i'); expect(await_final_result == 1234); - expect(std.mem.eql(u8, await_points, "abcdefghi")); + expect(std.mem.eql(u8, &await_points, "abcdefghi")); } async fn await_amain() void { await_seq('b'); @@ -240,7 +240,7 @@ test "coroutine await early return" { var p = async early_amain(); early_seq('f'); expect(early_final_result == 1234); - expect(std.mem.eql(u8, early_points, "abcdef")); + expect(std.mem.eql(u8, &early_points, "abcdef")); } async fn early_amain() void { early_seq('b'); @@ -1166,7 +1166,7 @@ test "suspend in for loop" { } fn atest() void { - expect(func([_]u8{ 1, 2, 3 }) == 6); + expect(func(&[_]u8{ 1, 2, 3 }) == 6); } fn func(stuff: []const u8) u32 { global_frame = @frame(); @@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" { fn doTheTest() void { var foo = Foo{ - .slice = [_]i32{ 1, 2 }, + .slice = &[_]i32{ 1, 2 }, }; expect(atest(&foo) == 3); } @@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { fn doTheTest() void { var foo = Foo{ - .slice = [_]i32{ 1, 2 }, + .slice = &[_]i32{ 1, 2 }, }; expect(atest(&foo) == 3); } diff --git a/test/stage1/behavior/await_struct.zig b/test/stage1/behavior/await_struct.zig index 6e4d330ea3..2d4faadc27 100644 --- a/test/stage1/behavior/await_struct.zig +++ b/test/stage1/behavior/await_struct.zig @@ -16,7 +16,7 @@ test "coroutine await struct" { resume await_a_promise; await_seq('i'); expect(await_final_result.x == 1234); - expect(std.mem.eql(u8, await_points, "abcdefghi")); + expect(std.mem.eql(u8, &await_points, "abcdefghi")); } async fn await_amain() void { await_seq('b'); diff --git a/test/stage1/behavior/bugs/1607.zig b/test/stage1/behavior/bugs/1607.zig index 3a1de80a86..ffc1aa85dc 100644 --- a/test/stage1/behavior/bugs/1607.zig +++ b/test/stage1/behavior/bugs/1607.zig @@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void { } test "slices pointing at the same address as global array." { - checkAddress(a); - comptime checkAddress(a); + checkAddress(&a); + comptime checkAddress(&a); } diff --git a/test/stage1/behavior/bugs/1914.zig b/test/stage1/behavior/bugs/1914.zig index 22269590d9..2c9e836e6a 100644 --- a/test/stage1/behavior/bugs/1914.zig +++ b/test/stage1/behavior/bugs/1914.zig @@ -7,7 +7,7 @@ const B = struct { a_pointer: *const A, }; -const b_list: []B = [_]B{}; +const b_list: []B = &[_]B{}; const a = A{ .b_list_pointer = &b_list }; test "segfault bug" { @@ -24,7 +24,7 @@ pub const B2 = struct { pointer_array: []*A2, }; -var b_value = B2{ .pointer_array = [_]*A2{} }; +var b_value = B2{ .pointer_array = &[_]*A2{} }; test "basic stuff" { std.debug.assert(&b_value == &b_value); diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index fec4494ad9..ba538a0ebb 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" { } fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { if (a) { - return [_]u8{}; + return &[_]u8{}; } return slice[0..1]; @@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void { } fn gimmeErrOrSlice() anyerror![]u8 { - return [_]u8{}; + return &[_]u8{}; } test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" { @@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" { } fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { if (a) { - return [_]u8{}; + return &[_]u8{}; } return slice[0..1]; @@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void { test "implicit cast from [*]T to ?*c_void" { var a = [_]u8{ 3, 2, 1 }; incrementVoidPtrArray(a[0..].ptr, 3); - expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 })); + expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); } fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { @@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" { test "peer resolution of string literals" { const S = struct { - const E = extern enum { a, b, c, d}; + const E = extern enum { + a, + b, + c, + d, + }; fn doTheTest(e: E) void { const cmd = switch (e) { @@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" { fn doTheTest() void { // [:x]T to []T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var slice: [:0]i32 = &array; var dest: []i32 = slice; - expect(mem.eql(i32, dest, &[_]i32{1,2,3,4})); + expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } // [*:x]T to [*]T { - var array = [4:99]i32{1,2,3,4}; + var array = [4:99]i32{ 1, 2, 3, 4 }; var dest: [*]i32 = &array; expect(dest[0] == 1); expect(dest[1] == 2); @@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" { // [N:x]T to [N]T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var dest: [4]i32 = array; - expect(mem.eql(i32, dest, &[_]i32{1,2,3,4})); + expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); } // *[N:x]T to *[N]T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var dest: *[4]i32 = &array; - expect(mem.eql(i32, dest, &[_]i32{1,2,3,4})); + expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } // [:x]T to [*:x]T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var slice: [:0]i32 = &array; var dest: [*:0]i32 = slice; expect(dest[0] == 1); @@ -674,3 +679,21 @@ test "type coercion related to sentinel-termination" { S.doTheTest(); comptime S.doTheTest(); } + +test "cast i8 fn call peers to i32 result" { + const S = struct { + fn doTheTest() void { + var cond = true; + const value: i32 = if (cond) smallBoi() else bigBoi(); + expect(value == 123); + } + fn smallBoi() i8 { + return 123; + } + fn bigBoi() i16 { + return 1234; + } + }; + S.doTheTest(); + comptime S.doTheTest(); +} diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index b7bce26568..be7226d94c 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" { }; var b = [1]u8{9}; - var f = @bytesToSlice(F, b); + var f = @bytesToSlice(F, &b); expect(f[0].a == 9); } @@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" { test "array concatenation forces comptime" { var a = oneItem(3) ++ oneItem(4); - expect(std.mem.eql(i32, a, [_]i32{ 3, 4 })); + expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); } test "array multiplication forces comptime" { var a = oneItem(3) ** scalar(2); - expect(std.mem.eql(i32, a, [_]i32{ 3, 3 })); + expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 })); } fn oneItem(x: i32) [1]i32 { diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig index cfa68bd216..5cf75ed497 100644 --- a/test/stage1/behavior/for.zig +++ b/test/stage1/behavior/for.zig @@ -26,7 +26,7 @@ test "for loop with pointer elem var" { var target: [source.len]u8 = undefined; mem.copy(u8, target[0..], source); mangleString(target[0..]); - expect(mem.eql(u8, target, "bcdefgh")); + expect(mem.eql(u8, &target, "bcdefgh")); for (source) |*c, i| expect(@typeOf(c) == *const u8); @@ -64,7 +64,7 @@ test "basic for loop" { buffer[buf_index] = @intCast(u8, index); buf_index += 1; } - const unknown_size: []const u8 = array; + const unknown_size: []const u8 = &array; for (unknown_size) |item| { buffer[buf_index] = item; buf_index += 1; @@ -74,7 +74,7 @@ test "basic for loop" { buf_index += 1; } - expect(mem.eql(u8, buffer[0..buf_index], expected_result)); + expect(mem.eql(u8, buffer[0..buf_index], &expected_result)); } test "break from outer for loop" { @@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" { } } }; - S.doTheTest([_]u8{ 1, 2 }); - comptime S.doTheTest([_]u8{ 1, 2 }); + S.doTheTest(&[_]u8{ 1, 2 }); + comptime S.doTheTest(&[_]u8{ 1, 2 }); } diff --git a/test/stage1/behavior/generics.zig b/test/stage1/behavior/generics.zig index 664b982c21..dc15ae1b8c 100644 --- a/test/stage1/behavior/generics.zig +++ b/test/stage1/behavior/generics.zig @@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T { } test "generic fn with implicit cast" { - expect(getFirstByte(u8, [_]u8{13}) == 13); - expect(getFirstByte(u16, [_]u16{ + expect(getFirstByte(u8, &[_]u8{13}) == 13); + expect(getFirstByte(u16, &[_]u16{ 0, 13, }) == 0); diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index 6ac745f5c5..a3da752f0d 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {} test "cast undefined" { const array: [100]u8 = undefined; - const slice = @as([]const u8, array); + const slice = @as([]const u8, &array); testCastUndefined(slice); } fn testCastUndefined(x: []const u8) void {} @@ -614,7 +614,7 @@ test "slicing zero length array" { expect(s1.len == 0); expect(s2.len == 0); expect(mem.eql(u8, s1, "")); - expect(mem.eql(u32, s2, [_]u32{})); + expect(mem.eql(u32, s2, &[_]u32{})); } const addr1 = @ptrCast(*const u8, emptyFn); @@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic const E = struct { entries: []u32, }; - var foo = E{ .entries = [_]u32{} }; + var foo = E{ .entries = &[_]u32{} }; expect(foo.entries.len == 0); } diff --git a/test/stage1/behavior/ptrcast.zig b/test/stage1/behavior/ptrcast.zig index ddb5a63eee..4c17b38e6e 100644 --- a/test/stage1/behavior/ptrcast.zig +++ b/test/stage1/behavior/ptrcast.zig @@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void { test "reinterpret struct field at comptime" { const numLittle = comptime Bytes.init(0x12345678); - expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes)); + expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes)); } const Bytes = struct { diff --git a/test/stage1/behavior/shuffle.zig b/test/stage1/behavior/shuffle.zig index 1985c8dc76..2189b3e0e1 100644 --- a/test/stage1/behavior/shuffle.zig +++ b/test/stage1/behavior/shuffle.zig @@ -9,28 +9,28 @@ test "@shuffle" { var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; var res = @shuffle(i32, v, x, mask); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); // Implicit cast from array (of mask) res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); // Undefined const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; res = @shuffle(i32, v, undefined, mask2); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 })); // Upcasting of b var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; res = @shuffle(i32, x, v2, mask3); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); // Upcasting of a var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; res = @shuffle(i32, v3, x, mask4); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); // bool // Disabled because of #3317 @@ -39,7 +39,7 @@ test "@shuffle" { var v4: @Vector(2, bool) = [2]bool{ true, false }; const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; var res2 = @shuffle(bool, x2, v4, mask5); - expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false })); } // TODO re-enable when LLVM codegen is fixed @@ -49,7 +49,7 @@ test "@shuffle" { var v4: @Vector(2, bool) = [2]bool{ true, false }; const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; var res2 = @shuffle(bool, x2, v4, mask5); - expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false })); } } }; diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig index 3c394e39a1..e325c6c8c8 100644 --- a/test/stage1/behavior/slice.zig +++ b/test/stage1/behavior/slice.zig @@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 { test "implicitly cast array of size 0 to slice" { var msg = [_]u8{}; - assertLenIsZero(msg); + assertLenIsZero(&msg); } fn assertLenIsZero(msg: []const u8) void { @@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 { } test "comptime slices are disambiguated" { - expect(sliceSum([_]u8{ 1, 2 }) == 3); - expect(sliceSum([_]u8{ 3, 4 }) == 7); + expect(sliceSum(&[_]u8{ 1, 2 }) == 3); + expect(sliceSum(&[_]u8{ 3, 4 }) == 7); } test "slice type with custom alignment" { diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index 7c2e58f2cb..408f5da687 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 { } test "pass slice of empty struct to fn" { - expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1); + expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1); } fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize { return slice.len; @@ -432,7 +432,7 @@ const Expr = union(enum) { }; fn alloc(comptime T: type) []T { - return [_]T{}; + return &[_]T{}; } test "call method with mutable reference to struct with no fields" { @@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" { .a = true, .b = "abcdefghijklmnopqurstu".*, }; - bar(foo.b); + const value = foo.b; + bar(&value); } }; S.doTheTest(); @@ -783,7 +784,7 @@ test "struct with var field" { x: var, y: var, }; - const pt = Point { + const pt = Point{ .x = 1, .y = 2, }; diff --git a/test/stage1/behavior/struct_contains_slice_of_itself.zig b/test/stage1/behavior/struct_contains_slice_of_itself.zig index 2f3b5f41df..14bf0320a2 100644 --- a/test/stage1/behavior/struct_contains_slice_of_itself.zig +++ b/test/stage1/behavior/struct_contains_slice_of_itself.zig @@ -14,21 +14,21 @@ test "struct contains slice of itself" { var other_nodes = [_]Node{ Node{ .payload = 31, - .children = [_]Node{}, + .children = &[_]Node{}, }, Node{ .payload = 32, - .children = [_]Node{}, + .children = &[_]Node{}, }, }; var nodes = [_]Node{ Node{ .payload = 1, - .children = [_]Node{}, + .children = &[_]Node{}, }, Node{ .payload = 2, - .children = [_]Node{}, + .children = &[_]Node{}, }, Node{ .payload = 3, @@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" { var other_nodes = [_]NodeAligned{ NodeAligned{ .payload = 31, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, NodeAligned{ .payload = 32, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, }; var nodes = [_]NodeAligned{ NodeAligned{ .payload = 1, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, NodeAligned{ .payload = 2, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, NodeAligned{ .payload = 3, diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig index f083359d1d..432a1e0e94 100644 --- a/test/stage1/behavior/type.zig +++ b/test/stage1/behavior/type.zig @@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void { test "Type.MetaType" { testing.expect(type == @Type(TypeInfo{ .Type = undefined })); - testTypes([_]type{type}); + testTypes(&[_]type{type}); } test "Type.Void" { testing.expect(void == @Type(TypeInfo{ .Void = undefined })); - testTypes([_]type{void}); + testTypes(&[_]type{void}); } test "Type.Bool" { testing.expect(bool == @Type(TypeInfo{ .Bool = undefined })); - testTypes([_]type{bool}); + testTypes(&[_]type{bool}); } test "Type.NoReturn" { testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined })); - testTypes([_]type{noreturn}); + testTypes(&[_]type{noreturn}); } test "Type.Int" { @@ -37,7 +37,7 @@ test "Type.Int" { testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } })); testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } })); testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } })); - testTypes([_]type{ u8, u32, i64 }); + testTypes(&[_]type{ u8, u32, i64 }); } test "Type.Float" { @@ -45,11 +45,11 @@ test "Type.Float" { testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } })); testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } })); testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } })); - testTypes([_]type{ f16, f32, f64, f128 }); + testTypes(&[_]type{ f16, f32, f64, f128 }); } test "Type.Pointer" { - testTypes([_]type{ + testTypes(&[_]type{ // One Value Pointer Types *u8, *const u8, *volatile u8, *const volatile u8, @@ -115,18 +115,18 @@ test "Type.Array" { .sentinel = 0, }, })); - testTypes([_]type{ [1]u8, [30]usize, [7]bool }); + testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); } test "Type.ComptimeFloat" { - testTypes([_]type{comptime_float}); + testTypes(&[_]type{comptime_float}); } test "Type.ComptimeInt" { - testTypes([_]type{comptime_int}); + testTypes(&[_]type{comptime_int}); } test "Type.Undefined" { - testTypes([_]type{@typeOf(undefined)}); + testTypes(&[_]type{@typeOf(undefined)}); } test "Type.Null" { - testTypes([_]type{@typeOf(null)}); + testTypes(&[_]type{@typeOf(null)}); } diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index d7481b21c7..43b26b79b8 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -241,7 +241,7 @@ pub const PackThis = union(enum) { }; test "constant packed union" { - testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }}); + testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }}); } fn testConstPackedUnion(expected_tokens: []const PackThis) void { diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig index f7b98b294f..b6033ea660 100644 --- a/test/stage1/behavior/vector.zig +++ b/test/stage1/behavior/vector.zig @@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" { fn doTheTest() void { const a: @Vector(4, bool) = [_]bool{ true, false, true, false }; const result_array: [4]bool = a; - expect(mem.eql(bool, result_array, [4]bool{ true, false, true, false })); + expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false })); } }; S.doTheTest(); @@ -20,11 +20,11 @@ test "vector wrap operators" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); - expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 })); - expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 })); + expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 })); + expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 })); + expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; - expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 })); + expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); } }; S.doTheTest(); @@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; - expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false })); - expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true })); - expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false })); - expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true })); - expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false })); - expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true })); + expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); + expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); + expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); + expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true })); + expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false })); + expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true })); } }; S.doTheTest(); @@ -53,10 +53,10 @@ test "vector int operators" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; - expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 })); - expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 })); - expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 })); - expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 })); + expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); + expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); + expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); + expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 })); } }; S.doTheTest(); @@ -68,10 +68,10 @@ test "vector float operators" { fn doTheTest() void { var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 }; - expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 })); - expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 })); - expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 })); - expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 })); + expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 })); + expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 })); + expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 })); + expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 })); } }; S.doTheTest(); @@ -83,9 +83,9 @@ test "vector bit operators" { fn doTheTest() void { var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; - expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); - expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); - expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); + expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); + expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); + expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); } }; S.doTheTest(); @@ -98,7 +98,7 @@ test "implicit cast vector to array" { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; var result_array: [4]i32 = a; result_array = a; - expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 })); + expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); } }; S.doTheTest(); @@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" { { var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; var x: [4]u3 = v; - expect(mem.eql(u3, x, @as([4]u3, v))); + expect(mem.eql(u3, &x, &@as([4]u3, v))); } { var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; var x: [4]u2 = v; - expect(mem.eql(u2, x, @as([4]u2, v))); + expect(mem.eql(u2, &x, &@as([4]u2, v))); } { var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; var x: [4]u1 = v; - expect(mem.eql(u1, x, @as([4]u1, v))); + expect(mem.eql(u1, &x, &@as([4]u1, v))); } { var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; var x: [4]bool = v; - expect(mem.eql(bool, x, @as([4]bool, v))); + expect(mem.eql(bool, &x, &@as([4]bool, v))); } } }; diff --git a/test/tests.zig b/test/tests.zig index 2bb0f33487..513c960f95 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -325,7 +325,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M const exe = b.addExecutable("test-cli", "test/cli.zig"); const run_cmd = exe.run(); - run_cmd.addArgs([_][]const u8{ + run_cmd.addArgs(&[_][]const u8{ fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable, b.pathFromRoot(b.cache_root), }); @@ -411,7 +411,7 @@ pub fn addPkgTests( const ArchTag = @TagType(builtin.Arch); if (test_target.disable_native and test_target.target.getOs() == builtin.os and - @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch)) + @as(ArchTag, test_target.target.getArch()) == @as(ArchTag, builtin.arch)) { continue; } @@ -429,7 +429,7 @@ pub fn addPkgTests( "bare"; const triple_prefix = if (test_target.target == .Native) - @as([]const u8,"native") + @as([]const u8, "native") else test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; @@ -626,7 +626,7 @@ pub const CompareOutputContext = struct { warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); - const child = std.ChildProcess.init([_][]const u8{full_exe_path}, b.allocator) catch unreachable; + const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable; defer child.deinit(); child.env_map = b.env_map; @@ -667,7 +667,7 @@ pub const CompareOutputContext = struct { .expected_output = expected_output, .link_libc = false, .special = special, - .cli_args = [_][]const u8{}, + .cli_args = &[_][]const u8{}, }; const root_src_name = if (special == Special.Asm) "source.s" else "source.zig"; tc.addSourceFile(root_src_name, source); @@ -704,7 +704,7 @@ pub const CompareOutputContext = struct { const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, case.sources.items[0].filename }, ) catch unreachable; switch (case.special) { @@ -720,7 +720,7 @@ pub const CompareOutputContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); exe.step.dependOn(&write_src.step); @@ -752,7 +752,7 @@ pub const CompareOutputContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); exe.step.dependOn(&write_src.step); @@ -783,7 +783,7 @@ pub const CompareOutputContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); exe.step.dependOn(&write_src.step); @@ -816,7 +816,7 @@ pub const StackTracesContext = struct { const source_pathname = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, "source.zig" }, + &[_][]const u8{ b.cache_root, "source.zig" }, ) catch unreachable; for (self.modes) |mode| { @@ -1073,7 +1073,7 @@ pub const CompileErrorContext = struct { const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, ) catch unreachable; var zig_args = ArrayList([]const u8).init(b.allocator); @@ -1270,7 +1270,7 @@ pub const CompileErrorContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); compile_and_cmp_errors.step.dependOn(&write_src.step); @@ -1404,7 +1404,7 @@ pub const TranslateCContext = struct { const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, ) catch unreachable; var zig_args = ArrayList([]const u8).init(b.allocator); @@ -1577,7 +1577,7 @@ pub const TranslateCContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); translate_c_and_cmp.step.dependOn(&write_src.step); @@ -1700,7 +1700,7 @@ pub const GenHContext = struct { const b = self.b; const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, case.sources.items[0].filename }, ) catch unreachable; const mode = builtin.Mode.Debug; @@ -1715,7 +1715,7 @@ pub const GenHContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); obj.step.dependOn(&write_src.step); -- cgit v1.2.3 From 4b4fbe388732da795c924293b4d1af3d9ca5ea69 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Mon, 9 Dec 2019 21:56:19 +0100 Subject: Replace @typeOf with @TypeOf in all zig source This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually. --- lib/std/array_list.zig | 2 +- lib/std/atomic/queue.zig | 2 +- lib/std/atomic/stack.zig | 2 +- lib/std/debug.zig | 8 +- lib/std/event/group.zig | 2 +- lib/std/event/loop.zig | 2 +- lib/std/fmt.zig | 66 +++++++-------- lib/std/hash/auto_hash.zig | 6 +- lib/std/hash/cityhash.zig | 8 +- lib/std/hash/murmur.zig | 8 +- lib/std/http/headers.zig | 2 +- lib/std/io.zig | 8 +- lib/std/json.zig | 6 +- lib/std/json/write_stream.zig | 4 +- lib/std/math.zig | 68 +++++++-------- lib/std/math/acos.zig | 4 +- lib/std/math/acosh.zig | 4 +- lib/std/math/asin.zig | 4 +- lib/std/math/asinh.zig | 4 +- lib/std/math/atan.zig | 4 +- lib/std/math/atanh.zig | 4 +- lib/std/math/big/int.zig | 4 +- lib/std/math/cbrt.zig | 4 +- lib/std/math/ceil.zig | 4 +- lib/std/math/complex/abs.zig | 4 +- lib/std/math/complex/acos.zig | 4 +- lib/std/math/complex/acosh.zig | 4 +- lib/std/math/complex/arg.zig | 4 +- lib/std/math/complex/asin.zig | 4 +- lib/std/math/complex/asinh.zig | 4 +- lib/std/math/complex/atan.zig | 4 +- lib/std/math/complex/atanh.zig | 4 +- lib/std/math/complex/conj.zig | 4 +- lib/std/math/complex/cos.zig | 4 +- lib/std/math/complex/cosh.zig | 4 +- lib/std/math/complex/exp.zig | 4 +- lib/std/math/complex/ldexp.zig | 4 +- lib/std/math/complex/log.zig | 4 +- lib/std/math/complex/proj.zig | 4 +- lib/std/math/complex/sin.zig | 4 +- lib/std/math/complex/sinh.zig | 4 +- lib/std/math/complex/sqrt.zig | 4 +- lib/std/math/complex/tan.zig | 4 +- lib/std/math/complex/tanh.zig | 4 +- lib/std/math/cos.zig | 4 +- lib/std/math/cosh.zig | 4 +- lib/std/math/exp.zig | 4 +- lib/std/math/exp2.zig | 4 +- lib/std/math/expm1.zig | 4 +- lib/std/math/expo2.zig | 4 +- lib/std/math/fabs.zig | 4 +- lib/std/math/floor.zig | 4 +- lib/std/math/frexp.zig | 4 +- lib/std/math/ilogb.zig | 2 +- lib/std/math/isfinite.zig | 2 +- lib/std/math/isinf.zig | 6 +- lib/std/math/isnormal.zig | 2 +- lib/std/math/ln.zig | 8 +- lib/std/math/log.zig | 4 +- lib/std/math/log10.zig | 8 +- lib/std/math/log1p.zig | 4 +- lib/std/math/log2.zig | 6 +- lib/std/math/modf.zig | 4 +- lib/std/math/round.zig | 4 +- lib/std/math/scalbn.zig | 4 +- lib/std/math/signbit.zig | 2 +- lib/std/math/sin.zig | 4 +- lib/std/math/sinh.zig | 4 +- lib/std/math/sqrt.zig | 4 +- lib/std/math/tan.zig | 4 +- lib/std/math/tanh.zig | 4 +- lib/std/math/trunc.zig | 4 +- lib/std/mem.zig | 36 ++++---- lib/std/meta.zig | 14 ++-- lib/std/meta/trait.zig | 42 +++++----- lib/std/mutex.zig | 2 +- lib/std/net.zig | 2 +- lib/std/os.zig | 2 +- lib/std/os/linux.zig | 4 +- lib/std/os/uefi.zig | 2 +- lib/std/os/windows/kernel32.zig | 4 +- lib/std/pdb.zig | 2 +- lib/std/reset_event.zig | 12 +-- lib/std/segmented_list.zig | 4 +- lib/std/special/build_runner.zig | 2 +- lib/std/special/compiler_rt.zig | 8 +- lib/std/special/start.zig | 8 +- lib/std/testing.zig | 10 +-- lib/std/thread.zig | 8 +- lib/std/zig/render.zig | 30 +++---- src-self-hosted/dep_tokenizer.zig | 4 +- src-self-hosted/ir.zig | 2 +- src-self-hosted/libc_installation.zig | 2 +- src-self-hosted/translate_c.zig | 4 +- src-self-hosted/type.zig | 6 +- test/compare_output.zig | 4 +- test/compile_errors.zig | 130 ++++++++++++++--------------- test/stage1/behavior/align.zig | 42 +++++----- test/stage1/behavior/array.zig | 6 +- test/stage1/behavior/async_fn.zig | 24 +++--- test/stage1/behavior/atomics.zig | 4 +- test/stage1/behavior/bugs/1851.zig | 2 +- test/stage1/behavior/bugs/2114.zig | 2 +- test/stage1/behavior/bugs/3742.zig | 2 +- test/stage1/behavior/bugs/655.zig | 2 +- test/stage1/behavior/bugs/718.zig | 2 +- test/stage1/behavior/cast.zig | 20 ++--- test/stage1/behavior/error.zig | 6 +- test/stage1/behavior/eval.zig | 4 +- test/stage1/behavior/fn.zig | 8 +- test/stage1/behavior/for.zig | 4 +- test/stage1/behavior/generics.zig | 2 +- test/stage1/behavior/math.zig | 6 +- test/stage1/behavior/misc.zig | 20 ++--- test/stage1/behavior/pointers.zig | 30 ++++--- test/stage1/behavior/ptrcast.zig | 2 +- test/stage1/behavior/reflection.zig | 12 +-- test/stage1/behavior/sizeof_and_typeof.zig | 20 ++--- test/stage1/behavior/switch.zig | 4 +- test/stage1/behavior/type.zig | 4 +- test/stage1/behavior/type_info.zig | 6 +- test/stage1/behavior/undefined.zig | 2 +- test/stage1/behavior/vector.zig | 2 +- test/translate_c.zig | 2 +- tools/merge_anal_dumps.zig | 2 +- 125 files changed, 508 insertions(+), 504 deletions(-) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index c718972537..33260a88df 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -40,7 +40,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { .allocator = allocator, }; } - + /// Initialize with capacity to hold at least num elements. /// Deinitialize with `deinit` or use `toOwnedSlice`. pub fn initCapacity(allocator: *Allocator, num: usize) !Self { diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index 63bacb4fb5..f5dbd04da7 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -106,7 +106,7 @@ pub fn Queue(comptime T: type) type { pub fn dump(self: *Self) void { var stderr_file = std.io.getStdErr() catch return; const stderr = &stderr_file.outStream().stream; - const Error = @typeInfo(@typeOf(stderr)).Pointer.child.Error; + const Error = @typeInfo(@TypeOf(stderr)).Pointer.child.Error; self.dumpToStream(Error, stderr) catch return; } diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index 9de8e36f87..0f67a257cc 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -9,7 +9,7 @@ const expect = std.testing.expect; pub fn Stack(comptime T: type) type { return struct { root: ?*Node, - lock: @typeOf(lock_init), + lock: @TypeOf(lock_init), const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 04a83c39f3..69b9e894bb 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct { try di.dwarf_seekable_stream.seekTo(this_unit_offset); var is_64: bool = undefined; - const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); + const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); if (unit_length == 0) return; const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); @@ -1392,7 +1392,7 @@ pub const DwarfInfo = struct { try di.dwarf_seekable_stream.seekTo(this_unit_offset); var is_64: bool = undefined; - const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); + const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); if (unit_length == 0) return; const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); @@ -1551,7 +1551,7 @@ pub const DwarfInfo = struct { try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset); var is_64: bool = undefined; - const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); + const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); if (unit_length == 0) { return error.MissingDebugInfo; } @@ -2080,7 +2080,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, DW.FORM_indirect => { const child_form_id = try noasync leb.readULEB128(u64, in_stream); - const F = @typeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64)); + const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64)); var frame = try allocator.create(F); defer allocator.destroy(frame); return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64); diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig index d9076ef78d..2668096615 100644 --- a/lib/std/event/group.zig +++ b/lib/std/event/group.zig @@ -61,7 +61,7 @@ pub fn Group(comptime ReturnType: type) type { /// `func` must be async and have return type `ReturnType`. /// Thread-safe. pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void { - var frame = try self.allocator.create(@typeOf(@call(.{ .modifier = .async_kw }, func, args))); + var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args))); errdefer self.allocator.destroy(frame); const node = try self.allocator.create(AllocStack.Node); errdefer self.allocator.destroy(node); diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index 3a6cced79b..e80266c640 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -42,7 +42,7 @@ pub const Loop = struct { }, else => {}, }; - pub const Overlapped = @typeOf(overlapped_init); + pub const Overlapped = @TypeOf(overlapped_init); pub const Id = enum { Basic, diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index f01510b02c..be4b0989c7 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -89,7 +89,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool { pub fn format( context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: var, ) Errors!void { @@ -320,17 +320,17 @@ pub fn formatType( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, max_depth: usize, ) Errors!void { if (comptime std.mem.eql(u8, fmt, "*")) { - try output(context, @typeName(@typeOf(value).Child)); + try output(context, @typeName(@TypeOf(value).Child)); try output(context, "@"); try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output); return; } - const T = @typeOf(value); + const T = @TypeOf(value); switch (@typeInfo(T)) { .ComptimeInt, .Int, .Float => { return formatValue(value, fmt, options, context, Errors, output); @@ -478,7 +478,7 @@ fn formatValue( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (comptime std.mem.eql(u8, fmt, "B")) { return formatBytes(value, options, 1000, context, Errors, output); @@ -486,7 +486,7 @@ fn formatValue( return formatBytes(value, options, 1024, context, Errors, output); } - const T = @typeOf(value); + const T = @TypeOf(value); switch (@typeId(T)) { .Float => return formatFloatValue(value, fmt, options, context, Errors, output), .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output), @@ -500,12 +500,12 @@ pub fn formatIntValue( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { comptime var radix = 10; comptime var uppercase = false; - const int_value = if (@typeOf(value) == comptime_int) blk: { + const int_value = if (@TypeOf(value) == comptime_int) blk: { const Int = math.IntFittingRange(value, value); break :blk @as(Int, value); } else @@ -515,7 +515,7 @@ pub fn formatIntValue( radix = 10; uppercase = false; } else if (comptime std.mem.eql(u8, fmt, "c")) { - if (@typeOf(int_value).bit_count <= 8) { + if (@TypeOf(int_value).bit_count <= 8) { return formatAsciiChar(@as(u8, int_value), options, context, Errors, output); } else { @compileError("Cannot print integer that is larger than 8 bits as a ascii"); @@ -542,7 +542,7 @@ fn formatFloatValue( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { return formatFloatScientific(value, options, context, Errors, output); @@ -559,7 +559,7 @@ pub fn formatText( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0) { return output(context, bytes); @@ -580,7 +580,7 @@ pub fn formatAsciiChar( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { return output(context, @as(*const [1]u8, &c)[0..]); } @@ -590,7 +590,7 @@ pub fn formatBuf( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { try output(context, buf); @@ -610,7 +610,7 @@ pub fn formatFloatScientific( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { var x = @floatCast(f64, value); @@ -672,7 +672,7 @@ pub fn formatFloatScientific( try output(context, float_decimal.digits[0..1]); try output(context, "."); if (float_decimal.digits.len > 1) { - const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; + const num_digits = if (@TypeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; try output(context, float_decimal.digits[1..num_digits]); } else { @@ -705,7 +705,7 @@ pub fn formatFloatDecimal( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { var x = @as(f64, value); @@ -851,7 +851,7 @@ pub fn formatBytes( comptime radix: usize, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (value == 0) { return output(context, "0B"); @@ -892,15 +892,15 @@ pub fn formatInt( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { - const int_value = if (@typeOf(value) == comptime_int) blk: { + const int_value = if (@TypeOf(value) == comptime_int) blk: { const Int = math.IntFittingRange(value, value); break :blk @as(Int, value); } else value; - if (@typeOf(int_value).is_signed) { + if (@TypeOf(int_value).is_signed) { return formatIntSigned(int_value, base, uppercase, options, context, Errors, output); } else { return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output); @@ -914,7 +914,7 @@ fn formatIntSigned( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { const new_options = FormatOptions{ .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null, @@ -922,7 +922,7 @@ fn formatIntSigned( .fill = options.fill, }; - const uint = @IntType(false, @typeOf(value).bit_count); + const uint = @IntType(false, @TypeOf(value).bit_count); if (value < 0) { const minus_sign: u8 = '-'; try output(context, @as(*const [1]u8, &minus_sign)[0..]); @@ -945,12 +945,12 @@ fn formatIntUnsigned( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { assert(base >= 2); - var buf: [math.max(@typeOf(value).bit_count, 1)]u8 = undefined; - const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count); - const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); + var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined; + const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count); + const MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits); var a: MinInt = value; var index: usize = buf.len; @@ -1420,7 +1420,7 @@ test "custom" { options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); @@ -1610,7 +1610,7 @@ test "formatIntValue with comptime_int" { const value: comptime_int = 123456789123456789; var buf = try std.Buffer.init(std.debug.global_allocator, ""); - try formatIntValue(value, "", FormatOptions{}, &buf, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append); + try formatIntValue(value, "", FormatOptions{}, &buf, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append); std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789")); } @@ -1626,7 +1626,7 @@ test "formatType max_depth" { options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0) { return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); @@ -1664,19 +1664,19 @@ test "formatType max_depth" { inst.tu.ptr = &inst.tu; var buf0 = try std.Buffer.init(std.debug.global_allocator, ""); - try formatType(inst, "", FormatOptions{}, &buf0, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0); + try formatType(inst, "", FormatOptions{}, &buf0, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0); std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }")); var buf1 = try std.Buffer.init(std.debug.global_allocator, ""); - try formatType(inst, "", FormatOptions{}, &buf1, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1); + try formatType(inst, "", FormatOptions{}, &buf1, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1); std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); var buf2 = try std.Buffer.init(std.debug.global_allocator, ""); - try formatType(inst, "", FormatOptions{}, &buf2, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2); + try formatType(inst, "", FormatOptions{}, &buf2, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2); std.testing.expect(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }")); var buf3 = try std.Buffer.init(std.debug.global_allocator, ""); - try formatType(inst, "", FormatOptions{}, &buf3, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3); + try formatType(inst, "", FormatOptions{}, &buf3, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3); std.testing.expect(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }")); } diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 696a5e81dc..e60a1c1055 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -22,7 +22,7 @@ pub const HashStrategy = enum { /// Helper function to hash a pointer and mutate the strategy if needed. pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void { - const info = @typeInfo(@typeOf(key)); + const info = @typeInfo(@TypeOf(key)); switch (info.Pointer.size) { builtin.TypeInfo.Pointer.Size.One => switch (strat) { @@ -74,7 +74,7 @@ pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void { /// Provides generic hashing for any eligible type. /// Strategy is provided to determine if pointers should be followed or not. pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { - const Key = @typeOf(key); + const Key = @TypeOf(key); switch (@typeInfo(Key)) { .NoReturn, .Opaque, @@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { /// Only hashes `key` itself, pointers are not followed. /// Slices are rejected to avoid ambiguity on the user's intention. pub fn autoHash(hasher: var, key: var) void { - const Key = @typeOf(key); + const Key = @TypeOf(key); if (comptime meta.trait.isSlice(Key)) { comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated const extra_help = if (Key == []const u8) diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 0f78140c9d..18b3abe16d 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -360,9 +360,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { var hashes: [hashbytes * 256]u8 = undefined; var final: [hashbytes]u8 = undefined; - @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); - @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); - @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); + @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key))); + @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes))); + @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final))); var i: u32 = 0; while (i < 256) : (i += 1) { @@ -370,7 +370,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { var h = hash_fn(key[0..i], 256 - i); if (builtin.endian == builtin.Endian.Big) - h = @byteSwap(@typeOf(h), h); + h = @byteSwap(@TypeOf(h), h); @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); } diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index 0163927010..f6c0ccafb3 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { var hashes: [hashbytes * 256]u8 = undefined; var final: [hashbytes]u8 = undefined; - @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); - @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); - @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); + @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key))); + @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes))); + @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final))); var i: u32 = 0; while (i < 256) : (i += 1) { @@ -295,7 +295,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { var h = hash_fn(key[0..i], 256 - i); if (builtin.endian == builtin.Endian.Big) - h = @byteSwap(@typeOf(h), h); + h = @byteSwap(@TypeOf(h), h); @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); } diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index 7cac6648de..e02a2187d6 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -367,7 +367,7 @@ pub const Headers = struct { options: std.fmt.FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { var it = self.iterator(); while (it.next()) |entry| { diff --git a/lib/std/io.zig b/lib/std/io.zig index 68c147a33c..c8635b8551 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -663,7 +663,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type { pub fn writeBits(self: *Self, value: var, bits: usize) Error!void { if (bits == 0) return; - const U = @typeOf(value); + const U = @TypeOf(value); comptime assert(trait.isUnsignedInt(U)); //by extending the buffer to a minimum of u8 we can cover a number of edge cases @@ -962,7 +962,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, /// Deserializes data into the type pointed to by `ptr` pub fn deserializeInto(self: *Self, ptr: var) !void { - const T = @typeOf(ptr); + const T = @TypeOf(ptr); comptime assert(trait.is(builtin.TypeId.Pointer)(T)); if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) { @@ -1091,7 +1091,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co } fn serializeInt(self: *Self, value: var) Error!void { - const T = @typeOf(value); + const T = @TypeOf(value); comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T)); const t_bit_count = comptime meta.bitCount(T); @@ -1123,7 +1123,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co /// Serializes the passed value into the stream pub fn serialize(self: *Self, value: var) Error!void { - const T = comptime @typeOf(value); + const T = comptime @TypeOf(value); if (comptime trait.isIndexable(T)) { for (value) |v| diff --git a/lib/std/json.zig b/lib/std/json.zig index a02c4ca733..c1a0b42009 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1038,7 +1038,7 @@ pub const Value = union(enum) { } pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void { - var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream); + var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream); w.newline = ""; w.one_indent = ""; w.space = ""; @@ -1048,7 +1048,7 @@ pub const Value = union(enum) { pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void { var one_indent = " " ** indent; - var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream); + var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream); w.one_indent = one_indent; try w.emitJson(self); } @@ -1338,7 +1338,7 @@ test "write json then parse it" { var slice_out_stream = std.io.SliceOutStream.init(&out_buffer); const out_stream = &slice_out_stream.stream; - var jw = WriteStream(@typeOf(out_stream).Child, 4).init(out_stream); + var jw = WriteStream(@TypeOf(out_stream).Child, 4).init(out_stream); try jw.beginObject(); diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig index 7cff613dad..51afe7fcbc 100644 --- a/lib/std/json/write_stream.zig +++ b/lib/std/json/write_stream.zig @@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { value: var, ) !void { assert(self.state[self.state_index] == State.Value); - switch (@typeInfo(@typeOf(value))) { + switch (@typeInfo(@TypeOf(value))) { .Int => |info| { if (info.bits < 53) { try self.stream.print("{}", .{value}); @@ -257,7 +257,7 @@ test "json write stream" { var mem_buf: [1024 * 10]u8 = undefined; const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator; - var w = std.json.WriteStream(@typeOf(out).Child, 10).init(out); + var w = std.json.WriteStream(@TypeOf(out).Child, 10).init(out); try w.emitJson(try getJson(allocator)); const result = slice_stream.getWritten(); diff --git a/lib/std/math.zig b/lib/std/math.zig index f87996f174..b3b50beac6 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -95,7 +95,7 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool { // TODO: Hide the following in an internal module. pub fn forceEval(value: var) void { - const T = @typeOf(value); + const T = @TypeOf(value); switch (T) { f16 => { var x: f16 = undefined; @@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type { }, else => {}, } - return @typeOf(@as(A, 0) + @as(B, 0)); + return @TypeOf(@as(A, 0) + @as(B, 0)); } /// Returns the smaller number. When one of the parameter's type's full range fits in the other, /// the return type is the smaller type. -pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { - const Result = Min(@typeOf(x), @typeOf(y)); +pub fn min(x: var, y: var) Min(@TypeOf(x), @TypeOf(y)) { + const Result = Min(@TypeOf(x), @TypeOf(y)); if (x < y) { // TODO Zig should allow this as an implicit cast because x is immutable and in this // scope it is known to fit in the return type. @@ -269,33 +269,33 @@ test "math.min" { var a: u16 = 999; var b: u32 = 10; var result = min(a, b); - testing.expect(@typeOf(result) == u16); + testing.expect(@TypeOf(result) == u16); testing.expect(result == 10); } { var a: f64 = 10.34; var b: f32 = 999.12; var result = min(a, b); - testing.expect(@typeOf(result) == f64); + testing.expect(@TypeOf(result) == f64); testing.expect(result == 10.34); } { var a: i8 = -127; var b: i16 = -200; var result = min(a, b); - testing.expect(@typeOf(result) == i16); + testing.expect(@TypeOf(result) == i16); testing.expect(result == -200); } { const a = 10.34; var b: f32 = 999.12; var result = min(a, b); - testing.expect(@typeOf(result) == f32); + testing.expect(@TypeOf(result) == f32); testing.expect(result == 10.34); } } -pub fn max(x: var, y: var) @typeOf(x + y) { +pub fn max(x: var, y: var) @TypeOf(x + y) { return if (x > y) x else y; } @@ -318,8 +318,8 @@ pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) { return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; } -pub fn negate(x: var) !@typeOf(x) { - return sub(@typeOf(x), 0, x); +pub fn negate(x: var) !@TypeOf(x) { + return sub(@TypeOf(x), 0, x); } pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T { @@ -333,7 +333,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { const abs_shift_amt = absCast(shift_amt); const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt); - if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) { + if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) { if (shift_amt < 0) { return a >> casted_shift_amt; } @@ -359,7 +359,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T { const abs_shift_amt = absCast(shift_amt); const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt); - if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) { + if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) { if (shift_amt >= 0) { return a >> casted_shift_amt; } else { @@ -505,12 +505,12 @@ fn testOverflow() void { testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); } -pub fn absInt(x: var) !@typeOf(x) { - const T = @typeOf(x); +pub fn absInt(x: var) !@TypeOf(x) { + const T = @TypeOf(x); comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt comptime assert(T.is_signed); // must pass a signed integer to absInt - if (x == minInt(@typeOf(x))) { + if (x == minInt(@TypeOf(x))) { return error.Overflow; } else { @setRuntimeSafety(false); @@ -654,16 +654,16 @@ fn testRem() void { /// Returns the absolute value of the integer parameter. /// Result is an unsigned integer. pub fn absCast(x: var) t: { - if (@typeOf(x) == comptime_int) { + if (@TypeOf(x) == comptime_int) { break :t comptime_int; } else { - break :t @IntType(false, @typeOf(x).bit_count); + break :t @IntType(false, @TypeOf(x).bit_count); } } { - if (@typeOf(x) == comptime_int) { + if (@TypeOf(x) == comptime_int) { return if (x < 0) -x else x; } - const uint = @IntType(false, @typeOf(x).bit_count); + const uint = @IntType(false, @TypeOf(x).bit_count); if (x >= 0) return @intCast(uint, x); return @intCast(uint, -(x + 1)) + 1; @@ -671,23 +671,23 @@ pub fn absCast(x: var) t: { test "math.absCast" { testing.expect(absCast(@as(i32, -999)) == 999); - testing.expect(@typeOf(absCast(@as(i32, -999))) == u32); + testing.expect(@TypeOf(absCast(@as(i32, -999))) == u32); testing.expect(absCast(@as(i32, 999)) == 999); - testing.expect(@typeOf(absCast(@as(i32, 999))) == u32); + testing.expect(@TypeOf(absCast(@as(i32, 999))) == u32); testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32)); - testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32); + testing.expect(@TypeOf(absCast(@as(i32, minInt(i32)))) == u32); testing.expect(absCast(-999) == 999); } /// Returns the negation of the integer parameter. /// Result is a signed integer. -pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { - if (@typeOf(x).is_signed) return negate(x); +pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) { + if (@TypeOf(x).is_signed) return negate(x); - const int = @IntType(true, @typeOf(x).bit_count); + const int = @IntType(true, @TypeOf(x).bit_count); if (x > -minInt(int)) return error.Overflow; if (x == -minInt(int)) return minInt(int); @@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { test "math.negateCast" { testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); - testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); + testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32)); - testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); + testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10))); } @@ -709,10 +709,10 @@ test "math.negateCast" { /// return an error. pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer - comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer - if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) { + comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer + if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) { return error.Overflow; - } else if (minInt(@typeOf(x)) < minInt(T) and x < minInt(T)) { + } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) { return error.Overflow; } else { return @intCast(T, x); @@ -726,13 +726,13 @@ test "math.cast" { testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255)); - testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8); + testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8); } pub const AlignCastError = error{UnalignedMemory}; /// Align cast a pointer but return an error if it's the wrong alignment -pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@typeOf(@alignCast(alignment, ptr)) { +pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) { const addr = @ptrToInt(ptr); if (addr % alignment != 0) { return error.UnalignedMemory; @@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" { } pub fn lossyCast(comptime T: type, value: var) T { - switch (@typeInfo(@typeOf(value))) { + switch (@typeInfo(@TypeOf(value))) { builtin.TypeId.Int => return @intToFloat(T, value), builtin.TypeId.Float => return @floatCast(T, value), builtin.TypeId.ComptimeInt => return @as(T, value), diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig index 94b6fc3f8f..aec0d4706a 100644 --- a/lib/std/math/acos.zig +++ b/lib/std/math/acos.zig @@ -12,8 +12,8 @@ const expect = std.testing.expect; /// /// Special cases: /// - acos(x) = nan if x < -1 or x > 1 -pub fn acos(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn acos(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => acos32(x), f64 => acos64(x), diff --git a/lib/std/math/acosh.zig b/lib/std/math/acosh.zig index 065e4d39de..0f99335058 100644 --- a/lib/std/math/acosh.zig +++ b/lib/std/math/acosh.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// Special cases: /// - acosh(x) = snan if x < 1 /// - acosh(nan) = nan -pub fn acosh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn acosh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => acosh32(x), f64 => acosh64(x), diff --git a/lib/std/math/asin.zig b/lib/std/math/asin.zig index d354f8ceed..db57e2088f 100644 --- a/lib/std/math/asin.zig +++ b/lib/std/math/asin.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - asin(+-0) = +-0 /// - asin(x) = nan if x < -1 or x > 1 -pub fn asin(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn asin(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => asin32(x), f64 => asin64(x), diff --git a/lib/std/math/asinh.zig b/lib/std/math/asinh.zig index b915df3171..ab1b650139 100644 --- a/lib/std/math/asinh.zig +++ b/lib/std/math/asinh.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; /// - asinh(+-0) = +-0 /// - asinh(+-inf) = +-inf /// - asinh(nan) = nan -pub fn asinh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn asinh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => asinh32(x), f64 => asinh64(x), diff --git a/lib/std/math/atan.zig b/lib/std/math/atan.zig index ea639872be..eb9154b5fe 100644 --- a/lib/std/math/atan.zig +++ b/lib/std/math/atan.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - atan(+-0) = +-0 /// - atan(+-inf) = +-pi/2 -pub fn atan(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn atan(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => atan32(x), f64 => atan64(x), diff --git a/lib/std/math/atanh.zig b/lib/std/math/atanh.zig index ae588f4fb8..e58a10fff5 100644 --- a/lib/std/math/atanh.zig +++ b/lib/std/math/atanh.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; /// - atanh(+-1) = +-inf with signal /// - atanh(x) = nan if |x| > 1 with signal /// - atanh(nan) = nan -pub fn atanh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn atanh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => atanh_32(x), f64 => atanh_64(x), diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 0d0b186332..ef83aceb2f 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -268,7 +268,7 @@ pub const Int = struct { /// Sets an Int to value. Value must be an primitive integer type. pub fn set(self: *Int, value: var) Allocator.Error!void { self.assertWritable(); - const T = @typeOf(value); + const T = @TypeOf(value); switch (@typeInfo(T)) { TypeId.Int => |info| { @@ -522,7 +522,7 @@ pub const Int = struct { options: std.fmt.FormatOptions, context: var, comptime FmtError: type, - output: fn (@typeOf(context), []const u8) FmtError!void, + output: fn (@TypeOf(context), []const u8) FmtError!void, ) FmtError!void { self.assertWritable(); // TODO look at fmt and support other bases diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig index c9e205a495..2b219d5368 100644 --- a/lib/std/math/cbrt.zig +++ b/lib/std/math/cbrt.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// - cbrt(+-0) = +-0 /// - cbrt(+-inf) = +-inf /// - cbrt(nan) = nan -pub fn cbrt(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn cbrt(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => cbrt32(x), f64 => cbrt64(x), diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig index b5a2238621..b94e13a176 100644 --- a/lib/std/math/ceil.zig +++ b/lib/std/math/ceil.zig @@ -15,8 +15,8 @@ const expect = std.testing.expect; /// - ceil(+-0) = +-0 /// - ceil(+-inf) = +-inf /// - ceil(nan) = nan -pub fn ceil(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn ceil(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => ceil32(x), f64 => ceil64(x), diff --git a/lib/std/math/complex/abs.zig b/lib/std/math/complex/abs.zig index 8105f57218..75b967f3d2 100644 --- a/lib/std/math/complex/abs.zig +++ b/lib/std/math/complex/abs.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the absolute value (modulus) of z. -pub fn abs(z: var) @typeOf(z.re) { - const T = @typeOf(z.re); +pub fn abs(z: var) @TypeOf(z.re) { + const T = @TypeOf(z.re); return math.hypot(T, z.re, z.im); } diff --git a/lib/std/math/complex/acos.zig b/lib/std/math/complex/acos.zig index b078ebf345..24a645375c 100644 --- a/lib/std/math/complex/acos.zig +++ b/lib/std/math/complex/acos.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the arc-cosine of z. -pub fn acos(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn acos(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = cmath.asin(z); return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im); } diff --git a/lib/std/math/complex/acosh.zig b/lib/std/math/complex/acosh.zig index 6f0fd2e36c..996334034a 100644 --- a/lib/std/math/complex/acosh.zig +++ b/lib/std/math/complex/acosh.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic arc-cosine of z. -pub fn acosh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn acosh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = cmath.acos(z); return Complex(T).new(-q.im, q.re); } diff --git a/lib/std/math/complex/arg.zig b/lib/std/math/complex/arg.zig index d0c9588b8d..f690e92143 100644 --- a/lib/std/math/complex/arg.zig +++ b/lib/std/math/complex/arg.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the angular component (in radians) of z. -pub fn arg(z: var) @typeOf(z.re) { - const T = @typeOf(z.re); +pub fn arg(z: var) @TypeOf(z.re) { + const T = @TypeOf(z.re); return math.atan2(T, z.im, z.re); } diff --git a/lib/std/math/complex/asin.zig b/lib/std/math/complex/asin.zig index 76f94a286c..01fa33156a 100644 --- a/lib/std/math/complex/asin.zig +++ b/lib/std/math/complex/asin.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; // Returns the arc-sine of z. -pub fn asin(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn asin(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const x = z.re; const y = z.im; diff --git a/lib/std/math/complex/asinh.zig b/lib/std/math/complex/asinh.zig index da065aad01..47d8244adb 100644 --- a/lib/std/math/complex/asinh.zig +++ b/lib/std/math/complex/asinh.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic arc-sine of z. -pub fn asinh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn asinh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = Complex(T).new(-z.im, z.re); const r = cmath.asin(q); return Complex(T).new(r.im, -r.re); diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig index 3cd19961c8..d5e3dcac73 100644 --- a/lib/std/math/complex/atan.zig +++ b/lib/std/math/complex/atan.zig @@ -12,8 +12,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the arc-tangent of z. -pub fn atan(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn atan(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => atan32(z), f64 => atan64(z), diff --git a/lib/std/math/complex/atanh.zig b/lib/std/math/complex/atanh.zig index 225e7c61de..8b70306224 100644 --- a/lib/std/math/complex/atanh.zig +++ b/lib/std/math/complex/atanh.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic arc-tangent of z. -pub fn atanh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn atanh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = Complex(T).new(-z.im, z.re); const r = cmath.atan(q); return Complex(T).new(r.im, -r.re); diff --git a/lib/std/math/complex/conj.zig b/lib/std/math/complex/conj.zig index bd71ca3c06..1065d4bb73 100644 --- a/lib/std/math/complex/conj.zig +++ b/lib/std/math/complex/conj.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the complex conjugate of z. -pub fn conj(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn conj(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); return Complex(T).new(z.re, -z.im); } diff --git a/lib/std/math/complex/cos.zig b/lib/std/math/complex/cos.zig index 332009ffe5..1aefa73db5 100644 --- a/lib/std/math/complex/cos.zig +++ b/lib/std/math/complex/cos.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the cosine of z. -pub fn cos(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn cos(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const p = Complex(T).new(-z.im, z.re); return cmath.cosh(p); } diff --git a/lib/std/math/complex/cosh.zig b/lib/std/math/complex/cosh.zig index 89afcac42e..ce2c78b455 100644 --- a/lib/std/math/complex/cosh.zig +++ b/lib/std/math/complex/cosh.zig @@ -14,8 +14,8 @@ const Complex = cmath.Complex; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; /// Returns the hyperbolic arc-cosine of z. -pub fn cosh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn cosh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); return switch (T) { f32 => cosh32(z), f64 => cosh64(z), diff --git a/lib/std/math/complex/exp.zig b/lib/std/math/complex/exp.zig index 5cd1cb4ed6..b39875c770 100644 --- a/lib/std/math/complex/exp.zig +++ b/lib/std/math/complex/exp.zig @@ -14,8 +14,8 @@ const Complex = cmath.Complex; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; /// Returns e raised to the power of z (e^z). -pub fn exp(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn exp(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => exp32(z), diff --git a/lib/std/math/complex/ldexp.zig b/lib/std/math/complex/ldexp.zig index d5d4cc64a6..9eccd4bb98 100644 --- a/lib/std/math/complex/ldexp.zig +++ b/lib/std/math/complex/ldexp.zig @@ -11,8 +11,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns exp(z) scaled to avoid overflow. -pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) { - const T = @typeOf(z.re); +pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => ldexp_cexp32(z, expt), diff --git a/lib/std/math/complex/log.zig b/lib/std/math/complex/log.zig index 762b4fde9a..f1fad3175e 100644 --- a/lib/std/math/complex/log.zig +++ b/lib/std/math/complex/log.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the natural logarithm of z. -pub fn log(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn log(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const r = cmath.abs(z); const phi = cmath.arg(z); diff --git a/lib/std/math/complex/proj.zig b/lib/std/math/complex/proj.zig index c8f2d9fc6d..349f6b3abb 100644 --- a/lib/std/math/complex/proj.zig +++ b/lib/std/math/complex/proj.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the projection of z onto the riemann sphere. -pub fn proj(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn proj(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); if (math.isInf(z.re) or math.isInf(z.im)) { return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re)); diff --git a/lib/std/math/complex/sin.zig b/lib/std/math/complex/sin.zig index 9ddc3a7a80..87dc57911b 100644 --- a/lib/std/math/complex/sin.zig +++ b/lib/std/math/complex/sin.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the sine of z. -pub fn sin(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn sin(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const p = Complex(T).new(-z.im, z.re); const q = cmath.sinh(p); return Complex(T).new(q.im, -q.re); diff --git a/lib/std/math/complex/sinh.zig b/lib/std/math/complex/sinh.zig index 0b1294bb6a..d633bcc37e 100644 --- a/lib/std/math/complex/sinh.zig +++ b/lib/std/math/complex/sinh.zig @@ -14,8 +14,8 @@ const Complex = cmath.Complex; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; /// Returns the hyperbolic sine of z. -pub fn sinh(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn sinh(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => sinh32(z), f64 => sinh64(z), diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig index 7e17f422bb..57e73f6cd1 100644 --- a/lib/std/math/complex/sqrt.zig +++ b/lib/std/math/complex/sqrt.zig @@ -12,8 +12,8 @@ const Complex = cmath.Complex; /// Returns the square root of z. The real and imaginary parts of the result have the same sign /// as the imaginary part of z. -pub fn sqrt(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn sqrt(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => sqrt32(z), diff --git a/lib/std/math/complex/tan.zig b/lib/std/math/complex/tan.zig index 398b8295ca..70304803db 100644 --- a/lib/std/math/complex/tan.zig +++ b/lib/std/math/complex/tan.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the tanget of z. -pub fn tan(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn tan(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = Complex(T).new(-z.im, z.re); const r = cmath.tanh(q); return Complex(T).new(r.im, -r.re); diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig index fc7f4e9ea8..3249a4309d 100644 --- a/lib/std/math/complex/tanh.zig +++ b/lib/std/math/complex/tanh.zig @@ -12,8 +12,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic tangent of z. -pub fn tanh(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn tanh(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => tanh32(z), f64 => tanh64(z), diff --git a/lib/std/math/cos.zig b/lib/std/math/cos.zig index 68e13e41bf..66a1cc8509 100644 --- a/lib/std/math/cos.zig +++ b/lib/std/math/cos.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - cos(+-inf) = nan /// - cos(nan) = nan -pub fn cos(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn cos(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => cos_(f32, x), f64 => cos_(f64, x), diff --git a/lib/std/math/cosh.zig b/lib/std/math/cosh.zig index 62bedeaa49..17c291d947 100644 --- a/lib/std/math/cosh.zig +++ b/lib/std/math/cosh.zig @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; /// - cosh(+-0) = 1 /// - cosh(+-inf) = +inf /// - cosh(nan) = nan -pub fn cosh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn cosh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => cosh32(x), f64 => cosh64(x), diff --git a/lib/std/math/exp.zig b/lib/std/math/exp.zig index 986c35bf0d..da80b201c0 100644 --- a/lib/std/math/exp.zig +++ b/lib/std/math/exp.zig @@ -14,8 +14,8 @@ const builtin = @import("builtin"); /// Special Cases: /// - exp(+inf) = +inf /// - exp(nan) = nan -pub fn exp(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn exp(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => exp32(x), f64 => exp64(x), diff --git a/lib/std/math/exp2.zig b/lib/std/math/exp2.zig index f3e51e542e..411f789187 100644 --- a/lib/std/math/exp2.zig +++ b/lib/std/math/exp2.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - exp2(+inf) = +inf /// - exp2(nan) = nan -pub fn exp2(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn exp2(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => exp2_32(x), f64 => exp2_64(x), diff --git a/lib/std/math/expm1.zig b/lib/std/math/expm1.zig index 871fa38449..91752e9f80 100644 --- a/lib/std/math/expm1.zig +++ b/lib/std/math/expm1.zig @@ -18,8 +18,8 @@ const expect = std.testing.expect; /// - expm1(+inf) = +inf /// - expm1(-inf) = -1 /// - expm1(nan) = nan -pub fn expm1(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn expm1(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => expm1_32(x), f64 => expm1_64(x), diff --git a/lib/std/math/expo2.zig b/lib/std/math/expo2.zig index 590f36bb18..e70e365f26 100644 --- a/lib/std/math/expo2.zig +++ b/lib/std/math/expo2.zig @@ -7,8 +7,8 @@ const math = @import("../math.zig"); /// Returns exp(x) / 2 for x >= log(maxFloat(T)). -pub fn expo2(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn expo2(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => expo2f(x), f64 => expo2d(x), diff --git a/lib/std/math/fabs.zig b/lib/std/math/fabs.zig index e0eadd0d00..a659e35ca2 100644 --- a/lib/std/math/fabs.zig +++ b/lib/std/math/fabs.zig @@ -14,8 +14,8 @@ const maxInt = std.math.maxInt; /// Special Cases: /// - fabs(+-inf) = +inf /// - fabs(nan) = nan -pub fn fabs(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn fabs(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f16 => fabs16(x), f32 => fabs32(x), diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig index f2cabe8f02..1eda362e69 100644 --- a/lib/std/math/floor.zig +++ b/lib/std/math/floor.zig @@ -15,8 +15,8 @@ const math = std.math; /// - floor(+-0) = +-0 /// - floor(+-inf) = +-inf /// - floor(nan) = nan -pub fn floor(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn floor(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f16 => floor16(x), f32 => floor32(x), diff --git a/lib/std/math/frexp.zig b/lib/std/math/frexp.zig index 93705ae6a4..cfdf9f838d 100644 --- a/lib/std/math/frexp.zig +++ b/lib/std/math/frexp.zig @@ -24,8 +24,8 @@ pub const frexp64_result = frexp_result(f64); /// - frexp(+-0) = +-0, 0 /// - frexp(+-inf) = +-inf, 0 /// - frexp(nan) = nan, undefined -pub fn frexp(x: var) frexp_result(@typeOf(x)) { - const T = @typeOf(x); +pub fn frexp(x: var) frexp_result(@TypeOf(x)) { + const T = @TypeOf(x); return switch (T) { f32 => frexp32(x), f64 => frexp64(x), diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig index 8d23bb09a0..22e3fbaa97 100644 --- a/lib/std/math/ilogb.zig +++ b/lib/std/math/ilogb.zig @@ -17,7 +17,7 @@ const minInt = std.math.minInt; /// - ilogb(0) = maxInt(i32) /// - ilogb(nan) = maxInt(i32) pub fn ilogb(x: var) i32 { - const T = @typeOf(x); + const T = @TypeOf(x); return switch (T) { f32 => ilogb32(x), f64 => ilogb64(x), diff --git a/lib/std/math/isfinite.zig b/lib/std/math/isfinite.zig index 3d23a0f3bf..26b3ce54a1 100644 --- a/lib/std/math/isfinite.zig +++ b/lib/std/math/isfinite.zig @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; /// Returns whether x is a finite value. pub fn isFinite(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { const bits = @bitCast(u16, x); diff --git a/lib/std/math/isinf.zig b/lib/std/math/isinf.zig index d691068be5..6eacab52ad 100644 --- a/lib/std/math/isinf.zig +++ b/lib/std/math/isinf.zig @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; /// Returns whether x is an infinity, ignoring sign. pub fn isInf(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { const bits = @bitCast(u16, x); @@ -31,7 +31,7 @@ pub fn isInf(x: var) bool { /// Returns whether x is an infinity with a positive sign. pub fn isPositiveInf(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { return @bitCast(u16, x) == 0x7C00; @@ -53,7 +53,7 @@ pub fn isPositiveInf(x: var) bool { /// Returns whether x is an infinity with a negative sign. pub fn isNegativeInf(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { return @bitCast(u16, x) == 0xFC00; diff --git a/lib/std/math/isnormal.zig b/lib/std/math/isnormal.zig index 01d919d417..917b4ebfcf 100644 --- a/lib/std/math/isnormal.zig +++ b/lib/std/math/isnormal.zig @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; // Returns whether x has a normalized representation (i.e. integer part of mantissa is 1). pub fn isNormal(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { const bits = @bitCast(u16, x); diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig index fd5741a818..f9bf03f83d 100644 --- a/lib/std/math/ln.zig +++ b/lib/std/math/ln.zig @@ -17,11 +17,11 @@ const TypeId = builtin.TypeId; /// - ln(0) = -inf /// - ln(x) = nan if x < 0 /// - ln(nan) = nan -pub fn ln(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn ln(x: var) @TypeOf(x) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(ln_64(x)); + return @TypeOf(1.0)(ln_64(x)); }, TypeId.Float => { return switch (T) { @@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) { }; }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(ln_64(@as(f64, x)))); + return @TypeOf(1)(math.floor(ln_64(@as(f64, x)))); }, TypeId.Int => { return @as(T, math.floor(ln_64(@as(f64, x)))); diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index 40b716b005..1302b564b6 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T { const float_base = math.lossyCast(f64, base); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base)); + return @TypeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base)); }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); + return @TypeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); }, builtin.TypeId.Int => { // TODO implement integer log without using float math diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index f895e102a0..873b33bdbe 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -18,11 +18,11 @@ const maxInt = std.math.maxInt; /// - log10(0) = -inf /// - log10(x) = nan if x < 0 /// - log10(nan) = nan -pub fn log10(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn log10(x: var) @TypeOf(x) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(log10_64(x)); + return @TypeOf(1.0)(log10_64(x)); }, TypeId.Float => { return switch (T) { @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { }; }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(log10_64(@as(f64, x)))); + return @TypeOf(1)(math.floor(log10_64(@as(f64, x)))); }, TypeId.Int => { return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); diff --git a/lib/std/math/log1p.zig b/lib/std/math/log1p.zig index 047e089a91..5e92cfdea3 100644 --- a/lib/std/math/log1p.zig +++ b/lib/std/math/log1p.zig @@ -17,8 +17,8 @@ const expect = std.testing.expect; /// - log1p(-1) = -inf /// - log1p(x) = nan if x < -1 /// - log1p(nan) = nan -pub fn log1p(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn log1p(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => log1p_32(x), f64 => log1p_64(x), diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index 47b214d6cf..bf052db59b 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -18,11 +18,11 @@ const maxInt = std.math.maxInt; /// - log2(0) = -inf /// - log2(x) = nan if x < 0 /// - log2(nan) = nan -pub fn log2(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn log2(x: var) @TypeOf(x) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(log2_64(x)); + return @TypeOf(1.0)(log2_64(x)); }, TypeId.Float => { return switch (T) { diff --git a/lib/std/math/modf.zig b/lib/std/math/modf.zig index 6567cbc9ed..6fd89e3dda 100644 --- a/lib/std/math/modf.zig +++ b/lib/std/math/modf.zig @@ -24,8 +24,8 @@ pub const modf64_result = modf_result(f64); /// Special Cases: /// - modf(+-inf) = +-inf, nan /// - modf(nan) = nan, nan -pub fn modf(x: var) modf_result(@typeOf(x)) { - const T = @typeOf(x); +pub fn modf(x: var) modf_result(@TypeOf(x)) { + const T = @TypeOf(x); return switch (T) { f32 => modf32(x), f64 => modf64(x), diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig index adedbf2e94..dceb3ed770 100644 --- a/lib/std/math/round.zig +++ b/lib/std/math/round.zig @@ -15,8 +15,8 @@ const math = std.math; /// - round(+-0) = +-0 /// - round(+-inf) = +-inf /// - round(nan) = nan -pub fn round(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn round(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => round32(x), f64 => round64(x), diff --git a/lib/std/math/scalbn.zig b/lib/std/math/scalbn.zig index e3c457ade5..bab109f334 100644 --- a/lib/std/math/scalbn.zig +++ b/lib/std/math/scalbn.zig @@ -9,8 +9,8 @@ const math = std.math; const expect = std.testing.expect; /// Returns x * 2^n. -pub fn scalbn(x: var, n: i32) @typeOf(x) { - const T = @typeOf(x); +pub fn scalbn(x: var, n: i32) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => scalbn32(x, n), f64 => scalbn64(x, n), diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig index f20753f2ff..9cb62b5042 100644 --- a/lib/std/math/signbit.zig +++ b/lib/std/math/signbit.zig @@ -4,7 +4,7 @@ const expect = std.testing.expect; /// Returns whether x is negative or negative 0. pub fn signbit(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); return switch (T) { f16 => signbit16(x), f32 => signbit32(x), diff --git a/lib/std/math/sin.zig b/lib/std/math/sin.zig index 3baa730123..5b92fd454b 100644 --- a/lib/std/math/sin.zig +++ b/lib/std/math/sin.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// - sin(+-0) = +-0 /// - sin(+-inf) = nan /// - sin(nan) = nan -pub fn sin(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn sin(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => sin_(T, x), f64 => sin_(T, x), diff --git a/lib/std/math/sinh.zig b/lib/std/math/sinh.zig index c9718e3ce2..e9c76cd509 100644 --- a/lib/std/math/sinh.zig +++ b/lib/std/math/sinh.zig @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; /// - sinh(+-0) = +-0 /// - sinh(+-inf) = +-inf /// - sinh(nan) = nan -pub fn sinh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn sinh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => sinh32(x), f64 => sinh64(x), diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index 89eda4ea2b..17c7003af1 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -12,8 +12,8 @@ const maxInt = std.math.maxInt; /// - sqrt(+-0) = +-0 /// - sqrt(x) = nan if x < 0 /// - sqrt(nan) = nan -pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { - const T = @typeOf(x); +pub fn sqrt(x: var) (if (@typeId(@TypeOf(x)) == TypeId.Int) @IntType(false, @TypeOf(x).bit_count / 2) else @TypeOf(x)) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128 TypeId.Float => return @sqrt(T, x), diff --git a/lib/std/math/tan.zig b/lib/std/math/tan.zig index 1a027cf403..14272a48e2 100644 --- a/lib/std/math/tan.zig +++ b/lib/std/math/tan.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// - tan(+-0) = +-0 /// - tan(+-inf) = nan /// - tan(nan) = nan -pub fn tan(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn tan(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => tan_(f32, x), f64 => tan_(f64, x), diff --git a/lib/std/math/tanh.zig b/lib/std/math/tanh.zig index ced5f58bcc..1cad399729 100644 --- a/lib/std/math/tanh.zig +++ b/lib/std/math/tanh.zig @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; /// - sinh(+-0) = +-0 /// - sinh(+-inf) = +-1 /// - sinh(nan) = nan -pub fn tanh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn tanh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => tanh32(x), f64 => tanh64(x), diff --git a/lib/std/math/trunc.zig b/lib/std/math/trunc.zig index 56a842345c..b70f0c6be3 100644 --- a/lib/std/math/trunc.zig +++ b/lib/std/math/trunc.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; /// - trunc(+-0) = +-0 /// - trunc(+-inf) = +-inf /// - trunc(nan) = nan -pub fn trunc(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn trunc(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => trunc32(x), f64 => trunc64(x), diff --git a/lib/std/mem.zig b/lib/std/mem.zig index cba1f9f177..8082d31063 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -86,7 +86,7 @@ pub const Allocator = struct { /// `ptr` should be the return value of `create`, or otherwise /// have the same address and alignment property. pub fn destroy(self: *Allocator, ptr: var) void { - const T = @typeOf(ptr).Child; + const T = @TypeOf(ptr).Child; if (@sizeOf(T) == 0) return; const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr)); const shrink_result = self.shrinkFn(self, non_const_ptr[0..@sizeOf(T)], @alignOf(T), 0, 1); @@ -147,10 +147,10 @@ pub const Allocator = struct { /// If you need guaranteed success, call `shrink`. /// If `new_n` is 0, this is the same as `free` and it always succeeds. pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; break :t Error![]align(Slice.alignment) Slice.child; } { - const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment; + const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment; return self.alignedRealloc(old_mem, old_alignment, new_n); } @@ -162,8 +162,8 @@ pub const Allocator = struct { old_mem: var, comptime new_alignment: u29, new_n: usize, - ) Error![]align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + ) Error![]align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child { + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; const T = Slice.child; if (old_mem.len == 0) { return self.alignedAlloc(T, new_alignment, new_n); @@ -189,10 +189,10 @@ pub const Allocator = struct { /// Returned slice has same alignment as old_mem. /// Shrinking to 0 is the same as calling `free`. pub fn shrink(self: *Allocator, old_mem: var, new_n: usize) t: { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; break :t []align(Slice.alignment) Slice.child; } { - const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment; + const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment; return self.alignedShrink(old_mem, old_alignment, new_n); } @@ -204,8 +204,8 @@ pub const Allocator = struct { old_mem: var, comptime new_alignment: u29, new_n: usize, - ) []align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + ) []align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child { + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; const T = Slice.child; if (new_n == 0) { @@ -229,7 +229,7 @@ pub const Allocator = struct { /// Free an array allocated with `alloc`. To free a single item, /// see `destroy`. pub fn free(self: *Allocator, memory: var) void { - const Slice = @typeInfo(@typeOf(memory)).Pointer; + const Slice = @typeInfo(@TypeOf(memory)).Pointer; const bytes = @sliceToBytes(memory); if (bytes.len == 0) return; const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr)); @@ -1323,8 +1323,8 @@ fn AsBytesReturnType(comptime P: type) type { } ///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness. -pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { - const P = @typeOf(ptr); +pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) { + const P = @TypeOf(ptr); return @ptrCast(AsBytesReturnType(P), ptr); } @@ -1363,7 +1363,7 @@ test "asBytes" { } ///Given any value, returns a copy of its bytes in an array. -pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { +pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 { return asBytes(&value).*; } @@ -1397,8 +1397,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { ///Given a pointer to an array of bytes, returns a pointer to a value of the specified type /// backed by those bytes, preserving constness. -pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typeOf(bytes)) { - return @ptrCast(BytesAsValueReturnType(T, @typeOf(bytes)), bytes); +pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @TypeOf(bytes)) { + return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes); } test "bytesAsValue" { @@ -1460,11 +1460,11 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { } ///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness. -pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) { +pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@TypeOf(ptr), length) { assert(start + length <= ptr.*.len); - const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length); - const T = meta.Child(meta.Child(@typeOf(ptr))); + const ReturnType = SubArrayPtrReturnType(@TypeOf(ptr), length); + const T = meta.Child(meta.Child(@TypeOf(ptr))); return @ptrCast(ReturnType, &ptr[start]); } diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 2352c0bfff..e0ddbed274 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -11,7 +11,7 @@ const TypeId = builtin.TypeId; const TypeInfo = builtin.TypeInfo; pub fn tagName(v: var) []const u8 { - const T = @typeOf(v); + const T = @TypeOf(v); switch (@typeInfo(T)) { TypeId.ErrorSet => return @errorName(v), else => return @tagName(v), @@ -339,8 +339,8 @@ test "std.meta.TagType" { } ///Returns the active tag of a tagged union -pub fn activeTag(u: var) @TagType(@typeOf(u)) { - const T = @typeOf(u); +pub fn activeTag(u: var) @TagType(@TypeOf(u)) { + const T = @TypeOf(u); return @as(@TagType(T), u); } @@ -365,7 +365,7 @@ test "std.meta.activeTag" { ///Given a tagged union type, and an enum, return the type of the union /// field corresponding to the enum tag. pub fn TagPayloadType(comptime U: type, tag: var) type { - const Tag = @typeOf(tag); + const Tag = @TypeOf(tag); testing.expect(trait.is(builtin.TypeId.Union)(U)); testing.expect(trait.is(builtin.TypeId.Enum)(Tag)); @@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" { }; const MovedEvent = TagPayloadType(Event, Event.Moved); var e: Event = undefined; - testing.expect(MovedEvent == @typeOf(e.Moved)); + testing.expect(MovedEvent == @TypeOf(e.Moved)); } ///Compares two of any type for equality. Containers are compared on a field-by-field basis, /// where possible. Pointers are not followed. -pub fn eql(a: var, b: @typeOf(a)) bool { - const T = @typeOf(a); +pub fn eql(a: var, b: @TypeOf(a)) bool { + const T = @TypeOf(a); switch (@typeId(T)) { builtin.TypeId.Struct => { diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index 5da6e464b6..f36f3e15f0 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool { return false; } -pub const TraitFn = @typeOf(traitFnWorkaround); +pub const TraitFn = @TypeOf(traitFnWorkaround); /// //////Trait generators @@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn { pub fn trait(comptime T: type) bool { if (!comptime isContainer(T)) return false; if (!comptime @hasDecl(T, name)) return false; - const DeclType = @typeOf(@field(T, name)); + const DeclType = @TypeOf(@field(T, name)); const decl_type_id = @typeId(DeclType); return decl_type_id == builtin.TypeId.Fn; } @@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool { test "std.meta.trait.isSingleItemPtr" { const array = [_]u8{0} ** 10; - testing.expect(isSingleItemPtr(@typeOf(&array[0]))); - testing.expect(!isSingleItemPtr(@typeOf(array))); - testing.expect(!isSingleItemPtr(@typeOf(array[0..1]))); + testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); + testing.expect(!isSingleItemPtr(@TypeOf(array))); + testing.expect(!isSingleItemPtr(@TypeOf(array[0..1]))); } /// @@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool { test "std.meta.trait.isManyItemPtr" { const array = [_]u8{0} ** 10; const mip = @ptrCast([*]const u8, &array[0]); - testing.expect(isManyItemPtr(@typeOf(mip))); - testing.expect(!isManyItemPtr(@typeOf(array))); - testing.expect(!isManyItemPtr(@typeOf(array[0..1]))); + testing.expect(isManyItemPtr(@TypeOf(mip))); + testing.expect(!isManyItemPtr(@TypeOf(array))); + testing.expect(!isManyItemPtr(@TypeOf(array[0..1]))); } /// @@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool { test "std.meta.trait.isSlice" { const array = [_]u8{0} ** 10; - testing.expect(isSlice(@typeOf(array[0..]))); - testing.expect(!isSlice(@typeOf(array))); - testing.expect(!isSlice(@typeOf(&array[0]))); + testing.expect(isSlice(@TypeOf(array[0..]))); + testing.expect(!isSlice(@TypeOf(array))); + testing.expect(!isSlice(@TypeOf(&array[0]))); } /// @@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" { const array = [_]u8{0} ** 10; const slice = array[0..]; - testing.expect(isIndexable(@typeOf(array))); - testing.expect(isIndexable(@typeOf(&array))); - testing.expect(isIndexable(@typeOf(slice))); - testing.expect(!isIndexable(meta.Child(@typeOf(slice)))); + testing.expect(isIndexable(@TypeOf(array))); + testing.expect(isIndexable(@TypeOf(&array))); + testing.expect(isIndexable(@TypeOf(slice))); + testing.expect(!isIndexable(meta.Child(@TypeOf(slice)))); } /// @@ -313,8 +313,8 @@ test "std.meta.trait.isNumber" { testing.expect(isNumber(u32)); testing.expect(isNumber(f32)); testing.expect(isNumber(u64)); - testing.expect(isNumber(@typeOf(102))); - testing.expect(isNumber(@typeOf(102.123))); + testing.expect(isNumber(@TypeOf(102))); + testing.expect(isNumber(@TypeOf(102.123))); testing.expect(!isNumber([]u8)); testing.expect(!isNumber(NotANumber)); } @@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool { test "std.meta.trait.isConstPtr" { var t = @as(u8, 0); const c = @as(u8, 0); - testing.expect(isConstPtr(*const @typeOf(t))); - testing.expect(isConstPtr(@typeOf(&c))); - testing.expect(!isConstPtr(*@typeOf(t))); - testing.expect(!isConstPtr(@typeOf(6))); + testing.expect(isConstPtr(*const @TypeOf(t))); + testing.expect(isConstPtr(@TypeOf(&c))); + testing.expect(!isConstPtr(*@TypeOf(t))); + testing.expect(!isConstPtr(@TypeOf(6))); } pub fn isContainer(comptime T: type) bool { diff --git a/lib/std/mutex.zig b/lib/std/mutex.zig index 39cfab19ce..71188054f3 100644 --- a/lib/std/mutex.zig +++ b/lib/std/mutex.zig @@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent; /// no-ops. In single threaded debug mode, there is deadlock detection. pub const Mutex = if (builtin.single_threaded) struct { - lock: @typeOf(lock_init), + lock: @TypeOf(lock_init), const lock_init = if (std.debug.runtime_safety) false else {}; diff --git a/lib/std/net.zig b/lib/std/net.zig index a3f9c1c6d1..0a98bd999b 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -271,7 +271,7 @@ pub const Address = extern union { options: std.fmt.FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) !void { switch (self.any.family) { os.AF_INET => { diff --git a/lib/std/os.zig b/lib/std/os.zig index 8d6c7dd05e..04de59d6e1 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2974,7 +2974,7 @@ pub fn res_mkquery( // Make a reasonably unpredictable id var ts: timespec = undefined; clock_gettime(CLOCK_REALTIME, &ts) catch {}; - const UInt = @IntType(false, @typeOf(ts.tv_nsec).bit_count); + const UInt = @IntType(false, @TypeOf(ts.tv_nsec).bit_count); const unsec = @bitCast(UInt, ts.tv_nsec); const id = @truncate(u32, unsec + unsec / 65536); q[0] = @truncate(u8, id / 256); diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 907fd24db1..899bb2a060 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -706,7 +706,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti .restorer = @ptrCast(extern fn () void, restorer_fn), }; var ksa_old: k_sigaction = undefined; - const ksa_mask_size = @sizeOf(@typeOf(ksa_old.mask)); + const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask)); @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size); const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size); const err = getErrno(result); @@ -786,7 +786,7 @@ pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { } pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { - if (@typeInfo(usize).Int.bits > @typeInfo(@typeOf(mmsghdr(undefined).msg_len)).Int.bits) { + if (@typeInfo(usize).Int.bits > @typeInfo(@TypeOf(mmsghdr(undefined).msg_len)).Int.bits) { // workaround kernel brokenness: // if adding up all iov_len overflows a i32 then split into multiple calls // see https://www.openwall.com/lists/musl/2014/06/07/5 diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 31d4d2ed50..c780cfd3b5 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -32,7 +32,7 @@ pub const Guid = extern struct { options: fmt.FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (f.len == 0) { return fmt.format(context, Errors, output, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", self.time_low, self.time_mid, self.time_high_and_version, self.clock_seq_high_and_reserved, self.clock_seq_low, self.node); diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 954261bd1b..33e56abce1 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -214,12 +214,12 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD; -pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll:BOOL, dwMilliseconds: DWORD) DWORD; +pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) DWORD; pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx( nCount: DWORD, lpHandle: [*]const HANDLE, - bWaitAll:BOOL, + bWaitAll: BOOL, dwMilliseconds: DWORD, bAlertable: BOOL, ) DWORD; diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index 4b9b3a2a65..db60e60494 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -635,7 +635,7 @@ const MsfStream = struct { /// Implementation of InStream trait for Pdb.MsfStream stream: Stream = undefined, - pub const Error = @typeOf(read).ReturnType.ErrorSet; + pub const Error = @TypeOf(read).ReturnType.ErrorSet; pub const Stream = io.InStream(Error); fn init(block_size: u32, file: File, blocks: []u32) MsfStream { diff --git a/lib/std/reset_event.zig b/lib/std/reset_event.zig index 91a7d25271..52235d4327 100644 --- a/lib/std/reset_event.zig +++ b/lib/std/reset_event.zig @@ -27,7 +27,7 @@ pub const ResetEvent = struct { pub fn isSet(self: *ResetEvent) bool { return self.os_event.isSet(); } - + /// Sets the event if not already set and /// wakes up AT LEAST one thread waiting the event. /// Returns whether or not a thread was woken up. @@ -62,7 +62,7 @@ const OsEvent = if (builtin.single_threaded) DebugEvent else switch (builtin.os) }; const DebugEvent = struct { - is_set: @typeOf(set_init), + is_set: @TypeOf(set_init), const set_init = if (std.debug.runtime_safety) false else {}; @@ -345,8 +345,8 @@ const PosixEvent = struct { timeout_abs += @intCast(u64, ts.tv_sec) * time.second; timeout_abs += @intCast(u64, ts.tv_nsec); } - ts.tv_sec = @intCast(@typeOf(ts.tv_sec), @divFloor(timeout_abs, time.second)); - ts.tv_nsec = @intCast(@typeOf(ts.tv_nsec), @mod(timeout_abs, time.second)); + ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.second)); + ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.second)); } var dummy_value: u32 = undefined; @@ -426,8 +426,8 @@ test "std.ResetEvent" { .event = event, .value = 0, }; - + var receiver = try std.Thread.spawn(&context, Context.receiver); defer receiver.wait(); try context.sender(); -} \ No newline at end of file +} diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig index 8c5ded3647..80e4666b6a 100644 --- a/lib/std/segmented_list.zig +++ b/lib/std/segmented_list.zig @@ -122,7 +122,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type self.* = undefined; } - pub fn at(self: var, i: usize) AtType(@typeOf(self)) { + pub fn at(self: var, i: usize) AtType(@TypeOf(self)) { assert(i < self.len); return self.uncheckedAt(i); } @@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type self.len = new_len; } - pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) { + pub fn uncheckedAt(self: var, index: usize) AtType(@TypeOf(self)) { if (index < prealloc_item_count) { return &self.prealloc_segment[index]; } diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig index 03d1e8fe1d..0a5e435a54 100644 --- a/lib/std/special/build_runner.zig +++ b/lib/std/special/build_runner.zig @@ -125,7 +125,7 @@ pub fn main() !void { } fn runBuild(builder: *Builder) anyerror!void { - switch (@typeId(@typeOf(root.build).ReturnType)) { + switch (@typeId(@TypeOf(root.build).ReturnType)) { .Void => root.build(builder), .ErrorUnion => try root.build(builder), else => @compileError("expected return type of build to be 'void' or '!void'"), diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 1fbb618b1e..0426f72417 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -384,7 +384,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_uidivmod).ReturnType = undefined; result.q = __udivmodsi4(n, d, &result.r); return result; } @@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_uldivmod).ReturnType = undefined; result.q = __udivmoddi4(n, d, &result.r); return result; } @@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_idivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_idivmod).ReturnType = undefined; result.q = __divmodsi4(n, d, &result.r); return result; } @@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_ldivmod).ReturnType = undefined; result.q = __divmoddi4(n, d, &result.r); return result; } diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index b5e4e2edab..60745dab7f 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -25,7 +25,7 @@ comptime { } } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { if (builtin.link_libc and @hasDecl(root, "main")) { - if (@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) { + if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) { @export("main", main, .Weak); } } else if (builtin.os == .windows) { @@ -69,7 +69,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u uefi.handle = handle; uefi.system_table = system_table; - switch (@typeInfo(@typeOf(root.main).ReturnType)) { + switch (@typeInfo(@TypeOf(root.main).ReturnType)) { .NoReturn => { root.main(); }, @@ -248,7 +248,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 { // This is not marked inline because it is called with @asyncCall when // there is an event loop. fn callMain() u8 { - switch (@typeInfo(@typeOf(root.main).ReturnType)) { + switch (@typeInfo(@TypeOf(root.main).ReturnType)) { .NoReturn => { root.main(); }, @@ -270,7 +270,7 @@ fn callMain() u8 { } return 1; }; - switch (@typeInfo(@typeOf(result))) { + switch (@typeInfo(@TypeOf(result))) { .Void => return 0, .Int => |info| { if (info.bits != 8) { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 0aeb2d8eda..437c12ee8b 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -21,14 +21,14 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void { /// equal, prints diagnostics to stderr to show exactly how they are not equal, /// then aborts. /// The types must match exactly. -pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { - switch (@typeInfo(@typeOf(actual))) { +pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void { + switch (@typeInfo(@TypeOf(actual))) { .NoReturn, .BoundFn, .Opaque, .Frame, .AnyFrame, - => @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"), + => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"), .Undefined, .Null, @@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { @compileError("Unable to compare untagged union values"); } - const TagType = @TagType(@typeOf(expected)); + const TagType = @TagType(@TypeOf(expected)); const expectedTag = @as(TagType, expected); const actualTag = @as(TagType, actual); @@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { expectEqual(expectedTag, actualTag); // we only reach this loop if the tags are equal - inline for (std.meta.fields(@typeOf(actual))) |fld| { + inline for (std.meta.fields(@TypeOf(actual))) |fld| { if (std.mem.eql(u8, fld.name, @tagName(actualTag))) { expectEqual(@field(expected, fld.name), @field(actual, fld.name)); return; diff --git a/lib/std/thread.zig b/lib/std/thread.zig index d443796df4..fea045288a 100644 --- a/lib/std/thread.zig +++ b/lib/std/thread.zig @@ -147,8 +147,8 @@ pub const Thread = struct { // https://github.com/ziglang/zig/issues/157 const default_stack_size = 16 * 1024 * 1024; - const Context = @typeOf(context); - comptime assert(@ArgType(@typeOf(startFn), 0) == Context); + const Context = @TypeOf(context); + comptime assert(@ArgType(@TypeOf(startFn), 0) == Context); if (builtin.os == builtin.Os.windows) { const WinThread = struct { @@ -158,7 +158,7 @@ pub const Thread = struct { }; extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD { const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*; - switch (@typeId(@typeOf(startFn).ReturnType)) { + switch (@typeId(@TypeOf(startFn).ReturnType)) { .Int => { return startFn(arg); }, @@ -201,7 +201,7 @@ pub const Thread = struct { extern fn linuxThreadMain(ctx_addr: usize) u8 { const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*; - switch (@typeId(@typeOf(startFn).ReturnType)) { + switch (@typeId(@TypeOf(startFn).ReturnType)) { .Int => { return startFn(arg); }, diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index f7b2eda7e4..9add521c00 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -13,19 +13,19 @@ pub const Error = error{ }; /// Returns whether anything changed -pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(stream).Child.Error || Error)!bool { - comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer); +pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool { + comptime assert(@typeId(@TypeOf(stream)) == builtin.TypeId.Pointer); var anything_changed: bool = false; // make a passthrough stream that checks whether something changed const MyStream = struct { const MyStream = @This(); - const StreamError = @typeOf(stream).Child.Error; + const StreamError = @TypeOf(stream).Child.Error; const Stream = std.io.OutStream(StreamError); anything_changed_ptr: *bool, - child_stream: @typeOf(stream), + child_stream: @TypeOf(stream), stream: Stream, source_index: usize, source: []const u8, @@ -70,7 +70,7 @@ fn renderRoot( allocator: *mem.Allocator, stream: var, tree: *ast.Tree, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { var tok_it = tree.tokens.iterator(0); // render all the line comments at the beginning of the file @@ -190,7 +190,7 @@ fn renderRoot( } } -fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @typeOf(stream).Child.Error!void { +fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void { const first_token = node.firstToken(); var prev_token = first_token; while (tree.tokens.at(prev_token - 1).id == .DocComment) { @@ -204,7 +204,7 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as } } -fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@typeOf(stream).Child.Error || Error)!void { +fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Child.Error || Error)!void { switch (decl.id) { .FnProto => { const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); @@ -325,7 +325,7 @@ fn renderExpression( start_col: *usize, base: *ast.Node, space: Space, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { switch (base.id) { .Identifier => { const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base); @@ -1903,7 +1903,7 @@ fn renderVarDecl( indent: usize, start_col: *usize, var_decl: *ast.Node.VarDecl, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { if (var_decl.visib_token) |visib_token| { try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub } @@ -1976,7 +1976,7 @@ fn renderParamDecl( start_col: *usize, base: *ast.Node, space: Space, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); try renderDocComments(tree, stream, param_decl, indent, start_col); @@ -2005,7 +2005,7 @@ fn renderStatement( indent: usize, start_col: *usize, base: *ast.Node, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { switch (base.id) { .VarDecl => { const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base); @@ -2044,7 +2044,7 @@ fn renderTokenOffset( start_col: *usize, space: Space, token_skip_bytes: usize, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { if (space == Space.BlockStart) { if (start_col.* < indent + indent_delta) return renderToken(tree, stream, token_index, indent, start_col, Space.Space); @@ -2232,7 +2232,7 @@ fn renderToken( indent: usize, start_col: *usize, space: Space, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0); } @@ -2242,7 +2242,7 @@ fn renderDocComments( node: var, indent: usize, start_col: *usize, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { const comment = node.doc_comments orelse return; var it = comment.lines.iterator(0); const first_token = node.firstToken(); @@ -2308,7 +2308,7 @@ const FindByteOutStream = struct { } }; -fn copyFixingWhitespace(stream: var, slice: []const u8) @typeOf(stream).Child.Error!void { +fn copyFixingWhitespace(stream: var, slice: []const u8) @TypeOf(stream).Child.Error!void { for (slice) |byte| switch (byte) { '\t' => try stream.write(" "), '\r' => {}, diff --git a/src-self-hosted/dep_tokenizer.zig b/src-self-hosted/dep_tokenizer.zig index b4e46bc1ad..eb3500cad1 100644 --- a/src-self-hosted/dep_tokenizer.zig +++ b/src-self-hosted/dep_tokenizer.zig @@ -1021,8 +1021,8 @@ comptime { // output: must be a function that takes a `self` idiom parameter // and a bytes parameter // context: must be that self -fn makeOutput(output: var, context: var) Output(@typeOf(output)) { - return Output(@typeOf(output)){ +fn makeOutput(output: var, context: var) Output(@TypeOf(output)) { + return Output(@TypeOf(output)){ .output = output, .context = context, }; diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig index 741dbb6e3d..a8f4980fa8 100644 --- a/src-self-hosted/ir.zig +++ b/src-self-hosted/ir.zig @@ -1807,7 +1807,7 @@ pub const Builder = struct { // Look at the params and ref() other instructions comptime var i = 0; inline while (i < @memberCount(I.Params)) : (i += 1) { - const FieldType = comptime @typeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i))); + const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i))); switch (FieldType) { *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self), *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self), diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index a8fcc920d5..701823c4be 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -72,7 +72,7 @@ pub const LibCInstallation = struct { inline for (keys) |key, i| { if (std.mem.eql(u8, name, key)) { found_keys[i].found = true; - switch (@typeInfo(@typeOf(@field(self, key)))) { + switch (@typeInfo(@TypeOf(@field(self, key)))) { .Optional => { if (value.len == 0) { @field(self, key) = null; diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 134e0b7672..c0ac3fbd52 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -1147,7 +1147,7 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node { var big = try std.math.big.Int.initCapacity(c.a(), num_limbs); defer big.deinit(); const data = ZigClangAPSInt_getRawData(int.?); - var i: @typeOf(num_limbs) = 0; + var i: @TypeOf(num_limbs) = 0; while (i < num_limbs) : (i += 1) big.limbs[i] = data[i]; const str = big.toString(c.a(), 10) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, @@ -1416,7 +1416,7 @@ fn revertAndWarn( source_loc: ZigClangSourceLocation, comptime format: []const u8, args: var, -) (@typeOf(err) || error{OutOfMemory}) { +) (@TypeOf(err) || error{OutOfMemory}) { rp.activate(); try emitWarning(rp.c, source_loc, format, args); return err; diff --git a/src-self-hosted/type.zig b/src-self-hosted/type.zig index 84efeea68a..d3f3ba746a 100644 --- a/src-self-hosted/type.zig +++ b/src-self-hosted/type.zig @@ -1038,14 +1038,14 @@ pub const Type = struct { }; fn hashAny(x: var, comptime seed: u64) u32 { - switch (@typeInfo(@typeOf(x))) { + switch (@typeInfo(@TypeOf(x))) { .Int => |info| { comptime var rng = comptime std.rand.DefaultPrng.init(seed); const unsigned_x = @bitCast(@IntType(false, info.bits), x); if (info.bits <= 32) { return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32); } else { - return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@typeOf(unsigned_x))); + return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@TypeOf(unsigned_x))); } }, .Pointer => |info| { @@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 { return hashAny(@as(u32, 1), seed); } }, - else => @compileError("implement hash function for " ++ @typeName(@typeOf(x))), + else => @compileError("implement hash function for " ++ @typeName(@TypeOf(x))), } } diff --git a/test/compare_output.zig b/test/compare_output.zig index 80bac9b1f7..b13c6cf530 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -258,12 +258,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { cases.add("order-independent declarations", \\const io = @import("std").io; \\const z = io.stdin_fileno; - \\const x : @typeOf(y) = 1234; + \\const x : @TypeOf(y) = 1234; \\const y : u16 = 5678; \\pub fn main() void { \\ var x_local : i32 = print_ok(x); \\} - \\fn print_ok(val: @typeOf(x)) @typeOf(foo) { + \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { \\ const stdout = &io.getStdOut().outStream().stream; \\ stdout.print("OK\n", .{}) catch unreachable; \\ return 0; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index b89287949b..12e9184c57 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ }; \\} , &[_][]const u8{ - "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", + "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'", }); cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional", @@ -854,7 +854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("field access of slices", \\export fn entry() void { \\ var slice: []i32 = undefined; - \\ const info = @typeOf(slice).unknown; + \\ const info = @TypeOf(slice).unknown; \\} , &[_][]const u8{ "tmp.zig:3:32: error: type '[]i32' does not support field access", @@ -894,7 +894,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("@sizeOf bad type", \\export fn entry() usize { - \\ return @sizeOf(@typeOf(null)); + \\ return @sizeOf(@TypeOf(null)); \\} , &[_][]const u8{ "tmp.zig:2:20: error: no size available for type '(null)'", @@ -1033,7 +1033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("bogus compile var", \\const x = @import("builtin").bogus; - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const u8{ "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", }); @@ -1080,7 +1080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var foo: Foo = undefined; \\ \\export fn entry() usize { - \\ return @sizeOf(@typeOf(foo.x)); + \\ return @sizeOf(@TypeOf(foo.x)); \\} , &[_][]const u8{ "tmp.zig:1:13: error: struct 'Foo' depends on itself", @@ -1118,8 +1118,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("top level decl dependency loop", - \\const a : @typeOf(b) = 0; - \\const b : @typeOf(a) = 0; + \\const a : @TypeOf(b) = 0; + \\const b : @TypeOf(a) = 0; \\export fn entry() void { \\ const c = a + b; \\} @@ -1620,7 +1620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var x: f64 = 1.0; \\var y: f32 = x; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:2:14: error: expected type 'f32', found 'f64'", }); @@ -2494,7 +2494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} , &[_][]const u8{ - "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'", + "tmp.zig:5:14: error: duplicate switch value: '@TypeOf(foo).ReturnType.ErrorSet.Foo'", "tmp.zig:3:14: note: other value is here", }); @@ -2626,7 +2626,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ try foo(); \\} , &[_][]const u8{ - "tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", + "tmp.zig:5:5: error: cannot resolve inferred error set '@TypeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", }); cases.add("implicit cast of error set not a subset", @@ -3555,7 +3555,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", }); @@ -3577,7 +3577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:13:15: error: duplicate switch value", "tmp.zig:10:15: note: other value is here", @@ -3601,7 +3601,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:13:15: error: duplicate switch value", "tmp.zig:10:15: note: other value is here", @@ -3628,7 +3628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ 0 => {}, \\ } \\} - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:2:5: error: switch must handle all possibilities", }); @@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ 206 ... 255 => 3, \\ }; \\} - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:6:9: error: duplicate switch value", "tmp.zig:5:14: note: previous value is here", @@ -3655,7 +3655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} \\const y: u8 = 100; - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:2:5: error: else prong required when switching on type '*u8'", }); @@ -3673,7 +3673,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const derp: usize = 1234; \\const a = derp ++ "foo"; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:3:11: error: expected array, found 'usize'", }); @@ -3683,14 +3683,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return s ++ "foo"; \\} \\var s: [10]u8 = undefined; - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:2:12: error: unable to evaluate constant expression", }); cases.add("@cImport with bogus include", \\const c = @cImport(@cInclude("bogus.h")); - \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } , &[_][]const u8{ "tmp.zig:1:11: error: C import failed", ".h:1:10: note: 'bogus.h' file not found", @@ -3700,14 +3700,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const x = 3; \\const y = &x; \\fn foo() *const i32 { return y; } - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", }); cases.add("integer overflow error", \\const x : u8 = 300; - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const u8{ "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", }); @@ -3736,7 +3736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\}; \\ - \\const member_fn_type = @typeOf(Foo.member_a); + \\const member_fn_type = @TypeOf(Foo.member_a); \\const members = [_]member_fn_type { \\ Foo.member_a, \\ Foo.member_b, @@ -3746,21 +3746,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const result = members[index](); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:20:34: error: expected 1 arguments, found 0", }); cases.add("missing function name", \\fn () void {} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:1:1: error: missing function name", }); cases.add("missing param name", \\fn f(i32) void {} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:1:6: error: missing parameter name", }); @@ -3770,7 +3770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn a() i32 {return 0;} \\fn b() i32 {return 1;} \\fn c() i32 {return 2;} - \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); } , &[_][]const u8{ "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", }); @@ -3781,7 +3781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub fn b(x: i32) i32 {return x + 1;} \\export fn c(x: i32) i32 {return x + 2;} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); } , &[_][]const u8{ "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'", }); @@ -3789,7 +3789,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("colliding invalid top level functions", \\fn func() bogus {} \\fn func() bogus {} - \\export fn entry() usize { return @sizeOf(@typeOf(func)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'func'", }); @@ -3801,7 +3801,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var global_var: usize = 1; \\fn get() usize { return global_var; } \\ - \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); } , &[_][]const u8{ "tmp.zig:5:25: error: unable to evaluate constant expression", "tmp.zig:2:12: note: referenced here", @@ -3813,7 +3813,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\}; \\const x = Foo {.field = 1} + Foo {.field = 2}; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const u8{ "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", }); @@ -3824,10 +3824,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const int_x = @as(u32, 1) / @as(u32, 0); \\const float_x = @as(f32, 1.0) / @as(f32, 0.0); \\ - \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } - \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } - \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } - \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } + \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } + \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } + \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } + \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } , &[_][]const u8{ "tmp.zig:1:21: error: division by zero", "tmp.zig:2:25: error: division by zero", @@ -3839,7 +3839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const foo = "a \\b"; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:1:15: error: newline not allowed in string literal", }); @@ -3848,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo() void {} \\const invalid = foo > foo; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); } , &[_][]const u8{ "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", }); @@ -3859,7 +3859,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return foo(a, b); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); } , &[_][]const u8{ "tmp.zig:3:16: error: unable to evaluate constant expression", }); @@ -3867,7 +3867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("assign null to non-optional pointer", \\const a: *u8 = null; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:1:16: error: expected type '*u8', found '(null)'", }); @@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return 1 / x; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: division by zero", "tmp.zig:1:14: note: referenced here", @@ -3896,7 +3896,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("branch on undefined value", \\const x = if (undefined) true else false; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const u8{ "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", }); @@ -4276,7 +4276,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return fibbonaci(x - 1) + fibbonaci(x - 2); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); } , &[_][]const u8{ "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", "tmp.zig:1:37: note: referenced here", @@ -4286,7 +4286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("@embedFile with bogus file", \\const resource = @embedFile("bogus.txt",); \\ - \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } , &[_][]const u8{ "tmp.zig:1:29: error: unable to find '", "bogus.txt'", @@ -4299,7 +4299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const a = Foo {.x = get_it()}; \\extern fn get_it() i32; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:4:21: error: unable to evaluate constant expression", }); @@ -4315,7 +4315,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\var global_side_effect = false; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:6:26: error: unable to evaluate constant expression", "tmp.zig:4:17: note: referenced here", @@ -4344,8 +4344,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a.* == b.*; \\} \\ - \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } - \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } + \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); } + \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); } , &[_][]const u8{ "tmp.zig:2:14: error: operator not allowed for type '[]u8'", "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", @@ -4392,7 +4392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return -x; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:12: error: negation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4404,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a + b; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4416,7 +4416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a - b; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4428,7 +4428,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a * b; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4440,7 +4440,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return @truncate(i8, x); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:3:26: error: expected signed integer type, found 'u32'", }); @@ -4480,7 +4480,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn f() i32 { \\ return foo(1, 2); \\} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", }); @@ -4524,7 +4524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn f(m: []const u8) void { \\ m.copy(u8, self[0..], m); \\} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", }); @@ -4537,7 +4537,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\ foo.method(1, 2); \\} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:6:15: error: expected 2 arguments, found 3", }); @@ -4596,7 +4596,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", }); @@ -4655,7 +4655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); \\ - \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); } , &[_][]const u8{ "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", }); @@ -4683,7 +4683,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const zero: i32 = 0; \\const a = zero{1}; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:2:11: error: expected type 'type', found 'i32'", }); @@ -4715,7 +4715,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return 0; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } , &[_][]const u8{ "tmp.zig:4:11: error: cannot return from defer expression", }); @@ -4730,7 +4730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("global variable alignment non power of 2", \\const some_data: [100]u8 align(3) = undefined; - \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } , &[_][]const u8{ "tmp.zig:1:32: error: alignment value 3 is not a power of 2", }); @@ -4772,7 +4772,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return x.*; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", }); @@ -4875,7 +4875,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return out.*[0..1]; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); } , &[_][]const u8{ "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", }); @@ -4890,7 +4890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return true; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", }); @@ -5726,7 +5726,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("@ArgType arg index out of bounds", \\comptime { - \\ _ = @ArgType(@typeOf(add), 2); + \\ _ = @ArgType(@TypeOf(add), 2); \\} \\fn add(a: i32, b: i32) i32 { return a + b; } , &[_][]const u8{ @@ -6220,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("getting return type of generic function", \\fn generic(a: var) void {} \\comptime { - \\ _ = @typeOf(generic).ReturnType; + \\ _ = @TypeOf(generic).ReturnType; \\} , &[_][]const u8{ "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic", @@ -6229,7 +6229,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("getting @ArgType of generic function", \\fn generic(a: var) void {} \\comptime { - \\ _ = @ArgType(@typeOf(generic), 0); + \\ _ = @ArgType(@TypeOf(generic), 0); \\} , &[_][]const u8{ "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic", diff --git a/test/stage1/behavior/align.zig b/test/stage1/behavior/align.zig index 7f9ccaff1e..1812394f2e 100644 --- a/test/stage1/behavior/align.zig +++ b/test/stage1/behavior/align.zig @@ -5,10 +5,10 @@ const builtin = @import("builtin"); var foo: u8 align(4) = 100; test "global variable alignment" { - expect(@typeOf(&foo).alignment == 4); - expect(@typeOf(&foo) == *align(4) u8); + expect(@TypeOf(&foo).alignment == 4); + expect(@TypeOf(&foo) == *align(4) u8); const slice = @as(*[1]u8, &foo)[0..]; - expect(@typeOf(slice) == []align(4) u8); + expect(@TypeOf(slice) == []align(4) u8); } fn derp() align(@sizeOf(usize) * 2) i32 { @@ -19,8 +19,8 @@ fn noop4() align(4) void {} test "function alignment" { expect(derp() == 1234); - expect(@typeOf(noop1) == fn () align(1) void); - expect(@typeOf(noop4) == fn () align(4) void); + expect(@TypeOf(noop1) == fn () align(1) void); + expect(@TypeOf(noop4) == fn () align(4) void); noop1(); noop4(); } @@ -31,7 +31,7 @@ var baz: packed struct { } = undefined; test "packed struct alignment" { - expect(@typeOf(&baz.b) == *align(1) u32); + expect(@TypeOf(&baz.b) == *align(1) u32); } const blah: packed struct { @@ -41,7 +41,7 @@ const blah: packed struct { } = undefined; test "bit field alignment" { - expect(@typeOf(&blah.b) == *align(1:3:1) const u3); + expect(@TypeOf(&blah.b) == *align(1:3:1) const u3); } test "default alignment allows unspecified in type syntax" { @@ -165,28 +165,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { test "@ptrCast preserves alignment of bigger source" { var x: u32 align(16) = 1234; const ptr = @ptrCast(*u8, &x); - expect(@typeOf(ptr) == *align(16) u8); + expect(@TypeOf(ptr) == *align(16) u8); } test "runtime known array index has best alignment possible" { // take full advantage of over-alignment var array align(4) = [_]u8{ 1, 2, 3, 4 }; - expect(@typeOf(&array[0]) == *align(4) u8); - expect(@typeOf(&array[1]) == *u8); - expect(@typeOf(&array[2]) == *align(2) u8); - expect(@typeOf(&array[3]) == *u8); + expect(@TypeOf(&array[0]) == *align(4) u8); + expect(@TypeOf(&array[1]) == *u8); + expect(@TypeOf(&array[2]) == *align(2) u8); + expect(@TypeOf(&array[3]) == *u8); // because align is too small but we still figure out to use 2 var bigger align(2) = [_]u64{ 1, 2, 3, 4 }; - expect(@typeOf(&bigger[0]) == *align(2) u64); - expect(@typeOf(&bigger[1]) == *align(2) u64); - expect(@typeOf(&bigger[2]) == *align(2) u64); - expect(@typeOf(&bigger[3]) == *align(2) u64); + expect(@TypeOf(&bigger[0]) == *align(2) u64); + expect(@TypeOf(&bigger[1]) == *align(2) u64); + expect(@TypeOf(&bigger[2]) == *align(2) u64); + expect(@TypeOf(&bigger[3]) == *align(2) u64); // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; - comptime expect(@typeOf(smaller[0..]) == []align(2) u32); - comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32); + comptime expect(@TypeOf(smaller[0..]) == []align(2) u32); + comptime expect(@TypeOf(smaller[0..].ptr) == [*]align(2) u32); testIndex(smaller[0..].ptr, 0, *align(2) u32); testIndex(smaller[0..].ptr, 1, *align(2) u32); testIndex(smaller[0..].ptr, 2, *align(2) u32); @@ -199,10 +199,10 @@ test "runtime known array index has best alignment possible" { testIndex2(array[0..].ptr, 3, *u8); } fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void { - comptime expect(@typeOf(&smaller[index]) == T); + comptime expect(@TypeOf(&smaller[index]) == T); } fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void { - comptime expect(@typeOf(&ptr[index]) == T); + comptime expect(@TypeOf(&ptr[index]) == T); } test "alignstack" { @@ -303,7 +303,7 @@ test "struct field explicit alignment" { var node: S.Node = undefined; node.massive_byte = 100; expect(node.massive_byte == 100); - comptime expect(@typeOf(&node.massive_byte) == *align(64) u8); + comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8); expect(@ptrToInt(&node.massive_byte) % 64 == 0); } diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig index 1d51f822d0..7ac1e8197d 100644 --- a/test/stage1/behavior/array.zig +++ b/test/stage1/behavior/array.zig @@ -30,7 +30,7 @@ test "void arrays" { var array: [4]void = undefined; array[0] = void{}; array[1] = array[2]; - expect(@sizeOf(@typeOf(array)) == 0); + expect(@sizeOf(@TypeOf(array)) == 0); expect(array.len == 4); } @@ -109,12 +109,12 @@ test "array literal with specified size" { test "array child property" { var x: [5]i32 = undefined; - expect(@typeOf(x).Child == i32); + expect(@TypeOf(x).Child == i32); } test "array len property" { var x: [5]i32 = undefined; - expect(@typeOf(x).len == 5); + expect(@TypeOf(x).len == 5); } test "array len field" { diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig index cbc8f5e9e8..1b21ba7eff 100644 --- a/test/stage1/behavior/async_fn.zig +++ b/test/stage1/behavior/async_fn.zig @@ -185,7 +185,7 @@ var a_promise: anyframe = undefined; var global_result = false; async fn testSuspendBlock() void { suspend { - comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock)); + comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); a_promise = @frame(); } @@ -282,7 +282,7 @@ test "async fn pointer in a struct field" { var foo = Foo{ .bar = simpleAsyncFn2 }; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, &data); - comptime expect(@typeOf(f) == anyframe->void); + comptime expect(@TypeOf(f) == anyframe->void); expect(data == 2); resume f; expect(data == 4); @@ -332,7 +332,7 @@ test "async fn with inferred error set" { fn doTheTest() void { var frame: [1]@Frame(middle) = undefined; var fn_ptr = middle; - var result: @typeOf(fn_ptr).ReturnType.ErrorSet!void = undefined; + var result: @TypeOf(fn_ptr).ReturnType.ErrorSet!void = undefined; _ = @asyncCall(@sliceToBytes(frame[0..]), &result, fn_ptr); resume global_frame; std.testing.expectError(error.Fail, result); @@ -952,7 +952,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" { fn doTheTest() void { var frame: [1]@Frame(middle) = undefined; - var result: @typeOf(middle).ReturnType.ErrorSet!void = undefined; + var result: @TypeOf(middle).ReturnType.ErrorSet!void = undefined; _ = @asyncCall(@sliceToBytes(frame[0..]), &result, middle); resume global_frame; std.testing.expectError(error.Fail, result); @@ -1009,7 +1009,7 @@ test "@asyncCall using the result location inside the frame" { var foo = Foo{ .bar = S.simple2 }; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, &data); - comptime expect(@typeOf(f) == anyframe->i32); + comptime expect(@TypeOf(f) == anyframe->i32); expect(data == 2); resume f; expect(data == 4); @@ -1017,18 +1017,18 @@ test "@asyncCall using the result location inside the frame" { expect(data == 1234); } -test "@typeOf an async function call of generic fn with error union type" { +test "@TypeOf an async function call of generic fn with error union type" { const S = struct { fn func(comptime x: var) anyerror!i32 { - const T = @typeOf(async func(x)); - comptime expect(T == @typeOf(@frame()).Child); + const T = @TypeOf(async func(x)); + comptime expect(T == @TypeOf(@frame()).Child); return undefined; } }; _ = async S.func(i32); } -test "using @typeOf on a generic function call" { +test "using @TypeOf on a generic function call" { const S = struct { var global_frame: anyframe = undefined; var global_ok = false; @@ -1043,7 +1043,7 @@ test "using @typeOf on a generic function call" { suspend { global_frame = @frame(); } - const F = @typeOf(async amain(x - 1)); + const F = @TypeOf(async amain(x - 1)); const frame = @intToPtr(*F, @ptrToInt(&buf)); return await @asyncCall(frame, {}, amain, x - 1); } @@ -1068,7 +1068,7 @@ test "recursive call of await @asyncCall with struct return type" { suspend { global_frame = @frame(); } - const F = @typeOf(async amain(x - 1)); + const F = @TypeOf(async amain(x - 1)); const frame = @intToPtr(*F, @ptrToInt(&buf)); return await @asyncCall(frame, {}, amain, x - 1); } @@ -1080,7 +1080,7 @@ test "recursive call of await @asyncCall with struct return type" { }; }; var res: S.Foo = undefined; - var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined; + var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined; _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1)); resume S.global_frame; expect(S.global_ok); diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig index 694eb160e4..d76be6ce6f 100644 --- a/test/stage1/behavior/atomics.zig +++ b/test/stage1/behavior/atomics.zig @@ -118,7 +118,7 @@ test "atomic load and rmw with enum" { expect(@atomicLoad(Value, &x, .SeqCst) != .b); - _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); + _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); expect(@atomicLoad(Value, &x, .SeqCst) == .c); expect(@atomicLoad(Value, &x, .SeqCst) != .a); expect(@atomicLoad(Value, &x, .SeqCst) != .b); @@ -143,4 +143,4 @@ fn testAtomicStore() void { expect(@atomicLoad(u32, &x, .SeqCst) == 1); @atomicStore(u32, &x, 12345678, .SeqCst); expect(@atomicLoad(u32, &x, .SeqCst) == 12345678); -} \ No newline at end of file +} diff --git a/test/stage1/behavior/bugs/1851.zig b/test/stage1/behavior/bugs/1851.zig index ff9ab419f8..679f4bf835 100644 --- a/test/stage1/behavior/bugs/1851.zig +++ b/test/stage1/behavior/bugs/1851.zig @@ -15,7 +15,7 @@ test "allocation and looping over 3-byte integer" { x[1] = 0xFFFFFF; const bytes = @sliceToBytes(x); - expect(@typeOf(bytes) == []align(4) u8); + expect(@TypeOf(bytes) == []align(4) u8); expect(bytes.len == 8); for (bytes) |*b| { diff --git a/test/stage1/behavior/bugs/2114.zig b/test/stage1/behavior/bugs/2114.zig index 5b664e64ef..ab32a22cf3 100644 --- a/test/stage1/behavior/bugs/2114.zig +++ b/test/stage1/behavior/bugs/2114.zig @@ -3,7 +3,7 @@ const expect = std.testing.expect; const math = std.math; fn ctz(x: var) usize { - return @ctz(@typeOf(x), x); + return @ctz(@TypeOf(x), x); } test "fixed" { diff --git a/test/stage1/behavior/bugs/3742.zig b/test/stage1/behavior/bugs/3742.zig index 74aed006f6..01bcb49f3c 100644 --- a/test/stage1/behavior/bugs/3742.zig +++ b/test/stage1/behavior/bugs/3742.zig @@ -24,7 +24,7 @@ pub fn isCommand(comptime T: type) bool { pub const ArgSerializer = struct { pub fn serializeCommand(command: var) void { - const CmdT = @typeOf(command); + const CmdT = @TypeOf(command); if (comptime isCommand(CmdT)) { // COMMENTING THE NEXT LINE REMOVES THE ERROR diff --git a/test/stage1/behavior/bugs/655.zig b/test/stage1/behavior/bugs/655.zig index d4491bfc27..3d1bccb183 100644 --- a/test/stage1/behavior/bugs/655.zig +++ b/test/stage1/behavior/bugs/655.zig @@ -3,7 +3,7 @@ const other_file = @import("655_other_file.zig"); test "function with *const parameter with type dereferenced by namespace" { const x: other_file.Integer = 1234; - comptime std.testing.expect(@typeOf(&x) == *const other_file.Integer); + comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer); foo(&x); } diff --git a/test/stage1/behavior/bugs/718.zig b/test/stage1/behavior/bugs/718.zig index 8dfb511bb4..b5a57b8944 100644 --- a/test/stage1/behavior/bugs/718.zig +++ b/test/stage1/behavior/bugs/718.zig @@ -9,7 +9,7 @@ const Keys = struct { }; var keys: Keys = undefined; test "zero keys with @memset" { - @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@typeOf(keys))); + @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys))); expect(!keys.up); expect(!keys.down); expect(!keys.left); diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index 05749142c6..b5dd99a858 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -226,14 +226,14 @@ fn testCastConstArrayRefToConstSlice() void { { const blah = "aoeu".*; const const_array_ref = &blah; - expect(@typeOf(const_array_ref) == *const [4:0]u8); + expect(@TypeOf(const_array_ref) == *const [4:0]u8); const slice: []const u8 = const_array_ref; expect(mem.eql(u8, slice, "aoeu")); } { const blah: [4]u8 = "aoeu".*; const const_array_ref = &blah; - expect(@typeOf(const_array_ref) == *const [4]u8); + expect(@TypeOf(const_array_ref) == *const [4]u8); const slice: []const u8 = const_array_ref; expect(mem.eql(u8, slice, "aoeu")); } @@ -353,29 +353,29 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" { test "@intCast comptime_int" { const result = @intCast(i32, 1234); - expect(@typeOf(result) == i32); + expect(@TypeOf(result) == i32); expect(result == 1234); } test "@floatCast comptime_int and comptime_float" { { const result = @floatCast(f16, 1234); - expect(@typeOf(result) == f16); + expect(@TypeOf(result) == f16); expect(result == 1234.0); } { const result = @floatCast(f16, 1234.0); - expect(@typeOf(result) == f16); + expect(@TypeOf(result) == f16); expect(result == 1234.0); } { const result = @floatCast(f32, 1234); - expect(@typeOf(result) == f32); + expect(@TypeOf(result) == f32); expect(result == 1234.0); } { const result = @floatCast(f32, 1234.0); - expect(@typeOf(result) == f32); + expect(@TypeOf(result) == f32); expect(result == 1234.0); } } @@ -383,12 +383,12 @@ test "@floatCast comptime_int and comptime_float" { test "comptime_int @intToFloat" { { const result = @intToFloat(f16, 1234); - expect(@typeOf(result) == f16); + expect(@TypeOf(result) == f16); expect(result == 1234.0); } { const result = @intToFloat(f32, 1234); - expect(@typeOf(result) == f32); + expect(@TypeOf(result) == f32); expect(result == 1234.0); } } @@ -396,7 +396,7 @@ test "comptime_int @intToFloat" { test "@bytesToSlice keeps pointer alignment" { var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; const numbers = @bytesToSlice(u32, bytes[0..]); - comptime expect(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32); + comptime expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); } test "@intCast i32 to u7" { diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig index f9b331caaf..7c1e093748 100644 --- a/test/stage1/behavior/error.zig +++ b/test/stage1/behavior/error.zig @@ -83,9 +83,9 @@ test "error union type " { fn testErrorUnionType() void { const x: anyerror!i32 = 1234; if (x) |value| expect(value == 1234) else |_| unreachable; - expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion); - expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); - expect(@typeOf(x).ErrorSet == anyerror); + expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion); + expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); + expect(@TypeOf(x).ErrorSet == anyerror); } test "error set type" { diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index 44ad2f81fa..e33def59c4 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -105,7 +105,7 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 { test "constant expressions" { var array: [array_size]u8 = undefined; - expect(@sizeOf(@typeOf(array)) == 20); + expect(@sizeOf(@TypeOf(array)) == 20); } const array_size: u8 = 20; @@ -598,7 +598,7 @@ test "pointer to type" { var T: type = i32; expect(T == i32); var ptr = &T; - expect(@typeOf(ptr) == *type); + expect(@TypeOf(ptr) == *type); ptr.* = f32; expect(T == f32); expect(*T == *f32); diff --git a/test/stage1/behavior/fn.zig b/test/stage1/behavior/fn.zig index 385b8bc418..654405df44 100644 --- a/test/stage1/behavior/fn.zig +++ b/test/stage1/behavior/fn.zig @@ -73,7 +73,7 @@ fn fnWithUnreachable() noreturn { } test "function pointers" { - const fns = [_]@typeOf(fn1){ + const fns = [_]@TypeOf(fn1){ fn1, fn2, fn3, @@ -130,7 +130,7 @@ test "pass by non-copying value through var arg" { } fn addPointCoordsVar(pt: var) i32 { - comptime expect(@typeOf(pt) == Point); + comptime expect(@TypeOf(pt) == Point); return pt.x + pt.y; } @@ -170,7 +170,7 @@ test "pass by non-copying value as method, at comptime" { } fn outer(y: u32) fn (u32) u32 { - const Y = @typeOf(y); + const Y = @TypeOf(y); const st = struct { fn get(z: u32) u32 { return z + @sizeOf(Y); @@ -265,7 +265,7 @@ test "ability to give comptime types and non comptime types to same parameter" { } fn foo(arg: var) i32 { - if (@typeInfo(@typeOf(arg)) == .Type and arg == i32) return 20; + if (@typeInfo(@TypeOf(arg)) == .Type and arg == i32) return 20; return 9 + arg; } }; diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig index 5cf75ed497..29b6f934f0 100644 --- a/test/stage1/behavior/for.zig +++ b/test/stage1/behavior/for.zig @@ -29,9 +29,9 @@ test "for loop with pointer elem var" { expect(mem.eql(u8, &target, "bcdefgh")); for (source) |*c, i| - expect(@typeOf(c) == *const u8); + expect(@TypeOf(c) == *const u8); for (target) |*c, i| - expect(@typeOf(c) == *u8); + expect(@TypeOf(c) == *u8); } fn mangleString(s: []u8) void { diff --git a/test/stage1/behavior/generics.zig b/test/stage1/behavior/generics.zig index dc15ae1b8c..a5d2f9dabe 100644 --- a/test/stage1/behavior/generics.zig +++ b/test/stage1/behavior/generics.zig @@ -47,7 +47,7 @@ comptime { expect(max_f64(1.2, 3.4) == 3.4); } -fn max_var(a: var, b: var) @typeOf(a + b) { +fn max_var(a: var, b: var) @TypeOf(a + b) { return if (a > b) a else b; } diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig index 37a23fa325..751275aeb6 100644 --- a/test/stage1/behavior/math.zig +++ b/test/stage1/behavior/math.zig @@ -281,8 +281,8 @@ test "small int addition" { x += 1; expect(x == 3); - var result: @typeOf(x) = 3; - expect(@addWithOverflow(@typeOf(x), x, 1, &result)); + var result: @TypeOf(x) = 3; + expect(@addWithOverflow(@TypeOf(x), x, 1, &result)); expect(result == 0); } @@ -586,7 +586,7 @@ test "@sqrt" { const x = 14.0; const y = x * x; - const z = @sqrt(@typeOf(y), y); + const z = @sqrt(@TypeOf(y), y); comptime expect(z == x); } diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index a3da752f0d..dd3ad29878 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -362,8 +362,8 @@ test "string concatenation" { const a = "OK" ++ " IT " ++ "WORKED"; const b = "OK IT WORKED"; - comptime expect(@typeOf(a) == *const [12:0]u8); - comptime expect(@typeOf(b) == *const [12:0]u8); + comptime expect(@TypeOf(a) == *const [12:0]u8); + comptime expect(@TypeOf(b) == *const [12:0]u8); const len = mem.len(u8, b); const len_with_null = len + 1; @@ -460,19 +460,19 @@ test "@typeId" { expect(@typeId(*f32) == Tid.Pointer); expect(@typeId([2]u8) == Tid.Array); expect(@typeId(AStruct) == Tid.Struct); - expect(@typeId(@typeOf(1)) == Tid.ComptimeInt); - expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat); - expect(@typeId(@typeOf(undefined)) == Tid.Undefined); - expect(@typeId(@typeOf(null)) == Tid.Null); + expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt); + expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat); + expect(@typeId(@TypeOf(undefined)) == Tid.Undefined); + expect(@typeId(@TypeOf(null)) == Tid.Null); expect(@typeId(?i32) == Tid.Optional); expect(@typeId(anyerror!i32) == Tid.ErrorUnion); expect(@typeId(anyerror) == Tid.ErrorSet); expect(@typeId(AnEnum) == Tid.Enum); - expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); + expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum); expect(@typeId(AUnionEnum) == Tid.Union); expect(@typeId(AUnion) == Tid.Union); expect(@typeId(fn () void) == Tid.Fn); - expect(@typeId(@typeOf(builtin)) == Tid.Type); + expect(@typeId(@TypeOf(builtin)) == Tid.Type); // TODO bound fn // TODO arg tuple // TODO opaque @@ -652,9 +652,9 @@ test "volatile load and store" { test "slice string literal has type []const u8" { comptime { - expect(@typeOf("aoeu"[0..]) == []const u8); + expect(@TypeOf("aoeu"[0..]) == []const u8); const array = [_]i32{ 1, 2, 3, 4 }; - expect(@typeOf(array[0..]) == []const i32); + expect(@TypeOf(array[0..]) == []const i32); } } diff --git a/test/stage1/behavior/pointers.zig b/test/stage1/behavior/pointers.zig index 58a46b539c..cb69762eda 100644 --- a/test/stage1/behavior/pointers.zig +++ b/test/stage1/behavior/pointers.zig @@ -93,10 +93,10 @@ test "peer type resolution with C pointers" { var x2 = if (t) ptr_many else ptr_c; var x3 = if (t) ptr_c else ptr_one; var x4 = if (t) ptr_c else ptr_many; - expect(@typeOf(x1) == [*c]u8); - expect(@typeOf(x2) == [*c]u8); - expect(@typeOf(x3) == [*c]u8); - expect(@typeOf(x4) == [*c]u8); + expect(@TypeOf(x1) == [*c]u8); + expect(@TypeOf(x2) == [*c]u8); + expect(@TypeOf(x3) == [*c]u8); + expect(@TypeOf(x4) == [*c]u8); } test "implicit casting between C pointer and optional non-C pointer" { @@ -144,11 +144,11 @@ test "allowzero pointer and slice" { expect(opt_ptr != null); expect(@ptrToInt(ptr) == 0); var slice = ptr[0..10]; - expect(@typeOf(slice) == []allowzero i32); + expect(@TypeOf(slice) == []allowzero i32); expect(@ptrToInt(&slice[5]) == 20); - expect(@typeInfo(@typeOf(ptr)).Pointer.is_allowzero); - expect(@typeInfo(@typeOf(slice)).Pointer.is_allowzero); + expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); + expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); } test "assign null directly to C pointer and test null equality" { @@ -204,7 +204,7 @@ test "assign null directly to C pointer and test null equality" { test "null terminated pointer" { const S = struct { fn doTheTest() void { - var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'}; + var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); var no_zero_ptr: [*]const u8 = zero_ptr; var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr); @@ -218,7 +218,7 @@ test "null terminated pointer" { test "allow any sentinel" { const S = struct { fn doTheTest() void { - var array = [_:std.math.minInt(i32)]i32{1, 2, 3, 4}; + var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; var ptr: [*:std.math.minInt(i32)]i32 = &array; expect(ptr[4] == std.math.minInt(i32)); } @@ -229,10 +229,14 @@ test "allow any sentinel" { test "pointer sentinel with enums" { const S = struct { - const Number = enum{one, two, sentinel}; + const Number = enum { + one, + two, + sentinel, + }; fn doTheTest() void { - var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{.one, .two, .two, .one}; + var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731 } }; @@ -243,7 +247,7 @@ test "pointer sentinel with enums" { test "pointer sentinel with optional element" { const S = struct { fn doTheTest() void { - var ptr: [*:null]?i32 = &[_:null]?i32{1, 2, 3, 4}; + var ptr: [*:null]?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; expect(ptr[4] == null); // TODO this should be comptime expect, see #3731 } }; @@ -255,7 +259,7 @@ test "pointer sentinel with +inf" { const S = struct { fn doTheTest() void { const inf = std.math.inf_f32; - var ptr: [*:inf]f32 = &[_:inf]f32{1.1, 2.2, 3.3, 4.4}; + var ptr: [*:inf]f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 }; expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731 } }; diff --git a/test/stage1/behavior/ptrcast.zig b/test/stage1/behavior/ptrcast.zig index 4c17b38e6e..1c1cf251a0 100644 --- a/test/stage1/behavior/ptrcast.zig +++ b/test/stage1/behavior/ptrcast.zig @@ -55,7 +55,7 @@ test "comptime ptrcast keeps larger alignment" { comptime { const a: u32 = 1234; const p = @ptrCast([*]const u8, &a); - std.debug.assert(@typeOf(p) == [*]align(@alignOf(u32)) const u8); + std.debug.assert(@TypeOf(p) == [*]align(@alignOf(u32)) const u8); } } diff --git a/test/stage1/behavior/reflection.zig b/test/stage1/behavior/reflection.zig index 12067ee51d..37bf2a582c 100644 --- a/test/stage1/behavior/reflection.zig +++ b/test/stage1/behavior/reflection.zig @@ -13,12 +13,12 @@ test "reflection: array, pointer, optional, error union type child" { test "reflection: function return type, var args, and param types" { comptime { - expect(@typeOf(dummy).ReturnType == i32); - expect(!@typeOf(dummy).is_var_args); - expect(@typeOf(dummy).arg_count == 3); - expect(@ArgType(@typeOf(dummy), 0) == bool); - expect(@ArgType(@typeOf(dummy), 1) == i32); - expect(@ArgType(@typeOf(dummy), 2) == f32); + expect(@TypeOf(dummy).ReturnType == i32); + expect(!@TypeOf(dummy).is_var_args); + expect(@TypeOf(dummy).arg_count == 3); + expect(@ArgType(@TypeOf(dummy), 0) == bool); + expect(@ArgType(@TypeOf(dummy), 1) == i32); + expect(@ArgType(@TypeOf(dummy), 2) == f32); } } diff --git a/test/stage1/behavior/sizeof_and_typeof.zig b/test/stage1/behavior/sizeof_and_typeof.zig index 0369be9989..d46cdccd0d 100644 --- a/test/stage1/behavior/sizeof_and_typeof.zig +++ b/test/stage1/behavior/sizeof_and_typeof.zig @@ -1,12 +1,12 @@ const builtin = @import("builtin"); const expect = @import("std").testing.expect; -test "@sizeOf and @typeOf" { - const y: @typeOf(x) = 120; - expect(@sizeOf(@typeOf(y)) == 2); +test "@sizeOf and @TypeOf" { + const y: @TypeOf(x) = 120; + expect(@sizeOf(@TypeOf(y)) == 2); } const x: u16 = 13; -const z: @typeOf(x) = 19; +const z: @TypeOf(x) = 19; const A = struct { a: u8, @@ -71,8 +71,8 @@ test "@bitOffsetOf" { test "@sizeOf on compile-time types" { expect(@sizeOf(comptime_int) == 0); expect(@sizeOf(comptime_float) == 0); - expect(@sizeOf(@typeOf(.hi)) == 0); - expect(@sizeOf(@typeOf(type)) == 0); + expect(@sizeOf(@TypeOf(.hi)) == 0); + expect(@sizeOf(@TypeOf(type)) == 0); } test "@sizeOf(T) == 0 doesn't force resolving struct size" { @@ -90,7 +90,7 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" { expect(@sizeOf(S.Bar) == 8); } -test "@typeOf() has no runtime side effects" { +test "@TypeOf() has no runtime side effects" { const S = struct { fn foo(comptime T: type, ptr: *T) T { ptr.* += 1; @@ -98,12 +98,12 @@ test "@typeOf() has no runtime side effects" { } }; var data: i32 = 0; - const T = @typeOf(S.foo(i32, &data)); + const T = @TypeOf(S.foo(i32, &data)); comptime expect(T == i32); expect(data == 0); } -test "branching logic inside @typeOf" { +test "branching logic inside @TypeOf" { const S = struct { var data: i32 = 0; fn foo() anyerror!i32 { @@ -111,7 +111,7 @@ test "branching logic inside @typeOf" { return undefined; } }; - const T = @typeOf(S.foo() catch undefined); + const T = @TypeOf(S.foo() catch undefined); comptime expect(T == i32); expect(S.data == 0); } diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig index 1a18a5c440..625585cd9e 100644 --- a/test/stage1/behavior/switch.zig +++ b/test/stage1/behavior/switch.zig @@ -406,7 +406,7 @@ test "switch prongs with cases with identical payload types" { fn doTheSwitch1(u: Union) void { switch (u) { .A, .C => |e| { - expect(@typeOf(e) == usize); + expect(@TypeOf(e) == usize); expect(e == 8); }, .B => |e| @panic("fail"), @@ -416,7 +416,7 @@ test "switch prongs with cases with identical payload types" { switch (u) { .A, .C => |e| @panic("fail"), .B => |e| { - expect(@typeOf(e) == isize); + expect(@TypeOf(e) == isize); expect(e == -8); }, } diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig index dfdc729c42..67c78b305f 100644 --- a/test/stage1/behavior/type.zig +++ b/test/stage1/behavior/type.zig @@ -125,10 +125,10 @@ test "Type.ComptimeInt" { testTypes(&[_]type{comptime_int}); } test "Type.Undefined" { - testTypes(&[_]type{@typeOf(undefined)}); + testTypes(&[_]type{@TypeOf(undefined)}); } test "Type.Null" { - testTypes(&[_]type{@typeOf(null)}); + testTypes(&[_]type{@TypeOf(null)}); } test "@Type create slice with null sentinel" { const Slice = @Type(builtin.TypeInfo{ diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index a0fd4a4e6c..5a7268443d 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -201,7 +201,7 @@ fn testUnion() void { expect(typeinfo_info.Union.fields.len == 25); expect(typeinfo_info.Union.fields[4].enum_field != null); expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); - expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); + expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); expect(typeinfo_info.Union.decls.len == 21); const TestNoTagUnion = union { @@ -264,7 +264,7 @@ test "type info: function type info" { } fn testFunction() void { - const fn_info = @typeInfo(@typeOf(foo)); + const fn_info = @typeInfo(@TypeOf(foo)); expect(@as(TypeId, fn_info) == TypeId.Fn); expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); expect(fn_info.Fn.is_generic); @@ -273,7 +273,7 @@ fn testFunction() void { expect(fn_info.Fn.return_type == null); const test_instance: TestStruct = undefined; - const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); + const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo)); expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); } diff --git a/test/stage1/behavior/undefined.zig b/test/stage1/behavior/undefined.zig index 4f2cbed3bc..3506e7e240 100644 --- a/test/stage1/behavior/undefined.zig +++ b/test/stage1/behavior/undefined.zig @@ -64,5 +64,5 @@ test "assign undefined to struct with method" { test "type name of undefined" { const x = undefined; - expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)")); + expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)")); } diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig index b6033ea660..338f24d806 100644 --- a/test/stage1/behavior/vector.zig +++ b/test/stage1/behavior/vector.zig @@ -148,7 +148,7 @@ test "vector @splat" { fn doTheTest() void { var v: u32 = 5; var x = @splat(4, v); - expect(@typeOf(x) == @Vector(4, u32)); + expect(@TypeOf(x) == @Vector(4, u32)); var array_x: [4]u32 = x; expect(array_x[0] == 5); expect(array_x[1] == 5); diff --git a/test/translate_c.zig b/test/translate_c.zig index a2ee07f219..aa27651241 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("macro pointer cast", \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) , &[_][]const u8{ - \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); + \\pub const NRF_GPIO = if (@typeId(@TypeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@TypeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); }); cases.add("if on non-bool", diff --git a/tools/merge_anal_dumps.zig b/tools/merge_anal_dumps.zig index c62b8aa848..e0e71696d6 100644 --- a/tools/merge_anal_dumps.zig +++ b/tools/merge_anal_dumps.zig @@ -311,7 +311,7 @@ const Dump = struct { } fn render(self: *Dump, stream: var) !void { - var jw = json.WriteStream(@typeOf(stream).Child, 10).init(stream); + var jw = json.WriteStream(@TypeOf(stream).Child, 10).init(stream); try jw.beginObject(); try jw.objectField("typeKinds"); -- cgit v1.2.3 From c3d8b1ffebb94d180c382bd74128d17dc21c1392 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 10 Dec 2019 15:08:10 -0500 Subject: remove iterator API from std.ArrayList This is not a meaningful abstraction. Use a for loop on the result of `toSlice` or `toSliceConst`. An iterator can be implemented on top of ArrayList by applications which want additional functionality, such as removing elements while iterating. Closes #3037. --- lib/std/array_list.zig | 69 ++++-------------------------------------------- lib/std/http/headers.zig | 65 ++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 103 deletions(-) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 33260a88df..444de30162 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -84,11 +84,6 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { self.items[i] = item; } - /// Return length of the list. - pub fn count(self: Self) usize { - return self.len; - } - /// Return the maximum number of items the list can hold /// without allocating more memory. pub fn capacity(self: Self) usize { @@ -114,7 +109,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return result; } - /// Insert `item` at index `n`. Moves `list[n .. list.count()]` + /// Insert `item` at index `n`. Moves `list[n .. list.len]` /// to make room. pub fn insert(self: *Self, n: usize, item: T) !void { try self.ensureCapacity(self.len + 1); @@ -125,7 +120,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { } /// Insert slice `items` at index `n`. Moves - /// `list[n .. list.count()]` to make room. + /// `list[n .. list.len]` to make room. pub fn insertSlice(self: *Self, n: usize, items: SliceConst) !void { try self.ensureCapacity(self.len + items.len); self.len += items.len; @@ -222,7 +217,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { } pub fn addOneAssumeCapacity(self: *Self) *T { - assert(self.count() < self.capacity()); + assert(self.len < self.capacity()); const result = &self.items[self.len]; self.len += 1; return result; @@ -240,31 +235,6 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { if (self.len == 0) return null; return self.pop(); } - - pub const Iterator = struct { - list: *const Self, - // how many items have we returned - count: usize, - - pub fn next(it: *Iterator) ?T { - if (it.count >= it.list.len) return null; - const val = it.list.at(it.count); - it.count += 1; - return val; - } - - pub fn reset(it: *Iterator) void { - it.count = 0; - } - }; - - /// Return an iterator over the list. - pub fn iterator(self: *const Self) Iterator { - return Iterator{ - .list = self, - .count = 0, - }; - } }; } @@ -275,7 +245,7 @@ test "std.ArrayList.init" { var list = ArrayList(i32).init(allocator); defer list.deinit(); - testing.expect(list.count() == 0); + testing.expect(list.len == 0); testing.expect(list.capacity() == 0); } @@ -284,7 +254,7 @@ test "std.ArrayList.initCapacity" { const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator; var list = try ArrayList(i8).initCapacity(allocator, 200); defer list.deinit(); - testing.expect(list.count() == 0); + testing.expect(list.len == 0); testing.expect(list.capacity() >= 200); } @@ -426,35 +396,6 @@ test "std.ArrayList.swapRemoveOrError" { testing.expectError(error.OutOfBounds, list.swapRemoveOrError(2)); } -test "std.ArrayList.iterator" { - var list = ArrayList(i32).init(debug.global_allocator); - defer list.deinit(); - - try list.append(1); - try list.append(2); - try list.append(3); - - var count: i32 = 0; - var it = list.iterator(); - while (it.next()) |next| { - testing.expect(next == count + 1); - count += 1; - } - - testing.expect(count == 3); - testing.expect(it.next() == null); - it.reset(); - count = 0; - while (it.next()) |next| { - testing.expect(next == count + 1); - count += 1; - if (count == 2) break; - } - - it.reset(); - testing.expect(it.next().? == 1); -} - test "std.ArrayList.insert" { var list = ArrayList(i32).init(debug.global_allocator); defer list.deinit(); diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index e02a2187d6..588ee7f796 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -133,8 +133,7 @@ pub const Headers = struct { self.index.deinit(); } { - var it = self.data.iterator(); - while (it.next()) |entry| { + for (self.data.toSliceConst()) |entry| { entry.deinit(); } self.data.deinit(); @@ -144,27 +143,20 @@ pub const Headers = struct { pub fn clone(self: Self, allocator: *Allocator) !Self { var other = Headers.init(allocator); errdefer other.deinit(); - try other.data.ensureCapacity(self.data.count()); + try other.data.ensureCapacity(self.data.len); try other.index.initCapacity(self.index.entries.len); - var it = self.data.iterator(); - while (it.next()) |entry| { + for (self.data.toSliceConst()) |entry| { try other.append(entry.name, entry.value, entry.never_index); } return other; } - pub fn count(self: Self) usize { - return self.data.count(); - } - - pub const Iterator = HeaderList.Iterator; - - pub fn iterator(self: Self) Iterator { - return self.data.iterator(); + pub fn toSlice(self: Self) []const HeaderEntry { + return self.data.toSliceConst(); } pub fn append(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void { - const n = self.data.count() + 1; + const n = self.data.len + 1; try self.data.ensureCapacity(n); var entry: HeaderEntry = undefined; if (self.index.get(name)) |kv| { @@ -190,7 +182,7 @@ pub const Headers = struct { pub fn upsert(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void { if (self.index.get(name)) |kv| { const dex = kv.value; - if (dex.count() != 1) + if (dex.len != 1) return error.CannotUpsertMultiValuedField; var e = &self.data.at(dex.at(0)); try e.modify(value, never_index); @@ -209,7 +201,7 @@ pub const Headers = struct { if (self.index.remove(name)) |kv| { var dex = &kv.value; // iterate backwards - var i = dex.count(); + var i = dex.len; while (i > 0) { i -= 1; const data_index = dex.at(i); @@ -232,18 +224,18 @@ pub const Headers = struct { const removed = self.data.orderedRemove(i); const kv = self.index.get(removed.name).?; var dex = &kv.value; - if (dex.count() == 1) { + if (dex.len == 1) { // was last item; delete the index _ = self.index.remove(kv.key); dex.deinit(); removed.deinit(); self.allocator.free(kv.key); } else { - dex.shrink(dex.count() - 1); + dex.shrink(dex.len - 1); removed.deinit(); } // if it was the last item; no need to rebuild index - if (i != self.data.count()) { + if (i != self.data.len) { self.rebuild_index(); } } @@ -254,18 +246,18 @@ pub const Headers = struct { const removed = self.data.swapRemove(i); const kv = self.index.get(removed.name).?; var dex = &kv.value; - if (dex.count() == 1) { + if (dex.len == 1) { // was last item; delete the index _ = self.index.remove(kv.key); dex.deinit(); removed.deinit(); self.allocator.free(kv.key); } else { - dex.shrink(dex.count() - 1); + dex.shrink(dex.len - 1); removed.deinit(); } // if it was the last item; no need to rebuild index - if (i != self.data.count()) { + if (i != self.data.len) { self.rebuild_index(); } } @@ -289,10 +281,9 @@ pub const Headers = struct { pub fn get(self: Self, allocator: *Allocator, name: []const u8) !?[]const HeaderEntry { const dex = self.getIndices(name) orelse return null; - const buf = try allocator.alloc(HeaderEntry, dex.count()); - var it = dex.iterator(); + const buf = try allocator.alloc(HeaderEntry, dex.len); var n: usize = 0; - while (it.next()) |idx| { + for (dex.toSliceConst()) |idx| { buf[n] = self.data.at(idx); n += 1; } @@ -314,9 +305,8 @@ pub const Headers = struct { // adapted from mem.join const total_len = blk: { - var sum: usize = dex.count() - 1; // space for separator(s) - var it = dex.iterator(); - while (it.next()) |idx| + var sum: usize = dex.len - 1; // space for separator(s) + for (dex.toSliceConst()) |idx| sum += self.data.at(idx).value.len; break :blk sum; }; @@ -348,10 +338,9 @@ pub const Headers = struct { } } { // fill up indexes again; we know capacity is fine from before - var it = self.data.iterator(); - while (it.next()) |entry| { + for (self.data.toSliceConst()) |entry, i| { var dex = &self.index.get(entry.name).?.value; - dex.appendAssumeCapacity(it.count); + dex.appendAssumeCapacity(i); } } } @@ -369,8 +358,7 @@ pub const Headers = struct { comptime Errors: type, output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { - var it = self.iterator(); - while (it.next()) |entry| { + for (self.toSlice()) |entry| { try output(context, entry.name); try output(context, ": "); try output(context, entry.value); @@ -386,8 +374,7 @@ test "Headers.iterator" { try h.append("cookie", "somevalue", null); var count: i32 = 0; - var it = h.iterator(); - while (it.next()) |e| { + for (h.toSlice()) |e| { if (count == 0) { testing.expectEqualSlices(u8, "foo", e.name); testing.expectEqualSlices(u8, "bar", e.value); @@ -420,10 +407,10 @@ test "Headers.delete" { try h.append("cookie", "somevalue", null); testing.expectEqual(false, h.delete("not-present")); - testing.expectEqual(@as(usize, 3), h.count()); + testing.expectEqual(@as(usize, 3), h.toSlice().len); testing.expectEqual(true, h.delete("foo")); - testing.expectEqual(@as(usize, 2), h.count()); + testing.expectEqual(@as(usize, 2), h.toSlice().len); { const e = h.at(0); testing.expectEqualSlices(u8, "baz", e.name); @@ -448,7 +435,7 @@ test "Headers.orderedRemove" { try h.append("cookie", "somevalue", null); h.orderedRemove(0); - testing.expectEqual(@as(usize, 2), h.count()); + testing.expectEqual(@as(usize, 2), h.toSlice().len); { const e = h.at(0); testing.expectEqualSlices(u8, "baz", e.name); @@ -471,7 +458,7 @@ test "Headers.swapRemove" { try h.append("cookie", "somevalue", null); h.swapRemove(0); - testing.expectEqual(@as(usize, 2), h.count()); + testing.expectEqual(@as(usize, 2), h.toSlice().len); { const e = h.at(0); testing.expectEqualSlices(u8, "cookie", e.name); -- cgit v1.2.3 From fb2f0cc497c0af897a3d2dd3f612e50522368221 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 12 Nov 2019 09:14:38 +0100 Subject: ArrayList: ptrAt function returns pointer to item at given index --- lib/std/array_list.zig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 444de30162..64f13eff9b 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -71,6 +71,11 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return self.toSliceConst()[i]; } + /// Safely access ptr to index i of the list. + pub fn ptrAt(self: Self, i: usize) *T { + return &self.toSlice()[i]; + } + /// Sets the value at index `i`, or returns `error.OutOfBounds` if /// the index is not in range. pub fn setOrError(self: Self, i: usize, item: T) !void { -- cgit v1.2.3