Skip to content

Commit e0db54e

Browse files
committed
update the codebase to use @as
1 parent 2a6fbbd commit e0db54e

File tree

206 files changed

+1287
-1282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+1287
-1282
lines changed

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
155155
) catch unreachable;
156156
for (dep.system_libs.toSliceConst()) |lib| {
157157
const static_bare_name = if (mem.eql(u8, lib, "curses"))
158-
([]const u8)("libncurses.a")
158+
@as([]const u8,"libncurses.a")
159159
else
160160
b.fmt("lib{}.a", lib);
161161
const static_lib_name = fs.path.join(

lib/std/array_list.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" {
344344
try list.append(7);
345345

346346
//remove from middle
347-
testing.expectEqual(i32(4), list.orderedRemove(3));
348-
testing.expectEqual(i32(5), list.at(3));
349-
testing.expectEqual(usize(6), list.len);
347+
testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
348+
testing.expectEqual(@as(i32, 5), list.at(3));
349+
testing.expectEqual(@as(usize, 6), list.len);
350350

351351
//remove from end
352-
testing.expectEqual(i32(7), list.orderedRemove(5));
353-
testing.expectEqual(usize(5), list.len);
352+
testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
353+
testing.expectEqual(@as(usize, 5), list.len);
354354

355355
//remove from front
356-
testing.expectEqual(i32(1), list.orderedRemove(0));
357-
testing.expectEqual(i32(2), list.at(0));
358-
testing.expectEqual(usize(4), list.len);
356+
testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
357+
testing.expectEqual(@as(i32, 2), list.at(0));
358+
testing.expectEqual(@as(usize, 4), list.len);
359359
}
360360

361361
test "std.ArrayList.swapRemove" {

lib/std/ascii.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,26 @@ const combinedTable = init: {
129129
comptime var i = 0;
130130
inline while (i < 128) : (i += 1) {
131131
table[i] =
132-
u8(alpha[i]) << @enumToInt(tIndex.Alpha) |
133-
u8(hex[i]) << @enumToInt(tIndex.Hex) |
134-
u8(space[i]) << @enumToInt(tIndex.Space) |
135-
u8(digit[i]) << @enumToInt(tIndex.Digit) |
136-
u8(lower[i]) << @enumToInt(tIndex.Lower) |
137-
u8(upper[i]) << @enumToInt(tIndex.Upper) |
138-
u8(punct[i]) << @enumToInt(tIndex.Punct) |
139-
u8(graph[i]) << @enumToInt(tIndex.Graph);
132+
@as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) |
133+
@as(u8, hex[i]) << @enumToInt(tIndex.Hex) |
134+
@as(u8, space[i]) << @enumToInt(tIndex.Space) |
135+
@as(u8, digit[i]) << @enumToInt(tIndex.Digit) |
136+
@as(u8, lower[i]) << @enumToInt(tIndex.Lower) |
137+
@as(u8, upper[i]) << @enumToInt(tIndex.Upper) |
138+
@as(u8, punct[i]) << @enumToInt(tIndex.Punct) |
139+
@as(u8, graph[i]) << @enumToInt(tIndex.Graph);
140140
}
141141
mem.set(u8, table[128..256], 0);
142142
break :init table;
143143
};
144144

145145
fn inTable(c: u8, t: tIndex) bool {
146-
return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0;
146+
return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
147147
}
148148

149149
pub fn isAlNum(c: u8) bool {
150-
return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) |
151-
u8(1) << @enumToInt(tIndex.Digit))) != 0;
150+
return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
151+
@as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
152152
}
153153

154154
pub fn isAlpha(c: u8) bool {

lib/std/atomic/queue.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ test "std.atomic.Queue" {
214214
std.debug.panic(
215215
"failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
216216
context.get_count,
217-
u32(puts_per_thread),
218-
u32(put_thread_count),
217+
@as(u32, puts_per_thread),
218+
@as(u32, put_thread_count),
219219
);
220220
}
221221
}

lib/std/atomic/stack.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type {
1111
root: ?*Node,
1212
lock: @typeOf(lock_init),
1313

14-
const lock_init = if (builtin.single_threaded) {} else u8(0);
14+
const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);
1515

1616
pub const Self = @This();
1717

@@ -141,8 +141,8 @@ test "std.atomic.stack" {
141141
std.debug.panic(
142142
"failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
143143
context.get_count,
144-
u32(puts_per_thread),
145-
u32(put_thread_count),
144+
@as(u32, puts_per_thread),
145+
@as(u32, put_thread_count),
146146
);
147147
}
148148
}

