authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-07 18:52:09-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-08 15:57:25-05:00
logaa0daea5415dd2a20e4d7c2fd047b7bcee6c9ea4
treeb8634d38380eb6fd32ca614678785f36167ca7b2
parenta2acc2787242fdee189ec4197c0dd847b8245139
signaturelock-open Commit is signed but in an unrecognized format.

update more of the std lib to use `@as`


28 files changed, 145 insertions(+), 145 deletions(-)

lib/std/bloom_filter.zig+8-8
......@@ -28,7 +28,7 @@ pub fn BloomFilter(
2828 assert(n_items > 0);
2929 assert(math.isPowerOfTwo(n_items));
3030 assert(K > 0);
31 const cellEmpty = if (Cell == bool) false else Cell(0);
31 const cellEmpty = if (Cell == bool) false else @as(Cell, 0);
3232 const cellMax = if (Cell == bool) true else math.maxInt(Cell);
3333 const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8;
3434 assert(n_bytes > 0);
......@@ -137,7 +137,7 @@ pub fn BloomFilter(
137137 var i: usize = 0;
138138 while (i < n_items) : (i += 1) {
139139 const cell = self.getCell(@intCast(Index, i));
140 n += if (if (Cell == bool) cell else cell > 0) Index(1) else Index(0);
140 n += if (if (Cell == bool) cell else cell > 0) @as(Index, 1) else @as(Index, 0);
141141 }
142142 }
143143 return n;
......@@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void {
161161
162162test "std.BloomFilter" {
163163 inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| {
164 const emptyCell = if (Cell == bool) false else Cell(0);
164 const emptyCell = if (Cell == bool) false else @as(Cell, 0);
165165 const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc);
166166 var bf = BF{};
167167 var i: usize = undefined;
......@@ -170,7 +170,7 @@ test "std.BloomFilter" {
170170 while (i < BF.items) : (i += 1) {
171171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
172172 }
173 testing.expectEqual(BF.Index(0), bf.popCount());
173 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
174174 testing.expectEqual(@as(f64, 0), bf.estimateItems());
175175 // fill in a few items
176176 bf.incrementCell(42);
......@@ -196,7 +196,7 @@ test "std.BloomFilter" {
196196 while (i < BF.items) : (i += 1) {
197197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
198198 }
199 testing.expectEqual(BF.Index(0), bf.popCount());
199 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
200200 testing.expectEqual(@as(f64, 0), bf.estimateItems());
201201
202202 // Lets add a string
......@@ -218,7 +218,7 @@ test "std.BloomFilter" {
218218 while (i < BF.items) : (i += 1) {
219219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
220220 }
221 testing.expectEqual(BF.Index(0), bf.popCount());
221 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
222222 testing.expectEqual(@as(f64, 0), bf.estimateItems());
223223
224224 comptime var teststrings = [_][]const u8{
......@@ -246,12 +246,12 @@ test "std.BloomFilter" {
246246 inline for (teststrings) |str| {
247247 testing.expectEqual(true, larger_bf.contains(str));
248248 }
249 testing.expectEqual(u12(bf.popCount()) * (4096 / 1024), larger_bf.popCount());
249 testing.expectEqual(@as(u12, bf.popCount()) * (4096 / 1024), larger_bf.popCount());
250250
251251 const smaller_bf = bf.resize(64);
252252 inline for (teststrings) |str| {
253253 testing.expectEqual(true, smaller_bf.contains(str));
254254 }
255 testing.expect(bf.popCount() <= u10(smaller_bf.popCount()) * (1024 / 64));
255 testing.expect(bf.popCount() <= @as(u10, smaller_bf.popCount()) * (1024 / 64));
256256 }
257257}
lib/std/crypto/x25519.zig+23-23
......@@ -199,9 +199,9 @@ const Fe = struct {
199199 inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void {
200200 const j = (i + 1) % 10;
201201
202 c[i] = (t[i] + (i64(1) << shift)) >> (shift + 1);
202 c[i] = (t[i] + (@as(i64, 1) << shift)) >> (shift + 1);
203203 t[j] += c[i] * mult;
204 t[i] -= c[i] * (i64(1) << (shift + 1));
204 t[i] -= c[i] * (@as(i64, 1) << (shift + 1));
205205 }
206206
207207 fn carry1(h: *Fe, t: []i64) void {
......@@ -273,7 +273,7 @@ const Fe = struct {
273273 var t: [10]i64 = undefined;
274274
275275 for (t[0..]) |_, i| {
276 t[i] = i64(f.b[i]) * g;
276 t[i] = @as(i64, f.b[i]) * g;
277277 }
278278
279279 carry1(h, t[0..]);
......@@ -305,16 +305,16 @@ const Fe = struct {
305305 // t's become h
306306 var t: [10]i64 = undefined;
307307
308 t[0] = f[0] * i64(g[0]) + F[1] * i64(G[9]) + f[2] * i64(G[8]) + F[3] * i64(G[7]) + f[4] * i64(G[6]) + F[5] * i64(G[5]) + f[6] * i64(G[4]) + F[7] * i64(G[3]) + f[8] * i64(G[2]) + F[9] * i64(G[1]);
309 t[1] = f[0] * i64(g[1]) + f[1] * i64(g[0]) + f[2] * i64(G[9]) + f[3] * i64(G[8]) + f[4] * i64(G[7]) + f[5] * i64(G[6]) + f[6] * i64(G[5]) + f[7] * i64(G[4]) + f[8] * i64(G[3]) + f[9] * i64(G[2]);
310 t[2] = f[0] * i64(g[2]) + F[1] * i64(g[1]) + f[2] * i64(g[0]) + F[3] * i64(G[9]) + f[4] * i64(G[8]) + F[5] * i64(G[7]) + f[6] * i64(G[6]) + F[7] * i64(G[5]) + f[8] * i64(G[4]) + F[9] * i64(G[3]);
311 t[3] = f[0] * i64(g[3]) + f[1] * i64(g[2]) + f[2] * i64(g[1]) + f[3] * i64(g[0]) + f[4] * i64(G[9]) + f[5] * i64(G[8]) + f[6] * i64(G[7]) + f[7] * i64(G[6]) + f[8] * i64(G[5]) + f[9] * i64(G[4]);
312 t[4] = f[0] * i64(g[4]) + F[1] * i64(g[3]) + f[2] * i64(g[2]) + F[3] * i64(g[1]) + f[4] * i64(g[0]) + F[5] * i64(G[9]) + f[6] * i64(G[8]) + F[7] * i64(G[7]) + f[8] * i64(G[6]) + F[9] * i64(G[5]);
313 t[5] = f[0] * i64(g[5]) + f[1] * i64(g[4]) + f[2] * i64(g[3]) + f[3] * i64(g[2]) + f[4] * i64(g[1]) + f[5] * i64(g[0]) + f[6] * i64(G[9]) + f[7] * i64(G[8]) + f[8] * i64(G[7]) + f[9] * i64(G[6]);
314 t[6] = f[0] * i64(g[6]) + F[1] * i64(g[5]) + f[2] * i64(g[4]) + F[3] * i64(g[3]) + f[4] * i64(g[2]) + F[5] * i64(g[1]) + f[6] * i64(g[0]) + F[7] * i64(G[9]) + f[8] * i64(G[8]) + F[9] * i64(G[7]);
315 t[7] = f[0] * i64(g[7]) + f[1] * i64(g[6]) + f[2] * i64(g[5]) + f[3] * i64(g[4]) + f[4] * i64(g[3]) + f[5] * i64(g[2]) + f[6] * i64(g[1]) + f[7] * i64(g[0]) + f[8] * i64(G[9]) + f[9] * i64(G[8]);
316 t[8] = f[0] * i64(g[8]) + F[1] * i64(g[7]) + f[2] * i64(g[6]) + F[3] * i64(g[5]) + f[4] * i64(g[4]) + F[5] * i64(g[3]) + f[6] * i64(g[2]) + F[7] * i64(g[1]) + f[8] * i64(g[0]) + F[9] * i64(G[9]);
317 t[9] = f[0] * i64(g[9]) + f[1] * i64(g[8]) + f[2] * i64(g[7]) + f[3] * i64(g[6]) + f[4] * i64(g[5]) + f[5] * i64(g[4]) + f[6] * i64(g[3]) + f[7] * i64(g[2]) + f[8] * i64(g[1]) + f[9] * i64(g[0]);
308 t[0] = f[0] * @as(i64, g[0]) + F[1] * @as(i64, G[9]) + f[2] * @as(i64, G[8]) + F[3] * @as(i64, G[7]) + f[4] * @as(i64, G[6]) + F[5] * @as(i64, G[5]) + f[6] * @as(i64, G[4]) + F[7] * @as(i64, G[3]) + f[8] * @as(i64, G[2]) + F[9] * @as(i64, G[1]);
309 t[1] = f[0] * @as(i64, g[1]) + f[1] * @as(i64, g[0]) + f[2] * @as(i64, G[9]) + f[3] * @as(i64, G[8]) + f[4] * @as(i64, G[7]) + f[5] * @as(i64, G[6]) + f[6] * @as(i64, G[5]) + f[7] * @as(i64, G[4]) + f[8] * @as(i64, G[3]) + f[9] * @as(i64, G[2]);
310 t[2] = f[0] * @as(i64, g[2]) + F[1] * @as(i64, g[1]) + f[2] * @as(i64, g[0]) + F[3] * @as(i64, G[9]) + f[4] * @as(i64, G[8]) + F[5] * @as(i64, G[7]) + f[6] * @as(i64, G[6]) + F[7] * @as(i64, G[5]) + f[8] * @as(i64, G[4]) + F[9] * @as(i64, G[3]);
311 t[3] = f[0] * @as(i64, g[3]) + f[1] * @as(i64, g[2]) + f[2] * @as(i64, g[1]) + f[3] * @as(i64, g[0]) + f[4] * @as(i64, G[9]) + f[5] * @as(i64, G[8]) + f[6] * @as(i64, G[7]) + f[7] * @as(i64, G[6]) + f[8] * @as(i64, G[5]) + f[9] * @as(i64, G[4]);
312 t[4] = f[0] * @as(i64, g[4]) + F[1] * @as(i64, g[3]) + f[2] * @as(i64, g[2]) + F[3] * @as(i64, g[1]) + f[4] * @as(i64, g[0]) + F[5] * @as(i64, G[9]) + f[6] * @as(i64, G[8]) + F[7] * @as(i64, G[7]) + f[8] * @as(i64, G[6]) + F[9] * @as(i64, G[5]);
313 t[5] = f[0] * @as(i64, g[5]) + f[1] * @as(i64, g[4]) + f[2] * @as(i64, g[3]) + f[3] * @as(i64, g[2]) + f[4] * @as(i64, g[1]) + f[5] * @as(i64, g[0]) + f[6] * @as(i64, G[9]) + f[7] * @as(i64, G[8]) + f[8] * @as(i64, G[7]) + f[9] * @as(i64, G[6]);
314 t[6] = f[0] * @as(i64, g[6]) + F[1] * @as(i64, g[5]) + f[2] * @as(i64, g[4]) + F[3] * @as(i64, g[3]) + f[4] * @as(i64, g[2]) + F[5] * @as(i64, g[1]) + f[6] * @as(i64, g[0]) + F[7] * @as(i64, G[9]) + f[8] * @as(i64, G[8]) + F[9] * @as(i64, G[7]);
315 t[7] = f[0] * @as(i64, g[7]) + f[1] * @as(i64, g[6]) + f[2] * @as(i64, g[5]) + f[3] * @as(i64, g[4]) + f[4] * @as(i64, g[3]) + f[5] * @as(i64, g[2]) + f[6] * @as(i64, g[1]) + f[7] * @as(i64, g[0]) + f[8] * @as(i64, G[9]) + f[9] * @as(i64, G[8]);
316 t[8] = f[0] * @as(i64, g[8]) + F[1] * @as(i64, g[7]) + f[2] * @as(i64, g[6]) + F[3] * @as(i64, g[5]) + f[4] * @as(i64, g[4]) + F[5] * @as(i64, g[3]) + f[6] * @as(i64, g[2]) + F[7] * @as(i64, g[1]) + f[8] * @as(i64, g[0]) + F[9] * @as(i64, G[9]);
317 t[9] = f[0] * @as(i64, g[9]) + f[1] * @as(i64, g[8]) + f[2] * @as(i64, g[7]) + f[3] * @as(i64, g[6]) + f[4] * @as(i64, g[5]) + f[5] * @as(i64, g[4]) + f[6] * @as(i64, g[3]) + f[7] * @as(i64, g[2]) + f[8] * @as(i64, g[1]) + f[9] * @as(i64, g[0]);
318318
319319 carry2(h, t[0..]);
320320 }
......@@ -348,16 +348,16 @@ const Fe = struct {
348348
349349 var t: [10]i64 = undefined;
350350
351 t[0] = f0 * i64(f0) + f1_2 * i64(f9_38) + f2_2 * i64(f8_19) + f3_2 * i64(f7_38) + f4_2 * i64(f6_19) + f5 * i64(f5_38);
352 t[1] = f0_2 * i64(f1) + f2 * i64(f9_38) + f3_2 * i64(f8_19) + f4 * i64(f7_38) + f5_2 * i64(f6_19);
353 t[2] = f0_2 * i64(f2) + f1_2 * i64(f1) + f3_2 * i64(f9_38) + f4_2 * i64(f8_19) + f5_2 * i64(f7_38) + f6 * i64(f6_19);
354 t[3] = f0_2 * i64(f3) + f1_2 * i64(f2) + f4 * i64(f9_38) + f5_2 * i64(f8_19) + f6 * i64(f7_38);
355 t[4] = f0_2 * i64(f4) + f1_2 * i64(f3_2) + f2 * i64(f2) + f5_2 * i64(f9_38) + f6_2 * i64(f8_19) + f7 * i64(f7_38);
356 t[5] = f0_2 * i64(f5) + f1_2 * i64(f4) + f2_2 * i64(f3) + f6 * i64(f9_38) + f7_2 * i64(f8_19);
357 t[6] = f0_2 * i64(f6) + f1_2 * i64(f5_2) + f2_2 * i64(f4) + f3_2 * i64(f3) + f7_2 * i64(f9_38) + f8 * i64(f8_19);
358 t[7] = f0_2 * i64(f7) + f1_2 * i64(f6) + f2_2 * i64(f5) + f3_2 * i64(f4) + f8 * i64(f9_38);
359 t[8] = f0_2 * i64(f8) + f1_2 * i64(f7_2) + f2_2 * i64(f6) + f3_2 * i64(f5_2) + f4 * i64(f4) + f9 * i64(f9_38);
360 t[9] = f0_2 * i64(f9) + f1_2 * i64(f8) + f2_2 * i64(f7) + f3_2 * i64(f6) + f4 * i64(f5_2);
351 t[0] = f0 * @as(i64, f0) + f1_2 * @as(i64, f9_38) + f2_2 * @as(i64, f8_19) + f3_2 * @as(i64, f7_38) + f4_2 * @as(i64, f6_19) + f5 * @as(i64, f5_38);
352 t[1] = f0_2 * @as(i64, f1) + f2 * @as(i64, f9_38) + f3_2 * @as(i64, f8_19) + f4 * @as(i64, f7_38) + f5_2 * @as(i64, f6_19);
353 t[2] = f0_2 * @as(i64, f2) + f1_2 * @as(i64, f1) + f3_2 * @as(i64, f9_38) + f4_2 * @as(i64, f8_19) + f5_2 * @as(i64, f7_38) + f6 * @as(i64, f6_19);
354 t[3] = f0_2 * @as(i64, f3) + f1_2 * @as(i64, f2) + f4 * @as(i64, f9_38) + f5_2 * @as(i64, f8_19) + f6 * @as(i64, f7_38);
355 t[4] = f0_2 * @as(i64, f4) + f1_2 * @as(i64, f3_2) + f2 * @as(i64, f2) + f5_2 * @as(i64, f9_38) + f6_2 * @as(i64, f8_19) + f7 * @as(i64, f7_38);
356 t[5] = f0_2 * @as(i64, f5) + f1_2 * @as(i64, f4) + f2_2 * @as(i64, f3) + f6 * @as(i64, f9_38) + f7_2 * @as(i64, f8_19);
357 t[6] = f0_2 * @as(i64, f6) + f1_2 * @as(i64, f5_2) + f2_2 * @as(i64, f4) + f3_2 * @as(i64, f3) + f7_2 * @as(i64, f9_38) + f8 * @as(i64, f8_19);
358 t[7] = f0_2 * @as(i64, f7) + f1_2 * @as(i64, f6) + f2_2 * @as(i64, f5) + f3_2 * @as(i64, f4) + f8 * @as(i64, f9_38);
359 t[8] = f0_2 * @as(i64, f8) + f1_2 * @as(i64, f7_2) + f2_2 * @as(i64, f6) + f3_2 * @as(i64, f5_2) + f4 * @as(i64, f4) + f9 * @as(i64, f9_38);
360 t[9] = f0_2 * @as(i64, f9) + f1_2 * @as(i64, f8) + f2_2 * @as(i64, f7) + f3_2 * @as(i64, f6) + f4 * @as(i64, f5_2);
361361
362362 carry2(h, t[0..]);
363363 }
lib/std/debug/leb128.zig+1-1
......@@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
101101 return error.Overflow;
102102
103103 var operand: UT = undefined;
104 if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
104 if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
105105 if (byte != 0x7f)
106106 return error.Overflow;
107107 }
lib/std/fmt.zig+11-11
......@@ -382,10 +382,10 @@ pub fn formatType(
382382 const info = @typeInfo(T).Union;
383383 if (info.tag_type) |UnionTagType| {
384384 try output(context, "{ .");
385 try output(context, @tagName(UnionTagType(value)));
385 try output(context, @tagName(@as(UnionTagType, value)));
386386 try output(context, " = ");
387387 inline for (info.fields) |u_field| {
388 if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) {
388 if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) {
389389 try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1);
390390 }
391391 }
......@@ -503,7 +503,7 @@ pub fn formatIntValue(
503503
504504 const int_value = if (@typeOf(value) == comptime_int) blk: {
505505 const Int = math.IntFittingRange(value, value);
506 break :blk Int(value);
506 break :blk @as(Int, value);
507507 } else
508508 value;
509509
......@@ -578,7 +578,7 @@ pub fn formatAsciiChar(
578578 comptime Errors: type,
579579 output: fn (@typeOf(context), []const u8) Errors!void,
580580) Errors!void {
581 return output(context, (*const [1]u8)(&c)[0..]);
581 return output(context, @as(*const [1]u8, &c)[0..]);
582582}
583583
584584pub fn formatBuf(
......@@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
998998
999999pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
10001000 if (!T.is_signed) return parseUnsigned(T, buf, radix);
1001 if (buf.len == 0) return T(0);
1001 if (buf.len == 0) return @as(T, 0);
10021002 if (buf[0] == '-') {
10031003 return math.negate(try parseUnsigned(T, buf[1..], radix));
10041004 } else if (buf[0] == '+') {
......@@ -1325,8 +1325,8 @@ test "float.scientific" {
13251325 // TODO https://github.com/ziglang/zig/issues/3289
13261326 return error.SkipZigTest;
13271327 }
1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));
1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));
1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));
1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));
13301330 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
13311331 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
13321332}
......@@ -1365,12 +1365,12 @@ test "float.decimal" {
13651365 return error.SkipZigTest;
13661366 }
13671367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
1368 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));
1369 try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));
1368 try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));
1369 try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567));
13701370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
13711371 // -11.12339... is rounded back up to -11.1234
1372 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));
1373 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));
1372 try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));
1373 try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));
13741374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
13751375 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
13761376 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
lib/std/fmt/parse_float.zig+3-3
......@@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
375375 return switch (try parseRepr(s, &r)) {
376376 ParseResult.Ok => convertRepr(T, r),
377377 ParseResult.PlusZero => 0.0,
378 ParseResult.MinusZero => -T(0.0),
378 ParseResult.MinusZero => -@as(T, 0.0),
379379 ParseResult.PlusInf => std.math.inf(T),
380380 ParseResult.MinusInf => -std.math.inf(T),
381381 };
......@@ -426,8 +426,8 @@ test "fmt.parseFloat" {
426426 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
427427
428428 expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
429 expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon));
430 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon));
429 expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
430 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
431431 }
432432 }
433433}
lib/std/heap.zig+2-2
......@@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
893893 if (mem.page_size << 2 > maxInt(usize)) return;
894894
895895 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
896 const large_align = u29(mem.page_size << 2);
896 const large_align = @as(u29, mem.page_size << 2);
897897
898898 var align_mask: usize = undefined;
899 _ = @shlWithOverflow(usize, ~@as(usize, 0), USizeShift(@ctz(u29, large_align)), &align_mask);
899 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
900900
901901 var slice = try allocator.alignedAlloc(u8, large_align, 500);
902902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
lib/std/io.zig+13-13
......@@ -355,19 +355,19 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
355355
356356 out_bits.* = @as(usize, 0);
357357 if (U == u0 or bits == 0) return 0;
358 var out_buffer = Buf(0);
358 var out_buffer = @as(Buf, 0);
359359
360360 if (self.bit_count > 0) {
361361 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
362362 const shift = u7_bit_count - n;
363363 switch (endian) {
364364 builtin.Endian.Big => {
365 out_buffer = Buf(self.bit_buffer >> shift);
365 out_buffer = @as(Buf, self.bit_buffer >> shift);
366366 self.bit_buffer <<= n;
367367 },
368368 builtin.Endian.Little => {
369369 const value = (self.bit_buffer << shift) >> shift;
370 out_buffer = Buf(value);
370 out_buffer = @as(Buf, value);
371371 self.bit_buffer >>= n;
372372 },
373373 }
......@@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
393393 if (n >= u8_bit_count) {
394394 out_buffer <<= @intCast(u3, u8_bit_count - 1);
395395 out_buffer <<= 1;
396 out_buffer |= Buf(next_byte);
396 out_buffer |= @as(Buf, next_byte);
397397 out_bits.* += u8_bit_count;
398398 continue;
399399 }
400400
401401 const shift = @intCast(u3, u8_bit_count - n);
402402 out_buffer <<= @intCast(BufShift, n);
403 out_buffer |= Buf(next_byte >> shift);
403 out_buffer |= @as(Buf, next_byte >> shift);
404404 out_bits.* += n;
405405 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
406406 self.bit_count = shift;
407407 },
408408 builtin.Endian.Little => {
409409 if (n >= u8_bit_count) {
410 out_buffer |= Buf(next_byte) << @intCast(BufShift, out_bits.*);
410 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
411411 out_bits.* += u8_bit_count;
412412 continue;
413413 }
414414
415415 const shift = @intCast(u3, u8_bit_count - n);
416416 const value = (next_byte << shift) >> shift;
417 out_buffer |= Buf(value) << @intCast(BufShift, out_bits.*);
417 out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*);
418418 out_bits.* += n;
419419 self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));
420420 self.bit_count = shift;
......@@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
949949 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
950950 }
951951
952 var result = U(0);
952 var result = @as(U, 0);
953953 for (buffer) |byte, i| {
954954 switch (endian) {
955955 builtin.Endian.Big => {
956956 result = (result << u8_bit_count) | byte;
957957 },
958958 builtin.Endian.Little => {
959 result |= U(byte) << @intCast(Log2U, u8_bit_count * i);
959 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
960960 },
961961 }
962962 }
......@@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
10501050 return;
10511051 }
10521052
1053 ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe
1053 ptr.* = @as(OC, undefined); //make it non-null so the following .? is guaranteed safe
10541054 const val_ptr = &ptr.*.?;
10551055 try self.deserializeInto(val_ptr);
10561056 },
......@@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11541154
11551155 switch (@typeId(T)) {
11561156 builtin.TypeId.Void => return,
1157 builtin.TypeId.Bool => try self.serializeInt(u1(@boolToInt(value))),
1157 builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
11581158 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
11591159 builtin.TypeId.Struct => {
11601160 const info = @typeInfo(T);
......@@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11971197 },
11981198 builtin.TypeId.Optional => {
11991199 if (value == null) {
1200 try self.serializeInt(u1(@boolToInt(false)));
1200 try self.serializeInt(@as(u1, @boolToInt(false)));
12011201 return;
12021202 }
1203 try self.serializeInt(u1(@boolToInt(true)));
1203 try self.serializeInt(@as(u1, @boolToInt(true)));
12041204
12051205 const OC = comptime meta.Child(T);
12061206 const val_ptr = &value.?;
lib/std/io/test.zig+12-12
......@@ -226,18 +226,18 @@ test "BitOutStream" {
226226 const OutError = io.SliceOutStream.Error;
227227 var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream);
228228
229 try bit_stream_be.writeBits(u2(1), 1);
230 try bit_stream_be.writeBits(u5(2), 2);
229 try bit_stream_be.writeBits(@as(u2, 1), 1);
230 try bit_stream_be.writeBits(@as(u5, 2), 2);
231231 try bit_stream_be.writeBits(@as(u128, 3), 3);
232232 try bit_stream_be.writeBits(@as(u8, 4), 4);
233 try bit_stream_be.writeBits(u9(5), 5);
234 try bit_stream_be.writeBits(u1(1), 1);
233 try bit_stream_be.writeBits(@as(u9, 5), 5);
234 try bit_stream_be.writeBits(@as(u1, 1), 1);
235235
236236 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
237237
238238 mem_out_be.pos = 0;
239239
240 try bit_stream_be.writeBits(u15(0b110011010000101), 15);
240 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
241241 try bit_stream_be.flushBits();
242242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
243243
......@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
345345 inline while (i <= max_test_bitsize) : (i += 1) {
346346 const U = @IntType(false, i);
347347 const S = @IntType(true, i);
348 try serializer.serializeInt(U(i));
349 if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0));
348 try serializer.serializeInt(@as(U, i));
349 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
350350 }
351351 try serializer.flush();
352352
......@@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
356356 const S = @IntType(true, i);
357357 const x = try deserializer.deserializeInt(U);
358358 const y = try deserializer.deserializeInt(S);
359 expect(x == U(i));
360 if (i != 0) expect(y == S(-1)) else expect(y == 0);
359 expect(x == @as(U, i));
360 if (i != 0) expect(y == @as(S, -1)) else expect(y == 0);
361361 }
362362
363363 const u8_bit_count = comptime meta.bitCount(u8);
......@@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v
577577 var in_stream = &in.stream;
578578 var deserializer = io.Deserializer(endian, packing, InError).init(in_stream);
579579
580 try serializer.serialize(u14(3));
580 try serializer.serialize(@as(u14, 3));
581581 expectError(error.InvalidEnumTag, deserializer.deserialize(A));
582582 out.pos = 0;
583 try serializer.serialize(u14(3));
584 try serializer.serialize(u14(88));
583 try serializer.serialize(@as(u14, 3));
584 try serializer.serialize(@as(u14, 88));
585585 expectError(error.InvalidEnumTag, deserializer.deserialize(C));
586586}
587587
lib/std/lazy_init.zig+1-1
......@@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type {
3939 },
4040 2 => {
4141 if (@sizeOf(T) == 0) {
42 return T(undefined);
42 return @as(T, undefined);
4343 } else {
4444 return &self.data;
4545 }
lib/std/math.zig+12-12
......@@ -543,8 +543,8 @@ test "math.absFloat" {
543543 comptime testAbsFloat();
544544}
545545fn testAbsFloat() void {
546 testing.expect(absFloat(f32(-10.05)) == 10.05);
547 testing.expect(absFloat(f32(10.05)) == 10.05);
546 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
547 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
548548}
549549
550550pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
......@@ -731,8 +731,8 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
731731test "math.cast" {
732732 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
733733 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
734 testing.expectError(error.Overflow, cast(u8, i8(-1)));
735 testing.expectError(error.Overflow, cast(u64, i8(-1)));
734 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
735 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
736736
737737 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
738738 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
......@@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
786786 comptime assert(@typeId(T) == builtin.TypeId.Int);
787787 comptime assert(!T.is_signed);
788788 assert(value != 0);
789 comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
790 comptime const shiftType = std.math.Log2Int(promotedType);
791 return promotedType(1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
789 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
790 comptime const shiftType = std.math.Log2Int(PromotedType);
791 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
792792}
793793
794794/// Returns the next power of two (if the value is not already a power of two).
......@@ -797,8 +797,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
797797pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
798798 comptime assert(@typeId(T) == builtin.TypeId.Int);
799799 comptime assert(!T.is_signed);
800 comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
801 comptime const overflowBit = promotedType(1) << T.bit_count;
800 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
801 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
802802 var x = ceilPowerOfTwoPromote(T, value);
803803 if (overflowBit & x != 0) {
804804 return error.Overflow;
......@@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
848848pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
849849 assert(x != 0);
850850 const log2_val = log2_int(T, x);
851 if (T(1) << log2_val == x)
851 if (@as(T, 1) << log2_val == x)
852852 return log2_val;
853853 return log2_val + 1;
854854}
......@@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T {
870870 switch (@typeInfo(@typeOf(value))) {
871871 builtin.TypeId.Int => return @intToFloat(T, value),
872872 builtin.TypeId.Float => return @floatCast(T, value),
873 builtin.TypeId.ComptimeInt => return T(value),
874 builtin.TypeId.ComptimeFloat => return T(value),
873 builtin.TypeId.ComptimeInt => return @as(T, value),
874 builtin.TypeId.ComptimeFloat => return @as(T, value),
875875 else => @compileError("bad type"),
876876 }
877877}
lib/std/math/big/int.zig+10-10
......@@ -281,7 +281,7 @@ pub const Int = struct {
281281 var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);
282282
283283 if (info.bits <= Limb.bit_count) {
284 self.limbs[0] = Limb(w_value);
284 self.limbs[0] = @as(Limb, w_value);
285285 self.metadata += 1;
286286 } else {
287287 var i: usize = 0;
......@@ -453,7 +453,7 @@ pub const Int = struct {
453453 for (self.limbs[0..self.len()]) |limb| {
454454 var shift: usize = 0;
455455 while (shift < Limb.bit_count) : (shift += base_shift) {
456 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & Limb(base - 1));
456 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));
457457 const ch = try digitToChar(r, base);
458458 try digits.append(ch);
459459 }
......@@ -560,7 +560,7 @@ pub const Int = struct {
560560 /// Returns -1, 0, 1 if a < b, a == b or a > b respectively.
561561 pub fn cmp(a: Int, b: Int) i8 {
562562 if (a.isPositive() != b.isPositive()) {
563 return if (a.isPositive()) i8(1) else -1;
563 return if (a.isPositive()) @as(i8, 1) else -1;
564564 } else {
565565 const r = cmpAbs(a, b);
566566 return if (a.isPositive()) r else -r;
......@@ -785,7 +785,7 @@ pub const Int = struct {
785785 const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1));
786786
787787 // r2 = b * c
788 const bc = DoubleLimb(math.mulWide(Limb, b, c));
788 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
789789 const r2 = @truncate(Limb, bc);
790790 const c2 = @truncate(Limb, bc >> Limb.bit_count);
791791
......@@ -1084,7 +1084,7 @@ pub const Int = struct {
10841084 rem.* = 0;
10851085 for (a) |_, ri| {
10861086 const i = a.len - ri - 1;
1087 const pdiv = ((DoubleLimb(rem.*) << Limb.bit_count) | a[i]);
1087 const pdiv = ((@as(DoubleLimb, rem.*) << Limb.bit_count) | a[i]);
10881088
10891089 if (pdiv == 0) {
10901090 quo[i] = 0;
......@@ -1143,9 +1143,9 @@ pub const Int = struct {
11431143 if (x.limbs[i] == y.limbs[t]) {
11441144 q.limbs[i - t - 1] = maxInt(Limb);
11451145 } else {
1146 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);
1147 const z = @intCast(Limb, num / DoubleLimb(y.limbs[t]));
1148 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z);
1146 const num = (@as(DoubleLimb, x.limbs[i]) << Limb.bit_count) | @as(DoubleLimb, x.limbs[i - 1]);
1147 const z = @intCast(Limb, num / @as(DoubleLimb, y.limbs[t]));
1148 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else @as(Limb, z);
11491149 }
11501150
11511151 // 3.2
......@@ -1362,7 +1362,7 @@ test "big.int comptime_int set" {
13621362
13631363 comptime var i: usize = 0;
13641364 inline while (i < s_limb_count) : (i += 1) {
1365 const result = Limb(s & maxInt(Limb));
1365 const result = @as(Limb, s & maxInt(Limb));
13661366 s >>= Limb.bit_count / 2;
13671367 s >>= Limb.bit_count / 2;
13681368 testing.expect(a.limbs[i] == result);
......@@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" {
13771377}
13781378
13791379test "big.int int set unaligned small" {
1380 var a = try Int.initSet(al, u7(45));
1380 var a = try Int.initSet(al, @as(u7, 45));
13811381
13821382 testing.expect(a.limbs[0] == 45);
13831383 testing.expect(a.isPositive() == true);
lib/std/math/complex.zig+4-4
......@@ -133,8 +133,8 @@ test "complex.div" {
133133 const b = Complex(f32).new(2, 7);
134134 const c = a.div(b);
135135
136 testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
137 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
136 testing.expect(math.approxEq(f32, c.re, @as(f32, 31) / 53, epsilon) and
137 math.approxEq(f32, c.im, @as(f32, -29) / 53, epsilon));
138138}
139139
140140test "complex.conjugate" {
......@@ -148,8 +148,8 @@ test "complex.reciprocal" {
148148 const a = Complex(f32).new(5, 3);
149149 const c = a.reciprocal();
150150
151 testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
152 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
151 testing.expect(math.approxEq(f32, c.re, @as(f32, 5) / 34, epsilon) and
152 math.approxEq(f32, c.im, @as(f32, -3) / 34, epsilon));
153153}
154154
155155test "complex.magnitude" {
lib/std/math/complex/acos.zig+1-1
......@@ -8,7 +8,7 @@ const Complex = cmath.Complex;
88pub fn acos(z: var) Complex(@typeOf(z.re)) {
99 const T = @typeOf(z.re);
1010 const q = cmath.asin(z);
11 return Complex(T).new(T(math.pi) / 2 - q.re, -q.im);
11 return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);
1212}
1313
1414const epsilon = 0.0001;
lib/std/math/complex/ldexp.zig+1-1
......@@ -65,7 +65,7 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
6565fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
6666 var ex_expt: i32 = undefined;
6767 const exp_x = frexp_exp64(z.re, &ex_expt);
68 const exptf = i64(expt + ex_expt);
68 const exptf = @as(i64, expt + ex_expt);
6969
7070 const half_expt1 = @divTrunc(exptf, 2);
7171 const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20);
lib/std/math/exp.zig+1-1
......@@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 {
134134 }
135135 if (x < -708.39641853226410622) {
136136 // underflow if x != -inf
137 // math.forceEval(f32(-0x1.0p-149 / x));
137 // math.forceEval(@as(f32, -0x1.0p-149 / x));
138138 if (x < -745.13321910194110842) {
139139 return 0;
140140 }
lib/std/math/ln.zig+1-1
......@@ -34,7 +34,7 @@ pub fn ln(x: var) @typeOf(x) {
3434 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
3535 },
3636 TypeId.Int => {
37 return T(math.floor(ln_64(@as(f64, x))));
37 return @as(T, math.floor(ln_64(@as(f64, x))));
3838 },
3939 else => @compileError("ln not implemented for " ++ @typeName(T)),
4040 }
lib/std/math/log.zig+2-2
......@@ -64,8 +64,8 @@ test "math.log float" {
6464}
6565
6666test "math.log float_special" {
67 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
68 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
67 expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
68 expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
6969
7070 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
7171 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
lib/std/math/log10.zig+1-1
......@@ -177,7 +177,7 @@ pub fn log10_64(x_: f64) f64 {
177177}
178178
179179test "math.log10" {
180 testing.expect(log10(f32(0.2)) == log10_32(0.2));
180 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
181181 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
182182}
183183
lib/std/math/sqrt.zig+2-2
......@@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;
1515pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
1616 const T = @typeOf(x);
1717 switch (@typeId(T)) {
18 TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128
18 TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
1919 TypeId.Float => return @sqrt(T, x),
2020 TypeId.ComptimeInt => comptime {
2121 if (x > maxInt(u128)) {
......@@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
2424 if (x < 0) {
2525 @compileError("sqrt on negative number");
2626 }
27 return T(sqrt_int(u128, x));
27 return @as(T, sqrt_int(u128, x));
2828 },
2929 TypeId.Int => return sqrt_int(T, x),
3030 else => @compileError("sqrt not implemented for " ++ @typeName(T)),
lib/std/meta.zig+1-1
......@@ -341,7 +341,7 @@ test "std.meta.TagType" {
341341///Returns the active tag of a tagged union
342342pub fn activeTag(u: var) @TagType(@typeOf(u)) {
343343 const T = @typeOf(u);
344 return @TagType(T)(u);
344 return @as(@TagType(T), u);
345345}
346346
347347test "std.meta.activeTag" {
lib/std/net.zig+4-4
......@@ -117,7 +117,7 @@ pub const IpAddress = extern union {
117117 ip_slice[10] = 0xff;
118118 ip_slice[11] = 0xff;
119119
120 const ptr = @sliceToBytes((*const [1]u32)(&addr)[0..]);
120 const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]);
121121
122122 ip_slice[12] = ptr[0];
123123 ip_slice[13] = ptr[1];
......@@ -161,7 +161,7 @@ pub const IpAddress = extern union {
161161 .addr = undefined,
162162 },
163163 };
164 const out_ptr = @sliceToBytes((*[1]u32)(&result.in.addr)[0..]);
164 const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]);
165165
166166 var x: u8 = 0;
167167 var index: u8 = 0;
......@@ -271,7 +271,7 @@ pub const IpAddress = extern union {
271271 },
272272 os.AF_INET6 => {
273273 const port = mem.bigToNative(u16, self.in6.port);
274 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{0,0,0,0,0,0,0,0,0,0,0xff,0xff})) {
274 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
275275 try std.fmt.format(
276276 context,
277277 Errors,
......@@ -1133,7 +1133,7 @@ fn resMSendRc(
11331133 }
11341134
11351135 // Wait for a response, or until time to retry
1136 const clamped_timeout = std.math.min(u31(std.math.maxInt(u31)), t1 + retry_interval - t2);
1136 const clamped_timeout = std.math.min(@as(u31, std.math.maxInt(u31)), t1 + retry_interval - t2);
11371137 const nevents = os.poll(&pfd, clamped_timeout) catch 0;
11381138 if (nevents == 0) continue;
11391139
lib/std/os/linux/test.zig+3-3
......@@ -72,7 +72,7 @@ test "statx" {
7272 expect(stat_buf.mode == statx_buf.mode);
7373 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
7474 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
75 expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.size);
76 expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.blksize);
77 expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.blocks);
75 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
76 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
77 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
7878}
lib/std/packed_int_array.zig+9-9
......@@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
193193 ///Initialize a packed array using an unpacked array
194194 /// or, more likely, an array literal.
195195 pub fn init(ints: [int_count]Int) Self {
196 var self = Self(undefined);
196 var self = @as(Self, undefined);
197197 for (ints) |int, i| self.set(i, int);
198198 return self;
199199 }
......@@ -328,11 +328,11 @@ test "PackedIntArray" {
328328 const expected_bytes = ((bits * int_count) + 7) / 8;
329329 testing.expect(@sizeOf(PackedArray) == expected_bytes);
330330
331 var data = PackedArray(undefined);
331 var data = @as(PackedArray, undefined);
332332
333333 //write values, counting up
334334 var i = @as(usize, 0);
335 var count = I(0);
335 var count = @as(I, 0);
336336 while (i < data.len()) : (i += 1) {
337337 data.set(i, count);
338338 if (bits > 0) count +%= 1;
......@@ -376,7 +376,7 @@ test "PackedIntSlice" {
376376
377377 //write values, counting up
378378 var i = @as(usize, 0);
379 var count = I(0);
379 var count = @as(I, 0);
380380 while (i < data.len()) : (i += 1) {
381381 data.set(i, count);
382382 if (bits > 0) count +%= 1;
......@@ -402,7 +402,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
402402 const Int = @IntType(false, bits);
403403
404404 const PackedArray = PackedIntArray(Int, int_count);
405 var packed_array = PackedArray(undefined);
405 var packed_array = @as(PackedArray, undefined);
406406
407407 const limit = (1 << bits);
408408
......@@ -463,7 +463,7 @@ test "PackedIntSlice accumulating bit offsets" {
463463 // anything
464464 {
465465 const PackedArray = PackedIntArray(u3, 16);
466 var packed_array = PackedArray(undefined);
466 var packed_array = @as(PackedArray, undefined);
467467
468468 var packed_slice = packed_array.slice(0, packed_array.len());
469469 var i = @as(usize, 0);
......@@ -473,7 +473,7 @@ test "PackedIntSlice accumulating bit offsets" {
473473 }
474474 {
475475 const PackedArray = PackedIntArray(u11, 88);
476 var packed_array = PackedArray(undefined);
476 var packed_array = @as(PackedArray, undefined);
477477
478478 var packed_slice = packed_array.slice(0, packed_array.len());
479479 var i = @as(usize, 0);
......@@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" {
518518 i = 0;
519519 while (i < packed_slice_cast_3.len()) : (i += 1) {
520520 const val = switch (builtin.endian) {
521 .Big => if (i % 2 == 0) u3(0b111) else u3(0b000),
522 .Little => if (i % 2 == 0) u3(0b111) else u3(0b000),
521 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
522 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
523523 };
524524 testing.expect(packed_slice_cast_3.get(i) == val);
525525 }
lib/std/rand.zig+4-4
......@@ -93,13 +93,13 @@ pub const Random = struct {
9393 // http://www.pcg-random.org/posts/bounded-rands.html
9494 // "Lemire's (with an extra tweak from me)"
9595 var x: Small = r.int(Small);
96 var m: Large = Large(x) * Large(less_than);
96 var m: Large = @as(Large, x) * @as(Large, less_than);
9797 var l: Small = @truncate(Small, m);
9898 if (l < less_than) {
9999 // TODO: workaround for https://github.com/ziglang/zig/issues/1770
100100 // should be:
101101 // var t: Small = -%less_than;
102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), Small(less_than)));
102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than)));
103103
104104 if (t >= less_than) {
105105 t -= less_than;
......@@ -109,7 +109,7 @@ pub const Random = struct {
109109 }
110110 while (l < t) {
111111 x = r.int(Small);
112 m = Large(x) * Large(less_than);
112 m = @as(Large, x) * @as(Large, less_than);
113113 l = @truncate(Small, m);
114114 }
115115 }
......@@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
286286 // adapted from:
287287 // http://www.pcg-random.org/posts/bounded-rands.html
288288 // "Integer Multiplication (Biased)"
289 var m: T2 = T2(random_int) * T2(less_than);
289 var m: T2 = @as(T2, random_int) * @as(T2, less_than);
290290 return @intCast(T, m >> T.bit_count);
291291}
292292
lib/std/unicode.zig+8-8
......@@ -7,10 +7,10 @@ const mem = std.mem;
77/// Returns how many bytes the UTF-8 representation would require
88/// for the given codepoint.
99pub fn utf8CodepointSequenceLength(c: u32) !u3 {
10 if (c < 0x80) return u3(1);
11 if (c < 0x800) return u3(2);
12 if (c < 0x10000) return u3(3);
13 if (c < 0x110000) return u3(4);
10 if (c < 0x80) return @as(u3, 1);
11 if (c < 0x800) return @as(u3, 2);
12 if (c < 0x10000) return @as(u3, 3);
13 if (c < 0x110000) return @as(u3, 4);
1414 return error.CodepointTooLarge;
1515}
1616
......@@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 {
1818/// returns a number 1-4 indicating the total length of the codepoint in bytes.
1919/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
2020pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
21 if (first_byte < 0b10000000) return u3(1);
22 if (first_byte & 0b11100000 == 0b11000000) return u3(2);
23 if (first_byte & 0b11110000 == 0b11100000) return u3(3);
24 if (first_byte & 0b11111000 == 0b11110000) return u3(4);
21 if (first_byte < 0b10000000) return @as(u3, 1);
22 if (first_byte & 0b11100000 == 0b11000000) return @as(u3, 2);
23 if (first_byte & 0b11110000 == 0b11100000) return @as(u3, 3);
24 if (first_byte & 0b11111000 == 0b11110000) return @as(u3, 4);
2525 return error.Utf8InvalidStartByte;
2626}
2727
src-self-hosted/stage1.zig+1-1
......@@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
224224 }
225225 if (flags.present("check")) {
226226 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
227 const code = if (anything_changed) u8(1) else u8(0);
227 const code = if (anything_changed) @as(u8, 1) else @as(u8, 0);
228228 process.exit(code);
229229 }
230230
src-self-hosted/translate_c.zig+1-1
......@@ -123,7 +123,7 @@ const Context = struct {
123123 fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 {
124124 const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc);
125125 const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc);
126 const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)");
126 const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)");
127127
128128 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
129129 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
test/compile_errors.zig+5-5
......@@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13321332 cases.add(
13331333 "@bitCast with different sizes inside an expression",
13341334 \\export fn entry() void {
1335 \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf);
1335 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
13361336 \\}
13371337 ,
13381338 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
......@@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21202120 cases.add(
21212121 "@floatToInt comptime safety",
21222122 \\comptime {
2123 \\ _ = @floatToInt(i8, f32(-129.1));
2123 \\ _ = @floatToInt(i8, @as(f32, -129.1));
21242124 \\}
21252125 \\comptime {
2126 \\ _ = @floatToInt(u8, f32(-1.1));
2126 \\ _ = @floatToInt(u8, @as(f32, -1.1));
21272127 \\}
21282128 \\comptime {
2129 \\ _ = @floatToInt(u8, f32(256.1));
2129 \\ _ = @floatToInt(u8, @as(f32, 256.1));
21302130 \\}
21312131 ,
21322132 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
......@@ -3888,7 +3888,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38883888 \\const lit_int_x = 1 / 0;
38893889 \\const lit_float_x = 1.0 / 0.0;
38903890 \\const int_x = @as(u32, 1) / @as(u32, 0);
3891 \\const float_x = f32(1.0) / f32(0.0);
3891 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
38923892 \\
38933893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
38943894 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }