authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-08 18:30:07-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-11-08 18:30:07-05:00
log6d5abf87ecd3509c6fb8b9c917b73b4db2ae59ff
treefcf1f309750159e579bdf99e2f7646c3bbd8a1a9
parent6d28b28ccc689e6bf8849b1d39e969e8da760999
parentf7b1e02158550a8df3c189299da88568b381f5b1
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3628 from ziglang/as-builtin

implement `@as` builtin and fix result location semantics with regards to type coercion

221 files changed, 1852 insertions(+), 1705 deletions(-)

build.zig+1-1
......@@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
155155 ) catch unreachable;
156156 for (dep.system_libs.toSliceConst()) |lib| {
157157 const static_bare_name = if (mem.eql(u8, lib, "curses"))
158 ([]const u8)("libncurses.a")
158 @as([]const u8, "libncurses.a")
159159 else
160160 b.fmt("lib{}.a", lib);
161161 const static_lib_name = fs.path.join(
doc/docgen.zig+2-2
......@@ -10,8 +10,8 @@ const testing = std.testing;
1010
1111const max_doc_file_size = 10 * 1024 * 1024;
1212
13const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
14const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
13const exe_ext = @as(std.build.Target, std.build.Target.Native).exeFileExt();
14const obj_ext = @as(std.build.Target, std.build.Target.Native).oFileExt();
1515const tmp_dir_name = "docgen_tmp";
1616const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
1717
doc/langref.html.in+78-70
......@@ -712,7 +712,7 @@ test "init with undefined" {
712712}
713713 {#code_end#}
714714 <p>
715 {#syntax#}undefined{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to any type.
715 {#syntax#}undefined{#endsyntax#} can be {#link|coerced|Type Coercion#} to any type.
716716 Once this happens, it is no longer possible to detect that the value is {#syntax#}undefined{#endsyntax#}.
717717 {#syntax#}undefined{#endsyntax#} means the value could be anything, even something that is nonsense
718718 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 {
920920 {#syntax#}f128{#endsyntax#}.
921921 </p>
922922 <p>
923 Float literals {#link|implicitly cast|Implicit Casts#} to any floating point type,
923 Float literals {#link|coerce|Type Coercion#} to any floating point type,
924924 and to any {#link|integer|Integers#} type when there is no fractional component.
925925 </p>
926926 {#code_begin|syntax#}
......@@ -950,7 +950,7 @@ const nan = std.math.nan(f128);
950950 {#code_begin|obj|foo#}
951951 {#code_release_fast#}
952952const builtin = @import("builtin");
953const big = f64(1 << 40);
953const big = @as(f64, 1 << 40);
954954
955955export fn foo_strict(x: f64) f64 {
956956 return x + big - big;
......@@ -1652,7 +1652,7 @@ test "iterate over an array" {
16521652 for (message) |byte| {
16531653 sum += byte;
16541654 }
1655 assert(sum == usize('h') + usize('e') + usize('l') * 2 + usize('o'));
1655 assert(sum == 'h' + 'e' + 'l' * 2 + 'o');
16561656}
16571657
16581658// modifiable array
......@@ -2003,7 +2003,7 @@ test "variable alignment" {
20032003 }
20042004}
20052005 {#code_end#}
2006 <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to a
2006 <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|coerced|Type Coercion#} to a
20072007 {#syntax#}*const i32{#endsyntax#}, a pointer with a larger alignment can be implicitly
20082008 cast to a pointer with a smaller alignment, but not vice versa.
20092009 </p>
......@@ -2019,7 +2019,7 @@ var foo: u8 align(4) = 100;
20192019test "global variable alignment" {
20202020 assert(@typeOf(&foo).alignment == 4);
20212021 assert(@typeOf(&foo) == *align(4) u8);
2022 const slice = (*[1]u8)(&foo)[0..];
2022 const slice = @as(*[1]u8, &foo)[0..];
20232023 assert(@typeOf(slice) == []align(4) u8);
20242024}
20252025
......@@ -2114,7 +2114,7 @@ const fmt = @import("std").fmt;
21142114test "using slices for strings" {
21152115 // Zig has no concept of strings. String literals are arrays of u8, and
21162116 // in general the string type is []u8 (slice of u8).
2117 // Here we implicitly cast [5]u8 to []const u8
2117 // Here we coerce [5]u8 to []const u8
21182118 const hello: []const u8 = "hello";
21192119 const world: []const u8 = "世界";
21202120
......@@ -2778,7 +2778,7 @@ test "simple union" {
27782778 This turns the union into a <em>tagged</em> union, which makes it eligible
27792779 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to
27802780 obtain the enum type from the union type.
2781 Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}
2781 Tagged unions coerce to their enum {#link|Type Coercion: unions and enums#}
27822782 </p>
27832783 {#code_begin|test#}
27842784const std = @import("std");
......@@ -2795,7 +2795,7 @@ const ComplexType = union(ComplexTypeTag) {
27952795
27962796test "switch on tagged union" {
27972797 const c = ComplexType{ .Ok = 42 };
2798 assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
2798 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
27992799
28002800 switch (c) {
28012801 ComplexTypeTag.Ok => |value| assert(value == 42),
......@@ -2807,7 +2807,7 @@ test "@TagType" {
28072807 assert(@TagType(ComplexType) == ComplexTypeTag);
28082808}
28092809
2810test "implicit cast to enum" {
2810test "coerce to enum" {
28112811 const c1 = ComplexType{ .Ok = 42 };
28122812 const c2 = ComplexType.NotOk;
28132813
......@@ -2833,7 +2833,7 @@ const ComplexType = union(ComplexTypeTag) {
28332833
28342834test "modify tagged union in switch" {
28352835 var c = ComplexType{ .Ok = 42 };
2836 assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
2836 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
28372837
28382838 switch (c) {
28392839 ComplexTypeTag.Ok => |*value| value.* += 1,
......@@ -3943,7 +3943,7 @@ test "fn reflection" {
39433943 However right now it is hard coded to be a {#syntax#}u16{#endsyntax#}. See <a href="https://github.com/ziglang/zig/issues/786">#768</a>.
39443944 </p>
39453945 <p>
3946 You can {#link|implicitly cast|Implicit Casts#} an error from a subset to a superset:
3946 You can {#link|coerce|Type Coercion#} an error from a subset to a superset:
39473947 </p>
39483948 {#code_begin|test#}
39493949const std = @import("std");
......@@ -3958,7 +3958,7 @@ const AllocationError = error {
39583958 OutOfMemory,
39593959};
39603960
3961test "implicit cast subset to superset" {
3961test "coerce subset to superset" {
39623962 const err = foo(AllocationError.OutOfMemory);
39633963 std.debug.assert(err == FileOpenError.OutOfMemory);
39643964}
......@@ -3968,7 +3968,7 @@ fn foo(err: AllocationError) FileOpenError {
39683968}
39693969 {#code_end#}
39703970 <p>
3971 But you cannot implicitly cast an error from a superset to a subset:
3971 But you cannot {#link|coerce|Type Coercion#} an error from a superset to a subset:
39723972 </p>
39733973 {#code_begin|test_err|not a member of destination error set#}
39743974const FileOpenError = error {
......@@ -3981,7 +3981,7 @@ const AllocationError = error {
39813981 OutOfMemory,
39823982};
39833983
3984test "implicit cast superset to subset" {
3984test "coerce superset to subset" {
39853985 foo(FileOpenError.OutOfMemory) catch {};
39863986}
39873987
......@@ -4008,7 +4008,7 @@ const err = (error {FileNotFound}).FileNotFound;
40084008 It is a superset of all other error sets and a subset of none of them.
40094009 </p>
40104010 <p>
4011 You can implicitly cast any error set to the global one, and you can explicitly
4011 You can {#link|coerce|Type Coercion#} any error set to the global one, and you can explicitly
40124012 cast an error of the global error set to a non-global one. This inserts a language-level
40134013 assert to make sure the error value is in fact in the destination error set.
40144014 </p>
......@@ -4079,7 +4079,7 @@ test "parse u64" {
40794079 <p>
40804080 Within the function definition, you can see some return statements that return
40814081 an error, and at the bottom a return statement that returns a {#syntax#}u64{#endsyntax#}.
4082 Both types {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyerror!u64{#endsyntax#}.
4082 Both types {#link|coerce|Type Coercion#} to {#syntax#}anyerror!u64{#endsyntax#}.
40834083 </p>
40844084 <p>
40854085 What it looks like to use this function varies depending on what you're
......@@ -4218,10 +4218,10 @@ const assert = @import("std").debug.assert;
42184218test "error union" {
42194219 var foo: anyerror!i32 = undefined;
42204220
4221 // Implicitly cast from child type of an error union:
4221 // Coerce from child type of an error union:
42224222 foo = 1234;
42234223
4224 // Implicitly cast from an error set:
4224 // Coerce from an error set:
42254225 foo = error.SomeError;
42264226
42274227 // Use compile-time reflection to access the payload type of an error union:
......@@ -4598,10 +4598,10 @@ fn doAThing(optional_foo: ?*Foo) void {
45984598const assert = @import("std").debug.assert;
45994599
46004600test "optional type" {
4601 // Declare an optional and implicitly cast from null:
4601 // Declare an optional and coerce from null:
46024602 var foo: ?i32 = null;
46034603
4604 // Implicitly cast from child type of an optional
4604 // Coerce from child type of an optional
46054605 foo = 1234;
46064606
46074607 // Use compile-time reflection to access the child type of the optional:
......@@ -4644,38 +4644,38 @@ test "optional pointers" {
46444644 {#header_open|Casting#}
46454645 <p>
46464646 A <strong>type cast</strong> converts a value of one type to another.
4647 Zig has {#link|Implicit Casts#} for conversions that are known to be completely safe and unambiguous,
4647 Zig has {#link|Type Coercion#} for conversions that are known to be completely safe and unambiguous,
46484648 and {#link|Explicit Casts#} for conversions that one would not want to happen on accident.
46494649 There is also a third kind of type conversion called {#link|Peer Type Resolution#} for
46504650 the case when a result type must be decided given multiple operand types.
46514651 </p>
4652 {#header_open|Implicit Casts#}
4652 {#header_open|Type Coercion#}
46534653 <p>
4654 An implicit cast occurs when one type is expected, but different type is provided:
4654 Type coercion occurs when one type is expected, but different type is provided:
46554655 </p>
46564656 {#code_begin|test#}
4657test "implicit cast - variable declaration" {
4657test "type coercion - variable declaration" {
46584658 var a: u8 = 1;
46594659 var b: u16 = a;
46604660}
46614661
4662test "implicit cast - function call" {
4662test "type coercion - function call" {
46634663 var a: u8 = 1;
46644664 foo(a);
46654665}
46664666
46674667fn foo(b: u16) void {}
46684668
4669test "implicit cast - invoke a type as a function" {
4669test "type coercion - @as builtin" {
46704670 var a: u8 = 1;
4671 var b = u16(a);
4671 var b = @as(u16, a);
46724672}
46734673 {#code_end#}
46744674 <p>
4675 Implicit casts are only allowed when it is completely unambiguous how to get from one type to another,
4675 Type coercions are only allowed when it is completely unambiguous how to get from one type to another,
46764676 and the transformation is guaranteed to be safe. There is one exception, which is {#link|C Pointers#}.
46774677 </p>
4678 {#header_open|Implicit Cast: Stricter Qualification#}
4678 {#header_open|Type Coercion: Stricter Qualification#}
46794679 <p>
46804680 Values which have the same representation at runtime can be cast to increase the strictness
46814681 of the qualifiers, no matter how nested the qualifiers are:
......@@ -4690,7 +4690,7 @@ test "implicit cast - invoke a type as a function" {
46904690 These casts are no-ops at runtime since the value representation does not change.
46914691 </p>
46924692 {#code_begin|test#}
4693test "implicit cast - const qualification" {
4693test "type coercion - const qualification" {
46944694 var a: i32 = 1;
46954695 var b: *i32 = &a;
46964696 foo(b);
......@@ -4699,7 +4699,7 @@ test "implicit cast - const qualification" {
46994699fn foo(a: *const i32) void {}
47004700 {#code_end#}
47014701 <p>
4702 In addition, pointers implicitly cast to const optional pointers:
4702 In addition, pointers coerce to const optional pointers:
47034703 </p>
47044704 {#code_begin|test#}
47054705const std = @import("std");
......@@ -4713,10 +4713,10 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
47134713}
47144714 {#code_end#}
47154715 {#header_close#}
4716 {#header_open|Implicit Cast: Integer and Float Widening#}
4716 {#header_open|Type Coercion: Integer and Float Widening#}
47174717 <p>
4718 {#link|Integers#} implicitly cast to integer types which can represent every value of the old type, and likewise
4719 {#link|Floats#} implicitly cast to float types which can represent every value of the old type.
4718 {#link|Integers#} coerce to integer types which can represent every value of the old type, and likewise
4719 {#link|Floats#} coerce to float types which can represent every value of the old type.
47204720 </p>
47214721 {#code_begin|test#}
47224722const std = @import("std");
......@@ -4748,7 +4748,7 @@ test "float widening" {
47484748}
47494749 {#code_end#}
47504750 {#header_close#}
4751 {#header_open|Implicit Cast: Arrays and Pointers#}
4751 {#header_open|Type Coercion: Arrays and Pointers#}
47524752 {#code_begin|test#}
47534753const std = @import("std");
47544754const assert = std.debug.assert;
......@@ -4797,7 +4797,7 @@ test "*[N]T to []T" {
47974797 assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 }));
47984798}
47994799
4800// Single-item pointers to arrays can be implicitly casted to
4800// Single-item pointers to arrays can be coerced to
48014801// unknown length pointers.
48024802test "*[N]T to [*]T" {
48034803 var buf: [5]u8 = "hello";
......@@ -4823,15 +4823,15 @@ test "*T to *[1]T" {
48234823 {#code_end#}
48244824 {#see_also|C Pointers#}
48254825 {#header_close#}
4826 {#header_open|Implicit Cast: Optionals#}
4826 {#header_open|Type Coercion: Optionals#}
48274827 <p>
4828 The payload type of {#link|Optionals#}, as well as {#link|null#}, implicitly cast to the optional type.
4828 The payload type of {#link|Optionals#}, as well as {#link|null#}, coerce to the optional type.
48294829 </p>
48304830 {#code_begin|test#}
48314831const std = @import("std");
48324832const assert = std.debug.assert;
48334833
4834test "implicit casting to optionals" {
4834test "coerce to optionals" {
48354835 const x: ?i32 = 1234;
48364836 const y: ?i32 = null;
48374837
......@@ -4844,7 +4844,7 @@ test "implicit casting to optionals" {
48444844const std = @import("std");
48454845const assert = std.debug.assert;
48464846
4847test "implicit casting to optionals wrapped in error union" {
4847test "coerce to optionals wrapped in error union" {
48484848 const x: anyerror!?i32 = 1234;
48494849 const y: anyerror!?i32 = null;
48504850
......@@ -4853,15 +4853,15 @@ test "implicit casting to optionals wrapped in error union" {
48534853}
48544854 {#code_end#}
48554855 {#header_close#}
4856 {#header_open|Implicit Cast: Error Unions#}
4856 {#header_open|Type Coercion: Error Unions#}
48574857 <p>The payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#}
4858 implicitly cast to the error union type:
4858 coerce to the error union type:
48594859 </p>
48604860 {#code_begin|test#}
48614861const std = @import("std");
48624862const assert = std.debug.assert;
48634863
4864test "implicit casting to error unions" {
4864test "coercion to error unions" {
48654865 const x: anyerror!i32 = 1234;
48664866 const y: anyerror!i32 = error.Failure;
48674867
......@@ -4870,23 +4870,23 @@ test "implicit casting to error unions" {
48704870}
48714871 {#code_end#}
48724872 {#header_close#}
4873 {#header_open|Implicit Cast: Compile-Time Known Numbers#}
4873 {#header_open|Type Coercion: Compile-Time Known Numbers#}
48744874 <p>When a number is {#link|comptime#}-known to be representable in the destination type,
4875 it may be implicitly casted:
4875 it may be coerced:
48764876 </p>
48774877 {#code_begin|test#}
48784878const std = @import("std");
48794879const assert = std.debug.assert;
48804880
4881test "implicit casting large integer type to smaller one when value is comptime known to fit" {
4881test "coercing large integer type to smaller one when value is comptime known to fit" {
48824882 const x: u64 = 255;
48834883 const y: u8 = x;
48844884 assert(y == 255);
48854885}
48864886 {#code_end#}
48874887 {#header_close#}
4888 {#header_open|Implicit Cast: unions and enums#}
4889 <p>Tagged unions can be implicitly cast to enums, and enums can be implicitly casted to tagged unions
4888 {#header_open|Type Coercion: unions and enums#}
4889 <p>Tagged unions can be coerced to enums, and enums can be coerced to tagged unions
48904890 when they are {#link|comptime#}-known to be a field of the union that has only one possible value, such as
48914891 {#link|void#}:
48924892 </p>
......@@ -4906,7 +4906,7 @@ const U = union(E) {
49064906 Three,
49074907};
49084908
4909test "implicit casting between unions and enums" {
4909test "coercion between unions and enums" {
49104910 var u = U{ .Two = 12.34 };
49114911 var e: E = u;
49124912 assert(e == E.Two);
......@@ -4918,20 +4918,20 @@ test "implicit casting between unions and enums" {
49184918 {#code_end#}
49194919 {#see_also|union|enum#}
49204920 {#header_close#}
4921 {#header_open|Implicit Cast: Zero Bit Types#}
4922 <p>{#link|Zero Bit Types#} may be implicitly casted to single-item {#link|Pointers#},
4921 {#header_open|Type Coercion: Zero Bit Types#}
4922 <p>{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#},
49234923 regardless of const.</p>
49244924 <p>TODO document the reasoning for this</p>
49254925 <p>TODO document whether vice versa should work and why</p>
49264926 {#code_begin|test#}
4927test "implicit casting of zero bit types" {
4927test "coercion of zero bit types" {
49284928 var x: void = {};
49294929 var y: *void = x;
49304930 //var z: void = y; // TODO
49314931}
49324932 {#code_end#}
49334933 {#header_close#}
4934 {#header_open|Implicit Cast: undefined#}
4934 {#header_open|Type Coercion: undefined#}
49354935 <p>{#link|undefined#} can be cast to any type.</p>
49364936 {#header_close#}
49374937 {#header_close#}
......@@ -4976,7 +4976,7 @@ test "implicit casting of zero bit types" {
49764976 <li>Some {#link|binary operations|Table of Operators#}</li>
49774977 </ul>
49784978 <p>
4979 This kind of type resolution chooses a type that all peer types can implicitly cast into. Here are
4979 This kind of type resolution chooses a type that all peer types can coerce into. Here are
49804980 some examples:
49814981 </p>
49824982 {#code_begin|test#}
......@@ -5007,8 +5007,8 @@ test "peer resolve array and const slice" {
50075007 comptime testPeerResolveArrayConstSlice(true);
50085008}
50095009fn testPeerResolveArrayConstSlice(b: bool) void {
5010 const value1 = if (b) "aoeu" else ([]const u8)("zz");
5011 const value2 = if (b) ([]const u8)("zz") else "aoeu";
5010 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
5011 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
50125012 assert(mem.eql(u8, value1, "aoeu"));
50135013 assert(mem.eql(u8, value2, "zz"));
50145014}
......@@ -5023,10 +5023,10 @@ test "peer type resolution: ?T and T" {
50235023}
50245024fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
50255025 if (c) {
5026 return if (b) null else usize(0);
5026 return if (b) null else @as(usize, 0);
50275027 }
50285028
5029 return usize(3);
5029 return @as(usize, 3);
50305030}
50315031
50325032test "peer type resolution: [0]u8 and []const u8" {
......@@ -5815,7 +5815,7 @@ test "printf too many arguments" {
58155815 </p>
58165816 <p>
58175817 Zig doesn't care whether the format argument is a string literal,
5818 only that it is a compile-time known value that is implicitly castable to a {#syntax#}[]const u8{#endsyntax#}:
5818 only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}:
58195819 </p>
58205820 {#code_begin|exe|printf#}
58215821const warn = @import("std").debug.warn;
......@@ -6185,7 +6185,7 @@ fn func() void {
61856185 </p>
61866186 <p>
61876187 {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that
6188 implicitly casts to {#syntax#}anyframe->T{#endsyntax#}.
6188 coerces to {#syntax#}anyframe->T{#endsyntax#}.
61896189 </p>
61906190 <p>
61916191 There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function.
......@@ -6445,6 +6445,14 @@ comptime {
64456445 </p>
64466446 {#header_close#}
64476447
6448 {#header_open|@as#}
6449 <pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre>
6450 <p>
6451 Performs {#link|Type Coercion#}. This cast is allowed when the conversion is unambiguous and safe,
6452 and is the preferred way to convert between types, whenever possible.
6453 </p>
6454 {#header_close#}
6455
64486456 {#header_open|@asyncCall#}
64496457 <pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: ...) anyframe->T{#endsyntax#}</pre>
64506458 <p>
......@@ -7108,7 +7116,7 @@ test "field access by string" {
71087116 <pre>{#syntax#}@frame() *@Frame(func){#endsyntax#}</pre>
71097117 <p>
71107118 This function returns a pointer to the frame for a given function. This type
7111 can be {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyframe->T{#endsyntax#} and
7119 can be {#link|coerced|Type Coercion#} to {#syntax#}anyframe->T{#endsyntax#} and
71127120 to {#syntax#}anyframe{#endsyntax#}, where {#syntax#}T{#endsyntax#} is the return type
71137121 of the function in scope.
71147122 </p>
......@@ -7827,7 +7835,7 @@ test "vector @splat" {
78277835 const scalar: u32 = 5;
78287836 const result = @splat(4, scalar);
78297837 comptime assert(@typeOf(result) == @Vector(4, u32));
7830 assert(std.mem.eql(u32, ([4]u32)(result), [_]u32{ 5, 5, 5, 5 }));
7838 assert(std.mem.eql(u32, @as([4]u32, result), [_]u32{ 5, 5, 5, 5 }));
78317839}
78327840 {#code_end#}
78337841 <p>
......@@ -8025,7 +8033,7 @@ test "integer truncation" {
80258033 </p>
80268034 <p>
80278035 If {#syntax#}T{#endsyntax#} is {#syntax#}comptime_int{#endsyntax#},
8028 then this is semantically equivalent to an {#link|implicit cast|Implicit Casts#}.
8036 then this is semantically equivalent to {#link|Type Coercion#}.
80298037 </p>
80308038 {#header_close#}
80318039
......@@ -8529,7 +8537,7 @@ pub fn main() void {
85298537 {#header_close#}
85308538 {#header_open|Cast Truncates Data#}
85318539 <p>At compile-time:</p>
8532 {#code_begin|test_err|integer value 300 cannot be implicitly casted to type 'u8'#}
8540 {#code_begin|test_err|integer value 300 cannot be coerced to type 'u8'#}
85338541comptime {
85348542 const spartan_count: u16 = 300;
85358543 const byte = @intCast(u8, spartan_count);
......@@ -8665,7 +8673,7 @@ test "wraparound addition and subtraction" {
86658673 <p>At compile-time:</p>
86668674 {#code_begin|test_err|operation caused overflow#}
86678675comptime {
8668 const x = @shlExact(u8(0b01010101), 2);
8676 const x = @shlExact(@as(u8, 0b01010101), 2);
86698677}
86708678 {#code_end#}
86718679 <p>At runtime:</p>
......@@ -8683,7 +8691,7 @@ pub fn main() void {
86838691 <p>At compile-time:</p>
86848692 {#code_begin|test_err|exact shift shifted out 1 bits#}
86858693comptime {
8686 const x = @shrExact(u8(0b10101010), 2);
8694 const x = @shrExact(@as(u8, 0b10101010), 2);
86878695}
86888696 {#code_end#}
86898697 <p>At runtime:</p>
......@@ -9535,8 +9543,8 @@ const c = @cImport({
95359543 <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p>
95369544 <ul>
95379545 <li>Supports all the syntax of the other two pointer types.</li>
9538 <li>Implicitly casts to other pointer types, as well as {#link|Optional Pointers#}.
9539 When a C pointer is implicitly casted to a non-optional pointer, safety-checked
9546 <li>Coerces to other pointer types, as well as {#link|Optional Pointers#}.
9547 When a C pointer is coerced to a non-optional pointer, safety-checked
95409548 {#link|Undefined Behavior#} occurs if the address is 0.
95419549 </li>
95429550 <li>Allows address 0. On non-freestanding targets, dereferencing address 0 is safety-checked
......@@ -9544,7 +9552,7 @@ const c = @cImport({
95449552 null, just like {#syntax#}?usize{#endsyntax#}. Note that creating an optional C pointer
95459553 is unnecessary as one can use normal {#link|Optional Pointers#}.
95469554 </li>
9547 <li>Supports {#link|implicit casting|Implicit Casts#} to and from integers.</li>
9555 <li>Supports {#link|Type Coercion#} to and from integers.</li>
95489556 <li>Supports comparison with integers.</li>
95499557 <li>Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#}
95509558 please!</li>
lib/std/array_list.zig+8-8
......@@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" {
344344 try list.append(7);
345345
346346 //remove from middle
347 testing.expectEqual(i32(4), list.orderedRemove(3));
348 testing.expectEqual(i32(5), list.at(3));
349 testing.expectEqual(usize(6), list.len);
347 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
348 testing.expectEqual(@as(i32, 5), list.at(3));
349 testing.expectEqual(@as(usize, 6), list.len);
350350
351351 //remove from end
352 testing.expectEqual(i32(7), list.orderedRemove(5));
353 testing.expectEqual(usize(5), list.len);
352 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
353 testing.expectEqual(@as(usize, 5), list.len);
354354
355355 //remove from front
356 testing.expectEqual(i32(1), list.orderedRemove(0));
357 testing.expectEqual(i32(2), list.at(0));
358 testing.expectEqual(usize(4), list.len);
356 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
357 testing.expectEqual(@as(i32, 2), list.at(0));
358 testing.expectEqual(@as(usize, 4), list.len);
359359}
360360
361361test "std.ArrayList.swapRemove" {
lib/std/ascii.zig+11-11
......@@ -129,26 +129,26 @@ const combinedTable = init: {
129129 comptime var i = 0;
130130 inline while (i < 128) : (i += 1) {
131131 table[i] =
132 u8(alpha[i]) << @enumToInt(tIndex.Alpha) |
133 u8(hex[i]) << @enumToInt(tIndex.Hex) |
134 u8(space[i]) << @enumToInt(tIndex.Space) |
135 u8(digit[i]) << @enumToInt(tIndex.Digit) |
136 u8(lower[i]) << @enumToInt(tIndex.Lower) |
137 u8(upper[i]) << @enumToInt(tIndex.Upper) |
138 u8(punct[i]) << @enumToInt(tIndex.Punct) |
139 u8(graph[i]) << @enumToInt(tIndex.Graph);
132 @as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) |
133 @as(u8, hex[i]) << @enumToInt(tIndex.Hex) |
134 @as(u8, space[i]) << @enumToInt(tIndex.Space) |
135 @as(u8, digit[i]) << @enumToInt(tIndex.Digit) |
136 @as(u8, lower[i]) << @enumToInt(tIndex.Lower) |
137 @as(u8, upper[i]) << @enumToInt(tIndex.Upper) |
138 @as(u8, punct[i]) << @enumToInt(tIndex.Punct) |
139 @as(u8, graph[i]) << @enumToInt(tIndex.Graph);
140140 }
141141 mem.set(u8, table[128..256], 0);
142142 break :init table;
143143};
144144
145145fn inTable(c: u8, t: tIndex) bool {
146 return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0;
146 return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
147147}
148148
149149pub fn isAlNum(c: u8) bool {
150 return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) |
151 u8(1) << @enumToInt(tIndex.Digit))) != 0;
150 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
151 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
152152}
153153
154154pub fn isAlpha(c: u8) bool {
lib/std/atomic/queue.zig+2-2
......@@ -214,8 +214,8 @@ test "std.atomic.Queue" {
214214 std.debug.panic(
215215 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
216216 context.get_count,
217 u32(puts_per_thread),
218 u32(put_thread_count),
217 @as(u32, puts_per_thread),
218 @as(u32, put_thread_count),
219219 );
220220 }
221221}
lib/std/atomic/stack.zig+3-3
......@@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type {
1111 root: ?*Node,
1212 lock: @typeOf(lock_init),
1313
14 const lock_init = if (builtin.single_threaded) {} else u8(0);
14 const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);
1515
1616 pub const Self = @This();
1717
......@@ -141,8 +141,8 @@ test "std.atomic.stack" {
141141 std.debug.panic(
142142 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
143143 context.get_count,
144 u32(puts_per_thread),
145 u32(put_thread_count),
144 @as(u32, puts_per_thread),
145 @as(u32, put_thread_count),
146146 );
147147 }
148148}
lib/std/bloom_filter.zig+11-11
......@@ -28,7 +28,7 @@ pub fn BloomFilter(
2828 assert(n_items > 0);
2929 assert(math.isPowerOfTwo(n_items));
3030 assert(K > 0);
31 const cellEmpty = if (Cell == bool) false else Cell(0);
31 const cellEmpty = if (Cell == bool) false else @as(Cell, 0);
3232 const cellMax = if (Cell == bool) true else math.maxInt(Cell);
3333 const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8;
3434 assert(n_bytes > 0);
......@@ -137,7 +137,7 @@ pub fn BloomFilter(
137137 var i: usize = 0;
138138 while (i < n_items) : (i += 1) {
139139 const cell = self.getCell(@intCast(Index, i));
140 n += if (if (Cell == bool) cell else cell > 0) Index(1) else Index(0);
140 n += if (if (Cell == bool) cell else cell > 0) @as(Index, 1) else @as(Index, 0);
141141 }
142142 }
143143 return n;
......@@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void {
161161
162162test "std.BloomFilter" {
163163 inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| {
164 const emptyCell = if (Cell == bool) false else Cell(0);
164 const emptyCell = if (Cell == bool) false else @as(Cell, 0);
165165 const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc);
166166 var bf = BF{};
167167 var i: usize = undefined;
......@@ -170,8 +170,8 @@ test "std.BloomFilter" {
170170 while (i < BF.items) : (i += 1) {
171171 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
172172 }
173 testing.expectEqual(BF.Index(0), bf.popCount());
174 testing.expectEqual(f64(0), bf.estimateItems());
173 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
174 testing.expectEqual(@as(f64, 0), bf.estimateItems());
175175 // fill in a few items
176176 bf.incrementCell(42);
177177 bf.incrementCell(255);
......@@ -196,8 +196,8 @@ test "std.BloomFilter" {
196196 while (i < BF.items) : (i += 1) {
197197 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
198198 }
199 testing.expectEqual(BF.Index(0), bf.popCount());
200 testing.expectEqual(f64(0), bf.estimateItems());
199 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
200 testing.expectEqual(@as(f64, 0), bf.estimateItems());
201201
202202 // Lets add a string
203203 bf.add("foo");
......@@ -218,8 +218,8 @@ test "std.BloomFilter" {
218218 while (i < BF.items) : (i += 1) {
219219 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
220220 }
221 testing.expectEqual(BF.Index(0), bf.popCount());
222 testing.expectEqual(f64(0), bf.estimateItems());
221 testing.expectEqual(@as(BF.Index, 0), bf.popCount());
222 testing.expectEqual(@as(f64, 0), bf.estimateItems());
223223
224224 comptime var teststrings = [_][]const u8{
225225 "foo",
......@@ -246,12 +246,12 @@ test "std.BloomFilter" {
246246 inline for (teststrings) |str| {
247247 testing.expectEqual(true, larger_bf.contains(str));
248248 }
249 testing.expectEqual(u12(bf.popCount()) * (4096 / 1024), larger_bf.popCount());
249 testing.expectEqual(@as(u12, bf.popCount()) * (4096 / 1024), larger_bf.popCount());
250250
251251 const smaller_bf = bf.resize(64);
252252 inline for (teststrings) |str| {
253253 testing.expectEqual(true, smaller_bf.contains(str));
254254 }
255 testing.expect(bf.popCount() <= u10(smaller_bf.popCount()) * (1024 / 64));
255 testing.expect(bf.popCount() <= @as(u10, smaller_bf.popCount()) * (1024 / 64));
256256 }
257257}
lib/std/c/darwin.zig+1-1
......@@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo
5353pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
5454
5555pub fn sigaddset(set: *sigset_t, signo: u5) void {
56 set.* |= u32(1) << (signo - 1);
56 set.* |= @as(u32, 1) << (signo - 1);
5757}
5858
5959pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
lib/std/child_process.zig+2-2
......@@ -219,7 +219,7 @@ pub const ChildProcess = struct {
219219 fn waitUnwrappedWindows(self: *ChildProcess) !void {
220220 const result = windows.WaitForSingleObject(self.handle, windows.INFINITE);
221221
222 self.term = (SpawnError!Term)(x: {
222 self.term = @as(SpawnError!Term, x: {
223223 var exit_code: windows.DWORD = undefined;
224224 if (windows.kernel32.GetExitCodeProcess(self.handle, &exit_code) == 0) {
225225 break :x Term{ .Unknown = 0 };
......@@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void {
717717// Child of fork calls this to report an error to the fork parent.
718718// Then the child exits.
719719fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
720 writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};
720 writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {};
721721 os.exit(1);
722722}
723723
lib/std/crypto/aes.zig+10-10
......@@ -6,7 +6,7 @@ const testing = std.testing;
66
77// Apply sbox0 to each byte in w.
88fn subw(w: u32) u32 {
9 return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]);
9 return @as(u32, sbox0[w >> 24]) << 24 | @as(u32, sbox0[w >> 16 & 0xff]) << 16 | @as(u32, sbox0[w >> 8 & 0xff]) << 8 | @as(u32, sbox0[w & 0xff]);
1010}
1111
1212fn rotw(w: u32) u32 {
......@@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
4848 }
4949
5050 // Last round uses s-box directly and XORs to produce output.
51 s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]);
52 s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | u32(sbox0[t0 & 0xff]);
53 s2 = u32(sbox0[t2 >> 24]) << 24 | u32(sbox0[t3 >> 16 & 0xff]) << 16 | u32(sbox0[t0 >> 8 & 0xff]) << 8 | u32(sbox0[t1 & 0xff]);
54 s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 0xff]);
51 s0 = @as(u32, sbox0[t0 >> 24]) << 24 | @as(u32, sbox0[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t3 & 0xff]);
52 s1 = @as(u32, sbox0[t1 >> 24]) << 24 | @as(u32, sbox0[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t0 & 0xff]);
53 s2 = @as(u32, sbox0[t2 >> 24]) << 24 | @as(u32, sbox0[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t1 & 0xff]);
54 s3 = @as(u32, sbox0[t3 >> 24]) << 24 | @as(u32, sbox0[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t2 & 0xff]);
5555
5656 s0 ^= xk[k + 0];
5757 s1 ^= xk[k + 1];
......@@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void {
9999 }
100100
101101 // Last round uses s-box directly and XORs to produce output.
102 s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]);
103 s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | u32(sbox1[t2 & 0xff]);
104 s2 = u32(sbox1[t2 >> 24]) << 24 | u32(sbox1[t1 >> 16 & 0xff]) << 16 | u32(sbox1[t0 >> 8 & 0xff]) << 8 | u32(sbox1[t3 & 0xff]);
105 s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 0xff]);
102 s0 = @as(u32, sbox1[t0 >> 24]) << 24 | @as(u32, sbox1[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t1 & 0xff]);
103 s1 = @as(u32, sbox1[t1 >> 24]) << 24 | @as(u32, sbox1[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t2 & 0xff]);
104 s2 = @as(u32, sbox1[t2 >> 24]) << 24 | @as(u32, sbox1[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t3 & 0xff]);
105 s3 = @as(u32, sbox1[t3 >> 24]) << 24 | @as(u32, sbox1[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t0 & 0xff]);
106106
107107 s0 ^= xk[k + 0];
108108 s1 ^= xk[k + 1];
......@@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void {
256256 while (i < enc.len) : (i += 1) {
257257 var t = enc[i - 1];
258258 if (i % nk == 0) {
259 t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24);
259 t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24);
260260 } else if (nk > 6 and i % nk == 4) {
261261 t = subw(t);
262262 }
lib/std/crypto/blake2.zig+8-8
......@@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type {
164164 inline while (j < 10) : (j += 1) {
165165 inline for (rounds) |r| {
166166 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
167 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16));
167 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16));
168168 v[r.c] = v[r.c] +% v[r.d];
169 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12));
169 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12));
170170 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
171 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8));
171 v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8));
172172 v[r.c] = v[r.c] +% v[r.d];
173 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7));
173 v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7));
174174 }
175175 }
176176
......@@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type {
398398 inline while (j < 12) : (j += 1) {
399399 inline for (rounds) |r| {
400400 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]];
401 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32));
401 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32));
402402 v[r.c] = v[r.c] +% v[r.d];
403 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24));
403 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24));
404404 v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]];
405 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16));
405 v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16));
406406 v[r.c] = v[r.c] +% v[r.d];
407 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63));
407 v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63));
408408 }
409409 }
410410
lib/std/crypto/chacha20.zig+4-4
......@@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {
4949 // two-round cycles
5050 inline for (rounds) |r| {
5151 x[r.a] +%= x[r.b];
52 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(16));
52 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 16));
5353 x[r.c] +%= x[r.d];
54 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(12));
54 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 12));
5555 x[r.a] +%= x[r.b];
56 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(8));
56 x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 8));
5757 x[r.c] +%= x[r.d];
58 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(7));
58 x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 7));
5959 }
6060 }
6161
lib/std/crypto/gimli.zig+4-4
......@@ -34,9 +34,9 @@ pub const State = struct {
3434
3535 pub fn permute(self: *Self) void {
3636 const state = &self.data;
37 var round = u32(24);
37 var round = @as(u32, 24);
3838 while (round > 0) : (round -= 1) {
39 var column = usize(0);
39 var column = @as(usize, 0);
4040 while (column < 4) : (column += 1) {
4141 const x = math.rotl(u32, state[column], 24);
4242 const y = math.rotl(u32, state[4 + column], 9);
......@@ -61,7 +61,7 @@ pub const State = struct {
6161 }
6262
6363 pub fn squeeze(self: *Self, out: []u8) void {
64 var i = usize(0);
64 var i = @as(usize, 0);
6565 while (i + RATE <= out.len) : (i += RATE) {
6666 self.permute();
6767 mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]);
......@@ -79,7 +79,7 @@ test "permute" {
7979 var state = State{
8080 .data = blk: {
8181 var input: [12]u32 = undefined;
82 var i = u32(0);
82 var i = @as(u32, 0);
8383 while (i < 12) : (i += 1) {
8484 input[i] = i * i * i + i *% 0x9e3779b9;
8585 }
lib/std/crypto/md5.zig+4-4
......@@ -126,10 +126,10 @@ pub const Md5 = struct {
126126 while (i < 16) : (i += 1) {
127127 // NOTE: Performing or's separately improves perf by ~10%
128128 s[i] = 0;
129 s[i] |= u32(b[i * 4 + 0]);
130 s[i] |= u32(b[i * 4 + 1]) << 8;
131 s[i] |= u32(b[i * 4 + 2]) << 16;
132 s[i] |= u32(b[i * 4 + 3]) << 24;
129 s[i] |= @as(u32, b[i * 4 + 0]);
130 s[i] |= @as(u32, b[i * 4 + 1]) << 8;
131 s[i] |= @as(u32, b[i * 4 + 2]) << 16;
132 s[i] |= @as(u32, b[i * 4 + 3]) << 24;
133133 }
134134
135135 var v: [4]u32 = [_]u32{
lib/std/crypto/poly1305.zig+6-6
......@@ -87,11 +87,11 @@ pub const Poly1305 = struct {
8787 // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff
8888 fn polyBlock(ctx: *Self) void {
8989 // s = h + c, without carry propagation
90 const s0 = u64(ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
91 const s1 = u64(ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
92 const s2 = u64(ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
93 const s3 = u64(ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
94 const s4 = u64(ctx.h[4]) + ctx.c[4]; // s4 <= 5
90 const s0 = @as(u64, ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe
91 const s1 = @as(u64, ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe
92 const s2 = @as(u64, ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe
93 const s3 = @as(u64, ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe
94 const s4 = @as(u64, ctx.h[4]) + ctx.c[4]; // s4 <= 5
9595
9696 // Local all the things!
9797 const r0 = ctx.r[0]; // r0 <= 0fffffff
......@@ -197,7 +197,7 @@ pub const Poly1305 = struct {
197197
198198 // check if we should subtract 2^130-5 by performing the
199199 // corresponding carry propagation.
200 const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004
200 const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004
201201 const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000
202202 const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000
203203 const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000
lib/std/crypto/sha1.zig+15-15
......@@ -146,10 +146,10 @@ pub const Sha1 = struct {
146146 Rp(0, 1, 2, 3, 4, 15),
147147 };
148148 inline for (round0a) |r| {
149 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);
149 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);
150150
151 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]));
152 v[r.b] = math.rotl(u32, v[r.b], u32(30));
151 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]));
152 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
153153 }
154154
155155 const round0b = comptime [_]RoundParam{
......@@ -160,10 +160,10 @@ pub const Sha1 = struct {
160160 };
161161 inline for (round0b) |r| {
162162 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
163 s[r.i & 0xf] = math.rotl(u32, t, u32(1));
163 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
164164
165 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]));
166 v[r.b] = math.rotl(u32, v[r.b], u32(30));
165 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]));
166 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
167167 }
168168
169169 const round1 = comptime [_]RoundParam{
......@@ -190,10 +190,10 @@ pub const Sha1 = struct {
190190 };
191191 inline for (round1) |r| {
192192 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
193 s[r.i & 0xf] = math.rotl(u32, t, u32(1));
193 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
194194
195 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]);
196 v[r.b] = math.rotl(u32, v[r.b], u32(30));
195 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]);
196 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
197197 }
198198
199199 const round2 = comptime [_]RoundParam{
......@@ -220,10 +220,10 @@ pub const Sha1 = struct {
220220 };
221221 inline for (round2) |r| {
222222 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
223 s[r.i & 0xf] = math.rotl(u32, t, u32(1));
223 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
224224
225 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]));
226 v[r.b] = math.rotl(u32, v[r.b], u32(30));
225 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]));
226 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
227227 }
228228
229229 const round3 = comptime [_]RoundParam{
......@@ -250,10 +250,10 @@ pub const Sha1 = struct {
250250 };
251251 inline for (round3) |r| {
252252 const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf];
253 s[r.i & 0xf] = math.rotl(u32, t, u32(1));
253 s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1));
254254
255 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]);
256 v[r.b] = math.rotl(u32, v[r.b], u32(30));
255 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]);
256 v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30));
257257 }
258258
259259 d.s[0] +%= v[0];
lib/std/crypto/sha2.zig+20-18
......@@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type {
180180 var i: usize = 0;
181181 while (i < 16) : (i += 1) {
182182 s[i] = 0;
183 s[i] |= u32(b[i * 4 + 0]) << 24;
184 s[i] |= u32(b[i * 4 + 1]) << 16;
185 s[i] |= u32(b[i * 4 + 2]) << 8;
186 s[i] |= u32(b[i * 4 + 3]) << 0;
183 s[i] |= @as(u32, b[i * 4 + 0]) << 24;
184 s[i] |= @as(u32, b[i * 4 + 1]) << 16;
185 s[i] |= @as(u32, b[i * 4 + 2]) << 8;
186 s[i] |= @as(u32, b[i * 4 + 3]) << 0;
187187 }
188188 while (i < 64) : (i += 1) {
189 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));
189 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));
190190 }
191191
192192 var v: [8]u32 = [_]u32{
......@@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type {
267267 Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2),
268268 };
269269 inline for (round0) |r| {
270 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];
270 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];
271271
272272 v[r.d] = v[r.d] +% v[r.h];
273273
274 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]));
274 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]));
275275 }
276276
277277 d.s[0] +%= v[0];
......@@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type {
522522 var i: usize = 0;
523523 while (i < 16) : (i += 1) {
524524 s[i] = 0;
525 s[i] |= u64(b[i * 8 + 0]) << 56;
526 s[i] |= u64(b[i * 8 + 1]) << 48;
527 s[i] |= u64(b[i * 8 + 2]) << 40;
528 s[i] |= u64(b[i * 8 + 3]) << 32;
529 s[i] |= u64(b[i * 8 + 4]) << 24;
530 s[i] |= u64(b[i * 8 + 5]) << 16;
531 s[i] |= u64(b[i * 8 + 6]) << 8;
532 s[i] |= u64(b[i * 8 + 7]) << 0;
525 s[i] |= @as(u64, b[i * 8 + 0]) << 56;
526 s[i] |= @as(u64, b[i * 8 + 1]) << 48;
527 s[i] |= @as(u64, b[i * 8 + 2]) << 40;
528 s[i] |= @as(u64, b[i * 8 + 3]) << 32;
529 s[i] |= @as(u64, b[i * 8 + 4]) << 24;
530 s[i] |= @as(u64, b[i * 8 + 5]) << 16;
531 s[i] |= @as(u64, b[i * 8 + 6]) << 8;
532 s[i] |= @as(u64, b[i * 8 + 7]) << 0;
533533 }
534534 while (i < 80) : (i += 1) {
535 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));
535 s[i] = s[i - 16] +% s[i - 7] +%
536 (math.rotr(u64, s[i - 15], @as(u64, 1)) ^ math.rotr(u64, s[i - 15], @as(u64, 8)) ^ (s[i - 15] >> 7)) +%
537 (math.rotr(u64, s[i - 2], @as(u64, 19)) ^ math.rotr(u64, s[i - 2], @as(u64, 61)) ^ (s[i - 2] >> 6));
536538 }
537539
538540 var v: [8]u64 = [_]u64{
......@@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type {
629631 Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817),
630632 };
631633 inline for (round0) |r| {
632 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];
634 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];
633635
634636 v[r.d] = v[r.d] +% v[r.h];
635637
636 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]));
638 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]));
637639 }
638640
639641 d.s[0] +%= v[0];
lib/std/crypto/sha3.zig+1-1
......@@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
133133 }
134134 x = 0;
135135 inline while (x < 5) : (x += 1) {
136 t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], usize(1));
136 t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], @as(usize, 1));
137137 y = 0;
138138 inline while (y < 5) : (y += 1) {
139139 s[x + y * 5] ^= t[0];
lib/std/crypto/x25519.zig+33-33
......@@ -199,9 +199,9 @@ const Fe = struct {
199199 inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void {
200200 const j = (i + 1) % 10;
201201
202 c[i] = (t[i] + (i64(1) << shift)) >> (shift + 1);
202 c[i] = (t[i] + (@as(i64, 1) << shift)) >> (shift + 1);
203203 t[j] += c[i] * mult;
204 t[i] -= c[i] * (i64(1) << (shift + 1));
204 t[i] -= c[i] * (@as(i64, 1) << (shift + 1));
205205 }
206206
207207 fn carry1(h: *Fe, t: []i64) void {
......@@ -256,15 +256,15 @@ const Fe = struct {
256256 var t: [10]i64 = undefined;
257257
258258 t[0] = readIntSliceLittle(u32, s[0..4]);
259 t[1] = u32(readIntSliceLittle(u24, s[4..7])) << 6;
260 t[2] = u32(readIntSliceLittle(u24, s[7..10])) << 5;
261 t[3] = u32(readIntSliceLittle(u24, s[10..13])) << 3;
262 t[4] = u32(readIntSliceLittle(u24, s[13..16])) << 2;
259 t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6;
260 t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5;
261 t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3;
262 t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2;
263263 t[5] = readIntSliceLittle(u32, s[16..20]);
264 t[6] = u32(readIntSliceLittle(u24, s[20..23])) << 7;
265 t[7] = u32(readIntSliceLittle(u24, s[23..26])) << 5;
266 t[8] = u32(readIntSliceLittle(u24, s[26..29])) << 4;
267 t[9] = (u32(readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
264 t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7;
265 t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5;
266 t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4;
267 t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2;
268268
269269 carry1(h, t[0..]);
270270 }
......@@ -273,7 +273,7 @@ const Fe = struct {
273273 var t: [10]i64 = undefined;
274274
275275 for (t[0..]) |_, i| {
276 t[i] = i64(f.b[i]) * g;
276 t[i] = @as(i64, f.b[i]) * g;
277277 }
278278
279279 carry1(h, t[0..]);
......@@ -305,16 +305,16 @@ const Fe = struct {
305305 // t's become h
306306 var t: [10]i64 = undefined;
307307
308 t[0] = f[0] * i64(g[0]) + F[1] * i64(G[9]) + f[2] * i64(G[8]) + F[3] * i64(G[7]) + f[4] * i64(G[6]) + F[5] * i64(G[5]) + f[6] * i64(G[4]) + F[7] * i64(G[3]) + f[8] * i64(G[2]) + F[9] * i64(G[1]);
309 t[1] = f[0] * i64(g[1]) + f[1] * i64(g[0]) + f[2] * i64(G[9]) + f[3] * i64(G[8]) + f[4] * i64(G[7]) + f[5] * i64(G[6]) + f[6] * i64(G[5]) + f[7] * i64(G[4]) + f[8] * i64(G[3]) + f[9] * i64(G[2]);
310 t[2] = f[0] * i64(g[2]) + F[1] * i64(g[1]) + f[2] * i64(g[0]) + F[3] * i64(G[9]) + f[4] * i64(G[8]) + F[5] * i64(G[7]) + f[6] * i64(G[6]) + F[7] * i64(G[5]) + f[8] * i64(G[4]) + F[9] * i64(G[3]);
311 t[3] = f[0] * i64(g[3]) + f[1] * i64(g[2]) + f[2] * i64(g[1]) + f[3] * i64(g[0]) + f[4] * i64(G[9]) + f[5] * i64(G[8]) + f[6] * i64(G[7]) + f[7] * i64(G[6]) + f[8] * i64(G[5]) + f[9] * i64(G[4]);
312 t[4] = f[0] * i64(g[4]) + F[1] * i64(g[3]) + f[2] * i64(g[2]) + F[3] * i64(g[1]) + f[4] * i64(g[0]) + F[5] * i64(G[9]) + f[6] * i64(G[8]) + F[7] * i64(G[7]) + f[8] * i64(G[6]) + F[9] * i64(G[5]);
313 t[5] = f[0] * i64(g[5]) + f[1] * i64(g[4]) + f[2] * i64(g[3]) + f[3] * i64(g[2]) + f[4] * i64(g[1]) + f[5] * i64(g[0]) + f[6] * i64(G[9]) + f[7] * i64(G[8]) + f[8] * i64(G[7]) + f[9] * i64(G[6]);
314 t[6] = f[0] * i64(g[6]) + F[1] * i64(g[5]) + f[2] * i64(g[4]) + F[3] * i64(g[3]) + f[4] * i64(g[2]) + F[5] * i64(g[1]) + f[6] * i64(g[0]) + F[7] * i64(G[9]) + f[8] * i64(G[8]) + F[9] * i64(G[7]);
315 t[7] = f[0] * i64(g[7]) + f[1] * i64(g[6]) + f[2] * i64(g[5]) + f[3] * i64(g[4]) + f[4] * i64(g[3]) + f[5] * i64(g[2]) + f[6] * i64(g[1]) + f[7] * i64(g[0]) + f[8] * i64(G[9]) + f[9] * i64(G[8]);
316 t[8] = f[0] * i64(g[8]) + F[1] * i64(g[7]) + f[2] * i64(g[6]) + F[3] * i64(g[5]) + f[4] * i64(g[4]) + F[5] * i64(g[3]) + f[6] * i64(g[2]) + F[7] * i64(g[1]) + f[8] * i64(g[0]) + F[9] * i64(G[9]);
317 t[9] = f[0] * i64(g[9]) + f[1] * i64(g[8]) + f[2] * i64(g[7]) + f[3] * i64(g[6]) + f[4] * i64(g[5]) + f[5] * i64(g[4]) + f[6] * i64(g[3]) + f[7] * i64(g[2]) + f[8] * i64(g[1]) + f[9] * i64(g[0]);
308 t[0] = f[0] * @as(i64, g[0]) + F[1] * @as(i64, G[9]) + f[2] * @as(i64, G[8]) + F[3] * @as(i64, G[7]) + f[4] * @as(i64, G[6]) + F[5] * @as(i64, G[5]) + f[6] * @as(i64, G[4]) + F[7] * @as(i64, G[3]) + f[8] * @as(i64, G[2]) + F[9] * @as(i64, G[1]);
309 t[1] = f[0] * @as(i64, g[1]) + f[1] * @as(i64, g[0]) + f[2] * @as(i64, G[9]) + f[3] * @as(i64, G[8]) + f[4] * @as(i64, G[7]) + f[5] * @as(i64, G[6]) + f[6] * @as(i64, G[5]) + f[7] * @as(i64, G[4]) + f[8] * @as(i64, G[3]) + f[9] * @as(i64, G[2]);
310 t[2] = f[0] * @as(i64, g[2]) + F[1] * @as(i64, g[1]) + f[2] * @as(i64, g[0]) + F[3] * @as(i64, G[9]) + f[4] * @as(i64, G[8]) + F[5] * @as(i64, G[7]) + f[6] * @as(i64, G[6]) + F[7] * @as(i64, G[5]) + f[8] * @as(i64, G[4]) + F[9] * @as(i64, G[3]);
311 t[3] = f[0] * @as(i64, g[3]) + f[1] * @as(i64, g[2]) + f[2] * @as(i64, g[1]) + f[3] * @as(i64, g[0]) + f[4] * @as(i64, G[9]) + f[5] * @as(i64, G[8]) + f[6] * @as(i64, G[7]) + f[7] * @as(i64, G[6]) + f[8] * @as(i64, G[5]) + f[9] * @as(i64, G[4]);
312 t[4] = f[0] * @as(i64, g[4]) + F[1] * @as(i64, g[3]) + f[2] * @as(i64, g[2]) + F[3] * @as(i64, g[1]) + f[4] * @as(i64, g[0]) + F[5] * @as(i64, G[9]) + f[6] * @as(i64, G[8]) + F[7] * @as(i64, G[7]) + f[8] * @as(i64, G[6]) + F[9] * @as(i64, G[5]);
313 t[5] = f[0] * @as(i64, g[5]) + f[1] * @as(i64, g[4]) + f[2] * @as(i64, g[3]) + f[3] * @as(i64, g[2]) + f[4] * @as(i64, g[1]) + f[5] * @as(i64, g[0]) + f[6] * @as(i64, G[9]) + f[7] * @as(i64, G[8]) + f[8] * @as(i64, G[7]) + f[9] * @as(i64, G[6]);
314 t[6] = f[0] * @as(i64, g[6]) + F[1] * @as(i64, g[5]) + f[2] * @as(i64, g[4]) + F[3] * @as(i64, g[3]) + f[4] * @as(i64, g[2]) + F[5] * @as(i64, g[1]) + f[6] * @as(i64, g[0]) + F[7] * @as(i64, G[9]) + f[8] * @as(i64, G[8]) + F[9] * @as(i64, G[7]);
315 t[7] = f[0] * @as(i64, g[7]) + f[1] * @as(i64, g[6]) + f[2] * @as(i64, g[5]) + f[3] * @as(i64, g[4]) + f[4] * @as(i64, g[3]) + f[5] * @as(i64, g[2]) + f[6] * @as(i64, g[1]) + f[7] * @as(i64, g[0]) + f[8] * @as(i64, G[9]) + f[9] * @as(i64, G[8]);
316 t[8] = f[0] * @as(i64, g[8]) + F[1] * @as(i64, g[7]) + f[2] * @as(i64, g[6]) + F[3] * @as(i64, g[5]) + f[4] * @as(i64, g[4]) + F[5] * @as(i64, g[3]) + f[6] * @as(i64, g[2]) + F[7] * @as(i64, g[1]) + f[8] * @as(i64, g[0]) + F[9] * @as(i64, G[9]);
317 t[9] = f[0] * @as(i64, g[9]) + f[1] * @as(i64, g[8]) + f[2] * @as(i64, g[7]) + f[3] * @as(i64, g[6]) + f[4] * @as(i64, g[5]) + f[5] * @as(i64, g[4]) + f[6] * @as(i64, g[3]) + f[7] * @as(i64, g[2]) + f[8] * @as(i64, g[1]) + f[9] * @as(i64, g[0]);
318318
319319 carry2(h, t[0..]);
320320 }
......@@ -348,16 +348,16 @@ const Fe = struct {
348348
349349 var t: [10]i64 = undefined;
350350
351 t[0] = f0 * i64(f0) + f1_2 * i64(f9_38) + f2_2 * i64(f8_19) + f3_2 * i64(f7_38) + f4_2 * i64(f6_19) + f5 * i64(f5_38);
352 t[1] = f0_2 * i64(f1) + f2 * i64(f9_38) + f3_2 * i64(f8_19) + f4 * i64(f7_38) + f5_2 * i64(f6_19);
353 t[2] = f0_2 * i64(f2) + f1_2 * i64(f1) + f3_2 * i64(f9_38) + f4_2 * i64(f8_19) + f5_2 * i64(f7_38) + f6 * i64(f6_19);
354 t[3] = f0_2 * i64(f3) + f1_2 * i64(f2) + f4 * i64(f9_38) + f5_2 * i64(f8_19) + f6 * i64(f7_38);
355 t[4] = f0_2 * i64(f4) + f1_2 * i64(f3_2) + f2 * i64(f2) + f5_2 * i64(f9_38) + f6_2 * i64(f8_19) + f7 * i64(f7_38);
356 t[5] = f0_2 * i64(f5) + f1_2 * i64(f4) + f2_2 * i64(f3) + f6 * i64(f9_38) + f7_2 * i64(f8_19);
357 t[6] = f0_2 * i64(f6) + f1_2 * i64(f5_2) + f2_2 * i64(f4) + f3_2 * i64(f3) + f7_2 * i64(f9_38) + f8 * i64(f8_19);
358 t[7] = f0_2 * i64(f7) + f1_2 * i64(f6) + f2_2 * i64(f5) + f3_2 * i64(f4) + f8 * i64(f9_38);
359 t[8] = f0_2 * i64(f8) + f1_2 * i64(f7_2) + f2_2 * i64(f6) + f3_2 * i64(f5_2) + f4 * i64(f4) + f9 * i64(f9_38);
360 t[9] = f0_2 * i64(f9) + f1_2 * i64(f8) + f2_2 * i64(f7) + f3_2 * i64(f6) + f4 * i64(f5_2);
351 t[0] = f0 * @as(i64, f0) + f1_2 * @as(i64, f9_38) + f2_2 * @as(i64, f8_19) + f3_2 * @as(i64, f7_38) + f4_2 * @as(i64, f6_19) + f5 * @as(i64, f5_38);
352 t[1] = f0_2 * @as(i64, f1) + f2 * @as(i64, f9_38) + f3_2 * @as(i64, f8_19) + f4 * @as(i64, f7_38) + f5_2 * @as(i64, f6_19);
353 t[2] = f0_2 * @as(i64, f2) + f1_2 * @as(i64, f1) + f3_2 * @as(i64, f9_38) + f4_2 * @as(i64, f8_19) + f5_2 * @as(i64, f7_38) + f6 * @as(i64, f6_19);
354 t[3] = f0_2 * @as(i64, f3) + f1_2 * @as(i64, f2) + f4 * @as(i64, f9_38) + f5_2 * @as(i64, f8_19) + f6 * @as(i64, f7_38);
355 t[4] = f0_2 * @as(i64, f4) + f1_2 * @as(i64, f3_2) + f2 * @as(i64, f2) + f5_2 * @as(i64, f9_38) + f6_2 * @as(i64, f8_19) + f7 * @as(i64, f7_38);
356 t[5] = f0_2 * @as(i64, f5) + f1_2 * @as(i64, f4) + f2_2 * @as(i64, f3) + f6 * @as(i64, f9_38) + f7_2 * @as(i64, f8_19);
357 t[6] = f0_2 * @as(i64, f6) + f1_2 * @as(i64, f5_2) + f2_2 * @as(i64, f4) + f3_2 * @as(i64, f3) + f7_2 * @as(i64, f9_38) + f8 * @as(i64, f8_19);
358 t[7] = f0_2 * @as(i64, f7) + f1_2 * @as(i64, f6) + f2_2 * @as(i64, f5) + f3_2 * @as(i64, f4) + f8 * @as(i64, f9_38);
359 t[8] = f0_2 * @as(i64, f8) + f1_2 * @as(i64, f7_2) + f2_2 * @as(i64, f6) + f3_2 * @as(i64, f5_2) + f4 * @as(i64, f4) + f9 * @as(i64, f9_38);
360 t[9] = f0_2 * @as(i64, f9) + f1_2 * @as(i64, f8) + f2_2 * @as(i64, f7) + f3_2 * @as(i64, f6) + f4 * @as(i64, f5_2);
361361
362362 carry2(h, t[0..]);
363363 }
......@@ -500,7 +500,7 @@ const Fe = struct {
500500 if (i + 1 < 10) {
501501 t[i + 1] += c[i];
502502 }
503 t[i] -= c[i] * (i32(1) << shift);
503 t[i] -= c[i] * (@as(i32, 1) << shift);
504504 }
505505
506506 fn toBytes(s: []u8, h: *const Fe) void {
......@@ -511,7 +511,7 @@ const Fe = struct {
511511 t[i] = h.b[i];
512512 }
513513
514 var q = (19 * t[9] + ((i32(1) << 24))) >> 25;
514 var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25;
515515 {
516516 var i: usize = 0;
517517 while (i < 5) : (i += 1) {
lib/std/debug.zig+13-10
......@@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
10081008 const word = try stream.readIntLittle(u32);
10091009 var bit_i: u5 = 0;
10101010 while (true) : (bit_i += 1) {
1011 if (word & (u32(1) << bit_i) != 0) {
1011 if (word & (@as(u32, 1) << bit_i) != 0) {
10121012 try list.append(word_i * 32 + bit_i);
10131013 }
10141014 if (bit_i == maxInt(u5)) break;
......@@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
15561556
15571557// TODO the noasyncs here are workarounds
15581558fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 {
1559 return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32));
1559 return if (is_64) try noasync in_stream.readIntLittle(u64) else @as(u64, try noasync in_stream.readIntLittle(u32));
15601560}
15611561
15621562// TODO the noasyncs here are workarounds
15631563fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
15641564 if (@sizeOf(usize) == 4) {
1565 return u64(try noasync in_stream.readIntLittle(u32));
1565 // TODO this cast should not be needed
1566 return @as(u64, try noasync in_stream.readIntLittle(u32));
15661567 } else if (@sizeOf(usize) == 8) {
15671568 return noasync in_stream.readIntLittle(u64);
15681569 } else {
......@@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
18461847 // special opcodes
18471848 const adjusted_opcode = opcode - opcode_base;
18481849 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
1849 const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);
1850 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
18501851 prog.line += inc_line;
18511852 prog.address += inc_addr;
18521853 if (try prog.checkLineMatch()) |info| return info;
......@@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
19131914 if (unit_length == 0) {
19141915 return error.MissingDebugInfo;
19151916 }
1916 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
1917 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
19171918
19181919 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
19191920 // TODO support 3 and 5
......@@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
20122013 // special opcodes
20132014 const adjusted_opcode = opcode - opcode_base;
20142015 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
2015 const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);
2016 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
20162017 prog.line += inc_line;
20172018 prog.address += inc_addr;
20182019 if (try prog.checkLineMatch()) |info| return info;
......@@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {
20932094 var is_64: bool = undefined;
20942095 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
20952096 if (unit_length == 0) return;
2096 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
2097 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
20972098
20982099 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
20992100 if (version < 2 or version > 5) return error.InvalidDebugInfo;
......@@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void {
21952196 var is_64: bool = undefined;
21962197 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
21972198 if (unit_length == 0) return;
2198 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
2199 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
21992200
22002201 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
22012202 if (version < 2 or version > 5) return error.InvalidDebugInfo;
......@@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {
23122313 } else {
23132314 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
23142315 ptr.* += 4;
2315 return u64(first_32_bits);
2316 // TODO this cast should not be needed
2317 return @as(u64, first_32_bits);
23162318 }
23172319}
23182320
......@@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool)
23292331 return in_stream.readIntLittle(u64);
23302332 } else {
23312333 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
2332 return u64(first_32_bits);
2334 // TODO this cast should not be needed
2335 return @as(u64, first_32_bits);
23332336 }
23342337}
23352338
lib/std/debug/leb128.zig+3-3
......@@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
6262 var shift: usize = 0;
6363
6464 while (true) {
65 const byte = u8(try in_stream.readByte());
65 const byte: u8 = try in_stream.readByte();
6666
6767 if (shift > T.bit_count)
6868 return error.Overflow;
6969
7070 var operand: UT = undefined;
71 if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
71 if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
7272 if (byte != 0x7f)
7373 return error.Overflow;
7474 }
......@@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
101101 return error.Overflow;
102102
103103 var operand: UT = undefined;
104 if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
104 if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) {
105105 if (byte != 0x7f)
106106 return error.Overflow;
107107 }
lib/std/dynamic_library.zig+2-2
......@@ -215,8 +215,8 @@ pub const ElfLib = struct {
215215
216216 var i: usize = 0;
217217 while (i < self.hashtab[1]) : (i += 1) {
218 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
219 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
218 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
219 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
220220 if (0 == self.syms[i].st_shndx) continue;
221221 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
222222 if (maybe_versym) |versym| {
lib/std/elf.zig+12-12
......@@ -441,9 +441,9 @@ pub const Elf = struct {
441441 elf.program_header_offset = try in.readInt(u64, elf.endian);
442442 elf.section_header_offset = try in.readInt(u64, elf.endian);
443443 } else {
444 elf.entry_addr = u64(try in.readInt(u32, elf.endian));
445 elf.program_header_offset = u64(try in.readInt(u32, elf.endian));
446 elf.section_header_offset = u64(try in.readInt(u32, elf.endian));
444 elf.entry_addr = @as(u64, try in.readInt(u32, elf.endian));
445 elf.program_header_offset = @as(u64, try in.readInt(u32, elf.endian));
446 elf.section_header_offset = @as(u64, try in.readInt(u32, elf.endian));
447447 }
448448
449449 // skip over flags
......@@ -458,13 +458,13 @@ pub const Elf = struct {
458458 const ph_entry_count = try in.readInt(u16, elf.endian);
459459 const sh_entry_size = try in.readInt(u16, elf.endian);
460460 const sh_entry_count = try in.readInt(u16, elf.endian);
461 elf.string_section_index = usize(try in.readInt(u16, elf.endian));
461 elf.string_section_index = @as(usize, try in.readInt(u16, elf.endian));
462462
463463 if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat;
464464
465 const sh_byte_count = u64(sh_entry_size) * u64(sh_entry_count);
465 const sh_byte_count = @as(u64, sh_entry_size) * @as(u64, sh_entry_count);
466466 const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count);
467 const ph_byte_count = u64(ph_entry_size) * u64(ph_entry_count);
467 const ph_byte_count = @as(u64, ph_entry_size) * @as(u64, ph_entry_count);
468468 const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count);
469469
470470 const stream_end = try seekable_stream.getEndPos();
......@@ -499,14 +499,14 @@ pub const Elf = struct {
499499 // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ?
500500 elf_section.name = try in.readInt(u32, elf.endian);
501501 elf_section.sh_type = try in.readInt(u32, elf.endian);
502 elf_section.flags = u64(try in.readInt(u32, elf.endian));
503 elf_section.addr = u64(try in.readInt(u32, elf.endian));
504 elf_section.offset = u64(try in.readInt(u32, elf.endian));
505 elf_section.size = u64(try in.readInt(u32, elf.endian));
502 elf_section.flags = @as(u64, try in.readInt(u32, elf.endian));
503 elf_section.addr = @as(u64, try in.readInt(u32, elf.endian));
504 elf_section.offset = @as(u64, try in.readInt(u32, elf.endian));
505 elf_section.size = @as(u64, try in.readInt(u32, elf.endian));
506506 elf_section.link = try in.readInt(u32, elf.endian);
507507 elf_section.info = try in.readInt(u32, elf.endian);
508 elf_section.addr_align = u64(try in.readInt(u32, elf.endian));
509 elf_section.ent_size = u64(try in.readInt(u32, elf.endian));
508 elf_section.addr_align = @as(u64, try in.readInt(u32, elf.endian));
509 elf_section.ent_size = @as(u64, try in.readInt(u32, elf.endian));
510510 }
511511 }
512512
lib/std/event/fs.zig+2-2
......@@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize {
328328 windows.ERROR.IO_PENDING => unreachable,
329329 windows.ERROR.OPERATION_ABORTED => return error.OperationAborted,
330330 windows.ERROR.BROKEN_PIPE => return error.BrokenPipe,
331 windows.ERROR.HANDLE_EOF => return usize(bytes_transferred),
331 windows.ERROR.HANDLE_EOF => return @as(usize, bytes_transferred),
332332 else => |err| return windows.unexpectedError(err),
333333 }
334334 }
335 return usize(bytes_transferred);
335 return @as(usize, bytes_transferred);
336336}
337337
338338/// iovecs must live until preadv frame completes
lib/std/event/loop.zig+11-11
......@@ -266,7 +266,7 @@ pub const Loop = struct {
266266 },
267267 };
268268
269 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
269 const empty_kevs = &[0]os.Kevent{};
270270
271271 for (self.eventfd_resume_nodes) |*eventfd_node, i| {
272272 eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
......@@ -289,7 +289,7 @@ pub const Loop = struct {
289289 .next = undefined,
290290 };
291291 self.available_eventfd_resume_nodes.push(eventfd_node);
292 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.data.kevent);
292 const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.data.kevent);
293293 _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
294294 eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE;
295295 eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER;
......@@ -305,7 +305,7 @@ pub const Loop = struct {
305305 .data = 0,
306306 .udata = @ptrToInt(&self.final_resume_node),
307307 };
308 const final_kev_arr = (*const [1]os.Kevent)(&self.os_data.final_kevent);
308 const final_kev_arr = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
309309 _ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
310310 self.os_data.final_kevent.flags = os.EV_ENABLE;
311311 self.os_data.final_kevent.fflags = os.NOTE_TRIGGER;
......@@ -572,8 +572,8 @@ pub const Loop = struct {
572572 eventfd_node.base.handle = next_tick_node.data;
573573 switch (builtin.os) {
574574 .macosx, .freebsd, .netbsd, .dragonfly => {
575 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);
576 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
575 const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.kevent);
576 const empty_kevs = &[0]os.Kevent{};
577577 _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
578578 self.next_tick_queue.unget(next_tick_node);
579579 self.available_eventfd_resume_nodes.push(resume_stack_node);
......@@ -695,8 +695,8 @@ pub const Loop = struct {
695695 },
696696 .macosx, .freebsd, .netbsd, .dragonfly => {
697697 self.posixFsRequest(&self.os_data.fs_end_request);
698 const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);
699 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
698 const final_kevent = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
699 const empty_kevs = &[0]os.Kevent{};
700700 // cannot fail because we already added it and this just enables it
701701 _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
702702 return;
......@@ -753,7 +753,7 @@ pub const Loop = struct {
753753 },
754754 .macosx, .freebsd, .netbsd, .dragonfly => {
755755 var eventlist: [1]os.Kevent = undefined;
756 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
756 const empty_kevs = &[0]os.Kevent{};
757757 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
758758 for (eventlist[0..count]) |ev| {
759759 const resume_node = @intToPtr(*ResumeNode, ev.udata);
......@@ -815,8 +815,8 @@ pub const Loop = struct {
815815 self.os_data.fs_queue.put(request_node);
816816 switch (builtin.os) {
817817 .macosx, .freebsd, .netbsd, .dragonfly => {
818 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);
819 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
818 const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wake);
819 const empty_kevs = &[0]os.Kevent{};
820820 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
821821 },
822822 .linux => {
......@@ -890,7 +890,7 @@ pub const Loop = struct {
890890 }
891891 },
892892 .macosx, .freebsd, .netbsd, .dragonfly => {
893 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);
893 const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wait);
894894 var out_kevs: [1]os.Kevent = undefined;
895895 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
896896 },
lib/std/fifo.zig+13-13
......@@ -257,7 +257,7 @@ test "ByteFifo" {
257257 defer fifo.deinit();
258258
259259 try fifo.write("HELLO");
260 testing.expectEqual(usize(5), fifo.readableLength());
260 testing.expectEqual(@as(usize, 5), fifo.readableLength());
261261 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
262262
263263 {
......@@ -265,34 +265,34 @@ test "ByteFifo" {
265265 while (i < 5) : (i += 1) {
266266 try fifo.write([_]u8{try fifo.peekItem(i)});
267267 }
268 testing.expectEqual(usize(10), fifo.readableLength());
268 testing.expectEqual(@as(usize, 10), fifo.readableLength());
269269 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
270270 }
271271
272272 {
273 testing.expectEqual(u8('H'), try fifo.readItem());
274 testing.expectEqual(u8('E'), try fifo.readItem());
275 testing.expectEqual(u8('L'), try fifo.readItem());
276 testing.expectEqual(u8('L'), try fifo.readItem());
277 testing.expectEqual(u8('O'), try fifo.readItem());
273 testing.expectEqual(@as(u8, 'H'), try fifo.readItem());
274 testing.expectEqual(@as(u8, 'E'), try fifo.readItem());
275 testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
276 testing.expectEqual(@as(u8, 'L'), try fifo.readItem());
277 testing.expectEqual(@as(u8, 'O'), try fifo.readItem());
278278 }
279 testing.expectEqual(usize(5), fifo.readableLength());
279 testing.expectEqual(@as(usize, 5), fifo.readableLength());
280280
281281 { // Writes that wrap around
282 testing.expectEqual(usize(11), fifo.writableLength());
283 testing.expectEqual(usize(6), fifo.writableSlice(0).len);
282 testing.expectEqual(@as(usize, 11), fifo.writableLength());
283 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
284284 fifo.writeAssumeCapacity("6<chars<11");
285285 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
286286 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
287287 fifo.discard(11);
288288 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
289289 fifo.discard(4);
290 testing.expectEqual(usize(0), fifo.readableLength());
290 testing.expectEqual(@as(usize, 0), fifo.readableLength());
291291 }
292292
293293 {
294294 const buf = try fifo.writeableWithSize(12);
295 testing.expectEqual(usize(12), buf.len);
295 testing.expectEqual(@as(usize, 12), buf.len);
296296 var i: u8 = 0;
297297 while (i < 10) : (i += 1) {
298298 buf[i] = i + 'a';
......@@ -313,6 +313,6 @@ test "ByteFifo" {
313313 try fifo.print("{}, {}!", "Hello", "World");
314314 var result: [30]u8 = undefined;
315315 testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result));
316 testing.expectEqual(usize(0), fifo.readableLength());
316 testing.expectEqual(@as(usize, 0), fifo.readableLength());
317317 }
318318}
lib/std/fmt.zig+62-62
......@@ -382,10 +382,10 @@ pub fn formatType(
382382 const info = @typeInfo(T).Union;
383383 if (info.tag_type) |UnionTagType| {
384384 try output(context, "{ .");
385 try output(context, @tagName(UnionTagType(value)));
385 try output(context, @tagName(@as(UnionTagType, value)));
386386 try output(context, " = ");
387387 inline for (info.fields) |u_field| {
388 if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) {
388 if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) {
389389 try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1);
390390 }
391391 }
......@@ -503,7 +503,7 @@ pub fn formatIntValue(
503503
504504 const int_value = if (@typeOf(value) == comptime_int) blk: {
505505 const Int = math.IntFittingRange(value, value);
506 break :blk Int(value);
506 break :blk @as(Int, value);
507507 } else
508508 value;
509509
......@@ -512,7 +512,7 @@ pub fn formatIntValue(
512512 uppercase = false;
513513 } else if (comptime std.mem.eql(u8, fmt, "c")) {
514514 if (@typeOf(int_value).bit_count <= 8) {
515 return formatAsciiChar(u8(int_value), options, context, Errors, output);
515 return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
516516 } else {
517517 @compileError("Cannot print integer that is larger than 8 bits as a ascii");
518518 }
......@@ -578,7 +578,7 @@ pub fn formatAsciiChar(
578578 comptime Errors: type,
579579 output: fn (@typeOf(context), []const u8) Errors!void,
580580) Errors!void {
581 return output(context, (*const [1]u8)(&c)[0..]);
581 return output(context, @as(*const [1]u8, &c)[0..]);
582582}
583583
584584pub fn formatBuf(
......@@ -594,7 +594,7 @@ pub fn formatBuf(
594594 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
595595 const pad_byte: u8 = options.fill;
596596 while (leftover_padding > 0) : (leftover_padding -= 1) {
597 try output(context, (*const [1]u8)(&pad_byte)[0..1]);
597 try output(context, @as(*const [1]u8, &pad_byte)[0..1]);
598598 }
599599}
600600
......@@ -668,7 +668,7 @@ pub fn formatFloatScientific(
668668 try output(context, float_decimal.digits[0..1]);
669669 try output(context, ".");
670670 if (float_decimal.digits.len > 1) {
671 const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len;
671 const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
672672
673673 try output(context, float_decimal.digits[1..num_digits]);
674674 } else {
......@@ -703,7 +703,7 @@ pub fn formatFloatDecimal(
703703 comptime Errors: type,
704704 output: fn (@typeOf(context), []const u8) Errors!void,
705705) Errors!void {
706 var x = f64(value);
706 var x = @as(f64, value);
707707
708708 // Errol doesn't handle these special cases.
709709 if (math.signbit(x)) {
......@@ -921,14 +921,14 @@ fn formatIntSigned(
921921 const uint = @IntType(false, @typeOf(value).bit_count);
922922 if (value < 0) {
923923 const minus_sign: u8 = '-';
924 try output(context, (*const [1]u8)(&minus_sign)[0..]);
924 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
925925 const new_value = @intCast(uint, -(value + 1)) + 1;
926926 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
927927 } else if (options.width == null or options.width.? == 0) {
928928 return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);
929929 } else {
930930 const plus_sign: u8 = '+';
931 try output(context, (*const [1]u8)(&plus_sign)[0..]);
931 try output(context, @as(*const [1]u8, &plus_sign)[0..]);
932932 const new_value = @intCast(uint, value);
933933 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
934934 }
......@@ -966,7 +966,7 @@ fn formatIntUnsigned(
966966 const zero_byte: u8 = options.fill;
967967 var leftover_padding = padding - index;
968968 while (true) {
969 try output(context, (*const [1]u8)(&zero_byte)[0..]);
969 try output(context, @as(*const [1]u8, &zero_byte)[0..]);
970970 leftover_padding -= 1;
971971 if (leftover_padding == 0) break;
972972 }
......@@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
998998
999999pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
10001000 if (!T.is_signed) return parseUnsigned(T, buf, radix);
1001 if (buf.len == 0) return T(0);
1001 if (buf.len == 0) return @as(T, 0);
10021002 if (buf[0] == '-') {
10031003 return math.negate(try parseUnsigned(T, buf[1..], radix));
10041004 } else if (buf[0] == '+') {
......@@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
10881088fn digitToChar(digit: u8, uppercase: bool) u8 {
10891089 return switch (digit) {
10901090 0...9 => digit + '0',
1091 10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
1091 10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10),
10921092 else => unreachable,
10931093 };
10941094}
......@@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
11341134test "bufPrintInt" {
11351135 var buffer: [100]u8 = undefined;
11361136 const buf = buffer[0..];
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678"));
1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e"));
1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, FormatOptions{}), "-BC614E"));
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678"));
1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e"));
1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E"));
11411141
1142 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, FormatOptions{}), "12345678"));
1142 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678"));
11431143
1144 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, FormatOptions{ .width = 6 }), " 666"));
1145 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1146 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
1144 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666"));
1145 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1146 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
11471147
1148 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, FormatOptions{ .width = 3 }), "+42"));
1149 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, FormatOptions{ .width = 3 }), "-42"));
1148 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42"));
1149 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
11501150}
11511151
11521152fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
......@@ -1208,8 +1208,8 @@ test "int.specifier" {
12081208}
12091209
12101210test "int.padded" {
1211 try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1));
1212 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", u8(1));
1211 try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));
1212 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));
12131213}
12141214
12151215test "buffer" {
......@@ -1287,8 +1287,8 @@ test "filesize" {
12871287 // TODO https://github.com/ziglang/zig/issues/3289
12881288 return error.SkipZigTest;
12891289 }
1290 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024));
1291 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", usize(63 * 1024 * 1024));
1290 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024));
1291 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024));
12921292}
12931293
12941294test "struct" {
......@@ -1325,10 +1325,10 @@ test "float.scientific" {
13251325 // TODO https://github.com/ziglang/zig/issues/3289
13261326 return error.SkipZigTest;
13271327 }
1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));
1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));
1330 try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10));
1331 try testFmt("f64: 9.99996e-40", "f64: {e}", f64(9.999960e-40));
1328 try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));
1329 try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));
1330 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
1331 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
13321332}
13331333
13341334test "float.scientific.precision" {
......@@ -1336,12 +1336,12 @@ test "float.scientific.precision" {
13361336 // TODO https://github.com/ziglang/zig/issues/3289
13371337 return error.SkipZigTest;
13381338 }
1339 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42));
1340 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563))));
1341 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", f64(@bitCast(f32, u32(1006632960))));
1339 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42));
1340 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563))));
1341 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));
13421342 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
13431343 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
1344 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", f64(@bitCast(f32, u32(1203982400))));
1344 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400))));
13451345}
13461346
13471347test "float.special" {
......@@ -1364,21 +1364,21 @@ test "float.decimal" {
13641364 // TODO https://github.com/ziglang/zig/issues/3289
13651365 return error.SkipZigTest;
13661366 }
1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29));
1368 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));
1369 try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567));
1367 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
1368 try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));
1369 try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567));
13701370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
13711371 // -11.12339... is rounded back up to -11.1234
1372 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));
1373 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));
1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235));
1375 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0));
1376 try testFmt("f64: 6", "f64: {d:.0}", f64(5.700));
1377 try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999));
1378 try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0));
1379 try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003));
1380 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45));
1381 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(9.999960e-40));
1372 try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));
1373 try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));
1374 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
1375 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
1376 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
1377 try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));
1378 try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));
1379 try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));
1380 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));
1381 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));
13821382}
13831383
13841384test "float.libc.sanity" {
......@@ -1386,22 +1386,22 @@ test "float.libc.sanity" {
13861386 // TODO https://github.com/ziglang/zig/issues/3289
13871387 return error.SkipZigTest;
13881388 }
1389 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781))));
1390 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389))));
1391 try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278))));
1392 try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133))));
1393 try testFmt("f64: 10.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1092616192))));
1389 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781))));
1390 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389))));
1391 try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278))));
1392 try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));
1393 try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));
13941394
13951395 // libc differences
13961396 //
13971397 // This is 0.015625 exactly according to gdb. We thus round down,
13981398 // however glibc rounds up for some reason. This occurs for all
13991399 // floats of the form x.yyyy25 on a precision point.
1400 try testFmt("f64: 0.01563", "f64: {d:.5}", f64(@bitCast(f32, u32(1015021568))));
1400 try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568))));
14011401 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
14021402 // also rounds to 630 so I'm inclined to believe libc is not
14031403 // optimal here.
1404 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1518338049))));
1404 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049))));
14051405}
14061406
14071407test "custom" {
......@@ -1677,17 +1677,17 @@ test "formatType max_depth" {
16771677}
16781678
16791679test "positional" {
1680 try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2));
1681 try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2));
1682 try testFmt("0 0", "{0} {0}", usize(0));
1683 try testFmt("0 1", "{} {1}", usize(0), usize(1));
1684 try testFmt("1 0 0 1", "{1} {} {0} {}", usize(0), usize(1));
1680 try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1681 try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
1682 try testFmt("0 0", "{0} {0}", @as(usize, 0));
1683 try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));
1684 try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));
16851685}
16861686
16871687test "positional with specifier" {
1688 try testFmt("10.0", "{0d:.1}", f64(9.999));
1688 try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
16891689}
16901690
16911691test "positional/alignment/width/precision" {
1692 try testFmt("10.0", "{0d: >3.1}", f64(9.999));
1692 try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));
16931693}
lib/std/fmt/errol.zig+2-2
......@@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void {
296296/// @buf: The output buffer.
297297/// &return: The exponent.
298298fn errolInt(val: f64, buffer: []u8) FloatDecimal {
299 const pow19 = u128(1e19);
299 const pow19 = @as(u128, 1e19);
300300
301301 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
302302
......@@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 {
670670 const bits = @bitCast(u64, from);
671671 assert((bits & ((1 << 52) - 1)) == 0);
672672
673 return u128(1) << @truncate(u7, (bits >> 52) -% 1023);
673 return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023);
674674}
675675
676676/// Given two different integers with the same length in terms of the number
lib/std/fmt/parse_float.zig+10-10
......@@ -59,29 +59,29 @@ const Z96 = struct {
5959
6060 // d += s
6161 inline fn add(d: *Z96, s: Z96) void {
62 var w = u64(d.d0) + u64(s.d0);
62 var w = @as(u64, d.d0) + @as(u64, s.d0);
6363 d.d0 = @truncate(u32, w);
6464
6565 w >>= 32;
66 w += u64(d.d1) + u64(s.d1);
66 w += @as(u64, d.d1) + @as(u64, s.d1);
6767 d.d1 = @truncate(u32, w);
6868
6969 w >>= 32;
70 w += u64(d.d2) + u64(s.d2);
70 w += @as(u64, d.d2) + @as(u64, s.d2);
7171 d.d2 = @truncate(u32, w);
7272 }
7373
7474 // d -= s
7575 inline fn sub(d: *Z96, s: Z96) void {
76 var w = u64(d.d0) -% u64(s.d0);
76 var w = @as(u64, d.d0) -% @as(u64, s.d0);
7777 d.d0 = @truncate(u32, w);
7878
7979 w >>= 32;
80 w += u64(d.d1) -% u64(s.d1);
80 w += @as(u64, d.d1) -% @as(u64, s.d1);
8181 d.d1 = @truncate(u32, w);
8282
8383 w >>= 32;
84 w += u64(d.d2) -% u64(s.d2);
84 w += @as(u64, d.d2) -% @as(u64, s.d2);
8585 d.d2 = @truncate(u32, w);
8686 }
8787};
......@@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {
160160 break :blk if (n.negative) f64_minus_zero else f64_plus_zero;
161161 } else if (s.d2 != 0) {
162162 const binexs2 = @intCast(u64, binary_exponent) << 52;
163 const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2;
163 const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2;
164164 break :blk if (n.negative) rr | (1 << 63) else rr;
165165 } else {
166166 break :blk 0;
......@@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
375375 return switch (try parseRepr(s, &r)) {
376376 ParseResult.Ok => convertRepr(T, r),
377377 ParseResult.PlusZero => 0.0,
378 ParseResult.MinusZero => -T(0.0),
378 ParseResult.MinusZero => -@as(T, 0.0),
379379 ParseResult.PlusInf => std.math.inf(T),
380380 ParseResult.MinusInf => -std.math.inf(T),
381381 };
......@@ -426,8 +426,8 @@ test "fmt.parseFloat" {
426426 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
427427
428428 expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
429 expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon));
430 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon));
429 expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
430 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
431431 }
432432 }
433433}
lib/std/fs.zig+1-1
......@@ -584,7 +584,7 @@ pub const Dir = struct {
584584 .FileBothDirectoryInformation,
585585 w.FALSE,
586586 null,
587 if (self.first) w.BOOLEAN(w.TRUE) else w.BOOLEAN(w.FALSE),
587 if (self.first) @as(w.BOOLEAN, w.TRUE) else @as(w.BOOLEAN, w.FALSE),
588588 );
589589 self.first = false;
590590 if (io.Information == 0) return null;
lib/std/fs/file.zig+3-3
......@@ -272,9 +272,9 @@ pub const File = struct {
272272 return Stat{
273273 .size = @bitCast(u64, st.size),
274274 .mode = st.mode,
275 .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
276 .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
277 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
275 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
276 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
277 .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
278278 };
279279 }
280280
lib/std/hash/auto_hash.zig+7-7
......@@ -306,7 +306,7 @@ test "hash struct deep" {
306306test "testHash optional" {
307307 const a: ?u32 = 123;
308308 const b: ?u32 = null;
309 testing.expectEqual(testHash(a), testHash(u32(123)));
309 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
310310 testing.expect(testHash(a) != testHash(b));
311311 testing.expectEqual(testHash(b), 0);
312312}
......@@ -315,9 +315,9 @@ test "testHash array" {
315315 const a = [_]u32{ 1, 2, 3 };
316316 const h = testHash(a);
317317 var hasher = Wyhash.init(0);
318 autoHash(&hasher, u32(1));
319 autoHash(&hasher, u32(2));
320 autoHash(&hasher, u32(3));
318 autoHash(&hasher, @as(u32, 1));
319 autoHash(&hasher, @as(u32, 2));
320 autoHash(&hasher, @as(u32, 3));
321321 testing.expectEqual(h, hasher.final());
322322}
323323
......@@ -330,9 +330,9 @@ test "testHash struct" {
330330 const f = Foo{};
331331 const h = testHash(f);
332332 var hasher = Wyhash.init(0);
333 autoHash(&hasher, u32(1));
334 autoHash(&hasher, u32(2));
335 autoHash(&hasher, u32(3));
333 autoHash(&hasher, @as(u32, 1));
334 autoHash(&hasher, @as(u32, 2));
335 autoHash(&hasher, @as(u32, 3));
336336 testing.expectEqual(h, hasher.final());
337337}
338338
lib/std/hash/cityhash.zig+4-4
......@@ -214,7 +214,7 @@ pub const CityHash64 = struct {
214214 }
215215
216216 fn hashLen0To16(str: []const u8) u64 {
217 const len: u64 = u64(str.len);
217 const len: u64 = @as(u64, str.len);
218218 if (len >= 8) {
219219 const mul: u64 = k2 +% len *% 2;
220220 const a: u64 = fetch64(str.ptr) +% k2;
......@@ -240,7 +240,7 @@ pub const CityHash64 = struct {
240240 }
241241
242242 fn hashLen17To32(str: []const u8) u64 {
243 const len: u64 = u64(str.len);
243 const len: u64 = @as(u64, str.len);
244244 const mul: u64 = k2 +% len *% 2;
245245 const a: u64 = fetch64(str.ptr) *% k1;
246246 const b: u64 = fetch64(str.ptr + 8);
......@@ -251,7 +251,7 @@ pub const CityHash64 = struct {
251251 }
252252
253253 fn hashLen33To64(str: []const u8) u64 {
254 const len: u64 = u64(str.len);
254 const len: u64 = @as(u64, str.len);
255255 const mul: u64 = k2 +% len *% 2;
256256 const a: u64 = fetch64(str.ptr) *% k2;
257257 const b: u64 = fetch64(str.ptr + 8);
......@@ -305,7 +305,7 @@ pub const CityHash64 = struct {
305305 return hashLen33To64(str);
306306 }
307307
308 var len: u64 = u64(str.len);
308 var len: u64 = @as(u64, str.len);
309309
310310 var x: u64 = fetch64(str.ptr + str.len - 40);
311311 var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56);
lib/std/hash/crc.zig+4-4
......@@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
6565 const p = input[i .. i + 8];
6666
6767 // Unrolling this way gives ~50Mb/s increase
68 self.crc ^= (u32(p[0]) << 0);
69 self.crc ^= (u32(p[1]) << 8);
70 self.crc ^= (u32(p[2]) << 16);
71 self.crc ^= (u32(p[3]) << 24);
68 self.crc ^= (@as(u32, p[0]) << 0);
69 self.crc ^= (@as(u32, p[1]) << 8);
70 self.crc ^= (@as(u32, p[2]) << 16);
71 self.crc ^= (@as(u32, p[3]) << 24);
7272
7373 self.crc =
7474 lookup_tables[0][p[7]] ^
lib/std/hash/murmur.zig+1-1
......@@ -98,7 +98,7 @@ pub const Murmur2_64 = struct {
9898
9999 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
100100 const m: u64 = 0xc6a4a7935bd1e995;
101 const len = u64(str.len);
101 const len = @as(u64, str.len);
102102 var h1: u64 = seed ^ (len *% m);
103103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104104 var k1: u64 = v;
lib/std/hash/siphash.zig+7-7
......@@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
102102 }
103103
104104 const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3;
105 return (u128(b2) << 64) | b1;
105 return (@as(u128, b2) << 64) | b1;
106106 }
107107
108108 fn round(self: *Self, b: []const u8) void {
......@@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
121121
122122 fn sipRound(d: *Self) void {
123123 d.v0 +%= d.v1;
124 d.v1 = math.rotl(u64, d.v1, u64(13));
124 d.v1 = math.rotl(u64, d.v1, @as(u64, 13));
125125 d.v1 ^= d.v0;
126 d.v0 = math.rotl(u64, d.v0, u64(32));
126 d.v0 = math.rotl(u64, d.v0, @as(u64, 32));
127127 d.v2 +%= d.v3;
128 d.v3 = math.rotl(u64, d.v3, u64(16));
128 d.v3 = math.rotl(u64, d.v3, @as(u64, 16));
129129 d.v3 ^= d.v2;
130130 d.v0 +%= d.v3;
131 d.v3 = math.rotl(u64, d.v3, u64(21));
131 d.v3 = math.rotl(u64, d.v3, @as(u64, 21));
132132 d.v3 ^= d.v0;
133133 d.v2 +%= d.v1;
134 d.v1 = math.rotl(u64, d.v1, u64(17));
134 d.v1 = math.rotl(u64, d.v1, @as(u64, 17));
135135 d.v1 ^= d.v2;
136 d.v2 = math.rotl(u64, d.v2, u64(32));
136 d.v2 = math.rotl(u64, d.v2, @as(u64, 32));
137137 }
138138
139139 pub fn hash(key: []const u8, input: []const u8) T {
lib/std/hash_map.zig+1-1
......@@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
402402 }
403403
404404 fn keyToIndex(hm: Self, key: K) usize {
405 return hm.constrainIndex(usize(hash(key)));
405 return hm.constrainIndex(@as(usize, hash(key)));
406406 }
407407
408408 fn constrainIndex(hm: Self, i: usize) usize {
lib/std/heap.zig+2-2
......@@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
893893 if (mem.page_size << 2 > maxInt(usize)) return;
894894
895895 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
896 const large_align = u29(mem.page_size << 2);
896 const large_align = @as(u29, mem.page_size << 2);
897897
898898 var align_mask: usize = undefined;
899 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask);
899 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
900900
901901 var slice = try allocator.alignedAlloc(u8, large_align, 500);
902902 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
lib/std/http/headers.zig+5-5
......@@ -399,7 +399,7 @@ test "Headers.iterator" {
399399 }
400400 count += 1;
401401 }
402 testing.expectEqual(i32(2), count);
402 testing.expectEqual(@as(i32, 2), count);
403403}
404404
405405test "Headers.contains" {
......@@ -420,10 +420,10 @@ test "Headers.delete" {
420420 try h.append("cookie", "somevalue", null);
421421
422422 testing.expectEqual(false, h.delete("not-present"));
423 testing.expectEqual(usize(3), h.count());
423 testing.expectEqual(@as(usize, 3), h.count());
424424
425425 testing.expectEqual(true, h.delete("foo"));
426 testing.expectEqual(usize(2), h.count());
426 testing.expectEqual(@as(usize, 2), h.count());
427427 {
428428 const e = h.at(0);
429429 testing.expectEqualSlices(u8, "baz", e.name);
......@@ -448,7 +448,7 @@ test "Headers.orderedRemove" {
448448 try h.append("cookie", "somevalue", null);
449449
450450 h.orderedRemove(0);
451 testing.expectEqual(usize(2), h.count());
451 testing.expectEqual(@as(usize, 2), h.count());
452452 {
453453 const e = h.at(0);
454454 testing.expectEqualSlices(u8, "baz", e.name);
......@@ -471,7 +471,7 @@ test "Headers.swapRemove" {
471471 try h.append("cookie", "somevalue", null);
472472
473473 h.swapRemove(0);
474 testing.expectEqual(usize(2), h.count());
474 testing.expectEqual(@as(usize, 2), h.count());
475475 {
476476 const e = h.at(0);
477477 testing.expectEqualSlices(u8, "cookie", e.name);
lib/std/io.zig+15-15
......@@ -353,21 +353,21 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
353353 const Buf = @IntType(false, buf_bit_count);
354354 const BufShift = math.Log2Int(Buf);
355355
356 out_bits.* = usize(0);
356 out_bits.* = @as(usize, 0);
357357 if (U == u0 or bits == 0) return 0;
358 var out_buffer = Buf(0);
358 var out_buffer = @as(Buf, 0);
359359
360360 if (self.bit_count > 0) {
361361 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
362362 const shift = u7_bit_count - n;
363363 switch (endian) {
364364 builtin.Endian.Big => {
365 out_buffer = Buf(self.bit_buffer >> shift);
365 out_buffer = @as(Buf, self.bit_buffer >> shift);
366366 self.bit_buffer <<= n;
367367 },
368368 builtin.Endian.Little => {
369369 const value = (self.bit_buffer << shift) >> shift;
370 out_buffer = Buf(value);
370 out_buffer = @as(Buf, value);
371371 self.bit_buffer >>= n;
372372 },
373373 }
......@@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
393393 if (n >= u8_bit_count) {
394394 out_buffer <<= @intCast(u3, u8_bit_count - 1);
395395 out_buffer <<= 1;
396 out_buffer |= Buf(next_byte);
396 out_buffer |= @as(Buf, next_byte);
397397 out_bits.* += u8_bit_count;
398398 continue;
399399 }
400400
401401 const shift = @intCast(u3, u8_bit_count - n);
402402 out_buffer <<= @intCast(BufShift, n);
403 out_buffer |= Buf(next_byte >> shift);
403 out_buffer |= @as(Buf, next_byte >> shift);
404404 out_bits.* += n;
405405 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
406406 self.bit_count = shift;
407407 },
408408 builtin.Endian.Little => {
409409 if (n >= u8_bit_count) {
410 out_buffer |= Buf(next_byte) << @intCast(BufShift, out_bits.*);
410 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
411411 out_bits.* += u8_bit_count;
412412 continue;
413413 }
414414
415415 const shift = @intCast(u3, u8_bit_count - n);
416416 const value = (next_byte << shift) >> shift;
417 out_buffer |= Buf(value) << @intCast(BufShift, out_bits.*);
417 out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*);
418418 out_bits.* += n;
419419 self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));
420420 self.bit_count = shift;
......@@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
434434 var self = @fieldParentPtr(Self, "stream", self_stream);
435435
436436 var out_bits: usize = undefined;
437 var out_bits_total = usize(0);
437 var out_bits_total = @as(usize, 0);
438438 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
439439 if (self.bit_count > 0) {
440440 for (buffer) |*b, i| {
......@@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
949949 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
950950 }
951951
952 var result = U(0);
952 var result = @as(U, 0);
953953 for (buffer) |byte, i| {
954954 switch (endian) {
955955 builtin.Endian.Big => {
956956 result = (result << u8_bit_count) | byte;
957957 },
958958 builtin.Endian.Little => {
959 result |= U(byte) << @intCast(Log2U, u8_bit_count * i);
959 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
960960 },
961961 }
962962 }
......@@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
10501050 return;
10511051 }
10521052
1053 ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe
1053 ptr.* = @as(OC, undefined); //make it non-null so the following .? is guaranteed safe
10541054 const val_ptr = &ptr.*.?;
10551055 try self.deserializeInto(val_ptr);
10561056 },
......@@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11541154
11551155 switch (@typeId(T)) {
11561156 builtin.TypeId.Void => return,
1157 builtin.TypeId.Bool => try self.serializeInt(u1(@boolToInt(value))),
1157 builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
11581158 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
11591159 builtin.TypeId.Struct => {
11601160 const info = @typeInfo(T);
......@@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11971197 },
11981198 builtin.TypeId.Optional => {
11991199 if (value == null) {
1200 try self.serializeInt(u1(@boolToInt(false)));
1200 try self.serializeInt(@as(u1, @boolToInt(false)));
12011201 return;
12021202 }
1203 try self.serializeInt(u1(@boolToInt(true)));
1203 try self.serializeInt(@as(u1, @boolToInt(true)));
12041204
12051205 const OC = comptime meta.Child(T);
12061206 const val_ptr = &value.?;
lib/std/io/out_stream.zig+2-2
......@@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type {
4040 }
4141
4242 pub fn writeByte(self: *Self, byte: u8) Error!void {
43 const slice = (*const [1]u8)(&byte)[0..];
43 const slice = @as(*const [1]u8, &byte)[0..];
4444 return self.writeFn(self, slice);
4545 }
4646
4747 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {
48 const slice = (*const [1]u8)(&byte)[0..];
48 const slice = @as(*const [1]u8, &byte)[0..];
4949 var i: usize = 0;
5050 while (i < n) : (i += 1) {
5151 try self.writeFn(self, slice);
lib/std/io/test.zig+32-32
......@@ -226,49 +226,49 @@ test "BitOutStream" {
226226 const OutError = io.SliceOutStream.Error;
227227 var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream);
228228
229 try bit_stream_be.writeBits(u2(1), 1);
230 try bit_stream_be.writeBits(u5(2), 2);
231 try bit_stream_be.writeBits(u128(3), 3);
232 try bit_stream_be.writeBits(u8(4), 4);
233 try bit_stream_be.writeBits(u9(5), 5);
234 try bit_stream_be.writeBits(u1(1), 1);
229 try bit_stream_be.writeBits(@as(u2, 1), 1);
230 try bit_stream_be.writeBits(@as(u5, 2), 2);
231 try bit_stream_be.writeBits(@as(u128, 3), 3);
232 try bit_stream_be.writeBits(@as(u8, 4), 4);
233 try bit_stream_be.writeBits(@as(u9, 5), 5);
234 try bit_stream_be.writeBits(@as(u1, 1), 1);
235235
236236 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
237237
238238 mem_out_be.pos = 0;
239239
240 try bit_stream_be.writeBits(u15(0b110011010000101), 15);
240 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
241241 try bit_stream_be.flushBits();
242242 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
243243
244244 mem_out_be.pos = 0;
245 try bit_stream_be.writeBits(u32(0b110011010000101), 16);
245 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
246246 expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
247247
248 try bit_stream_be.writeBits(u0(0), 0);
248 try bit_stream_be.writeBits(@as(u0, 0), 0);
249249
250250 var mem_out_le = io.SliceOutStream.init(mem_le[0..]);
251251 var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream);
252252
253 try bit_stream_le.writeBits(u2(1), 1);
254 try bit_stream_le.writeBits(u5(2), 2);
255 try bit_stream_le.writeBits(u128(3), 3);
256 try bit_stream_le.writeBits(u8(4), 4);
257 try bit_stream_le.writeBits(u9(5), 5);
258 try bit_stream_le.writeBits(u1(1), 1);
253 try bit_stream_le.writeBits(@as(u2, 1), 1);
254 try bit_stream_le.writeBits(@as(u5, 2), 2);
255 try bit_stream_le.writeBits(@as(u128, 3), 3);
256 try bit_stream_le.writeBits(@as(u8, 4), 4);
257 try bit_stream_le.writeBits(@as(u9, 5), 5);
258 try bit_stream_le.writeBits(@as(u1, 1), 1);
259259
260260 expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
261261
262262 mem_out_le.pos = 0;
263 try bit_stream_le.writeBits(u15(0b110011010000101), 15);
263 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
264264 try bit_stream_le.flushBits();
265265 expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
266266
267267 mem_out_le.pos = 0;
268 try bit_stream_le.writeBits(u32(0b1100110100001011), 16);
268 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
269269 expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
270270
271 try bit_stream_le.writeBits(u0(0), 0);
271 try bit_stream_le.writeBits(@as(u0, 0), 0);
272272}
273273
274274test "BitStreams with File Stream" {
......@@ -282,12 +282,12 @@ test "BitStreams with File Stream" {
282282 const OutError = File.WriteError;
283283 var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream);
284284
285 try bit_stream.writeBits(u2(1), 1);
286 try bit_stream.writeBits(u5(2), 2);
287 try bit_stream.writeBits(u128(3), 3);
288 try bit_stream.writeBits(u8(4), 4);
289 try bit_stream.writeBits(u9(5), 5);
290 try bit_stream.writeBits(u1(1), 1);
285 try bit_stream.writeBits(@as(u2, 1), 1);
286 try bit_stream.writeBits(@as(u5, 2), 2);
287 try bit_stream.writeBits(@as(u128, 3), 3);
288 try bit_stream.writeBits(@as(u8, 4), 4);
289 try bit_stream.writeBits(@as(u9, 5), 5);
290 try bit_stream.writeBits(@as(u1, 1), 1);
291291 try bit_stream.flushBits();
292292 }
293293 {
......@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
345345 inline while (i <= max_test_bitsize) : (i += 1) {
346346 const U = @IntType(false, i);
347347 const S = @IntType(true, i);
348 try serializer.serializeInt(U(i));
349 if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0));
348 try serializer.serializeInt(@as(U, i));
349 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
350350 }
351351 try serializer.flush();
352352
......@@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
356356 const S = @IntType(true, i);
357357 const x = try deserializer.deserializeInt(U);
358358 const y = try deserializer.deserializeInt(S);
359 expect(x == U(i));
360 if (i != 0) expect(y == S(-1)) else expect(y == 0);
359 expect(x == @as(U, i));
360 if (i != 0) expect(y == @as(S, -1)) else expect(y == 0);
361361 }
362362
363363 const u8_bit_count = comptime meta.bitCount(u8);
......@@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v
577577 var in_stream = &in.stream;
578578 var deserializer = io.Deserializer(endian, packing, InError).init(in_stream);
579579
580 try serializer.serialize(u14(3));
580 try serializer.serialize(@as(u14, 3));
581581 expectError(error.InvalidEnumTag, deserializer.deserialize(A));
582582 out.pos = 0;
583 try serializer.serialize(u14(3));
584 try serializer.serialize(u14(88));
583 try serializer.serialize(@as(u14, 3));
584 try serializer.serialize(@as(u14, 88));
585585 expectError(error.InvalidEnumTag, deserializer.deserialize(C));
586586}
587587
......@@ -603,7 +603,7 @@ test "c out stream" {
603603 }
604604
605605 const out_stream = &io.COutStream.init(out_file).stream;
606 try out_stream.print("hi: {}\n", i32(123));
606 try out_stream.print("hi: {}\n", @as(i32, 123));
607607}
608608
609609test "File seek ops" {
lib/std/json.zig+2-2
......@@ -1343,7 +1343,7 @@ test "write json then parse it" {
13431343 try jw.emitBool(true);
13441344
13451345 try jw.objectField("int");
1346 try jw.emitNumber(i32(1234));
1346 try jw.emitNumber(@as(i32, 1234));
13471347
13481348 try jw.objectField("array");
13491349 try jw.beginArray();
......@@ -1352,7 +1352,7 @@ test "write json then parse it" {
13521352 try jw.emitNull();
13531353
13541354 try jw.arrayElem();
1355 try jw.emitNumber(f64(12.34));
1355 try jw.emitNumber(@as(f64, 12.34));
13561356
13571357 try jw.endArray();
13581358
lib/std/lazy_init.zig+1-1
......@@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type {
3939 },
4040 2 => {
4141 if (@sizeOf(T) == 0) {
42 return T(undefined);
42 return @as(T, undefined);
4343 } else {
4444 return &self.data;
4545 }
lib/std/math.zig+80-80
......@@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079;
4444pub const sqrt1_2 = 0.707106781186547524400844362104849039;
4545
4646// From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128)
47pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001));
48pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000));
49pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
50pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000));
47pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001));
48pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000));
49pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
50pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000));
5151pub const f128_toint = 1.0 / f128_epsilon;
5252
5353// float.h details
......@@ -69,28 +69,28 @@ pub const f16_max = 65504;
6969pub const f16_epsilon = 0.0009765625; // 2**-10
7070pub const f16_toint = 1.0 / f16_epsilon;
7171
72pub const nan_u16 = u16(0x7C01);
72pub const nan_u16 = @as(u16, 0x7C01);
7373pub const nan_f16 = @bitCast(f16, nan_u16);
7474
75pub const inf_u16 = u16(0x7C00);
75pub const inf_u16 = @as(u16, 0x7C00);
7676pub const inf_f16 = @bitCast(f16, inf_u16);
7777
78pub const nan_u32 = u32(0x7F800001);
78pub const nan_u32 = @as(u32, 0x7F800001);
7979pub const nan_f32 = @bitCast(f32, nan_u32);
8080
81pub const inf_u32 = u32(0x7F800000);
81pub const inf_u32 = @as(u32, 0x7F800000);
8282pub const inf_f32 = @bitCast(f32, inf_u32);
8383
84pub const nan_u64 = u64(0x7FF << 52) | 1;
84pub const nan_u64 = @as(u64, 0x7FF << 52) | 1;
8585pub const nan_f64 = @bitCast(f64, nan_u64);
8686
87pub const inf_u64 = u64(0x7FF << 52);
87pub const inf_u64 = @as(u64, 0x7FF << 52);
8888pub const inf_f64 = @bitCast(f64, inf_u64);
8989
90pub const nan_u128 = u128(0x7fff0000000000000000000000000001);
90pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
9191pub const nan_f128 = @bitCast(f128, nan_u128);
9292
93pub const inf_u128 = u128(0x7fff0000000000000000000000000000);
93pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000);
9494pub const inf_f128 = @bitCast(f128, inf_u128);
9595
9696pub const nan = @import("math/nan.zig").nan;
......@@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type {
248248 },
249249 else => {},
250250 }
251 return @typeOf(A(0) + B(0));
251 return @typeOf(@as(A, 0) + @as(B, 0));
252252}
253253
254254/// 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)) {
273273}
274274
275275test "math.min" {
276 testing.expect(min(i32(-1), i32(2)) == -1);
276 testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
277277 {
278278 var a: u16 = 999;
279279 var b: u32 = 10;
......@@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
309309}
310310
311311test "math.max" {
312 testing.expect(max(i32(-1), i32(2)) == 2);
312 testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
313313}
314314
315315pub 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 {
352352}
353353
354354test "math.shl" {
355 testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000);
356 testing.expect(shl(u8, 0b11111111, usize(8)) == 0);
357 testing.expect(shl(u8, 0b11111111, usize(9)) == 0);
358 testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111);
355 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
356 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
357 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
358 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
359359 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
360360 testing.expect(shl(u8, 0b11111111, 8) == 0);
361361 testing.expect(shl(u8, 0b11111111, 9) == 0);
......@@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
380380}
381381
382382test "math.shr" {
383 testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111);
384 testing.expect(shr(u8, 0b11111111, usize(8)) == 0);
385 testing.expect(shr(u8, 0b11111111, usize(9)) == 0);
386 testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100);
383 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
384 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
385 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
386 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
387387 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
388388 testing.expect(shr(u8, 0b11111111, 8) == 0);
389389 testing.expect(shr(u8, 0b11111111, 9) == 0);
......@@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
402402}
403403
404404test "math.rotr" {
405 testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001);
406 testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000);
407 testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001);
408 testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000);
409 testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);
405 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
406 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
407 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
408 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
409 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
410410}
411411
412412/// Rotates left. Only unsigned values can be rotated.
......@@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
421421}
422422
423423test "math.rotl" {
424 testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001);
425 testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010);
426 testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001);
427 testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000);
428 testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);
424 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
425 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
426 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
427 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
428 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
429429}
430430
431431pub fn Log2Int(comptime T: type) type {
......@@ -532,8 +532,8 @@ test "math.absInt" {
532532 comptime testAbsInt();
533533}
534534fn testAbsInt() void {
535 testing.expect((absInt(i32(-10)) catch unreachable) == 10);
536 testing.expect((absInt(i32(10)) catch unreachable) == 10);
535 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
536 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
537537}
538538
539539pub const absFloat = fabs;
......@@ -543,8 +543,8 @@ test "math.absFloat" {
543543 comptime testAbsFloat();
544544}
545545fn testAbsFloat() void {
546 testing.expect(absFloat(f32(-10.05)) == 10.05);
547 testing.expect(absFloat(f32(10.05)) == 10.05);
546 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
547 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
548548}
549549
550550pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
......@@ -679,14 +679,14 @@ pub fn absCast(x: var) t: {
679679}
680680
681681test "math.absCast" {
682 testing.expect(absCast(i32(-999)) == 999);
683 testing.expect(@typeOf(absCast(i32(-999))) == u32);
682 testing.expect(absCast(@as(i32, -999)) == 999);
683 testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);
684684
685 testing.expect(absCast(i32(999)) == 999);
686 testing.expect(@typeOf(absCast(i32(999))) == u32);
685 testing.expect(absCast(@as(i32, 999)) == 999);
686 testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);
687687
688 testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));
689 testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);
688 testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
689 testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);
690690
691691 testing.expect(absCast(-999) == 999);
692692}
......@@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
705705}
706706
707707test "math.negateCast" {
708 testing.expect((negateCast(u32(999)) catch unreachable) == -999);
709 testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
708 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
709 testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
710710
711 testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
712 testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
711 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
712 testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
713713
714 testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10)));
714 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
715715}
716716
717717/// 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) {
729729}
730730
731731test "math.cast" {
732 testing.expectError(error.Overflow, cast(u8, u32(300)));
733 testing.expectError(error.Overflow, cast(i8, i32(-200)));
734 testing.expectError(error.Overflow, cast(u8, i8(-1)));
735 testing.expectError(error.Overflow, cast(u64, i8(-1)));
732 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
733 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
734 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
735 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
736736
737 testing.expect((try cast(u8, u32(255))) == u8(255));
738 testing.expect(@typeOf(try cast(u8, u32(255))) == u8);
737 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
738 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
739739}
740740
741741pub const AlignCastError = error{UnalignedMemory};
......@@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
786786 comptime assert(@typeId(T) == builtin.TypeId.Int);
787787 comptime assert(!T.is_signed);
788788 assert(value != 0);
789 comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
790 comptime const shiftType = std.math.Log2Int(promotedType);
791 return promotedType(1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
789 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
790 comptime const shiftType = std.math.Log2Int(PromotedType);
791 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
792792}
793793
794794/// Returns the next power of two (if the value is not already a power of two).
......@@ -797,8 +797,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
797797pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
798798 comptime assert(@typeId(T) == builtin.TypeId.Int);
799799 comptime assert(!T.is_signed);
800 comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
801 comptime const overflowBit = promotedType(1) << T.bit_count;
800 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
801 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
802802 var x = ceilPowerOfTwoPromote(T, value);
803803 if (overflowBit & x != 0) {
804804 return error.Overflow;
......@@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" {
812812}
813813
814814fn testCeilPowerOfTwoPromote() void {
815 testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1));
816 testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2));
817 testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63));
818 testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64));
819 testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65));
820 testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7));
821 testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8));
822 testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9));
823 testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9));
815 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
816 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
817 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
818 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
819 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
820 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
821 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
822 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
823 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
824824}
825825
826826test "math.ceilPowerOfTwo" {
......@@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" {
829829}
830830
831831fn testCeilPowerOfTwo() !void {
832 testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1));
833 testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2));
834 testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63));
835 testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64));
836 testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65));
837 testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7));
838 testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8));
839 testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9));
832 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
833 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
834 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
835 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
836 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
837 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
838 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
839 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
840840 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
841841}
842842
......@@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
848848pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
849849 assert(x != 0);
850850 const log2_val = log2_int(T, x);
851 if (T(1) << log2_val == x)
851 if (@as(T, 1) << log2_val == x)
852852 return log2_val;
853853 return log2_val + 1;
854854}
......@@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T {
870870 switch (@typeInfo(@typeOf(value))) {
871871 builtin.TypeId.Int => return @intToFloat(T, value),
872872 builtin.TypeId.Float => return @floatCast(T, value),
873 builtin.TypeId.ComptimeInt => return T(value),
874 builtin.TypeId.ComptimeFloat => return T(value),
873 builtin.TypeId.ComptimeInt => return @as(T, value),
874 builtin.TypeId.ComptimeFloat => return @as(T, value),
875875 else => @compileError("bad type"),
876876 }
877877}
......@@ -944,7 +944,7 @@ test "max value type" {
944944
945945pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
946946 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
947 return ResultInt(a) * ResultInt(b);
947 return @as(ResultInt, a) * @as(ResultInt, b);
948948}
949949
950950test "math.mulWide" {
lib/std/math/acos.zig+2-2
......@@ -149,8 +149,8 @@ fn acos64(x: f64) f64 {
149149}
150150
151151test "math.acos" {
152 expect(acos(f32(0.0)) == acos32(0.0));
153 expect(acos(f64(0.0)) == acos64(0.0));
152 expect(acos(@as(f32, 0.0)) == acos32(0.0));
153 expect(acos(@as(f64, 0.0)) == acos64(0.0));
154154}
155155
156156test "math.acos32" {
lib/std/math/acosh.zig+2-2
......@@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 {
6161}
6262
6363test "math.acosh" {
64 expect(acosh(f32(1.5)) == acosh32(1.5));
65 expect(acosh(f64(1.5)) == acosh64(1.5));
64 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
65 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
6666}
6767
6868test "math.acosh32" {
lib/std/math/asin.zig+2-2
......@@ -142,8 +142,8 @@ fn asin64(x: f64) f64 {
142142}
143143
144144test "math.asin" {
145 expect(asin(f32(0.0)) == asin32(0.0));
146 expect(asin(f64(0.0)) == asin64(0.0));
145 expect(asin(@as(f32, 0.0)) == asin32(0.0));
146 expect(asin(@as(f64, 0.0)) == asin64(0.0));
147147}
148148
149149test "math.asin32" {
lib/std/math/asinh.zig+2-2
......@@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 {
8989}
9090
9191test "math.asinh" {
92 expect(asinh(f32(0.0)) == asinh32(0.0));
93 expect(asinh(f64(0.0)) == asinh64(0.0));
92 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
93 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
9494}
9595
9696test "math.asinh32" {
lib/std/math/atan.zig+2-2
......@@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 {
212212}
213213
214214test "math.atan" {
215 expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));
216 expect(atan(f64(0.2)) == atan64(0.2));
215 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
216 expect(atan(@as(f64, 0.2)) == atan64(0.2));
217217}
218218
219219test "math.atan32" {
lib/std/math/atanh.zig+2-2
......@@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 {
8484}
8585
8686test "math.atanh" {
87 expect(atanh(f32(0.0)) == atanh_32(0.0));
88 expect(atanh(f64(0.0)) == atanh_64(0.0));
87 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
88 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
8989}
9090
9191test "math.atanh_32" {
lib/std/math/big/int.zig+11-11
......@@ -261,7 +261,7 @@ pub const Int = struct {
261261 /// the minus sign. This is used for determining the number of characters needed to print the
262262 /// value. It is inexact and may exceed the given value by ~1-2 bytes.
263263 pub fn sizeInBase(self: Int, base: usize) usize {
264 const bit_count = usize(@boolToInt(!self.isPositive())) + self.bitCountAbs();
264 const bit_count = @as(usize, @boolToInt(!self.isPositive())) + self.bitCountAbs();
265265 return (bit_count / math.log2(base)) + 1;
266266 }
267267
......@@ -281,7 +281,7 @@ pub const Int = struct {
281281 var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);
282282
283283 if (info.bits <= Limb.bit_count) {
284 self.limbs[0] = Limb(w_value);
284 self.limbs[0] = @as(Limb, w_value);
285285 self.metadata += 1;
286286 } else {
287287 var i: usize = 0;
......@@ -453,7 +453,7 @@ pub const Int = struct {
453453 for (self.limbs[0..self.len()]) |limb| {
454454 var shift: usize = 0;
455455 while (shift < Limb.bit_count) : (shift += base_shift) {
456 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & Limb(base - 1));
456 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));
457457 const ch = try digitToChar(r, base);
458458 try digits.append(ch);
459459 }
......@@ -560,7 +560,7 @@ pub const Int = struct {
560560 /// Returns -1, 0, 1 if a < b, a == b or a > b respectively.
561561 pub fn cmp(a: Int, b: Int) i8 {
562562 if (a.isPositive() != b.isPositive()) {
563 return if (a.isPositive()) i8(1) else -1;
563 return if (a.isPositive()) @as(i8, 1) else -1;
564564 } else {
565565 const r = cmpAbs(a, b);
566566 return if (a.isPositive()) r else -r;
......@@ -785,7 +785,7 @@ pub const Int = struct {
785785 const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1));
786786
787787 // r2 = b * c
788 const bc = DoubleLimb(math.mulWide(Limb, b, c));
788 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
789789 const r2 = @truncate(Limb, bc);
790790 const c2 = @truncate(Limb, bc >> Limb.bit_count);
791791
......@@ -1084,7 +1084,7 @@ pub const Int = struct {
10841084 rem.* = 0;
10851085 for (a) |_, ri| {
10861086 const i = a.len - ri - 1;
1087 const pdiv = ((DoubleLimb(rem.*) << Limb.bit_count) | a[i]);
1087 const pdiv = ((@as(DoubleLimb, rem.*) << Limb.bit_count) | a[i]);
10881088
10891089 if (pdiv == 0) {
10901090 quo[i] = 0;
......@@ -1143,9 +1143,9 @@ pub const Int = struct {
11431143 if (x.limbs[i] == y.limbs[t]) {
11441144 q.limbs[i - t - 1] = maxInt(Limb);
11451145 } else {
1146 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);
1147 const z = @intCast(Limb, num / DoubleLimb(y.limbs[t]));
1148 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z);
1146 const num = (@as(DoubleLimb, x.limbs[i]) << Limb.bit_count) | @as(DoubleLimb, x.limbs[i - 1]);
1147 const z = @intCast(Limb, num / @as(DoubleLimb, y.limbs[t]));
1148 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else @as(Limb, z);
11491149 }
11501150
11511151 // 3.2
......@@ -1362,7 +1362,7 @@ test "big.int comptime_int set" {
13621362
13631363 comptime var i: usize = 0;
13641364 inline while (i < s_limb_count) : (i += 1) {
1365 const result = Limb(s & maxInt(Limb));
1365 const result = @as(Limb, s & maxInt(Limb));
13661366 s >>= Limb.bit_count / 2;
13671367 s >>= Limb.bit_count / 2;
13681368 testing.expect(a.limbs[i] == result);
......@@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" {
13771377}
13781378
13791379test "big.int int set unaligned small" {
1380 var a = try Int.initSet(al, u7(45));
1380 var a = try Int.initSet(al, @as(u7, 45));
13811381
13821382 testing.expect(a.limbs[0] == 45);
13831383 testing.expect(a.isPositive() == true);
lib/std/math/cbrt.zig+5-5
......@@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 {
5454 // first step newton to 16 bits
5555 var t: f64 = @bitCast(f32, u);
5656 var r: f64 = t * t * t;
57 t = t * (f64(x) + x + r) / (x + r + r);
57 t = t * (@as(f64, x) + x + r) / (x + r + r);
5858
5959 // second step newton to 47 bits
6060 r = t * t * t;
61 t = t * (f64(x) + x + r) / (x + r + r);
61 t = t * (@as(f64, x) + x + r) / (x + r + r);
6262
6363 return @floatCast(f32, t);
6464}
......@@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 {
9797 }
9898
9999 u &= 1 << 63;
100 u |= u64(hx) << 32;
100 u |= @as(u64, hx) << 32;
101101 var t = @bitCast(f64, u);
102102
103103 // cbrt to 23 bits
......@@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 {
120120}
121121
122122test "math.cbrt" {
123 expect(cbrt(f32(0.0)) == cbrt32(0.0));
124 expect(cbrt(f64(0.0)) == cbrt64(0.0));
123 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
124 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
125125}
126126
127127test "math.cbrt32" {
lib/std/math/ceil.zig+3-3
......@@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 {
3737 if (e >= 23) {
3838 return x;
3939 } else if (e >= 0) {
40 m = u32(0x007FFFFF) >> @intCast(u5, e);
40 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
4141 if (u & m == 0) {
4242 return x;
4343 }
......@@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 {
8787}
8888
8989test "math.ceil" {
90 expect(ceil(f32(0.0)) == ceil32(0.0));
91 expect(ceil(f64(0.0)) == ceil64(0.0));
90 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
91 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
9292}
9393
9494test "math.ceil32" {
lib/std/math/complex.zig+4-4
......@@ -133,8 +133,8 @@ test "complex.div" {
133133 const b = Complex(f32).new(2, 7);
134134 const c = a.div(b);
135135
136 testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
137 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
136 testing.expect(math.approxEq(f32, c.re, @as(f32, 31) / 53, epsilon) and
137 math.approxEq(f32, c.im, @as(f32, -29) / 53, epsilon));
138138}
139139
140140test "complex.conjugate" {
......@@ -148,8 +148,8 @@ test "complex.reciprocal" {
148148 const a = Complex(f32).new(5, 3);
149149 const c = a.reciprocal();
150150
151 testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
152 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
151 testing.expect(math.approxEq(f32, c.re, @as(f32, 5) / 34, epsilon) and
152 math.approxEq(f32, c.im, @as(f32, -3) / 34, epsilon));
153153}
154154
155155test "complex.magnitude" {
lib/std/math/complex/acos.zig+1-1
......@@ -8,7 +8,7 @@ const Complex = cmath.Complex;
88pub fn acos(z: var) Complex(@typeOf(z.re)) {
99 const T = @typeOf(z.re);
1010 const q = cmath.asin(z);
11 return Complex(T).new(T(math.pi) / 2 - q.re, -q.im);
11 return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);
1212}
1313
1414const epsilon = 0.0001;
lib/std/math/complex/ldexp.zig+2-2
......@@ -59,13 +59,13 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
5959 expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
6060
6161 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
62 return @bitCast(f64, (u64(high_word) << 32) | lx);
62 return @bitCast(f64, (@as(u64, high_word) << 32) | lx);
6363}
6464
6565fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
6666 var ex_expt: i32 = undefined;
6767 const exp_x = frexp_exp64(z.re, &ex_expt);
68 const exptf = i64(expt + ex_expt);
68 const exptf = @as(i64, expt + ex_expt);
6969
7070 const half_expt1 = @divTrunc(exptf, 2);
7171 const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20);
lib/std/math/complex/sqrt.zig+2-2
......@@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {
5252 // y = nan special case is handled fine below
5353
5454 // double-precision avoids overflow with correct rounding.
55 const dx = f64(x);
56 const dy = f64(y);
55 const dx = @as(f64, x);
56 const dy = @as(f64, y);
5757
5858 if (dx >= 0) {
5959 const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
lib/std/math/complex/tanh.zig+1-1
......@@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
7676 return Complex(f64).new(x, r);
7777 }
7878
79 const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx);
79 const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx);
8080 const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y);
8181 return Complex(f64).new(xx, math.copysign(f64, 0, r));
8282 }
lib/std/math/copysign.zig+3-3
......@@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 {
2424 const uy = @bitCast(u16, y);
2525
2626 const h1 = ux & (maxInt(u16) / 2);
27 const h2 = uy & (u16(1) << 15);
27 const h2 = uy & (@as(u16, 1) << 15);
2828 return @bitCast(f16, h1 | h2);
2929}
3030
......@@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 {
3333 const uy = @bitCast(u32, y);
3434
3535 const h1 = ux & (maxInt(u32) / 2);
36 const h2 = uy & (u32(1) << 31);
36 const h2 = uy & (@as(u32, 1) << 31);
3737 return @bitCast(f32, h1 | h2);
3838}
3939
......@@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 {
4242 const uy = @bitCast(u64, y);
4343
4444 const h1 = ux & (maxInt(u64) / 2);
45 const h2 = uy & (u64(1) << 63);
45 const h2 = uy & (@as(u64, 1) << 63);
4646 return @bitCast(f64, h1 | h2);
4747}
4848
lib/std/math/cos.zig+2-2
......@@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T {
8383}
8484
8585test "math.cos" {
86 expect(cos(f32(0.0)) == cos_(f32, 0.0));
87 expect(cos(f64(0.0)) == cos_(f64, 0.0));
86 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
87 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
8888}
8989
9090test "math.cos32" {
lib/std/math/cosh.zig+2-2
......@@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 {
8888}
8989
9090test "math.cosh" {
91 expect(cosh(f32(1.5)) == cosh32(1.5));
92 expect(cosh(f64(1.5)) == cosh64(1.5));
91 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
92 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
9393}
9494
9595test "math.cosh32" {
lib/std/math/exp.zig+3-3
......@@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 {
134134 }
135135 if (x < -708.39641853226410622) {
136136 // underflow if x != -inf
137 // math.forceEval(f32(-0x1.0p-149 / x));
137 // math.forceEval(@as(f32, -0x1.0p-149 / x));
138138 if (x < -745.13321910194110842) {
139139 return 0;
140140 }
......@@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 {
183183}
184184
185185test "math.exp" {
186 assert(exp(f32(0.0)) == exp32(0.0));
187 assert(exp(f64(0.0)) == exp64(0.0));
186 assert(exp(@as(f32, 0.0)) == exp32(0.0));
187 assert(exp(@as(f64, 0.0)) == exp64(0.0));
188188}
189189
190190test "math.exp32" {
lib/std/math/exp2.zig+3-3
......@@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 {
8585 const k = i_0 / tblsiz;
8686 // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the
8787 // intended result but should confirm how GCC/Clang handle this to ensure.
88 const uk = @bitCast(f64, u64(0x3FF + k) << 52);
88 const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52);
8989 i_0 &= tblsiz - 1;
9090 uf -= redux;
9191
......@@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 {
421421}
422422
423423test "math.exp2" {
424 expect(exp2(f32(0.8923)) == exp2_32(0.8923));
425 expect(exp2(f64(0.8923)) == exp2_64(0.8923));
424 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
425 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
426426}
427427
428428test "math.exp2_32" {
lib/std/math/expm1.zig+2-2
......@@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 {
287287}
288288
289289test "math.exp1m" {
290 expect(expm1(f32(0.0)) == expm1_32(0.0));
291 expect(expm1(f64(0.0)) == expm1_64(0.0));
290 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
291 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
292292}
293293
294294test "math.expm1_32" {
lib/std/math/expo2.zig+1-1
......@@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 {
3030 const kln2 = 0x1.62066151ADD8BP+10;
3131
3232 const u = (0x3FF + k / 2) << 20;
33 const scale = @bitCast(f64, u64(u) << 32);
33 const scale = @bitCast(f64, @as(u64, u) << 32);
3434 return math.exp(x - kln2) * scale * scale;
3535}
lib/std/math/fabs.zig+4-4
......@@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 {
5050}
5151
5252test "math.fabs" {
53 expect(fabs(f16(1.0)) == fabs16(1.0));
54 expect(fabs(f32(1.0)) == fabs32(1.0));
55 expect(fabs(f64(1.0)) == fabs64(1.0));
56 expect(fabs(f128(1.0)) == fabs128(1.0));
53 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
54 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
55 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
56 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
5757}
5858
5959test "math.fabs16" {
lib/std/math/floor.zig+5-5
......@@ -40,7 +40,7 @@ fn floor16(x: f16) f16 {
4040 }
4141
4242 if (e >= 0) {
43 m = u16(1023) >> @intCast(u4, e);
43 m = @as(u16, 1023) >> @intCast(u4, e);
4444 if (u & m == 0) {
4545 return x;
4646 }
......@@ -74,7 +74,7 @@ fn floor32(x: f32) f32 {
7474 }
7575
7676 if (e >= 0) {
77 m = u32(0x007FFFFF) >> @intCast(u5, e);
77 m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
7878 if (u & m == 0) {
7979 return x;
8080 }
......@@ -123,9 +123,9 @@ fn floor64(x: f64) f64 {
123123}
124124
125125test "math.floor" {
126 expect(floor(f16(1.3)) == floor16(1.3));
127 expect(floor(f32(1.3)) == floor32(1.3));
128 expect(floor(f64(1.3)) == floor64(1.3));
126 expect(floor(@as(f16, 1.3)) == floor16(1.3));
127 expect(floor(@as(f32, 1.3)) == floor32(1.3));
128 expect(floor(@as(f64, 1.3)) == floor64(1.3));
129129}
130130
131131test "math.floor16" {
lib/std/math/fma.zig+1-1
......@@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T {
1818}
1919
2020fn fma32(x: f32, y: f32, z: f32) f32 {
21 const xy = f64(x) * y;
21 const xy = @as(f64, x) * y;
2222 const xy_z = xy + z;
2323 const u = @bitCast(u64, xy_z);
2424 const e = (u >> 52) & 0x7FF;
lib/std/math/frexp.zig+2-2
......@@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result {
108108}
109109
110110test "math.frexp" {
111 const a = frexp(f32(1.3));
111 const a = frexp(@as(f32, 1.3));
112112 const b = frexp32(1.3);
113113 expect(a.significand == b.significand and a.exponent == b.exponent);
114114
115 const c = frexp(f64(1.3));
115 const c = frexp(@as(f64, 1.3));
116116 const d = frexp64(1.3);
117117 expect(c.significand == d.significand and c.exponent == d.exponent);
118118}
lib/std/math/hypot.zig+1-1
......@@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 {
5656 yy *= 0x1.0p-90;
5757 }
5858
59 return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y));
59 return z * math.sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y));
6060}
6161
6262fn sq(hi: *f64, lo: *f64, x: f64) void {
lib/std/math/ilogb.zig+3-3
......@@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 {
2626}
2727
2828// NOTE: Should these be exposed publicly?
29const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1);
29const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1);
3030const fp_ilogb0 = fp_ilogbnan;
3131
3232fn ilogb32(x: f32) i32 {
......@@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 {
101101}
102102
103103test "math.ilogb" {
104 expect(ilogb(f32(0.2)) == ilogb32(0.2));
105 expect(ilogb(f64(0.2)) == ilogb64(0.2));
104 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
105 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
106106}
107107
108108test "math.ilogb32" {
lib/std/math/isfinite.zig+6-6
......@@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool {
2626}
2727
2828test "math.isFinite" {
29 expect(isFinite(f16(0.0)));
30 expect(isFinite(f16(-0.0)));
31 expect(isFinite(f32(0.0)));
32 expect(isFinite(f32(-0.0)));
33 expect(isFinite(f64(0.0)));
34 expect(isFinite(f64(-0.0)));
29 expect(isFinite(@as(f16, 0.0)));
30 expect(isFinite(@as(f16, -0.0)));
31 expect(isFinite(@as(f32, 0.0)));
32 expect(isFinite(@as(f32, -0.0)));
33 expect(isFinite(@as(f64, 0.0)));
34 expect(isFinite(@as(f64, -0.0)));
3535 expect(!isFinite(math.inf(f16)));
3636 expect(!isFinite(-math.inf(f16)));
3737 expect(!isFinite(math.inf(f32)));
lib/std/math/isinf.zig+24-24
......@@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool {
7474}
7575
7676test "math.isInf" {
77 expect(!isInf(f16(0.0)));
78 expect(!isInf(f16(-0.0)));
79 expect(!isInf(f32(0.0)));
80 expect(!isInf(f32(-0.0)));
81 expect(!isInf(f64(0.0)));
82 expect(!isInf(f64(-0.0)));
83 expect(!isInf(f128(0.0)));
84 expect(!isInf(f128(-0.0)));
77 expect(!isInf(@as(f16, 0.0)));
78 expect(!isInf(@as(f16, -0.0)));
79 expect(!isInf(@as(f32, 0.0)));
80 expect(!isInf(@as(f32, -0.0)));
81 expect(!isInf(@as(f64, 0.0)));
82 expect(!isInf(@as(f64, -0.0)));
83 expect(!isInf(@as(f128, 0.0)));
84 expect(!isInf(@as(f128, -0.0)));
8585 expect(isInf(math.inf(f16)));
8686 expect(isInf(-math.inf(f16)));
8787 expect(isInf(math.inf(f32)));
......@@ -93,14 +93,14 @@ test "math.isInf" {
9393}
9494
9595test "math.isPositiveInf" {
96 expect(!isPositiveInf(f16(0.0)));
97 expect(!isPositiveInf(f16(-0.0)));
98 expect(!isPositiveInf(f32(0.0)));
99 expect(!isPositiveInf(f32(-0.0)));
100 expect(!isPositiveInf(f64(0.0)));
101 expect(!isPositiveInf(f64(-0.0)));
102 expect(!isPositiveInf(f128(0.0)));
103 expect(!isPositiveInf(f128(-0.0)));
96 expect(!isPositiveInf(@as(f16, 0.0)));
97 expect(!isPositiveInf(@as(f16, -0.0)));
98 expect(!isPositiveInf(@as(f32, 0.0)));
99 expect(!isPositiveInf(@as(f32, -0.0)));
100 expect(!isPositiveInf(@as(f64, 0.0)));
101 expect(!isPositiveInf(@as(f64, -0.0)));
102 expect(!isPositiveInf(@as(f128, 0.0)));
103 expect(!isPositiveInf(@as(f128, -0.0)));
104104 expect(isPositiveInf(math.inf(f16)));
105105 expect(!isPositiveInf(-math.inf(f16)));
106106 expect(isPositiveInf(math.inf(f32)));
......@@ -112,14 +112,14 @@ test "math.isPositiveInf" {
112112}
113113
114114test "math.isNegativeInf" {
115 expect(!isNegativeInf(f16(0.0)));
116 expect(!isNegativeInf(f16(-0.0)));
117 expect(!isNegativeInf(f32(0.0)));
118 expect(!isNegativeInf(f32(-0.0)));
119 expect(!isNegativeInf(f64(0.0)));
120 expect(!isNegativeInf(f64(-0.0)));
121 expect(!isNegativeInf(f128(0.0)));
122 expect(!isNegativeInf(f128(-0.0)));
115 expect(!isNegativeInf(@as(f16, 0.0)));
116 expect(!isNegativeInf(@as(f16, -0.0)));
117 expect(!isNegativeInf(@as(f32, 0.0)));
118 expect(!isNegativeInf(@as(f32, -0.0)));
119 expect(!isNegativeInf(@as(f64, 0.0)));
120 expect(!isNegativeInf(@as(f64, -0.0)));
121 expect(!isNegativeInf(@as(f128, 0.0)));
122 expect(!isNegativeInf(@as(f128, -0.0)));
123123 expect(!isNegativeInf(math.inf(f16)));
124124 expect(isNegativeInf(-math.inf(f16)));
125125 expect(!isNegativeInf(math.inf(f32)));
lib/std/math/isnan.zig+4-4
......@@ -20,8 +20,8 @@ test "math.isNan" {
2020 expect(isNan(math.nan(f32)));
2121 expect(isNan(math.nan(f64)));
2222 expect(isNan(math.nan(f128)));
23 expect(!isNan(f16(1.0)));
24 expect(!isNan(f32(1.0)));
25 expect(!isNan(f64(1.0)));
26 expect(!isNan(f128(1.0)));
23 expect(!isNan(@as(f16, 1.0)));
24 expect(!isNan(@as(f32, 1.0)));
25 expect(!isNan(@as(f64, 1.0)));
26 expect(!isNan(@as(f128, 1.0)));
2727}
lib/std/math/isnormal.zig+6-6
......@@ -29,10 +29,10 @@ test "math.isNormal" {
2929 expect(!isNormal(math.nan(f16)));
3030 expect(!isNormal(math.nan(f32)));
3131 expect(!isNormal(math.nan(f64)));
32 expect(!isNormal(f16(0)));
33 expect(!isNormal(f32(0)));
34 expect(!isNormal(f64(0)));
35 expect(isNormal(f16(1.0)));
36 expect(isNormal(f32(1.0)));
37 expect(isNormal(f64(1.0)));
32 expect(!isNormal(@as(f16, 0)));
33 expect(!isNormal(@as(f32, 0)));
34 expect(!isNormal(@as(f64, 0)));
35 expect(isNormal(@as(f16, 1.0)));
36 expect(isNormal(@as(f32, 1.0)));
37 expect(isNormal(@as(f64, 1.0)));
3838}
lib/std/math/ln.zig+5-5
......@@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) {
3131 };
3232 },
3333 TypeId.ComptimeInt => {
34 return @typeOf(1)(math.floor(ln_64(f64(x))));
34 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
3535 },
3636 TypeId.Int => {
37 return T(math.floor(ln_64(f64(x))));
37 return @as(T, math.floor(ln_64(@as(f64, x))));
3838 },
3939 else => @compileError("ln not implemented for " ++ @typeName(T)),
4040 }
......@@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 {
132132 hx += 0x3FF00000 - 0x3FE6A09E;
133133 k += @intCast(i32, hx >> 20) - 0x3FF;
134134 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
135 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
135 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
136136 x = @bitCast(f64, ix);
137137
138138 const f = x - 1.0;
......@@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 {
149149}
150150
151151test "math.ln" {
152 expect(ln(f32(0.2)) == ln_32(0.2));
153 expect(ln(f64(0.2)) == ln_64(0.2));
152 expect(ln(@as(f32, 0.2)) == ln_32(0.2));
153 expect(ln(@as(f64, 0.2)) == ln_64(0.2));
154154}
155155
156156test "math.ln32" {
lib/std/math/log.zig+7-7
......@@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
2323 const float_base = math.lossyCast(f64, base);
2424 switch (@typeId(T)) {
2525 TypeId.ComptimeFloat => {
26 return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base));
26 return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
2727 },
2828 TypeId.ComptimeInt => {
29 return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base)));
29 return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
3030 },
3131 builtin.TypeId.Int => {
3232 // TODO implement integer log without using float math
......@@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
3535
3636 builtin.TypeId.Float => {
3737 switch (T) {
38 f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)),
38 f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),
3939 f64 => return math.ln(x) / math.ln(float_base),
4040 else => @compileError("log not implemented for " ++ @typeName(T)),
4141 }
......@@ -64,9 +64,9 @@ test "math.log float" {
6464}
6565
6666test "math.log float_special" {
67 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
68 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
67 expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
68 expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
6969
70 expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));
71 expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));
70 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
71 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
7272}
lib/std/math/log10.zig+5-5
......@@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
3232 };
3333 },
3434 TypeId.ComptimeInt => {
35 return @typeOf(1)(math.floor(log10_64(f64(x))));
35 return @typeOf(1)(math.floor(log10_64(@as(f64, x))));
3636 },
3737 TypeId.Int => {
3838 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
......@@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 {
143143 hx += 0x3FF00000 - 0x3FE6A09E;
144144 k += @intCast(i32, hx >> 20) - 0x3FF;
145145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
146 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
146 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
147147 x = @bitCast(f64, ix);
148148
149149 const f = x - 1.0;
......@@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 {
158158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
159159 var hi = f - hfsq;
160160 var hii = @bitCast(u64, hi);
161 hii &= u64(maxInt(u64)) << 32;
161 hii &= @as(u64, maxInt(u64)) << 32;
162162 hi = @bitCast(f64, hii);
163163 const lo = f - hi - hfsq + s * (hfsq + R);
164164
......@@ -177,8 +177,8 @@ pub fn log10_64(x_: f64) f64 {
177177}
178178
179179test "math.log10" {
180 testing.expect(log10(f32(0.2)) == log10_32(0.2));
181 testing.expect(log10(f64(0.2)) == log10_64(0.2));
180 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
181 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
182182}
183183
184184test "math.log10_32" {
lib/std/math/log1p.zig+3-3
......@@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 {
166166
167167 // u into [sqrt(2)/2, sqrt(2)]
168168 iu = (iu & 0x000FFFFF) + 0x3FE6A09E;
169 const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF);
169 const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF);
170170 f = @bitCast(f64, iq) - 1;
171171 }
172172
......@@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 {
183183}
184184
185185test "math.log1p" {
186 expect(log1p(f32(0.0)) == log1p_32(0.0));
187 expect(log1p(f64(0.0)) == log1p_64(0.0));
186 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
187 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
188188}
189189
190190test "math.log1p_32" {
lib/std/math/log2.zig+4-4
......@@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 {
143143 hx += 0x3FF00000 - 0x3FE6A09E;
144144 k += @intCast(i32, hx >> 20) - 0x3FF;
145145 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
146 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
146 ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
147147 x = @bitCast(f64, ix);
148148
149149 const f = x - 1.0;
......@@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 {
158158 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
159159 var hi = f - hfsq;
160160 var hii = @bitCast(u64, hi);
161 hii &= u64(maxInt(u64)) << 32;
161 hii &= @as(u64, maxInt(u64)) << 32;
162162 hi = @bitCast(f64, hii);
163163 const lo = f - hi - hfsq + s * (hfsq + R);
164164
......@@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 {
175175}
176176
177177test "math.log2" {
178 expect(log2(f32(0.2)) == log2_32(0.2));
179 expect(log2(f64(0.2)) == log2_64(0.2));
178 expect(log2(@as(f32, 0.2)) == log2_32(0.2));
179 expect(log2(@as(f64, 0.2)) == log2_64(0.2));
180180}
181181
182182test "math.log2_32" {
lib/std/math/modf.zig+4-4
......@@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result {
6565 return result;
6666 }
6767
68 const mask = u32(0x007FFFFF) >> @intCast(u5, e);
68 const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
6969 if (u & mask == 0) {
7070 result.ipart = x;
7171 result.fpart = @bitCast(f32, us);
......@@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result {
109109 return result;
110110 }
111111
112 const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e);
112 const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e);
113113 if (u & mask == 0) {
114114 result.ipart = x;
115115 result.fpart = @bitCast(f64, us);
......@@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result {
123123}
124124
125125test "math.modf" {
126 const a = modf(f32(1.0));
126 const a = modf(@as(f32, 1.0));
127127 const b = modf32(1.0);
128128 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
129129 expect(a.ipart == b.ipart and a.fpart == b.fpart);
130130
131 const c = modf(f64(1.0));
131 const c = modf(@as(f64, 1.0));
132132 const d = modf64(1.0);
133133 expect(a.ipart == b.ipart and a.fpart == b.fpart);
134134}
lib/std/math/round.zig+2-2
......@@ -91,8 +91,8 @@ fn round64(x_: f64) f64 {
9191}
9292
9393test "math.round" {
94 expect(round(f32(1.3)) == round32(1.3));
95 expect(round(f64(1.3)) == round64(1.3));
94 expect(round(@as(f32, 1.3)) == round32(1.3));
95 expect(round(@as(f64, 1.3)) == round64(1.3));
9696}
9797
9898test "math.round32" {
lib/std/math/scalbn.zig+2-2
......@@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 {
7979}
8080
8181test "math.scalbn" {
82 expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));
83 expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));
82 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
83 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
8484}
8585
8686test "math.scalbn32" {
lib/std/math/signbit.zig+3-3
......@@ -29,9 +29,9 @@ fn signbit64(x: f64) bool {
2929}
3030
3131test "math.signbit" {
32 expect(signbit(f16(4.0)) == signbit16(4.0));
33 expect(signbit(f32(4.0)) == signbit32(4.0));
34 expect(signbit(f64(4.0)) == signbit64(4.0));
32 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
33 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
34 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
3535}
3636
3737test "math.signbit16" {
lib/std/math/sin.zig+3-3
......@@ -88,9 +88,9 @@ test "math.sin" {
8888 // TODO https://github.com/ziglang/zig/issues/3289
8989 return error.SkipZigTest;
9090 }
91 expect(sin(f32(0.0)) == sin_(f32, 0.0));
92 expect(sin(f64(0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(f64(2))) == math.sin(f64(2)));
91 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
92 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
9494}
9595
9696test "math.sin32" {
lib/std/math/sinh.zig+2-2
......@@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 {
9393}
9494
9595test "math.sinh" {
96 expect(sinh(f32(1.5)) == sinh32(1.5));
97 expect(sinh(f64(1.5)) == sinh64(1.5));
96 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
97 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
9898}
9999
100100test "math.sinh32" {
lib/std/math/sqrt.zig+5-5
......@@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;
1515pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
1616 const T = @typeOf(x);
1717 switch (@typeId(T)) {
18 TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128
18 TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
1919 TypeId.Float => return @sqrt(T, x),
2020 TypeId.ComptimeInt => comptime {
2121 if (x > maxInt(u128)) {
......@@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
2424 if (x < 0) {
2525 @compileError("sqrt on negative number");
2626 }
27 return T(sqrt_int(u128, x));
27 return @as(T, sqrt_int(u128, x));
2828 },
2929 TypeId.Int => return sqrt_int(T, x),
3030 else => @compileError("sqrt not implemented for " ++ @typeName(T)),
......@@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
3232}
3333
3434test "math.sqrt" {
35 expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
36 expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
37 expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
35 expect(sqrt(@as(f16, 0.0)) == @sqrt(f16, 0.0));
36 expect(sqrt(@as(f32, 0.0)) == @sqrt(f32, 0.0));
37 expect(sqrt(@as(f64, 0.0)) == @sqrt(f64, 0.0));
3838}
3939
4040test "math.sqrt16" {
lib/std/math/tan.zig+2-2
......@@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T {
7575}
7676
7777test "math.tan" {
78 expect(tan(f32(0.0)) == tan_(f32, 0.0));
79 expect(tan(f64(0.0)) == tan_(f64, 0.0));
78 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
79 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
8080}
8181
8282test "math.tan32" {
lib/std/math/tanh.zig+2-2
......@@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 {
119119}
120120
121121test "math.tanh" {
122 expect(tanh(f32(1.5)) == tanh32(1.5));
123 expect(tanh(f64(1.5)) == tanh64(1.5));
122 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
123 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
124124}
125125
126126test "math.tanh32" {
lib/std/math/trunc.zig+4-4
......@@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 {
3636 e = 1;
3737 }
3838
39 m = u32(maxInt(u32)) >> @intCast(u5, e);
39 m = @as(u32, maxInt(u32)) >> @intCast(u5, e);
4040 if (u & m == 0) {
4141 return x;
4242 } else {
......@@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 {
5757 e = 1;
5858 }
5959
60 m = u64(maxInt(u64)) >> @intCast(u6, e);
60 m = @as(u64, maxInt(u64)) >> @intCast(u6, e);
6161 if (u & m == 0) {
6262 return x;
6363 } else {
......@@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 {
6767}
6868
6969test "math.trunc" {
70 expect(trunc(f32(1.3)) == trunc32(1.3));
71 expect(trunc(f64(1.3)) == trunc64(1.3));
70 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
71 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
7272}
7373
7474test "math.trunc32" {
lib/std/mem.zig+10-10
......@@ -118,7 +118,7 @@ pub const Allocator = struct {
118118 } else @alignOf(T);
119119
120120 if (n == 0) {
121 return ([*]align(a) T)(undefined)[0..0];
121 return @as([*]align(a) T, undefined)[0..0];
122122 }
123123
124124 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
......@@ -170,7 +170,7 @@ pub const Allocator = struct {
170170 }
171171 if (new_n == 0) {
172172 self.free(old_mem);
173 return ([*]align(new_alignment) T)(undefined)[0..0];
173 return @as([*]align(new_alignment) T, undefined)[0..0];
174174 }
175175
176176 const old_byte_slice = @sliceToBytes(old_mem);
......@@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.
523523 builtin.Endian.Little => {
524524 const ShiftType = math.Log2Int(ReturnType);
525525 for (bytes) |b, index| {
526 result = result | (ReturnType(b) << @intCast(ShiftType, index * 8));
526 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));
527527 }
528528 },
529529 }
......@@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type {
13321332 if (comptime !trait.isSingleItemPtr(P))
13331333 @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P));
13341334
1335 const size = usize(@sizeOf(meta.Child(P)));
1335 const size = @as(usize, @sizeOf(meta.Child(P)));
13361336 const alignment = comptime meta.alignment(P);
13371337
13381338 if (alignment == 0) {
......@@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {
13531353}
13541354
13551355test "asBytes" {
1356 const deadbeef = u32(0xDEADBEEF);
1356 const deadbeef = @as(u32, 0xDEADBEEF);
13571357 const deadbeef_bytes = switch (builtin.endian) {
13581358 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
13591359 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
......@@ -1361,7 +1361,7 @@ test "asBytes" {
13611361
13621362 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
13631363
1364 var codeface = u32(0xC0DEFACE);
1364 var codeface = @as(u32, 0xC0DEFACE);
13651365 for (asBytes(&codeface).*) |*b|
13661366 b.* = 0;
13671367 testing.expect(codeface == 0);
......@@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
13921392}
13931393
13941394test "toBytes" {
1395 var my_bytes = toBytes(u32(0x12345678));
1395 var my_bytes = toBytes(@as(u32, 0x12345678));
13961396 switch (builtin.endian) {
13971397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
13981398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
......@@ -1406,7 +1406,7 @@ test "toBytes" {
14061406}
14071407
14081408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
1409 const size = usize(@sizeOf(T));
1409 const size = @as(usize, @sizeOf(T));
14101410
14111411 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) {
14121412 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
......@@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ
14241424}
14251425
14261426test "bytesAsValue" {
1427 const deadbeef = u32(0xDEADBEEF);
1427 const deadbeef = @as(u32, 0xDEADBEEF);
14281428 const deadbeef_bytes = switch (builtin.endian) {
14291429 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
14301430 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
......@@ -1472,7 +1472,7 @@ test "bytesToValue" {
14721472 };
14731473
14741474 const deadbeef = bytesToValue(u32, deadbeef_bytes);
1475 testing.expect(deadbeef == u32(0xDEADBEEF));
1475 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
14761476}
14771477
14781478fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
lib/std/meta.zig+2-2
......@@ -341,7 +341,7 @@ test "std.meta.TagType" {
341341///Returns the active tag of a tagged union
342342pub fn activeTag(u: var) @TagType(@typeOf(u)) {
343343 const T = @typeOf(u);
344 return @TagType(T)(u);
344 return @as(@TagType(T), u);
345345}
346346
347347test "std.meta.activeTag" {
......@@ -505,7 +505,7 @@ test "std.meta.eql" {
505505 const EU = struct {
506506 fn tst(err: bool) !u8 {
507507 if (err) return error.Error;
508 return u8(5);
508 return @as(u8, 5);
509509 }
510510 };
511511
lib/std/meta/trait.zig+2-2
......@@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool {
327327}
328328
329329test "std.meta.trait.isConstPtr" {
330 var t = u8(0);
331 const c = u8(0);
330 var t = @as(u8, 0);
331 const c = @as(u8, 0);
332332 testing.expect(isConstPtr(*const @typeOf(t)));
333333 testing.expect(isConstPtr(@typeOf(&c)));
334334 testing.expect(!isConstPtr(*@typeOf(t)));
lib/std/net.zig+11-11
......@@ -117,7 +117,7 @@ pub const IpAddress = extern union {
117117 ip_slice[10] = 0xff;
118118 ip_slice[11] = 0xff;
119119
120 const ptr = @sliceToBytes((*const [1]u32)(&addr)[0..]);
120 const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]);
121121
122122 ip_slice[12] = ptr[0];
123123 ip_slice[13] = ptr[1];
......@@ -161,7 +161,7 @@ pub const IpAddress = extern union {
161161 .addr = undefined,
162162 },
163163 };
164 const out_ptr = @sliceToBytes((*[1]u32)(&result.in.addr)[0..]);
164 const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]);
165165
166166 var x: u8 = 0;
167167 var index: u8 = 0;
......@@ -271,7 +271,7 @@ pub const IpAddress = extern union {
271271 },
272272 os.AF_INET6 => {
273273 const port = mem.bigToNative(u16, self.in6.port);
274 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{0,0,0,0,0,0,0,0,0,0,0xff,0xff})) {
274 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
275275 try std.fmt.format(
276276 context,
277277 Errors,
......@@ -611,7 +611,7 @@ fn linuxLookupName(
611611 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
612612 mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
613613 }
614 if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
614 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
615615 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
616616 prefixlen = prefixMatch(sa6.addr, da6.addr);
617617 } else |_| {}
......@@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
710710 // address. However the definition of the source prefix length is
711711 // not clear and thus this limiting is not yet implemented.
712712 var i: u8 = 0;
713 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
713 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
714714 return i;
715715}
716716
......@@ -1133,7 +1133,7 @@ fn resMSendRc(
11331133 }
11341134
11351135 // Wait for a response, or until time to retry
1136 const clamped_timeout = std.math.min(u31(std.math.maxInt(u31)), t1 + retry_interval - t2);
1136 const clamped_timeout = std.math.min(@as(u31, std.math.maxInt(u31)), t1 + retry_interval - t2);
11371137 const nevents = os.poll(&pfd, clamped_timeout) catch 0;
11381138 if (nevents == 0) continue;
11391139
......@@ -1194,23 +1194,23 @@ fn dnsParse(
11941194 if (r.len < 12) return error.InvalidDnsPacket;
11951195 if ((r[3] & 15) != 0) return;
11961196 var p = r.ptr + 12;
1197 var qdcount = r[4] * usize(256) + r[5];
1198 var ancount = r[6] * usize(256) + r[7];
1197 var qdcount = r[4] * @as(usize, 256) + r[5];
1198 var ancount = r[6] * @as(usize, 256) + r[7];
11991199 if (qdcount + ancount > 64) return error.InvalidDnsPacket;
12001200 while (qdcount != 0) {
12011201 qdcount -= 1;
12021202 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
12031203 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
12041204 return error.InvalidDnsPacket;
1205 p += usize(5) + @boolToInt(p[0] != 0);
1205 p += @as(usize, 5) + @boolToInt(p[0] != 0);
12061206 }
12071207 while (ancount != 0) {
12081208 ancount -= 1;
12091209 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
12101210 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
12111211 return error.InvalidDnsPacket;
1212 p += usize(1) + @boolToInt(p[0] != 0);
1213 const len = p[8] * usize(256) + p[9];
1212 p += @as(usize, 1) + @boolToInt(p[0] != 0);
1213 const len = p[8] * @as(usize, 256) + p[9];
12141214 if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket;
12151215 try callback(ctx, p[1], p[10 .. 10 + len], r);
12161216 p += 10 + len;
lib/std/os.zig+7-7
......@@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
472472
473473 var index: usize = 0;
474474 while (index < bytes.len) {
475 const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len));
475 const amt_to_write = math.min(bytes.len - index, @as(usize, max_bytes_len));
476476 const rc = system.write(fd, bytes.ptr + index, amt_to_write);
477477 switch (errno(rc)) {
478478 0 => {
......@@ -1126,9 +1126,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro
11261126
11271127 const want_rmdir_behavior = (flags & AT_REMOVEDIR) != 0;
11281128 const create_options_flags = if (want_rmdir_behavior)
1129 w.ULONG(w.FILE_DELETE_ON_CLOSE)
1129 @as(w.ULONG, w.FILE_DELETE_ON_CLOSE)
11301130 else
1131 w.ULONG(w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
1131 @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
11321132
11331133 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
11341134 var nt_name = w.UNICODE_STRING{
......@@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool {
15261526 }
15271527 if (builtin.os == .linux) {
15281528 var wsz: linux.winsize = undefined;
1529 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
1529 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
15301530 }
15311531 unreachable;
15321532}
......@@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
15471547 }
15481548
15491549 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
1550 const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
1550 const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];
15511551 const name_wide = @bytesToSlice(u16, name_bytes);
15521552 return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
15531553 mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
......@@ -2897,7 +2897,7 @@ pub fn res_mkquery(
28972897 // Construct query template - ID will be filled later
28982898 var q: [280]u8 = undefined;
28992899 @memset(&q, 0, n);
2900 q[2] = u8(op) * 8 + 1;
2900 q[2] = @as(u8, op) * 8 + 1;
29012901 q[5] = 1;
29022902 mem.copy(u8, q[13..], name);
29032903 var i: usize = 13;
......@@ -3143,7 +3143,7 @@ pub fn dn_expand(
31433143 // loop invariants: p<end, dest<dend
31443144 if ((p[0] & 0xc0) != 0) {
31453145 if (p + 1 == end) return error.InvalidDnsPacket;
3146 var j = ((p[0] & usize(0x3f)) << 8) | p[1];
3146 var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
31473147 if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr);
31483148 if (j >= msg.len) return error.InvalidDnsPacket;
31493149 p = msg.ptr + j;
lib/std/os/bits/dragonfly.zig+1-1
......@@ -315,7 +315,7 @@ pub const dirent = extern struct {
315315 d_name: [256]u8,
316316
317317 pub fn reclen(self: dirent) u16 {
318 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7);
318 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
319319 }
320320};
321321
lib/std/os/bits/linux.zig+5-5
......@@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400;
559559pub const EPOLLERR = 0x008;
560560pub const EPOLLHUP = 0x010;
561561pub const EPOLLRDHUP = 0x2000;
562pub const EPOLLEXCLUSIVE = (u32(1) << 28);
563pub const EPOLLWAKEUP = (u32(1) << 29);
564pub const EPOLLONESHOT = (u32(1) << 30);
565pub const EPOLLET = (u32(1) << 31);
562pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28);
563pub const EPOLLWAKEUP = (@as(u32, 1) << 29);
564pub const EPOLLONESHOT = (@as(u32, 1) << 30);
565pub const EPOLLET = (@as(u32, 1) << 31);
566566
567567pub const CLOCK_REALTIME = 0;
568568pub const CLOCK_MONOTONIC = 1;
......@@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool {
950950}
951951
952952pub fn CAP_TO_MASK(cap: u8) u32 {
953 return u32(1) << u5(cap & 31);
953 return @as(u32, 1) << u5(cap & 31);
954954}
955955
956956pub fn CAP_TO_INDEX(cap: u8) u8 {
lib/std/os/linux.zig+94-94
......@@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 {
4646
4747pub fn dup2(old: i32, new: i32) usize {
4848 if (@hasDecl(@This(), "SYS_dup2")) {
49 return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)));
49 return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));
5050 } else {
5151 if (old == new) {
5252 if (std.debug.runtime_safety) {
53 const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD);
53 const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD);
5454 if (@bitCast(isize, rc) < 0) return rc;
5555 }
5656 return @intCast(usize, old);
5757 } else {
58 return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0);
58 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);
5959 }
6060 }
6161}
6262
6363pub fn dup3(old: i32, new: i32, flags: u32) usize {
64 return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags);
64 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
6565}
6666
6767// TODO https://github.com/ziglang/zig/issues/265
......@@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
102102
103103// TODO https://github.com/ziglang/zig/issues/265
104104pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize {
105 return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
105 return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
106106}
107107
108108pub 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 {
120120pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
121121 return syscall3(
122122 SYS_getdents,
123 @bitCast(usize, isize(fd)),
123 @bitCast(usize, @as(isize, fd)),
124124 @ptrToInt(dirp),
125125 std.math.min(len, maxInt(c_int)),
126126 );
......@@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
129129pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
130130 return syscall3(
131131 SYS_getdents64,
132 @bitCast(usize, isize(fd)),
132 @bitCast(usize, @as(isize, fd)),
133133 @ptrToInt(dirp),
134134 std.math.min(len, maxInt(c_int)),
135135 );
......@@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize {
140140}
141141
142142pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize {
143 return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask);
143 return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
144144}
145145
146146pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
147 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd)));
147 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
148148}
149149
150150// 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
152152 if (@hasDecl(@This(), "SYS_readlink")) {
153153 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
154154 } else {
155 return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
155 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
156156 }
157157}
158158
159159// TODO https://github.com/ziglang/zig/issues/265
160160pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
161 return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
161 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
162162}
163163
164164// TODO https://github.com/ziglang/zig/issues/265
......@@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
166166 if (@hasDecl(@This(), "SYS_mkdir")) {
167167 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
168168 } else {
169 return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode);
169 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
170170 }
171171}
172172
173173// TODO https://github.com/ziglang/zig/issues/265
174174pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize {
175 return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode);
175 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
176176}
177177
178178// 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
194194 if (@hasDecl(@This(), "SYS_mmap2")) {
195195 // Make sure the offset is also specified in multiples of page size
196196 if ((offset & (MMAP2_UNIT - 1)) != 0)
197 return @bitCast(usize, isize(-EINVAL));
197 return @bitCast(usize, @as(isize, -EINVAL));
198198
199199 return syscall6(
200200 SYS_mmap2,
......@@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
202202 length,
203203 prot,
204204 flags,
205 @bitCast(usize, isize(fd)),
205 @bitCast(usize, @as(isize, fd)),
206206 @truncate(usize, offset / MMAP2_UNIT),
207207 );
208208 } else {
......@@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
212212 length,
213213 prot,
214214 flags,
215 @bitCast(usize, isize(fd)),
215 @bitCast(usize, @as(isize, fd)),
216216 offset,
217217 );
218218 }
......@@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
249249}
250250
251251pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
252 return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);
252 return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
253253}
254254
255255pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
256256 return syscall5(
257257 SYS_preadv,
258 @bitCast(usize, isize(fd)),
258 @bitCast(usize, @as(isize, fd)),
259259 @ptrToInt(iov),
260260 count,
261261 @truncate(usize, offset),
......@@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
266266pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
267267 return syscall6(
268268 SYS_preadv2,
269 @bitCast(usize, isize(fd)),
269 @bitCast(usize, @as(isize, fd)),
270270 @ptrToInt(iov),
271271 count,
272272 @truncate(usize, offset),
......@@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k
276276}
277277
278278pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
279 return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);
279 return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
280280}
281281
282282pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
283 return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);
283 return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
284284}
285285
286286pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
287287 return syscall5(
288288 SYS_pwritev,
289 @bitCast(usize, isize(fd)),
289 @bitCast(usize, @as(isize, fd)),
290290 @ptrToInt(iov),
291291 count,
292292 @truncate(usize, offset),
......@@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us
297297pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
298298 return syscall6(
299299 SYS_pwritev2,
300 @bitCast(usize, isize(fd)),
300 @bitCast(usize, @as(isize, fd)),
301301 @ptrToInt(iov),
302302 count,
303303 @truncate(usize, offset),
......@@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize {
311311 if (@hasDecl(@This(), "SYS_rmdir")) {
312312 return syscall1(SYS_rmdir, @ptrToInt(path));
313313 } else {
314 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
314 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
315315 }
316316}
317317
......@@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
320320 if (@hasDecl(@This(), "SYS_symlink")) {
321321 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
322322 } else {
323 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));
323 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
324324 }
325325}
326326
327327// TODO https://github.com/ziglang/zig/issues/265
328328pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize {
329 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath));
329 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
330330}
331331
332332// TODO https://github.com/ziglang/zig/issues/265
333333pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
334 return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);
334 return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
335335}
336336
337337// TODO https://github.com/ziglang/zig/issues/265
......@@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize {
339339 if (@hasDecl(@This(), "SYS_access")) {
340340 return syscall2(SYS_access, @ptrToInt(path), mode);
341341 } else {
342 return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0);
342 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
343343 }
344344}
345345
346346// TODO https://github.com/ziglang/zig/issues/265
347347pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
348 return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags);
348 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
349349}
350350
351351pub fn pipe(fd: *[2]i32) usize {
......@@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize {
363363}
364364
365365pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
366 return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);
366 return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
367367}
368368
369369pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
370 return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);
370 return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
371371}
372372
373373// TODO https://github.com/ziglang/zig/issues/265
......@@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {
375375 if (@hasDecl(@This(), "SYS_rename")) {
376376 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
377377 } else if (@hasDecl(@This(), "SYS_renameat")) {
378 return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));
378 return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
379379 } else {
380 return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0);
380 return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
381381 }
382382}
383383
......@@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
385385 if (@hasDecl(@This(), "SYS_renameat")) {
386386 return syscall4(
387387 SYS_renameat,
388 @bitCast(usize, isize(oldfd)),
388 @bitCast(usize, @as(isize, oldfd)),
389389 @ptrToInt(old),
390 @bitCast(usize, isize(newfd)),
390 @bitCast(usize, @as(isize, newfd)),
391391 @ptrToInt(new),
392392 );
393393 } else {
394394 return syscall5(
395395 SYS_renameat2,
396 @bitCast(usize, isize(oldfd)),
396 @bitCast(usize, @as(isize, oldfd)),
397397 @ptrToInt(old),
398 @bitCast(usize, isize(newfd)),
398 @bitCast(usize, @as(isize, newfd)),
399399 @ptrToInt(new),
400400 0,
401401 );
......@@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
406406pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize {
407407 return syscall5(
408408 SYS_renameat2,
409 @bitCast(usize, isize(oldfd)),
409 @bitCast(usize, @as(isize, oldfd)),
410410 @ptrToInt(oldpath),
411 @bitCast(usize, isize(newfd)),
411 @bitCast(usize, @as(isize, newfd)),
412412 @ptrToInt(newpath),
413413 flags,
414414 );
......@@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
421421 } else {
422422 return syscall4(
423423 SYS_openat,
424 @bitCast(usize, isize(AT_FDCWD)),
424 @bitCast(usize, @as(isize, AT_FDCWD)),
425425 @ptrToInt(path),
426426 flags,
427427 perm,
......@@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {
437437// TODO https://github.com/ziglang/zig/issues/265
438438pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize {
439439 // dirfd could be negative, for example AT_FDCWD is -100
440 return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode);
440 return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
441441}
442442
443443/// See also `clone` (from the arch-specific include)
......@@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
451451}
452452
453453pub fn close(fd: i32) usize {
454 return syscall1(SYS_close, @bitCast(usize, isize(fd)));
454 return syscall1(SYS_close, @bitCast(usize, @as(isize, fd)));
455455}
456456
457457/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
458458pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
459459 return syscall5(
460460 SYS__llseek,
461 @bitCast(usize, isize(fd)),
461 @bitCast(usize, @as(isize, fd)),
462462 @truncate(usize, offset >> 32),
463463 @truncate(usize, offset),
464464 @ptrToInt(result),
......@@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
468468
469469/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
470470pub fn lseek(fd: i32, offset: i64, whence: usize) usize {
471 return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence);
471 return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);
472472}
473473
474474pub fn exit(status: i32) noreturn {
475 _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
475 _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status)));
476476 unreachable;
477477}
478478
479479pub fn exit_group(status: i32) noreturn {
480 _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status)));
480 _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status)));
481481 unreachable;
482482}
483483
......@@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
486486}
487487
488488pub fn kill(pid: i32, sig: i32) usize {
489 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));
489 return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
490490}
491491
492492// TODO https://github.com/ziglang/zig/issues/265
......@@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize {
494494 if (@hasDecl(@This(), "SYS_unlink")) {
495495 return syscall1(SYS_unlink, @ptrToInt(path));
496496 } else {
497 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0);
497 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
498498 }
499499}
500500
501501// TODO https://github.com/ziglang/zig/issues/265
502502pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize {
503 return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags);
503 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
504504}
505505
506506pub fn waitpid(pid: i32, status: *u32, flags: u32) usize {
507 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0);
507 return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
508508}
509509
510510var 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 {
519519 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
520520 const rc = f(clk_id, tp);
521521 switch (rc) {
522 0, @bitCast(usize, isize(-EINVAL)) => return rc,
522 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
523523 else => {},
524524 }
525525 }
526526 }
527 return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
527 return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
528528}
529529
530530extern 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 {
537537 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
538538 return f(clk, ts);
539539 }
540 return @bitCast(usize, isize(-ENOSYS));
540 return @bitCast(usize, @as(isize, -ENOSYS));
541541}
542542
543543pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
544 return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
544 return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
545545}
546546
547547pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
548 return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
548 return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
549549}
550550
551551pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
......@@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize {
594594
595595pub fn getuid() u32 {
596596 if (@hasDecl(@This(), "SYS_getuid32")) {
597 return u32(syscall0(SYS_getuid32));
597 return @as(u32, syscall0(SYS_getuid32));
598598 } else {
599 return u32(syscall0(SYS_getuid));
599 return @as(u32, syscall0(SYS_getuid));
600600 }
601601}
602602
603603pub fn getgid() u32 {
604604 if (@hasDecl(@This(), "SYS_getgid32")) {
605 return u32(syscall0(SYS_getgid32));
605 return @as(u32, syscall0(SYS_getgid32));
606606 } else {
607 return u32(syscall0(SYS_getgid));
607 return @as(u32, syscall0(SYS_getgid));
608608 }
609609}
610610
611611pub fn geteuid() u32 {
612612 if (@hasDecl(@This(), "SYS_geteuid32")) {
613 return u32(syscall0(SYS_geteuid32));
613 return @as(u32, syscall0(SYS_geteuid32));
614614 } else {
615 return u32(syscall0(SYS_geteuid));
615 return @as(u32, syscall0(SYS_geteuid));
616616 }
617617}
618618
619619pub fn getegid() u32 {
620620 if (@hasDecl(@This(), "SYS_getegid32")) {
621 return u32(syscall0(SYS_getegid32));
621 return @as(u32, syscall0(SYS_getegid32));
622622 } else {
623 return u32(syscall0(SYS_getegid));
623 return @as(u32, syscall0(SYS_getegid));
624624 }
625625}
626626
......@@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
743743}
744744
745745pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
746 return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));
746 return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
747747}
748748
749749pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
750 return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));
750 return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
751751}
752752
753753pub 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 {
755755}
756756
757757pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
758 return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
758 return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
759759}
760760
761761pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
762 return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
762 return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
763763}
764764
765765pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
766 return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags);
766 return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
767767}
768768
769769pub 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
781781 // batch-send all messages up to the current message
782782 if (next_unsent < i) {
783783 const batch_size = i - next_unsent;
784 const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
784 const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
785785 if (getErrno(r) != 0) return next_unsent;
786786 if (r < batch_size) return next_unsent + r;
787787 }
......@@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
797797 }
798798 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
799799 const batch_size = kvlen - next_unsent;
800 const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
800 const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
801801 if (getErrno(r) != 0) return r;
802802 return next_unsent + r;
803803 }
804804 return kvlen;
805805 }
806 return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags);
806 return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags);
807807}
808808
809809pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
810 return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len);
810 return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
811811}
812812
813813pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
814 return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags);
814 return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
815815}
816816
817817pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
818 return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
818 return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
819819}
820820
821821pub fn shutdown(fd: i32, how: i32) usize {
822 return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how)));
822 return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
823823}
824824
825825pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
826 return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len));
826 return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
827827}
828828
829829pub fn listen(fd: i32, backlog: u32) usize {
830 return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog);
830 return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog);
831831}
832832
833833pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
834 return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
834 return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
835835}
836836
837837pub 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 {
843843}
844844
845845pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {
846 return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags);
846 return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
847847}
848848
849849pub fn fstat(fd: i32, stat_buf: *Stat) usize {
850850 if (@hasDecl(@This(), "SYS_fstat64")) {
851 return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
851 return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
852852 } else {
853 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
853 return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
854854 }
855855}
856856
......@@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
875875// TODO https://github.com/ziglang/zig/issues/265
876876pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
877877 if (@hasDecl(@This(), "SYS_fstatat64")) {
878 return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
878 return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
879879 } else {
880 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
880 return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
881881 }
882882}
883883
......@@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
885885 if (@hasDecl(@This(), "SYS_statx")) {
886886 return syscall5(
887887 SYS_statx,
888 @bitCast(usize, isize(dirfd)),
888 @bitCast(usize, @as(isize, dirfd)),
889889 @ptrToInt(path),
890890 flags,
891891 mask,
892892 @ptrToInt(statx_buf),
893893 );
894894 }
895 return @bitCast(usize, isize(-ENOSYS));
895 return @bitCast(usize, @as(isize, -ENOSYS));
896896}
897897
898898// TODO https://github.com/ziglang/zig/issues/265
......@@ -959,7 +959,7 @@ pub fn sched_yield() usize {
959959}
960960
961961pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize {
962 const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set));
962 const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set));
963963 if (@bitCast(isize, rc) < 0) return rc;
964964 if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
965965 return 0;
......@@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize {
974974}
975975
976976pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
977 return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev));
977 return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev));
978978}
979979
980980pub 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
984984pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {
985985 return syscall6(
986986 SYS_epoll_pwait,
987 @bitCast(usize, isize(epoll_fd)),
987 @bitCast(usize, @as(isize, epoll_fd)),
988988 @ptrToInt(events),
989989 @intCast(usize, maxevents),
990 @bitCast(usize, isize(timeout)),
990 @bitCast(usize, @as(isize, timeout)),
991991 @ptrToInt(sigmask),
992992 @sizeOf(sigset_t),
993993 );
......@@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
998998}
999999
10001000pub fn timerfd_create(clockid: i32, flags: u32) usize {
1001 return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags);
1001 return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
10021002}
10031003
10041004pub const itimerspec = extern struct {
......@@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct {
10071007};
10081008
10091009pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1010 return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value));
1010 return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value));
10111011}
10121012
10131013pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1014 return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
1014 return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
10151015}
10161016
10171017pub fn unshare(flags: usize) usize {
......@@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
10961096}
10971097
10981098pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
1099 return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
1099 return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
11001100}
11011101
11021102pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {
1103 return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args);
1103 return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
11041104}
11051105
11061106test "" {
lib/std/os/linux/arm-eabi.zig+2-2
......@@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize {
100100pub nakedcc fn restore() void {
101101 return asm volatile ("svc #0"
102102 :
103 : [number] "{r7}" (usize(SYS_sigreturn))
103 : [number] "{r7}" (@as(usize, SYS_sigreturn))
104104 : "memory"
105105 );
106106}
......@@ -108,7 +108,7 @@ pub nakedcc fn restore() void {
108108pub nakedcc fn restore_rt() void {
109109 return asm volatile ("svc #0"
110110 :
111 : [number] "{r7}" (usize(SYS_rt_sigreturn))
111 : [number] "{r7}" (@as(usize, SYS_rt_sigreturn))
112112 : "memory"
113113 );
114114}
lib/std/os/linux/arm64.zig+1-1
......@@ -93,7 +93,7 @@ pub const restore = restore_rt;
9393pub nakedcc fn restore_rt() void {
9494 return asm volatile ("svc #0"
9595 :
96 : [number] "{x8}" (usize(SYS_rt_sigreturn))
96 : [number] "{x8}" (@as(usize, SYS_rt_sigreturn))
9797 : "memory", "cc"
9898 );
9999}
lib/std/os/linux/mipsel.zig+3-3
......@@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
2626 \\ sw $3, 4($4)
2727 \\ 2:
2828 : [ret] "={$2}" (-> usize)
29 : [number] "{$2}" (usize(SYS_pipe))
29 : [number] "{$2}" (@as(usize, SYS_pipe))
3030 : "memory", "cc", "$7"
3131 );
3232}
......@@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
147147pub nakedcc fn restore() void {
148148 return asm volatile ("syscall"
149149 :
150 : [number] "{$2}" (usize(SYS_sigreturn))
150 : [number] "{$2}" (@as(usize, SYS_sigreturn))
151151 : "memory", "cc", "$7"
152152 );
153153}
......@@ -155,7 +155,7 @@ pub nakedcc fn restore() void {
155155pub nakedcc fn restore_rt() void {
156156 return asm volatile ("syscall"
157157 :
158 : [number] "{$2}" (usize(SYS_rt_sigreturn))
158 : [number] "{$2}" (@as(usize, SYS_rt_sigreturn))
159159 : "memory", "cc", "$7"
160160 );
161161}
lib/std/os/linux/riscv64.zig+1-1
......@@ -92,7 +92,7 @@ pub const restore = restore_rt;
9292pub nakedcc fn restore_rt() void {
9393 return asm volatile ("ecall"
9494 :
95 : [number] "{x17}" (usize(SYS_rt_sigreturn))
95 : [number] "{x17}" (@as(usize, SYS_rt_sigreturn))
9696 : "memory"
9797 );
9898}
lib/std/os/linux/test.zig+3-3
......@@ -72,7 +72,7 @@ test "statx" {
7272 expect(stat_buf.mode == statx_buf.mode);
7373 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
7474 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
75 expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.size);
76 expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.blksize);
77 expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.blocks);
75 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
76 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
77 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
7878}
lib/std/os/linux/vdso.zig+2-2
......@@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6262
6363 var i: usize = 0;
6464 while (i < hashtab[1]) : (i += 1) {
65 if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
65 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
6767 if (0 == syms[i].st_shndx) continue;
6868 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;
6969 if (maybe_versym) |versym| {
lib/std/os/linux/x86_64.zig+1-1
......@@ -93,7 +93,7 @@ pub const restore = restore_rt;
9393pub nakedcc fn restore_rt() void {
9494 return asm volatile ("syscall"
9595 :
96 : [number] "{rax}" (usize(SYS_rt_sigreturn))
96 : [number] "{rax}" (@as(usize, SYS_rt_sigreturn))
9797 : "rcx", "r11", "memory"
9898 );
9999}
lib/std/os/test.zig+1-1
......@@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {
172172
173173 var counter = data.?;
174174 // Count how many libraries are loaded
175 counter.* += usize(1);
175 counter.* += @as(usize, 1);
176176
177177 // The image should contain at least a PT_LOAD segment
178178 if (info.dlpi_phnum < 1) return -1;
lib/std/os/windows.zig+2-2
......@@ -262,7 +262,7 @@ pub const ReadFileError = error{Unexpected};
262262pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {
263263 var index: usize = 0;
264264 while (index < buffer.len) {
265 const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));
265 const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len - index));
266266 var amt_read: DWORD = undefined;
267267 if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
268268 switch (kernel32.GetLastError()) {
......@@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 {
801801}
802802
803803pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 {
804 const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime);
804 const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime);
805805 return fromSysTime(hns);
806806}
807807
lib/std/os/windows/bits.zig+12-12
......@@ -69,7 +69,7 @@ pub const FALSE = 0;
6969
7070pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
7171
72pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
72pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
7373
7474pub const FILE_ALL_INFORMATION = extern struct {
7575 BasicInformation: FILE_BASIC_INFORMATION,
......@@ -571,16 +571,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;
571571pub const KF_FLAG_ALIAS_ONLY = -2147483648;
572572
573573pub const S_OK = 0;
574pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
575pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
576pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
577pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
578pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
579pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
580pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
581pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
582pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
583pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
574pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001));
575pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002));
576pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003));
577pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004));
578pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005));
579pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF));
580pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005));
581pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006));
582pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E));
583pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057));
584584
585585pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
586586pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
......@@ -873,4 +873,4 @@ pub const CURDIR = extern struct {
873873 Handle: HANDLE,
874874};
875875
876pub const DUPLICATE_SAME_ACCESS = 2;
\ No newline at end of file
876pub const DUPLICATE_SAME_ACCESS = 2;
lib/std/os/zen.zig+2-2
......@@ -138,7 +138,7 @@ pub const Syscall = enum(usize) {
138138////////////////////
139139
140140pub fn exit(status: i32) noreturn {
141 _ = syscall1(Syscall.exit, @bitCast(usize, isize(status)));
141 _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status)));
142142 unreachable;
143143}
144144
......@@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
167167}
168168
169169pub fn createThread(function: fn () void) u16 {
170 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
170 return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function)));
171171}
172172
173173/////////////////////////
lib/std/packed_int_array.zig+18-18
......@@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
193193 ///Initialize a packed array using an unpacked array
194194 /// or, more likely, an array literal.
195195 pub fn init(ints: [int_count]Int) Self {
196 var self = Self(undefined);
196 var self = @as(Self, undefined);
197197 for (ints) |int, i| self.set(i, int);
198198 return self;
199199 }
......@@ -328,11 +328,11 @@ test "PackedIntArray" {
328328 const expected_bytes = ((bits * int_count) + 7) / 8;
329329 testing.expect(@sizeOf(PackedArray) == expected_bytes);
330330
331 var data = PackedArray(undefined);
331 var data = @as(PackedArray, undefined);
332332
333333 //write values, counting up
334 var i = usize(0);
335 var count = I(0);
334 var i = @as(usize, 0);
335 var count = @as(I, 0);
336336 while (i < data.len()) : (i += 1) {
337337 data.set(i, count);
338338 if (bits > 0) count +%= 1;
......@@ -352,7 +352,7 @@ test "PackedIntArray" {
352352test "PackedIntArray init" {
353353 const PackedArray = PackedIntArray(u3, 8);
354354 var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
355 var i = usize(0);
355 var i = @as(usize, 0);
356356 while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i);
357357}
358358
......@@ -375,8 +375,8 @@ test "PackedIntSlice" {
375375 var data = P.init(&buffer, int_count);
376376
377377 //write values, counting up
378 var i = usize(0);
379 var count = I(0);
378 var i = @as(usize, 0);
379 var count = @as(I, 0);
380380 while (i < data.len()) : (i += 1) {
381381 data.set(i, count);
382382 if (bits > 0) count +%= 1;
......@@ -402,11 +402,11 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
402402 const Int = @IntType(false, bits);
403403
404404 const PackedArray = PackedIntArray(Int, int_count);
405 var packed_array = PackedArray(undefined);
405 var packed_array = @as(PackedArray, undefined);
406406
407407 const limit = (1 << bits);
408408
409 var i = usize(0);
409 var i = @as(usize, 0);
410410 while (i < packed_array.len()) : (i += 1) {
411411 packed_array.set(i, @intCast(Int, i % limit));
412412 }
......@@ -463,20 +463,20 @@ test "PackedIntSlice accumulating bit offsets" {
463463 // anything
464464 {
465465 const PackedArray = PackedIntArray(u3, 16);
466 var packed_array = PackedArray(undefined);
466 var packed_array = @as(PackedArray, undefined);
467467
468468 var packed_slice = packed_array.slice(0, packed_array.len());
469 var i = usize(0);
469 var i = @as(usize, 0);
470470 while (i < packed_array.len() - 1) : (i += 1) {
471471 packed_slice = packed_slice.slice(1, packed_slice.len());
472472 }
473473 }
474474 {
475475 const PackedArray = PackedIntArray(u11, 88);
476 var packed_array = PackedArray(undefined);
476 var packed_array = @as(PackedArray, undefined);
477477
478478 var packed_slice = packed_array.slice(0, packed_array.len());
479 var i = usize(0);
479 var i = @as(usize, 0);
480480 while (i < packed_array.len() - 1) : (i += 1) {
481481 packed_slice = packed_slice.slice(1, packed_slice.len());
482482 }
......@@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" {
493493 var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9);
494494 const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3);
495495
496 var i = usize(0);
496 var i = @as(usize, 0);
497497 while (i < packed_slice_cast_2.len()) : (i += 1) {
498498 const val = switch (builtin.endian) {
499499 .Big => 0b01,
......@@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" {
518518 i = 0;
519519 while (i < packed_slice_cast_3.len()) : (i += 1) {
520520 const val = switch (builtin.endian) {
521 .Big => if (i % 2 == 0) u3(0b111) else u3(0b000),
522 .Little => if (i % 2 == 0) u3(0b111) else u3(0b000),
521 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
522 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
523523 };
524524 testing.expect(packed_slice_cast_3.get(i) == val);
525525 }
......@@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" {
541541 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542542 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543543
544 var i = usize(0);
544 var i = @as(usize, 0);
545545 while (i < packed_array_be.len()) : (i += 1) {
546546 testing.expect(packed_array_be.get(i) == i);
547547 }
......@@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" {
579579 testing.expect(packed_array_be.bytes[3] == 0b00000001);
580580 testing.expect(packed_array_be.bytes[4] == 0b00000000);
581581
582 var i = usize(0);
582 var i = @as(usize, 0);
583583 while (i < packed_array_be.len()) : (i += 1) {
584584 testing.expect(packed_array_be.get(i) == i);
585585 }
lib/std/pdb.zig+1-1
......@@ -532,7 +532,7 @@ const Msf = struct {
532532 const stream_sizes = try allocator.alloc(u32, stream_count);
533533 defer allocator.free(stream_sizes);
534534
535 // Microsoft's implementation uses u32(-1) for inexistant streams.
535 // Microsoft's implementation uses @as(u32, -1) for inexistant streams.
536536 // These streams are not used, but still participate in the file
537537 // and must be taken into account when resolving stream indices.
538538 const Nil = 0xFFFFFFFF;
lib/std/priority_queue.zig+30-30
......@@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" {
236236 try queue.add(23);
237237 try queue.add(25);
238238 try queue.add(13);
239 expectEqual(u32(7), queue.remove());
240 expectEqual(u32(12), queue.remove());
241 expectEqual(u32(13), queue.remove());
242 expectEqual(u32(23), queue.remove());
243 expectEqual(u32(25), queue.remove());
244 expectEqual(u32(54), queue.remove());
239 expectEqual(@as(u32, 7), queue.remove());
240 expectEqual(@as(u32, 12), queue.remove());
241 expectEqual(@as(u32, 13), queue.remove());
242 expectEqual(@as(u32, 23), queue.remove());
243 expectEqual(@as(u32, 25), queue.remove());
244 expectEqual(@as(u32, 54), queue.remove());
245245}
246246
247247test "std.PriorityQueue: add and remove same min heap" {
......@@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" {
254254 try queue.add(2);
255255 try queue.add(1);
256256 try queue.add(1);
257 expectEqual(u32(1), queue.remove());
258 expectEqual(u32(1), queue.remove());
259 expectEqual(u32(1), queue.remove());
260 expectEqual(u32(1), queue.remove());
261 expectEqual(u32(2), queue.remove());
262 expectEqual(u32(2), queue.remove());
257 expectEqual(@as(u32, 1), queue.remove());
258 expectEqual(@as(u32, 1), queue.remove());
259 expectEqual(@as(u32, 1), queue.remove());
260 expectEqual(@as(u32, 1), queue.remove());
261 expectEqual(@as(u32, 2), queue.remove());
262 expectEqual(@as(u32, 2), queue.remove());
263263}
264264
265265test "std.PriorityQueue: removeOrNull on empty" {
......@@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" {
276276 try queue.add(9);
277277 try queue.add(3);
278278 try queue.add(2);
279 expectEqual(u32(2), queue.remove());
280 expectEqual(u32(3), queue.remove());
281 expectEqual(u32(9), queue.remove());
279 expectEqual(@as(u32, 2), queue.remove());
280 expectEqual(@as(u32, 3), queue.remove());
281 expectEqual(@as(u32, 9), queue.remove());
282282}
283283
284284test "std.PriorityQueue: peek" {
......@@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" {
289289 try queue.add(9);
290290 try queue.add(3);
291291 try queue.add(2);
292 expectEqual(u32(2), queue.peek().?);
293 expectEqual(u32(2), queue.peek().?);
292 expectEqual(@as(u32, 2), queue.peek().?);
293 expectEqual(@as(u32, 2), queue.peek().?);
294294}
295295
296296test "std.PriorityQueue: sift up with odd indices" {
......@@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" {
341341 try queue.add(23);
342342 try queue.add(25);
343343 try queue.add(13);
344 expectEqual(u32(54), queue.remove());
345 expectEqual(u32(25), queue.remove());
346 expectEqual(u32(23), queue.remove());
347 expectEqual(u32(13), queue.remove());
348 expectEqual(u32(12), queue.remove());
349 expectEqual(u32(7), queue.remove());
344 expectEqual(@as(u32, 54), queue.remove());
345 expectEqual(@as(u32, 25), queue.remove());
346 expectEqual(@as(u32, 23), queue.remove());
347 expectEqual(@as(u32, 13), queue.remove());
348 expectEqual(@as(u32, 12), queue.remove());
349 expectEqual(@as(u32, 7), queue.remove());
350350}
351351
352352test "std.PriorityQueue: add and remove same max heap" {
......@@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" {
359359 try queue.add(2);
360360 try queue.add(1);
361361 try queue.add(1);
362 expectEqual(u32(2), queue.remove());
363 expectEqual(u32(2), queue.remove());
364 expectEqual(u32(1), queue.remove());
365 expectEqual(u32(1), queue.remove());
366 expectEqual(u32(1), queue.remove());
367 expectEqual(u32(1), queue.remove());
362 expectEqual(@as(u32, 2), queue.remove());
363 expectEqual(@as(u32, 2), queue.remove());
364 expectEqual(@as(u32, 1), queue.remove());
365 expectEqual(@as(u32, 1), queue.remove());
366 expectEqual(@as(u32, 1), queue.remove());
367 expectEqual(@as(u32, 1), queue.remove());
368368}
369369
370370test "std.PriorityQueue: iterator" {
......@@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" {
386386 _ = map.remove(e);
387387 }
388388
389 expectEqual(usize(0), map.count());
389 expectEqual(@as(usize, 0), map.count());
390390}
lib/std/rand.zig+8-8
......@@ -93,13 +93,13 @@ pub const Random = struct {
9393 // http://www.pcg-random.org/posts/bounded-rands.html
9494 // "Lemire's (with an extra tweak from me)"
9595 var x: Small = r.int(Small);
96 var m: Large = Large(x) * Large(less_than);
96 var m: Large = @as(Large, x) * @as(Large, less_than);
9797 var l: Small = @truncate(Small, m);
9898 if (l < less_than) {
9999 // TODO: workaround for https://github.com/ziglang/zig/issues/1770
100100 // should be:
101101 // var t: Small = -%less_than;
102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), Small(less_than)));
102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than)));
103103
104104 if (t >= less_than) {
105105 t -= less_than;
......@@ -109,7 +109,7 @@ pub const Random = struct {
109109 }
110110 while (l < t) {
111111 x = r.int(Small);
112 m = Large(x) * Large(less_than);
112 m = @as(Large, x) * @as(Large, less_than);
113113 l = @truncate(Small, m);
114114 }
115115 }
......@@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
286286 // adapted from:
287287 // http://www.pcg-random.org/posts/bounded-rands.html
288288 // "Integer Multiplication (Biased)"
289 var m: T2 = T2(random_int) * T2(less_than);
289 var m: T2 = @as(T2, random_int) * @as(T2, less_than);
290290 return @intCast(T, m >> T.bit_count);
291291}
292292
......@@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct {
633633 const r = s0 +% s1;
634634
635635 s1 ^= s0;
636 self.s[0] = math.rotl(u64, s0, u8(55)) ^ s1 ^ (s1 << 14);
637 self.s[1] = math.rotl(u64, s1, u8(36));
636 self.s[0] = math.rotl(u64, s0, @as(u8, 55)) ^ s1 ^ (s1 << 14);
637 self.s[1] = math.rotl(u64, s1, @as(u8, 36));
638638
639639 return r;
640640 }
......@@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct {
652652 inline for (table) |entry| {
653653 var b: usize = 0;
654654 while (b < 64) : (b += 1) {
655 if ((entry & (u64(1) << @intCast(u6, b))) != 0) {
655 if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) {
656656 s0 ^= self.s[0];
657657 s1 ^= self.s[1];
658658 }
......@@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void {
10901090 testRangeBias(r, start, end, false);
10911091}
10921092fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
1093 const count = @intCast(usize, i32(end) - i32(start));
1093 const count = @intCast(usize, @as(i32, end) - @as(i32, start));
10941094 var values_buffer = [_]bool{false} ** 0x100;
10951095 const values = values_buffer[0..count];
10961096 var i: usize = 0;
lib/std/rand/ziggurat.zig+1-1
......@@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 {
1717 // We manually construct a float from parts as we can avoid an extra random lookup here by
1818 // using the unused exponent for the lookup table entry.
1919 const bits = random.scalar(u64);
20 const i = usize(bits & 0xff);
20 const i = @as(usize, bits & 0xff);
2121
2222 const u = blk: {
2323 if (tables.is_symmetric) {
lib/std/segmented_list.zig+5-5
......@@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
162162 /// Grows or shrinks capacity to match usage.
163163 pub fn setCapacity(self: *Self, new_capacity: usize) !void {
164164 if (prealloc_item_count != 0) {
165 if (new_capacity <= usize(1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) {
165 if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) {
166166 return self.shrinkCapacity(new_capacity);
167167 }
168168 }
......@@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
231231
232232 fn shelfSize(shelf_index: ShelfIndex) usize {
233233 if (prealloc_item_count == 0) {
234 return usize(1) << shelf_index;
234 return @as(usize, 1) << shelf_index;
235235 }
236 return usize(1) << (shelf_index + (prealloc_exp + 1));
236 return @as(usize, 1) << (shelf_index + (prealloc_exp + 1));
237237 }
238238
239239 fn shelfIndex(list_index: usize) ShelfIndex {
......@@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
245245
246246 fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize {
247247 if (prealloc_item_count == 0) {
248 return (list_index + 1) - (usize(1) << shelf_index);
248 return (list_index + 1) - (@as(usize, 1) << shelf_index);
249249 }
250 return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index));
250 return list_index + prealloc_item_count - (@as(usize, 1) << ((prealloc_exp + 1) + shelf_index));
251251 }
252252
253253 fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void {
lib/std/sort.zig+4-4
......@@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s
813813// where have some idea as to how many unique values there are and where the next value might be
814814fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
815815 if (range.length() == 0) return range.start;
816 const skip = math.max(range.length() / unique, usize(1));
816 const skip = math.max(range.length() / unique, @as(usize, 1));
817817
818818 var index = range.start + skip;
819819 while (lessThan(items[index - 1], value)) : (index += skip) {
......@@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh
827827
828828fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
829829 if (range.length() == 0) return range.start;
830 const skip = math.max(range.length() / unique, usize(1));
830 const skip = math.max(range.length() / unique, @as(usize, 1));
831831
832832 var index = range.end - skip;
833833 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
841841
842842fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
843843 if (range.length() == 0) return range.start;
844 const skip = math.max(range.length() / unique, usize(1));
844 const skip = math.max(range.length() / unique, @as(usize, 1));
845845
846846 var index = range.start + skip;
847847 while (!lessThan(value, items[index - 1])) : (index += skip) {
......@@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha
855855
856856fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize {
857857 if (range.length() == 0) return range.start;
858 const skip = math.max(range.length() / unique, usize(1));
858 const skip = math.max(range.length() / unique, @as(usize, 1));
859859
860860 var index = range.end - skip;
861861 while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) {
lib/std/special/c.zig+3-3
......@@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int {
6262 r += 1;
6363 n -= 1;
6464 }
65 return c_int(l[0]) - c_int(r[0]);
65 return @as(c_int, l[0]) - @as(c_int, r[0]);
6666}
6767
6868extern fn strerror(errnum: c_int) [*]const u8 {
......@@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
540540 // scale result up
541541 if (ex > 0) {
542542 ux -%= 1 << digits;
543 ux |= uint(@bitCast(u32, ex)) << digits;
543 ux |= @as(uint, @bitCast(u32, ex)) << digits;
544544 } else {
545545 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));
546546 }
......@@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 {
687687
688688export fn sqrtf(x: f32) f32 {
689689 const tiny: f32 = 1.0e-30;
690 const sign: i32 = @bitCast(i32, u32(0x80000000));
690 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));
691691 var ix: i32 = @bitCast(i32, x);
692692
693693 if ((ix & 0x7F800000) == 0x7F800000) {
lib/std/special/compiler_rt.zig+17-17
......@@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 {
672672 // special cases
673673 if (d == 0) return 0; // ?!
674674 if (n == 0) return 0;
675 var sr = @bitCast(c_uint, c_int(@clz(u32, d)) - c_int(@clz(u32, n)));
675 var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n)));
676676 // 0 <= sr <= n_uword_bits - 1 or sr large
677677 if (sr > n_uword_bits - 1) {
678678 // d > r
......@@ -1414,10 +1414,10 @@ test "test_divsi3" {
14141414 [_]i32{ -2, 1, -2 },
14151415 [_]i32{ -2, -1, 2 },
14161416
1417 [_]i32{ @bitCast(i32, u32(0x80000000)), 1, @bitCast(i32, u32(0x80000000)) },
1418 [_]i32{ @bitCast(i32, u32(0x80000000)), -1, @bitCast(i32, u32(0x80000000)) },
1419 [_]i32{ @bitCast(i32, u32(0x80000000)), -2, 0x40000000 },
1420 [_]i32{ @bitCast(i32, u32(0x80000000)), 2, @bitCast(i32, u32(0xC0000000)) },
1417 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) },
1418 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) },
1419 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 },
1420 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) },
14211421 };
14221422
14231423 for (cases) |case| {
......@@ -1443,8 +1443,8 @@ test "test_divmodsi4" {
14431443 [_]i32{ 19, 5, 3, 4 },
14441444 [_]i32{ 19, -5, -3, 4 },
14451445
1446 [_]i32{ @bitCast(i32, u32(0x80000000)), 8, @bitCast(i32, u32(0xf0000000)), 0 },
1447 [_]i32{ @bitCast(i32, u32(0x80000007)), 8, @bitCast(i32, u32(0xf0000001)), -1 },
1446 [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 },
1447 [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 },
14481448 };
14491449
14501450 for (cases) |case| {
......@@ -1467,10 +1467,10 @@ test "test_divdi3" {
14671467 [_]i64{ -2, 1, -2 },
14681468 [_]i64{ -2, -1, 2 },
14691469
1470 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)) },
1471 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)) },
1472 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -2, 0x4000000000000000 },
1473 [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0xC000000000000000)) },
1470 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
1471 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) },
1472 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 },
1473 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) },
14741474 };
14751475
14761476 for (cases) |case| {
......@@ -1492,12 +1492,12 @@ test "test_moddi3" {
14921492 [_]i64{ -5, 3, -2 },
14931493 [_]i64{ -5, -3, -2 },
14941494
1495 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 1, 0 },
1496 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -1, 0 },
1497 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 2, 0 },
1498 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -2, 0 },
1499 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 3, -2 },
1500 [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -3, -2 },
1495 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 },
1496 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 },
1497 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 },
1498 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 },
1499 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 },
1500 [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 },
15011501 };
15021502
15031503 for (cases) |case| {
lib/std/special/compiler_rt/addXf3.zig+13-13
......@@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 {
1919}
2020
2121pub extern fn __subsf3(a: f32, b: f32) f32 {
22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (u32(1) << 31));
22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));
2323 return addXf3(f32, a, neg_b);
2424}
2525
2626pub extern fn __subdf3(a: f64, b: f64) f64 {
27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (u64(1) << 63));
27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63));
2828 return addXf3(f64, a, neg_b);
2929}
3030
3131pub extern fn __subtf3(a: f128, b: f128) f128 {
32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127));
32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127));
3333 return addXf3(f128, a, neg_b);
3434}
3535
3636// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
3737fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
3838 const Z = @IntType(false, T.bit_count);
39 const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1));
39 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
4040 const significandBits = std.math.floatMantissaBits(T);
41 const implicitBit = Z(1) << significandBits;
41 const implicitBit = @as(Z, 1) << significandBits;
4242
4343 const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
4444 significand.* <<= @intCast(S, shift);
......@@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
4848// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
4949fn addXf3(comptime T: type, a: T, b: T) T {
5050 const Z = @IntType(false, T.bit_count);
51 const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1));
51 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
5252
5353 const typeWidth = T.bit_count;
5454 const significandBits = std.math.floatMantissaBits(T);
5555 const exponentBits = std.math.floatExponentBits(T);
5656
57 const signBit = (Z(1) << (significandBits + exponentBits));
57 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
5858 const maxExponent = ((1 << exponentBits) - 1);
5959 const exponentBias = (maxExponent >> 1);
6060
61 const implicitBit = (Z(1) << significandBits);
61 const implicitBit = (@as(Z, 1) << significandBits);
6262 const quietBit = implicitBit >> 1;
6363 const significandMask = implicitBit - 1;
6464
......@@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T {
7878 const infRep = @bitCast(Z, std.math.inf(T));
7979
8080 // Detect if a or b is zero, infinity, or NaN.
81 if (aAbs -% Z(1) >= infRep - Z(1) or
82 bAbs -% Z(1) >= infRep - Z(1))
81 if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
82 bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
8383 {
8484 // NaN + anything = qNaN
8585 if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);
......@@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
148148 const @"align" = @intCast(Z, aExponent - bExponent);
149149 if (@"align" != 0) {
150150 if (@"align" < typeWidth) {
151 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0;
151 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0;
152152 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
153153 } else {
154154 bSignificand = 1; // sticky; b is known to be non-zero.
......@@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
157157 if (subtraction) {
158158 aSignificand -= bSignificand;
159159 // If a == -b, return +zero.
160 if (aSignificand == 0) return @bitCast(T, Z(0));
160 if (aSignificand == 0) return @bitCast(T, @as(Z, 0));
161161
162162 // If partial cancellation occured, we need to left-shift the result
163163 // and adjust the exponent:
......@@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
185185 // Result is denormal before rounding; the exponent is zero and we
186186 // need to shift the significand.
187187 const shift = @intCast(Z, 1 - aExponent);
188 const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0;
188 const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) @as(Z, 1) else 0;
189189 aSignificand = aSignificand >> @intCast(S, shift | sticky);
190190 aExponent = 0;
191191 }
lib/std/special/compiler_rt/addXf3_test.zig+4-4
......@@ -3,8 +3,8 @@
33// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c
44// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c
55
6const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64);
7const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64);
6const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
7const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
88
99const __addtf3 = @import("addXf3.zig").__addtf3;
1010
......@@ -34,7 +34,7 @@ test "addtf3" {
3434 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3535
3636 // NaN + any = NaN
37 test__addtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
37 test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3838
3939 // inf + inf = inf
4040 test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
......@@ -75,7 +75,7 @@ test "subtf3" {
7575 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7676
7777 // NaN + any = NaN
78 test__subtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
78 test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7979
8080 // inf - any = inf
8181 test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
lib/std/special/compiler_rt/comparedf2.zig+10-10
......@@ -13,19 +13,19 @@ const srep_t = i64;
1313const typeWidth = rep_t.bit_count;
1414const significandBits = std.math.floatMantissaBits(fp_t);
1515const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (rep_t(1) << (significandBits + exponentBits));
16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
1717const absMask = signBit - 1;
18const implicitBit = rep_t(1) << significandBits;
18const implicitBit = @as(rep_t, 1) << significandBits;
1919const significandMask = implicitBit - 1;
2020const exponentMask = absMask ^ significandMask;
2121const infRep = @bitCast(rep_t, std.math.inf(fp_t));
2222
2323// TODO https://github.com/ziglang/zig/issues/641
2424// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = c_int(-1);
26const LE_EQUAL = c_int(0);
27const LE_GREATER = c_int(1);
28const LE_UNORDERED = c_int(1);
25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);
2929
3030pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {
3131 @setRuntimeSafety(is_test);
......@@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {
6565
6666// TODO https://github.com/ziglang/zig/issues/641
6767// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = c_int(-1);
69const GE_EQUAL = c_int(0);
70const GE_GREATER = c_int(1);
71const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
7373pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {
7474 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/comparesf2.zig+10-10
......@@ -13,19 +13,19 @@ const srep_t = i32;
1313const typeWidth = rep_t.bit_count;
1414const significandBits = std.math.floatMantissaBits(fp_t);
1515const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (rep_t(1) << (significandBits + exponentBits));
16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
1717const absMask = signBit - 1;
18const implicitBit = rep_t(1) << significandBits;
18const implicitBit = @as(rep_t, 1) << significandBits;
1919const significandMask = implicitBit - 1;
2020const exponentMask = absMask ^ significandMask;
2121const infRep = @bitCast(rep_t, std.math.inf(fp_t));
2222
2323// TODO https://github.com/ziglang/zig/issues/641
2424// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = c_int(-1);
26const LE_EQUAL = c_int(0);
27const LE_GREATER = c_int(1);
28const LE_UNORDERED = c_int(1);
25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);
2929
3030pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {
3131 @setRuntimeSafety(is_test);
......@@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {
6565
6666// TODO https://github.com/ziglang/zig/issues/641
6767// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = c_int(-1);
69const GE_EQUAL = c_int(0);
70const GE_GREATER = c_int(1);
71const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
7373pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {
7474 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/comparetf2.zig+10-10
......@@ -1,9 +1,9 @@
11// TODO https://github.com/ziglang/zig/issues/641
22// and then make the return types of some of these functions the enum instead of c_int
3const LE_LESS = c_int(-1);
4const LE_EQUAL = c_int(0);
5const LE_GREATER = c_int(1);
6const LE_UNORDERED = c_int(1);
3const LE_LESS = @as(c_int, -1);
4const LE_EQUAL = @as(c_int, 0);
5const LE_GREATER = @as(c_int, 1);
6const LE_UNORDERED = @as(c_int, 1);
77
88const rep_t = u128;
99const srep_t = i128;
......@@ -11,9 +11,9 @@ const srep_t = i128;
1111const typeWidth = rep_t.bit_count;
1212const significandBits = 112;
1313const exponentBits = (typeWidth - significandBits - 1);
14const signBit = (rep_t(1) << (significandBits + exponentBits));
14const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
1515const absMask = signBit - 1;
16const implicitBit = rep_t(1) << significandBits;
16const implicitBit = @as(rep_t, 1) << significandBits;
1717const significandMask = implicitBit - 1;
1818const exponentMask = absMask ^ significandMask;
1919const infRep = exponentMask;
......@@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int {
6060
6161// TODO https://github.com/ziglang/zig/issues/641
6262// and then make the return types of some of these functions the enum instead of c_int
63const GE_LESS = c_int(-1);
64const GE_EQUAL = c_int(0);
65const GE_GREATER = c_int(1);
66const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
63const GE_LESS = @as(c_int, -1);
64const GE_EQUAL = @as(c_int, 0);
65const GE_GREATER = @as(c_int, 1);
66const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
6767
6868pub extern fn __getf2(a: f128, b: f128) c_int {
6969 @setRuntimeSafety(is_test);
lib/std/special/compiler_rt/divdf3.zig+33-33
......@@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
1414 const significandBits = std.math.floatMantissaBits(f64);
1515 const exponentBits = std.math.floatExponentBits(f64);
1616
17 const signBit = (Z(1) << (significandBits + exponentBits));
17 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1818 const maxExponent = ((1 << exponentBits) - 1);
1919 const exponentBias = (maxExponent >> 1);
2020
21 const implicitBit = (Z(1) << significandBits);
21 const implicitBit = (@as(Z, 1) << significandBits);
2222 const quietBit = implicitBit >> 1;
2323 const significandMask = implicitBit - 1;
2424
......@@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
9191 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
9292 // is accurate to about 3.5 binary digits.
9393 const q31b: u32 = @truncate(u32, bSignificand >> 21);
94 var recip32 = u32(0x7504f333) -% q31b;
94 var recip32 = @as(u32, 0x7504f333) -% q31b;
9595
9696 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
9797 //
......@@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 {
101101 // with each iteration, so after three iterations, we have about 28 binary
102102 // digits of accuracy.
103103 var correction32: u32 = undefined;
104 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);
105 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);
106 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);
107 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);
108 correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1);
109 recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31);
104 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
105 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
106 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
107 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
108 correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1);
109 recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31);
110110
111111 // recip32 might have overflowed to exactly zero in the preceding
112112 // 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 {
119119 const q63blo: u32 = @truncate(u32, bSignificand << 11);
120120 var correction: u64 = undefined;
121121 var reciprocal: u64 = undefined;
122 correction = ~(u64(recip32) *% q31b +% (u64(recip32) *% q63blo >> 32)) +% 1;
122 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
123123 const cHi = @truncate(u32, correction >> 32);
124124 const cLo = @truncate(u32, correction);
125 reciprocal = u64(recip32) *% cHi +% (u64(recip32) *% cLo >> 32);
125 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
126126
127127 // We already adjusted the 32-bit estimate, now we need to adjust the final
128128 // 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 {
195195 // Clear the implicit bit
196196 var absResult = quotient & significandMask;
197197 // Insert the exponent
198 absResult |= @bitCast(Z, SignedZ(writtenExponent)) << significandBits;
198 absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits;
199199 // Round
200200 absResult +%= round;
201201 // Insert the sign and return
......@@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
208208 switch (Z) {
209209 u32 => {
210210 // 32x32 --> 64 bit multiply
211 const product = u64(a) * u64(b);
211 const product = @as(u64, a) * @as(u64, b);
212212 hi.* = @truncate(u32, product >> 32);
213213 lo.* = @truncate(u32, product);
214214 },
......@@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
237237 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
238238 },
239239 u128 => {
240 const Word_LoMask = u64(0x00000000ffffffff);
241 const Word_HiMask = u64(0xffffffff00000000);
242 const Word_FullMask = u64(0xffffffffffffffff);
240 const Word_LoMask = @as(u64, 0x00000000ffffffff);
241 const Word_HiMask = @as(u64, 0xffffffff00000000);
242 const Word_FullMask = @as(u64, 0xffffffffffffffff);
243243 const S = struct {
244244 fn Word_1(x: u128) u64 {
245245 return @truncate(u32, x >> 96);
......@@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
275275 const product43: u64 = S.Word_4(a) * S.Word_3(b);
276276 const product44: u64 = S.Word_4(a) * S.Word_4(b);
277277
278 const sum0: u128 = u128(product44);
279 const sum1: u128 = u128(product34) +%
280 u128(product43);
281 const sum2: u128 = u128(product24) +%
282 u128(product33) +%
283 u128(product42);
284 const sum3: u128 = u128(product14) +%
285 u128(product23) +%
286 u128(product32) +%
287 u128(product41);
288 const sum4: u128 = u128(product13) +%
289 u128(product22) +%
290 u128(product31);
291 const sum5: u128 = u128(product12) +%
292 u128(product21);
293 const sum6: u128 = u128(product11);
278 const sum0: u128 = @as(u128, product44);
279 const sum1: u128 = @as(u128, product34) +%
280 @as(u128, product43);
281 const sum2: u128 = @as(u128, product24) +%
282 @as(u128, product33) +%
283 @as(u128, product42);
284 const sum3: u128 = @as(u128, product14) +%
285 @as(u128, product23) +%
286 @as(u128, product32) +%
287 @as(u128, product41);
288 const sum4: u128 = @as(u128, product13) +%
289 @as(u128, product22) +%
290 @as(u128, product31);
291 const sum5: u128 = @as(u128, product12) +%
292 @as(u128, product21);
293 const sum6: u128 = @as(u128, product11);
294294
295295 const r0: u128 = (sum0 & Word_FullMask) +%
296296 ((sum1 & Word_LoMask) << 32);
......@@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
316316 @setRuntimeSafety(builtin.is_test);
317317 const Z = @IntType(false, T.bit_count);
318318 const significandBits = std.math.floatMantissaBits(T);
319 const implicitBit = Z(1) << significandBits;
319 const implicitBit = @as(Z, 1) << significandBits;
320320
321321 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
322322 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/divsf3.zig+11-11
......@@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
1313 const significandBits = std.math.floatMantissaBits(f32);
1414 const exponentBits = std.math.floatExponentBits(f32);
1515
16 const signBit = (Z(1) << (significandBits + exponentBits));
16 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1717 const maxExponent = ((1 << exponentBits) - 1);
1818 const exponentBias = (maxExponent >> 1);
1919
20 const implicitBit = (Z(1) << significandBits);
20 const implicitBit = (@as(Z, 1) << significandBits);
2121 const quietBit = implicitBit >> 1;
2222 const significandMask = implicitBit - 1;
2323
......@@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
9090 // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
9191 // is accurate to about 3.5 binary digits.
9292 const q31b = bSignificand << 8;
93 var reciprocal = u32(0x7504f333) -% q31b;
93 var reciprocal = @as(u32, 0x7504f333) -% q31b;
9494
9595 // Now refine the reciprocal estimate using a Newton-Raphson iteration:
9696 //
......@@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 {
100100 // with each iteration, so after three iterations, we have about 28 binary
101101 // digits of accuracy.
102102 var correction: u32 = undefined;
103 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);
104 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);
105 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);
106 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);
107 correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1);
108 reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31);
103 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
104 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
105 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
106 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
107 correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
108 reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31);
109109
110110 // Exhaustive testing shows that the error in reciprocal after three steps
111111 // 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 {
127127 // is the error in the reciprocal of b scaled by the maximum
128128 // possible value of a. As a consequence of this error bound,
129129 // either q or nextafter(q) is the correctly rounded
130 var quotient: Z = @truncate(u32, u64(reciprocal) *% (aSignificand << 1) >> 32);
130 var quotient: Z = @truncate(u32, @as(u64, reciprocal) *% (aSignificand << 1) >> 32);
131131
132132 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
133133 // 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 {
189189 @setRuntimeSafety(builtin.is_test);
190190 const Z = @IntType(false, T.bit_count);
191191 const significandBits = std.math.floatMantissaBits(T);
192 const implicitBit = Z(1) << significandBits;
192 const implicitBit = @as(Z, 1) << significandBits;
193193
194194 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
195195 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/divti3_test.zig+4-4
......@@ -14,8 +14,8 @@ test "divti3" {
1414 test__divti3(-2, 1, -2);
1515 test__divti3(-2, -1, 2);
1616
17 test__divti3(@bitCast(i128, u128(0x8 << 124)), 1, @bitCast(i128, u128(0x8 << 124)));
18 test__divti3(@bitCast(i128, u128(0x8 << 124)), -1, @bitCast(i128, u128(0x8 << 124)));
19 test__divti3(@bitCast(i128, u128(0x8 << 124)), -2, @bitCast(i128, u128(0x4 << 124)));
20 test__divti3(@bitCast(i128, u128(0x8 << 124)), 2, @bitCast(i128, u128(0xc << 124)));
17 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
18 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
19 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
20 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
2121}
lib/std/special/compiler_rt/extendXfYf2.zig+7-7
......@@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
4949 const dstInfExp = (1 << dstExpBits) - 1;
5050 const dstExpBias = dstInfExp >> 1;
5151
52 const dstMinNormal: dst_rep_t = dst_rep_t(1) << dstSigBits;
52 const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits;
5353
5454 // Break a into a sign and representation of the absolute value
5555 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
6161 // a is a normal number.
6262 // Extend to the destination type by shifting the significand and
6363 // exponent into the proper position and rebiasing the exponent.
64 absResult = dst_rep_t(aAbs) << (dstSigBits - srcSigBits);
64 absResult = @as(dst_rep_t, aAbs) << (dstSigBits - srcSigBits);
6565 absResult += (dstExpBias - srcExpBias) << dstSigBits;
6666 } else if (aAbs >= srcInfinity) {
6767 // a is NaN or infinity.
......@@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
6969 // bit (if needed) and right-aligning the rest of the trailing NaN
7070 // payload field.
7171 absResult = dstInfExp << dstSigBits;
72 absResult |= dst_rep_t(aAbs & srcQNaN) << (dstSigBits - srcSigBits);
73 absResult |= dst_rep_t(aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
72 absResult |= @as(dst_rep_t, aAbs & srcQNaN) << (dstSigBits - srcSigBits);
73 absResult |= @as(dst_rep_t, aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
7474 } else if (aAbs != 0) {
7575 // a is denormal.
7676 // renormalize the significand and clear the leading bit, then insert
7777 // the correct adjusted exponent in the destination type.
7878 const scale: u32 = @clz(src_rep_t, aAbs) -
79 @clz(src_rep_t, src_rep_t(srcMinNormal));
80 absResult = dst_rep_t(aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
79 @clz(src_rep_t, @as(src_rep_t, srcMinNormal));
80 absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
8181 absResult ^= dstMinNormal;
8282 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
8383 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
8787 }
8888
8989 // Apply the signbit to (dst_t)abs(a).
90 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | dst_rep_t(sign) << (dstBits - srcBits);
90 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);
9191 return @bitCast(dst_t, result);
9292}
9393
lib/std/special/compiler_rt/extendXfYf2_test.zig+4-4
......@@ -134,11 +134,11 @@ test "extendsftf2" {
134134}
135135
136136fn makeQNaN64() f64 {
137 return @bitCast(f64, u64(0x7ff8000000000000));
137 return @bitCast(f64, @as(u64, 0x7ff8000000000000));
138138}
139139
140140fn makeInf64() f64 {
141 return @bitCast(f64, u64(0x7ff0000000000000));
141 return @bitCast(f64, @as(u64, 0x7ff0000000000000));
142142}
143143
144144fn makeNaN64(rand: u64) f64 {
......@@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 {
146146}
147147
148148fn makeQNaN32() f32 {
149 return @bitCast(f32, u32(0x7fc00000));
149 return @bitCast(f32, @as(u32, 0x7fc00000));
150150}
151151
152152fn makeNaN32(rand: u32) f32 {
......@@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 {
154154}
155155
156156fn makeInf32() f32 {
157 return @bitCast(f32, u32(0x7f800000));
157 return @bitCast(f32, @as(u32, 0x7f800000));
158158}
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixdfdi(a: f64, expected: i64) void {
88 const x = __fixdfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixdfsi(a: f64, expected: i32) void {
88 const x = __fixdfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixdfti_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixdfti(a: f64, expected: i128) void {
88 const x = __fixdfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixint.zig+3-3
......@@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
2525
2626 const typeWidth = rep_t.bit_count;
2727 const exponentBits = (typeWidth - significandBits - 1);
28 const signBit = (rep_t(1) << (significandBits + exponentBits));
28 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
2929 const maxExponent = ((1 << exponentBits) - 1);
3030 const exponentBias = (maxExponent >> 1);
3131
32 const implicitBit = (rep_t(1) << significandBits);
32 const implicitBit = (@as(rep_t, 1) << significandBits);
3333 const significandMask = (implicitBit - 1);
3434
3535 // 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 {
5151
5252 // If the value is too large for the integer type, saturate.
5353 if (@intCast(usize, exponent) >= fixint_t.bit_count) {
54 return if (negative) fixint_t(minInt(fixint_t)) else fixint_t(maxInt(fixint_t));
54 return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t));
5555 }
5656
5757 // If 0 <= exponent < significandBits, right shift else left shift
lib/std/special/compiler_rt/fixint_test.zig+13-13
......@@ -81,8 +81,8 @@ test "fixint.i3" {
8181test "fixint.i32" {
8282 test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
8383 test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
84 test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32));
85 test__fixint(f64, i32, f64(math.minInt(i32)) + 1, math.minInt(i32) + 1);
84 test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
85 test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
8686 test__fixint(f64, i32, -2.0, -2);
8787 test__fixint(f64, i32, -1.9, -1);
8888 test__fixint(f64, i32, -1.1, -1);
......@@ -96,8 +96,8 @@ test "fixint.i32" {
9696 test__fixint(f64, i32, 0.1, 0);
9797 test__fixint(f64, i32, 0.9, 0);
9898 test__fixint(f64, i32, 1.0, 1);
99 test__fixint(f64, i32, f64(math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
100 test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32));
99 test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
100 test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
101101 test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
102102 test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
103103}
......@@ -105,9 +105,9 @@ test "fixint.i32" {
105105test "fixint.i64" {
106106 test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
107107 test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
108 test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64));
109 test__fixint(f64, i64, f64(math.minInt(i64)) + 1, math.minInt(i64));
110 test__fixint(f64, i64, f64(math.minInt(i64) / 2), math.minInt(i64) / 2);
108 test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
109 test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
110 test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
111111 test__fixint(f64, i64, -2.0, -2);
112112 test__fixint(f64, i64, -1.9, -1);
113113 test__fixint(f64, i64, -1.1, -1);
......@@ -121,8 +121,8 @@ test "fixint.i64" {
121121 test__fixint(f64, i64, 0.1, 0);
122122 test__fixint(f64, i64, 0.9, 0);
123123 test__fixint(f64, i64, 1.0, 1);
124 test__fixint(f64, i64, f64(math.maxInt(i64)) - 1, math.maxInt(i64));
125 test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64));
124 test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
125 test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
126126 test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
127127 test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
128128}
......@@ -130,8 +130,8 @@ test "fixint.i64" {
130130test "fixint.i128" {
131131 test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
132132 test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
133 test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128));
134 test__fixint(f64, i128, f64(math.minInt(i128)) + 1, math.minInt(i128));
133 test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
134 test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
135135 test__fixint(f64, i128, -2.0, -2);
136136 test__fixint(f64, i128, -1.9, -1);
137137 test__fixint(f64, i128, -1.1, -1);
......@@ -145,8 +145,8 @@ test "fixint.i128" {
145145 test__fixint(f64, i128, 0.1, 0);
146146 test__fixint(f64, i128, 0.9, 0);
147147 test__fixint(f64, i128, 1.0, 1);
148 test__fixint(f64, i128, f64(math.maxInt(i128)) - 1, math.maxInt(i128));
149 test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128));
148 test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
149 test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
150150 test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
151151 test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
152152}
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixsfdi(a: f32, expected: i64) void {
88 const x = __fixsfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixsfsi(a: f32, expected: i32) void {
88 const x = __fixsfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixsfti_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixsfti(a: f32, expected: i128) void {
88 const x = __fixsfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixtfdi(a: f128, expected: i64) void {
88 const x = __fixtfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixtfsi(a: f128, expected: i32) void {
88 const x = __fixtfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixtfti_test.zig+1-1
......@@ -6,7 +6,7 @@ const warn = std.debug.warn;
66
77fn test__fixtfti(a: f128, expected: i128) void {
88 const x = __fixtfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected));
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected));
1010 testing.expect(x == expected);
1111}
1212
lib/std/special/compiler_rt/fixuint.zig+4-4
......@@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
1919 };
2020 const typeWidth = rep_t.bit_count;
2121 const exponentBits = (typeWidth - significandBits - 1);
22 const signBit = (rep_t(1) << (significandBits + exponentBits));
22 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
2323 const maxExponent = ((1 << exponentBits) - 1);
2424 const exponentBias = (maxExponent >> 1);
2525
26 const implicitBit = (rep_t(1) << significandBits);
26 const implicitBit = (@as(rep_t, 1) << significandBits);
2727 const significandMask = (implicitBit - 1);
2828
2929 // 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
3131 const absMask = signBit - 1;
3232 const aAbs: rep_t = aRep & absMask;
3333
34 const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1);
34 const sign = if ((aRep & signBit) != 0) @as(i32, -1) else @as(i32, 1);
3535 const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias;
3636 const significand: rep_t = (aAbs & significandMask) | implicitBit;
3737
......@@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
3939 if (sign == -1 or exponent < 0) return 0;
4040
4141 // If the value is too large for the integer type, saturate.
42 if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);
42 if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0);
4343
4444 // If 0 <= exponent < significandBits, right shift to get the result.
4545 // Otherwise, shift left.
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1
......@@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void {
66 testing.expect(x == expected);
77}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
1111test "fixunstfsi" {
1212 test__fixunstfsi(inf128, 0xffffffff);
lib/std/special/compiler_rt/fixunstfti_test.zig+1-1
......@@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void {
66 testing.expect(x == expected);
77}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
1111test "fixunstfti" {
1212 test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
lib/std/special/compiler_rt/floatsiXf.zig+5-5
......@@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T {
66 @setRuntimeSafety(builtin.is_test);
77
88 const Z = @IntType(false, T.bit_count);
9 const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1));
9 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
1010
1111 if (a == 0) {
12 return T(0.0);
12 return @as(T, 0.0);
1313 }
1414
1515 const significandBits = std.math.floatMantissaBits(T);
1616 const exponentBits = std.math.floatExponentBits(T);
1717 const exponentBias = ((1 << exponentBits - 1) - 1);
1818
19 const implicitBit = Z(1) << significandBits;
20 const signBit = Z(1 << Z.bit_count - 1);
19 const implicitBit = @as(Z, 1) << significandBits;
20 const signBit = @as(Z, 1 << Z.bit_count - 1);
2121
2222 const sign = a >> 31;
2323 // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31).
2424 const abs_a = (a ^ sign) -% sign;
2525 // The exponent is the width of abs(a)
26 const exp = Z(31 - @clz(i32, abs_a));
26 const exp = @as(Z, 31 - @clz(i32, abs_a));
2727
2828 const sign_bit = if (sign < 0) signBit else 0;
2929
lib/std/special/compiler_rt/floattidf.zig+1-1
......@@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 {
4747 a += 1; // round - this step may add a significant bit
4848 a >>= 2; // dump Q and R
4949 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
50 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
50 if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) {
5151 a >>= 1;
5252 e += 1;
5353 }
lib/std/special/compiler_rt/floattisf.zig+1-1
......@@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 {
4848 a += 1; // round - this step may add a significant bit
4949 a >>= 2; // dump Q and R
5050 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
51 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
51 if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) {
5252 a >>= 1;
5353 e += 1;
5454 }
lib/std/special/compiler_rt/floattitf.zig+1-1
......@@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 {
4747 a += 1; // round - this step may add a significant bit
4848 a >>= 2; // dump Q and R
4949 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
50 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
50 if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) {
5151 a >>= 1;
5252 e += 1;
5353 }
lib/std/special/compiler_rt/floatunsidf.zig+3-3
......@@ -2,7 +2,7 @@ const builtin = @import("builtin");
22const std = @import("std");
33const maxInt = std.math.maxInt;
44
5const implicitBit = u64(1) << 52;
5const implicitBit = @as(u64, 1) << 52;
66
77pub extern fn __floatunsidf(arg: u32) f64 {
88 @setRuntimeSafety(builtin.is_test);
......@@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 {
1010 if (arg == 0) return 0.0;
1111
1212 // The exponent is the width of abs(a)
13 const exp = u64(31) - @clz(u32, arg);
13 const exp = @as(u64, 31) - @clz(u32, arg);
1414 // Shift a into the significand field and clear the implicit bit
1515 const shift = @intCast(u6, 52 - exp);
16 const mant = u64(arg) << shift ^ implicitBit;
16 const mant = @as(u64, arg) << shift ^ implicitBit;
1717
1818 return @bitCast(f64, mant | (exp + 1023) << 52);
1919}
lib/std/special/compiler_rt/floatuntidf.zig+2-2
......@@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
3232 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
3333 const shift_amt_u7 = @intCast(u7, shift_amt);
3434 a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) |
35 @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);
35 @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0);
3636 },
3737 }
3838 // finish
......@@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
4040 a += 1; // round - this step may add a significant bit
4141 a >>= 2; // dump Q and R
4242 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
43 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
43 if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) {
4444 a >>= 1;
4545 e += 1;
4646 }
lib/std/special/compiler_rt/floatuntisf.zig+2-2
......@@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
3232 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
3333 const shift_amt_u7 = @intCast(u7, shift_amt);
3434 a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) |
35 @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);
35 @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0);
3636 },
3737 }
3838 // finish
......@@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
4040 a += 1; // round - this step may add a significant bit
4141 a >>= 2; // dump Q and R
4242 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
43 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
43 if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) {
4444 a >>= 1;
4545 e += 1;
4646 }
lib/std/special/compiler_rt/floatuntitf.zig+2-2
......@@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
3232 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
3333 const shift_amt_u7 = @intCast(u7, shift_amt);
3434 a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) |
35 @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);
35 @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0);
3636 },
3737 }
3838 // finish
......@@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
4040 a += 1; // round - this step may add a significant bit
4141 a >>= 2; // dump Q and R
4242 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
43 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
43 if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) {
4444 a >>= 1;
4545 e += 1;
4646 }
lib/std/special/compiler_rt/mulXf3.zig+25-25
......@@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
2424 const significandBits = std.math.floatMantissaBits(T);
2525 const exponentBits = std.math.floatExponentBits(T);
2626
27 const signBit = (Z(1) << (significandBits + exponentBits));
27 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
2828 const maxExponent = ((1 << exponentBits) - 1);
2929 const exponentBias = (maxExponent >> 1);
3030
31 const implicitBit = (Z(1) << significandBits);
31 const implicitBit = (@as(Z, 1) << significandBits);
3232 const quietBit = implicitBit >> 1;
3333 const significandMask = implicitBit - 1;
3434
......@@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T {
122122 // a zero of the appropriate sign. Mathematically there is no need to
123123 // handle this case separately, but we make it a special case to
124124 // simplify the shift logic.
125 const shift: u32 = @truncate(u32, Z(1) -% @bitCast(u32, productExponent));
125 const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent));
126126 if (shift >= typeWidth) return @bitCast(T, productSign);
127127
128128 // 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 {
131131 } else {
132132 // Result is normal before rounding; insert the exponent.
133133 productHi &= significandMask;
134 productHi |= Z(@bitCast(u32, productExponent)) << significandBits;
134 productHi |= @as(Z, @bitCast(u32, productExponent)) << significandBits;
135135 }
136136
137137 // Insert the sign of the result:
......@@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
150150 switch (Z) {
151151 u32 => {
152152 // 32x32 --> 64 bit multiply
153 const product = u64(a) * u64(b);
153 const product = @as(u64, a) * @as(u64, b);
154154 hi.* = @truncate(u32, product >> 32);
155155 lo.* = @truncate(u32, product);
156156 },
......@@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
179179 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
180180 },
181181 u128 => {
182 const Word_LoMask = u64(0x00000000ffffffff);
183 const Word_HiMask = u64(0xffffffff00000000);
184 const Word_FullMask = u64(0xffffffffffffffff);
182 const Word_LoMask = @as(u64, 0x00000000ffffffff);
183 const Word_HiMask = @as(u64, 0xffffffff00000000);
184 const Word_FullMask = @as(u64, 0xffffffffffffffff);
185185 const S = struct {
186186 fn Word_1(x: u128) u64 {
187187 return @truncate(u32, x >> 96);
......@@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
217217 const product43: u64 = S.Word_4(a) * S.Word_3(b);
218218 const product44: u64 = S.Word_4(a) * S.Word_4(b);
219219
220 const sum0: u128 = u128(product44);
221 const sum1: u128 = u128(product34) +%
222 u128(product43);
223 const sum2: u128 = u128(product24) +%
224 u128(product33) +%
225 u128(product42);
226 const sum3: u128 = u128(product14) +%
227 u128(product23) +%
228 u128(product32) +%
229 u128(product41);
230 const sum4: u128 = u128(product13) +%
231 u128(product22) +%
232 u128(product31);
233 const sum5: u128 = u128(product12) +%
234 u128(product21);
235 const sum6: u128 = u128(product11);
220 const sum0: u128 = @as(u128, product44);
221 const sum1: u128 = @as(u128, product34) +%
222 @as(u128, product43);
223 const sum2: u128 = @as(u128, product24) +%
224 @as(u128, product33) +%
225 @as(u128, product42);
226 const sum3: u128 = @as(u128, product14) +%
227 @as(u128, product23) +%
228 @as(u128, product32) +%
229 @as(u128, product41);
230 const sum4: u128 = @as(u128, product13) +%
231 @as(u128, product22) +%
232 @as(u128, product31);
233 const sum5: u128 = @as(u128, product12) +%
234 @as(u128, product21);
235 const sum6: u128 = @as(u128, product11);
236236
237237 const r0: u128 = (sum0 & Word_FullMask) +%
238238 ((sum1 & Word_LoMask) << 32);
......@@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
258258 @setRuntimeSafety(builtin.is_test);
259259 const Z = @IntType(false, T.bit_count);
260260 const significandBits = std.math.floatMantissaBits(T);
261 const implicitBit = Z(1) << significandBits;
261 const implicitBit = @as(Z, 1) << significandBits;
262262
263263 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
264264 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
lib/std/special/compiler_rt/mulXf3_test.zig+9-9
......@@ -2,8 +2,8 @@
22//
33// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c
44
5const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64);
6const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64);
5const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
6const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
77
88const __multf3 = @import("mulXf3.zig").__multf3;
99
......@@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
3939}
4040
4141fn makeNaN128(rand: u64) f128 {
42 const int_result = u128(0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
42 const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64;
4343 const float_result = @bitCast(f128, int_result);
4444 return float_result;
4545}
......@@ -55,15 +55,15 @@ test "multf3" {
5555
5656 // any * any
5757 test__multf3(
58 @bitCast(f128, u128(0x40042eab345678439abcdefea5678234)),
59 @bitCast(f128, u128(0x3ffeedcb34a235253948765432134675)),
58 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
59 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
6060 0x400423e7f9e3c9fc,
6161 0xd906c2c2a85777c4,
6262 );
6363
6464 test__multf3(
65 @bitCast(f128, u128(0x3fcd353e45674d89abacc3a2ebf3ff50)),
66 @bitCast(f128, u128(0x3ff6ed8764648369535adf4be3214568)),
65 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
66 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
6767 0x3fc52a163c6223fc,
6868 0xc94c4bf0430768b4,
6969 );
......@@ -76,8 +76,8 @@ test "multf3" {
7676 );
7777
7878 test__multf3(
79 @bitCast(f128, u128(0x3f154356473c82a9fabf2d22ace345df)),
80 @bitCast(f128, u128(0x3e38eda98765476743ab21da23d45679)),
79 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
80 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
8181 0x3d4f37c1a3137cae,
8282 0xfc6807048bc2836a,
8383 );
lib/std/special/compiler_rt/muldi3.zig+1-1
......@@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
2121 @setRuntimeSafety(builtin.is_test);
2222
2323 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
24 const lower_mask = (~u32(0)) >> bits_in_word_2;
24 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
2525
2626 var r: dwords = undefined;
2727 r.s.low = (a & lower_mask) *% (b & lower_mask);
lib/std/special/compiler_rt/mulodi4.zig+1-1
......@@ -6,7 +6,7 @@ const minInt = std.math.minInt;
66pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 {
77 @setRuntimeSafety(builtin.is_test);
88
9 const min = @bitCast(i64, u64(1 << (i64.bit_count - 1)));
9 const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1)));
1010 const max = ~min;
1111
1212 overflow.* = 0;
lib/std/special/compiler_rt/mulodi4_test.zig+24-24
......@@ -52,34 +52,34 @@ test "mulodi4" {
5252
5353 test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
5454 test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
55 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, u64(0x8000000000000001)), 0);
56 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 0);
55 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
56 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
5757 test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
5858 test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
5959 test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
6060 test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
61 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, u64(0x8000000000000001)), 1);
62 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 1);
61 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
62 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
6363
64 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -2, @bitCast(i64, u64(0x8000000000000000)), 1);
65 test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);
66 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)), 1);
67 test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);
68 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 0, 0, 0);
69 test__mulodi4(0, @bitCast(i64, u64(0x8000000000000000)), 0, 0);
70 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)), 0);
71 test__mulodi4(1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 0);
72 test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0x8000000000000000)), 1);
73 test__mulodi4(2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1);
64 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
65 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
66 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
67 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
68 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
69 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
70 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
71 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
72 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
73 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
7474
75 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -2, @bitCast(i64, u64(0x8000000000000001)), 1);
76 test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 1);
77 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
78 test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
79 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 0, 0, 0);
80 test__mulodi4(0, @bitCast(i64, u64(0x8000000000000001)), 0, 0);
81 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 1, @bitCast(i64, u64(0x8000000000000001)), 0);
82 test__mulodi4(1, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 0);
83 test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 2, @bitCast(i64, u64(0x8000000000000000)), 1);
84 test__mulodi4(2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000000)), 1);
75 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
76 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
77 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
78 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
79 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
80 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
81 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
82 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
83 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
84 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
8585}
lib/std/special/compiler_rt/muloti4.zig+1-1
......@@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig");
44pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {
55 @setRuntimeSafety(builtin.is_test);
66
7 const min = @bitCast(i128, u128(1 << (i128.bit_count - 1)));
7 const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1)));
88 const max = ~min;
99 overflow.* = 0;
1010
lib/std/special/compiler_rt/muloti4_test.zig+31-31
......@@ -39,38 +39,38 @@ test "muloti4" {
3939 test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
4040 test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
4141
42 test__muloti4(@bitCast(i128, u128(0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, u128(0x000000000000000000B504F333F9DE5B)), @bitCast(i128, u128(0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
43 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
44 test__muloti4(-2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
42 test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
43 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
44 test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
4545
46 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
47 test__muloti4(-1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
48 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
49 test__muloti4(0, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
50 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
51 test__muloti4(1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
52 test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
53 test__muloti4(2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
46 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
47 test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
48 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
49 test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
50 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
51 test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
52 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
53 test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
5454
55 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
56 test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
57 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
58 test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
59 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0, 0);
60 test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0);
61 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0);
62 test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 0);
63 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
64 test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
55 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
56 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
57 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
58 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
59 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
60 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
61 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
62 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
63 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
64 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
6565
66 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
67 test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1);
68 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
69 test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
70 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0, 0);
71 test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0);
72 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
73 test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0);
74 test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
75 test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1);
66 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
67 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
68 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
69 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
70 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
71 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
72 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
73 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
74 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
75 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
7676}
lib/std/special/compiler_rt/multi3.zig+1-1
......@@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 {
2121
2222fn __mulddi3(a: u64, b: u64) i128 {
2323 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;
24 const lower_mask = ~u64(0) >> bits_in_dword_2;
24 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;
2525 var r: twords = undefined;
2626 r.s.low = (a & lower_mask) *% (b & lower_mask);
2727 var t: u64 = r.s.low >> bits_in_dword_2;
lib/std/special/compiler_rt/negXf2.zig+1-1
......@@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T {
1515 const significandBits = std.math.floatMantissaBits(T);
1616 const exponentBits = std.math.floatExponentBits(T);
1717
18 const signBit = (Z(1) << (significandBits + exponentBits));
18 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
1919
2020 return @bitCast(T, @bitCast(Z, a) ^ signBit);
2121}
lib/std/special/compiler_rt/popcountdi2_test.zig+3-3
......@@ -20,8 +20,8 @@ test "popcountdi2" {
2020 test__popcountdi2(0);
2121 test__popcountdi2(1);
2222 test__popcountdi2(2);
23 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFD)));
24 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFE)));
25 test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFF)));
23 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
24 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
25 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
2626 // TODO some fuzz testing
2727}
lib/std/special/compiler_rt/truncXfYf2.zig+1-1
......@@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
6969 // destination format. We can convert by simply right-shifting with
7070 // rounding and adjusting the exponent.
7171 absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits));
72 absResult -%= dst_rep_t(srcExpBias - dstExpBias) << dstSigBits;
72 absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits;
7373
7474 const roundBits: src_rep_t = aAbs & roundMask;
7575 if (roundBits > halfway) {
lib/std/special/compiler_rt/truncXfYf2_test.zig+10-10
......@@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
152152
153153test "trunctfsf2" {
154154 // qnan
155 test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000);
155 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
156156 // nan
157 test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);
157 test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000);
158158 // inf
159 test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000);
159 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000);
160160 // zero
161161 test__trunctfsf2(0.0, 0x0);
162162
......@@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
187187
188188test "trunctfdf2" {
189189 // qnan
190 test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000);
190 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
191191 // nan
192 test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);
192 test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000);
193193 // inf
194 test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000);
194 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000);
195195 // zero
196196 test__trunctfdf2(0.0, 0x0);
197197
......@@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
224224
225225test "truncdfsf2" {
226226 // nan & qnan
227 test__truncdfsf2(@bitCast(f64, u64(0x7ff8000000000000)), 0x7fc00000);
228 test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000001)), 0x7fc00000);
227 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000);
228 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000);
229229 // inf
230 test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000000)), 0x7f800000);
231 test__truncdfsf2(@bitCast(f64, u64(0xfff0000000000000)), 0xff800000);
230 test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000);
231 test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000);
232232
233233 test__truncdfsf2(0.0, 0x0);
234234 test__truncdfsf2(1.0, 0x3f800000);
lib/std/special/compiler_rt/udivmod.zig+3-3
......@@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
7676 // K K
7777 // ---
7878 // K 0
79 sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high])));
79 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
8080 // 0 <= sr <= SingleInt.bit_count - 2 or sr large
8181 if (sr > SingleInt.bit_count - 2) {
8282 if (maybe_rem) |rem| {
......@@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
114114 // K X
115115 // ---
116116 // 0 K
117 sr = 1 + SingleInt.bit_count + c_uint(@clz(SingleInt, d[low])) - c_uint(@clz(SingleInt, n[high]));
117 sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
118118 // 2 <= sr <= DoubleInt.bit_count - 1
119119 // q.all = a << (DoubleInt.bit_count - sr);
120120 // r.all = a >> sr;
......@@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
140140 // K X
141141 // ---
142142 // K K
143 sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high])));
143 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
144144 // 0 <= sr <= SingleInt.bit_count - 1 or sr large
145145 if (sr > SingleInt.bit_count - 1) {
146146 if (maybe_rem) |rem| {
lib/std/target.zig+1-1
......@@ -581,7 +581,7 @@ pub const Target = union(enum) {
581581 };
582582
583583 pub fn getExternalExecutor(self: Target) Executor {
584 if (@TagType(Target)(self) == .Native) return .native;
584 if (@as(@TagType(Target),self) == .Native) return .native;
585585
586586 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
587587 if (self.getOs() == builtin.os) {
lib/std/thread.zig+1-1
......@@ -344,7 +344,7 @@ pub const Thread = struct {
344344 pub fn cpuCount() CpuCountError!usize {
345345 if (builtin.os == .linux) {
346346 const cpu_set = try os.sched_getaffinity(0);
347 return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
347 return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
348348 }
349349 if (builtin.os == .windows) {
350350 var system_info: windows.SYSTEM_INFO = undefined;
lib/std/time.zig+4-4
......@@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 {
3838 const hns_per_ms = (ns_per_s / 100) / ms_per_s;
3939 const epoch_adj = epoch.windows * ms_per_s;
4040
41 const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
41 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
4242 return @divFloor(ft64, hns_per_ms) - -epoch_adj;
4343 }
4444 if (builtin.os == .wasi and !builtin.link_libc) {
......@@ -142,10 +142,10 @@ pub const Timer = struct {
142142 // seccomp is going to block us it will at least do so consistently
143143 var ts: os.timespec = undefined;
144144 os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported;
145 self.resolution = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);
145 self.resolution = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec);
146146
147147 os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported;
148 self.start_time = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);
148 self.start_time = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec);
149149 }
150150
151151 return self;
......@@ -185,7 +185,7 @@ pub const Timer = struct {
185185 }
186186 var ts: os.timespec = undefined;
187187 os.clock_gettime(monotonic_clock_id, &ts) catch unreachable;
188 return @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);
188 return @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec);
189189 }
190190};
191191
lib/std/unicode.zig+13-13
......@@ -7,10 +7,10 @@ const mem = std.mem;
77/// Returns how many bytes the UTF-8 representation would require
88/// for the given codepoint.
99pub fn utf8CodepointSequenceLength(c: u32) !u3 {
10 if (c < 0x80) return u3(1);
11 if (c < 0x800) return u3(2);
12 if (c < 0x10000) return u3(3);
13 if (c < 0x110000) return u3(4);
10 if (c < 0x80) return @as(u3, 1);
11 if (c < 0x800) return @as(u3, 2);
12 if (c < 0x10000) return @as(u3, 3);
13 if (c < 0x110000) return @as(u3, 4);
1414 return error.CodepointTooLarge;
1515}
1616
......@@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 {
1818/// returns a number 1-4 indicating the total length of the codepoint in bytes.
1919/// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte.
2020pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
21 if (first_byte < 0b10000000) return u3(1);
22 if (first_byte & 0b11100000 == 0b11000000) return u3(2);
23 if (first_byte & 0b11110000 == 0b11100000) return u3(3);
24 if (first_byte & 0b11111000 == 0b11110000) return u3(4);
21 if (first_byte < 0b10000000) return @as(u3, 1);
22 if (first_byte & 0b11100000 == 0b11000000) return @as(u3, 2);
23 if (first_byte & 0b11110000 == 0b11100000) return @as(u3, 3);
24 if (first_byte & 0b11111000 == 0b11110000) return @as(u3, 4);
2525 return error.Utf8InvalidStartByte;
2626}
2727
......@@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error
6868/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
6969pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 {
7070 return switch (bytes.len) {
71 1 => u32(bytes[0]),
71 1 => @as(u32, bytes[0]),
7272 2 => utf8Decode2(bytes),
7373 3 => utf8Decode3(bytes),
7474 4 => utf8Decode4(bytes),
......@@ -226,7 +226,7 @@ pub const Utf8Iterator = struct {
226226 const slice = it.nextCodepointSlice() orelse return null;
227227
228228 switch (slice.len) {
229 1 => return u32(slice[0]),
229 1 => return @as(u32, slice[0]),
230230 2 => return utf8Decode2(slice) catch unreachable,
231231 3 => return utf8Decode3(slice) catch unreachable,
232232 4 => return utf8Decode4(slice) catch unreachable,
......@@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct {
250250 assert(it.i <= it.bytes.len);
251251 if (it.i == it.bytes.len) return null;
252252 const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]);
253 if (c0 & ~u32(0x03ff) == 0xd800) {
253 if (c0 & ~@as(u32, 0x03ff) == 0xd800) {
254254 // surrogate pair
255255 it.i += 2;
256256 if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf;
257257 const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]);
258 if (c1 & ~u32(0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf;
258 if (c1 & ~@as(u32, 0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf;
259259 it.i += 2;
260260 return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff));
261 } else if (c0 & ~u32(0x03ff) == 0xdc00) {
261 } else if (c0 & ~@as(u32, 0x03ff) == 0xdc00) {
262262 return error.UnexpectedSecondSurrogateHalf;
263263 } else {
264264 it.i += 2;
lib/std/valgrind.zig+1-1
......@@ -76,7 +76,7 @@ pub const ClientRequest = extern enum {
7676 InnerThreads = 6402,
7777};
7878pub fn ToolBase(base: [2]u8) u32 {
79 return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16);
79 return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16);
8080}
8181pub fn IsTool(base: [2]u8, code: usize) bool {
8282 return ToolBase(base) == (code & 0xffff0000);
lib/std/zig/parse_string_literal.zig+1-1
......@@ -19,7 +19,7 @@ pub fn parseStringLiteral(
1919 bytes: []const u8,
2020 bad_index: *usize, // populated if error.InvalidCharacter is returned
2121) ParseStringLiteralError![]u8 {
22 const first_index = if (bytes[0] == 'c') usize(2) else usize(1);
22 const first_index = if (bytes[0] == 'c') @as(usize, 2) else @as(usize, 1);
2323 assert(bytes[bytes.len - 1] == '"');
2424
2525 var list = std.ArrayList(u8).init(allocator);
lib/std/zig/parser_test.zig+1-1
......@@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" {
3737 \\test "" {
3838 \\ const result = while (returnError()) |value| {
3939 \\ break value;
40 \\ } else |err| i32(2);
40 \\ } else |err| @as(i32, 2);
4141 \\ expect(result == 2);
4242 \\}
4343 \\
lib/std/zig/render.zig+3-3
......@@ -410,8 +410,8 @@ fn renderExpression(
410410 switch (prefix_op_node.op) {
411411 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
412412 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {
413 Token.Id.AsteriskAsterisk => usize(1),
414 else => usize(0),
413 Token.Id.AsteriskAsterisk => @as(usize, 1),
414 else => @as(usize, 0),
415415 };
416416 try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // *
417417 if (ptr_info.allowzero_token) |allowzero_token| {
......@@ -2097,7 +2097,7 @@ fn renderTokenOffset(
20972097
20982098 while (true) {
20992099 assert(loc.line != 0);
2100 const newline_count = if (loc.line == 1) u8(1) else u8(2);
2100 const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2);
21012101 try stream.writeByteNTimes('\n', newline_count);
21022102 try stream.writeByteNTimes(' ', indent);
21032103 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
lib/std/zig/tokenizer.zig+1-1
......@@ -350,7 +350,7 @@ pub const Tokenizer = struct {
350350 };
351351 } else {
352352 // Skip the UTF-8 BOM if present
353 const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0);
353 const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else @as(usize, 0);
354354 return Tokenizer{
355355 .buffer = buffer,
356356 .index = src_start,
src-self-hosted/stage1.zig+1-1
......@@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
224224 }
225225 if (flags.present("check")) {
226226 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
227 const code = if (anything_changed) u8(1) else u8(0);
227 const code = if (anything_changed) @as(u8, 1) else @as(u8, 0);
228228 process.exit(code);
229229 }
230230
src-self-hosted/translate_c.zig+11-7
......@@ -123,7 +123,7 @@ const Context = struct {
123123 fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 {
124124 const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc);
125125 const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc);
126 const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)");
126 const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)");
127127
128128 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
129129 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
......@@ -774,12 +774,14 @@ fn transCCast(
774774 if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))
775775 return transCPtrCast(rp, loc, dst_type, src_type, expr);
776776 if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) {
777 const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
777 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
778 try cast_node.params.push(try transQualType(rp, dst_type, loc));
779 _ = try appendToken(rp.c, .Comma, ",");
778780 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");
779781 try builtin_node.params.push(expr);
780782 builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")");
781 try cast_node.op.Call.params.push(&builtin_node.base);
782 cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
783 try cast_node.params.push(&builtin_node.base);
784 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
783785 return &cast_node.base;
784786 }
785787 if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) {
......@@ -793,9 +795,11 @@ fn transCCast(
793795 // TODO: maybe widen to increase size
794796 // TODO: maybe bitcast to change sign
795797 // TODO: maybe truncate to reduce size
796 const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
797 try cast_node.op.Call.params.push(expr);
798 cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
798 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
799 try cast_node.params.push(try transQualType(rp, dst_type, loc));
800 _ = try appendToken(rp.c, .Comma, ",");
801 try cast_node.params.push(expr);
802 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
799803 return &cast_node.base;
800804}
801805
src/all_types.hpp+17-8
......@@ -48,6 +48,7 @@ struct ResultLoc;
4848struct ResultLocPeer;
4949struct ResultLocPeerParent;
5050struct ResultLocBitCast;
51struct ResultLocCast;
5152struct ResultLocReturn;
5253
5354enum PtrLen {
......@@ -1691,6 +1692,7 @@ enum BuiltinFnId {
16911692 BuiltinFnIdFrameType,
16921693 BuiltinFnIdFrameHandle,
16931694 BuiltinFnIdFrameSize,
1695 BuiltinFnIdAs,
16941696};
16951697
16961698struct BuiltinFnEntry {
......@@ -3458,6 +3460,13 @@ struct IrInstructionPtrCastGen {
34583460 bool safety_check_on;
34593461};
34603462
3463struct IrInstructionImplicitCast {
3464 IrInstruction base;
3465
3466 IrInstruction *operand;
3467 ResultLocCast *result_loc_cast;
3468};
3469
34613470struct IrInstructionBitCastSrc {
34623471 IrInstruction base;
34633472
......@@ -3823,14 +3832,6 @@ struct IrInstructionEndExpr {
38233832 ResultLoc *result_loc;
38243833};
38253834
3826struct IrInstructionImplicitCast {
3827 IrInstruction base;
3828
3829 IrInstruction *dest_type;
3830 IrInstruction *target;
3831 ResultLoc *result_loc;
3832};
3833
38343835// This one is for writing through the result pointer.
38353836struct IrInstructionResolveResult {
38363837 IrInstruction base;
......@@ -3928,6 +3929,7 @@ enum ResultLocId {
39283929 ResultLocIdPeerParent,
39293930 ResultLocIdInstruction,
39303931 ResultLocIdBitCast,
3932 ResultLocIdCast,
39313933};
39323934
39333935// Additions to this struct may need to be handled in
......@@ -3995,6 +3997,13 @@ struct ResultLocBitCast {
39953997 ResultLoc *parent;
39963998};
39973999
4000// The source_instruction is the destination type
4001struct ResultLocCast {
4002 ResultLoc base;
4003
4004 ResultLoc *parent;
4005};
4006
39984007static const size_t slice_ptr_index = 0;
39994008static const size_t slice_len_index = 1;
40004009
src/codegen.cpp+1
......@@ -8070,6 +8070,7 @@ static void define_builtin_fns(CodeGen *g) {
80708070 create_builtin_fn(g, BuiltinFnIdFrameType, "Frame", 1);
80718071 create_builtin_fn(g, BuiltinFnIdFrameAddress, "frameAddress", 0);
80728072 create_builtin_fn(g, BuiltinFnIdFrameSize, "frameSize", 1);
8073 create_builtin_fn(g, BuiltinFnIdAs, "as", 2);
80738074}
80748075
80758076static const char *bool_to_str(bool b) {
src/ir.cpp+180-66
......@@ -200,6 +200,8 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
200200static void ir_reset_result(ResultLoc *result_loc);
201201static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
202202 Scope *scope, AstNode *source_node, Buf *out_bare_name);
203static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
204 ResultLoc *parent_result_loc);
203205
204206static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
205207 assert(get_src_ptr_type(const_val->type) != nullptr);
......@@ -2766,6 +2768,18 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc
27662768 return &instruction->base;
27672769}
27682770
2771static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
2772 IrInstruction *operand, ResultLocCast *result_loc_cast)
2773{
2774 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);
2775 instruction->operand = operand;
2776 instruction->result_loc_cast = result_loc_cast;
2777
2778 ir_ref_instruction(operand, irb->current_basic_block);
2779
2780 return &instruction->base;
2781}
2782
27692783static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
27702784 IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)
27712785{
......@@ -3063,20 +3077,6 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode
30633077 return &instruction->base;
30643078}
30653079
3066static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
3067 IrInstruction *dest_type, IrInstruction *target, ResultLoc *result_loc)
3068{
3069 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);
3070 instruction->dest_type = dest_type;
3071 instruction->target = target;
3072 instruction->result_loc = result_loc;
3073
3074 ir_ref_instruction(dest_type, irb->current_basic_block);
3075 ir_ref_instruction(target, irb->current_basic_block);
3076
3077 return &instruction->base;
3078}
3079
30803080static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
30813081 ResultLoc *result_loc, IrInstruction *ty)
30823082{
......@@ -5374,6 +5374,24 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
53745374 IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
53755375 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
53765376 }
5377 case BuiltinFnIdAs:
5378 {
5379 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5380 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
5381 if (dest_type == irb->codegen->invalid_instruction)
5382 return dest_type;
5383
5384 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
5385
5386 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5387 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
5388 &result_loc_cast->base);
5389 if (arg1_value == irb->codegen->invalid_instruction)
5390 return arg1_value;
5391
5392 IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
5393 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5394 }
53775395 case BuiltinFnIdIntToPtr:
53785396 {
53795397 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
62146232 return result_loc_var;
62156233}
62166234
6235static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
6236 ResultLoc *parent_result_loc)
6237{
6238 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
6239 result_loc_cast->base.id = ResultLocIdCast;
6240 result_loc_cast->base.source_instruction = dest_type;
6241 ir_ref_instruction(dest_type, irb->current_basic_block);
6242 result_loc_cast->parent = parent_result_loc;
6243
6244 ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
6245
6246 return result_loc_cast;
6247}
6248
62176249static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
62186250 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)
62196251{
......@@ -6282,7 +6314,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
62826314
62836315 // Create a result location for the initialization expression.
62846316 ResultLocVar *result_loc_var = ir_build_var_result_loc(irb, alloca, var);
6285 ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr;
6317 ResultLoc *init_result_loc;
6318 ResultLocCast *result_loc_cast;
6319 if (type_instruction != nullptr) {
6320 result_loc_cast = ir_build_cast_result_loc(irb, type_instruction, &result_loc_var->base);
6321 init_result_loc = &result_loc_cast->base;
6322 } else {
6323 result_loc_cast = nullptr;
6324 init_result_loc = &result_loc_var->base;
6325 }
62866326
62876327 Scope *init_scope = is_comptime_scalar ?
62886328 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
62986338 if (init_value == irb->codegen->invalid_instruction)
62996339 return irb->codegen->invalid_instruction;
63006340
6301 if (type_instruction != nullptr) {
6302 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, node, type_instruction, init_value,
6303 &result_loc_var->base);
6341 if (result_loc_cast != nullptr) {
6342 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,
6343 init_value, result_loc_cast);
63046344 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
63056345 }
63066346
......@@ -9571,7 +9611,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
95719611 }
95729612
95739613 ir_add_error(ira, instruction,
9574 buf_sprintf("%s value %s cannot be implicitly casted to type '%s'",
9614 buf_sprintf("%s value %s cannot be coerced to type '%s'",
95759615 num_lit_str,
95769616 buf_ptr(val_buf),
95779617 buf_ptr(&other_type->name)));
......@@ -13026,8 +13066,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1302613066 return ira->codegen->invalid_instruction;
1302713067}
1302813068
13029static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type,
13030 ResultLoc *result_loc)
13069static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *source_instr,
13070 IrInstruction *value, ZigType *expected_type, ResultLoc *result_loc)
1303113071{
1303213072 assert(value);
1303313073 assert(value != ira->codegen->invalid_instruction);
......@@ -13041,11 +13081,11 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction
1304113081 if (value->value.type->id == ZigTypeIdUnreachable)
1304213082 return value;
1304313083
13044 return ir_analyze_cast(ira, value, expected_type, value, result_loc);
13084 return ir_analyze_cast(ira, source_instr, expected_type, value, result_loc);
1304513085}
1304613086
1304713087static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
13048 return ir_implicit_cast_with_result(ira, value, expected_type, nullptr);
13088 return ir_implicit_cast_with_result(ira, value, value, expected_type, nullptr);
1304913089}
1305013090
1305113091static 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
1543515475 case ResultLocIdNone:
1543615476 case ResultLocIdVar:
1543715477 case ResultLocIdBitCast:
15478 case ResultLocIdCast:
1543815479 return nullptr;
1543915480 case ResultLocIdInstruction:
1544015481 return result_loc->source_instruction->child->value.type;
......@@ -15489,6 +15530,7 @@ static bool ir_result_has_type(ResultLoc *result_loc) {
1548915530 case ResultLocIdReturn:
1549015531 case ResultLocIdInstruction:
1549115532 case ResultLocIdBitCast:
15533 case ResultLocIdCast:
1549215534 return true;
1549315535 case ResultLocIdVar:
1549415536 return reinterpret_cast<ResultLocVar *>(result_loc)->var->decl_node->data.variable_declaration.type != nullptr;
......@@ -15496,6 +15538,26 @@ static bool ir_result_has_type(ResultLoc *result_loc) {
1549615538 zig_unreachable();
1549715539}
1549815540
15541static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,
15542 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
15543{
15544 Error err;
15545
15546 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
15547 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
15548 return ira->codegen->invalid_instruction;
15549 alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
15550 PtrLenSingle, 0, 0, 0, false);
15551 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
15552 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
15553 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
15554 fn_entry->alloca_gen_list.append(alloca_gen);
15555 }
15556 result_loc->written = true;
15557 result_loc->resolved_loc = &alloca_gen->base;
15558 return result_loc->resolved_loc;
15559}
15560
1549915561// when calling this function, at the callsite must check for result type noreturn and propagate it up
1550015562static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
1550115563 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
1551815580 return nullptr;
1551915581 }
1552015582 // need to return a result location and don't have one. use a stack allocation
15521 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
15522 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
15523 return ira->codegen->invalid_instruction;
15524 alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
15525 PtrLenSingle, 0, 0, 0, false);
15526 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
15527 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
15528 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
15529 fn_entry->alloca_gen_list.append(alloca_gen);
15530 }
15531 result_loc->written = true;
15532 result_loc->resolved_loc = &alloca_gen->base;
15533 return result_loc->resolved_loc;
15583 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
15584 force_runtime, non_null_comptime);
1553415585 }
1553515586 case ResultLocIdVar: {
1553615587 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
......@@ -15668,6 +15719,67 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1566815719 result_loc->resolved_loc = parent_result_loc;
1566915720 return result_loc->resolved_loc;
1567015721 }
15722 case ResultLocIdCast: {
15723 if (value != nullptr && value->value.special != ConstValSpecialRuntime)
15724 return nullptr;
15725 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
15726 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
15727 if (type_is_invalid(dest_type))
15728 return ira->codegen->invalid_instruction;
15729
15730 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type,
15731 result_cast->base.source_instruction->source_node, false);
15732 if (const_cast_result.id == ConstCastResultIdInvalid)
15733 return ira->codegen->invalid_instruction;
15734 if (const_cast_result.id != ConstCastResultIdOk) {
15735 // We will not be able to provide a result location for this value. Create
15736 // a new result location.
15737 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
15738 force_runtime, non_null_comptime);
15739 }
15740
15741 // In this case we can pointer cast the result location.
15742 IrInstruction *casted_value;
15743 if (value != nullptr) {
15744 casted_value = ir_implicit_cast(ira, value, dest_type);
15745 } else {
15746 casted_value = nullptr;
15747 }
15748
15749 if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) {
15750 return casted_value;
15751 }
15752
15753 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
15754 dest_type, casted_value, force_runtime, non_null_comptime, true);
15755 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
15756 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
15757 {
15758 return parent_result_loc;
15759 }
15760 ZigType *parent_ptr_type = parent_result_loc->value.type;
15761 assert(parent_ptr_type->id == ZigTypeIdPointer);
15762 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
15763 ResolveStatusAlignmentKnown)))
15764 {
15765 return ira->codegen->invalid_instruction;
15766 }
15767 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
15768 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
15769 return ira->codegen->invalid_instruction;
15770 }
15771 if (!type_has_bits(value_type)) {
15772 parent_ptr_align = 0;
15773 }
15774 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
15775 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
15776 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
15777
15778 result_loc->written = true;
15779 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
15780 ptr_type, result_cast->base.source_instruction, false);
15781 return result_loc->resolved_loc;
15782 }
1567115783 case ResultLocIdBitCast: {
1567215784 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
1567315785 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
1579015902 return result_loc;
1579115903}
1579215904
15793static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
15794 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
15795 if (type_is_invalid(dest_type))
15796 return ira->codegen->invalid_instruction;
15797
15798 IrInstruction *target = instruction->target->child;
15799 if (type_is_invalid(target->value.type))
15800 return ira->codegen->invalid_instruction;
15801
15802 return ir_implicit_cast_with_result(ira, target, dest_type, instruction->result_loc);
15803}
15804
1580515905static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) {
1580615906 ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
1580715907 if (type_is_invalid(implicit_elem_type))
......@@ -15864,6 +15964,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
1586415964 case ResultLocIdNone:
1586515965 case ResultLocIdInstruction:
1586615966 case ResultLocIdBitCast:
15967 case ResultLocIdCast:
1586715968 break;
1586815969 }
1586915970}
......@@ -16903,25 +17004,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1690317004
1690417005 if (is_comptime || instr_is_comptime(fn_ref)) {
1690517006 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
16906 ZigType *dest_type = ir_resolve_type(ira, fn_ref);
16907 if (type_is_invalid(dest_type))
16908 return ira->codegen->invalid_instruction;
16909
16910 size_t actual_param_count = call_instruction->arg_count;
16911
16912 if (actual_param_count != 1) {
16913 ir_add_error_node(ira, call_instruction->base.source_node,
16914 buf_sprintf("cast expression expects exactly one parameter"));
16915 return ira->codegen->invalid_instruction;
16916 }
16917
16918 IrInstruction *arg = call_instruction->args[0]->child;
16919
16920 IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg,
16921 call_instruction->result_loc);
16922 if (type_is_invalid(cast_instruction->value.type))
17007 ZigType *ty = ir_resolve_type(ira, fn_ref);
17008 if (ty == nullptr)
1692317009 return ira->codegen->invalid_instruction;
16924 return ir_finish_anal(ira, cast_instruction);
17010 ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,
17011 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
17012 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
17013 buf_sprintf("use @as builtin for type coercion"));
17014 return ira->codegen->invalid_instruction;
1692517015 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
1692617016 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
1692717017 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
1745317543 if (peer_parent != nullptr && ir_result_has_type(peer_parent->parent)) {
1745417544 if (peer_parent->parent->id == ResultLocIdReturn) {
1745517545 resolved_type = ira->explicit_return_type;
17546 } else if (peer_parent->parent->id == ResultLocIdCast) {
17547 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
17548 if (type_is_invalid(resolved_type))
17549 return ira->codegen->invalid_instruction;
1745617550 } else {
1745717551 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type;
1745817552 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
2595826052 return ir_const_void(ira, &instruction->base);
2595926053}
2596026054
26055static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
26056 IrInstruction *operand = instruction->operand->child;
26057 if (type_is_invalid(operand->value.type))
26058 return operand;
26059
26060 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
26061 &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true);
26062 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))
26063 return result_loc;
26064
26065 if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {
26066 return instruction->result_loc_cast->parent->gen_instruction;
26067 }
26068
26069 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
26070 if (type_is_invalid(dest_type))
26071 return ira->codegen->invalid_instruction;
26072 return ir_implicit_cast_with_result(ira, &instruction->base, operand, dest_type, nullptr);
26073}
26074
2596126075static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
2596226076 IrInstruction *operand = instruction->operand->child;
2596326077 if (type_is_invalid(operand->value.type))
src/ir_print.cpp+15-8
......@@ -601,6 +601,12 @@ static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_
601601 fprintf(irp->f, ")");
602602}
603603
604static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) {
605 fprintf(irp->f, "cast(ty=");
606 ir_print_other_instruction(irp, result_loc_cast->base.source_instruction);
607 fprintf(irp->f, ")");
608}
609
604610static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
605611 switch (result_loc->id) {
606612 case ResultLocIdInvalid:
......@@ -619,6 +625,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
619625 return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc);
620626 case ResultLocIdBitCast:
621627 return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc);
628 case ResultLocIdCast:
629 return ir_print_result_loc_cast(irp, (ResultLocCast *)result_loc);
622630 case ResultLocIdPeerParent:
623631 fprintf(irp->f, "peer_parent");
624632 return;
......@@ -1484,6 +1492,13 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc
14841492 fprintf(irp->f, ")");
14851493}
14861494
1495static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
1496 fprintf(irp->f, "@implicitCast(");
1497 ir_print_other_instruction(irp, instruction->operand);
1498 fprintf(irp->f, ")result=");
1499 ir_print_result_loc(irp, &instruction->result_loc_cast->base);
1500}
1501
14871502static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {
14881503 fprintf(irp->f, "@bitCast(");
14891504 ir_print_other_instruction(irp, instruction->operand);
......@@ -1739,14 +1754,6 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio
17391754 fprintf(irp->f, ")");
17401755}
17411756
1742static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
1743 fprintf(irp->f, "@implicitCast(");
1744 ir_print_other_instruction(irp, instruction->dest_type);
1745 fprintf(irp->f, ",");
1746 ir_print_other_instruction(irp, instruction->target);
1747 fprintf(irp->f, ")");
1748}
1749
17501757static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {
17511758 fprintf(irp->f, "ResolveResult(");
17521759 ir_print_result_loc(irp, instruction->result_loc);
src/translate_c.cpp+15-14
......@@ -221,6 +221,15 @@ static AstNode *trans_create_node_opaque(Context *c) {
221221 return trans_create_node_builtin_fn_call_str(c, "OpaqueType");
222222}
223223
224static AstNode *trans_create_node_cast(Context *c, AstNode *dest_type, AstNode *operand) {
225 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
226 node->data.fn_call_expr.fn_ref_expr = trans_create_node_symbol(c, buf_create_from_str("as"));
227 node->data.fn_call_expr.modifier = CallModifierBuiltin;
228 node->data.fn_call_expr.params.append(dest_type);
229 node->data.fn_call_expr.params.append(operand);
230 return node;
231}
232
224233static AstNode *trans_create_node_fn_call_1(Context *c, AstNode *fn_ref_expr, AstNode *arg1) {
225234 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
226235 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) {
337346 return trans_create_node_unsigned_negative(c, x, false);
338347}
339348
340static AstNode *trans_create_node_cast(Context *c, AstNode *dest, AstNode *src) {
341 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
342 node->data.fn_call_expr.fn_ref_expr = dest;
343 node->data.fn_call_expr.params.resize(1);
344 node->data.fn_call_expr.params.items[0] = src;
345 return node;
346}
347
348349static AstNode *trans_create_node_unsigned_negative_type(Context *c, uint64_t x, bool is_negative,
349350 const char *type_name)
350351{
......@@ -701,7 +702,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location,
701702 if (c_is_unsigned_integer(c, dest_type) && qual_type_is_ptr(src_type)) {
702703 AstNode *addr_node = trans_create_node_builtin_fn_call_str(c, "ptrToInt");
703704 addr_node->data.fn_call_expr.params.append(expr);
704 return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), addr_node);
705 return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), addr_node);
705706 }
706707 if (c_is_unsigned_integer(c, src_type) && qual_type_is_ptr(dest_type)) {
707708 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,
712713 // TODO: maybe widen to increase size
713714 // TODO: maybe bitcast to change sign
714715 // TODO: maybe truncate to reduce size
715 return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), expr);
716 return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), expr);
716717}
717718
718719static bool c_is_signed_integer(Context *c, ZigClangQualType qt) {
......@@ -1527,7 +1528,7 @@ static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQua
15271528
15281529 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, rhs_expr, TransRValue);
15291530 if (rhs == nullptr) return nullptr;
1530 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1531 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
15311532
15321533 return trans_create_node_bin_op(c, lhs, bin_op, coerced_rhs);
15331534}
......@@ -1702,7 +1703,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
17021703
17031704 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
17041705 if (rhs == nullptr) return nullptr;
1705 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1706 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
17061707
17071708 return trans_create_node_bin_op(c, lhs, assign_op, coerced_rhs);
17081709 } else {
......@@ -1733,7 +1734,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
17331734
17341735 AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
17351736 if (rhs == nullptr) return nullptr;
1736 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1737 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
17371738
17381739 // operation_type(*_ref)
17391740 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)
26842685
26852686 // @TagType(Enum)(0)
26862687 AstNode *zero = trans_create_node_unsigned_negative(c, 0, false);
2687 AstNode *casted_zero = trans_create_node_fn_call_1(c, tag_type, zero);
2688 AstNode *casted_zero = trans_create_node_cast(c, tag_type, zero);
26882689
26892690 // @bitCast(Enum, @TagType(Enum)(0))
26902691 AstNode *bitcast = trans_create_node_builtin_fn_call_str(c, "bitCast");
test/compare_output.zig+34-34
......@@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
122122 \\
123123 \\pub fn main() void {
124124 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
125 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
125 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable;
126126 \\}
127127 , "Hello, world!\n 12 12 a\n");
128128
......@@ -145,75 +145,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
145145 \\ _ = c._setmode(1, c._O_BINARY);
146146 \\ }
147147 \\ _ = c.printf(c"0: %llu\n",
148 \\ u64(0));
148 \\ @as(u64, 0));
149149 \\ _ = c.printf(c"320402575052271: %llu\n",
150 \\ u64(320402575052271));
150 \\ @as(u64, 320402575052271));
151151 \\ _ = c.printf(c"0x01236789abcdef: %llu\n",
152 \\ u64(0x01236789abcdef));
152 \\ @as(u64, 0x01236789abcdef));
153153 \\ _ = c.printf(c"0xffffffffffffffff: %llu\n",
154 \\ u64(0xffffffffffffffff));
154 \\ @as(u64, 0xffffffffffffffff));
155155 \\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n",
156 \\ u64(0x000000ffffffffffffffff));
156 \\ @as(u64, 0x000000ffffffffffffffff));
157157 \\ _ = c.printf(c"0o1777777777777777777777: %llu\n",
158 \\ u64(0o1777777777777777777777));
158 \\ @as(u64, 0o1777777777777777777777));
159159 \\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n",
160 \\ u64(0o0000001777777777777777777777));
160 \\ @as(u64, 0o0000001777777777777777777777));
161161 \\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",
162 \\ u64(0b1111111111111111111111111111111111111111111111111111111111111111));
162 \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111));
163163 \\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",
164 \\ u64(0b0000001111111111111111111111111111111111111111111111111111111111111111));
164 \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111));
165165 \\
166166 \\ _ = c.printf(c"\n");
167167 \\
168168 \\ _ = c.printf(c"0.0: %.013a\n",
169 \\ f64(0.0));
169 \\ @as(f64, 0.0));
170170 \\ _ = c.printf(c"0e0: %.013a\n",
171 \\ f64(0e0));
171 \\ @as(f64, 0e0));
172172 \\ _ = c.printf(c"0.0e0: %.013a\n",
173 \\ f64(0.0e0));
173 \\ @as(f64, 0.0e0));
174174 \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
175 \\ f64(000000000000000000000000000000000000000000000000000000000.0e0));
175 \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0));
176176 \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
177 \\ f64(0.000000000000000000000000000000000000000000000000000000000e0));
177 \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0));
178178 \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
179 \\ f64(0.0e000000000000000000000000000000000000000000000000000000000));
179 \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000));
180180 \\ _ = c.printf(c"1.0: %.013a\n",
181 \\ f64(1.0));
181 \\ @as(f64, 1.0));
182182 \\ _ = c.printf(c"10.0: %.013a\n",
183 \\ f64(10.0));
183 \\ @as(f64, 10.0));
184184 \\ _ = c.printf(c"10.5: %.013a\n",
185 \\ f64(10.5));
185 \\ @as(f64, 10.5));
186186 \\ _ = c.printf(c"10.5e5: %.013a\n",
187 \\ f64(10.5e5));
187 \\ @as(f64, 10.5e5));
188188 \\ _ = c.printf(c"10.5e+5: %.013a\n",
189 \\ f64(10.5e+5));
189 \\ @as(f64, 10.5e+5));
190190 \\ _ = c.printf(c"50.0e-2: %.013a\n",
191 \\ f64(50.0e-2));
191 \\ @as(f64, 50.0e-2));
192192 \\ _ = c.printf(c"50e-2: %.013a\n",
193 \\ f64(50e-2));
193 \\ @as(f64, 50e-2));
194194 \\
195195 \\ _ = c.printf(c"\n");
196196 \\
197197 \\ _ = c.printf(c"0x1.0: %.013a\n",
198 \\ f64(0x1.0));
198 \\ @as(f64, 0x1.0));
199199 \\ _ = c.printf(c"0x10.0: %.013a\n",
200 \\ f64(0x10.0));
200 \\ @as(f64, 0x10.0));
201201 \\ _ = c.printf(c"0x100.0: %.013a\n",
202 \\ f64(0x100.0));
202 \\ @as(f64, 0x100.0));
203203 \\ _ = c.printf(c"0x103.0: %.013a\n",
204 \\ f64(0x103.0));
204 \\ @as(f64, 0x103.0));
205205 \\ _ = c.printf(c"0x103.7: %.013a\n",
206 \\ f64(0x103.7));
206 \\ @as(f64, 0x103.7));
207207 \\ _ = c.printf(c"0x103.70: %.013a\n",
208 \\ f64(0x103.70));
208 \\ @as(f64, 0x103.70));
209209 \\ _ = c.printf(c"0x103.70p4: %.013a\n",
210 \\ f64(0x103.70p4));
210 \\ @as(f64, 0x103.70p4));
211211 \\ _ = c.printf(c"0x103.70p5: %.013a\n",
212 \\ f64(0x103.70p5));
212 \\ @as(f64, 0x103.70p5));
213213 \\ _ = c.printf(c"0x103.70p+5: %.013a\n",
214 \\ f64(0x103.70p+5));
214 \\ @as(f64, 0x103.70p+5));
215215 \\ _ = c.printf(c"0x103.70p-5: %.013a\n",
216 \\ f64(0x103.70p-5));
216 \\ @as(f64, 0x103.70p-5));
217217 \\
218218 \\ return 0;
219219 \\}
......@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
323323 \\ const x: f64 = small;
324324 \\ const y = @floatToInt(i32, x);
325325 \\ const z = @intToFloat(f64, y);
326 \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4));
326 \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));
327327 \\ return 0;
328328 \\}
329329 , "3.25\n3\n3.00\n-0.40\n");
test/compile_errors.zig+66-68
......@@ -186,21 +186,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
186186 cases.add(
187187 "shift amount has to be an integer type",
188188 \\export fn entry() void {
189 \\ const x = 1 << &u8(10);
189 \\ const x = 1 << &@as(u8, 10);
190190 \\}
191191 ,
192 "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'",
192 "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'",
193193 "tmp.zig:2:17: note: referenced here",
194194 );
195195
196196 cases.add(
197197 "bit shifting only works on integer types",
198198 \\export fn entry() void {
199 \\ const x = &u8(1) << 10;
199 \\ const x = &@as(u8, 1) << 10;
200200 \\}
201201 ,
202 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",
203 "tmp.zig:2:22: note: referenced here",
202 "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'",
203 "tmp.zig:2:27: note: referenced here",
204204 );
205205
206206 cases.add(
......@@ -241,11 +241,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
241241 \\ var x: []align(true) i32 = undefined;
242242 \\}
243243 \\export fn entry2() void {
244 \\ var x: *align(f64(12.34)) i32 = undefined;
244 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
245245 \\}
246246 ,
247247 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
248 "tmp.zig:5:22: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
248 "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
249249 );
250250
251251 cases.addCase(x: {
......@@ -1243,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12431243 \\ var ptr: [*c]u8 = x;
12441244 \\}
12451245 ,
1246 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be implicitly casted to type 'usize'",
1246 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
12471247 "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
12481248 );
12491249
......@@ -1297,17 +1297,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12971297 cases.add(
12981298 "@truncate undefined value",
12991299 \\export fn entry() void {
1300 \\ var z = @truncate(u8, u16(undefined));
1300 \\ var z = @truncate(u8, @as(u16, undefined));
13011301 \\}
13021302 ,
1303 "tmp.zig:2:30: error: use of undefined value here causes undefined behavior",
1303 "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
13041304 );
13051305
13061306 cases.addTest(
13071307 "return invalid type from test",
13081308 \\test "example" { return 1; }
13091309 ,
1310 "tmp.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'",
1310 "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",
13111311 );
13121312
13131313 cases.add(
......@@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13321332 cases.add(
13331333 "@bitCast with different sizes inside an expression",
13341334 \\export fn entry() void {
1335 \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf);
1335 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
13361336 \\}
13371337 ,
13381338 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
......@@ -1464,8 +1464,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14641464 \\ var byte: u8 = spartan_count;
14651465 \\}
14661466 ,
1467 "tmp.zig:3:31: error: integer value 300 cannot be implicitly casted to type 'u8'",
1468 "tmp.zig:7:22: error: integer value 300 cannot be implicitly casted to type 'u8'",
1467 "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'",
1468 "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'",
14691469 "tmp.zig:11:20: error: expected type 'u8', found 'u16'",
14701470 );
14711471
......@@ -1498,7 +1498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14981498 \\ var x: i65536 = 1;
14991499 \\}
15001500 ,
1501 "tmp.zig:2:31: error: integer value 65536 cannot be implicitly casted to type 'u16'",
1501 "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
15021502 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
15031503 );
15041504
......@@ -1686,10 +1686,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16861686 cases.add(
16871687 "non float passed to @floatToInt",
16881688 \\export fn entry() void {
1689 \\ const x = @floatToInt(i32, i32(54));
1689 \\ const x = @floatToInt(i32, @as(i32, 54));
16901690 \\}
16911691 ,
1692 "tmp.zig:2:35: error: expected float type, found 'i32'",
1692 "tmp.zig:2:32: error: expected float type, found 'i32'",
16931693 );
16941694
16951695 cases.add(
......@@ -1698,7 +1698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16981698 \\ const x = @floatToInt(i8, 200);
16991699 \\}
17001700 ,
1701 "tmp.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'",
1701 "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
17021702 );
17031703
17041704 cases.add(
......@@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21202120 cases.add(
21212121 "@floatToInt comptime safety",
21222122 \\comptime {
2123 \\ _ = @floatToInt(i8, f32(-129.1));
2123 \\ _ = @floatToInt(i8, @as(f32, -129.1));
21242124 \\}
21252125 \\comptime {
2126 \\ _ = @floatToInt(u8, f32(-1.1));
2126 \\ _ = @floatToInt(u8, @as(f32, -1.1));
21272127 \\}
21282128 \\comptime {
2129 \\ _ = @floatToInt(u8, f32(256.1));
2129 \\ _ = @floatToInt(u8, @as(f32, 256.1));
21302130 \\}
21312131 ,
21322132 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
......@@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21972197 cases.add(
21982198 "error when evaluating return type",
21992199 \\const Foo = struct {
2200 \\ map: i32(i32),
2200 \\ map: @as(i32, i32),
22012201 \\
22022202 \\ fn init() Foo {
22032203 \\ return undefined;
......@@ -2207,7 +2207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22072207 \\ var rule_set = try Foo.init();
22082208 \\}
22092209 ,
2210 "tmp.zig:2:13: error: expected type 'i32', found 'type'",
2210 "tmp.zig:2:10: error: expected type 'i32', found 'type'",
22112211 );
22122212
22132213 cases.add(
......@@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23382338 cases.add(
23392339 "var not allowed in structs",
23402340 \\export fn entry() void {
2341 \\ var s = (struct{v: var}){.v=i32(10)};
2341 \\ var s = (struct{v: var}){.v=@as(i32, 10)};
23422342 \\}
23432343 ,
23442344 "tmp.zig:2:23: error: invalid token: 'var'",
......@@ -2357,10 +2357,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23572357 cases.add(
23582358 "comptime slice of undefined pointer non-zero len",
23592359 \\export fn entry() void {
2360 \\ const slice = ([*]i32)(undefined)[0..1];
2360 \\ const slice = @as([*]i32, undefined)[0..1];
23612361 \\}
23622362 ,
2363 "tmp.zig:2:38: error: non-zero length slice of undefined pointer",
2363 "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
23642364 );
23652365
23662366 cases.add(
......@@ -2657,10 +2657,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26572657 cases.add(
26582658 "cast negative integer literal to usize",
26592659 \\export fn entry() void {
2660 \\ const x = usize(-10);
2660 \\ const x = @as(usize, -10);
26612661 \\}
26622662 ,
2663 "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'",
2663 "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
26642664 );
26652665
26662666 cases.add(
......@@ -3384,11 +3384,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
33843384 \\ const x : i32 = if (b) h: { break :h 1; };
33853385 \\}
33863386 \\fn g(b: bool) void {
3387 \\ const y = if (b) h: { break :h i32(1); };
3387 \\ const y = if (b) h: { break :h @as(i32, 1); };
33883388 \\}
33893389 \\export fn entry() void { f(true); g(true); }
33903390 ,
3391 "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
3391 "tmp.zig:2:21: error: expected type 'i32', found 'void'",
33923392 "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
33933393 );
33943394
......@@ -3520,11 +3520,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35203520 cases.add(
35213521 "cast unreachable",
35223522 \\fn f() i32 {
3523 \\ return i32(return 1);
3523 \\ return @as(i32, return 1);
35243524 \\}
35253525 \\export fn entry() void { _ = f(); }
35263526 ,
3527 "tmp.zig:2:15: error: unreachable code",
3527 "tmp.zig:2:12: error: unreachable code",
35283528 );
35293529
35303530 cases.add(
......@@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35953595 \\ switch (n) {
35963596 \\ Number.One => 1,
35973597 \\ Number.Two => 2,
3598 \\ Number.Three => i32(3),
3598 \\ Number.Three => @as(i32, 3),
35993599 \\ }
36003600 \\}
36013601 \\
......@@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36163616 \\ switch (n) {
36173617 \\ Number.One => 1,
36183618 \\ Number.Two => 2,
3619 \\ Number.Three => i32(3),
3619 \\ Number.Three => @as(i32, 3),
36203620 \\ Number.Four => 4,
36213621 \\ Number.Two => 2,
36223622 \\ }
......@@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36403640 \\ switch (n) {
36413641 \\ Number.One => 1,
36423642 \\ Number.Two => 2,
3643 \\ Number.Three => i32(3),
3643 \\ Number.Three => @as(i32, 3),
36443644 \\ Number.Four => 4,
36453645 \\ Number.Two => 2,
36463646 \\ else => 10,
......@@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36853685 "switch expression - duplicate or overlapping integer value",
36863686 \\fn foo(x: u8) u8 {
36873687 \\ return switch (x) {
3688 \\ 0 ... 100 => u8(0),
3688 \\ 0 ... 100 => @as(u8, 0),
36893689 \\ 101 ... 200 => 1,
36903690 \\ 201, 203 ... 207 => 2,
36913691 \\ 206 ... 255 => 3,
......@@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37223722 cases.add(
37233723 "array concatenation with wrong type",
37243724 \\const src = "aoeu";
3725 \\const derp = usize(1234);
3725 \\const derp = @as(usize, 1234);
37263726 \\const a = derp ++ "foo";
37273727 \\
37283728 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
......@@ -3765,7 +3765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37653765 \\const x : u8 = 300;
37663766 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
37673767 ,
3768 "tmp.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'",
3768 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
37693769 );
37703770
37713771 cases.add(
......@@ -3887,8 +3887,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38873887 "division by zero",
38883888 \\const lit_int_x = 1 / 0;
38893889 \\const lit_float_x = 1.0 / 0.0;
3890 \\const int_x = u32(1) / u32(0);
3891 \\const float_x = f32(1.0) / f32(0.0);
3890 \\const int_x = @as(u32, 1) / @as(u32, 0);
3891 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
38923892 \\
38933893 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
38943894 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }
......@@ -3897,8 +3897,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38973897 ,
38983898 "tmp.zig:1:21: error: division by zero",
38993899 "tmp.zig:2:25: error: division by zero",
3900 "tmp.zig:3:22: error: division by zero",
3901 "tmp.zig:4:26: error: division by zero",
3900 "tmp.zig:3:27: error: division by zero",
3901 "tmp.zig:4:31: error: division by zero",
39023902 );
39033903
39043904 cases.add(
......@@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
45904590 \\var bytes: [ext()]u8 = undefined;
45914591 \\export fn f() void {
45924592 \\ for (bytes) |*b, i| {
4593 \\ b.* = u8(i);
4593 \\ b.* = @as(u8, i);
45944594 \\ }
45954595 \\}
45964596 ,
......@@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48744874 \\}
48754875 \\
48764876 \\fn foo() i32 {
4877 \\ return add(i32(1234));
4877 \\ return add(@as(i32, 1234));
48784878 \\}
48794879 \\
48804880 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
......@@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48864886 cases.add(
48874887 "pass integer literal to var args",
48884888 \\fn add(args: ...) i32 {
4889 \\ var sum = i32(0);
4889 \\ var sum = @as(i32, 0);
48904890 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
48914891 \\ sum += args[i];
48924892 \\ }}
......@@ -4908,7 +4908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49084908 \\ var vga_mem: u16 = 0xB8000;
49094909 \\}
49104910 ,
4911 "tmp.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'",
4911 "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
49124912 );
49134913
49144914 cases.add(
......@@ -5080,7 +5080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50805080 cases.add(
50815081 "pass const ptr to mutable ptr fn",
50825082 \\fn foo() bool {
5083 \\ const a = ([]const u8)("a",);
5083 \\ const a = @as([]const u8, "a",);
50845084 \\ const b = &a;
50855085 \\ return ptrEql(b, b);
50865086 \\}
......@@ -5581,10 +5581,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55815581 cases.add(
55825582 "explicit cast float literal to integer when there is a fraction component",
55835583 \\export fn entry() i32 {
5584 \\ return i32(12.34);
5584 \\ return @as(i32, 12.34);
55855585 \\}
55865586 ,
5587 "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
5587 "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
55885588 );
55895589
55905590 cases.add(
......@@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55995599 cases.add(
56005600 "@shlExact shifts out 1 bits",
56015601 \\comptime {
5602 \\ const x = @shlExact(u8(0b01010101), 2);
5602 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
56035603 \\}
56045604 ,
56055605 "tmp.zig:2:15: error: operation caused overflow",
......@@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56085608 cases.add(
56095609 "@shrExact shifts out 1 bits",
56105610 \\comptime {
5611 \\ const x = @shrExact(u8(0b10101010), 2);
5611 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
56125612 \\}
56135613 ,
56145614 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
......@@ -5671,16 +5671,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56715671 \\export fn entry() void {
56725672 \\ var foo = Foo { .a = 1, .b = 10 };
56735673 \\ foo.b += 1;
5674 \\ bar((*[1]u32)(&foo.b)[0..]);
5674 \\ bar(@as(*[1]u32, &foo.b)[0..]);
56755675 \\}
56765676 \\
56775677 \\fn bar(x: []u32) void {
56785678 \\ x[0] += 1;
56795679 \\}
56805680 ,
5681 "tmp.zig:9:18: error: cast increases pointer alignment",
5682 "tmp.zig:9:23: note: '*align(1) u32' has alignment 1",
5683 "tmp.zig:9:18: note: '*[1]u32' has alignment 4",
5681 "tmp.zig:9:9: error: cast increases pointer alignment",
5682 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
5683 "tmp.zig:9:9: note: '*[1]u32' has alignment 4",
56845684 );
56855685
56865686 cases.add(
......@@ -5699,10 +5699,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56995699 cases.add(
57005700 "@alignCast expects pointer or slice",
57015701 \\export fn entry() void {
5702 \\ @alignCast(4, u32(3));
5702 \\ @alignCast(4, @as(u32, 3));
57035703 \\}
57045704 ,
5705 "tmp.zig:2:22: error: expected pointer or slice, found 'u32'",
5705 "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
57065706 );
57075707
57085708 cases.add(
......@@ -5740,11 +5740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57405740 );
57415741
57425742 cases.add(
5743 "wrong pointer implicitly casted to pointer to @OpaqueType()",
5743 "wrong pointer coerced to pointer to @OpaqueType()",
57445744 \\const Derp = @OpaqueType();
57455745 \\extern fn bar(d: *Derp) void;
57465746 \\export fn foo() void {
5747 \\ var x = u8(1);
5747 \\ var x = @as(u8, 1);
57485748 \\ bar(@ptrCast(*c_void, &x));
57495749 \\}
57505750 ,
......@@ -5793,27 +5793,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57935793 "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
57945794 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",
57955795 "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
5796 "tmp.zig:26:4: error: unreachable code",
5796 "tmp.zig:26:22: error: unreachable code",
57975797 );
57985798
57995799 cases.add(
58005800 "wrong types given to atomic order args in cmpxchg",
58015801 \\export fn entry() void {
58025802 \\ var x: i32 = 1234;
5803 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {}
5803 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
58045804 \\}
58055805 ,
5806 "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
5806 "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
58075807 );
58085808
58095809 cases.add(
58105810 "wrong types given to @export",
58115811 \\extern fn entry() void { }
58125812 \\comptime {
5813 \\ @export("entry", entry, u32(1234));
5813 \\ @export("entry", entry, @as(u32, 1234));
58145814 \\}
58155815 ,
5816 "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
5816 "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
58175817 );
58185818
58195819 cases.add(
......@@ -6185,7 +6185,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
61856185 \\};
61866186 \\
61876187 \\export fn entry() void {
6188 \\ var y = u3(3);
6188 \\ var y = @as(u3, 3);
61896189 \\ var x = @intToEnum(Small, y);
61906190 \\}
61916191 ,
......@@ -6722,8 +6722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67226722 "tmp.zig:1:1: note: declared here",
67236723 );
67246724
6725 // fixed bug #2032
6726 cases.add(
6725 cases.add( // fixed bug #2032
67276726 "compile diagnostic string for top level decl type",
67286727 \\export fn entry() void {
67296728 \\ var foo: u32 = @This(){};
......@@ -6731,6 +6730,5 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67316730 ,
67326731 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",
67336732 "tmp.zig:1:1: note: (root) declared here",
6734 "tmp.zig:2:5: note: referenced here",
67356733 );
67366734}
test/stage1/behavior/align.zig+2-2
......@@ -7,7 +7,7 @@ var foo: u8 align(4) = 100;
77test "global variable alignment" {
88 expect(@typeOf(&foo).alignment == 4);
99 expect(@typeOf(&foo) == *align(4) u8);
10 const slice = (*[1]u8)(&foo)[0..];
10 const slice = @as(*[1]u8, &foo)[0..];
1111 expect(@typeOf(slice) == []align(4) u8);
1212}
1313
......@@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
6161test "implicitly decreasing slice alignment" {
6262 const a: u32 align(4) = 3;
6363 const b: u32 align(8) = 4;
64 expect(addUnalignedSlice((*const [1]u32)(&a)[0..], (*const [1]u32)(&b)[0..]) == 7);
64 expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
6565}
6666fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
6767 return a[0] + b[0];
test/stage1/behavior/array.zig+2-2
......@@ -12,7 +12,7 @@ test "arrays" {
1212 }
1313
1414 i = 0;
15 var accumulator = u32(0);
15 var accumulator = @as(u32, 0);
1616 while (i < 5) {
1717 accumulator += array[i];
1818
......@@ -149,7 +149,7 @@ test "implicit cast single-item pointer" {
149149
150150fn testImplicitCastSingleItemPtr() void {
151151 var byte: u8 = 100;
152 const slice = (*[1]u8)(&byte)[0..];
152 const slice = @as(*[1]u8, &byte)[0..];
153153 slice[0] += 1;
154154 expect(byte == 101);
155155}
test/stage1/behavior/asm.zig+8-8
......@@ -45,42 +45,42 @@ test "alternative constraints" {
4545test "sized integer/float in asm input" {
4646 asm volatile (""
4747 :
48 : [_] "m" (usize(3))
48 : [_] "m" (@as(usize, 3))
4949 : ""
5050 );
5151 asm volatile (""
5252 :
53 : [_] "m" (i15(-3))
53 : [_] "m" (@as(i15, -3))
5454 : ""
5555 );
5656 asm volatile (""
5757 :
58 : [_] "m" (u3(3))
58 : [_] "m" (@as(u3, 3))
5959 : ""
6060 );
6161 asm volatile (""
6262 :
63 : [_] "m" (i3(3))
63 : [_] "m" (@as(i3, 3))
6464 : ""
6565 );
6666 asm volatile (""
6767 :
68 : [_] "m" (u121(3))
68 : [_] "m" (@as(u121, 3))
6969 : ""
7070 );
7171 asm volatile (""
7272 :
73 : [_] "m" (i121(3))
73 : [_] "m" (@as(i121, 3))
7474 : ""
7575 );
7676 asm volatile (""
7777 :
78 : [_] "m" (f32(3.17))
78 : [_] "m" (@as(f32, 3.17))
7979 : ""
8080 );
8181 asm volatile (""
8282 :
83 : [_] "m" (f64(3.17))
83 : [_] "m" (@as(f64, 3.17))
8484 : ""
8585 );
8686}
test/stage1/behavior/async_fn.zig+5-5
......@@ -191,7 +191,7 @@ async fn testSuspendBlock() void {
191191
192192 // Test to make sure that @frame() works as advertised (issue #1296)
193193 // var our_handle: anyframe = @frame();
194 expect(a_promise == anyframe(@frame()));
194 expect(a_promise == @as(anyframe, @frame()));
195195
196196 global_result = true;
197197}
......@@ -543,7 +543,7 @@ test "pass string literal to async function" {
543543 fn hello(msg: []const u8) void {
544544 frame = @frame();
545545 suspend;
546 expectEqual(([]const u8)("hello"), msg);
546 expectEqual(@as([]const u8, "hello"), msg);
547547 ok = true;
548548 }
549549 };
......@@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" {
10481048 return await @asyncCall(frame, {}, amain, x - 1);
10491049 }
10501050 };
1051 _ = async S.amain(u32(1));
1051 _ = async S.amain(@as(u32, 1));
10521052 resume S.global_frame;
10531053 expect(S.global_ok);
10541054}
......@@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" {
10801080 };
10811081 };
10821082 var res: S.Foo = undefined;
1083 var frame: @typeOf(async S.amain(u32(1))) = undefined;
1084 _ = @asyncCall(&frame, &res, S.amain, u32(1));
1083 var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined;
1084 _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1));
10851085 resume S.global_frame;
10861086 expect(S.global_ok);
10871087 expect(res.x == 1);
test/stage1/behavior/atomics.zig+3-3
......@@ -98,12 +98,12 @@ test "cmpxchg with ignored result" {
9898
9999 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
100100
101 expectEqual(i32(5678), x);
101 expectEqual(@as(i32, 5678), x);
102102}
103103
104var a_global_variable = u32(1234);
104var a_global_variable = @as(u32, 1234);
105105
106106test "cmpxchg on a global variable" {
107107 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
108 expectEqual(u32(42), a_global_variable);
108 expectEqual(@as(u32, 42), a_global_variable);
109109}
test/stage1/behavior/bitreverse.zig+14-14
......@@ -46,24 +46,24 @@ fn testBitReverse() void {
4646 expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
4848 // using comptime_ints, signed, positive
49 expect(@bitReverse(u8, u8(0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));
51 expect(@bitReverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));
52 expect(@bitReverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));
53 expect(@bitReverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));
54 expect(@bitReverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));
55 expect(@bitReverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));
56 expect(@bitReverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));
57 expect(@bitReverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));
58 expect(@bitReverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));
49 expect(@bitReverse(u8, @as(u8, 0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
51 expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
52 expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
53 expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
54 expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
55 expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
56 expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
57 expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
58 expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
5959
6060 // using signed, negative. Compare to runtime ints returned from llvm.
6161 var neg8: i8 = -18;
62 expect(@bitReverse(i8, i8(-18)) == @bitReverse(i8, neg8));
62 expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
6363 var neg16: i16 = -32694;
64 expect(@bitReverse(i16, i16(-32694)) == @bitReverse(i16, neg16));
64 expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
6565 var neg24: i24 = -6773785;
66 expect(@bitReverse(i24, i24(-6773785)) == @bitReverse(i24, neg24));
66 expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
6767 var neg32: i32 = -16773785;
68 expect(@bitReverse(i32, i32(-16773785)) == @bitReverse(i32, neg32));
68 expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
6969}
test/stage1/behavior/bool.zig+4-4
......@@ -8,14 +8,14 @@ test "bool literals" {
88test "cast bool to int" {
99 const t = true;
1010 const f = false;
11 expect(@boolToInt(t) == u32(1));
12 expect(@boolToInt(f) == u32(0));
11 expect(@boolToInt(t) == @as(u32, 1));
12 expect(@boolToInt(f) == @as(u32, 0));
1313 nonConstCastBoolToInt(t, f);
1414}
1515
1616fn nonConstCastBoolToInt(t: bool, f: bool) void {
17 expect(@boolToInt(t) == u32(1));
18 expect(@boolToInt(f) == u32(0));
17 expect(@boolToInt(t) == @as(u32, 1));
18 expect(@boolToInt(f) == @as(u32, 0));
1919}
2020
2121test "bool cmp" {
test/stage1/behavior/bugs/1322.zig+2-2
......@@ -13,7 +13,7 @@ const C = struct {};
1313
1414test "tagged union with all void fields but a meaningful tag" {
1515 var a: A = A{ .b = B{ .c = C{} } };
16 std.testing.expect(@TagType(B)(a.b) == @TagType(B).c);
16 std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c);
1717 a = A{ .b = B.None };
18 std.testing.expect(@TagType(B)(a.b) == @TagType(B).None);
18 std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None);
1919}
test/stage1/behavior/bugs/1421.zig+1-1
......@@ -10,5 +10,5 @@ const S = struct {
1010
1111test "functions with return type required to be comptime are generic" {
1212 const ti = S.method();
13 expect(builtin.TypeId(ti) == builtin.TypeId.Struct);
13 expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct);
1414}
test/stage1/behavior/bugs/2114.zig+4-4
......@@ -12,8 +12,8 @@ test "fixed" {
1212}
1313
1414fn testClz() void {
15 expect(ctz(u128(0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1)) == u128(0x80000000000000000000000000000000));
17 expect(ctz(u128(0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1))) == 127);
15 expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
17 expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
1919}
test/stage1/behavior/bugs/3046.zig+1-1
......@@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined;
1313
1414test "fixed" {
1515 some_struct = SomeStruct{
16 .field = couldFail() catch |_| i32(0),
16 .field = couldFail() catch |_| @as(i32, 0),
1717 };
1818 expect(some_struct.field == 1);
1919}
test/stage1/behavior/byteswap.zig+12-12
......@@ -11,24 +11,24 @@ test "@byteSwap integers" {
1111 t(u24, 0x123456, 0x563412);
1212 t(u32, 0x12345678, 0x78563412);
1313 t(u40, 0x123456789a, 0x9a78563412);
14 t(i48, 0x123456789abc, @bitCast(i48, u48(0xbc9a78563412)));
14 t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
1515 t(u56, 0x123456789abcde, 0xdebc9a78563412);
1616 t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
1717 t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
1818
19 t(u0, u0(0), 0);
20 t(i8, i8(-50), -50);
21 t(i16, @bitCast(i16, u16(0x1234)), @bitCast(i16, u16(0x3412)));
22 t(i24, @bitCast(i24, u24(0x123456)), @bitCast(i24, u24(0x563412)));
23 t(i32, @bitCast(i32, u32(0x12345678)), @bitCast(i32, u32(0x78563412)));
24 t(u40, @bitCast(i40, u40(0x123456789a)), u40(0x9a78563412));
25 t(i48, @bitCast(i48, u48(0x123456789abc)), @bitCast(i48, u48(0xbc9a78563412)));
26 t(i56, @bitCast(i56, u56(0x123456789abcde)), @bitCast(i56, u56(0xdebc9a78563412)));
27 t(i64, @bitCast(i64, u64(0x123456789abcdef1)), @bitCast(i64, u64(0xf1debc9a78563412)));
19 t(u0, @as(u0, 0), 0);
20 t(i8, @as(i8, -50), -50);
21 t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
22 t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
23 t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
24 t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
25 t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
26 t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
27 t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
2828 t(
2929 i128,
30 @bitCast(i128, u128(0x123456789abcdef11121314151617181)),
31 @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)),
30 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
31 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
3232 );
3333 }
3434 fn t(comptime I: type, input: I, expected_output: I) void {
test/stage1/behavior/cast.zig+12-12
......@@ -4,7 +4,7 @@ const mem = std.mem;
44const maxInt = std.math.maxInt;
55
66test "int to ptr cast" {
7 const x = usize(13);
7 const x = @as(usize, 13);
88 const y = @intToPtr(*u8, x);
99 const z = @ptrToInt(y);
1010 expect(z == 13);
......@@ -75,8 +75,8 @@ test "peer resolve array and const slice" {
7575 comptime testPeerResolveArrayConstSlice(true);
7676}
7777fn testPeerResolveArrayConstSlice(b: bool) void {
78 const value1 = if (b) "aoeu" else ([]const u8)("zz");
79 const value2 = if (b) ([]const u8)("zz") else "aoeu";
78 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
79 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
8080 expect(mem.eql(u8, value1, "aoeu"));
8181 expect(mem.eql(u8, value2, "zz"));
8282}
......@@ -90,7 +90,7 @@ const A = struct {
9090 a: i32,
9191};
9292fn castToOptionalTypeError(z: i32) void {
93 const x = i32(1);
93 const x = @as(i32, 1);
9494 const y: anyerror!?i32 = x;
9595 expect((try y).? == 1);
9696
......@@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" {
134134}
135135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
136136 if (c) {
137 return if (b) null else usize(0);
137 return if (b) null else @as(usize, 0);
138138 }
139139
140 return usize(3);
140 return @as(usize, 3);
141141}
142142
143143test "peer type resolution: [0]u8 and []const u8" {
......@@ -256,9 +256,9 @@ test "@floatToInt" {
256256}
257257
258258fn testFloatToInts() void {
259 const x = i32(1e4);
259 const x = @as(i32, 1e4);
260260 expect(x == 10000);
261 const y = @floatToInt(i32, f32(1e4));
261 const y = @floatToInt(i32, @as(f32, 1e4));
262262 expect(y == 10000);
263263 expectFloatToInt(f16, 255.1, u8, 255);
264264 expectFloatToInt(f16, 127.2, i8, 127);
......@@ -392,7 +392,7 @@ fn MakeType(comptime T: type) type {
392392 }
393393
394394 fn getNonNull() ?T {
395 return T(undefined);
395 return @as(T, undefined);
396396 }
397397 };
398398}
......@@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
442442}
443443
444444test "*usize to *void" {
445 var i = usize(0);
445 var i = @as(usize, 0);
446446 var v = @ptrCast(*void, &i);
447447 v.* = {};
448448}
......@@ -535,12 +535,12 @@ test "peer type resolution: unreachable, error set, unreachable" {
535535}
536536
537537test "implicit cast comptime_int to comptime_float" {
538 comptime expect(comptime_float(10) == f32(10));
538 comptime expect(@as(comptime_float, 10) == @as(f32, 10));
539539 expect(2 == 2.0);
540540}
541541
542542test "implicit cast *[0]T to E![]const u8" {
543 var x = (anyerror![]const u8)(&[0]u8{});
543 var x = @as(anyerror![]const u8, &[0]u8{});
544544 expect((x catch unreachable).len == 0);
545545}
546546
test/stage1/behavior/defer.zig+1-1
......@@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void {
5252}
5353
5454test "defer and labeled break" {
55 var i = usize(0);
55 var i = @as(usize, 0);
5656
5757 blk: {
5858 defer i += 1;
test/stage1/behavior/enum.zig+2-2
......@@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
788788 expect(1234 == switch (x) {
789789 MultipleChoice.A => 1,
790790 MultipleChoice.B => 2,
791 MultipleChoice.C => u32(1234),
791 MultipleChoice.C => @as(u32, 1234),
792792 MultipleChoice.D => 4,
793793 });
794794}
......@@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
816816 MultipleChoice2.A => 1,
817817 MultipleChoice2.B => 2,
818818 MultipleChoice2.C => 3,
819 MultipleChoice2.D => u32(1234),
819 MultipleChoice2.D => @as(u32, 1234),
820820 MultipleChoice2.Unspecified1 => 5,
821821 MultipleChoice2.Unspecified2 => 6,
822822 MultipleChoice2.Unspecified3 => 7,
test/stage1/behavior/error.zig+2-2
......@@ -51,7 +51,7 @@ test "error binary operator" {
5151 expect(b == 10);
5252}
5353fn errBinaryOperatorG(x: bool) anyerror!isize {
54 return if (x) error.ItBroke else isize(10);
54 return if (x) error.ItBroke else @as(isize, 10);
5555}
5656
5757test "unwrap simple value from error" {
......@@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" {
295295test "widen cast integer payload of error union function call" {
296296 const S = struct {
297297 fn errorable() !u64 {
298 var x = u64(try number());
298 var x = @as(u64, try number());
299299 return x;
300300 }
301301
test/stage1/behavior/eval.zig+18-18
......@@ -405,19 +405,19 @@ test "float literal at compile time not lossy" {
405405}
406406
407407test "f32 at compile time is lossy" {
408 expect(f32(1 << 24) + 1 == 1 << 24);
408 expect(@as(f32, 1 << 24) + 1 == 1 << 24);
409409}
410410
411411test "f64 at compile time is lossy" {
412 expect(f64(1 << 53) + 1 == 1 << 53);
412 expect(@as(f64, 1 << 53) + 1 == 1 << 53);
413413}
414414
415415test "f128 at compile time is lossy" {
416 expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
416 expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
417417}
418418
419419comptime {
420 expect(f128(1 << 113) == 10384593717069655257060992658440192);
420 expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
421421}
422422
423423pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
......@@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" {
434434}
435435
436436test "comptime slice of undefined pointer of length 0" {
437 const slice1 = ([*]i32)(undefined)[0..0];
437 const slice1 = @as([*]i32, undefined)[0..0];
438438 expect(slice1.len == 0);
439 const slice2 = ([*]i32)(undefined)[100..100];
439 const slice2 = @as([*]i32, undefined)[100..100];
440440 expect(slice2.len == 0);
441441}
442442
......@@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void {
444444 comptime var i: usize = 0;
445445 inline while (i < 4) : (i += 1) {
446446 s[i] = 0;
447 s[i] |= u32(b[i * 4 + 0]) << 24;
448 s[i] |= u32(b[i * 4 + 1]) << 16;
449 s[i] |= u32(b[i * 4 + 2]) << 8;
450 s[i] |= u32(b[i * 4 + 3]) << 0;
447 s[i] |= @as(u32, b[i * 4 + 0]) << 24;
448 s[i] |= @as(u32, b[i * 4 + 1]) << 16;
449 s[i] |= @as(u32, b[i * 4 + 2]) << 8;
450 s[i] |= @as(u32, b[i * 4 + 3]) << 0;
451451 }
452452}
453453
......@@ -557,14 +557,14 @@ test "array concat of slices gives slice" {
557557
558558test "comptime shlWithOverflow" {
559559 const ct_shifted: u64 = comptime amt: {
560 var amt = u64(0);
561 _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);
560 var amt = @as(u64, 0);
561 _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt);
562562 break :amt amt;
563563 };
564564
565565 const rt_shifted: u64 = amt: {
566 var amt = u64(0);
567 _ = @shlWithOverflow(u64, ~u64(0), 16, &amt);
566 var amt = @as(u64, 0);
567 _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt);
568568 break :amt amt;
569569 };
570570
......@@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void {
670670}
671671
672672test "variable inside inline loop that has different types on different iterations" {
673 testVarInsideInlineLoop(true, u32(42));
673 testVarInsideInlineLoop(true, @as(u32, 42));
674674}
675675
676676fn testVarInsideInlineLoop(args: ...) void {
......@@ -757,11 +757,11 @@ test "comptime bitwise operators" {
757757 expect(-3 | -1 == -1);
758758 expect(3 ^ -1 == -4);
759759 expect(-3 ^ -1 == 2);
760 expect(~i8(-1) == 0);
761 expect(~i128(-1) == 0);
760 expect(~@as(i8, -1) == 0);
761 expect(~@as(i128, -1) == 0);
762762 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
763763 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
764 expect(~u128(0) == 0xffffffffffffffffffffffffffffffff);
764 expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
765765 }
766766}
767767
test/stage1/behavior/floatop.zig+2-2
......@@ -117,11 +117,11 @@ test "@ln" {
117117fn testLn() void {
118118 {
119119 var a: f32 = e;
120 expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, u32(0x3f7fffff)));
120 expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, @as(u32, 0x3f7fffff)));
121121 }
122122 {
123123 var a: f64 = e;
124 expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, u64(0x3ff0000000000000)));
124 expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
125125 }
126126}
127127
test/stage1/behavior/fn.zig+2-2
......@@ -29,7 +29,7 @@ test "mutable local variables" {
2929 var zero: i32 = 0;
3030 expect(zero == 0);
3131
32 var i = i32(0);
32 var i = @as(i32, 0);
3333 while (i != 3) {
3434 i += 1;
3535 }
......@@ -43,7 +43,7 @@ test "separate block scopes" {
4343 }
4444
4545 const c = x: {
46 const no_conflict = i32(10);
46 const no_conflict = @as(i32, 10);
4747 break :x no_conflict;
4848 };
4949 expect(c == 10);
test/stage1/behavior/if.zig+2-2
......@@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 {
3232 } else if (c == 1) {
3333 return 1;
3434 } else {
35 return u8(2);
35 return @as(u8, 2);
3636 }
3737}
3838
......@@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" {
5858 var c = true;
5959 if (c) {
6060 answer = if (true) blk: {
61 break :blk i32(42);
61 break :blk @as(i32, 42);
6262 };
6363 }
6464 expect(answer == 42);
test/stage1/behavior/import.zig+2-2
......@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;
33const a_namespace = @import("import/a_namespace.zig");
44
55test "call fn via namespace lookup" {
6 expectEqual(i32(1234), a_namespace.foo());
6 expectEqual(@as(i32, 1234), a_namespace.foo());
77}
88
99test "importing the same thing gives the same import" {
......@@ -14,5 +14,5 @@ test "import in non-toplevel scope" {
1414 const S = struct {
1515 usingnamespace @import("import/a_namespace.zig");
1616 };
17 expectEqual(i32(1234), S.foo());
17 expectEqual(@as(i32, 1234), S.foo());
1818}
test/stage1/behavior/math.zig+12-12
......@@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void {
186186 assertFalse(90 >> 1 >> 2 != 90 >> 3);
187187 assertFalse(100 - 1 + 1000 != 1099);
188188 assertFalse(5 * 4 / 2 % 3 != 1);
189 assertFalse(i32(i32(5)) != 5);
189 assertFalse(@as(i32, @as(i32, 5)) != 5);
190190 assertFalse(!!false);
191 assertFalse(i32(7) != --(i32(7)));
191 assertFalse(@as(i32, 7) != --(@as(i32, 7)));
192192}
193193fn assertFalse(b: bool) void {
194194 expect(!b);
......@@ -256,10 +256,10 @@ const DivResult = struct {
256256
257257test "binary not" {
258258 expect(comptime x: {
259 break :x ~u16(0b1010101010101010) == 0b0101010101010101;
259 break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;
260260 });
261261 expect(comptime x: {
262 break :x ~u64(2147483647) == 18446744071562067968;
262 break :x ~@as(u64, 2147483647) == 18446744071562067968;
263263 });
264264 testBinaryNot(0b1010101010101010);
265265}
......@@ -472,7 +472,7 @@ test "comptime_int multiplication" {
472472
473473test "comptime_int shifting" {
474474 comptime {
475 expect((u128(1) << 127) == 0x80000000000000000000000000000000);
475 expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
476476 }
477477}
478478
......@@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" {
480480 comptime {
481481 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
482482
483 expect(u32(a & 0xffffffff) == 0xaaaaaaab);
483 expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
484484 a >>= 32;
485 expect(u32(a & 0xffffffff) == 0xeeeeeeef);
485 expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
486486 a >>= 32;
487 expect(u32(a & 0xffffffff) == 0xa0000001);
487 expect(@as(u32, a & 0xffffffff) == 0xa0000001);
488488 a >>= 32;
489 expect(u32(a & 0xffffffff) == 0xefffffff);
489 expect(@as(u32, a & 0xffffffff) == 0xefffffff);
490490 a >>= 32;
491491
492492 expect(a == 0);
......@@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void {
552552
553553test "comptime float rem int" {
554554 comptime {
555 var x = f32(1) % 2;
555 var x = @as(f32, 1) % 2;
556556 expect(x == 1.0);
557557 }
558558}
......@@ -568,8 +568,8 @@ test "remainder division" {
568568}
569569
570570fn remdiv(comptime T: type) void {
571 expect(T(1) == T(1) % T(2));
572 expect(T(1) == T(7) % T(3));
571 expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
572 expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
573573}
574574
575575test "@sqrt" {
test/stage1/behavior/misc.zig+8-8
......@@ -241,14 +241,14 @@ fn memFree(comptime T: type, memory: []T) void {}
241241
242242test "cast undefined" {
243243 const array: [100]u8 = undefined;
244 const slice = ([]const u8)(array);
244 const slice = @as([]const u8, array);
245245 testCastUndefined(slice);
246246}
247247fn testCastUndefined(x: []const u8) void {}
248248
249249test "cast small unsigned to larger signed" {
250 expect(castSmallUnsignedToLargerSigned1(200) == i16(200));
251 expect(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
250 expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
251 expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
252252}
253253fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
254254 return x;
......@@ -268,7 +268,7 @@ fn outer() i64 {
268268}
269269
270270test "pointer dereferencing" {
271 var x = i32(3);
271 var x = @as(i32, 3);
272272 const y = &x;
273273
274274 y.* += 1;
......@@ -350,7 +350,7 @@ fn testTakeAddressOfParameter(f: f32) void {
350350}
351351
352352test "pointer comparison" {
353 const a = ([]const u8)("a");
353 const a = @as([]const u8, "a");
354354 const b = &a;
355355 expect(ptrEql(b, b));
356356}
......@@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type {
500500}
501501
502502test "double implicit cast in same expression" {
503 var x = i32(u16(nine()));
503 var x = @as(i32, @as(u16, nine()));
504504 expect(x == 9);
505505}
506506fn nine() u8 {
......@@ -642,7 +642,7 @@ test "self reference through fn ptr field" {
642642
643643test "volatile load and store" {
644644 var number: i32 = 1234;
645 const ptr = (*volatile i32)(&number);
645 const ptr = @as(*volatile i32, &number);
646646 ptr.* += 1;
647647 expect(ptr.* == 1235);
648648}
......@@ -761,7 +761,7 @@ test "nested optional field in struct" {
761761
762762fn maybe(x: bool) anyerror!?u32 {
763763 return switch (x) {
764 true => u32(42),
764 true => @as(u32, 42),
765765 else => null,
766766 };
767767}
test/stage1/behavior/popcount.zig+1-1
......@@ -35,7 +35,7 @@ fn testPopCount() void {
3535 expect(@popCount(i8, x) == 2);
3636 }
3737 comptime {
38 expect(@popCount(u8, @bitCast(u8, i8(-120))) == 2);
38 expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
3939 }
4040 comptime {
4141 expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
test/stage1/behavior/pub_enum.zig+1-1
......@@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void {
99}
1010
1111test "cast with imported symbol" {
12 expect(other.size_t(42) == 42);
12 expect(@as(other.size_t, 42) == 42);
1313}
test/stage1/behavior/shuffle.zig+13-13
......@@ -7,39 +7,39 @@ test "@shuffle" {
77 fn doTheTest() void {
88 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
99 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
10 const mask: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 3, ~i32(3) };
10 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
1111 var res = @shuffle(i32, v, x, mask);
12 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 }));
12 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
1313
1414 // Implicit cast from array (of mask)
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~i32(2), 3, ~i32(3) });
16 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 }));
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
1717
1818 // Undefined
1919 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
2020 res = @shuffle(i32, v, undefined, mask2);
21 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 40, -2, 30, 2147483647 }));
21 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 }));
2222
2323 // Upcasting of b
2424 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
25 const mask3: @Vector(4, i32) = [4]i32{ ~i32(0), 2, ~i32(0), 3 };
25 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
2626 res = @shuffle(i32, x, v2, mask3);
27 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 2147483647, 4 }));
27 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 }));
2828
2929 // Upcasting of a
3030 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 1, ~i32(3) };
31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
3232 res = @shuffle(i32, v3, x, mask4);
33 expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, -2, 4 }));
33 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 }));
3434
3535 // bool
3636 // Disabled because of #3317
3737 if (@import("builtin").arch != .mipsel) {
3838 var x2: @Vector(4, bool) = [4]bool{ false, true, false, true };
3939 var v4: @Vector(2, bool) = [2]bool{ true, false };
40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 };
40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
4141 var res2 = @shuffle(bool, x2, v4, mask5);
42 expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false }));
42 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
4343 }
4444
4545 // TODO re-enable when LLVM codegen is fixed
......@@ -47,9 +47,9 @@ test "@shuffle" {
4747 if (false) {
4848 var x2: @Vector(3, bool) = [3]bool{ false, true, false };
4949 var v4: @Vector(2, bool) = [2]bool{ true, false };
50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 };
50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
5151 var res2 = @shuffle(bool, x2, v4, mask5);
52 expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false }));
52 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
5353 }
5454 }
5555 };
test/stage1/behavior/slicetobytes.zig+1-1
......@@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" {
1010 const S = struct {
1111 fn doTheTest() void {
1212 var foo: Foo = undefined;
13 var slice = @sliceToBytes(((*[1]Foo)(&foo))[0..1]);
13 var slice = @sliceToBytes(@as(*[1]Foo, &foo)[0..1]);
1414 slice[0] = 0x13;
1515 switch (builtin.endian) {
1616 builtin.Endian.Big => {
test/stage1/behavior/struct.zig+8-8
......@@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" {
388388 expect(s2.y == @intCast(u4, x2));
389389}
390390
391var x1 = u4(1);
392var x2 = u8(2);
391var x1 = @as(u4, 1);
392var x2 = @as(u8, 2);
393393
394394const Nibbles = packed struct {
395395 x: u4,
......@@ -545,9 +545,9 @@ test "packed struct with fp fields" {
545545 s.data[1] = 2.0;
546546 s.data[2] = 3.0;
547547 s.frob();
548 expectEqual(f32(6.0), s.data[0]);
549 expectEqual(f32(11.0), s.data[1]);
550 expectEqual(f32(20.0), s.data[2]);
548 expectEqual(@as(f32, 6.0), s.data[0]);
549 expectEqual(@as(f32, 11.0), s.data[1]);
550 expectEqual(@as(f32, 20.0), s.data[2]);
551551}
552552
553553test "use within struct scope" {
......@@ -558,7 +558,7 @@ test "use within struct scope" {
558558 }
559559 };
560560 };
561 expectEqual(i32(42), S.inner());
561 expectEqual(@as(i32, 42), S.inner());
562562}
563563
564564test "default struct initialization fields" {
......@@ -583,7 +583,7 @@ test "extern fn returns struct by value" {
583583 const S = struct {
584584 fn entry() void {
585585 var x = makeBar(10);
586 expectEqual(i32(10), x.handle);
586 expectEqual(@as(i32, 10), x.handle);
587587 }
588588
589589 const ExternBar = extern struct {
......@@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {
614614
615615 const ArrayList = struct {
616616 fn toSlice(self: *ArrayList) []*Foo {
617 return ([*]*Foo)(undefined)[0..0];
617 return @as([*]*Foo, undefined)[0..0];
618618 }
619619 };
620620
test/stage1/behavior/switch.zig+4-4
......@@ -68,7 +68,7 @@ test "switch statement" {
6868}
6969fn nonConstSwitch(foo: SwitchStatmentFoo) void {
7070 const val = switch (foo) {
71 SwitchStatmentFoo.A => i32(1),
71 SwitchStatmentFoo.A => @as(i32, 1),
7272 SwitchStatmentFoo.B => 2,
7373 SwitchStatmentFoo.C => 3,
7474 SwitchStatmentFoo.D => 4,
......@@ -127,7 +127,7 @@ test "switch with multiple expressions" {
127127 const x = switch (returnsFive()) {
128128 1, 2, 3 => 1,
129129 4, 5, 6 => 2,
130 else => i32(3),
130 else => @as(i32, 3),
131131 };
132132 expect(x == 2);
133133}
......@@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void {
186186
187187fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
188188 return switch (x) {
189 0 => u2(3),
189 0 => @as(u2, 3),
190190 1 => 2,
191191 2 => 1,
192192 3 => 0,
......@@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
195195
196196fn testSwitchHandleAllCasesRange(x: u8) u8 {
197197 return switch (x) {
198 0...100 => u8(0),
198 0...100 => @as(u8, 0),
199199 101...200 => 1,
200200 201, 203 => 2,
201201 202 => 4,
test/stage1/behavior/try.zig+3-3
......@@ -8,7 +8,7 @@ test "try on error union" {
88fn tryOnErrorUnionImpl() void {
99 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
1010 error.ItBroke, error.NoMem => 1,
11 error.CrappedOut => i32(2),
11 error.CrappedOut => @as(i32, 2),
1212 else => unreachable,
1313 };
1414 expect(x == 11);
......@@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 {
1919}
2020
2121test "try without vars" {
22 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);
22 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
2323 expect(result1 == 2);
2424
25 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);
25 const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2);
2626 expect(result2 == 1);
2727}
2828
test/stage1/behavior/type_info.zig+23-23
......@@ -13,7 +13,7 @@ test "type info: tag type, void info" {
1313fn testBasic() void {
1414 expect(@TagType(TypeInfo) == TypeId);
1515 const void_info = @typeInfo(void);
16 expect(TypeId(void_info) == TypeId.Void);
16 expect(@as(TypeId, void_info) == TypeId.Void);
1717 expect(void_info.Void == {});
1818}
1919
......@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {
2424
2525fn testIntFloat() void {
2626 const u8_info = @typeInfo(u8);
27 expect(TypeId(u8_info) == TypeId.Int);
27 expect(@as(TypeId, u8_info) == TypeId.Int);
2828 expect(!u8_info.Int.is_signed);
2929 expect(u8_info.Int.bits == 8);
3030
3131 const f64_info = @typeInfo(f64);
32 expect(TypeId(f64_info) == TypeId.Float);
32 expect(@as(TypeId, f64_info) == TypeId.Float);
3333 expect(f64_info.Float.bits == 64);
3434}
3535
......@@ -40,7 +40,7 @@ test "type info: pointer type info" {
4040
4141fn testPointer() void {
4242 const u32_ptr_info = @typeInfo(*u32);
43 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
43 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);
4444 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
4545 expect(u32_ptr_info.Pointer.is_const == false);
4646 expect(u32_ptr_info.Pointer.is_volatile == false);
......@@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" {
5555
5656fn testUnknownLenPtr() void {
5757 const u32_ptr_info = @typeInfo([*]const volatile f64);
58 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
58 expect(@as(TypeId,u32_ptr_info) == TypeId.Pointer);
5959 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
6060 expect(u32_ptr_info.Pointer.is_const == true);
6161 expect(u32_ptr_info.Pointer.is_volatile == true);
......@@ -70,7 +70,7 @@ test "type info: C pointer type info" {
7070
7171fn testCPtr() void {
7272 const ptr_info = @typeInfo([*c]align(4) const i8);
73 expect(TypeId(ptr_info) == TypeId.Pointer);
73 expect(@as(TypeId,ptr_info) == TypeId.Pointer);
7474 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);
7575 expect(ptr_info.Pointer.is_const);
7676 expect(!ptr_info.Pointer.is_volatile);
......@@ -85,7 +85,7 @@ test "type info: slice type info" {
8585
8686fn testSlice() void {
8787 const u32_slice_info = @typeInfo([]u32);
88 expect(TypeId(u32_slice_info) == TypeId.Pointer);
88 expect(@as(TypeId, u32_slice_info) == TypeId.Pointer);
8989 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
9090 expect(u32_slice_info.Pointer.is_const == false);
9191 expect(u32_slice_info.Pointer.is_volatile == false);
......@@ -100,7 +100,7 @@ test "type info: array type info" {
100100
101101fn testArray() void {
102102 const arr_info = @typeInfo([42]bool);
103 expect(TypeId(arr_info) == TypeId.Array);
103 expect(@as(TypeId, arr_info) == TypeId.Array);
104104 expect(arr_info.Array.len == 42);
105105 expect(arr_info.Array.child == bool);
106106}
......@@ -112,7 +112,7 @@ test "type info: optional type info" {
112112
113113fn testOptional() void {
114114 const null_info = @typeInfo(?void);
115 expect(TypeId(null_info) == TypeId.Optional);
115 expect(@as(TypeId, null_info) == TypeId.Optional);
116116 expect(null_info.Optional.child == void);
117117}
118118
......@@ -129,18 +129,18 @@ fn testErrorSet() void {
129129 };
130130
131131 const error_set_info = @typeInfo(TestErrorSet);
132 expect(TypeId(error_set_info) == TypeId.ErrorSet);
132 expect(@as(TypeId, error_set_info) == TypeId.ErrorSet);
133133 expect(error_set_info.ErrorSet.?.len == 3);
134134 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
135135 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));
136136
137137 const error_union_info = @typeInfo(TestErrorSet!usize);
138 expect(TypeId(error_union_info) == TypeId.ErrorUnion);
138 expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion);
139139 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
140140 expect(error_union_info.ErrorUnion.payload == usize);
141141
142142 const global_info = @typeInfo(anyerror);
143 expect(TypeId(global_info) == TypeId.ErrorSet);
143 expect(@as(TypeId, global_info) == TypeId.ErrorSet);
144144 expect(global_info.ErrorSet == null);
145145}
146146
......@@ -158,7 +158,7 @@ fn testEnum() void {
158158 };
159159
160160 const os_info = @typeInfo(Os);
161 expect(TypeId(os_info) == TypeId.Enum);
161 expect(@as(TypeId, os_info) == TypeId.Enum);
162162 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
163163 expect(os_info.Enum.fields.len == 4);
164164 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
......@@ -174,7 +174,7 @@ test "type info: union info" {
174174
175175fn testUnion() void {
176176 const typeinfo_info = @typeInfo(TypeInfo);
177 expect(TypeId(typeinfo_info) == TypeId.Union);
177 expect(@as(TypeId, typeinfo_info) == TypeId.Union);
178178 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
179179 expect(typeinfo_info.Union.tag_type.? == TypeId);
180180 expect(typeinfo_info.Union.fields.len == 26);
......@@ -189,7 +189,7 @@ fn testUnion() void {
189189 };
190190
191191 const notag_union_info = @typeInfo(TestNoTagUnion);
192 expect(TypeId(notag_union_info) == TypeId.Union);
192 expect(@as(TypeId, notag_union_info) == TypeId.Union);
193193 expect(notag_union_info.Union.tag_type == null);
194194 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);
195195 expect(notag_union_info.Union.fields.len == 2);
......@@ -214,7 +214,7 @@ test "type info: struct info" {
214214
215215fn testStruct() void {
216216 const struct_info = @typeInfo(TestStruct);
217 expect(TypeId(struct_info) == TypeId.Struct);
217 expect(@as(TypeId, struct_info) == TypeId.Struct);
218218 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
219219 expect(struct_info.Struct.fields.len == 3);
220220 expect(struct_info.Struct.fields[1].offset == null);
......@@ -244,7 +244,7 @@ test "type info: function type info" {
244244
245245fn testFunction() void {
246246 const fn_info = @typeInfo(@typeOf(foo));
247 expect(TypeId(fn_info) == TypeId.Fn);
247 expect(@as(TypeId, fn_info) == TypeId.Fn);
248248 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
249249 expect(fn_info.Fn.is_generic);
250250 expect(fn_info.Fn.args.len == 2);
......@@ -253,7 +253,7 @@ fn testFunction() void {
253253
254254 const test_instance: TestStruct = undefined;
255255 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
256 expect(TypeId(bound_fn_info) == TypeId.BoundFn);
256 expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn);
257257 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
258258}
259259
......@@ -275,7 +275,7 @@ test "type info: vectors" {
275275
276276fn testVector() void {
277277 const vec_info = @typeInfo(@Vector(4, i32));
278 expect(TypeId(vec_info) == TypeId.Vector);
278 expect(@as(TypeId, vec_info) == TypeId.Vector);
279279 expect(vec_info.Vector.len == 4);
280280 expect(vec_info.Vector.child == i32);
281281}
......@@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" {
288288fn testAnyFrame() void {
289289 {
290290 const anyframe_info = @typeInfo(anyframe->i32);
291 expect(TypeId(anyframe_info) == .AnyFrame);
291 expect(@as(TypeId,anyframe_info) == .AnyFrame);
292292 expect(anyframe_info.AnyFrame.child.? == i32);
293293 }
294294
295295 {
296296 const anyframe_info = @typeInfo(anyframe);
297 expect(TypeId(anyframe_info) == .AnyFrame);
297 expect(@as(TypeId,anyframe_info) == .AnyFrame);
298298 expect(anyframe_info.AnyFrame.child == null);
299299 }
300300}
......@@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" {
334334 if (std.mem.eql(u8, decl.name, "bar1")) {
335335 expect(decl.data.Fn.lib_name == null);
336336 } else {
337 std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?);
337 std.testing.expectEqual(@as([]const u8,"cool"), decl.data.Fn.lib_name.?);
338338 }
339339 }
340340 }
......@@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" {
342342
343343test "data field is a compile-time value" {
344344 const S = struct {
345 const Bar = isize(-1);
345 const Bar = @as(isize, -1);
346346 };
347347 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
348348}
test/stage1/behavior/union.zig+12-12
......@@ -14,7 +14,7 @@ const Agg = struct {
1414const v1 = Value{ .Int = 1234 };
1515const v2 = Value{ .Array = [_]u8{3} ** 9 };
1616
17const err = (anyerror!Agg)(Agg{
17const err = @as(anyerror!Agg, Agg{
1818 .val1 = v1,
1919 .val2 = v2,
2020});
......@@ -110,11 +110,11 @@ fn doTest() void {
110110}
111111
112112fn bar(value: Payload) i32 {
113 expect(Letter(value) == Letter.A);
113 expect(@as(Letter,value) == Letter.A);
114114 return switch (value) {
115115 Payload.A => |x| return x - 1244,
116 Payload.B => |x| if (x == 12.34) i32(20) else 21,
117 Payload.C => |x| if (x) i32(30) else 31,
116 Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,
117 Payload.C => |x| if (x) @as(i32, 30) else 31,
118118 };
119119}
120120
......@@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) {
127127test "simple union(enum(u32))" {
128128 var x = MultipleChoice.C;
129129 expect(x == MultipleChoice.C);
130 expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
130 expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60);
131131}
132132
133133const MultipleChoice2 = union(enum(u32)) {
......@@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" {
149149}
150150
151151fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
152 expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60);
153153 expect(1123 == switch (x) {
154154 MultipleChoice2.A => 1,
155155 MultipleChoice2.B => 2,
156 MultipleChoice2.C => |v| i32(1000) + v,
156 MultipleChoice2.C => |v| @as(i32, 1000) + v,
157157 MultipleChoice2.D => 4,
158158 MultipleChoice2.Unspecified1 => 5,
159159 MultipleChoice2.Unspecified2 => 6,
......@@ -208,12 +208,12 @@ test "cast union to tag type of union" {
208208}
209209
210210fn testCastUnionToTagType(x: TheUnion) void {
211 expect(TheTag(x) == TheTag.B);
211 expect(@as(TheTag,x) == TheTag.B);
212212}
213213
214214test "cast tag type of union to union" {
215215 var x: Value2 = Letter2.B;
216 expect(Letter2(x) == Letter2.B);
216 expect(@as(Letter2, x) == Letter2.B);
217217}
218218const Letter2 = enum {
219219 A,
......@@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) {
297297
298298fn testTaggedUnionInit(x: var) bool {
299299 const y = TaggedUnionWithAVoid{ .A = x };
300 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
300 return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;
301301}
302302
303303pub const UnionEnumNoPayloads = union(enum) {
......@@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" {
326326 var e = Expr{ .Literal = Literal{ .Bool = true } };
327327 const Tag = @TagType(Expr);
328328 comptime expect(@TagType(Tag) == u0);
329 var t = Tag(e);
329 var t = @as(Tag, e);
330330 expect(t == Expr.Literal);
331331}
332332
......@@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci
346346
347347 var e = Expr{ .Literal = Literal{ .Bool = true } };
348348 comptime expect(@TagType(Tag) == comptime_int);
349 var t = Tag(e);
349 var t = @as(Tag, e);
350350 expect(t == Expr.Literal);
351351 expect(@enumToInt(t) == 33);
352352 comptime expect(@enumToInt(t) == 33);
test/stage1/behavior/var_args.zig+5-5
......@@ -1,7 +1,7 @@
11const expect = @import("std").testing.expect;
22
33fn add(args: ...) i32 {
4 var sum = i32(0);
4 var sum = @as(i32, 0);
55 {
66 comptime var i: usize = 0;
77 inline while (i < args.len) : (i += 1) {
......@@ -12,8 +12,8 @@ fn add(args: ...) i32 {
1212}
1313
1414test "add arbitrary args" {
15 expect(add(i32(1), i32(2), i32(3), i32(4)) == 10);
16 expect(add(i32(1234)) == 1234);
15 expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
16 expect(add(@as(i32, 1234)) == 1234);
1717 expect(add() == 0);
1818}
1919
......@@ -26,8 +26,8 @@ test "send void arg to var args" {
2626}
2727
2828test "pass args directly" {
29 expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);
30 expect(addSomeStuff(i32(1234)) == 1234);
29 expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
30 expect(addSomeStuff(@as(i32, 1234)) == 1234);
3131 expect(addSomeStuff() == 0);
3232}
3333
test/stage1/behavior/vector.zig+25-25
......@@ -20,11 +20,11 @@ test "vector wrap operators" {
2020 fn doTheTest() void {
2121 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
2222 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
23 expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
23 expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
2626 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
27 expect(mem.eql(i32, ([4]i32)(-%z), [4]i32{ -1, -2, -3, -2147483648 }));
27 expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 }));
2828 }
2929 };
3030 S.doTheTest();
......@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
3636 fn doTheTest() void {
3737 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
3838 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
39 expect(mem.eql(bool, ([4]bool)(v == x), [4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, ([4]bool)(v != x), [4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, ([4]bool)(v < x), [4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, ([4]bool)(v > x), [4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, ([4]bool)(v <= x), [4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, ([4]bool)(v >= x), [4]bool{ true, false, true, true }));
39 expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));
4545 }
4646 };
4747 S.doTheTest();
......@@ -53,10 +53,10 @@ test "vector int operators" {
5353 fn doTheTest() void {
5454 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
5555 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
56 expect(mem.eql(i32, ([4]i32)(v + x), [4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, ([4]i32)(v - x), [4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, ([4]i32)(v * x), [4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, ([4]i32)(-v), [4]i32{ -10, -20, -30, -40 }));
56 expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));
6060 }
6161 };
6262 S.doTheTest();
......@@ -68,10 +68,10 @@ test "vector float operators" {
6868 fn doTheTest() void {
6969 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
7070 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
71 expect(mem.eql(f32, ([4]f32)(v + x), [4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, ([4]f32)(v - x), [4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, ([4]f32)(v * x), [4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, ([4]f32)(-x), [4]f32{ -1, -2, -3, -4 }));
71 expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));
7575 }
7676 };
7777 S.doTheTest();
......@@ -83,9 +83,9 @@ test "vector bit operators" {
8383 fn doTheTest() void {
8484 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
8585 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
86 expect(mem.eql(u8, ([4]u8)(v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, ([4]u8)(v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, ([4]u8)(v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
86 expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
8989 }
9090 };
9191 S.doTheTest();
......@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120120 {
121121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122122 var x: [4]u3 = v;
123 expect(mem.eql(u3, x, ([4]u3)(v)));
123 expect(mem.eql(u3, x, @as([4]u3, v)));
124124 }
125125 {
126126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127127 var x: [4]u2 = v;
128 expect(mem.eql(u2, x, ([4]u2)(v)));
128 expect(mem.eql(u2, x, @as([4]u2, v)));
129129 }
130130 {
131131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132132 var x: [4]u1 = v;
133 expect(mem.eql(u1, x, ([4]u1)(v)));
133 expect(mem.eql(u1, x, @as([4]u1, v)));
134134 }
135135 {
136136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137137 var x: [4]bool = v;
138 expect(mem.eql(bool, x, ([4]bool)(v)));
138 expect(mem.eql(bool, x, @as([4]bool, v)));
139139 }
140140 }
141141 };
test/stage1/behavior/void.zig+1-1
......@@ -26,7 +26,7 @@ test "iterate over a void slice" {
2626}
2727
2828fn times(n: usize) []const void {
29 return ([*]void)(undefined)[0..n];
29 return @as([*]void, undefined)[0..n];
3030}
3131
3232test "void optional" {
test/stage1/behavior/while.zig+8-8
......@@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" {
137137 const result = while (returnNull()) |value| {
138138 break value;
139139 } else
140 i32(2);
140 @as(i32, 2);
141141 expect(result == 2);
142142}
143143
......@@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" {
145145 const result = while (returnOptional(10)) |value| {
146146 break value;
147147 } else
148 i32(2);
148 @as(i32, 2);
149149 expect(result == 10);
150150}
151151
......@@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" {
153153 const result = while (returnError()) |value| {
154154 break value;
155155 } else |err|
156 i32(2);
156 @as(i32, 2);
157157 expect(result == 2);
158158}
159159
......@@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" {
161161 const result = while (returnSuccess(10)) |value| {
162162 break value;
163163 } else |err|
164 i32(2);
164 @as(i32, 2);
165165 expect(result == 10);
166166}
167167
168168test "while on bool with else result follow else prong" {
169169 const result = while (returnFalse()) {
170 break i32(10);
170 break @as(i32, 10);
171171 } else
172 i32(2);
172 @as(i32, 2);
173173 expect(result == 2);
174174}
175175
176176test "while on bool with else result follow break prong" {
177177 const result = while (returnTrue()) {
178 break i32(10);
178 break @as(i32, 10);
179179 } else
180 i32(2);
180 @as(i32, 2);
181181 expect(result == 10);
182182}
183183
test/tests.zig+2-2
......@@ -411,7 +411,7 @@ pub fn addPkgTests(
411411 const ArchTag = @TagType(builtin.Arch);
412412 if (test_target.disable_native and
413413 test_target.target.getOs() == builtin.os and
414 ArchTag(test_target.target.getArch()) == ArchTag(builtin.arch))
414 @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch))
415415 {
416416 continue;
417417 }
......@@ -429,7 +429,7 @@ pub fn addPkgTests(
429429 "bare";
430430
431431 const triple_prefix = if (test_target.target == .Native)
432 ([]const u8)("native")
432 @as([]const u8,"native")
433433 else
434434 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
435435
test/translate_c.zig+57-57
......@@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2828 ,
2929 \\pub fn foo() void {
3030 \\ var a: c_int = undefined;
31 \\ var b: u8 = u8(123);
31 \\ var b: u8 = @as(u8, 123);
3232 \\ const c: c_int = undefined;
33 \\ const d: c_uint = c_uint(440);
33 \\ const d: c_uint = @as(c_uint, 440);
3434 \\}
3535 );
3636
......@@ -144,7 +144,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
144144 \\pub extern fn foo() void;
145145 \\pub fn bar() void {
146146 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
147 \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, c_ulong(@ptrToInt(func_ptr)));
147 \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr)));
148148 \\}
149149 );
150150
......@@ -561,43 +561,43 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
561561 cases.add("u integer suffix after hex literal",
562562 \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
563563 ,
564 \\pub const SDL_INIT_VIDEO = c_uint(32);
564 \\pub const SDL_INIT_VIDEO = @as(c_uint, 32);
565565 );
566566
567567 cases.add("l integer suffix after hex literal",
568568 \\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
569569 ,
570 \\pub const SDL_INIT_VIDEO = c_long(32);
570 \\pub const SDL_INIT_VIDEO = @as(c_long, 32);
571571 );
572572
573573 cases.add("ul integer suffix after hex literal",
574574 \\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
575575 ,
576 \\pub const SDL_INIT_VIDEO = c_ulong(32);
576 \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
577577 );
578578
579579 cases.add("lu integer suffix after hex literal",
580580 \\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
581581 ,
582 \\pub const SDL_INIT_VIDEO = c_ulong(32);
582 \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
583583 );
584584
585585 cases.add("ll integer suffix after hex literal",
586586 \\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
587587 ,
588 \\pub const SDL_INIT_VIDEO = c_longlong(32);
588 \\pub const SDL_INIT_VIDEO = @as(c_longlong, 32);
589589 );
590590
591591 cases.add("ull integer suffix after hex literal",
592592 \\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
593593 ,
594 \\pub const SDL_INIT_VIDEO = c_ulonglong(32);
594 \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
595595 );
596596
597597 cases.add("llu integer suffix after hex literal",
598598 \\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
599599 ,
600 \\pub const SDL_INIT_VIDEO = c_ulonglong(32);
600 \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
601601 );
602602
603603 cases.add("zig keywords in C code",
......@@ -676,8 +676,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
676676 \\pub export fn log2(_arg_a: c_uint) c_int {
677677 \\ var a = _arg_a;
678678 \\ var i: c_int = 0;
679 \\ while (a > c_uint(0)) {
680 \\ a >>= @import("std").math.Log2Int(c_uint)(1);
679 \\ while (a > @as(c_uint, 0)) {
680 \\ a >>= @as(@import("std").math.Log2Int(c_uint), 1);
681681 \\ }
682682 \\ return i;
683683 \\}
......@@ -848,8 +848,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
848848 \\pub export fn log2(_arg_a: u32) c_int {
849849 \\ var a = _arg_a;
850850 \\ var i: c_int = 0;
851 \\ while (a > c_uint(0)) {
852 \\ a >>= u5(1);
851 \\ while (a > @as(c_uint, 0)) {
852 \\ a >>= @as(u5, 1);
853853 \\ }
854854 \\ return i;
855855 \\}
......@@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
937937 \\}
938938 ,
939939 \\pub export fn float_to_int(a: f32) c_int {
940 \\ return c_int(a);
940 \\ return @as(c_int, a);
941941 \\}
942942 );
943943
......@@ -1027,7 +1027,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10271027 \\}
10281028 ,
10291029 \\pub export fn foo() c_int {
1030 \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1);
1030 \\ return (1 << @as(@import("std").math.Log2Int(c_int), 2)) >> @as(@import("std").math.Log2Int(c_int), 1);
10311031 \\}
10321032 );
10331033
......@@ -1076,14 +1076,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10761076 \\ _ref.* = (_ref.* ^ 1);
10771077 \\ break :x _ref.*;
10781078 \\ });
1079 \\ a >>= @import("std").math.Log2Int(c_int)((x: {
1079 \\ a >>= @as(@import("std").math.Log2Int(c_int), (x: {
10801080 \\ const _ref = &a;
1081 \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_int)(1));
1081 \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_int), 1));
10821082 \\ break :x _ref.*;
10831083 \\ }));
1084 \\ a <<= @import("std").math.Log2Int(c_int)((x: {
1084 \\ a <<= @as(@import("std").math.Log2Int(c_int), (x: {
10851085 \\ const _ref = &a;
1086 \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_int)(1));
1086 \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_int), 1));
10871087 \\ break :x _ref.*;
10881088 \\ }));
10891089 \\}
......@@ -1103,45 +1103,45 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11031103 \\}
11041104 ,
11051105 \\pub export fn foo() void {
1106 \\ var a: c_uint = c_uint(0);
1106 \\ var a: c_uint = @as(c_uint, 0);
11071107 \\ a +%= (x: {
11081108 \\ const _ref = &a;
1109 \\ _ref.* = (_ref.* +% c_uint(1));
1109 \\ _ref.* = (_ref.* +% @as(c_uint, 1));
11101110 \\ break :x _ref.*;
11111111 \\ });
11121112 \\ a -%= (x: {
11131113 \\ const _ref = &a;
1114 \\ _ref.* = (_ref.* -% c_uint(1));
1114 \\ _ref.* = (_ref.* -% @as(c_uint, 1));
11151115 \\ break :x _ref.*;
11161116 \\ });
11171117 \\ a *%= (x: {
11181118 \\ const _ref = &a;
1119 \\ _ref.* = (_ref.* *% c_uint(1));
1119 \\ _ref.* = (_ref.* *% @as(c_uint, 1));
11201120 \\ break :x _ref.*;
11211121 \\ });
11221122 \\ a &= (x: {
11231123 \\ const _ref = &a;
1124 \\ _ref.* = (_ref.* & c_uint(1));
1124 \\ _ref.* = (_ref.* & @as(c_uint, 1));
11251125 \\ break :x _ref.*;
11261126 \\ });
11271127 \\ a |= (x: {
11281128 \\ const _ref = &a;
1129 \\ _ref.* = (_ref.* | c_uint(1));
1129 \\ _ref.* = (_ref.* | @as(c_uint, 1));
11301130 \\ break :x _ref.*;
11311131 \\ });
11321132 \\ a ^= (x: {
11331133 \\ const _ref = &a;
1134 \\ _ref.* = (_ref.* ^ c_uint(1));
1134 \\ _ref.* = (_ref.* ^ @as(c_uint, 1));
11351135 \\ break :x _ref.*;
11361136 \\ });
1137 \\ a >>= @import("std").math.Log2Int(c_uint)((x: {
1137 \\ a >>= @as(@import("std").math.Log2Int(c_uint), (x: {
11381138 \\ const _ref = &a;
1139 \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_uint)(1));
1139 \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_uint), 1));
11401140 \\ break :x _ref.*;
11411141 \\ }));
1142 \\ a <<= @import("std").math.Log2Int(c_uint)((x: {
1142 \\ a <<= @as(@import("std").math.Log2Int(c_uint), (x: {
11431143 \\ const _ref = &a;
1144 \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_uint)(1));
1144 \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_uint), 1));
11451145 \\ break :x _ref.*;
11461146 \\ }));
11471147 \\}
......@@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11741174 ,
11751175 \\pub export fn foo() void {
11761176 \\ var i: c_int = 0;
1177 \\ var u: c_uint = c_uint(0);
1177 \\ var u: c_uint = @as(c_uint, 0);
11781178 \\ i += 1;
11791179 \\ i -= 1;
11801180 \\ u +%= 1;
......@@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12221222 ,
12231223 \\pub export fn foo() void {
12241224 \\ var i: c_int = 0;
1225 \\ var u: c_uint = c_uint(0);
1225 \\ var u: c_uint = @as(c_uint, 0);
12261226 \\ i += 1;
12271227 \\ i -= 1;
12281228 \\ u +%= 1;
......@@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15391539 cases.add("macro pointer cast",
15401540 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
15411541 ,
1542 \\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);
1542 \\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);
15431543 );
15441544
15451545 cases.add("if on non-bool",
......@@ -1564,7 +1564,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15641564 \\ if (a != 0) return 0;
15651565 \\ if (b != 0) return 1;
15661566 \\ if (c != null) return 2;
1567 \\ if (d != @bitCast(enum_SomeEnum, @TagType(enum_SomeEnum)(0))) return 3;
1567 \\ if (d != @bitCast(enum_SomeEnum, @as(@TagType(enum_SomeEnum), 0))) return 3;
15681568 \\ return 4;
15691569 \\}
15701570 );
......@@ -1646,49 +1646,49 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16461646 cases.addC(
16471647 "u integer suffix after 0 (zero) in macro definition",
16481648 "#define ZERO 0U",
1649 "pub const ZERO = c_uint(0);",
1649 "pub const ZERO = @as(c_uint, 0);",
16501650 );
16511651
16521652 cases.addC(
16531653 "l integer suffix after 0 (zero) in macro definition",
16541654 "#define ZERO 0L",
1655 "pub const ZERO = c_long(0);",
1655 "pub const ZERO = @as(c_long, 0);",
16561656 );
16571657
16581658 cases.addC(
16591659 "ul integer suffix after 0 (zero) in macro definition",
16601660 "#define ZERO 0UL",
1661 "pub const ZERO = c_ulong(0);",
1661 "pub const ZERO = @as(c_ulong, 0);",
16621662 );
16631663
16641664 cases.addC(
16651665 "lu integer suffix after 0 (zero) in macro definition",
16661666 "#define ZERO 0LU",
1667 "pub const ZERO = c_ulong(0);",
1667 "pub const ZERO = @as(c_ulong, 0);",
16681668 );
16691669
16701670 cases.addC(
16711671 "ll integer suffix after 0 (zero) in macro definition",
16721672 "#define ZERO 0LL",
1673 "pub const ZERO = c_longlong(0);",
1673 "pub const ZERO = @as(c_longlong, 0);",
16741674 );
16751675
16761676 cases.addC(
16771677 "ull integer suffix after 0 (zero) in macro definition",
16781678 "#define ZERO 0ULL",
1679 "pub const ZERO = c_ulonglong(0);",
1679 "pub const ZERO = @as(c_ulonglong, 0);",
16801680 );
16811681
16821682 cases.addC(
16831683 "llu integer suffix after 0 (zero) in macro definition",
16841684 "#define ZERO 0LLU",
1685 "pub const ZERO = c_ulonglong(0);",
1685 "pub const ZERO = @as(c_ulonglong, 0);",
16861686 );
16871687
16881688 cases.addC(
16891689 "bitwise not on u-suffixed 0 (zero) in macro definition",
16901690 "#define NOT_ZERO (~0U)",
1691 "pub const NOT_ZERO = ~c_uint(0);",
1691 "pub const NOT_ZERO = ~@as(c_uint, 0);",
16921692 );
16931693
16941694 cases.addC("implicit casts",
......@@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17331733 \\ fn_int(1094861636);
17341734 \\ fn_f32(@intToFloat(f32, 3));
17351735 \\ fn_f64(@intToFloat(f64, 3));
1736 \\ fn_char(u8('3'));
1737 \\ fn_char(u8('\x01'));
1738 \\ fn_char(u8(0));
1736 \\ fn_char(@as(u8, '3'));
1737 \\ fn_char(@as(u8, '\x01'));
1738 \\ fn_char(@as(u8, 0));
17391739 \\ fn_f32(3.000000);
17401740 \\ fn_f64(3.000000);
17411741 \\ fn_bool(true);
......@@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17981798 \\
17991799 ,
18001800 \\pub export fn escapes() [*c]const u8 {
1801 \\ var a: u8 = u8('\'');
1802 \\ var b: u8 = u8('\\');
1803 \\ var c: u8 = u8('\x07');
1804 \\ var d: u8 = u8('\x08');
1805 \\ var e: u8 = u8('\x0c');
1806 \\ var f: u8 = u8('\n');
1807 \\ var g: u8 = u8('\r');
1808 \\ var h: u8 = u8('\t');
1809 \\ var i: u8 = u8('\x0b');
1810 \\ var j: u8 = u8('\x00');
1811 \\ var k: u8 = u8('\"');
1801 \\ var a: u8 = @as(u8, '\'');
1802 \\ var b: u8 = @as(u8, '\\');
1803 \\ var c: u8 = @as(u8, '\x07');
1804 \\ var d: u8 = @as(u8, '\x08');
1805 \\ var e: u8 = @as(u8, '\x0c');
1806 \\ var f: u8 = @as(u8, '\n');
1807 \\ var g: u8 = @as(u8, '\r');
1808 \\ var h: u8 = @as(u8, '\t');
1809 \\ var i: u8 = @as(u8, '\x0b');
1810 \\ var j: u8 = @as(u8, '\x00');
1811 \\ var k: u8 = @as(u8, '\"');
18121812 \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
18131813 \\}
18141814 \\