diff --git a/build.zig b/build.zig
index ca78bdf19797..cd25001eef07 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/doc/docgen.zig b/doc/docgen.zig
index 07a7f23968b6..b25a9035018a 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -10,8 +10,8 @@ const testing = std.testing;
const max_doc_file_size = 10 * 1024 * 1024;
-const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
-const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
+const exe_ext = @as(std.build.Target, std.build.Target.Native).exeFileExt();
+const obj_ext = @as(std.build.Target, std.build.Target.Native).oFileExt();
const tmp_dir_name = "docgen_tmp";
const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 3eb30c305862..627709ec84f9 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -712,7 +712,7 @@ test "init with undefined" {
}
{#code_end#}
- {#syntax#}undefined{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to any type.
+ {#syntax#}undefined{#endsyntax#} can be {#link|coerced|Type Coercion#} to any type.
Once this happens, it is no longer possible to detect that the value is {#syntax#}undefined{#endsyntax#}.
{#syntax#}undefined{#endsyntax#} means the value could be anything, even something that is nonsense
according to the type. Translated into English, {#syntax#}undefined{#endsyntax#} means "Not a meaningful
@@ -920,7 +920,7 @@ fn divide(a: i32, b: i32) i32 {
{#syntax#}f128{#endsyntax#}.
- Float literals {#link|implicitly cast|Implicit Casts#} to any floating point type,
+ Float literals {#link|coerce|Type Coercion#} to any floating point type,
and to any {#link|integer|Integers#} type when there is no fractional component.
{#code_begin|syntax#}
@@ -950,7 +950,7 @@ const nan = std.math.nan(f128);
{#code_begin|obj|foo#}
{#code_release_fast#}
const builtin = @import("builtin");
-const big = f64(1 << 40);
+const big = @as(f64, 1 << 40);
export fn foo_strict(x: f64) f64 {
return x + big - big;
@@ -1652,7 +1652,7 @@ test "iterate over an array" {
for (message) |byte| {
sum += byte;
}
- assert(sum == usize('h') + usize('e') + usize('l') * 2 + usize('o'));
+ assert(sum == 'h' + 'e' + 'l' * 2 + 'o');
}
// modifiable array
@@ -2003,7 +2003,7 @@ test "variable alignment" {
}
}
{#code_end#}
- In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to a
+
In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|coerced|Type Coercion#} to a
{#syntax#}*const i32{#endsyntax#}, a pointer with a larger alignment can be implicitly
cast to a pointer with a smaller alignment, but not vice versa.
@@ -2019,7 +2019,7 @@ var foo: u8 align(4) = 100;
test "global variable alignment" {
assert(@typeOf(&foo).alignment == 4);
assert(@typeOf(&foo) == *align(4) u8);
- const slice = (*[1]u8)(&foo)[0..];
+ const slice = @as(*[1]u8, &foo)[0..];
assert(@typeOf(slice) == []align(4) u8);
}
@@ -2114,7 +2114,7 @@ const fmt = @import("std").fmt;
test "using slices for strings" {
// Zig has no concept of strings. String literals are arrays of u8, and
// in general the string type is []u8 (slice of u8).
- // Here we implicitly cast [5]u8 to []const u8
+ // Here we coerce [5]u8 to []const u8
const hello: []const u8 = "hello";
const world: []const u8 = "世界";
@@ -2778,7 +2778,7 @@ test "simple union" {
This turns the union into a tagged union, which makes it eligible
to use with {#link|switch#} expressions. One can use {#link|@TagType#} to
obtain the enum type from the union type.
- Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}
+ Tagged unions coerce to their enum {#link|Type Coercion: unions and enums#}
{#code_begin|test#}
const std = @import("std");
@@ -2795,7 +2795,7 @@ const ComplexType = union(ComplexTypeTag) {
test "switch on tagged union" {
const c = ComplexType{ .Ok = 42 };
- assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
+ assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
switch (c) {
ComplexTypeTag.Ok => |value| assert(value == 42),
@@ -2807,7 +2807,7 @@ test "@TagType" {
assert(@TagType(ComplexType) == ComplexTypeTag);
}
-test "implicit cast to enum" {
+test "coerce to enum" {
const c1 = ComplexType{ .Ok = 42 };
const c2 = ComplexType.NotOk;
@@ -2833,7 +2833,7 @@ const ComplexType = union(ComplexTypeTag) {
test "modify tagged union in switch" {
var c = ComplexType{ .Ok = 42 };
- assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
+ assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
switch (c) {
ComplexTypeTag.Ok => |*value| value.* += 1,
@@ -3943,7 +3943,7 @@ test "fn reflection" {
However right now it is hard coded to be a {#syntax#}u16{#endsyntax#}. See #768.
- You can {#link|implicitly cast|Implicit Casts#} an error from a subset to a superset:
+ You can {#link|coerce|Type Coercion#} an error from a subset to a superset:
{#code_begin|test#}
const std = @import("std");
@@ -3958,7 +3958,7 @@ const AllocationError = error {
OutOfMemory,
};
-test "implicit cast subset to superset" {
+test "coerce subset to superset" {
const err = foo(AllocationError.OutOfMemory);
std.debug.assert(err == FileOpenError.OutOfMemory);
}
@@ -3968,7 +3968,7 @@ fn foo(err: AllocationError) FileOpenError {
}
{#code_end#}
- But you cannot implicitly cast an error from a superset to a subset:
+ But you cannot {#link|coerce|Type Coercion#} an error from a superset to a subset:
{#code_begin|test_err|not a member of destination error set#}
const FileOpenError = error {
@@ -3981,7 +3981,7 @@ const AllocationError = error {
OutOfMemory,
};
-test "implicit cast superset to subset" {
+test "coerce superset to subset" {
foo(FileOpenError.OutOfMemory) catch {};
}
@@ -4008,7 +4008,7 @@ const err = (error {FileNotFound}).FileNotFound;
It is a superset of all other error sets and a subset of none of them.
- You can implicitly cast any error set to the global one, and you can explicitly
+ You can {#link|coerce|Type Coercion#} any error set to the global one, and you can explicitly
cast an error of the global error set to a non-global one. This inserts a language-level
assert to make sure the error value is in fact in the destination error set.
@@ -4079,7 +4079,7 @@ test "parse u64" {
Within the function definition, you can see some return statements that return
an error, and at the bottom a return statement that returns a {#syntax#}u64{#endsyntax#}.
- Both types {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyerror!u64{#endsyntax#}.
+ Both types {#link|coerce|Type Coercion#} to {#syntax#}anyerror!u64{#endsyntax#}.
What it looks like to use this function varies depending on what you're
@@ -4218,10 +4218,10 @@ const assert = @import("std").debug.assert;
test "error union" {
var foo: anyerror!i32 = undefined;
- // Implicitly cast from child type of an error union:
+ // Coerce from child type of an error union:
foo = 1234;
- // Implicitly cast from an error set:
+ // Coerce from an error set:
foo = error.SomeError;
// Use compile-time reflection to access the payload type of an error union:
@@ -4598,10 +4598,10 @@ fn doAThing(optional_foo: ?*Foo) void {
const assert = @import("std").debug.assert;
test "optional type" {
- // Declare an optional and implicitly cast from null:
+ // Declare an optional and coerce from null:
var foo: ?i32 = null;
- // Implicitly cast from child type of an optional
+ // Coerce from child type of an optional
foo = 1234;
// Use compile-time reflection to access the child type of the optional:
@@ -4644,38 +4644,38 @@ test "optional pointers" {
{#header_open|Casting#}
A type cast converts a value of one type to another.
- Zig has {#link|Implicit Casts#} for conversions that are known to be completely safe and unambiguous,
+ Zig has {#link|Type Coercion#} for conversions that are known to be completely safe and unambiguous,
and {#link|Explicit Casts#} for conversions that one would not want to happen on accident.
There is also a third kind of type conversion called {#link|Peer Type Resolution#} for
the case when a result type must be decided given multiple operand types.
- {#header_open|Implicit Casts#}
+ {#header_open|Type Coercion#}
- An implicit cast occurs when one type is expected, but different type is provided:
+ Type coercion occurs when one type is expected, but different type is provided:
{#code_begin|test#}
-test "implicit cast - variable declaration" {
+test "type coercion - variable declaration" {
var a: u8 = 1;
var b: u16 = a;
}
-test "implicit cast - function call" {
+test "type coercion - function call" {
var a: u8 = 1;
foo(a);
}
fn foo(b: u16) void {}
-test "implicit cast - invoke a type as a function" {
+test "type coercion - @as builtin" {
var a: u8 = 1;
- var b = u16(a);
+ var b = @as(u16, a);
}
{#code_end#}
- Implicit casts are only allowed when it is completely unambiguous how to get from one type to another,
+ Type coercions are only allowed when it is completely unambiguous how to get from one type to another,
and the transformation is guaranteed to be safe. There is one exception, which is {#link|C Pointers#}.
- {#header_open|Implicit Cast: Stricter Qualification#}
+ {#header_open|Type Coercion: Stricter Qualification#}
Values which have the same representation at runtime can be cast to increase the strictness
of the qualifiers, no matter how nested the qualifiers are:
@@ -4690,7 +4690,7 @@ test "implicit cast - invoke a type as a function" {
These casts are no-ops at runtime since the value representation does not change.
{#code_begin|test#}
-test "implicit cast - const qualification" {
+test "type coercion - const qualification" {
var a: i32 = 1;
var b: *i32 = &a;
foo(b);
@@ -4699,7 +4699,7 @@ test "implicit cast - const qualification" {
fn foo(a: *const i32) void {}
{#code_end#}
- In addition, pointers implicitly cast to const optional pointers:
+ In addition, pointers coerce to const optional pointers:
{#code_begin|test#}
const std = @import("std");
@@ -4713,10 +4713,10 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
}
{#code_end#}
{#header_close#}
- {#header_open|Implicit Cast: Integer and Float Widening#}
+ {#header_open|Type Coercion: Integer and Float Widening#}
- {#link|Integers#} implicitly cast to integer types which can represent every value of the old type, and likewise
- {#link|Floats#} implicitly cast to float types which can represent every value of the old type.
+ {#link|Integers#} coerce to integer types which can represent every value of the old type, and likewise
+ {#link|Floats#} coerce to float types which can represent every value of the old type.
{#code_begin|test#}
const std = @import("std");
@@ -4748,7 +4748,7 @@ test "float widening" {
}
{#code_end#}
{#header_close#}
- {#header_open|Implicit Cast: Arrays and Pointers#}
+ {#header_open|Type Coercion: Arrays and Pointers#}
{#code_begin|test#}
const std = @import("std");
const assert = std.debug.assert;
@@ -4797,7 +4797,7 @@ test "*[N]T to []T" {
assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 }));
}
-// Single-item pointers to arrays can be implicitly casted to
+// Single-item pointers to arrays can be coerced to
// unknown length pointers.
test "*[N]T to [*]T" {
var buf: [5]u8 = "hello";
@@ -4823,15 +4823,15 @@ test "*T to *[1]T" {
{#code_end#}
{#see_also|C Pointers#}
{#header_close#}
- {#header_open|Implicit Cast: Optionals#}
+ {#header_open|Type Coercion: Optionals#}
- The payload type of {#link|Optionals#}, as well as {#link|null#}, implicitly cast to the optional type.
+ The payload type of {#link|Optionals#}, as well as {#link|null#}, coerce to the optional type.
{#code_begin|test#}
const std = @import("std");
const assert = std.debug.assert;
-test "implicit casting to optionals" {
+test "coerce to optionals" {
const x: ?i32 = 1234;
const y: ?i32 = null;
@@ -4844,7 +4844,7 @@ test "implicit casting to optionals" {
const std = @import("std");
const assert = std.debug.assert;
-test "implicit casting to optionals wrapped in error union" {
+test "coerce to optionals wrapped in error union" {
const x: anyerror!?i32 = 1234;
const y: anyerror!?i32 = null;
@@ -4853,15 +4853,15 @@ test "implicit casting to optionals wrapped in error union" {
}
{#code_end#}
{#header_close#}
- {#header_open|Implicit Cast: Error Unions#}
+ {#header_open|Type Coercion: Error Unions#}
The payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#}
- implicitly cast to the error union type:
+ coerce to the error union type:
{#code_begin|test#}
const std = @import("std");
const assert = std.debug.assert;
-test "implicit casting to error unions" {
+test "coercion to error unions" {
const x: anyerror!i32 = 1234;
const y: anyerror!i32 = error.Failure;
@@ -4870,23 +4870,23 @@ test "implicit casting to error unions" {
}
{#code_end#}
{#header_close#}
- {#header_open|Implicit Cast: Compile-Time Known Numbers#}
+ {#header_open|Type Coercion: Compile-Time Known Numbers#}
When a number is {#link|comptime#}-known to be representable in the destination type,
- it may be implicitly casted:
+ it may be coerced:
{#code_begin|test#}
const std = @import("std");
const assert = std.debug.assert;
-test "implicit casting large integer type to smaller one when value is comptime known to fit" {
+test "coercing large integer type to smaller one when value is comptime known to fit" {
const x: u64 = 255;
const y: u8 = x;
assert(y == 255);
}
{#code_end#}
{#header_close#}
- {#header_open|Implicit Cast: unions and enums#}
- Tagged unions can be implicitly cast to enums, and enums can be implicitly casted to tagged unions
+ {#header_open|Type Coercion: unions and enums#}
+
Tagged unions can be coerced to enums, and enums can be coerced to tagged unions
when they are {#link|comptime#}-known to be a field of the union that has only one possible value, such as
{#link|void#}:
@@ -4906,7 +4906,7 @@ const U = union(E) {
Three,
};
-test "implicit casting between unions and enums" {
+test "coercion between unions and enums" {
var u = U{ .Two = 12.34 };
var e: E = u;
assert(e == E.Two);
@@ -4918,20 +4918,20 @@ test "implicit casting between unions and enums" {
{#code_end#}
{#see_also|union|enum#}
{#header_close#}
- {#header_open|Implicit Cast: Zero Bit Types#}
- {#link|Zero Bit Types#} may be implicitly casted to single-item {#link|Pointers#},
+ {#header_open|Type Coercion: Zero Bit Types#}
+
{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#},
regardless of const.
TODO document the reasoning for this
TODO document whether vice versa should work and why
{#code_begin|test#}
-test "implicit casting of zero bit types" {
+test "coercion of zero bit types" {
var x: void = {};
var y: *void = x;
//var z: void = y; // TODO
}
{#code_end#}
{#header_close#}
- {#header_open|Implicit Cast: undefined#}
+ {#header_open|Type Coercion: undefined#}
{#link|undefined#} can be cast to any type.
{#header_close#}
{#header_close#}
@@ -4976,7 +4976,7 @@ test "implicit casting of zero bit types" {
Some {#link|binary operations|Table of Operators#}
- This kind of type resolution chooses a type that all peer types can implicitly cast into. Here are
+ This kind of type resolution chooses a type that all peer types can coerce into. Here are
some examples:
{#code_begin|test#}
@@ -5007,8 +5007,8 @@ test "peer resolve array and const slice" {
comptime testPeerResolveArrayConstSlice(true);
}
fn testPeerResolveArrayConstSlice(b: bool) void {
- const value1 = if (b) "aoeu" else ([]const u8)("zz");
- const value2 = if (b) ([]const u8)("zz") else "aoeu";
+ const value1 = if (b) "aoeu" else @as([]const u8, "zz");
+ const value2 = if (b) @as([]const u8, "zz") else "aoeu";
assert(mem.eql(u8, value1, "aoeu"));
assert(mem.eql(u8, value2, "zz"));
}
@@ -5023,10 +5023,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" {
@@ -5815,7 +5815,7 @@ test "printf too many arguments" {
Zig doesn't care whether the format argument is a string literal,
- only that it is a compile-time known value that is implicitly castable to a {#syntax#}[]const u8{#endsyntax#}:
+ only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}:
{#code_begin|exe|printf#}
const warn = @import("std").debug.warn;
@@ -6185,7 +6185,7 @@ fn func() void {
{#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that
- implicitly casts to {#syntax#}anyframe->T{#endsyntax#}.
+ coerces to {#syntax#}anyframe->T{#endsyntax#}.
There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function.
@@ -6445,6 +6445,14 @@ comptime {
{#header_close#}
+ {#header_open|@as#}
+ {#syntax#}@as(comptime T: type, expression) T{#endsyntax#}
+
+ Performs {#link|Type Coercion#}. This cast is allowed when the conversion is unambiguous and safe,
+ and is the preferred way to convert between types, whenever possible.
+
+ {#header_close#}
+
{#header_open|@asyncCall#}
{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: ...) anyframe->T{#endsyntax#}
@@ -7108,7 +7116,7 @@ test "field access by string" {
{#syntax#}@frame() *@Frame(func){#endsyntax#}
This function returns a pointer to the frame for a given function. This type
- can be {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyframe->T{#endsyntax#} and
+ can be {#link|coerced|Type Coercion#} to {#syntax#}anyframe->T{#endsyntax#} and
to {#syntax#}anyframe{#endsyntax#}, where {#syntax#}T{#endsyntax#} is the return type
of the function in scope.
@@ -7827,7 +7835,7 @@ test "vector @splat" {
const scalar: u32 = 5;
const result = @splat(4, scalar);
comptime assert(@typeOf(result) == @Vector(4, u32));
- assert(std.mem.eql(u32, ([4]u32)(result), [_]u32{ 5, 5, 5, 5 }));
+ assert(std.mem.eql(u32, @as([4]u32, result), [_]u32{ 5, 5, 5, 5 }));
}
{#code_end#}
@@ -8025,7 +8033,7 @@ test "integer truncation" {
If {#syntax#}T{#endsyntax#} is {#syntax#}comptime_int{#endsyntax#},
- then this is semantically equivalent to an {#link|implicit cast|Implicit Casts#}.
+ then this is semantically equivalent to {#link|Type Coercion#}.
{#header_close#}
@@ -8529,7 +8537,7 @@ pub fn main() void {
{#header_close#}
{#header_open|Cast Truncates Data#}
At compile-time:
- {#code_begin|test_err|integer value 300 cannot be implicitly casted to type 'u8'#}
+ {#code_begin|test_err|integer value 300 cannot be coerced to type 'u8'#}
comptime {
const spartan_count: u16 = 300;
const byte = @intCast(u8, spartan_count);
@@ -8665,7 +8673,7 @@ test "wraparound addition and subtraction" {
At compile-time:
{#code_begin|test_err|operation caused overflow#}
comptime {
- const x = @shlExact(u8(0b01010101), 2);
+ const x = @shlExact(@as(u8, 0b01010101), 2);
}
{#code_end#}
At runtime:
@@ -8683,7 +8691,7 @@ pub fn main() void {
At compile-time:
{#code_begin|test_err|exact shift shifted out 1 bits#}
comptime {
- const x = @shrExact(u8(0b10101010), 2);
+ const x = @shrExact(@as(u8, 0b10101010), 2);
}
{#code_end#}
At runtime:
@@ -9535,8 +9543,8 @@ const c = @cImport({
{#syntax#}[*c]T{#endsyntax#} - C pointer.
- Supports all the syntax of the other two pointer types.
- - Implicitly casts to other pointer types, as well as {#link|Optional Pointers#}.
- When a C pointer is implicitly casted to a non-optional pointer, safety-checked
+
- Coerces to other pointer types, as well as {#link|Optional Pointers#}.
+ When a C pointer is coerced to a non-optional pointer, safety-checked
{#link|Undefined Behavior#} occurs if the address is 0.
- Allows address 0. On non-freestanding targets, dereferencing address 0 is safety-checked
@@ -9544,7 +9552,7 @@ const c = @cImport({
null, just like {#syntax#}?usize{#endsyntax#}. Note that creating an optional C pointer
is unnecessary as one can use normal {#link|Optional Pointers#}.
- - Supports {#link|implicit casting|Implicit Casts#} to and from integers.
+ - Supports {#link|Type Coercion#} to and from integers.
- Supports comparison with integers.
- Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#}
please!
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index a57839ec3b83..59fd2a10e517 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 2bc11ba3f25b..71f52bfd1747 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 dbc011bed3a8..173355eb3b7f 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 dd288adbf160..664191eb7773 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 c36c5e9dfa0f..6c4d713076d7 100644
--- a/lib/std/bloom_filter.zig
+++ b/lib/std/bloom_filter.zig
@@ -28,7 +28,7 @@ pub fn BloomFilter(
assert(n_items > 0);
assert(math.isPowerOfTwo(n_items));
assert(K > 0);
- const cellEmpty = if (Cell == bool) false else Cell(0);
+ const cellEmpty = if (Cell == bool) false else @as(Cell, 0);
const cellMax = if (Cell == bool) true else math.maxInt(Cell);
const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8;
assert(n_bytes > 0);
@@ -137,7 +137,7 @@ pub fn BloomFilter(
var i: usize = 0;
while (i < n_items) : (i += 1) {
const cell = self.getCell(@intCast(Index, i));
- n += if (if (Cell == bool) cell else cell > 0) Index(1) else Index(0);
+ n += if (if (Cell == bool) cell else cell > 0) @as(Index, 1) else @as(Index, 0);
}
}
return n;
@@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void {
test "std.BloomFilter" {
inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| {
- const emptyCell = if (Cell == bool) false else Cell(0);
+ const emptyCell = if (Cell == bool) false else @as(Cell, 0);
const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc);
var bf = BF{};
var i: usize = undefined;
@@ -170,8 +170,8 @@ test "std.BloomFilter" {
while (i < BF.items) : (i += 1) {
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(BF.Index, 0), bf.popCount());
+ testing.expectEqual(@as(f64, 0), bf.estimateItems());
// fill in a few items
bf.incrementCell(42);
bf.incrementCell(255);
@@ -196,8 +196,8 @@ test "std.BloomFilter" {
while (i < BF.items) : (i += 1) {
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(BF.Index, 0), bf.popCount());
+ testing.expectEqual(@as(f64, 0), bf.estimateItems());
// Lets add a string
bf.add("foo");
@@ -218,8 +218,8 @@ test "std.BloomFilter" {
while (i < BF.items) : (i += 1) {
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(BF.Index, 0), bf.popCount());
+ testing.expectEqual(@as(f64, 0), bf.estimateItems());
comptime var teststrings = [_][]const u8{
"foo",
@@ -246,12 +246,12 @@ test "std.BloomFilter" {
inline for (teststrings) |str| {
testing.expectEqual(true, larger_bf.contains(str));
}
- testing.expectEqual(u12(bf.popCount()) * (4096 / 1024), larger_bf.popCount());
+ testing.expectEqual(@as(u12, bf.popCount()) * (4096 / 1024), larger_bf.popCount());
const smaller_bf = bf.resize(64);
inline for (teststrings) |str| {
testing.expectEqual(true, smaller_bf.contains(str));
}
- testing.expect(bf.popCount() <= u10(smaller_bf.popCount()) * (1024 / 64));
+ testing.expect(bf.popCount() <= @as(u10, smaller_bf.popCount()) * (1024 / 64));
}
}
diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig
index eaccb1dcfddd..4d40e8aee536 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 5fae9447a995..e6e284db1899 100644
--- a/lib/std/child_process.zig
+++ b/lib/std/child_process.zig
@@ -219,7 +219,7 @@ pub const ChildProcess = struct {
fn waitUnwrappedWindows(self: *ChildProcess) !void {
const result = windows.WaitForSingleObject(self.handle, windows.INFINITE);
- self.term = (SpawnError!Term)(x: {
+ self.term = @as(SpawnError!Term, x: {
var exit_code: windows.DWORD = undefined;
if (windows.kernel32.GetExitCodeProcess(self.handle, &exit_code) == 0) {
break :x Term{ .Unknown = 0 };
@@ -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 4e7a4f2e134d..ddccd0b1b326 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 6bb2764b92bf..d6b1e497245f 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 0d997e0d142c..d5d03f2bfa21 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 0a0a5056c667..0d18afd705ca 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 ddbb39a9df2a..db6150699d7e 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 bd0b33e5860b..78881ba049b5 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 c5160a1f376f..c17ef2daf775 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 b40a39d5797e..77698176bd11 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 659e7a254f21..d417ef07e251 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 7f9220c3f4ee..cd908b086854 100644
--- a/lib/std/crypto/x25519.zig
+++ b/lib/std/crypto/x25519.zig
@@ -199,9 +199,9 @@ const Fe = struct {
inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void {
const j = (i + 1) % 10;
- c[i] = (t[i] + (i64(1) << shift)) >> (shift + 1);
+ c[i] = (t[i] + (@as(i64, 1) << shift)) >> (shift + 1);
t[j] += c[i] * mult;
- t[i] -= c[i] * (i64(1) << (shift + 1));
+ t[i] -= c[i] * (@as(i64, 1) << (shift + 1));
}
fn carry1(h: *Fe, t: []i64) void {
@@ -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..]);
}
@@ -273,7 +273,7 @@ const Fe = struct {
var t: [10]i64 = undefined;
for (t[0..]) |_, i| {
- t[i] = i64(f.b[i]) * g;
+ t[i] = @as(i64, f.b[i]) * g;
}
carry1(h, t[0..]);
@@ -305,16 +305,16 @@ const Fe = struct {
// t's become h
var t: [10]i64 = undefined;
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
+ 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]);
carry2(h, t[0..]);
}
@@ -348,16 +348,16 @@ const Fe = struct {
var t: [10]i64 = undefined;
- 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);
- t[1] = f0_2 * i64(f1) + f2 * i64(f9_38) + f3_2 * i64(f8_19) + f4 * i64(f7_38) + f5_2 * i64(f6_19);
- 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);
- t[3] = f0_2 * i64(f3) + f1_2 * i64(f2) + f4 * i64(f9_38) + f5_2 * i64(f8_19) + f6 * i64(f7_38);
- 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);
- t[5] = f0_2 * i64(f5) + f1_2 * i64(f4) + f2_2 * i64(f3) + f6 * i64(f9_38) + f7_2 * i64(f8_19);
- 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);
- t[7] = f0_2 * i64(f7) + f1_2 * i64(f6) + f2_2 * i64(f5) + f3_2 * i64(f4) + f8 * i64(f9_38);
- 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);
- t[9] = f0_2 * i64(f9) + f1_2 * i64(f8) + f2_2 * i64(f7) + f3_2 * i64(f6) + f4 * i64(f5_2);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
carry2(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 cd0c3863ffe2..02305086cc5e 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 cb59c5b0d214..dba57e1f9791 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;
}
@@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
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 341378801970..0e8792ca9099 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 b3aea3e5c62e..3bb4054bfe41 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 d86bcbaed57b..1035a51b81be 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/event/loop.zig b/lib/std/event/loop.zig
index d5d73dabbc38..543863c71e3f 100644
--- a/lib/std/event/loop.zig
+++ b/lib/std/event/loop.zig
@@ -266,7 +266,7 @@ pub const Loop = struct {
},
};
- const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
+ const empty_kevs = &[0]os.Kevent{};
for (self.eventfd_resume_nodes) |*eventfd_node, i| {
eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
@@ -289,7 +289,7 @@ pub const Loop = struct {
.next = undefined,
};
self.available_eventfd_resume_nodes.push(eventfd_node);
- const kevent_array = (*const [1]os.Kevent)(&eventfd_node.data.kevent);
+ const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.data.kevent);
_ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE;
eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER;
@@ -305,7 +305,7 @@ pub const Loop = struct {
.data = 0,
.udata = @ptrToInt(&self.final_resume_node),
};
- const final_kev_arr = (*const [1]os.Kevent)(&self.os_data.final_kevent);
+ const final_kev_arr = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
_ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
self.os_data.final_kevent.flags = os.EV_ENABLE;
self.os_data.final_kevent.fflags = os.NOTE_TRIGGER;
@@ -572,8 +572,8 @@ pub const Loop = struct {
eventfd_node.base.handle = next_tick_node.data;
switch (builtin.os) {
.macosx, .freebsd, .netbsd, .dragonfly => {
- const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);
- const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
+ const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.kevent);
+ const empty_kevs = &[0]os.Kevent{};
_ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
self.next_tick_queue.unget(next_tick_node);
self.available_eventfd_resume_nodes.push(resume_stack_node);
@@ -695,8 +695,8 @@ pub const Loop = struct {
},
.macosx, .freebsd, .netbsd, .dragonfly => {
self.posixFsRequest(&self.os_data.fs_end_request);
- const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);
- const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
+ const final_kevent = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
+ const empty_kevs = &[0]os.Kevent{};
// cannot fail because we already added it and this just enables it
_ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
return;
@@ -753,7 +753,7 @@ pub const Loop = struct {
},
.macosx, .freebsd, .netbsd, .dragonfly => {
var eventlist: [1]os.Kevent = undefined;
- const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
+ const empty_kevs = &[0]os.Kevent{};
const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
for (eventlist[0..count]) |ev| {
const resume_node = @intToPtr(*ResumeNode, ev.udata);
@@ -815,8 +815,8 @@ pub const Loop = struct {
self.os_data.fs_queue.put(request_node);
switch (builtin.os) {
.macosx, .freebsd, .netbsd, .dragonfly => {
- const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);
- const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
+ const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wake);
+ const empty_kevs = &[0]os.Kevent{};
_ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
},
.linux => {
@@ -890,7 +890,7 @@ pub const Loop = struct {
}
},
.macosx, .freebsd, .netbsd, .dragonfly => {
- const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);
+ const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wait);
var out_kevs: [1]os.Kevent = undefined;
_ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
},
diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig
index b47dda34def5..73f9b2dee7fd 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;
}
@@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
if (!T.is_signed) return parseUnsigned(T, buf, radix);
- if (buf.len == 0) return T(0);
+ if (buf.len == 0) return @as(T, 0);
if (buf[0] == '-') {
return math.negate(try parseUnsigned(T, buf[1..], radix));
} else if (buf[0] == '+') {
@@ -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" {
@@ -1325,10 +1325,10 @@ test "float.scientific" {
// TODO https://github.com/ziglang/zig/issues/3289
return error.SkipZigTest;
}
- 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("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));
+ try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));
+ 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("f32: 1.1", "f32: {d:.1}", f32(1.1234));
- try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));
+ try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
+ try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));
+ try testFmt("f32: 1234.57", "f32: {d:.2}", @as(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("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));
+ try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));
+ 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 a835195fc702..e697b7d42fa2 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 9a35e27c2190..78ce0b7d0abb 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;
@@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
return switch (try parseRepr(s, &r)) {
ParseResult.Ok => convertRepr(T, r),
ParseResult.PlusZero => 0.0,
- ParseResult.MinusZero => -T(0.0),
+ ParseResult.MinusZero => -@as(T, 0.0),
ParseResult.PlusInf => std.math.inf(T),
ParseResult.MinusInf => -std.math.inf(T),
};
@@ -426,8 +426,8 @@ test "fmt.parseFloat" {
expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
- expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon));
- expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon));
+ expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
+ expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
}
}
}
diff --git a/lib/std/fs.zig b/lib/std/fs.zig
index 2a96fd3fbcd6..3f20c66102a4 100644
--- a/lib/std/fs.zig
+++ b/lib/std/fs.zig
@@ -584,7 +584,7 @@ pub const Dir = struct {
.FileBothDirectoryInformation,
w.FALSE,
null,
- if (self.first) w.BOOLEAN(w.TRUE) else w.BOOLEAN(w.FALSE),
+ if (self.first) @as(w.BOOLEAN, w.TRUE) else @as(w.BOOLEAN, w.FALSE),
);
self.first = false;
if (io.Information == 0) return null;
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig
index 431b89bebf16..117e49369a74 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 3a4abcbcd91b..1df434116c4d 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 43e5b7a385cc..d31ee17105ed 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 cdcaf55610b2..6176ded81dc0 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 a0c8f91338ce..f70190d31197 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 3d67ba685b62..c3a9184fa429 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 7c872de5ca40..aae3b60831ac 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 ccdab8d33297..24ab39573413 100644
--- a/lib/std/heap.zig
+++ b/lib/std/heap.zig
@@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
if (mem.page_size << 2 > maxInt(usize)) return;
const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
- const large_align = u29(mem.page_size << 2);
+ const large_align = @as(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), @as(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 7ee035ce80ce..a860186e4741 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 95280b888f0f..f2cbeff922ed 100644
--- a/lib/std/io.zig
+++ b/lib/std/io.zig
@@ -353,21 +353,21 @@ 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);
+ var out_buffer = @as(Buf, 0);
if (self.bit_count > 0) {
const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
const shift = u7_bit_count - n;
switch (endian) {
builtin.Endian.Big => {
- out_buffer = Buf(self.bit_buffer >> shift);
+ out_buffer = @as(Buf, self.bit_buffer >> shift);
self.bit_buffer <<= n;
},
builtin.Endian.Little => {
const value = (self.bit_buffer << shift) >> shift;
- out_buffer = Buf(value);
+ out_buffer = @as(Buf, value);
self.bit_buffer >>= n;
},
}
@@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
if (n >= u8_bit_count) {
out_buffer <<= @intCast(u3, u8_bit_count - 1);
out_buffer <<= 1;
- out_buffer |= Buf(next_byte);
+ out_buffer |= @as(Buf, next_byte);
out_bits.* += u8_bit_count;
continue;
}
const shift = @intCast(u3, u8_bit_count - n);
out_buffer <<= @intCast(BufShift, n);
- out_buffer |= Buf(next_byte >> shift);
+ out_buffer |= @as(Buf, next_byte >> shift);
out_bits.* += n;
self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
self.bit_count = shift;
},
builtin.Endian.Little => {
if (n >= u8_bit_count) {
- out_buffer |= Buf(next_byte) << @intCast(BufShift, out_bits.*);
+ out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
out_bits.* += u8_bit_count;
continue;
}
const shift = @intCast(u3, u8_bit_count - n);
const value = (next_byte << shift) >> shift;
- out_buffer |= Buf(value) << @intCast(BufShift, out_bits.*);
+ out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*);
out_bits.* += n;
self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));
self.bit_count = shift;
@@ -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| {
@@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
}
- var result = U(0);
+ var result = @as(U, 0);
for (buffer) |byte, i| {
switch (endian) {
builtin.Endian.Big => {
result = (result << u8_bit_count) | byte;
},
builtin.Endian.Little => {
- result |= U(byte) << @intCast(Log2U, u8_bit_count * i);
+ result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
},
}
}
@@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
return;
}
- ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe
+ ptr.* = @as(OC, undefined); //make it non-null so the following .? is guaranteed safe
const val_ptr = &ptr.*.?;
try self.deserializeInto(val_ptr);
},
@@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
switch (@typeId(T)) {
builtin.TypeId.Void => return,
- builtin.TypeId.Bool => try self.serializeInt(u1(@boolToInt(value))),
+ builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
builtin.TypeId.Struct => {
const info = @typeInfo(T);
@@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
},
builtin.TypeId.Optional => {
if (value == null) {
- try self.serializeInt(u1(@boolToInt(false)));
+ try self.serializeInt(@as(u1, @boolToInt(false)));
return;
}
- try self.serializeInt(u1(@boolToInt(true)));
+ try self.serializeInt(@as(u1, @boolToInt(true)));
const OC = comptime meta.Child(T);
const val_ptr = &value.?;
diff --git a/lib/std/io/out_stream.zig b/lib/std/io/out_stream.zig
index 42c40337a80f..c0cd6e48a159 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 e93b74169bc5..28b8371d9d49 100644
--- a/lib/std/io/test.zig
+++ b/lib/std/io/test.zig
@@ -226,49 +226,49 @@ test "BitOutStream" {
const OutError = io.SliceOutStream.Error;
var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream);
- 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(u9(5), 5);
- try bit_stream_be.writeBits(u1(1), 1);
+ try bit_stream_be.writeBits(@as(u2, 1), 1);
+ try bit_stream_be.writeBits(@as(u5, 2), 2);
+ try bit_stream_be.writeBits(@as(u128, 3), 3);
+ try bit_stream_be.writeBits(@as(u8, 4), 4);
+ try bit_stream_be.writeBits(@as(u9, 5), 5);
+ try bit_stream_be.writeBits(@as(u1, 1), 1);
expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
mem_out_be.pos = 0;
- try bit_stream_be.writeBits(u15(0b110011010000101), 15);
+ try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
try bit_stream_be.flushBits();
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();
}
{
@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
inline while (i <= max_test_bitsize) : (i += 1) {
const U = @IntType(false, i);
const S = @IntType(true, i);
- try serializer.serializeInt(U(i));
- if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0));
+ try serializer.serializeInt(@as(U, i));
+ if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
}
try serializer.flush();
@@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
const S = @IntType(true, i);
const x = try deserializer.deserializeInt(U);
const y = try deserializer.deserializeInt(S);
- expect(x == U(i));
- if (i != 0) expect(y == S(-1)) else expect(y == 0);
+ expect(x == @as(U, i));
+ if (i != 0) expect(y == @as(S, -1)) else expect(y == 0);
}
const u8_bit_count = comptime meta.bitCount(u8);
@@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v
var in_stream = &in.stream;
var deserializer = io.Deserializer(endian, packing, InError).init(in_stream);
- try serializer.serialize(u14(3));
+ try serializer.serialize(@as(u14, 3));
expectError(error.InvalidEnumTag, deserializer.deserialize(A));
out.pos = 0;
- try serializer.serialize(u14(3));
- try serializer.serialize(u14(88));
+ try serializer.serialize(@as(u14, 3));
+ try serializer.serialize(@as(u14, 88));
expectError(error.InvalidEnumTag, deserializer.deserialize(C));
}
@@ -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 6cd032806e1e..ecf0bf822bdc 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/lazy_init.zig b/lib/std/lazy_init.zig
index 7beabb9cdeeb..add40a372d8d 100644
--- a/lib/std/lazy_init.zig
+++ b/lib/std/lazy_init.zig
@@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type {
},
2 => {
if (@sizeOf(T) == 0) {
- return T(undefined);
+ return @as(T, undefined);
} else {
return &self.data;
}
diff --git a/lib/std/math.zig b/lib/std/math.zig
index 9b56d0b8ce62..8e08cacc420a 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;
@@ -543,8 +543,8 @@ test "math.absFloat" {
comptime testAbsFloat();
}
fn testAbsFloat() void {
- testing.expect(absFloat(f32(-10.05)) == 10.05);
- testing.expect(absFloat(f32(10.05)) == 10.05);
+ testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
+ testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
}
pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
@@ -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, i8(-1)));
- testing.expectError(error.Overflow, cast(u64, i8(-1)));
+ testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
+ testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
+ testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
+ testing.expectError(error.Overflow, cast(u64, @as(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};
@@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
comptime assert(@typeId(T) == builtin.TypeId.Int);
comptime assert(!T.is_signed);
assert(value != 0);
- comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
- comptime const shiftType = std.math.Log2Int(promotedType);
- return promotedType(1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
+ comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
+ comptime const shiftType = std.math.Log2Int(PromotedType);
+ return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
}
/// 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
pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
comptime assert(@typeId(T) == builtin.TypeId.Int);
comptime assert(!T.is_signed);
- comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
- comptime const overflowBit = promotedType(1) << T.bit_count;
+ comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
+ comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
var x = ceilPowerOfTwoPromote(T, value);
if (overflowBit & x != 0) {
return error.Overflow;
@@ -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));
}
@@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
assert(x != 0);
const log2_val = log2_int(T, x);
- if (T(1) << log2_val == x)
+ if (@as(T, 1) << log2_val == x)
return log2_val;
return log2_val + 1;
}
@@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T {
switch (@typeInfo(@typeOf(value))) {
builtin.TypeId.Int => return @intToFloat(T, value),
builtin.TypeId.Float => return @floatCast(T, value),
- builtin.TypeId.ComptimeInt => return T(value),
- builtin.TypeId.ComptimeFloat => return T(value),
+ builtin.TypeId.ComptimeInt => return @as(T, value),
+ builtin.TypeId.ComptimeFloat => return @as(T, value),
else => @compileError("bad type"),
}
}
@@ -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 de07da8fe0cd..94b6fc3f8f4a 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 503c0433fc35..065e4d39de9d 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 2db9f86ff105..d354f8ceed7e 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 0fb51d1b4395..b915df317127 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 5790eba8cfa5..ea639872be52 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 8ba29be761ae..ae588f4fb825 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 bfdc768375d7..0459b0b15828 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;
}
@@ -281,7 +281,7 @@ pub const Int = struct {
var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);
if (info.bits <= Limb.bit_count) {
- self.limbs[0] = Limb(w_value);
+ self.limbs[0] = @as(Limb, w_value);
self.metadata += 1;
} else {
var i: usize = 0;
@@ -453,7 +453,7 @@ pub const Int = struct {
for (self.limbs[0..self.len()]) |limb| {
var shift: usize = 0;
while (shift < Limb.bit_count) : (shift += base_shift) {
- const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & Limb(base - 1));
+ const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));
const ch = try digitToChar(r, base);
try digits.append(ch);
}
@@ -560,7 +560,7 @@ pub const Int = struct {
/// Returns -1, 0, 1 if a < b, a == b or a > b respectively.
pub fn cmp(a: Int, b: Int) i8 {
if (a.isPositive() != b.isPositive()) {
- return if (a.isPositive()) i8(1) else -1;
+ return if (a.isPositive()) @as(i8, 1) else -1;
} else {
const r = cmpAbs(a, b);
return if (a.isPositive()) r else -r;
@@ -785,7 +785,7 @@ pub const Int = struct {
const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1));
// r2 = b * c
- const bc = DoubleLimb(math.mulWide(Limb, b, c));
+ const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
const r2 = @truncate(Limb, bc);
const c2 = @truncate(Limb, bc >> Limb.bit_count);
@@ -1084,7 +1084,7 @@ pub const Int = struct {
rem.* = 0;
for (a) |_, ri| {
const i = a.len - ri - 1;
- const pdiv = ((DoubleLimb(rem.*) << Limb.bit_count) | a[i]);
+ const pdiv = ((@as(DoubleLimb, rem.*) << Limb.bit_count) | a[i]);
if (pdiv == 0) {
quo[i] = 0;
@@ -1143,9 +1143,9 @@ pub const Int = struct {
if (x.limbs[i] == y.limbs[t]) {
q.limbs[i - t - 1] = maxInt(Limb);
} else {
- const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);
- const z = @intCast(Limb, num / DoubleLimb(y.limbs[t]));
- q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z);
+ const num = (@as(DoubleLimb, x.limbs[i]) << Limb.bit_count) | @as(DoubleLimb, x.limbs[i - 1]);
+ const z = @intCast(Limb, num / @as(DoubleLimb, y.limbs[t]));
+ q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else @as(Limb, z);
}
// 3.2
@@ -1362,7 +1362,7 @@ test "big.int comptime_int set" {
comptime var i: usize = 0;
inline while (i < s_limb_count) : (i += 1) {
- const result = Limb(s & maxInt(Limb));
+ const result = @as(Limb, s & maxInt(Limb));
s >>= Limb.bit_count / 2;
s >>= Limb.bit_count / 2;
testing.expect(a.limbs[i] == result);
@@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" {
}
test "big.int int set unaligned small" {
- var a = try Int.initSet(al, u7(45));
+ var a = try Int.initSet(al, @as(u7, 45));
testing.expect(a.limbs[0] == 45);
testing.expect(a.isPositive() == true);
diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig
index 5241e31323ea..c9e205a49590 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 5f86093a6d67..b5a2238621fc 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.zig b/lib/std/math/complex.zig
index e5574f9ceed4..8bff2313fc1d 100644
--- a/lib/std/math/complex.zig
+++ b/lib/std/math/complex.zig
@@ -133,8 +133,8 @@ test "complex.div" {
const b = Complex(f32).new(2, 7);
const c = a.div(b);
- testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
- math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
+ testing.expect(math.approxEq(f32, c.re, @as(f32, 31) / 53, epsilon) and
+ math.approxEq(f32, c.im, @as(f32, -29) / 53, epsilon));
}
test "complex.conjugate" {
@@ -148,8 +148,8 @@ test "complex.reciprocal" {
const a = Complex(f32).new(5, 3);
const c = a.reciprocal();
- testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
- math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
+ testing.expect(math.approxEq(f32, c.re, @as(f32, 5) / 34, epsilon) and
+ math.approxEq(f32, c.im, @as(f32, -3) / 34, epsilon));
}
test "complex.magnitude" {
diff --git a/lib/std/math/complex/acos.zig b/lib/std/math/complex/acos.zig
index f3526cc9fff5..b078ebf3458f 100644
--- a/lib/std/math/complex/acos.zig
+++ b/lib/std/math/complex/acos.zig
@@ -8,7 +8,7 @@ const Complex = cmath.Complex;
pub fn acos(z: var) Complex(@typeOf(z.re)) {
const T = @typeOf(z.re);
const q = cmath.asin(z);
- return Complex(T).new(T(math.pi) / 2 - q.re, -q.im);
+ return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);
}
const epsilon = 0.0001;
diff --git a/lib/std/math/complex/ldexp.zig b/lib/std/math/complex/ldexp.zig
index d6f810793f4d..d5d4cc64a6d6 100644
--- a/lib/std/math/complex/ldexp.zig
+++ b/lib/std/math/complex/ldexp.zig
@@ -59,13 +59,13 @@ 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) {
var ex_expt: i32 = undefined;
const exp_x = frexp_exp64(z.re, &ex_expt);
- const exptf = i64(expt + ex_expt);
+ const exptf = @as(i64, expt + ex_expt);
const half_expt1 = @divTrunc(exptf, 2);
const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20);
diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig
index 36f4c28e29c3..7e17f422bb58 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 6895e8a76976..fc7f4e9ea8a0 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 e4d90c395e67..e874da0bb941 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 5261a25f80c1..68e13e41bfcb 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 75c5c15ec153..62bedeaa49e8 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 718bbcd47633..986c35bf0d2c 100644
--- a/lib/std/math/exp.zig
+++ b/lib/std/math/exp.zig
@@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 {
}
if (x < -708.39641853226410622) {
// underflow if x != -inf
- // math.forceEval(f32(-0x1.0p-149 / x));
+ // math.forceEval(@as(f32, -0x1.0p-149 / x));
if (x < -745.13321910194110842) {
return 0;
}
@@ -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 57f6620d77ca..f3e51e542ed1 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 5e347f86f6ca..871fa38449ad 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 c00098a5a72e..590f36bb18d9 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 6469f388352f..e0eadd0d0042 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 e5ff2b1fc1a7..f2cabe8f029c 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 19c306fa2a3b..014593cda5f9 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 2759cd64923d..93705ae6a4aa 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 c15da1495e86..59116014b3ed 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 fe4158a6dd13..8d23bb09a0ed 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 99eba668f9b4..3d23a0f3bf29 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 37934f4cf44e..d691068be56e 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 cf8cd2e1c25c..ac865f0d0c60 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 f8611ef80528..01d919d41776 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 c5d4c9ff2573..fd5741a81843 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 @as(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 77f3639fd296..40b716b00597 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)),
}
@@ -64,9 +64,9 @@ test "math.log float" {
}
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(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
+ expect(log(f32, 10, 0.2301974) == math.log10(@as(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 9b0bc3ac52c7..f895e102a040 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);
@@ -177,8 +177,8 @@ 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(f32, 0.2)) == log10_32(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 bae6deb53698..047e089a91a7 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 88450a7ffdd1..47b214d6cf52 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 92194d4c7599..6567cbc9ed9d 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 0b80a46ce5b6..adedbf2e940e 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 d5716d621ca3..e3c457ade59b 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 e5c5909292ff..f20753f2ff8f 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 ee07b4f85e11..3baa730123ba 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 73ee65ea6f0e..c9718e3ce214 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 30af5915d40f..89eda4ea2b69 100644
--- a/lib/std/math/sqrt.zig
+++ b/lib/std/math/sqrt.zig
@@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;
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 T(@sqrt(f64, x)), // TODO upgrade to f128
+ TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
TypeId.Float => return @sqrt(T, x),
TypeId.ComptimeInt => comptime {
if (x > maxInt(u128)) {
@@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
if (x < 0) {
@compileError("sqrt on negative number");
}
- return T(sqrt_int(u128, x));
+ return @as(T, sqrt_int(u128, x));
},
TypeId.Int => return sqrt_int(T, x),
else => @compileError("sqrt not implemented for " ++ @typeName(T)),
@@ -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 049c85df12d5..1a027cf403f3 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 48d26d091e41..ced5f58bcc03 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 219bcd49146f..56a842345c26 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 89248283786c..19e9634d5a61 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 b29eb6020106..903c3a12b336 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -341,7 +341,7 @@ test "std.meta.TagType" {
///Returns the active tag of a tagged union
pub fn activeTag(u: var) @TagType(@typeOf(u)) {
const T = @typeOf(u);
- return @TagType(T)(u);
+ return @as(@TagType(T), u);
}
test "std.meta.activeTag" {
@@ -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 43be7f3dfb42..8857b4aa9e1d 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 95036707b6d1..d1db1478661d 100644
--- a/lib/std/net.zig
+++ b/lib/std/net.zig
@@ -117,7 +117,7 @@ pub const IpAddress = extern union {
ip_slice[10] = 0xff;
ip_slice[11] = 0xff;
- const ptr = @sliceToBytes((*const [1]u32)(&addr)[0..]);
+ const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]);
ip_slice[12] = ptr[0];
ip_slice[13] = ptr[1];
@@ -161,7 +161,7 @@ pub const IpAddress = extern union {
.addr = undefined,
},
};
- const out_ptr = @sliceToBytes((*[1]u32)(&result.in.addr)[0..]);
+ const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]);
var x: u8 = 0;
var index: u8 = 0;
@@ -271,7 +271,7 @@ pub const IpAddress = 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,
@@ -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;
}
@@ -1133,7 +1133,7 @@ fn resMSendRc(
}
// Wait for a response, or until time to retry
- const clamped_timeout = std.math.min(u31(std.math.maxInt(u31)), t1 + retry_interval - t2);
+ const clamped_timeout = std.math.min(@as(u31, std.math.maxInt(u31)), t1 + retry_interval - t2);
const nevents = os.poll(&pfd, clamped_timeout) catch 0;
if (nevents == 0) continue;
@@ -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 6803006bf175..68a3a6e9f65f 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 => {
@@ -1126,9 +1126,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro
const want_rmdir_behavior = (flags & AT_REMOVEDIR) != 0;
const create_options_flags = if (want_rmdir_behavior)
- w.ULONG(w.FILE_DELETE_ON_CLOSE)
+ @as(w.ULONG, w.FILE_DELETE_ON_CLOSE)
else
- w.ULONG(w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
+ @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
var nt_name = w.UNICODE_STRING{
@@ -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 87d89df7d8f8..042857b7501d 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 0fd528b0c0da..e101337c3ad5 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 a7dedefb4362..618a21f4568c 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 c7371fc28d6d..c457e10bebf4 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 b8d8a1636bb4..ac2bb3bfdfdf 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 791bec6a1282..60408c1e8434 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 64facede8991..b7c59a9039a6 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/test.zig b/lib/std/os/linux/test.zig
index e089a024457c..bccb7beb1e3a 100644
--- a/lib/std/os/linux/test.zig
+++ b/lib/std/os/linux/test.zig
@@ -72,7 +72,7 @@ test "statx" {
expect(stat_buf.mode == statx_buf.mode);
expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
- expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.size);
- expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.blksize);
- expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.blocks);
+ expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
+ expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
+ expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
}
diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig
index 86d54bfbf888..d3e00b867395 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 e0e4687c9fb8..d037b3c6aee2 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 1d615483969a..741f108eea25 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 c8c99c6a5917..9cdf8e931784 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -262,7 +262,7 @@ pub const ReadFileError = error{Unexpected};
pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {
var index: usize = 0;
while (index < buffer.len) {
- const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));
+ const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len - index));
var amt_read: DWORD = undefined;
if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
switch (kernel32.GetLastError()) {
@@ -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/windows/bits.zig b/lib/std/os/windows/bits.zig
index 214f75186f2e..951edf2d6708 100644
--- a/lib/std/os/windows/bits.zig
+++ b/lib/std/os/windows/bits.zig
@@ -69,7 +69,7 @@ pub const FALSE = 0;
pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
-pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
+pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
pub const FILE_ALL_INFORMATION = extern struct {
BasicInformation: FILE_BASIC_INFORMATION,
@@ -571,16 +571,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;
pub const KF_FLAG_ALIAS_ONLY = -2147483648;
pub const S_OK = 0;
-pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
-pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
-pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
-pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
-pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
-pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
-pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
-pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
-pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
-pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
+pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001));
+pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002));
+pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003));
+pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004));
+pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005));
+pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF));
+pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005));
+pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006));
+pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E));
+pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057));
pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
@@ -873,4 +873,4 @@ pub const CURDIR = extern struct {
Handle: HANDLE,
};
-pub const DUPLICATE_SAME_ACCESS = 2;
\ No newline at end of file
+pub const DUPLICATE_SAME_ACCESS = 2;
diff --git a/lib/std/os/zen.zig b/lib/std/os/zen.zig
index 9d111d98ae3b..190b7ffe0889 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 5cbab2d33be5..d8c77db59b4a 100644
--- a/lib/std/packed_int_array.zig
+++ b/lib/std/packed_int_array.zig
@@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
///Initialize a packed array using an unpacked array
/// or, more likely, an array literal.
pub fn init(ints: [int_count]Int) Self {
- var self = Self(undefined);
+ var self = @as(Self, undefined);
for (ints) |int, i| self.set(i, int);
return self;
}
@@ -328,11 +328,11 @@ test "PackedIntArray" {
const expected_bytes = ((bits * int_count) + 7) / 8;
testing.expect(@sizeOf(PackedArray) == expected_bytes);
- var data = PackedArray(undefined);
+ var data = @as(PackedArray, undefined);
//write values, counting up
- var i = usize(0);
- var count = I(0);
+ var i = @as(usize, 0);
+ var count = @as(I, 0);
while (i < data.len()) : (i += 1) {
data.set(i, count);
if (bits > 0) count +%= 1;
@@ -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,8 +375,8 @@ test "PackedIntSlice" {
var data = P.init(&buffer, int_count);
//write values, counting up
- var i = usize(0);
- var count = I(0);
+ var i = @as(usize, 0);
+ var count = @as(I, 0);
while (i < data.len()) : (i += 1) {
data.set(i, count);
if (bits > 0) count +%= 1;
@@ -402,11 +402,11 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
const Int = @IntType(false, bits);
const PackedArray = PackedIntArray(Int, int_count);
- var packed_array = PackedArray(undefined);
+ var packed_array = @as(PackedArray, undefined);
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));
}
@@ -463,20 +463,20 @@ test "PackedIntSlice accumulating bit offsets" {
// anything
{
const PackedArray = PackedIntArray(u3, 16);
- var packed_array = PackedArray(undefined);
+ var packed_array = @as(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());
}
}
{
const PackedArray = PackedIntArray(u11, 88);
- var packed_array = PackedArray(undefined);
+ var packed_array = @as(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,
@@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" {
i = 0;
while (i < packed_slice_cast_3.len()) : (i += 1) {
const val = switch (builtin.endian) {
- .Big => if (i % 2 == 0) u3(0b111) else u3(0b000),
- .Little => if (i % 2 == 0) u3(0b111) else u3(0b000),
+ .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
+ .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
};
testing.expect(packed_slice_cast_3.get(i) == val);
}
@@ -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 7a2b2c6b6b0d..8e4a9b5d6a9c 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 a081e03c5fc4..bf54f6937f3e 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 e14a60e2aecb..1fea0526edef 100644
--- a/lib/std/rand.zig
+++ b/lib/std/rand.zig
@@ -93,13 +93,13 @@ pub const Random = struct {
// http://www.pcg-random.org/posts/bounded-rands.html
// "Lemire's (with an extra tweak from me)"
var x: Small = r.int(Small);
- var m: Large = Large(x) * Large(less_than);
+ var m: Large = @as(Large, x) * @as(Large, less_than);
var l: Small = @truncate(Small, m);
if (l < less_than) {
// TODO: workaround for https://github.com/ziglang/zig/issues/1770
// should be:
// var t: Small = -%less_than;
- var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), Small(less_than)));
+ var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than)));
if (t >= less_than) {
t -= less_than;
@@ -109,7 +109,7 @@ pub const Random = struct {
}
while (l < t) {
x = r.int(Small);
- m = Large(x) * Large(less_than);
+ m = @as(Large, x) * @as(Large, less_than);
l = @truncate(Small, m);
}
}
@@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
// adapted from:
// http://www.pcg-random.org/posts/bounded-rands.html
// "Integer Multiplication (Biased)"
- var m: T2 = T2(random_int) * T2(less_than);
+ var m: T2 = @as(T2, random_int) * @as(T2, less_than);
return @intCast(T, m >> T.bit_count);
}
@@ -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 995248415be1..c29d3eeb2b38 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 3bbbde782e3e..7db153575560 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 378a92992fdd..c5758dd6e7ff 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 473d2d4e330d..145c8897d5ea 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 0a09f616e945..1fbb618b1e10 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 1654c1f08bb1..e3dd1819c35d 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 099b73797638..af991b37e923 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 f97e2474be36..95dc87863026 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 e99e0bb3dd44..4468da4fbeda 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 05e59745582e..e97301845519 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 072feaec675e..9937b09497e9 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 447653fbe1cc..4ee2eed36cfa 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 e1c1babae7fe..8601cfae030c 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 e10667843fe8..3bdc5164e220 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 6f8111c8fbc7..aa2faae90119 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 1ba8a4f87d68..e06d641824e8 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 fa5ff72e8f21..da53468c7da8 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 4ab2c04cd1bf..b0c9049ba857 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 fd31798cc2f9..426ee1d58acf 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 a876e1726339..d5f7b3898d23 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 bfd715425c50..02844946a784 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 30406fea22d6..69d8309de071 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 7136f7cfe865..cecfeda557ad 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 7c6354764263..b45001e18eef 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 da769089df02..c6f66239950b 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 02dba7fd6134..b36c5beb4eb6 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 55a113b3689b..977d3c16c989 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 e7096369122a..286567629a3f 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 833e4779ddc6..62a9bbfecfb8 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 7e05a3ebf7f3..714681834d26 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 42ef6df7e449..1e83674598a0 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 f397d130ef71..0c02bfff1f50 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 b05282e29376..aac22e36d012 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 efeb4c267257..d744009aeaa7 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 2cd38c73084b..5d3a201058b6 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 1b42b267d960..e450ad9a4810 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 eddcf92efd67..f92942e0347a 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 51d40ad26f62..11ee0b49a4da 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 1c0c0fc04337..57dc38532174 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 7700777c1664..3efc5a9ac64d 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 82e9ef32536d..21c7fd1f9745 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 7575c770440f..803d60e8fa82 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 ccde8e3e6cf8..ad6ad4380805 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 00144a8839b8..f94a13e04f9b 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 799b1f575d7d..f3b74b85d908 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 b71a503c1dbf..c4be085d62b1 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 bedcbcd1de20..fe02786e15bd 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 e4c4aa38a72f..d231c0d41655 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 eccf7efb7e4c..d1dd837ddc2b 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 c3066153f31d..96fb7b3bdd32 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 d297312b4eb4..d84ef473474a 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 fbfb1afd1e10..4e1535405501 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 04dbb908e296..716c99957793 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 2e961471665e..726b84f1250a 100644
--- a/lib/std/unicode.zig
+++ b/lib/std/unicode.zig
@@ -7,10 +7,10 @@ const mem = std.mem;
/// Returns how many bytes the UTF-8 representation would require
/// for the given codepoint.
pub fn utf8CodepointSequenceLength(c: u32) !u3 {
- if (c < 0x80) return u3(1);
- if (c < 0x800) return u3(2);
- if (c < 0x10000) return u3(3);
- if (c < 0x110000) return u3(4);
+ if (c < 0x80) return @as(u3, 1);
+ if (c < 0x800) return @as(u3, 2);
+ if (c < 0x10000) return @as(u3, 3);
+ if (c < 0x110000) return @as(u3, 4);
return error.CodepointTooLarge;
}
@@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 {
/// returns a number 1-4 indicating the total length of the codepoint in bytes.
/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
- if (first_byte < 0b10000000) return u3(1);
- if (first_byte & 0b11100000 == 0b11000000) return u3(2);
- if (first_byte & 0b11110000 == 0b11100000) return u3(3);
- if (first_byte & 0b11111000 == 0b11110000) return u3(4);
+ if (first_byte < 0b10000000) return @as(u3, 1);
+ if (first_byte & 0b11100000 == 0b11000000) return @as(u3, 2);
+ if (first_byte & 0b11110000 == 0b11100000) return @as(u3, 3);
+ if (first_byte & 0b11111000 == 0b11110000) return @as(u3, 4);
return error.Utf8InvalidStartByte;
}
@@ -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 0d7f79dfa2ab..a8ebbbd8a400 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 acae0b64c79c..a6bdff4a023d 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 28bd287c8a55..28497ad6f1ae 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 996cfc29e4e2..81ba8e941cd9 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 19488ba87317..b401b25aded1 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/src-self-hosted/stage1.zig b/src-self-hosted/stage1.zig
index 3524c4f5b5fe..e84f7b0ac1bc 100644
--- a/src-self-hosted/stage1.zig
+++ b/src-self-hosted/stage1.zig
@@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
}
if (flags.present("check")) {
const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
- const code = if (anything_changed) u8(1) else u8(0);
+ const code = if (anything_changed) @as(u8, 1) else @as(u8, 0);
process.exit(code);
}
diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig
index b4f69753b1a8..f8d3a12343a1 100644
--- a/src-self-hosted/translate_c.zig
+++ b/src-self-hosted/translate_c.zig
@@ -123,7 +123,7 @@ const Context = struct {
fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 {
const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc);
const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc);
- const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)");
+ const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)");
const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
@@ -774,12 +774,14 @@ fn transCCast(
if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))
return transCPtrCast(rp, loc, dst_type, src_type, expr);
if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) {
- const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
+ const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
+ try cast_node.params.push(try transQualType(rp, dst_type, loc));
+ _ = try appendToken(rp.c, .Comma, ",");
const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");
try builtin_node.params.push(expr);
builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")");
- try cast_node.op.Call.params.push(&builtin_node.base);
- cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
+ try cast_node.params.push(&builtin_node.base);
+ cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
return &cast_node.base;
}
if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) {
@@ -793,9 +795,11 @@ fn transCCast(
// TODO: maybe widen to increase size
// TODO: maybe bitcast to change sign
// TODO: maybe truncate to reduce size
- const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
- try cast_node.op.Call.params.push(expr);
- cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
+ const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
+ try cast_node.params.push(try transQualType(rp, dst_type, loc));
+ _ = try appendToken(rp.c, .Comma, ",");
+ try cast_node.params.push(expr);
+ cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
return &cast_node.base;
}
diff --git a/src/all_types.hpp b/src/all_types.hpp
index 42f14539f3d5..8ba2bfc50351 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -48,6 +48,7 @@ struct ResultLoc;
struct ResultLocPeer;
struct ResultLocPeerParent;
struct ResultLocBitCast;
+struct ResultLocCast;
struct ResultLocReturn;
enum PtrLen {
@@ -1691,6 +1692,7 @@ enum BuiltinFnId {
BuiltinFnIdFrameType,
BuiltinFnIdFrameHandle,
BuiltinFnIdFrameSize,
+ BuiltinFnIdAs,
};
struct BuiltinFnEntry {
@@ -3458,6 +3460,13 @@ struct IrInstructionPtrCastGen {
bool safety_check_on;
};
+struct IrInstructionImplicitCast {
+ IrInstruction base;
+
+ IrInstruction *operand;
+ ResultLocCast *result_loc_cast;
+};
+
struct IrInstructionBitCastSrc {
IrInstruction base;
@@ -3823,14 +3832,6 @@ struct IrInstructionEndExpr {
ResultLoc *result_loc;
};
-struct IrInstructionImplicitCast {
- IrInstruction base;
-
- IrInstruction *dest_type;
- IrInstruction *target;
- ResultLoc *result_loc;
-};
-
// This one is for writing through the result pointer.
struct IrInstructionResolveResult {
IrInstruction base;
@@ -3928,6 +3929,7 @@ enum ResultLocId {
ResultLocIdPeerParent,
ResultLocIdInstruction,
ResultLocIdBitCast,
+ ResultLocIdCast,
};
// Additions to this struct may need to be handled in
@@ -3995,6 +3997,13 @@ struct ResultLocBitCast {
ResultLoc *parent;
};
+// The source_instruction is the destination type
+struct ResultLocCast {
+ ResultLoc base;
+
+ ResultLoc *parent;
+};
+
static const size_t slice_ptr_index = 0;
static const size_t slice_len_index = 1;
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 89c41b61cc13..4861def16cac 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -8070,6 +8070,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdFrameType, "Frame", 1);
create_builtin_fn(g, BuiltinFnIdFrameAddress, "frameAddress", 0);
create_builtin_fn(g, BuiltinFnIdFrameSize, "frameSize", 1);
+ create_builtin_fn(g, BuiltinFnIdAs, "as", 2);
}
static const char *bool_to_str(bool b) {
diff --git a/src/ir.cpp b/src/ir.cpp
index dae759ed84ef..9225968ce9a1 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -200,6 +200,8 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
static void ir_reset_result(ResultLoc *result_loc);
static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
Scope *scope, AstNode *source_node, Buf *out_bare_name);
+static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
+ ResultLoc *parent_result_loc);
static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
assert(get_src_ptr_type(const_val->type) != nullptr);
@@ -2766,6 +2768,18 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc
return &instruction->base;
}
+static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
+ IrInstruction *operand, ResultLocCast *result_loc_cast)
+{
+ IrInstructionImplicitCast *instruction = ir_build_instruction(irb, scope, source_node);
+ instruction->operand = operand;
+ instruction->result_loc_cast = result_loc_cast;
+
+ ir_ref_instruction(operand, irb->current_basic_block);
+
+ return &instruction->base;
+}
+
static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)
{
@@ -3063,20 +3077,6 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode
return &instruction->base;
}
-static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
- IrInstruction *dest_type, IrInstruction *target, ResultLoc *result_loc)
-{
- IrInstructionImplicitCast *instruction = ir_build_instruction(irb, scope, source_node);
- instruction->dest_type = dest_type;
- instruction->target = target;
- instruction->result_loc = result_loc;
-
- ir_ref_instruction(dest_type, irb->current_basic_block);
- ir_ref_instruction(target, irb->current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
ResultLoc *result_loc, IrInstruction *ty)
{
@@ -5374,6 +5374,24 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
}
+ case BuiltinFnIdAs:
+ {
+ AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
+ IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
+ if (dest_type == irb->codegen->invalid_instruction)
+ return dest_type;
+
+ ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
+
+ AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
+ IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
+ &result_loc_cast->base);
+ if (arg1_value == irb->codegen->invalid_instruction)
+ return arg1_value;
+
+ IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
+ return ir_lval_wrap(irb, scope, result, lval, result_loc);
+ }
case BuiltinFnIdIntToPtr:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
@@ -6214,6 +6232,20 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo
return result_loc_var;
}
+static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
+ ResultLoc *parent_result_loc)
+{
+ ResultLocCast *result_loc_cast = allocate(1);
+ result_loc_cast->base.id = ResultLocIdCast;
+ result_loc_cast->base.source_instruction = dest_type;
+ ir_ref_instruction(dest_type, irb->current_basic_block);
+ result_loc_cast->parent = parent_result_loc;
+
+ ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
+
+ return result_loc_cast;
+}
+
static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)
{
@@ -6282,7 +6314,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
// Create a result location for the initialization expression.
ResultLocVar *result_loc_var = ir_build_var_result_loc(irb, alloca, var);
- ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr;
+ ResultLoc *init_result_loc;
+ ResultLocCast *result_loc_cast;
+ if (type_instruction != nullptr) {
+ result_loc_cast = ir_build_cast_result_loc(irb, type_instruction, &result_loc_var->base);
+ init_result_loc = &result_loc_cast->base;
+ } else {
+ result_loc_cast = nullptr;
+ init_result_loc = &result_loc_var->base;
+ }
Scope *init_scope = is_comptime_scalar ?
create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
@@ -6298,9 +6338,9 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
if (init_value == irb->codegen->invalid_instruction)
return irb->codegen->invalid_instruction;
- if (type_instruction != nullptr) {
- IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, node, type_instruction, init_value,
- &result_loc_var->base);
+ if (result_loc_cast != nullptr) {
+ IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,
+ init_value, result_loc_cast);
ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
}
@@ -9571,7 +9611,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
}
ir_add_error(ira, instruction,
- buf_sprintf("%s value %s cannot be implicitly casted to type '%s'",
+ buf_sprintf("%s value %s cannot be coerced to type '%s'",
num_lit_str,
buf_ptr(val_buf),
buf_ptr(&other_type->name)));
@@ -13026,8 +13066,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return ira->codegen->invalid_instruction;
}
-static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type,
- ResultLoc *result_loc)
+static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *source_instr,
+ IrInstruction *value, ZigType *expected_type, ResultLoc *result_loc)
{
assert(value);
assert(value != ira->codegen->invalid_instruction);
@@ -13041,11 +13081,11 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction
if (value->value.type->id == ZigTypeIdUnreachable)
return value;
- return ir_analyze_cast(ira, value, expected_type, value, result_loc);
+ return ir_analyze_cast(ira, source_instr, expected_type, value, result_loc);
}
static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
- return ir_implicit_cast_with_result(ira, value, expected_type, nullptr);
+ return ir_implicit_cast_with_result(ira, value, value, expected_type, nullptr);
}
static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
@@ -15435,6 +15475,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe
case ResultLocIdNone:
case ResultLocIdVar:
case ResultLocIdBitCast:
+ case ResultLocIdCast:
return nullptr;
case ResultLocIdInstruction:
return result_loc->source_instruction->child->value.type;
@@ -15489,6 +15530,7 @@ static bool ir_result_has_type(ResultLoc *result_loc) {
case ResultLocIdReturn:
case ResultLocIdInstruction:
case ResultLocIdBitCast:
+ case ResultLocIdCast:
return true;
case ResultLocIdVar:
return reinterpret_cast(result_loc)->var->decl_node->data.variable_declaration.type != nullptr;
@@ -15496,6 +15538,26 @@ static bool ir_result_has_type(ResultLoc *result_loc) {
zig_unreachable();
}
+static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,
+ ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
+{
+ Error err;
+
+ IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
+ if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
+ return ira->codegen->invalid_instruction;
+ alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
+ PtrLenSingle, 0, 0, 0, false);
+ set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
+ fn_entry->alloca_gen_list.append(alloca_gen);
+ }
+ result_loc->written = true;
+ result_loc->resolved_loc = &alloca_gen->base;
+ return result_loc->resolved_loc;
+}
+
// 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)
@@ -15518,19 +15580,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
return nullptr;
}
// need to return a result location and don't have one. use a stack allocation
- IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
- if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
- return ira->codegen->invalid_instruction;
- alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
- PtrLenSingle, 0, 0, 0, false);
- set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
- ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
- if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
- fn_entry->alloca_gen_list.append(alloca_gen);
- }
- result_loc->written = true;
- result_loc->resolved_loc = &alloca_gen->base;
- return result_loc->resolved_loc;
+ return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
+ force_runtime, non_null_comptime);
}
case ResultLocIdVar: {
ResultLocVar *result_loc_var = reinterpret_cast(result_loc);
@@ -15668,6 +15719,67 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
result_loc->resolved_loc = parent_result_loc;
return result_loc->resolved_loc;
}
+ case ResultLocIdCast: {
+ if (value != nullptr && value->value.special != ConstValSpecialRuntime)
+ return nullptr;
+ ResultLocCast *result_cast = reinterpret_cast(result_loc);
+ ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
+ if (type_is_invalid(dest_type))
+ return ira->codegen->invalid_instruction;
+
+ 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);
+ } else {
+ casted_value = nullptr;
+ }
+
+ if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) {
+ return casted_value;
+ }
+
+ 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) ||
+ parent_result_loc->value.type->id == ZigTypeIdUnreachable)
+ {
+ return parent_result_loc;
+ }
+ ZigType *parent_ptr_type = parent_result_loc->value.type;
+ assert(parent_ptr_type->id == ZigTypeIdPointer);
+ if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
+ ResolveStatusAlignmentKnown)))
+ {
+ return ira->codegen->invalid_instruction;
+ }
+ uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
+ if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
+ return ira->codegen->invalid_instruction;
+ }
+ if (!type_has_bits(value_type)) {
+ parent_ptr_align = 0;
+ }
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
+ 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);
+
+ result_loc->written = true;
+ result_loc->resolved_loc = 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);
ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
@@ -15790,18 +15902,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
return result_loc;
}
-static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
- ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
- if (type_is_invalid(dest_type))
- return ira->codegen->invalid_instruction;
-
- IrInstruction *target = instruction->target->child;
- if (type_is_invalid(target->value.type))
- return ira->codegen->invalid_instruction;
-
- return ir_implicit_cast_with_result(ira, target, dest_type, instruction->result_loc);
-}
-
static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) {
ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
if (type_is_invalid(implicit_elem_type))
@@ -15864,6 +15964,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
case ResultLocIdNone:
case ResultLocIdInstruction:
case ResultLocIdBitCast:
+ case ResultLocIdCast:
break;
}
}
@@ -16903,25 +17004,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
if (is_comptime || instr_is_comptime(fn_ref)) {
if (fn_ref->value.type->id == ZigTypeIdMetaType) {
- ZigType *dest_type = ir_resolve_type(ira, fn_ref);
- if (type_is_invalid(dest_type))
- return ira->codegen->invalid_instruction;
-
- size_t actual_param_count = call_instruction->arg_count;
-
- if (actual_param_count != 1) {
- ir_add_error_node(ira, call_instruction->base.source_node,
- buf_sprintf("cast expression expects exactly one parameter"));
- return ira->codegen->invalid_instruction;
- }
-
- IrInstruction *arg = call_instruction->args[0]->child;
-
- IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg,
- call_instruction->result_loc);
- if (type_is_invalid(cast_instruction->value.type))
+ ZigType *ty = ir_resolve_type(ira, fn_ref);
+ if (ty == nullptr)
return ira->codegen->invalid_instruction;
- return ir_finish_anal(ira, cast_instruction);
+ ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,
+ buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
+ add_error_note(ira->codegen, msg, call_instruction->base.source_node,
+ buf_sprintf("use @as builtin for type coercion"));
+ return ira->codegen->invalid_instruction;
} else if (fn_ref->value.type->id == ZigTypeIdFn) {
ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type;
@@ -17453,6 +17543,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
if (peer_parent != nullptr && ir_result_has_type(peer_parent->parent)) {
if (peer_parent->parent->id == ResultLocIdReturn) {
resolved_type = ira->explicit_return_type;
+ } else if (peer_parent->parent->id == ResultLocIdCast) {
+ resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
+ if (type_is_invalid(resolved_type))
+ return ira->codegen->invalid_instruction;
} else {
ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type;
ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
@@ -25958,6 +26052,26 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
return ir_const_void(ira, &instruction->base);
}
+static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
+ IrInstruction *operand = instruction->operand->child;
+ if (type_is_invalid(operand->value.type))
+ return operand;
+
+ IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
+ &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true);
+ if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))
+ return result_loc;
+
+ if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {
+ return instruction->result_loc_cast->parent->gen_instruction;
+ }
+
+ ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
+ if (type_is_invalid(dest_type))
+ return ira->codegen->invalid_instruction;
+ return ir_implicit_cast_with_result(ira, &instruction->base, operand, dest_type, nullptr);
+}
+
static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
IrInstruction *operand = instruction->operand->child;
if (type_is_invalid(operand->value.type))
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index aa53b11e03f1..85b58faefc17 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -601,6 +601,12 @@ static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_
fprintf(irp->f, ")");
}
+static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) {
+ fprintf(irp->f, "cast(ty=");
+ ir_print_other_instruction(irp, result_loc_cast->base.source_instruction);
+ fprintf(irp->f, ")");
+}
+
static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
switch (result_loc->id) {
case ResultLocIdInvalid:
@@ -619,6 +625,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc);
case ResultLocIdBitCast:
return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc);
+ case ResultLocIdCast:
+ return ir_print_result_loc_cast(irp, (ResultLocCast *)result_loc);
case ResultLocIdPeerParent:
fprintf(irp->f, "peer_parent");
return;
@@ -1484,6 +1492,13 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc
fprintf(irp->f, ")");
}
+static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
+ fprintf(irp->f, "@implicitCast(");
+ ir_print_other_instruction(irp, instruction->operand);
+ fprintf(irp->f, ")result=");
+ ir_print_result_loc(irp, &instruction->result_loc_cast->base);
+}
+
static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {
fprintf(irp->f, "@bitCast(");
ir_print_other_instruction(irp, instruction->operand);
@@ -1739,14 +1754,6 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio
fprintf(irp->f, ")");
}
-static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
- fprintf(irp->f, "@implicitCast(");
- ir_print_other_instruction(irp, instruction->dest_type);
- fprintf(irp->f, ",");
- ir_print_other_instruction(irp, instruction->target);
- fprintf(irp->f, ")");
-}
-
static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {
fprintf(irp->f, "ResolveResult(");
ir_print_result_loc(irp, instruction->result_loc);
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index 6765bf45fb92..2214dc7d547c 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -221,6 +221,15 @@ static AstNode *trans_create_node_opaque(Context *c) {
return trans_create_node_builtin_fn_call_str(c, "OpaqueType");
}
+static AstNode *trans_create_node_cast(Context *c, AstNode *dest_type, AstNode *operand) {
+ AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
+ node->data.fn_call_expr.fn_ref_expr = trans_create_node_symbol(c, buf_create_from_str("as"));
+ node->data.fn_call_expr.modifier = CallModifierBuiltin;
+ node->data.fn_call_expr.params.append(dest_type);
+ node->data.fn_call_expr.params.append(operand);
+ return node;
+}
+
static AstNode *trans_create_node_fn_call_1(Context *c, AstNode *fn_ref_expr, AstNode *arg1) {
AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
node->data.fn_call_expr.fn_ref_expr = fn_ref_expr;
@@ -337,14 +346,6 @@ static AstNode *trans_create_node_unsigned(Context *c, uint64_t x) {
return trans_create_node_unsigned_negative(c, x, false);
}
-static AstNode *trans_create_node_cast(Context *c, AstNode *dest, AstNode *src) {
- AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
- node->data.fn_call_expr.fn_ref_expr = dest;
- node->data.fn_call_expr.params.resize(1);
- node->data.fn_call_expr.params.items[0] = src;
- return node;
-}
-
static AstNode *trans_create_node_unsigned_negative_type(Context *c, uint64_t x, bool is_negative,
const char *type_name)
{
@@ -701,7 +702,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location,
if (c_is_unsigned_integer(c, dest_type) && qual_type_is_ptr(src_type)) {
AstNode *addr_node = trans_create_node_builtin_fn_call_str(c, "ptrToInt");
addr_node->data.fn_call_expr.params.append(expr);
- return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), addr_node);
+ return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), addr_node);
}
if (c_is_unsigned_integer(c, src_type) && qual_type_is_ptr(dest_type)) {
AstNode *ptr_node = trans_create_node_builtin_fn_call_str(c, "intToPtr");
@@ -712,7 +713,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location,
// TODO: maybe widen to increase size
// TODO: maybe bitcast to change sign
// TODO: maybe truncate to reduce size
- return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), expr);
+ return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), expr);
}
static bool c_is_signed_integer(Context *c, ZigClangQualType qt) {
@@ -1527,7 +1528,7 @@ static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQua
AstNode *rhs = trans_expr(c, ResultUsedYes, scope, rhs_expr, TransRValue);
if (rhs == nullptr) return nullptr;
- AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
+ AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
return trans_create_node_bin_op(c, lhs, bin_op, coerced_rhs);
}
@@ -1702,7 +1703,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
AstNode *rhs = trans_expr(c, ResultUsedYes, scope, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
if (rhs == nullptr) return nullptr;
- AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
+ AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
return trans_create_node_bin_op(c, lhs, assign_op, coerced_rhs);
} else {
@@ -1733,7 +1734,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
if (rhs == nullptr) return nullptr;
- AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
+ AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
// operation_type(*_ref)
AstNode *operation_type_cast = trans_c_cast(c, rhs_location,
@@ -2684,7 +2685,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type)
// @TagType(Enum)(0)
AstNode *zero = trans_create_node_unsigned_negative(c, 0, false);
- AstNode *casted_zero = trans_create_node_fn_call_1(c, tag_type, zero);
+ AstNode *casted_zero = trans_create_node_cast(c, tag_type, zero);
// @bitCast(Enum, @TagType(Enum)(0))
AstNode *bitcast = trans_create_node_builtin_fn_call_str(c, "bitCast");
diff --git a/test/compare_output.zig b/test/compare_output.zig
index cbc74c8be27f..4e55b374b6ab 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");
@@ -145,75 +145,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ _ = c._setmode(1, c._O_BINARY);
\\ }
\\ _ = c.printf(c"0: %llu\n",
- \\ u64(0));
+ \\ @as(u64, 0));
\\ _ = c.printf(c"320402575052271: %llu\n",
- \\ u64(320402575052271));
+ \\ @as(u64, 320402575052271));
\\ _ = c.printf(c"0x01236789abcdef: %llu\n",
- \\ u64(0x01236789abcdef));
+ \\ @as(u64, 0x01236789abcdef));
\\ _ = c.printf(c"0xffffffffffffffff: %llu\n",
- \\ u64(0xffffffffffffffff));
+ \\ @as(u64, 0xffffffffffffffff));
\\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n",
- \\ u64(0x000000ffffffffffffffff));
+ \\ @as(u64, 0x000000ffffffffffffffff));
\\ _ = c.printf(c"0o1777777777777777777777: %llu\n",
- \\ u64(0o1777777777777777777777));
+ \\ @as(u64, 0o1777777777777777777777));
\\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n",
- \\ u64(0o0000001777777777777777777777));
+ \\ @as(u64, 0o0000001777777777777777777777));
\\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",
- \\ u64(0b1111111111111111111111111111111111111111111111111111111111111111));
+ \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111));
\\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",
- \\ u64(0b0000001111111111111111111111111111111111111111111111111111111111111111));
+ \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111));
\\
\\ _ = 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 6cdc5d1cda0c..0917c3dbb451 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -186,21 +186,21 @@ 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'",
+ "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'",
"tmp.zig:2:17: note: referenced here",
);
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'",
- "tmp.zig:2:22: note: referenced here",
+ "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'",
+ "tmp.zig:2:27: note: referenced here",
);
cases.add(
@@ -241,11 +241,11 @@ 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'",
- "tmp.zig:5:22: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
+ "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
);
cases.addCase(x: {
@@ -1243,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var ptr: [*c]u8 = x;
\\}
,
- "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be implicitly casted to type 'usize'",
+ "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
"tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
);
@@ -1297,17 +1297,17 @@ 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",
+ "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
);
cases.addTest(
"return invalid type from test",
\\test "example" { return 1; }
,
- "tmp.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'",
+ "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",
);
cases.add(
@@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@bitCast with different sizes inside an expression",
\\export fn entry() void {
- \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf);
+ \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
\\}
,
"tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
@@ -1464,8 +1464,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var byte: u8 = spartan_count;
\\}
,
- "tmp.zig:3:31: error: integer value 300 cannot be implicitly casted to type 'u8'",
- "tmp.zig:7:22: error: integer value 300 cannot be implicitly casted to type 'u8'",
+ "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'",
+ "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'",
"tmp.zig:11:20: error: expected type 'u8', found 'u16'",
);
@@ -1498,7 +1498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var x: i65536 = 1;
\\}
,
- "tmp.zig:2:31: error: integer value 65536 cannot be implicitly casted to type 'u16'",
+ "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
"tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
);
@@ -1686,10 +1686,10 @@ 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'",
+ "tmp.zig:2:32: error: expected float type, found 'i32'",
);
cases.add(
@@ -1698,7 +1698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ const x = @floatToInt(i8, 200);
\\}
,
- "tmp.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'",
+ "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
);
cases.add(
@@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@floatToInt comptime safety",
\\comptime {
- \\ _ = @floatToInt(i8, f32(-129.1));
+ \\ _ = @floatToInt(i8, @as(f32, -129.1));
\\}
\\comptime {
- \\ _ = @floatToInt(u8, f32(-1.1));
+ \\ _ = @floatToInt(u8, @as(f32, -1.1));
\\}
\\comptime {
- \\ _ = @floatToInt(u8, f32(256.1));
+ \\ _ = @floatToInt(u8, @as(f32, 256.1));
\\}
,
"tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
@@ -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;
@@ -2207,7 +2207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var rule_set = try Foo.init();
\\}
,
- "tmp.zig:2:13: error: expected type 'i32', found 'type'",
+ "tmp.zig:2:10: error: expected type 'i32', found 'type'",
);
cases.add(
@@ -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'",
@@ -2357,10 +2357,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"comptime slice of undefined pointer non-zero len",
\\export fn entry() void {
- \\ const slice = ([*]i32)(undefined)[0..1];
+ \\ const slice = @as([*]i32, undefined)[0..1];
\\}
,
- "tmp.zig:2:38: error: non-zero length slice of undefined pointer",
+ "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
);
cases.add(
@@ -2657,10 +2657,10 @@ 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'",
+ "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
);
cases.add(
@@ -3384,11 +3384,11 @@ 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); }
,
- "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
+ "tmp.zig:2:21: error: expected type 'i32', found 'void'",
"tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
);
@@ -3520,11 +3520,11 @@ 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(); }
,
- "tmp.zig:2:15: error: unreachable code",
+ "tmp.zig:2:12: error: unreachable code",
);
cases.add(
@@ -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)); }
@@ -3765,7 +3765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const x : u8 = 300;
\\export fn entry() usize { return @sizeOf(@typeOf(x)); }
,
- "tmp.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'",
+ "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
);
cases.add(
@@ -3887,8 +3887,8 @@ 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 float_x = f32(1.0) / f32(0.0);
+ \\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)); }
@@ -3897,8 +3897,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
,
"tmp.zig:1:21: error: division by zero",
"tmp.zig:2:25: error: division by zero",
- "tmp.zig:3:22: error: division by zero",
- "tmp.zig:4:26: error: division by zero",
+ "tmp.zig:3:27: error: division by zero",
+ "tmp.zig:4:31: error: division by zero",
);
cases.add(
@@ -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];
\\ }}
@@ -4908,7 +4908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var vga_mem: u16 = 0xB8000;
\\}
,
- "tmp.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'",
+ "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
);
cases.add(
@@ -5080,7 +5080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"pass const ptr to mutable ptr fn",
\\fn foo() bool {
- \\ const a = ([]const u8)("a",);
+ \\ const a = @as([]const u8, "a",);
\\ const b = &a;
\\ return ptrEql(b, b);
\\}
@@ -5581,10 +5581,10 @@ 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'",
+ "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
);
cases.add(
@@ -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",
@@ -5671,16 +5671,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\export fn entry() void {
\\ var foo = Foo { .a = 1, .b = 10 };
\\ foo.b += 1;
- \\ bar((*[1]u32)(&foo.b)[0..]);
+ \\ bar(@as(*[1]u32, &foo.b)[0..]);
\\}
\\
\\fn bar(x: []u32) void {
\\ x[0] += 1;
\\}
,
- "tmp.zig:9:18: error: cast increases pointer alignment",
- "tmp.zig:9:23: note: '*align(1) u32' has alignment 1",
- "tmp.zig:9:18: note: '*[1]u32' has alignment 4",
+ "tmp.zig:9:9: error: cast increases pointer alignment",
+ "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
+ "tmp.zig:9:9: note: '*[1]u32' has alignment 4",
);
cases.add(
@@ -5699,10 +5699,10 @@ 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'",
+ "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
);
cases.add(
@@ -5740,11 +5740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
);
cases.add(
- "wrong pointer implicitly casted to pointer to @OpaqueType()",
+ "wrong pointer coerced to pointer to @OpaqueType()",
\\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));
\\}
,
@@ -5793,27 +5793,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
"tmp.zig:20:4: error: variable of type 'type' must be const or comptime",
"tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
- "tmp.zig:26:4: error: unreachable code",
+ "tmp.zig:26:22: error: unreachable code",
);
cases.add(
"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'",
+ "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
);
cases.add(
"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'",
+ "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
);
cases.add(
@@ -6185,7 +6185,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\};
\\
\\export fn entry() void {
- \\ var y = u3(3);
+ \\ var y = @as(u3, 3);
\\ var x = @intToEnum(Small, y);
\\}
,
@@ -6722,8 +6722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:1:1: note: declared here",
);
- // fixed bug #2032
- cases.add(
+ cases.add( // fixed bug #2032
"compile diagnostic string for top level decl type",
\\export fn entry() void {
\\ var foo: u32 = @This(){};
@@ -6731,6 +6730,5 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
,
"tmp.zig:2:27: error: expected type 'u32', found '(root)'",
"tmp.zig:1:1: note: (root) declared here",
- "tmp.zig:2:5: note: referenced here",
);
}
diff --git a/test/stage1/behavior/align.zig b/test/stage1/behavior/align.zig
index bb40270cdad8..7f9ccaff1eb8 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 462977066e46..f9ca1efdb923 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 3fe0654a6ac5..9278d45d5d1e 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 8445bcb5b25b..99efa0e7be50 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 8c4a186032b0..d49589bdcca3 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 2b0eb71fb69c..8de2d5d2ca4b 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 dfc22790052e..ef9383244e7f 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 f1d61baa3af1..3231a985e77f 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 48cf1ae2a6c0..da0ba4168037 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 e266279564d8..5b664e64efa1 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 709198fd584e..b62474f9ba12 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 5408b893f55a..c799ba484968 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 e5650bc3fc03..98d987a73f21 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);
@@ -75,8 +75,8 @@ test "peer resolve array and const slice" {
comptime testPeerResolveArrayConstSlice(true);
}
fn testPeerResolveArrayConstSlice(b: bool) void {
- const value1 = if (b) "aoeu" else ([]const u8)("zz");
- const value2 = if (b) ([]const u8)("zz") else "aoeu";
+ const value1 = if (b) "aoeu" else @as([]const u8, "zz");
+ const value2 = if (b) @as([]const u8, "zz") else "aoeu";
expect(mem.eql(u8, value1, "aoeu"));
expect(mem.eql(u8, value2, "zz"));
}
@@ -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,9 +256,9 @@ test "@floatToInt" {
}
fn testFloatToInts() void {
- const x = i32(1e4);
+ const x = @as(i32, 1e4);
expect(x == 10000);
- const y = @floatToInt(i32, f32(1e4));
+ const y = @floatToInt(i32, @as(f32, 1e4));
expect(y == 10000);
expectFloatToInt(f16, 255.1, u8, 255);
expectFloatToInt(f16, 127.2, i8, 127);
@@ -392,7 +392,7 @@ fn MakeType(comptime T: type) type {
}
fn getNonNull() ?T {
- return T(undefined);
+ return @as(T, undefined);
}
};
}
@@ -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.* = {};
}
@@ -535,12 +535,12 @@ test "peer type resolution: unreachable, error set, unreachable" {
}
test "implicit cast comptime_int to comptime_float" {
- comptime expect(comptime_float(10) == f32(10));
+ comptime expect(@as(comptime_float, 10) == @as(f32, 10));
expect(2 == 2.0);
}
test "implicit cast *[0]T to E![]const u8" {
- var x = (anyerror![]const u8)(&[0]u8{});
+ var x = @as(anyerror![]const u8, &[0]u8{});
expect((x catch unreachable).len == 0);
}
diff --git a/test/stage1/behavior/defer.zig b/test/stage1/behavior/defer.zig
index 6c0e2a432a25..5a643609fdef 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 6084dad3cb92..f20523487d7f 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 983f790cbee9..8ee1b3090782 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 58d662d76879..fa899d0cb212 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 de2f6815a623..eb386d75f963 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 6b9c8b8fe7fc..1fc586f39f80 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 d299817f465b..9e93ceb656c7 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 aa6e9d82bae9..2aa2ec4e6004 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 1ff63e3e2312..37a23fa325b8 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 65ac83bcf077..1a227a5b935c 100644
--- a/test/stage1/behavior/misc.zig
+++ b/test/stage1/behavior/misc.zig
@@ -241,14 +241,14 @@ fn memFree(comptime T: type, memory: []T) void {}
test "cast undefined" {
const array: [100]u8 = undefined;
- const slice = ([]const u8)(array);
+ const slice = @as([]const u8, array);
testCastUndefined(slice);
}
fn testCastUndefined(x: []const u8) void {}
test "cast small unsigned to larger signed" {
- expect(castSmallUnsignedToLargerSigned1(200) == i16(200));
- expect(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
+ expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
+ expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
}
fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
return x;
@@ -268,7 +268,7 @@ fn outer() i64 {
}
test "pointer dereferencing" {
- var x = i32(3);
+ var x = @as(i32, 3);
const y = &x;
y.* += 1;
@@ -350,7 +350,7 @@ fn testTakeAddressOfParameter(f: f32) void {
}
test "pointer comparison" {
- const a = ([]const u8)("a");
+ const a = @as([]const u8, "a");
const b = &a;
expect(ptrEql(b, b));
}
@@ -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 {
@@ -642,7 +642,7 @@ test "self reference through fn ptr field" {
test "volatile load and store" {
var number: i32 = 1234;
- const ptr = (*volatile i32)(&number);
+ const ptr = @as(*volatile i32, &number);
ptr.* += 1;
expect(ptr.* == 1235);
}
@@ -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 044864cedee2..884a7bdb6d32 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 6275be7a0190..0613df94d9ad 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 a8daf6557a54..1985c8dc76ab 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 b86b38beaf53..c0eb4a8f9b76 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 ede31c0162e2..76ecad6b4301 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 936dbed786f7..1a18a5c44006 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 9c700f6260ae..9e93183c3b63 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 aafce2990cc8..ed64e3e43006 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 40adf601c454..40af5c4fd451 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 191893ff8bd9..19df43648162 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 f747f7c1843e..f7b98b294f81 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 19e879d1570d..80df9fe4f943 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 58ff713c23e7..0d0ef3a69f8f 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 84a9c979cd2c..2bb0f3348771 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 a79d12fbfb76..17b089d1dbac 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);
\\}
);
@@ -144,7 +144,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub extern fn foo() void;
\\pub fn bar() void {
\\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
- \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, c_ulong(@ptrToInt(func_ptr)));
+ \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr)));
\\}
);
@@ -561,43 +561,43 @@ 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",
\\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
,
- \\pub const SDL_INIT_VIDEO = c_long(32);
+ \\pub const SDL_INIT_VIDEO = @as(c_long, 32);
);
cases.add("ul integer suffix after hex literal",
\\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
,
- \\pub const SDL_INIT_VIDEO = c_ulong(32);
+ \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
);
cases.add("lu integer suffix after hex literal",
\\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
,
- \\pub const SDL_INIT_VIDEO = c_ulong(32);
+ \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
);
cases.add("ll integer suffix after hex literal",
\\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
,
- \\pub const SDL_INIT_VIDEO = c_longlong(32);
+ \\pub const SDL_INIT_VIDEO = @as(c_longlong, 32);
);
cases.add("ull integer suffix after hex literal",
\\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
,
- \\pub const SDL_INIT_VIDEO = c_ulonglong(32);
+ \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
);
cases.add("llu integer suffix after hex literal",
\\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
,
- \\pub const SDL_INIT_VIDEO = c_ulonglong(32);
+ \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
);
cases.add("zig keywords in C code",
@@ -676,8 +676,8 @@ 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)) {
- \\ a >>= @import("std").math.Log2Int(c_uint)(1);
+ \\ while (a > @as(c_uint, 0)) {
+ \\ a >>= @as(@import("std").math.Log2Int(c_uint), 1);
\\ }
\\ return i;
\\}
@@ -848,8 +848,8 @@ 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)) {
- \\ a >>= u5(1);
+ \\ while (a > @as(c_uint, 0)) {
+ \\ a >>= @as(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);
\\}
);
@@ -1027,7 +1027,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\}
,
\\pub export fn foo() c_int {
- \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1);
+ \\ return (1 << @as(@import("std").math.Log2Int(c_int), 2)) >> @as(@import("std").math.Log2Int(c_int), 1);
\\}
);
@@ -1076,14 +1076,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ _ref.* = (_ref.* ^ 1);
\\ break :x _ref.*;
\\ });
- \\ a >>= @import("std").math.Log2Int(c_int)((x: {
+ \\ a >>= @as(@import("std").math.Log2Int(c_int), (x: {
\\ const _ref = &a;
- \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_int)(1));
+ \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_int), 1));
\\ break :x _ref.*;
\\ }));
- \\ a <<= @import("std").math.Log2Int(c_int)((x: {
+ \\ a <<= @as(@import("std").math.Log2Int(c_int), (x: {
\\ const _ref = &a;
- \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_int)(1));
+ \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_int), 1));
\\ break :x _ref.*;
\\ }));
\\}
@@ -1103,45 +1103,45 @@ 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: {
+ \\ a >>= @as(@import("std").math.Log2Int(c_uint), (x: {
\\ const _ref = &a;
- \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_uint)(1));
+ \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_uint), 1));
\\ break :x _ref.*;
\\ }));
- \\ a <<= @import("std").math.Log2Int(c_uint)((x: {
+ \\ a <<= @as(@import("std").math.Log2Int(c_uint), (x: {
\\ const _ref = &a;
- \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_uint)(1));
+ \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_uint), 1));
\\ break :x _ref.*;
\\ }));
\\}
@@ -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;
@@ -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)
,
- \\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 ([*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",
@@ -1564,7 +1564,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ if (a != 0) return 0;
\\ if (b != 0) return 1;
\\ if (c != null) return 2;
- \\ if (d != @bitCast(enum_SomeEnum, @TagType(enum_SomeEnum)(0))) return 3;
+ \\ if (d != @bitCast(enum_SomeEnum, @as(@TagType(enum_SomeEnum), 0))) return 3;
\\ return 4;
\\}
);
@@ -1646,49 +1646,49 @@ 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(
"l integer suffix after 0 (zero) in macro definition",
"#define ZERO 0L",
- "pub const ZERO = c_long(0);",
+ "pub const ZERO = @as(c_long, 0);",
);
cases.addC(
"ul integer suffix after 0 (zero) in macro definition",
"#define ZERO 0UL",
- "pub const ZERO = c_ulong(0);",
+ "pub const ZERO = @as(c_ulong, 0);",
);
cases.addC(
"lu integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LU",
- "pub const ZERO = c_ulong(0);",
+ "pub const ZERO = @as(c_ulong, 0);",
);
cases.addC(
"ll integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LL",
- "pub const ZERO = c_longlong(0);",
+ "pub const ZERO = @as(c_longlong, 0);",
);
cases.addC(
"ull integer suffix after 0 (zero) in macro definition",
"#define ZERO 0ULL",
- "pub const ZERO = c_ulonglong(0);",
+ "pub const ZERO = @as(c_ulonglong, 0);",
);
cases.addC(
"llu integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LLU",
- "pub const ZERO = c_ulonglong(0);",
+ "pub const ZERO = @as(c_ulonglong, 0);",
);
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\"";
\\}
\\