lib/std/bloom_filter.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ test "std.BloomFilter" {
171171
testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
172172
}
173173
testing.expectEqual(BF.Index(0), bf.popCount());
174-
testing.expectEqual(f64(0), bf.estimateItems());
174+
testing.expectEqual(@as(f64, 0), bf.estimateItems());
175175
// fill in a few items
176176
bf.incrementCell(42);
177177
bf.incrementCell(255);
@@ -197,7 +197,7 @@ test "std.BloomFilter" {
197197
testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
198198
}
199199
testing.expectEqual(BF.Index(0), bf.popCount());
200-
testing.expectEqual(f64(0), bf.estimateItems());
200+
testing.expectEqual(@as(f64, 0), bf.estimateItems());
201201

202202
// Lets add a string
203203
bf.add("foo");
@@ -219,7 +219,7 @@ test "std.BloomFilter" {
219219
testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
220220
}
221221
testing.expectEqual(BF.Index(0), bf.popCount());
222-
testing.expectEqual(f64(0), bf.estimateItems());
222+
testing.expectEqual(@as(f64, 0), bf.estimateItems());
223223

224224
comptime var teststrings = [_][]const u8{
225225
"foo",

lib/std/c/darwin.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo
5353
pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
5454

5555
pub fn sigaddset(set: *sigset_t, signo: u5) void {
56-
set.* |= u32(1) << (signo - 1);
56+
set.* |= @as(u32, 1) << (signo - 1);
5757
}
5858

5959
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;

lib/std/child_process.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void {
717717
// Child of fork calls this to report an error to the fork parent.
718718
// Then the child exits.
719719
fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
720-
writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};
720+
writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {};
721721
os.exit(1);
722722
}
723723

lib/std/crypto/aes.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const testing = std.testing;
66

77
// Apply sbox0 to each byte in w.
88
fn subw(w: u32) u32 {
9-
return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]);
9+
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]);
1010
}
1111

1212
fn rotw(w: u32) u32 {
@@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
4848
}
4949

5050
// Last round uses s-box directly and XORs to produce output.
51-
s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]);
52-
s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | u32(sbox0[t0 & 0xff]);
53-
s2 = u32(sbox0[t2 >> 24]) << 24 | u32(sbox0[t3 >> 16 & 0xff]) << 16 | u32(sbox0[t0 >> 8 & 0xff]) << 8 | u32(sbox0[t1 & 0xff]);
54-
s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 0xff]);
51+
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]);
52+
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]);
53+
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]);
54+
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]);
5555

5656
s0 ^= xk[k + 0];
5757
s1 ^= xk[k + 1];
@@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
9999
}
100100

101101
// Last round uses s-box directly and XORs to produce output.
102-
s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]);
103-
s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | u32(sbox1[t2 & 0xff]);
104-
s2 = u32(sbox1[t2 >> 24]) << 24 | u32(sbox1[t1 >> 16 & 0xff]) << 16 | u32(sbox1[t0 >> 8 & 0xff]) << 8 | u32(sbox1[t3 & 0xff]);
105-
s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 0xff]);
102+
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]);
103+
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]);
104+
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]);
105+
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]);
106106

107107
s0 ^= xk[k + 0];
108108
s1 ^= xk[k + 1];
@@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void {
256256
while (i < enc.len) : (i += 1) {
257257
var t = enc[i - 1];
258258
if (i % nk == 0) {
259-
t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24);
259+
t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24);
260260
} else if (nk > 6 and i % nk == 4) {
261261
t = subw(t);
262262
}

lib/std/crypto/blake2.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type {
164164
inline while (j < 10) : (j += 1) {
165165
inline for (rounds) |r| {
166166
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
167-
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16));
167+
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16));
168168
v[r.c] = v[r.c] +% v[r.d];
169-
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12));
169+
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12));
170170
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
171-
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8));
171+
v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8));
172172
v[r.c] = v[r.c] +% v[r.d];
173-
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7));
173+
v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7));
174174
}
175175
}
176176

@@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type {
398398
inline while (j < 12) : (j += 1) {
399399
inline for (rounds) |r| {
400400
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
401-
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32));
401+
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32));
402402
v[r.c] = v[r.c] +% v[r.d];
403-
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24));
403+
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24));
404404
v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
405-
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16));
405+
v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16));
406406
v[r.c] = v[r.c] +% v[r.d];
407-
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63));
407+
v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63));
408408
}
409409
}
410410

0 commit comments

Comments
 (0)