authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-23 19:13:48+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-23 19:13:48+02:00
log03cc81665bb28eb35c8c6d4be17b5a56fa66261f
treee686671775e606c3cf1129b535f2c2487e4e6e3c
parent86d9563d1539cd7581dc120023bb830fae77ba0f
parentad0871ea4bf2dfbed07282ffe14738b5347d5d32
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'master' into modernize-stage2


309 files changed, 8518 insertions(+), 3248 deletions(-)

README.md+2-2
......@@ -1,7 +1,7 @@
11![ZIG](https://ziglang.org/zig-logo.svg)
22
3A general-purpose programming language designed for **robustness**,
4**optimality**, and **maintainability**.
3A general-purpose programming language for maintaining **robust**, **optimal**,
4and **reusable** code.
55
66## Resources
77
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(
ci/azure/pipelines.yml+2-2
......@@ -14,7 +14,7 @@ jobs:
1414 displayName: 'Build and test'
1515- job: BuildLinux
1616 pool:
17 vmImage: 'ubuntu-16.04'
17 vmImage: 'ubuntu-18.04'
1818
1919 timeoutInMinutes: 360
2020
......@@ -53,7 +53,7 @@ jobs:
5353 strategy:
5454 maxParallel: 1
5555 pool:
56 vmImage: 'ubuntu-16.04'
56 vmImage: 'ubuntu-18.04'
5757 variables:
5858 version: $[ dependencies.BuildLinux.outputs['main.version'] ]
5959 steps:
ci/drone/drone.yml+2
......@@ -9,6 +9,8 @@ steps:
99- name: build-and-test
1010 image: ziglang/static-base:llvm9-1
1111 environment:
12 SRHT_OAUTH_TOKEN:
13 from_secret: SRHT_OAUTH_TOKEN
1214 AWS_ACCESS_KEY_ID:
1315 from_secret: AWS_ACCESS_KEY_ID
1416 AWS_SECRET_ACCESS_KEY:
doc/docgen.zig+3-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
......@@ -856,6 +856,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
856856
857857 .LineComment,
858858 .DocComment,
859 .ContainerDocComment,
859860 .ShebangLine,
860861 => {
861862 try out.write("<span class=\"tok-comment\">");
doc/langref.html.in+222-85
......@@ -164,15 +164,17 @@
164164 <div id="contents">
165165 {#header_open|Introduction#}
166166 <p>
167 Zig is a general-purpose programming language designed for <strong>robustness</strong>,
168 <strong>optimality</strong>, and <strong>maintainability</strong>.
167 Zig is a general-purpose programming language for maintaining <strong>robust</strong>,
168 <strong>optimal</strong>, and <strong>reusable</strong> code.
169169 </p>
170170 <ul>
171171 <li><strong>Robust</strong> - behavior is correct even for edge cases such as out of memory.</li>
172172 <li><strong>Optimal</strong> - write programs the best way they can behave and perform.</li>
173 <li><strong>Maintainable</strong> - precisely communicate intent to the compiler and other programmers.
174 The language imposes a low overhead to reading code and is resilient to changing requirements
175 and environments.</li>
173 <li><strong>Reusable</strong> - the same code works in many environments which have different
174 constraints.</li>
175 <li><strong>Maintainable</strong> - precisely communicate intent to the compiler and
176 other programmers. The language imposes a low overhead to reading code and is
177 resilient to changing requirements and environments.</li>
176178 </ul>
177179 <p>
178180 Often the most efficient way to learn something new is to see examples, so
......@@ -202,11 +204,8 @@
202204const std = @import("std");
203205
204206pub fn main() !void {
205 // If this program is run without stdout attached, exit with an error.
206 const stdout_file = try std.io.getStdOut();
207 // If this program encounters pipe failure when printing to stdout, exit
208 // with an error.
209 try stdout_file.write("Hello, world!\n");
207 const stdout = &std.io.getStdOut().outStream().stream;
208 try stdout.print("Hello, {}!\n", "world");
210209}
211210 {#code_end#}
212211 <p>
......@@ -712,7 +711,7 @@ test "init with undefined" {
712711}
713712 {#code_end#}
714713 <p>
715 {#syntax#}undefined{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to any type.
714 {#syntax#}undefined{#endsyntax#} can be {#link|coerced|Type Coercion#} to any type.
716715 Once this happens, it is no longer possible to detect that the value is {#syntax#}undefined{#endsyntax#}.
717716 {#syntax#}undefined{#endsyntax#} means the value could be anything, even something that is nonsense
718717 according to the type. Translated into English, {#syntax#}undefined{#endsyntax#} means "Not a meaningful
......@@ -920,7 +919,7 @@ fn divide(a: i32, b: i32) i32 {
920919 {#syntax#}f128{#endsyntax#}.
921920 </p>
922921 <p>
923 Float literals {#link|implicitly cast|Implicit Casts#} to any floating point type,
922 Float literals {#link|coerce|Type Coercion#} to any floating point type,
924923 and to any {#link|integer|Integers#} type when there is no fractional component.
925924 </p>
926925 {#code_begin|syntax#}
......@@ -950,7 +949,7 @@ const nan = std.math.nan(f128);
950949 {#code_begin|obj|foo#}
951950 {#code_release_fast#}
952951const builtin = @import("builtin");
953const big = f64(1 << 40);
952const big = @as(f64, 1 << 40);
954953
955954export fn foo_strict(x: f64) f64 {
956955 return x + big - big;
......@@ -1652,7 +1651,7 @@ test "iterate over an array" {
16521651 for (message) |byte| {
16531652 sum += byte;
16541653 }
1655 assert(sum == usize('h') + usize('e') + usize('l') * 2 + usize('o'));
1654 assert(sum == 'h' + 'e' + 'l' * 2 + 'o');
16561655}
16571656
16581657// modifiable array
......@@ -1734,6 +1733,43 @@ test "array initialization with function calls" {
17341733 {#code_end#}
17351734 {#see_also|for|Slices#}
17361735
1736 {#header_open|Anonymous List Literals#}
1737 <p>Similar to {#link|Enum Literals#} and {#link|Anonymous Struct Literals#}
1738 the type can be omitted from array literals:</p>
1739 {#code_begin|test|anon_list#}
1740const std = @import("std");
1741const assert = std.debug.assert;
1742
1743test "anonymous list literal syntax" {
1744 var array: [4]u8 = .{11, 22, 33, 44};
1745 assert(array[0] == 11);
1746 assert(array[1] == 22);
1747 assert(array[2] == 33);
1748 assert(array[3] == 44);
1749}
1750 {#code_end#}
1751 <p>
1752 If there is no type in the result location then an anonymous list literal actually
1753 turns into a {#link|struct#} with numbered field names:
1754 </p>
1755 {#code_begin|test|infer_list_literal#}
1756const std = @import("std");
1757const assert = std.debug.assert;
1758
1759test "fully anonymous list literal" {
1760 dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"});
1761}
1762
1763fn dump(args: var) void {
1764 assert(args.@"0" == 1234);
1765 assert(args.@"1" == 12.34);
1766 assert(args.@"2");
1767 assert(args.@"3"[0] == 'h');
1768 assert(args.@"3"[1] == 'i');
1769}
1770 {#code_end#}
1771 {#header_close#}
1772
17371773 {#header_open|Multidimensional Arrays#}
17381774 <p>
17391775 Mutlidimensional arrays can be created by nesting arrays:
......@@ -2003,7 +2039,7 @@ test "variable alignment" {
20032039 }
20042040}
20052041 {#code_end#}
2006 <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to a
2042 <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|coerced|Type Coercion#} to a
20072043 {#syntax#}*const i32{#endsyntax#}, a pointer with a larger alignment can be implicitly
20082044 cast to a pointer with a smaller alignment, but not vice versa.
20092045 </p>
......@@ -2019,7 +2055,7 @@ var foo: u8 align(4) = 100;
20192055test "global variable alignment" {
20202056 assert(@typeOf(&foo).alignment == 4);
20212057 assert(@typeOf(&foo) == *align(4) u8);
2022 const slice = (*[1]u8)(&foo)[0..];
2058 const slice = @as(*[1]u8, &foo)[0..];
20232059 assert(@typeOf(slice) == []align(4) u8);
20242060}
20252061
......@@ -2114,7 +2150,7 @@ const fmt = @import("std").fmt;
21142150test "using slices for strings" {
21152151 // Zig has no concept of strings. String literals are arrays of u8, and
21162152 // in general the string type is []u8 (slice of u8).
2117 // Here we implicitly cast [5]u8 to []const u8
2153 // Here we coerce [5]u8 to []const u8
21182154 const hello: []const u8 = "hello";
21192155 const world: []const u8 = "世界";
21202156
......@@ -2526,7 +2562,8 @@ test "overaligned pointer to packed struct" {
25262562 Don't worry, there will be a good solution for this use case in zig.
25272563 </p>
25282564 {#header_close#}
2529 {#header_open|struct Naming#}
2565
2566 {#header_open|Struct Naming#}
25302567 <p>Since all structs are anonymous, Zig infers the type name based on a few rules.</p>
25312568 <ul>
25322569 <li>If the struct is in the initialization expression of a variable, it gets named after
......@@ -2552,6 +2589,53 @@ fn List(comptime T: type) type {
25522589}
25532590 {#code_end#}
25542591 {#header_close#}
2592
2593 {#header_open|Anonymous Struct Literals#}
2594 <p>
2595 Zig allows omitting the struct type of a literal. When the result is {#link|coerced|Type Coercion#},
2596 the struct literal will directly instantiate the result location, with no copy:
2597 </p>
2598 {#code_begin|test|struct_result#}
2599const std = @import("std");
2600const assert = std.debug.assert;
2601
2602const Point = struct {x: i32, y: i32};
2603
2604test "anonymous struct literal" {
2605 var pt: Point = .{
2606 .x = 13,
2607 .y = 67,
2608 };
2609 assert(pt.x == 13);
2610 assert(pt.y == 67);
2611}
2612 {#code_end#}
2613 <p>
2614 The struct type can be inferred. Here the result location does not include a type, and
2615 so Zig infers the type:
2616 </p>
2617 {#code_begin|test|struct_anon#}
2618const std = @import("std");
2619const assert = std.debug.assert;
2620
2621test "fully anonymous struct" {
2622 dump(.{
2623 .int = @as(u32, 1234),
2624 .float = @as(f64, 12.34),
2625 .b = true,
2626 .s = "hi",
2627 });
2628}
2629
2630fn dump(args: var) void {
2631 assert(args.int == 1234);
2632 assert(args.float == 12.34);
2633 assert(args.b);
2634 assert(args.s[0] == 'h');
2635 assert(args.s[1] == 'i');
2636}
2637 {#code_end#}
2638 {#header_close#}
25552639 {#see_also|comptime|@fieldParentPtr#}
25562640 {#header_close#}
25572641 {#header_open|enum#}
......@@ -2778,7 +2862,7 @@ test "simple union" {
27782862 This turns the union into a <em>tagged</em> union, which makes it eligible
27792863 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to
27802864 obtain the enum type from the union type.
2781 Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}
2865 Tagged unions coerce to their enum {#link|Type Coercion: unions and enums#}
27822866 </p>
27832867 {#code_begin|test#}
27842868const std = @import("std");
......@@ -2795,7 +2879,7 @@ const ComplexType = union(ComplexTypeTag) {
27952879
27962880test "switch on tagged union" {
27972881 const c = ComplexType{ .Ok = 42 };
2798 assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
2882 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
27992883
28002884 switch (c) {
28012885 ComplexTypeTag.Ok => |value| assert(value == 42),
......@@ -2807,7 +2891,7 @@ test "@TagType" {
28072891 assert(@TagType(ComplexType) == ComplexTypeTag);
28082892}
28092893
2810test "implicit cast to enum" {
2894test "coerce to enum" {
28112895 const c1 = ComplexType{ .Ok = 42 };
28122896 const c2 = ComplexType.NotOk;
28132897
......@@ -2833,7 +2917,7 @@ const ComplexType = union(ComplexTypeTag) {
28332917
28342918test "modify tagged union in switch" {
28352919 var c = ComplexType{ .Ok = 42 };
2836 assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
2920 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
28372921
28382922 switch (c) {
28392923 ComplexTypeTag.Ok => |*value| value.* += 1,
......@@ -2906,6 +2990,32 @@ test "@tagName" {
29062990 <p>A {#syntax#}packed union{#endsyntax#} has well-defined in-memory layout and is eligible
29072991 to be in a {#link|packed struct#}.
29082992 {#header_close#}
2993
2994 {#header_open|Anonymous Union Literals#}
2995 <p>{#link|Anonymous Struct Literals#} syntax can be used to initialize unions without specifying
2996 the type:</p>
2997 {#code_begin|test|anon_union#}
2998const std = @import("std");
2999const assert = std.debug.assert;
3000
3001const Number = union {
3002 int: i32,
3003 float: f64,
3004};
3005
3006test "anonymous union literal syntax" {
3007 var i: Number = .{.int = 42};
3008 var f = makeNumber();
3009 assert(i.int == 42);
3010 assert(f.float == 12.34);
3011}
3012
3013fn makeNumber() Number {
3014 return .{.float = 12.34};
3015}
3016 {#code_end#}
3017 {#header_close#}
3018
29093019 {#header_close#}
29103020
29113021 {#header_open|blocks#}
......@@ -3943,7 +4053,7 @@ test "fn reflection" {
39434053 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>.
39444054 </p>
39454055 <p>
3946 You can {#link|implicitly cast|Implicit Casts#} an error from a subset to a superset:
4056 You can {#link|coerce|Type Coercion#} an error from a subset to a superset:
39474057 </p>
39484058 {#code_begin|test#}
39494059const std = @import("std");
......@@ -3958,7 +4068,7 @@ const AllocationError = error {
39584068 OutOfMemory,
39594069};
39604070
3961test "implicit cast subset to superset" {
4071test "coerce subset to superset" {
39624072 const err = foo(AllocationError.OutOfMemory);
39634073 std.debug.assert(err == FileOpenError.OutOfMemory);
39644074}
......@@ -3968,7 +4078,7 @@ fn foo(err: AllocationError) FileOpenError {
39684078}
39694079 {#code_end#}
39704080 <p>
3971 But you cannot implicitly cast an error from a superset to a subset:
4081 But you cannot {#link|coerce|Type Coercion#} an error from a superset to a subset:
39724082 </p>
39734083 {#code_begin|test_err|not a member of destination error set#}
39744084const FileOpenError = error {
......@@ -3981,7 +4091,7 @@ const AllocationError = error {
39814091 OutOfMemory,
39824092};
39834093
3984test "implicit cast superset to subset" {
4094test "coerce superset to subset" {
39854095 foo(FileOpenError.OutOfMemory) catch {};
39864096}
39874097
......@@ -4008,7 +4118,7 @@ const err = (error {FileNotFound}).FileNotFound;
40084118 It is a superset of all other error sets and a subset of none of them.
40094119 </p>
40104120 <p>
4011 You can implicitly cast any error set to the global one, and you can explicitly
4121 You can {#link|coerce|Type Coercion#} any error set to the global one, and you can explicitly
40124122 cast an error of the global error set to a non-global one. This inserts a language-level
40134123 assert to make sure the error value is in fact in the destination error set.
40144124 </p>
......@@ -4079,7 +4189,7 @@ test "parse u64" {
40794189 <p>
40804190 Within the function definition, you can see some return statements that return
40814191 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#}.
4192 Both types {#link|coerce|Type Coercion#} to {#syntax#}anyerror!u64{#endsyntax#}.
40834193 </p>
40844194 <p>
40854195 What it looks like to use this function varies depending on what you're
......@@ -4218,10 +4328,10 @@ const assert = @import("std").debug.assert;
42184328test "error union" {
42194329 var foo: anyerror!i32 = undefined;
42204330
4221 // Implicitly cast from child type of an error union:
4331 // Coerce from child type of an error union:
42224332 foo = 1234;
42234333
4224 // Implicitly cast from an error set:
4334 // Coerce from an error set:
42254335 foo = error.SomeError;
42264336
42274337 // Use compile-time reflection to access the payload type of an error union:
......@@ -4598,10 +4708,10 @@ fn doAThing(optional_foo: ?*Foo) void {
45984708const assert = @import("std").debug.assert;
45994709
46004710test "optional type" {
4601 // Declare an optional and implicitly cast from null:
4711 // Declare an optional and coerce from null:
46024712 var foo: ?i32 = null;
46034713
4604 // Implicitly cast from child type of an optional
4714 // Coerce from child type of an optional
46054715 foo = 1234;
46064716
46074717 // Use compile-time reflection to access the child type of the optional:
......@@ -4644,38 +4754,38 @@ test "optional pointers" {
46444754 {#header_open|Casting#}
46454755 <p>
46464756 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,
4757 Zig has {#link|Type Coercion#} for conversions that are known to be completely safe and unambiguous,
46484758 and {#link|Explicit Casts#} for conversions that one would not want to happen on accident.
46494759 There is also a third kind of type conversion called {#link|Peer Type Resolution#} for
46504760 the case when a result type must be decided given multiple operand types.
46514761 </p>
4652 {#header_open|Implicit Casts#}
4762 {#header_open|Type Coercion#}
46534763 <p>
4654 An implicit cast occurs when one type is expected, but different type is provided:
4764 Type coercion occurs when one type is expected, but different type is provided:
46554765 </p>
46564766 {#code_begin|test#}
4657test "implicit cast - variable declaration" {
4767test "type coercion - variable declaration" {
46584768 var a: u8 = 1;
46594769 var b: u16 = a;
46604770}
46614771
4662test "implicit cast - function call" {
4772test "type coercion - function call" {
46634773 var a: u8 = 1;
46644774 foo(a);
46654775}
46664776
46674777fn foo(b: u16) void {}
46684778
4669test "implicit cast - invoke a type as a function" {
4779test "type coercion - @as builtin" {
46704780 var a: u8 = 1;
4671 var b = u16(a);
4781 var b = @as(u16, a);
46724782}
46734783 {#code_end#}
46744784 <p>
4675 Implicit casts are only allowed when it is completely unambiguous how to get from one type to another,
4785 Type coercions are only allowed when it is completely unambiguous how to get from one type to another,
46764786 and the transformation is guaranteed to be safe. There is one exception, which is {#link|C Pointers#}.
46774787 </p>
4678 {#header_open|Implicit Cast: Stricter Qualification#}
4788 {#header_open|Type Coercion: Stricter Qualification#}
46794789 <p>
46804790 Values which have the same representation at runtime can be cast to increase the strictness
46814791 of the qualifiers, no matter how nested the qualifiers are:
......@@ -4690,7 +4800,7 @@ test "implicit cast - invoke a type as a function" {
46904800 These casts are no-ops at runtime since the value representation does not change.
46914801 </p>
46924802 {#code_begin|test#}
4693test "implicit cast - const qualification" {
4803test "type coercion - const qualification" {
46944804 var a: i32 = 1;
46954805 var b: *i32 = &a;
46964806 foo(b);
......@@ -4699,7 +4809,7 @@ test "implicit cast - const qualification" {
46994809fn foo(a: *const i32) void {}
47004810 {#code_end#}
47014811 <p>
4702 In addition, pointers implicitly cast to const optional pointers:
4812 In addition, pointers coerce to const optional pointers:
47034813 </p>
47044814 {#code_begin|test#}
47054815const std = @import("std");
......@@ -4713,10 +4823,10 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
47134823}
47144824 {#code_end#}
47154825 {#header_close#}
4716 {#header_open|Implicit Cast: Integer and Float Widening#}
4826 {#header_open|Type Coercion: Integer and Float Widening#}
47174827 <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.
4828 {#link|Integers#} coerce to integer types which can represent every value of the old type, and likewise
4829 {#link|Floats#} coerce to float types which can represent every value of the old type.
47204830 </p>
47214831 {#code_begin|test#}
47224832const std = @import("std");
......@@ -4748,7 +4858,7 @@ test "float widening" {
47484858}
47494859 {#code_end#}
47504860 {#header_close#}
4751 {#header_open|Implicit Cast: Arrays and Pointers#}
4861 {#header_open|Type Coercion: Arrays and Pointers#}
47524862 {#code_begin|test#}
47534863const std = @import("std");
47544864const assert = std.debug.assert;
......@@ -4797,7 +4907,7 @@ test "*[N]T to []T" {
47974907 assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 }));
47984908}
47994909
4800// Single-item pointers to arrays can be implicitly casted to
4910// Single-item pointers to arrays can be coerced to
48014911// unknown length pointers.
48024912test "*[N]T to [*]T" {
48034913 var buf: [5]u8 = "hello";
......@@ -4823,15 +4933,15 @@ test "*T to *[1]T" {
48234933 {#code_end#}
48244934 {#see_also|C Pointers#}
48254935 {#header_close#}
4826 {#header_open|Implicit Cast: Optionals#}
4936 {#header_open|Type Coercion: Optionals#}
48274937 <p>
4828 The payload type of {#link|Optionals#}, as well as {#link|null#}, implicitly cast to the optional type.
4938 The payload type of {#link|Optionals#}, as well as {#link|null#}, coerce to the optional type.
48294939 </p>
48304940 {#code_begin|test#}
48314941const std = @import("std");
48324942const assert = std.debug.assert;
48334943
4834test "implicit casting to optionals" {
4944test "coerce to optionals" {
48354945 const x: ?i32 = 1234;
48364946 const y: ?i32 = null;
48374947
......@@ -4844,7 +4954,7 @@ test "implicit casting to optionals" {
48444954const std = @import("std");
48454955const assert = std.debug.assert;
48464956
4847test "implicit casting to optionals wrapped in error union" {
4957test "coerce to optionals wrapped in error union" {
48484958 const x: anyerror!?i32 = 1234;
48494959 const y: anyerror!?i32 = null;
48504960
......@@ -4853,15 +4963,15 @@ test "implicit casting to optionals wrapped in error union" {
48534963}
48544964 {#code_end#}
48554965 {#header_close#}
4856 {#header_open|Implicit Cast: Error Unions#}
4966 {#header_open|Type Coercion: Error Unions#}
48574967 <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:
4968 coerce to the error union type:
48594969 </p>
48604970 {#code_begin|test#}
48614971const std = @import("std");
48624972const assert = std.debug.assert;
48634973
4864test "implicit casting to error unions" {
4974test "coercion to error unions" {
48654975 const x: anyerror!i32 = 1234;
48664976 const y: anyerror!i32 = error.Failure;
48674977
......@@ -4870,23 +4980,23 @@ test "implicit casting to error unions" {
48704980}
48714981 {#code_end#}
48724982 {#header_close#}
4873 {#header_open|Implicit Cast: Compile-Time Known Numbers#}
4983 {#header_open|Type Coercion: Compile-Time Known Numbers#}
48744984 <p>When a number is {#link|comptime#}-known to be representable in the destination type,
4875 it may be implicitly casted:
4985 it may be coerced:
48764986 </p>
48774987 {#code_begin|test#}
48784988const std = @import("std");
48794989const assert = std.debug.assert;
48804990
4881test "implicit casting large integer type to smaller one when value is comptime known to fit" {
4991test "coercing large integer type to smaller one when value is comptime known to fit" {
48824992 const x: u64 = 255;
48834993 const y: u8 = x;
48844994 assert(y == 255);
48854995}
48864996 {#code_end#}
48874997 {#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
4998 {#header_open|Type Coercion: unions and enums#}
4999 <p>Tagged unions can be coerced to enums, and enums can be coerced to tagged unions
48905000 when they are {#link|comptime#}-known to be a field of the union that has only one possible value, such as
48915001 {#link|void#}:
48925002 </p>
......@@ -4906,7 +5016,7 @@ const U = union(E) {
49065016 Three,
49075017};
49085018
4909test "implicit casting between unions and enums" {
5019test "coercion between unions and enums" {
49105020 var u = U{ .Two = 12.34 };
49115021 var e: E = u;
49125022 assert(e == E.Two);
......@@ -4918,20 +5028,20 @@ test "implicit casting between unions and enums" {
49185028 {#code_end#}
49195029 {#see_also|union|enum#}
49205030 {#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#},
5031 {#header_open|Type Coercion: Zero Bit Types#}
5032 <p>{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#},
49235033 regardless of const.</p>
49245034 <p>TODO document the reasoning for this</p>
49255035 <p>TODO document whether vice versa should work and why</p>
49265036 {#code_begin|test#}
4927test "implicit casting of zero bit types" {
5037test "coercion of zero bit types" {
49285038 var x: void = {};
49295039 var y: *void = x;
49305040 //var z: void = y; // TODO
49315041}
49325042 {#code_end#}
49335043 {#header_close#}
4934 {#header_open|Implicit Cast: undefined#}
5044 {#header_open|Type Coercion: undefined#}
49355045 <p>{#link|undefined#} can be cast to any type.</p>
49365046 {#header_close#}
49375047 {#header_close#}
......@@ -4976,7 +5086,7 @@ test "implicit casting of zero bit types" {
49765086 <li>Some {#link|binary operations|Table of Operators#}</li>
49775087 </ul>
49785088 <p>
4979 This kind of type resolution chooses a type that all peer types can implicitly cast into. Here are
5089 This kind of type resolution chooses a type that all peer types can coerce into. Here are
49805090 some examples:
49815091 </p>
49825092 {#code_begin|test#}
......@@ -5007,8 +5117,8 @@ test "peer resolve array and const slice" {
50075117 comptime testPeerResolveArrayConstSlice(true);
50085118}
50095119fn testPeerResolveArrayConstSlice(b: bool) void {
5010 const value1 = if (b) "aoeu" else ([]const u8)("zz");
5011 const value2 = if (b) ([]const u8)("zz") else "aoeu";
5120 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
5121 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
50125122 assert(mem.eql(u8, value1, "aoeu"));
50135123 assert(mem.eql(u8, value2, "zz"));
50145124}
......@@ -5023,10 +5133,10 @@ test "peer type resolution: ?T and T" {
50235133}
50245134fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
50255135 if (c) {
5026 return if (b) null else usize(0);
5136 return if (b) null else @as(usize, 0);
50275137 }
50285138
5029 return usize(3);
5139 return @as(usize, 3);
50305140}
50315141
50325142test "peer type resolution: [0]u8 and []const u8" {
......@@ -5293,7 +5403,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {
52935403 <p>
52945404 For example, if we were to introduce another function to the above snippet:
52955405 </p>
5296 {#code_begin|test_err|cannot store runtime value in type 'type'#}
5406 {#code_begin|test_err|values of type 'type' must be comptime known#}
52975407fn max(comptime T: type, a: T, b: T) T {
52985408 return if (a > b) a else b;
52995409}
......@@ -5815,7 +5925,7 @@ test "printf too many arguments" {
58155925 </p>
58165926 <p>
58175927 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#}:
5928 only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}:
58195929 </p>
58205930 {#code_begin|exe|printf#}
58215931const warn = @import("std").debug.warn;
......@@ -6185,7 +6295,7 @@ fn func() void {
61856295 </p>
61866296 <p>
61876297 {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that
6188 implicitly casts to {#syntax#}anyframe->T{#endsyntax#}.
6298 coerces to {#syntax#}anyframe->T{#endsyntax#}.
61896299 </p>
61906300 <p>
61916301 There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function.
......@@ -6445,6 +6555,14 @@ comptime {
64456555 </p>
64466556 {#header_close#}
64476557
6558 {#header_open|@as#}
6559 <pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre>
6560 <p>
6561 Performs {#link|Type Coercion#}. This cast is allowed when the conversion is unambiguous and safe,
6562 and is the preferred way to convert between types, whenever possible.
6563 </p>
6564 {#header_close#}
6565
64486566 {#header_open|@asyncCall#}
64496567 <pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: ...) anyframe->T{#endsyntax#}</pre>
64506568 <p>
......@@ -6493,14 +6611,14 @@ async fn func(y: *i32) void {
64936611 This builtin function atomically dereferences a pointer and returns the value.
64946612 </p>
64956613 <p>
6496 {#syntax#}T{#endsyntax#} must be a pointer type, a {#syntax#}bool{#endsyntax#},
6497 or an integer whose bit count meets these requirements:
6614 {#syntax#}T{#endsyntax#} must be a pointer type, a {#syntax#}bool{#endsyntax#}
6615 an integer whose bit count meets these requirements:
64986616 </p>
64996617 <ul>
65006618 <li>At least 8</li>
65016619 <li>At most the same as usize</li>
65026620 <li>Power of 2</li>
6503 </ul>
6621 </ul> or an enum with a valid integer tag type.
65046622 <p>
65056623 TODO right now bool is not accepted. Also I think we could make non powers of 2 work fine, maybe
65066624 we can remove this restriction
......@@ -6541,6 +6659,25 @@ async fn func(y: *i32) void {
65416659 <li>{#syntax#}.Min{#endsyntax#} - stores the operand if it is smaller. Supports integers and floats.</li>
65426660 </ul>
65436661 {#header_close#}
6662 {#header_open|@atomicStore#}
6663 <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: builtin.AtomicOrder) void{#endsyntax#}</pre>
6664 <p>
6665 This builtin function atomically stores a value.
6666 </p>
6667 <p>
6668 {#syntax#}T{#endsyntax#} must be a pointer type, a {#syntax#}bool{#endsyntax#}
6669 an integer whose bit count meets these requirements:
6670 </p>
6671 <ul>
6672 <li>At least 8</li>
6673 <li>At most the same as usize</li>
6674 <li>Power of 2</li>
6675 </ul> or an enum with a valid integer tag type.
6676 <p>
6677 TODO right now bool is not accepted. Also I think we could make non powers of 2 work fine, maybe
6678 we can remove this restriction
6679 </p>
6680 {#header_close#}
65446681 {#header_open|@bitCast#}
65456682 <pre>{#syntax#}@bitCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre>
65466683 <p>
......@@ -7108,7 +7245,7 @@ test "field access by string" {
71087245 <pre>{#syntax#}@frame() *@Frame(func){#endsyntax#}</pre>
71097246 <p>
71107247 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
7248 can be {#link|coerced|Type Coercion#} to {#syntax#}anyframe->T{#endsyntax#} and
71127249 to {#syntax#}anyframe{#endsyntax#}, where {#syntax#}T{#endsyntax#} is the return type
71137250 of the function in scope.
71147251 </p>
......@@ -7827,7 +7964,7 @@ test "vector @splat" {
78277964 const scalar: u32 = 5;
78287965 const result = @splat(4, scalar);
78297966 comptime assert(@typeOf(result) == @Vector(4, u32));
7830 assert(std.mem.eql(u32, ([4]u32)(result), [_]u32{ 5, 5, 5, 5 }));
7967 assert(std.mem.eql(u32, @as([4]u32, result), [_]u32{ 5, 5, 5, 5 }));
78317968}
78327969 {#code_end#}
78337970 <p>
......@@ -8025,7 +8162,7 @@ test "integer truncation" {
80258162 </p>
80268163 <p>
80278164 If {#syntax#}T{#endsyntax#} is {#syntax#}comptime_int{#endsyntax#},
8028 then this is semantically equivalent to an {#link|implicit cast|Implicit Casts#}.
8165 then this is semantically equivalent to {#link|Type Coercion#}.
80298166 </p>
80308167 {#header_close#}
80318168
......@@ -8529,7 +8666,7 @@ pub fn main() void {
85298666 {#header_close#}
85308667 {#header_open|Cast Truncates Data#}
85318668 <p>At compile-time:</p>
8532 {#code_begin|test_err|integer value 300 cannot be implicitly casted to type 'u8'#}
8669 {#code_begin|test_err|integer value 300 cannot be coerced to type 'u8'#}
85338670comptime {
85348671 const spartan_count: u16 = 300;
85358672 const byte = @intCast(u8, spartan_count);
......@@ -8665,7 +8802,7 @@ test "wraparound addition and subtraction" {
86658802 <p>At compile-time:</p>
86668803 {#code_begin|test_err|operation caused overflow#}
86678804comptime {
8668 const x = @shlExact(u8(0b01010101), 2);
8805 const x = @shlExact(@as(u8, 0b01010101), 2);
86698806}
86708807 {#code_end#}
86718808 <p>At runtime:</p>
......@@ -8683,7 +8820,7 @@ pub fn main() void {
86838820 <p>At compile-time:</p>
86848821 {#code_begin|test_err|exact shift shifted out 1 bits#}
86858822comptime {
8686 const x = @shrExact(u8(0b10101010), 2);
8823 const x = @shrExact(@as(u8, 0b10101010), 2);
86878824}
86888825 {#code_end#}
86898826 <p>At runtime:</p>
......@@ -9535,8 +9672,8 @@ const c = @cImport({
95359672 <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p>
95369673 <ul>
95379674 <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
9675 <li>Coerces to other pointer types, as well as {#link|Optional Pointers#}.
9676 When a C pointer is coerced to a non-optional pointer, safety-checked
95409677 {#link|Undefined Behavior#} occurs if the address is 0.
95419678 </li>
95429679 <li>Allows address 0. On non-freestanding targets, dereferencing address 0 is safety-checked
......@@ -9544,7 +9681,7 @@ const c = @cImport({
95449681 null, just like {#syntax#}?usize{#endsyntax#}. Note that creating an optional C pointer
95459682 is unnecessary as one can use normal {#link|Optional Pointers#}.
95469683 </li>
9547 <li>Supports {#link|implicit casting|Implicit Casts#} to and from integers.</li>
9684 <li>Supports {#link|Type Coercion#} to and from integers.</li>
95489685 <li>Supports comparison with integers.</li>
95499686 <li>Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#}
95509687 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+3-3
......@@ -199,7 +199,7 @@ test "std.atomic.Queue" {
199199
200200 for (putters) |t|
201201 t.wait();
202 _ = @atomicRmw(u8, &context.puts_done, builtin.AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
202 @atomicStore(u8, &context.puts_done, 1, AtomicOrder.SeqCst);
203203 for (getters) |t|
204204 t.wait();
205205
......@@ -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+4-4
......@@ -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
......@@ -128,7 +128,7 @@ test "std.atomic.stack" {
128128
129129 for (putters) |t|
130130 t.wait();
131 _ = @atomicRmw(u8, &context.puts_done, builtin.AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
131 @atomicStore(u8, &context.puts_done, 1, AtomicOrder.SeqCst);
132132 for (getters) |t|
133133 t.wait();
134134 }
......@@ -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/build.zig+82-1
......@@ -53,7 +53,7 @@ pub const Builder = struct {
5353 release_mode: ?builtin.Mode,
5454 is_release: bool,
5555 override_lib_dir: ?[]const u8,
56
56 vcpkg_root: VcpkgRoot,
5757 pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
5858
5959 const PkgConfigError = error{
......@@ -159,6 +159,7 @@ pub const Builder = struct {
159159 .is_release = false,
160160 .override_lib_dir = null,
161161 .install_path = undefined,
162 .vcpkg_root = VcpkgRoot{ .Unattempted = {} },
162163 };
163164 try self.top_level_steps.append(&self.install_tls);
164165 try self.top_level_steps.append(&self.uninstall_tls);
......@@ -957,6 +958,7 @@ pub const Builder = struct {
957958 error.ProcessTerminated => error.PkgConfigCrashed,
958959 error.ExitCodeFailure => error.PkgConfigFailed,
959960 error.FileNotFound => error.PkgConfigNotInstalled,
961 error.InvalidName => error.PkgConfigNotInstalled,
960962 error.PkgConfigInvalidOutput => error.PkgConfigInvalidOutput,
961963 else => return err,
962964 };
......@@ -1046,6 +1048,7 @@ pub const LibExeObjStep = struct {
10461048 output_dir: ?[]const u8,
10471049 need_system_paths: bool,
10481050 is_linking_libc: bool = false,
1051 vcpkg_bin_path: ?[]const u8 = null,
10491052
10501053 installed_path: ?[]const u8,
10511054 install_step: ?*InstallArtifactStep,
......@@ -1264,6 +1267,11 @@ pub const LibExeObjStep = struct {
12641267 // option is supplied.
12651268 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name));
12661269 run_step.addArtifactArg(exe);
1270
1271 if (exe.vcpkg_bin_path) |path| {
1272 run_step.addPathDir(path);
1273 }
1274
12671275 return run_step;
12681276 }
12691277
......@@ -1569,6 +1577,43 @@ pub const LibExeObjStep = struct {
15691577 }) catch unreachable;
15701578 }
15711579
1580 /// If Vcpkg was found on the system, it will be added to include and lib
1581 /// paths for the specified target.
1582 pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: VcpkgLinkage) !void {
1583 // Ideally in the Unattempted case we would call the function recursively
1584 // after findVcpkgRoot and have only one switch statement, but the compiler
1585 // cannot resolve the error set.
1586 switch (self.builder.vcpkg_root) {
1587 .Unattempted => {
1588 self.builder.vcpkg_root = if (try findVcpkgRoot(self.builder.allocator)) |root|
1589 VcpkgRoot{ .Found = root }
1590 else
1591 .NotFound;
1592 },
1593 .NotFound => return error.VcpkgNotFound,
1594 .Found => {},
1595 }
1596
1597 switch (self.builder.vcpkg_root) {
1598 .Unattempted => unreachable,
1599 .NotFound => return error.VcpkgNotFound,
1600 .Found => |root| {
1601 const allocator = self.builder.allocator;
1602 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
1603 defer self.builder.allocator.free(triplet);
1604
1605 const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" });
1606 errdefer allocator.free(include_path);
1607 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });
1608
1609 const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" });
1610 try self.lib_paths.append(lib_path);
1611
1612 self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" });
1613 },
1614 }
1615 }
1616
15721617 pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void {
15731618 assert(self.kind == Kind.Test);
15741619 self.exec_cmd_args = args;
......@@ -2341,6 +2386,42 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
23412386 };
23422387}
23432388
2389/// Returned slice must be freed by the caller.
2390fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
2391 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
2392 defer allocator.free(appdata_path);
2393
2394 const path_file = try fs.path.join(allocator, [_][]const u8{ appdata_path, "vcpkg.path.txt" });
2395 defer allocator.free(path_file);
2396
2397 const file = fs.File.openRead(path_file) catch return null;
2398 defer file.close();
2399
2400 const size = @intCast(usize, try file.getEndPos());
2401 const vcpkg_path = try allocator.alloc(u8, size);
2402 const size_read = try file.read(vcpkg_path);
2403 std.debug.assert(size == size_read);
2404
2405 return vcpkg_path;
2406}
2407
2408const VcpkgRoot = union(VcpkgRootStatus) {
2409 Unattempted: void,
2410 NotFound: void,
2411 Found: []const u8,
2412};
2413
2414const VcpkgRootStatus = enum {
2415 Unattempted,
2416 NotFound,
2417 Found,
2418};
2419
2420pub const VcpkgLinkage = enum {
2421 Static,
2422 Dynamic,
2423};
2424
23442425pub const InstallDir = enum {
23452426 Prefix,
23462427 Lib,
lib/std/builtin.zig+2-31
......@@ -90,40 +90,11 @@ pub const Mode = enum {
9090 ReleaseSmall,
9191};
9292
93/// This data structure is used by the Zig language code generation and
94/// therefore must be kept in sync with the compiler implementation.
95pub const TypeId = enum {
96 Type,
97 Void,
98 Bool,
99 NoReturn,
100 Int,
101 Float,
102 Pointer,
103 Array,
104 Struct,
105 ComptimeFloat,
106 ComptimeInt,
107 Undefined,
108 Null,
109 Optional,
110 ErrorUnion,
111 ErrorSet,
112 Enum,
113 Union,
114 Fn,
115 BoundFn,
116 ArgTuple,
117 Opaque,
118 Frame,
119 AnyFrame,
120 Vector,
121 EnumLiteral,
122};
93pub const TypeId = @TagType(TypeInfo);
12394
12495/// This data structure is used by the Zig language code generation and
12596/// therefore must be kept in sync with the compiler implementation.
126pub const TypeInfo = union(TypeId) {
97pub const TypeInfo = union(enum) {
12798 Type: void,
12899 Void: void,
129100 Bool: void,
lib/std/c.zig+23-1
......@@ -8,9 +8,16 @@ pub usingnamespace switch (builtin.os) {
88 .linux => @import("c/linux.zig"),
99 .windows => @import("c/windows.zig"),
1010 .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),
11 .freebsd => @import("c/freebsd.zig"),
11 .freebsd, .kfreebsd => @import("c/freebsd.zig"),
1212 .netbsd => @import("c/netbsd.zig"),
1313 .dragonfly => @import("c/dragonfly.zig"),
14 .openbsd => @import("c/openbsd.zig"),
15 .haiku => @import("c/haiku.zig"),
16 .hermit => @import("c/hermit.zig"),
17 .solaris => @import("c/solaris.zig"),
18 .fuchsia => @import("c/fuchsia.zig"),
19 .minix => @import("c/minix.zig"),
20 .emscripten => @import("c/emscripten.zig"),
1421 else => struct {},
1522};
1623
......@@ -203,3 +210,18 @@ pub extern "c" fn dn_expand(
203210 exp_dn: [*]u8,
204211 length: c_int,
205212) c_int;
213
214pub extern "c" fn sched_yield() c_int;
215
216pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
217pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
218pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
219pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int;
220
221pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};
222pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int;
223pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int;
224pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int;
225
226pub const pthread_t = *@OpaqueType();
227pub const FILE = @OpaqueType();
lib/std/c/darwin.zig+17-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;
......@@ -112,3 +112,19 @@ pub const EAI_PROTOCOL = 13;
112112/// argument buffer overflow
113113pub const EAI_OVERFLOW = 14;
114114pub const EAI_MAX = 15;
115
116pub const pthread_mutex_t = extern struct {
117 __sig: c_long = 0x32AAABA7,
118 __opaque: [__PTHREAD_MUTEX_SIZE__]u8 = [_]u8{0} ** __PTHREAD_MUTEX_SIZE__,
119};
120pub const pthread_cond_t = extern struct {
121 __sig: c_long = 0x3CB0B1BB,
122 __opaque: [__PTHREAD_COND_SIZE__]u8 = [_]u8{0} ** __PTHREAD_COND_SIZE__,
123};
124const __PTHREAD_MUTEX_SIZE__ = if (@sizeOf(usize) == 8) 56 else 40;
125const __PTHREAD_COND_SIZE__ = if (@sizeOf(usize) == 8) 40 else 24;
126
127pub const pthread_attr_t = extern struct {
128 __sig: c_long,
129 __opaque: [56]u8,
130};
lib/std/c/dragonfly.zig+12-1
......@@ -1,6 +1,5 @@
11const std = @import("../std.zig");
22usingnamespace std.c;
3
43extern "c" threadlocal var errno: c_int;
54pub fn _errno() *c_int {
65 return &errno;
......@@ -12,3 +11,15 @@ pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize
1211
1312pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
1413pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
14
15pub const pthread_mutex_t = extern struct {
16 inner: ?*c_void = null,
17};
18pub const pthread_cond_t = extern struct {
19 inner: ?*c_void = null,
20};
21
22pub const pthread_attr_t = extern struct { // copied from freebsd
23 __size: [56]u8,
24 __align: c_long,
25};
lib/std/c/emscripten.zig created+8
......@@ -0,0 +1,8 @@
1pub const pthread_mutex_t = extern struct {
2 size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(4) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
3};
4pub const pthread_cond_t = extern struct {
5 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
6};
7const __SIZEOF_PTHREAD_COND_T = 48;
8const __SIZEOF_PTHREAD_MUTEX_T = 28;
lib/std/c/freebsd.zig+12
......@@ -10,3 +10,15 @@ pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize
1010
1111pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
1212pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
13
14pub const pthread_mutex_t = extern struct {
15 inner: ?*c_void = null,
16};
17pub const pthread_cond_t = extern struct {
18 inner: ?*c_void = null,
19};
20
21pub const pthread_attr_t = extern struct {
22 __size: [56]u8,
23 __align: c_long,
24};
lib/std/c/fuchsia.zig created+8
......@@ -0,0 +1,8 @@
1pub const pthread_mutex_t = extern struct {
2 size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
3};
4pub const pthread_cond_t = extern struct {
5 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
6};
7const __SIZEOF_PTHREAD_COND_T = 48;
8const __SIZEOF_PTHREAD_MUTEX_T = 40;
lib/std/c/haiku.zig created+14
......@@ -0,0 +1,14 @@
1pub const pthread_mutex_t = extern struct {
2 flags: u32 = 0,
3 lock: i32 = 0,
4 unused: i32 = -42,
5 owner: i32 = -1,
6 owner_count: i32 = 0,
7};
8pub const pthread_cond_t = extern struct {
9 flags: u32 = 0,
10 unused: i32 = -42,
11 mutex: ?*c_void = null,
12 waiter_count: i32 = 0,
13 lock: i32 = 0,
14};
lib/std/c/hermit.zig created+6
......@@ -0,0 +1,6 @@
1pub const pthread_mutex_t = extern struct {
2 inner: usize = ~usize(0),
3};
4pub const pthread_cond_t = extern struct {
5 inner: usize = ~usize(0),
6};
lib/std/c/linux.zig+23
......@@ -75,3 +75,26 @@ pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize
7575pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
7676
7777pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
78
79pub const pthread_attr_t = extern struct {
80 __size: [56]u8,
81 __align: c_long,
82};
83
84pub const pthread_mutex_t = extern struct {
85 size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
86};
87pub const pthread_cond_t = extern struct {
88 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
89};
90const __SIZEOF_PTHREAD_COND_T = 48;
91const __SIZEOF_PTHREAD_MUTEX_T = if (builtin.os == .fuchsia) 40 else switch (builtin.abi) {
92 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
93 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (builtin.arch) {
94 .aarch64 => 48,
95 .x86_64 => if (builtin.abi == .gnux32) 40 else 32,
96 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
97 else => if (@sizeOf(usize) == 8) 40 else 24,
98 },
99 else => unreachable,
100};
lib/std/c/minix.zig created+18
......@@ -0,0 +1,18 @@
1const builtin = @import("builtin");
2pub const pthread_mutex_t = extern struct {
3 size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T,
4};
5pub const pthread_cond_t = extern struct {
6 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
7};
8const __SIZEOF_PTHREAD_COND_T = 48;
9const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) {
10 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
11 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (builtin.arch) {
12 .aarch64 => 48,
13 .x86_64 => if (builtin.abi == .gnux32) 40 else 32,
14 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
15 else => if (@sizeOf(usize) == 8) 40 else 24,
16 },
17 else => unreachable,
18};
lib/std/c/netbsd.zig+29
......@@ -6,3 +6,32 @@ pub const _errno = __errno;
66
77pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
88pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
9
10pub const pthread_mutex_t = extern struct {
11 ptm_magic: c_uint = 0x33330003,
12 ptm_errorcheck: padded_spin_t = 0,
13 ptm_unused: padded_spin_t = 0,
14 ptm_owner: usize = 0,
15 ptm_waiters: ?*u8 = null,
16 ptm_recursed: c_uint = 0,
17 ptm_spare2: ?*c_void = null,
18};
19pub const pthread_cond_t = extern struct {
20 ptc_magic: c_uint = 0x55550005,
21 ptc_lock: pthread_spin_t = 0,
22 ptc_waiters_first: ?*u8 = null,
23 ptc_waiters_last: ?*u8 = null,
24 ptc_mutex: ?*pthread_mutex_t = null,
25 ptc_private: ?*c_void = null,
26};
27const pthread_spin_t = if (builtin.arch == .arm or .arch == .powerpc) c_int else u8;
28const padded_spin_t = switch (builtin.arch) {
29 .sparc, .sparcel, .sparcv9, .i386, .x86_64, .le64 => u32,
30 else => spin_t,
31};
32
33pub const pthread_attr_t = extern struct {
34 pta_magic: u32,
35 pta_flags: c_int,
36 pta_private: *c_void,
37};
lib/std/c/openbsd.zig created+6
......@@ -0,0 +1,6 @@
1pub const pthread_mutex_t = extern struct {
2 inner: ?*c_void = null,
3};
4pub const pthread_cond_t = extern struct {
5 inner: ?*c_void = null,
6};
lib/std/c/solaris.zig created+15
......@@ -0,0 +1,15 @@
1pub const pthread_mutex_t = extern struct {
2 __pthread_mutex_flag1: u16 = 0,
3 __pthread_mutex_flag2: u8 = 0,
4 __pthread_mutex_ceiling: u8 = 0,
5 __pthread_mutex_type: u16 = 0,
6 __pthread_mutex_magic: u16 = 0x4d58,
7 __pthread_mutex_lock: u64 = 0,
8 __pthread_mutex_data: u64 = 0,
9};
10pub const pthread_cond_t = extern struct {
11 __pthread_cond_flag: u32 = 0,
12 __pthread_cond_type: u16 = 0,
13 __pthread_cond_magic: u16 = 0x4356,
14 __pthread_cond_data: u64 = 0,
15};
lib/std/child_process.zig+78-19
......@@ -50,8 +50,20 @@ pub const ChildProcess = struct {
5050 err_pipe: if (builtin.os == .windows) void else [2]os.fd_t,
5151 llnode: if (builtin.os == .windows) void else TailQueue(*ChildProcess).Node,
5252
53 pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||
54 os.ChangeCurDirError || windows.CreateProcessError;
53 pub const SpawnError = error{
54 OutOfMemory,
55
56 /// POSIX-only. `StdIo.Ignore` was selected and opening `/dev/null` returned ENODEV.
57 NoDevice,
58
59 /// Windows-only. One of:
60 /// * `cwd` was provided and it could not be re-encoded into UTF16LE, or
61 /// * The `PATH` or `PATHEXT` environment variable contained invalid UTF-8.
62 InvalidUtf8,
63
64 /// Windows-only. `cwd` was provided, but the path did not exist when spawning the child process.
65 CurrentWorkingDirectoryUnlinked,
66 } || os.ExecveError || os.SetIdError || os.ChangeCurDirError || windows.CreateProcessError || windows.WaitForSingleObjectError;
5567
5668 pub const Term = union(enum) {
5769 Exited: u32,
......@@ -102,7 +114,7 @@ pub const ChildProcess = struct {
102114 }
103115
104116 /// On success must call `kill` or `wait`.
105 pub fn spawn(self: *ChildProcess) !void {
117 pub fn spawn(self: *ChildProcess) SpawnError!void {
106118 if (builtin.os == .windows) {
107119 return self.spawnWindows();
108120 } else {
......@@ -110,7 +122,7 @@ pub const ChildProcess = struct {
110122 }
111123 }
112124
113 pub fn spawnAndWait(self: *ChildProcess) !Term {
125 pub fn spawnAndWait(self: *ChildProcess) SpawnError!Term {
114126 try self.spawn();
115127 return self.wait();
116128 }
......@@ -162,7 +174,13 @@ pub const ChildProcess = struct {
162174
163175 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
164176 /// If it succeeds, the caller owns result.stdout and result.stderr memory.
165 pub fn exec(allocator: *mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, env_map: ?*const BufMap, max_output_size: usize) !ExecResult {
177 pub fn exec(
178 allocator: *mem.Allocator,
179 argv: []const []const u8,
180 cwd: ?[]const u8,
181 env_map: ?*const BufMap,
182 max_output_size: usize,
183 ) !ExecResult {
166184 const child = try ChildProcess.init(argv, allocator);
167185 defer child.deinit();
168186
......@@ -219,7 +237,7 @@ pub const ChildProcess = struct {
219237 fn waitUnwrappedWindows(self: *ChildProcess) !void {
220238 const result = windows.WaitForSingleObject(self.handle, windows.INFINITE);
221239
222 self.term = (SpawnError!Term)(x: {
240 self.term = @as(SpawnError!Term, x: {
223241 var exit_code: windows.DWORD = undefined;
224242 if (windows.kernel32.GetExitCodeProcess(self.handle, &exit_code) == 0) {
225243 break :x Term{ .Unknown = 0 };
......@@ -292,7 +310,7 @@ pub const ChildProcess = struct {
292310 Term{ .Unknown = status };
293311 }
294312
295 fn spawnPosix(self: *ChildProcess) !void {
313 fn spawnPosix(self: *ChildProcess) SpawnError!void {
296314 const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try os.pipe() else undefined;
297315 errdefer if (self.stdin_behavior == StdIo.Pipe) {
298316 destroyPipe(stdin_pipe);
......@@ -309,7 +327,16 @@ pub const ChildProcess = struct {
309327 };
310328
311329 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
312 const dev_null_fd = if (any_ignore) try os.openC(c"/dev/null", os.O_RDWR, 0) else undefined;
330 const dev_null_fd = if (any_ignore)
331 os.openC(c"/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
332 error.PathAlreadyExists => unreachable,
333 error.NoSpaceLeft => unreachable,
334 error.FileTooBig => unreachable,
335 error.DeviceBusy => unreachable,
336 else => |e| return e,
337 }
338 else
339 undefined;
313340 defer {
314341 if (any_ignore) os.close(dev_null_fd);
315342 }
......@@ -403,7 +430,7 @@ pub const ChildProcess = struct {
403430 }
404431 }
405432
406 fn spawnWindows(self: *ChildProcess) !void {
433 fn spawnWindows(self: *ChildProcess) SpawnError!void {
407434 const saAttr = windows.SECURITY_ATTRIBUTES{
408435 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
409436 .bInheritHandle = windows.TRUE,
......@@ -412,11 +439,28 @@ pub const ChildProcess = struct {
412439
413440 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
414441
415 const nul_handle = if (any_ignore) blk: {
416 break :blk try windows.CreateFile("NUL", windows.GENERIC_READ, windows.FILE_SHARE_READ, null, windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, null);
417 } else blk: {
418 break :blk undefined;
419 };
442 const nul_handle = if (any_ignore)
443 windows.CreateFile(
444 "NUL",
445 windows.GENERIC_READ,
446 windows.FILE_SHARE_READ,
447 null,
448 windows.OPEN_EXISTING,
449 windows.FILE_ATTRIBUTE_NORMAL,
450 null,
451 ) catch |err| switch (err) {
452 error.SharingViolation => unreachable, // not possible for "NUL"
453 error.PathAlreadyExists => unreachable, // not possible for "NUL"
454 error.PipeBusy => unreachable, // not possible for "NUL"
455 error.InvalidUtf8 => unreachable, // not possible for "NUL"
456 error.BadPathName => unreachable, // not possible for "NUL"
457 error.FileNotFound => unreachable, // not possible for "NUL"
458 error.AccessDenied => unreachable, // not possible for "NUL"
459 error.NameTooLong => unreachable, // not possible for "NUL"
460 else => |e| return e,
461 }
462 else
463 undefined;
420464 defer {
421465 if (any_ignore) os.close(nul_handle);
422466 }
......@@ -542,10 +586,25 @@ pub const ChildProcess = struct {
542586 windowsCreateProcess(app_name_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
543587 if (no_path_err != error.FileNotFound) return no_path_err;
544588
545 const PATH = try process.getEnvVarOwned(self.allocator, "PATH");
546 defer self.allocator.free(PATH);
547 const PATHEXT = try process.getEnvVarOwned(self.allocator, "PATHEXT");
548 defer self.allocator.free(PATHEXT);
589 var free_path = true;
590 const PATH = process.getEnvVarOwned(self.allocator, "PATH") catch |err| switch (err) {
591 error.EnvironmentVariableNotFound => blk: {
592 free_path = false;
593 break :blk "";
594 },
595 else => |e| return e,
596 };
597 defer if (free_path) self.allocator.free(PATH);
598
599 var free_path_ext = true;
600 const PATHEXT = process.getEnvVarOwned(self.allocator, "PATHEXT") catch |err| switch (err) {
601 error.EnvironmentVariableNotFound => blk: {
602 free_path_ext = false;
603 break :blk "";
604 },
605 else => |e| return e,
606 };
607 defer if (free_path_ext) self.allocator.free(PATHEXT);
549608
550609 var it = mem.tokenize(PATH, ";");
551610 retry: while (it.next()) |search_path| {
......@@ -717,7 +776,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void {
717776// Child of fork calls this to report an error to the fork parent.
718777// Then the child exits.
719778fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
720 writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};
779 writeIntFd(fd, @as(ErrInt, @errorToInt(err))) catch {};
721780 os.exit(1);
722781}
723782
lib/std/coff.zig+1-1
......@@ -179,7 +179,7 @@ pub const Coff = struct {
179179 if (byte != 0 and i == buffer.len)
180180 return error.NameTooLong;
181181
182 return i;
182 return @as(usize, i);
183183 }
184184
185185 pub fn loadSections(self: *Coff) !void {
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/benchmark.zig+1-3
......@@ -131,9 +131,7 @@ fn printPad(stdout: var, s: []const u8) !void {
131131}
132132
133133pub fn main() !void {
134 var stdout_file = try std.io.getStdOut();
135 var stdout_out_stream = stdout_file.outStream();
136 const stdout = &stdout_out_stream.stream;
134 const stdout = &std.io.getStdOut().outStream().stream;
137135
138136 var buffer: [1024]u8 = undefined;
139137 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
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+31-18
......@@ -45,18 +45,19 @@ var stderr_file_out_stream: File.OutStream = undefined;
4545
4646var stderr_stream: ?*io.OutStream(File.WriteError) = null;
4747var stderr_mutex = std.Mutex.init();
48
4849pub fn warn(comptime fmt: []const u8, args: ...) void {
4950 const held = stderr_mutex.acquire();
5051 defer held.release();
51 const stderr = getStderrStream() catch return;
52 const stderr = getStderrStream();
5253 stderr.print(fmt, args) catch return;
5354}
5455
55pub fn getStderrStream() !*io.OutStream(File.WriteError) {
56pub fn getStderrStream() *io.OutStream(File.WriteError) {
5657 if (stderr_stream) |st| {
5758 return st;
5859 } else {
59 stderr_file = try io.getStdErr();
60 stderr_file = io.getStdErr();
6061 stderr_file_out_stream = stderr_file.outStream();
6162 const st = &stderr_file_out_stream.stream;
6263 stderr_stream = st;
......@@ -64,6 +65,10 @@ pub fn getStderrStream() !*io.OutStream(File.WriteError) {
6465 }
6566}
6667
68pub fn getStderrMutex() *std.Mutex {
69 return &stderr_mutex;
70}
71
6772/// TODO multithreaded awareness
6873var self_debug_info: ?DebugInfo = null;
6974
......@@ -85,7 +90,7 @@ fn wantTtyColor() bool {
8590/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
8691/// TODO multithreaded awareness
8792pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
88 const stderr = getStderrStream() catch return;
93 const stderr = getStderrStream();
8994 if (builtin.strip_debug_info) {
9095 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
9196 return;
......@@ -104,7 +109,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
104109/// unbuffered, and ignores any error returned.
105110/// TODO multithreaded awareness
106111pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
107 const stderr = getStderrStream() catch return;
112 const stderr = getStderrStream();
108113 if (builtin.strip_debug_info) {
109114 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
110115 return;
......@@ -177,7 +182,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
177182/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
178183/// TODO multithreaded awareness
179184pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
180 const stderr = getStderrStream() catch return;
185 const stderr = getStderrStream();
181186 if (builtin.strip_debug_info) {
182187 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
183188 return;
......@@ -232,7 +237,7 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
232237 // which first called panic can finish printing a stack trace.
233238 os.abort();
234239 }
235 const stderr = getStderrStream() catch os.abort();
240 const stderr = getStderrStream();
236241 stderr.print(format ++ "\n", args) catch os.abort();
237242 if (trace) |t| {
238243 dumpStackTrace(t.*);
......@@ -1003,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
10031008 const word = try stream.readIntLittle(u32);
10041009 var bit_i: u5 = 0;
10051010 while (true) : (bit_i += 1) {
1006 if (word & (u32(1) << bit_i) != 0) {
1011 if (word & (@as(u32, 1) << bit_i) != 0) {
10071012 try list.append(word_i * 32 + bit_i);
10081013 }
10091014 if (bit_i == maxInt(u5)) break;
......@@ -1551,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
15511556
15521557// TODO the noasyncs here are workarounds
15531558fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 {
1554 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));
15551560}
15561561
15571562// TODO the noasyncs here are workarounds
15581563fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
15591564 if (@sizeOf(usize) == 4) {
1560 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));
15611567 } else if (@sizeOf(usize) == 8) {
15621568 return noasync in_stream.readIntLittle(u64);
15631569 } else {
......@@ -1705,7 +1711,12 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
17051711 const ofile_path = mem.toSliceConst(u8, di.strings.ptr + ofile.n_strx);
17061712
17071713 gop.kv.value = MachOFile{
1708 .bytes = try std.io.readFileAllocAligned(di.ofiles.allocator, ofile_path, @alignOf(macho.mach_header_64)),
1714 .bytes = try std.fs.Dir.cwd().readFileAllocAligned(
1715 di.ofiles.allocator,
1716 ofile_path,
1717 maxInt(usize),
1718 @alignOf(macho.mach_header_64),
1719 ),
17091720 .sect_debug_info = null,
17101721 .sect_debug_line = null,
17111722 };
......@@ -1841,7 +1852,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
18411852 // special opcodes
18421853 const adjusted_opcode = opcode - opcode_base;
18431854 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
1844 const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);
1855 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
18451856 prog.line += inc_line;
18461857 prog.address += inc_addr;
18471858 if (try prog.checkLineMatch()) |info| return info;
......@@ -1908,7 +1919,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
19081919 if (unit_length == 0) {
19091920 return error.MissingDebugInfo;
19101921 }
1911 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
1922 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
19121923
19131924 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
19141925 // TODO support 3 and 5
......@@ -2007,7 +2018,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr
20072018 // special opcodes
20082019 const adjusted_opcode = opcode - opcode_base;
20092020 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
2010 const inc_line = i32(line_base) + i32(adjusted_opcode % line_range);
2021 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
20112022 prog.line += inc_line;
20122023 prog.address += inc_addr;
20132024 if (try prog.checkLineMatch()) |info| return info;
......@@ -2088,7 +2099,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void {
20882099 var is_64: bool = undefined;
20892100 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
20902101 if (unit_length == 0) return;
2091 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
2102 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
20922103
20932104 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
20942105 if (version < 2 or version > 5) return error.InvalidDebugInfo;
......@@ -2190,7 +2201,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void {
21902201 var is_64: bool = undefined;
21912202 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
21922203 if (unit_length == 0) return;
2193 const next_offset = unit_length + (if (is_64) usize(12) else usize(4));
2204 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
21942205
21952206 const version = try di.dwarf_in_stream.readInt(u16, di.endian);
21962207 if (version < 2 or version > 5) return error.InvalidDebugInfo;
......@@ -2307,7 +2318,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {
23072318 } else {
23082319 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
23092320 ptr.* += 4;
2310 return u64(first_32_bits);
2321 // TODO this cast should not be needed
2322 return @as(u64, first_32_bits);
23112323 }
23122324}
23132325
......@@ -2324,7 +2336,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool)
23242336 return in_stream.readIntLittle(u64);
23252337 } else {
23262338 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
2327 return u64(first_32_bits);
2339 // TODO this cast should not be needed
2340 return @as(u64, first_32_bits);
23282341 }
23292342}
23302343
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/channel.zig+2-2
......@@ -161,7 +161,7 @@ pub fn Channel(comptime T: type) type {
161161
162162 fn dispatch(self: *SelfChannel) void {
163163 // set the "need dispatch" flag
164 _ = @atomicRmw(u8, &self.need_dispatch, .Xchg, 1, .SeqCst);
164 @atomicStore(u8, &self.need_dispatch, 1, .SeqCst);
165165
166166 lock: while (true) {
167167 // set the lock flag
......@@ -169,7 +169,7 @@ pub fn Channel(comptime T: type) type {
169169 if (prev_lock != 0) return;
170170
171171 // clear the need_dispatch flag since we're about to do it
172 _ = @atomicRmw(u8, &self.need_dispatch, .Xchg, 0, .SeqCst);
172 @atomicStore(u8, &self.need_dispatch, 0, .SeqCst);
173173
174174 while (true) {
175175 one_dispatch: {
lib/std/event/fs.zig+8-5
......@@ -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
......@@ -415,7 +415,8 @@ pub fn openPosix(
415415pub fn openRead(loop: *Loop, path: []const u8) File.OpenError!fd_t {
416416 switch (builtin.os) {
417417 .macosx, .linux, .freebsd, .netbsd, .dragonfly => {
418 const flags = os.O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
418 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
419 const flags = O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
419420 return openPosix(loop, path, flags, File.default_mode);
420421 },
421422
......@@ -448,7 +449,8 @@ pub fn openWriteMode(loop: *Loop, path: []const u8, mode: File.Mode) File.OpenEr
448449 .netbsd,
449450 .dragonfly,
450451 => {
451 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;
452 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
453 const flags = O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;
452454 return openPosix(loop, path, flags, File.default_mode);
453455 },
454456 .windows => return windows.CreateFile(
......@@ -472,7 +474,8 @@ pub fn openReadWrite(
472474) File.OpenError!fd_t {
473475 switch (builtin.os) {
474476 .macosx, .linux, .freebsd, .netbsd, .dragonfly => {
475 const flags = os.O_LARGEFILE | os.O_RDWR | os.O_CREAT | os.O_CLOEXEC;
477 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
478 const flags = O_LARGEFILE | os.O_RDWR | os.O_CREAT | os.O_CLOEXEC;
476479 return openPosix(loop, path, flags, mode);
477480 },
478481
lib/std/event/future.zig+13-12
......@@ -12,12 +12,13 @@ pub fn Future(comptime T: type) type {
1212 return struct {
1313 lock: Lock,
1414 data: T,
15 available: Available,
1516
16 /// TODO make this an enum
17 /// 0 - not started
18 /// 1 - started
19 /// 2 - finished
20 available: u8,
17 const Available = enum(u8) {
18 NotStarted,
19 Started,
20 Finished,
21 };
2122
2223 const Self = @This();
2324 const Queue = std.atomic.Queue(anyframe);
......@@ -34,7 +35,7 @@ pub fn Future(comptime T: type) type {
3435 /// available.
3536 /// Thread-safe.
3637 pub async fn get(self: *Self) *T {
37 if (@atomicLoad(u8, &self.available, .SeqCst) == 2) {
38 if (@atomicLoad(Available, &self.available, .SeqCst) == .Finished) {
3839 return &self.data;
3940 }
4041 const held = self.lock.acquire();
......@@ -46,7 +47,7 @@ pub fn Future(comptime T: type) type {
4647 /// Gets the data without waiting for it. If it's available, a pointer is
4748 /// returned. Otherwise, null is returned.
4849 pub fn getOrNull(self: *Self) ?*T {
49 if (@atomicLoad(u8, &self.available, .SeqCst) == 2) {
50 if (@atomicLoad(Available, &self.available, .SeqCst) == .Finished) {
5051 return &self.data;
5152 } else {
5253 return null;
......@@ -59,14 +60,14 @@ pub fn Future(comptime T: type) type {
5960 /// It's not required to call start() before resolve() but it can be useful since
6061 /// this method is thread-safe.
6162 pub async fn start(self: *Self) ?*T {
62 const state = @cmpxchgStrong(u8, &self.available, 0, 1, .SeqCst, .SeqCst) orelse return null;
63 const state = @cmpxchgStrong(Available, &self.available, .NotStarted, .Started, .SeqCst, .SeqCst) orelse return null;
6364 switch (state) {
64 1 => {
65 .Started => {
6566 const held = self.lock.acquire();
6667 held.release();
6768 return &self.data;
6869 },
69 2 => return &self.data,
70 .Finished => return &self.data,
7071 else => unreachable,
7172 }
7273 }
......@@ -74,8 +75,8 @@ pub fn Future(comptime T: type) type {
7475 /// Make the data become available. May be called only once.
7576 /// Before calling this, modify the `data` property.
7677 pub fn resolve(self: *Self) void {
77 const prev = @atomicRmw(u8, &self.available, .Xchg, 2, .SeqCst);
78 assert(prev == 0 or prev == 1); // resolve() called twice
78 const prev = @atomicRmw(Available, &self.available, .Xchg, .Finished, .SeqCst);
79 assert(prev != .Finished); // resolve() called twice
7980 Lock.Held.release(Lock.Held{ .lock = &self.lock });
8081 }
8182 };
lib/std/event/group.zig+34-7
......@@ -8,7 +8,7 @@ const Allocator = std.mem.Allocator;
88pub fn Group(comptime ReturnType: type) type {
99 return struct {
1010 frame_stack: Stack,
11 alloc_stack: Stack,
11 alloc_stack: AllocStack,
1212 lock: Lock,
1313 allocator: *Allocator,
1414
......@@ -19,11 +19,17 @@ pub fn Group(comptime ReturnType: type) type {
1919 else => void,
2020 };
2121 const Stack = std.atomic.Stack(anyframe->ReturnType);
22 const AllocStack = std.atomic.Stack(Node);
23
24 pub const Node = struct {
25 bytes: []const u8 = [0]u8{},
26 handle: anyframe->ReturnType,
27 };
2228
2329 pub fn init(allocator: *Allocator) Self {
2430 return Self{
2531 .frame_stack = Stack.init(),
26 .alloc_stack = Stack.init(),
32 .alloc_stack = AllocStack.init(),
2733 .lock = Lock.init(),
2834 .allocator = allocator,
2935 };
......@@ -31,10 +37,12 @@ pub fn Group(comptime ReturnType: type) type {
3137
3238 /// Add a frame to the group. Thread-safe.
3339 pub fn add(self: *Self, handle: anyframe->ReturnType) (error{OutOfMemory}!void) {
34 const node = try self.allocator.create(Stack.Node);
35 node.* = Stack.Node{
40 const node = try self.allocator.create(AllocStack.Node);
41 node.* = AllocStack.Node{
3642 .next = undefined,
37 .data = handle,
43 .data = Node{
44 .handle = handle,
45 },
3846 };
3947 self.alloc_stack.push(node);
4048 }
......@@ -48,6 +56,24 @@ pub fn Group(comptime ReturnType: type) type {
4856 self.frame_stack.push(node);
4957 }
5058
59 /// This is equivalent to adding a frame to the group but the memory of its frame is
60 /// allocated by the group and freed by `wait`.
61 /// `func` must be async and have return type `ReturnType`.
62 /// Thread-safe.
63 pub fn call(self: *Self, comptime func: var, args: ...) error{OutOfMemory}!void {
64 var frame = try self.allocator.create(@Frame(func));
65 const node = try self.allocator.create(AllocStack.Node);
66 node.* = AllocStack.Node{
67 .next = undefined,
68 .data = Node{
69 .handle = frame,
70 .bytes = @sliceToBytes((*[1]@Frame(func))(frame)[0..]),
71 },
72 };
73 frame.* = async func(args);
74 self.alloc_stack.push(node);
75 }
76
5177 /// Wait for all the calls and promises of the group to complete.
5278 /// Thread-safe.
5379 /// Safe to call any number of times.
......@@ -67,8 +93,7 @@ pub fn Group(comptime ReturnType: type) type {
6793 }
6894 }
6995 while (self.alloc_stack.pop()) |node| {
70 const handle = node.data;
71 self.allocator.destroy(node);
96 const handle = node.data.handle;
7297 if (Error == void) {
7398 await handle;
7499 } else {
......@@ -76,6 +101,8 @@ pub fn Group(comptime ReturnType: type) type {
76101 result = err;
77102 };
78103 }
104 self.allocator.free(node.data.bytes);
105 self.allocator.destroy(node);
79106 }
80107 return result;
81108 }
lib/std/event/lock.zig+5-5
......@@ -31,8 +31,8 @@ pub const Lock = struct {
3131 }
3232
3333 // We need to release the lock.
34 _ = @atomicRmw(u8, &self.lock.queue_empty_bit, .Xchg, 1, .SeqCst);
35 _ = @atomicRmw(u8, &self.lock.shared_bit, .Xchg, 0, .SeqCst);
34 @atomicStore(u8, &self.lock.queue_empty_bit, 1, .SeqCst);
35 @atomicStore(u8, &self.lock.shared_bit, 0, .SeqCst);
3636
3737 // There might be a queue item. If we know the queue is empty, we can be done,
3838 // because the other actor will try to obtain the lock.
......@@ -56,8 +56,8 @@ pub const Lock = struct {
5656 }
5757
5858 // Release the lock again.
59 _ = @atomicRmw(u8, &self.lock.queue_empty_bit, .Xchg, 1, .SeqCst);
60 _ = @atomicRmw(u8, &self.lock.shared_bit, .Xchg, 0, .SeqCst);
59 @atomicStore(u8, &self.lock.queue_empty_bit, 1, .SeqCst);
60 @atomicStore(u8, &self.lock.shared_bit, 0, .SeqCst);
6161
6262 // Find out if we can be done.
6363 if (@atomicLoad(u8, &self.lock.queue_empty_bit, .SeqCst) == 1) {
......@@ -101,7 +101,7 @@ pub const Lock = struct {
101101
102102 // We set this bit so that later we can rely on the fact, that if queue_empty_bit is 1, some actor
103103 // will attempt to grab the lock.
104 _ = @atomicRmw(u8, &self.queue_empty_bit, .Xchg, 0, .SeqCst);
104 @atomicStore(u8, &self.queue_empty_bit, 0, .SeqCst);
105105
106106 const old_bit = @atomicRmw(u8, &self.shared_bit, .Xchg, 1, .SeqCst);
107107 if (old_bit == 0) {
lib/std/event/loop.zig+15-37
......@@ -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);
......@@ -645,12 +645,6 @@ pub const Loop = struct {
645645 }
646646 }
647647
648 /// This is equivalent to function call, except it calls `startCpuBoundOperation` first.
649 pub fn call(comptime func: var, args: ...) @typeOf(func).ReturnType {
650 startCpuBoundOperation();
651 return func(args);
652 }
653
654648 /// Yielding lets the event loop run, starting any unstarted async operations.
655649 /// Note that async operations automatically start when a function yields for any other reason,
656650 /// for example, when async I/O is performed. This function is intended to be used only when
......@@ -695,8 +689,8 @@ pub const Loop = struct {
695689 },
696690 .macosx, .freebsd, .netbsd, .dragonfly => {
697691 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];
692 const final_kevent = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
693 const empty_kevs = &[0]os.Kevent{};
700694 // cannot fail because we already added it and this just enables it
701695 _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
702696 return;
......@@ -753,7 +747,7 @@ pub const Loop = struct {
753747 },
754748 .macosx, .freebsd, .netbsd, .dragonfly => {
755749 var eventlist: [1]os.Kevent = undefined;
756 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
750 const empty_kevs = &[0]os.Kevent{};
757751 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
758752 for (eventlist[0..count]) |ev| {
759753 const resume_node = @intToPtr(*ResumeNode, ev.udata);
......@@ -815,12 +809,12 @@ pub const Loop = struct {
815809 self.os_data.fs_queue.put(request_node);
816810 switch (builtin.os) {
817811 .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];
812 const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wake);
813 const empty_kevs = &[0]os.Kevent{};
820814 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
821815 },
822816 .linux => {
823 _ = @atomicRmw(i32, &self.os_data.fs_queue_item, AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
817 @atomicStore(i32, &self.os_data.fs_queue_item, 1, AtomicOrder.SeqCst);
824818 const rc = os.linux.futex_wake(&self.os_data.fs_queue_item, os.linux.FUTEX_WAKE, 1);
825819 switch (os.linux.getErrno(rc)) {
826820 0 => {},
......@@ -843,7 +837,7 @@ pub const Loop = struct {
843837 fn posixFsRun(self: *Loop) void {
844838 while (true) {
845839 if (builtin.os == .linux) {
846 _ = @atomicRmw(i32, &self.os_data.fs_queue_item, .Xchg, 0, .SeqCst);
840 @atomicStore(i32, &self.os_data.fs_queue_item, 0, .SeqCst);
847841 }
848842 while (self.os_data.fs_queue.get()) |node| {
849843 switch (node.data.msg) {
......@@ -862,7 +856,8 @@ pub const Loop = struct {
862856 },
863857 .Close => |*msg| noasync os.close(msg.fd),
864858 .WriteFile => |*msg| blk: {
865 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT |
859 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
860 const flags = O_LARGEFILE | os.O_WRONLY | os.O_CREAT |
866861 os.O_CLOEXEC | os.O_TRUNC;
867862 const fd = noasync os.openC(msg.path.ptr, flags, msg.mode) catch |err| {
868863 msg.result = err;
......@@ -890,7 +885,7 @@ pub const Loop = struct {
890885 }
891886 },
892887 .macosx, .freebsd, .netbsd, .dragonfly => {
893 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);
888 const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wait);
894889 var out_kevs: [1]os.Kevent = undefined;
895890 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
896891 },
......@@ -942,23 +937,6 @@ test "std.event.Loop - basic" {
942937 loop.run();
943938}
944939
945test "std.event.Loop - call" {
946 // https://github.com/ziglang/zig/issues/1908
947 if (builtin.single_threaded) return error.SkipZigTest;
948
949 var loop: Loop = undefined;
950 try loop.initMultiThreaded();
951 defer loop.deinit();
952
953 var did_it = false;
954 var handle = async Loop.call(testEventLoop);
955 var handle2 = async Loop.call(testEventLoop2, &handle, &did_it);
956
957 loop.run();
958
959 testing.expect(did_it);
960}
961
962940async fn testEventLoop() i32 {
963941 return 1234;
964942}
lib/std/event/rwlock.zig+22-22
......@@ -13,17 +13,17 @@ const Loop = std.event.Loop;
1313/// When a write lock is held, it will not be released until the writer queue is empty.
1414/// TODO: make this API also work in blocking I/O mode
1515pub const RwLock = struct {
16 shared_state: u8, // TODO make this an enum
16 shared_state: State,
1717 writer_queue: Queue,
1818 reader_queue: Queue,
1919 writer_queue_empty_bit: u8, // TODO make this a bool
2020 reader_queue_empty_bit: u8, // TODO make this a bool
2121 reader_lock_count: usize,
2222
23 const State = struct {
24 const Unlocked = 0;
25 const WriteLock = 1;
26 const ReadLock = 2;
23 const State = enum(u8) {
24 Unlocked,
25 WriteLock,
26 ReadLock,
2727 };
2828
2929 const Queue = std.atomic.Queue(anyframe);
......@@ -40,8 +40,8 @@ pub const RwLock = struct {
4040 return;
4141 }
4242
43 _ = @atomicRmw(u8, &self.lock.reader_queue_empty_bit, .Xchg, 1, .SeqCst);
44 if (@cmpxchgStrong(u8, &self.lock.shared_state, State.ReadLock, State.Unlocked, .SeqCst, .SeqCst) != null) {
43 @atomicStore(u8, &self.lock.reader_queue_empty_bit, 1, .SeqCst);
44 if (@cmpxchgStrong(State, &self.lock.shared_state, .ReadLock, .Unlocked, .SeqCst, .SeqCst) != null) {
4545 // Didn't unlock. Someone else's problem.
4646 return;
4747 }
......@@ -64,15 +64,15 @@ pub const RwLock = struct {
6464 // We need to release the write lock. Check if any readers are waiting to grab the lock.
6565 if (@atomicLoad(u8, &self.lock.reader_queue_empty_bit, .SeqCst) == 0) {
6666 // Switch to a read lock.
67 _ = @atomicRmw(u8, &self.lock.shared_state, .Xchg, State.ReadLock, .SeqCst);
67 @atomicStore(State, &self.lock.shared_state, .ReadLock, .SeqCst);
6868 while (self.lock.reader_queue.get()) |node| {
6969 global_event_loop.onNextTick(node);
7070 }
7171 return;
7272 }
7373
74 _ = @atomicRmw(u8, &self.lock.writer_queue_empty_bit, .Xchg, 1, .SeqCst);
75 _ = @atomicRmw(u8, &self.lock.shared_state, .Xchg, State.Unlocked, .SeqCst);
74 @atomicStore(u8, &self.lock.writer_queue_empty_bit, 1, .SeqCst);
75 @atomicStore(State, &self.lock.shared_state, .Unlocked, .SeqCst);
7676
7777 self.lock.commonPostUnlock();
7878 }
......@@ -80,7 +80,7 @@ pub const RwLock = struct {
8080
8181 pub fn init() RwLock {
8282 return RwLock{
83 .shared_state = State.Unlocked,
83 .shared_state = .Unlocked,
8484 .writer_queue = Queue.init(),
8585 .writer_queue_empty_bit = 1,
8686 .reader_queue = Queue.init(),
......@@ -92,7 +92,7 @@ pub const RwLock = struct {
9292 /// Must be called when not locked. Not thread safe.
9393 /// All calls to acquire() and release() must complete before calling deinit().
9494 pub fn deinit(self: *RwLock) void {
95 assert(self.shared_state == State.Unlocked);
95 assert(self.shared_state == .Unlocked);
9696 while (self.writer_queue.get()) |node| resume node.data;
9797 while (self.reader_queue.get()) |node| resume node.data;
9898 }
......@@ -113,10 +113,10 @@ pub const RwLock = struct {
113113
114114 // We set this bit so that later we can rely on the fact, that if reader_queue_empty_bit is 1,
115115 // some actor will attempt to grab the lock.
116 _ = @atomicRmw(u8, &self.reader_queue_empty_bit, .Xchg, 0, .SeqCst);
116 @atomicStore(u8, &self.reader_queue_empty_bit, 0, .SeqCst);
117117
118118 // Here we don't care if we are the one to do the locking or if it was already locked for reading.
119 const have_read_lock = if (@cmpxchgStrong(u8, &self.shared_state, State.Unlocked, State.ReadLock, .SeqCst, .SeqCst)) |old_state| old_state == State.ReadLock else true;
119 const have_read_lock = if (@cmpxchgStrong(State, &self.shared_state, .Unlocked, .ReadLock, .SeqCst, .SeqCst)) |old_state| old_state == .ReadLock else true;
120120 if (have_read_lock) {
121121 // Give out all the read locks.
122122 if (self.reader_queue.get()) |first_node| {
......@@ -144,10 +144,10 @@ pub const RwLock = struct {
144144
145145 // We set this bit so that later we can rely on the fact, that if writer_queue_empty_bit is 1,
146146 // some actor will attempt to grab the lock.
147 _ = @atomicRmw(u8, &self.writer_queue_empty_bit, .Xchg, 0, .SeqCst);
147 @atomicStore(u8, &self.writer_queue_empty_bit, 0, .SeqCst);
148148
149149 // Here we must be the one to acquire the write lock. It cannot already be locked.
150 if (@cmpxchgStrong(u8, &self.shared_state, State.Unlocked, State.WriteLock, .SeqCst, .SeqCst) == null) {
150 if (@cmpxchgStrong(State, &self.shared_state, .Unlocked, .WriteLock, .SeqCst, .SeqCst) == null) {
151151 // We now have a write lock.
152152 if (self.writer_queue.get()) |node| {
153153 // Whether this node is us or someone else, we tail resume it.
......@@ -166,7 +166,7 @@ pub const RwLock = struct {
166166 // But if there's a writer_queue item or a reader_queue item,
167167 // we are the actor which must loop and attempt to grab the lock again.
168168 if (@atomicLoad(u8, &self.writer_queue_empty_bit, .SeqCst) == 0) {
169 if (@cmpxchgStrong(u8, &self.shared_state, State.Unlocked, State.WriteLock, .SeqCst, .SeqCst) != null) {
169 if (@cmpxchgStrong(State, &self.shared_state, .Unlocked, .WriteLock, .SeqCst, .SeqCst) != null) {
170170 // We did not obtain the lock. Great, the queues are someone else's problem.
171171 return;
172172 }
......@@ -176,13 +176,13 @@ pub const RwLock = struct {
176176 return;
177177 }
178178 // Release the lock again.
179 _ = @atomicRmw(u8, &self.writer_queue_empty_bit, .Xchg, 1, .SeqCst);
180 _ = @atomicRmw(u8, &self.shared_state, .Xchg, State.Unlocked, .SeqCst);
179 @atomicStore(u8, &self.writer_queue_empty_bit, 1, .SeqCst);
180 @atomicStore(State, &self.shared_state, .Unlocked, .SeqCst);
181181 continue;
182182 }
183183
184184 if (@atomicLoad(u8, &self.reader_queue_empty_bit, .SeqCst) == 0) {
185 if (@cmpxchgStrong(u8, &self.shared_state, State.Unlocked, State.ReadLock, .SeqCst, .SeqCst) != null) {
185 if (@cmpxchgStrong(State, &self.shared_state, .Unlocked, .ReadLock, .SeqCst, .SeqCst) != null) {
186186 // We did not obtain the lock. Great, the queues are someone else's problem.
187187 return;
188188 }
......@@ -195,8 +195,8 @@ pub const RwLock = struct {
195195 return;
196196 }
197197 // Release the lock again.
198 _ = @atomicRmw(u8, &self.reader_queue_empty_bit, .Xchg, 1, .SeqCst);
199 if (@cmpxchgStrong(u8, &self.shared_state, State.ReadLock, State.Unlocked, .SeqCst, .SeqCst) != null) {
198 @atomicStore(u8, &self.reader_queue_empty_bit, 1, .SeqCst);
199 if (@cmpxchgStrong(State, &self.shared_state, .ReadLock, .Unlocked, .SeqCst, .SeqCst) != null) {
200200 // Didn't unlock. Someone else's problem.
201201 return;
202202 }
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+67-63
......@@ -167,6 +167,10 @@ pub fn format(
167167 '}' => {
168168 const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);
169169
170 if (arg_to_print >= args.len) {
171 @compileError("Too few arguments");
172 }
173
170174 try formatType(
171175 args[arg_to_print],
172176 fmt[0..0],
......@@ -378,10 +382,10 @@ pub fn formatType(
378382 const info = @typeInfo(T).Union;
379383 if (info.tag_type) |UnionTagType| {
380384 try output(context, "{ .");
381 try output(context, @tagName(UnionTagType(value)));
385 try output(context, @tagName(@as(UnionTagType, value)));
382386 try output(context, " = ");
383387 inline for (info.fields) |u_field| {
384 if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) {
388 if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) {
385389 try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1);
386390 }
387391 }
......@@ -499,7 +503,7 @@ pub fn formatIntValue(
499503
500504 const int_value = if (@typeOf(value) == comptime_int) blk: {
501505 const Int = math.IntFittingRange(value, value);
502 break :blk Int(value);
506 break :blk @as(Int, value);
503507 } else
504508 value;
505509
......@@ -508,7 +512,7 @@ pub fn formatIntValue(
508512 uppercase = false;
509513 } else if (comptime std.mem.eql(u8, fmt, "c")) {
510514 if (@typeOf(int_value).bit_count <= 8) {
511 return formatAsciiChar(u8(int_value), options, context, Errors, output);
515 return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
512516 } else {
513517 @compileError("Cannot print integer that is larger than 8 bits as a ascii");
514518 }
......@@ -574,7 +578,7 @@ pub fn formatAsciiChar(
574578 comptime Errors: type,
575579 output: fn (@typeOf(context), []const u8) Errors!void,
576580) Errors!void {
577 return output(context, (*const [1]u8)(&c)[0..]);
581 return output(context, @as(*const [1]u8, &c)[0..]);
578582}
579583
580584pub fn formatBuf(
......@@ -590,7 +594,7 @@ pub fn formatBuf(
590594 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
591595 const pad_byte: u8 = options.fill;
592596 while (leftover_padding > 0) : (leftover_padding -= 1) {
593 try output(context, (*const [1]u8)(&pad_byte)[0..1]);
597 try output(context, @as(*const [1]u8, &pad_byte)[0..1]);
594598 }
595599}
596600
......@@ -664,7 +668,7 @@ pub fn formatFloatScientific(
664668 try output(context, float_decimal.digits[0..1]);
665669 try output(context, ".");
666670 if (float_decimal.digits.len > 1) {
667 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;
668672
669673 try output(context, float_decimal.digits[1..num_digits]);
670674 } else {
......@@ -699,7 +703,7 @@ pub fn formatFloatDecimal(
699703 comptime Errors: type,
700704 output: fn (@typeOf(context), []const u8) Errors!void,
701705) Errors!void {
702 var x = f64(value);
706 var x = @as(f64, value);
703707
704708 // Errol doesn't handle these special cases.
705709 if (math.signbit(x)) {
......@@ -888,7 +892,7 @@ pub fn formatInt(
888892) Errors!void {
889893 const int_value = if (@typeOf(value) == comptime_int) blk: {
890894 const Int = math.IntFittingRange(value, value);
891 break :blk Int(value);
895 break :blk @as(Int, value);
892896 } else
893897 value;
894898
......@@ -917,14 +921,14 @@ fn formatIntSigned(
917921 const uint = @IntType(false, @typeOf(value).bit_count);
918922 if (value < 0) {
919923 const minus_sign: u8 = '-';
920 try output(context, (*const [1]u8)(&minus_sign)[0..]);
924 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
921925 const new_value = @intCast(uint, -(value + 1)) + 1;
922926 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
923927 } else if (options.width == null or options.width.? == 0) {
924928 return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);
925929 } else {
926930 const plus_sign: u8 = '+';
927 try output(context, (*const [1]u8)(&plus_sign)[0..]);
931 try output(context, @as(*const [1]u8, &plus_sign)[0..]);
928932 const new_value = @intCast(uint, value);
929933 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
930934 }
......@@ -962,7 +966,7 @@ fn formatIntUnsigned(
962966 const zero_byte: u8 = options.fill;
963967 var leftover_padding = padding - index;
964968 while (true) {
965 try output(context, (*const [1]u8)(&zero_byte)[0..]);
969 try output(context, @as(*const [1]u8, &zero_byte)[0..]);
966970 leftover_padding -= 1;
967971 if (leftover_padding == 0) break;
968972 }
......@@ -994,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
994998
995999pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
9961000 if (!T.is_signed) return parseUnsigned(T, buf, radix);
997 if (buf.len == 0) return T(0);
1001 if (buf.len == 0) return @as(T, 0);
9981002 if (buf[0] == '-') {
9991003 return math.negate(try parseUnsigned(T, buf[1..], radix));
10001004 } else if (buf[0] == '+') {
......@@ -1084,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
10841088fn digitToChar(digit: u8, uppercase: bool) u8 {
10851089 return switch (digit) {
10861090 0...9 => digit + '0',
1087 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),
10881092 else => unreachable,
10891093 };
10901094}
......@@ -1130,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
11301134test "bufPrintInt" {
11311135 var buffer: [100]u8 = undefined;
11321136 const buf = buffer[0..];
1133 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1134 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678"));
1135 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e"));
1136 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"));
11371141
1138 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"));
11391143
1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, FormatOptions{ .width = 6 }), " 666"));
1141 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1142 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"));
11431147
1144 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, FormatOptions{ .width = 3 }), "+42"));
1145 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"));
11461150}
11471151
11481152fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
......@@ -1204,8 +1208,8 @@ test "int.specifier" {
12041208}
12051209
12061210test "int.padded" {
1207 try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1));
1208 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));
12091213}
12101214
12111215test "buffer" {
......@@ -1283,8 +1287,8 @@ test "filesize" {
12831287 // TODO https://github.com/ziglang/zig/issues/3289
12841288 return error.SkipZigTest;
12851289 }
1286 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024));
1287 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));
12881292}
12891293
12901294test "struct" {
......@@ -1321,10 +1325,10 @@ test "float.scientific" {
13211325 // TODO https://github.com/ziglang/zig/issues/3289
13221326 return error.SkipZigTest;
13231327 }
1324 try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34));
1325 try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34));
1326 try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10));
1327 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));
13281332}
13291333
13301334test "float.scientific.precision" {
......@@ -1332,12 +1336,12 @@ test "float.scientific.precision" {
13321336 // TODO https://github.com/ziglang/zig/issues/3289
13331337 return error.SkipZigTest;
13341338 }
1335 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42));
1336 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563))));
1337 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))));
13381342 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
13391343 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
1340 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))));
13411345}
13421346
13431347test "float.special" {
......@@ -1360,21 +1364,21 @@ test "float.decimal" {
13601364 // TODO https://github.com/ziglang/zig/issues/3289
13611365 return error.SkipZigTest;
13621366 }
1363 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29));
1364 try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234));
1365 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));
13661370 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
13671371 // -11.12339... is rounded back up to -11.1234
1368 try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234));
1369 try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345));
1370 try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235));
1371 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0));
1372 try testFmt("f64: 6", "f64: {d:.0}", f64(5.700));
1373 try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999));
1374 try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0));
1375 try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003));
1376 try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45));
1377 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));
13781382}
13791383
13801384test "float.libc.sanity" {
......@@ -1382,22 +1386,22 @@ test "float.libc.sanity" {
13821386 // TODO https://github.com/ziglang/zig/issues/3289
13831387 return error.SkipZigTest;
13841388 }
1385 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781))));
1386 try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389))));
1387 try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278))));
1388 try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133))));
1389 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))));
13901394
13911395 // libc differences
13921396 //
13931397 // This is 0.015625 exactly according to gdb. We thus round down,
13941398 // however glibc rounds up for some reason. This occurs for all
13951399 // floats of the form x.yyyy25 on a precision point.
1396 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))));
13971401 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
13981402 // also rounds to 630 so I'm inclined to believe libc is not
13991403 // optimal here.
1400 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))));
14011405}
14021406
14031407test "custom" {
......@@ -1673,17 +1677,17 @@ test "formatType max_depth" {
16731677}
16741678
16751679test "positional" {
1676 try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2));
1677 try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2));
1678 try testFmt("0 0", "{0} {0}", usize(0));
1679 try testFmt("0 1", "{} {1}", usize(0), usize(1));
1680 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));
16811685}
16821686
16831687test "positional with specifier" {
1684 try testFmt("10.0", "{0d:.1}", f64(9.999));
1688 try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
16851689}
16861690
16871691test "positional/alignment/width/precision" {
1688 try testFmt("10.0", "{0d: >3.1}", f64(9.999));
1692 try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));
16891693}
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+104-11
......@@ -6,6 +6,7 @@ const base64 = std.base64;
66const crypto = std.crypto;
77const Allocator = std.mem.Allocator;
88const assert = std.debug.assert;
9const math = std.math;
910
1011pub const path = @import("fs/path.zig");
1112pub const File = @import("fs/file.zig").File;
......@@ -584,7 +585,7 @@ pub const Dir = struct {
584585 .FileBothDirectoryInformation,
585586 w.FALSE,
586587 null,
587 if (self.first) w.BOOLEAN(w.TRUE) else w.BOOLEAN(w.FALSE),
588 if (self.first) @as(w.BOOLEAN, w.TRUE) else @as(w.BOOLEAN, w.FALSE),
588589 );
589590 self.first = false;
590591 if (io.Information == 0) return null;
......@@ -698,17 +699,81 @@ pub const Dir = struct {
698699
699700 /// Call `File.close` on the result when done.
700701 pub fn openRead(self: Dir, sub_path: []const u8) File.OpenError!File {
702 if (builtin.os == .windows) {
703 const path_w = try os.windows.sliceToPrefixedFileW(sub_path);
704 return self.openReadW(&path_w);
705 }
701706 const path_c = try os.toPosixPath(sub_path);
702707 return self.openReadC(&path_c);
703708 }
704709
705710 /// Call `File.close` on the result when done.
706711 pub fn openReadC(self: Dir, sub_path: [*]const u8) File.OpenError!File {
707 const flags = os.O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
712 if (builtin.os == .windows) {
713 const path_w = try os.windows.cStrToPrefixedFileW(sub_path);
714 return self.openReadW(&path_w);
715 }
716 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
717 const flags = O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
708718 const fd = try os.openatC(self.fd, sub_path, flags, 0);
709719 return File.openHandle(fd);
710720 }
711721
722 pub fn openReadW(self: Dir, sub_path_w: [*]const u16) File.OpenError!File {
723 const w = os.windows;
724
725 var result = File{ .handle = undefined };
726
727 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
728 error.Overflow => return error.NameTooLong,
729 };
730 var nt_name = w.UNICODE_STRING{
731 .Length = path_len_bytes,
732 .MaximumLength = path_len_bytes,
733 .Buffer = @intToPtr([*]u16, @ptrToInt(sub_path_w)),
734 };
735 var attr = w.OBJECT_ATTRIBUTES{
736 .Length = @sizeOf(w.OBJECT_ATTRIBUTES),
737 .RootDirectory = if (path.isAbsoluteW(sub_path_w)) null else self.fd,
738 .Attributes = 0, // Note we do not use OBJ_CASE_INSENSITIVE here.
739 .ObjectName = &nt_name,
740 .SecurityDescriptor = null,
741 .SecurityQualityOfService = null,
742 };
743 if (sub_path_w[0] == '.' and sub_path_w[1] == 0) {
744 return error.IsDir;
745 }
746 if (sub_path_w[0] == '.' and sub_path_w[1] == '.' and sub_path_w[2] == 0) {
747 return error.IsDir;
748 }
749 var io: w.IO_STATUS_BLOCK = undefined;
750 const rc = w.ntdll.NtCreateFile(
751 &result.handle,
752 w.GENERIC_READ | w.SYNCHRONIZE,
753 &attr,
754 &io,
755 null,
756 w.FILE_ATTRIBUTE_NORMAL,
757 w.FILE_SHARE_READ,
758 w.FILE_OPEN,
759 w.FILE_NON_DIRECTORY_FILE | w.FILE_SYNCHRONOUS_IO_NONALERT,
760 null,
761 0,
762 );
763 switch (rc) {
764 w.STATUS.SUCCESS => return result,
765 w.STATUS.OBJECT_NAME_INVALID => unreachable,
766 w.STATUS.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
767 w.STATUS.OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
768 w.STATUS.INVALID_PARAMETER => unreachable,
769 w.STATUS.SHARING_VIOLATION => return error.SharingViolation,
770 w.STATUS.ACCESS_DENIED => return error.AccessDenied,
771 w.STATUS.PIPE_BUSY => return error.PipeBusy,
772 w.STATUS.OBJECT_PATH_SYNTAX_BAD => unreachable,
773 else => return w.unexpectedStatus(rc),
774 }
775 }
776
712777 /// Call `close` on the result when done.
713778 pub fn openDir(self: Dir, sub_path: []const u8) OpenError!Dir {
714779 if (builtin.os == .windows) {
......@@ -866,6 +931,34 @@ pub const Dir = struct {
866931 return os.readlinkatC(self.fd, sub_path_c, buffer);
867932 }
868933
934 /// On success, caller owns returned buffer.
935 /// If the file is larger than `max_bytes`, returns `error.FileTooBig`.
936 pub fn readFileAlloc(self: Dir, allocator: *mem.Allocator, file_path: []const u8, max_bytes: usize) ![]u8 {
937 return self.readFileAllocAligned(allocator, file_path, max_bytes, @alignOf(u8));
938 }
939
940 /// On success, caller owns returned buffer.
941 /// If the file is larger than `max_bytes`, returns `error.FileTooBig`.
942 pub fn readFileAllocAligned(
943 self: Dir,
944 allocator: *mem.Allocator,
945 file_path: []const u8,
946 max_bytes: usize,
947 comptime A: u29,
948 ) ![]align(A) u8 {
949 var file = try self.openRead(file_path);
950 defer file.close();
951
952 const size = math.cast(usize, try file.getEndPos()) catch math.maxInt(usize);
953 if (size > max_bytes) return error.FileTooBig;
954
955 const buf = try allocator.alignedAlloc(u8, A, size);
956 errdefer allocator.free(buf);
957
958 try file.inStream().stream.readNoEof(buf);
959 return buf;
960 }
961
869962 pub const DeleteTreeError = error{
870963 AccessDenied,
871964 FileTooBig,
......@@ -1100,7 +1193,7 @@ pub const Walker = struct {
11001193 }
11011194
11021195 pub fn deinit(self: *Walker) void {
1103 while (self.stack.popOrNull()) |*item| item.dir_it.close();
1196 while (self.stack.popOrNull()) |*item| item.dir_it.dir.close();
11041197 self.stack.deinit();
11051198 self.name_buffer.deinit();
11061199 }
......@@ -1150,9 +1243,9 @@ pub fn openSelfExe() OpenSelfExeError!File {
11501243 return File.openReadC(c"/proc/self/exe");
11511244 }
11521245 if (builtin.os == .windows) {
1153 var buf: [os.windows.PATH_MAX_WIDE]u16 = undefined;
1154 const wide_slice = try selfExePathW(&buf);
1155 return File.openReadW(wide_slice.ptr);
1246 const wide_slice = selfExePathW();
1247 const prefixed_path_w = try os.windows.wToPrefixedFileW(wide_slice);
1248 return Dir.cwd().openReadW(&prefixed_path_w);
11561249 }
11571250 var buf: [MAX_PATH_BYTES]u8 = undefined;
11581251 const self_exe_path = try selfExePath(&buf);
......@@ -1203,8 +1296,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
12031296 return mem.toSlice(u8, out_buffer);
12041297 },
12051298 .windows => {
1206 var utf16le_buf: [os.windows.PATH_MAX_WIDE]u16 = undefined;
1207 const utf16le_slice = try selfExePathW(&utf16le_buf);
1299 const utf16le_slice = selfExePathW();
12081300 // Trust that Windows gives us valid UTF-16LE.
12091301 const end_index = std.unicode.utf16leToUtf8(out_buffer, utf16le_slice) catch unreachable;
12101302 return out_buffer[0..end_index];
......@@ -1213,9 +1305,10 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
12131305 }
12141306}
12151307
1216/// Same as `selfExePath` except the result is UTF16LE-encoded.
1217pub fn selfExePathW(out_buffer: *[os.windows.PATH_MAX_WIDE]u16) SelfExePathError![]u16 {
1218 return os.windows.GetModuleFileNameW(null, out_buffer, out_buffer.len);
1308/// The result is UTF16LE-encoded.
1309pub fn selfExePathW() []const u16 {
1310 const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName;
1311 return mem.toSliceConst(u16, image_path_name.Buffer);
12191312}
12201313
12211314/// `selfExeDirPath` except allocates the result on the heap.
lib/std/fs/file.zig+24-32
......@@ -25,42 +25,23 @@ pub const File = struct {
2525
2626 pub const OpenError = windows.CreateFileError || os.OpenError;
2727
28 /// Call close to clean up.
28 /// Deprecated; call `std.fs.Dir.openRead` directly.
2929 pub fn openRead(path: []const u8) OpenError!File {
30 if (builtin.os == .windows) {
31 const path_w = try windows.sliceToPrefixedFileW(path);
32 return openReadW(&path_w);
33 }
34 const path_c = try os.toPosixPath(path);
35 return openReadC(&path_c);
30 return std.fs.Dir.cwd().openRead(path);
3631 }
3732
38 /// `openRead` except with a null terminated path
39 pub fn openReadC(path: [*]const u8) OpenError!File {
40 if (builtin.os == .windows) {
41 const path_w = try windows.cStrToPrefixedFileW(path);
42 return openReadW(&path_w);
43 }
44 const flags = os.O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
45 const fd = try os.openC(path, flags, 0);
46 return openHandle(fd);
33 /// Deprecated; call `std.fs.Dir.openReadC` directly.
34 pub fn openReadC(path_c: [*]const u8) OpenError!File {
35 return std.fs.Dir.cwd().openReadC(path_c);
4736 }
4837
49 /// `openRead` except with a null terminated UTF16LE encoded path
38 /// Deprecated; call `std.fs.Dir.openReadW` directly.
5039 pub fn openReadW(path_w: [*]const u16) OpenError!File {
51 const handle = try windows.CreateFileW(
52 path_w,
53 windows.GENERIC_READ,
54 windows.FILE_SHARE_READ,
55 null,
56 windows.OPEN_EXISTING,
57 windows.FILE_ATTRIBUTE_NORMAL,
58 null,
59 );
60 return openHandle(handle);
40 return std.fs.Dir.cwd().openReadW(path_w);
6141 }
6242
6343 /// Calls `openWriteMode` with `default_mode` for the mode.
44 /// TODO: deprecate this and move it to `std.fs.Dir`.
6445 pub fn openWrite(path: []const u8) OpenError!File {
6546 return openWriteMode(path, default_mode);
6647 }
......@@ -68,6 +49,7 @@ pub const File = struct {
6849 /// If the path does not exist it will be created.
6950 /// If a file already exists in the destination it will be truncated.
7051 /// Call close to clean up.
52 /// TODO: deprecate this and move it to `std.fs.Dir`.
7153 pub fn openWriteMode(path: []const u8, file_mode: Mode) OpenError!File {
7254 if (builtin.os == .windows) {
7355 const path_w = try windows.sliceToPrefixedFileW(path);
......@@ -78,17 +60,20 @@ pub const File = struct {
7860 }
7961
8062 /// Same as `openWriteMode` except `path` is null-terminated.
63 /// TODO: deprecate this and move it to `std.fs.Dir`.
8164 pub fn openWriteModeC(path: [*]const u8, file_mode: Mode) OpenError!File {
8265 if (builtin.os == .windows) {
8366 const path_w = try windows.cStrToPrefixedFileW(path);
8467 return openWriteModeW(&path_w, file_mode);
8568 }
86 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;
69 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
70 const flags = O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;
8771 const fd = try os.openC(path, flags, file_mode);
8872 return openHandle(fd);
8973 }
9074
9175 /// Same as `openWriteMode` except `path` is null-terminated and UTF16LE encoded
76 /// TODO: deprecate this and move it to `std.fs.Dir`.
9277 pub fn openWriteModeW(path_w: [*]const u16, file_mode: Mode) OpenError!File {
9378 const handle = try windows.CreateFileW(
9479 path_w,
......@@ -105,6 +90,7 @@ pub const File = struct {
10590 /// If the path does not exist it will be created.
10691 /// If a file already exists in the destination this returns OpenError.PathAlreadyExists
10792 /// Call close to clean up.
93 /// TODO: deprecate this and move it to `std.fs.Dir`.
10894 pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File {
10995 if (builtin.os == .windows) {
11096 const path_w = try windows.sliceToPrefixedFileW(path);
......@@ -114,16 +100,19 @@ pub const File = struct {
114100 return openWriteNoClobberC(&path_c, file_mode);
115101 }
116102
103 /// TODO: deprecate this and move it to `std.fs.Dir`.
117104 pub fn openWriteNoClobberC(path: [*]const u8, file_mode: Mode) OpenError!File {
118105 if (builtin.os == .windows) {
119106 const path_w = try windows.cStrToPrefixedFileW(path);
120107 return openWriteNoClobberW(&path_w, file_mode);
121108 }
122 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_EXCL;
109 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
110 const flags = O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_EXCL;
123111 const fd = try os.openC(path, flags, file_mode);
124112 return openHandle(fd);
125113 }
126114
115 /// TODO: deprecate this and move it to `std.fs.Dir`.
127116 pub fn openWriteNoClobberW(path_w: [*]const u16, file_mode: Mode) OpenError!File {
128117 const handle = try windows.CreateFileW(
129118 path_w,
......@@ -146,16 +135,19 @@ pub const File = struct {
146135 /// In general it is recommended to avoid this function. For example,
147136 /// instead of testing if a file exists and then opening it, just
148137 /// open it and handle the error for file not found.
138 /// TODO: deprecate this and move it to `std.fs.Dir`.
149139 pub fn access(path: []const u8) !void {
150140 return os.access(path, os.F_OK);
151141 }
152142
153143 /// Same as `access` except the parameter is null-terminated.
144 /// TODO: deprecate this and move it to `std.fs.Dir`.
154145 pub fn accessC(path: [*]const u8) !void {
155146 return os.accessC(path, os.F_OK);
156147 }
157148
158149 /// Same as `access` except the parameter is null-terminated UTF16LE-encoded.
150 /// TODO: deprecate this and move it to `std.fs.Dir`.
159151 pub fn accessW(path: [*]const u16) !void {
160152 return os.accessW(path, os.F_OK);
161153 }
......@@ -272,9 +264,9 @@ pub const File = struct {
272264 return Stat{
273265 .size = @bitCast(u64, st.size),
274266 .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,
267 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
268 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
269 .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
278270 };
279271 }
280272
lib/std/fs/path.zig+1-1
......@@ -32,7 +32,7 @@ pub fn isSep(byte: u8) bool {
3232/// This is different from mem.join in that the separator will not be repeated if
3333/// it is found at the end or beginning of a pair of consecutive paths.
3434fn joinSep(allocator: *Allocator, separator: u8, paths: []const []const u8) ![]u8 {
35 if (paths.len == 0) return (([*]u8)(undefined))[0..0];
35 if (paths.len == 0) return &[0]u8{};
3636
3737 const total_len = blk: {
3838 var sum: usize = paths[0].len;
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+5-7
......@@ -41,8 +41,7 @@ var direct_allocator_state = Allocator{
4141
4242const DirectAllocator = struct {
4343 fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 {
44 if (n == 0)
45 return (([*]u8)(undefined))[0..0];
44 if (n == 0) return &[0]u8{};
4645
4746 if (builtin.os == .windows) {
4847 const w = os.windows;
......@@ -261,8 +260,7 @@ pub const HeapAllocator = switch (builtin.os) {
261260
262261 fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 {
263262 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
264 if (n == 0)
265 return (([*]u8)(undefined))[0..0];
263 if (n == 0) return &[0]u8{};
266264
267265 const amt = n + alignment + @sizeOf(usize);
268266 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, builtin.AtomicOrder.SeqCst);
......@@ -677,7 +675,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
677675 ) catch {
678676 const result = try self.fallback_allocator.reallocFn(
679677 self.fallback_allocator,
680 ([*]u8)(undefined)[0..0],
678 &[0]u8{},
681679 undefined,
682680 new_size,
683681 new_align,
......@@ -895,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
895893 if (mem.page_size << 2 > maxInt(usize)) return;
896894
897895 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
898 const large_align = u29(mem.page_size << 2);
896 const large_align = @as(u29, mem.page_size << 2);
899897
900898 var align_mask: usize = undefined;
901 _ = @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);
902900
903901 var slice = try allocator.alignedAlloc(u8, large_align, 500);
904902 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+26-48
......@@ -34,28 +34,23 @@ else
3434 Mode.blocking;
3535pub const is_async = mode != .blocking;
3636
37pub const GetStdIoError = os.windows.GetStdHandleError;
38
39pub fn getStdOut() GetStdIoError!File {
37pub fn getStdOut() File {
4038 if (builtin.os == .windows) {
41 const handle = try os.windows.GetStdHandle(os.windows.STD_OUTPUT_HANDLE);
42 return File.openHandle(handle);
39 return File.openHandle(os.windows.peb().ProcessParameters.hStdOutput);
4340 }
4441 return File.openHandle(os.STDOUT_FILENO);
4542}
4643
47pub fn getStdErr() GetStdIoError!File {
44pub fn getStdErr() File {
4845 if (builtin.os == .windows) {
49 const handle = try os.windows.GetStdHandle(os.windows.STD_ERROR_HANDLE);
50 return File.openHandle(handle);
46 return File.openHandle(os.windows.peb().ProcessParameters.hStdError);
5147 }
5248 return File.openHandle(os.STDERR_FILENO);
5349}
5450
55pub fn getStdIn() GetStdIoError!File {
51pub fn getStdIn() File {
5652 if (builtin.os == .windows) {
57 const handle = try os.windows.GetStdHandle(os.windows.STD_INPUT_HANDLE);
58 return File.openHandle(handle);
53 return File.openHandle(os.windows.peb().ProcessParameters.hStdInput);
5954 }
6055 return File.openHandle(os.STDIN_FILENO);
6156}
......@@ -74,24 +69,9 @@ pub fn writeFile(path: []const u8, data: []const u8) !void {
7469}
7570
7671/// On success, caller owns returned buffer.
77/// TODO move this to `std.fs` and add a version to `std.fs.Dir`.
72/// This function is deprecated; use `std.fs.Dir.readFileAlloc`.
7873pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 {
79 return readFileAllocAligned(allocator, path, @alignOf(u8));
80}
81
82/// On success, caller owns returned buffer.
83/// TODO move this to `std.fs` and add a version to `std.fs.Dir`.
84pub fn readFileAllocAligned(allocator: *mem.Allocator, path: []const u8, comptime A: u29) ![]align(A) u8 {
85 var file = try File.openRead(path);
86 defer file.close();
87
88 const size = try math.cast(usize, try file.getEndPos());
89 const buf = try allocator.alignedAlloc(u8, A, size);
90 errdefer allocator.free(buf);
91
92 var adapter = file.inStream();
93 try adapter.stream.readNoEof(buf[0..size]);
94 return buf;
74 return fs.Dir.cwd().readFileAlloc(allocator, path, math.maxInt(usize));
9575}
9676
9777pub fn BufferedInStream(comptime Error: type) type {
......@@ -353,21 +333,21 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
353333 const Buf = @IntType(false, buf_bit_count);
354334 const BufShift = math.Log2Int(Buf);
355335
356 out_bits.* = usize(0);
336 out_bits.* = @as(usize, 0);
357337 if (U == u0 or bits == 0) return 0;
358 var out_buffer = Buf(0);
338 var out_buffer = @as(Buf, 0);
359339
360340 if (self.bit_count > 0) {
361341 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
362342 const shift = u7_bit_count - n;
363343 switch (endian) {
364344 builtin.Endian.Big => {
365 out_buffer = Buf(self.bit_buffer >> shift);
345 out_buffer = @as(Buf, self.bit_buffer >> shift);
366346 self.bit_buffer <<= n;
367347 },
368348 builtin.Endian.Little => {
369349 const value = (self.bit_buffer << shift) >> shift;
370 out_buffer = Buf(value);
350 out_buffer = @as(Buf, value);
371351 self.bit_buffer >>= n;
372352 },
373353 }
......@@ -393,28 +373,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
393373 if (n >= u8_bit_count) {
394374 out_buffer <<= @intCast(u3, u8_bit_count - 1);
395375 out_buffer <<= 1;
396 out_buffer |= Buf(next_byte);
376 out_buffer |= @as(Buf, next_byte);
397377 out_bits.* += u8_bit_count;
398378 continue;
399379 }
400380
401381 const shift = @intCast(u3, u8_bit_count - n);
402382 out_buffer <<= @intCast(BufShift, n);
403 out_buffer |= Buf(next_byte >> shift);
383 out_buffer |= @as(Buf, next_byte >> shift);
404384 out_bits.* += n;
405385 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
406386 self.bit_count = shift;
407387 },
408388 builtin.Endian.Little => {
409389 if (n >= u8_bit_count) {
410 out_buffer |= Buf(next_byte) << @intCast(BufShift, out_bits.*);
390 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
411391 out_bits.* += u8_bit_count;
412392 continue;
413393 }
414394
415395 const shift = @intCast(u3, u8_bit_count - n);
416396 const value = (next_byte << shift) >> shift;
417 out_buffer |= Buf(value) << @intCast(BufShift, out_bits.*);
397 out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*);
418398 out_bits.* += n;
419399 self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n));
420400 self.bit_count = shift;
......@@ -434,7 +414,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
434414 var self = @fieldParentPtr(Self, "stream", self_stream);
435415
436416 var out_bits: usize = undefined;
437 var out_bits_total = usize(0);
417 var out_bits_total = @as(usize, 0);
438418 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
439419 if (self.bit_count > 0) {
440420 for (buffer) |*b, i| {
......@@ -598,7 +578,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
598578 self.index = 0;
599579 }
600580
601 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
581 fn writeFn(out_stream: *Stream, bytes: []const u8) Error!void {
602582 const self = @fieldParentPtr(Self, "stream", out_stream);
603583
604584 if (bytes.len >= self.buffer.len) {
......@@ -814,8 +794,7 @@ pub const BufferedAtomicFile = struct {
814794};
815795
816796pub fn readLine(buf: *std.Buffer) ![]u8 {
817 var stdin = try getStdIn();
818 var stdin_stream = stdin.inStream();
797 var stdin_stream = getStdIn().inStream();
819798 return readLineFrom(&stdin_stream.stream, buf);
820799}
821800
......@@ -856,8 +835,7 @@ test "io.readLineFrom" {
856835}
857836
858837pub fn readLineSlice(slice: []u8) ![]u8 {
859 var stdin = try getStdIn();
860 var stdin_stream = stdin.inStream();
838 var stdin_stream = getStdIn().inStream();
861839 return readLineSliceFrom(&stdin_stream.stream, slice);
862840}
863841
......@@ -949,14 +927,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
949927 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
950928 }
951929
952 var result = U(0);
930 var result = @as(U, 0);
953931 for (buffer) |byte, i| {
954932 switch (endian) {
955933 builtin.Endian.Big => {
956934 result = (result << u8_bit_count) | byte;
957935 },
958936 builtin.Endian.Little => {
959 result |= U(byte) << @intCast(Log2U, u8_bit_count * i);
937 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
960938 },
961939 }
962940 }
......@@ -1050,7 +1028,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
10501028 return;
10511029 }
10521030
1053 ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe
1031 ptr.* = @as(OC, undefined); //make it non-null so the following .? is guaranteed safe
10541032 const val_ptr = &ptr.*.?;
10551033 try self.deserializeInto(val_ptr);
10561034 },
......@@ -1154,7 +1132,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11541132
11551133 switch (@typeId(T)) {
11561134 builtin.TypeId.Void => return,
1157 builtin.TypeId.Bool => try self.serializeInt(u1(@boolToInt(value))),
1135 builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
11581136 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
11591137 builtin.TypeId.Struct => {
11601138 const info = @typeInfo(T);
......@@ -1197,10 +1175,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11971175 },
11981176 builtin.TypeId.Optional => {
11991177 if (value == null) {
1200 try self.serializeInt(u1(@boolToInt(false)));
1178 try self.serializeInt(@as(u1, @boolToInt(false)));
12011179 return;
12021180 }
1203 try self.serializeInt(u1(@boolToInt(true)));
1181 try self.serializeInt(@as(u1, @boolToInt(true)));
12041182
12051183 const OC = comptime meta.Child(T);
12061184 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+25-105
......@@ -1012,119 +1012,39 @@ pub const Value = union(enum) {
10121012 Object: ObjectMap,
10131013
10141014 pub fn dump(self: Value) void {
1015 switch (self) {
1016 Value.Null => {
1017 debug.warn("null");
1018 },
1019 Value.Bool => |inner| {
1020 debug.warn("{}", inner);
1021 },
1022 Value.Integer => |inner| {
1023 debug.warn("{}", inner);
1024 },
1025 Value.Float => |inner| {
1026 debug.warn("{:.5}", inner);
1027 },
1028 Value.String => |inner| {
1029 debug.warn("\"{}\"", inner);
1030 },
1031 Value.Array => |inner| {
1032 var not_first = false;
1033 debug.warn("[");
1034 for (inner.toSliceConst()) |value| {
1035 if (not_first) {
1036 debug.warn(",");
1037 }
1038 not_first = true;
1039 value.dump();
1040 }
1041 debug.warn("]");
1042 },
1043 Value.Object => |inner| {
1044 var not_first = false;
1045 debug.warn("{{");
1046 var it = inner.iterator();
1047
1048 while (it.next()) |entry| {
1049 if (not_first) {
1050 debug.warn(",");
1051 }
1052 not_first = true;
1053 debug.warn("\"{}\":", entry.key);
1054 entry.value.dump();
1055 }
1056 debug.warn("}}");
1057 },
1058 }
1015 var held = std.debug.getStderrMutex().acquire();
1016 defer held.release();
1017
1018 const stderr = std.debug.getStderrStream();
1019 self.dumpStream(stderr, 1024) catch return;
10591020 }
10601021
1061 pub fn dumpIndent(self: Value, indent: usize) void {
1022 pub fn dumpIndent(self: Value, comptime indent: usize) void {
10621023 if (indent == 0) {
10631024 self.dump();
10641025 } else {
1065 self.dumpIndentLevel(indent, 0);
1026 var held = std.debug.getStderrMutex().acquire();
1027 defer held.release();
1028
1029 const stderr = std.debug.getStderrStream();
1030 self.dumpStreamIndent(indent, stderr, 1024) catch return;
10661031 }
10671032 }
10681033
1069 fn dumpIndentLevel(self: Value, indent: usize, level: usize) void {
1070 switch (self) {
1071 Value.Null => {
1072 debug.warn("null");
1073 },
1074 Value.Bool => |inner| {
1075 debug.warn("{}", inner);
1076 },
1077 Value.Integer => |inner| {
1078 debug.warn("{}", inner);
1079 },
1080 Value.Float => |inner| {
1081 debug.warn("{:.5}", inner);
1082 },
1083 Value.String => |inner| {
1084 debug.warn("\"{}\"", inner);
1085 },
1086 Value.Array => |inner| {
1087 var not_first = false;
1088 debug.warn("[\n");
1089
1090 for (inner.toSliceConst()) |value| {
1091 if (not_first) {
1092 debug.warn(",\n");
1093 }
1094 not_first = true;
1095 padSpace(level + indent);
1096 value.dumpIndentLevel(indent, level + indent);
1097 }
1098 debug.warn("\n");
1099 padSpace(level);
1100 debug.warn("]");
1101 },
1102 Value.Object => |inner| {
1103 var not_first = false;
1104 debug.warn("{{\n");
1105 var it = inner.iterator();
1106
1107 while (it.next()) |entry| {
1108 if (not_first) {
1109 debug.warn(",\n");
1110 }
1111 not_first = true;
1112 padSpace(level + indent);
1113 debug.warn("\"{}\": ", entry.key);
1114 entry.value.dumpIndentLevel(indent, level + indent);
1115 }
1116 debug.warn("\n");
1117 padSpace(level);
1118 debug.warn("}}");
1119 },
1120 }
1034 pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void {
1035 var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream);
1036 w.newline = "";
1037 w.one_indent = "";
1038 w.space = "";
1039 try w.emitJson(self);
11211040 }
11221041
1123 fn padSpace(indent: usize) void {
1124 var i: usize = 0;
1125 while (i < indent) : (i += 1) {
1126 debug.warn(" ");
1127 }
1042 pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void {
1043 var one_indent = " " ** indent;
1044
1045 var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream);
1046 w.one_indent = one_indent;
1047 try w.emitJson(self);
11281048 }
11291049};
11301050
......@@ -1423,7 +1343,7 @@ test "write json then parse it" {
14231343 try jw.emitBool(true);
14241344
14251345 try jw.objectField("int");
1426 try jw.emitNumber(i32(1234));
1346 try jw.emitNumber(@as(i32, 1234));
14271347
14281348 try jw.objectField("array");
14291349 try jw.beginArray();
......@@ -1432,7 +1352,7 @@ test "write json then parse it" {
14321352 try jw.emitNull();
14331353
14341354 try jw.arrayElem();
1435 try jw.emitNumber(f64(12.34));
1355 try jw.emitNumber(@as(f64, 12.34));
14361356
14371357 try jw.endArray();
14381358
lib/std/json/write_stream.zig+5-1
......@@ -27,6 +27,9 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
2727 /// The string used as a newline character.
2828 newline: []const u8 = "\n",
2929
30 /// The string used as spacing.
31 space: []const u8 = " ",
32
3033 stream: *OutStream,
3134 state_index: usize,
3235 state: [max_depth]State,
......@@ -87,7 +90,8 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
8790 self.pushState(.Value);
8891 try self.indent();
8992 try self.writeEscapedString(name);
90 try self.stream.write(": ");
93 try self.stream.write(":");
94 try self.stream.write(self.space);
9195 },
9296 }
9397 }
lib/std/lazy_init.zig+14-12
......@@ -1,24 +1,26 @@
11const std = @import("std.zig");
2const builtin = @import("builtin");
32const assert = std.debug.assert;
43const testing = std.testing;
5const AtomicRmwOp = builtin.AtomicRmwOp;
6const AtomicOrder = builtin.AtomicOrder;
74
85/// Thread-safe initialization of global data.
96/// TODO use a mutex instead of a spinlock
107pub fn lazyInit(comptime T: type) LazyInit(T) {
118 return LazyInit(T){
129 .data = undefined,
13 .state = 0,
1410 };
1511}
1612
1713fn LazyInit(comptime T: type) type {
1814 return struct {
19 state: u8, // TODO make this an enum
15 state: State = .NotResolved,
2016 data: Data,
2117
18 const State = enum(u8) {
19 NotResolved,
20 Resolving,
21 Resolved,
22 };
23
2224 const Self = @This();
2325
2426 // TODO this isn't working for void, investigate and then remove this special case
......@@ -30,16 +32,16 @@ fn LazyInit(comptime T: type) type {
3032 /// perform the initialization and then call resolve().
3133 pub fn get(self: *Self) ?Ptr {
3234 while (true) {
33 var state = @cmpxchgWeak(u8, &self.state, 0, 1, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse return null;
35 var state = @cmpxchgWeak(State, &self.state, .NotResolved, .Resolving, .SeqCst, .SeqCst) orelse return null;
3436 switch (state) {
35 0 => continue,
36 1 => {
37 .NotResolved => continue,
38 .Resolving => {
3739 // TODO mutex instead of a spinlock
3840 continue;
3941 },
40 2 => {
42 .Resolved => {
4143 if (@sizeOf(T) == 0) {
42 return T(undefined);
44 return @as(T, undefined);
4345 } else {
4446 return &self.data;
4547 }
......@@ -50,8 +52,8 @@ fn LazyInit(comptime T: type) type {
5052 }
5153
5254 pub fn resolve(self: *Self) void {
53 const prev = @atomicRmw(u8, &self.state, AtomicRmwOp.Xchg, 2, AtomicOrder.SeqCst);
54 assert(prev == 1); // resolve() called twice
55 const prev = @atomicRmw(State, &self.state, .Xchg, .Resolved, .SeqCst);
56 assert(prev != .Resolved); // resolve() called twice
5557 }
5658 };
5759}
lib/std/math.zig+83-80
......@@ -10,6 +10,9 @@ pub const e = 2.71828182845904523536028747135266249775724709369995;
1010/// Archimedes' constant (π)
1111pub const pi = 3.14159265358979323846264338327950288419716939937510;
1212
13/// Circle constant (τ)
14pub const tau = 2 * pi;
15
1316/// log2(e)
1417pub const log2e = 1.442695040888963407359924681001892137;
1518
......@@ -44,10 +47,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079;
4447pub const sqrt1_2 = 0.707106781186547524400844362104849039;
4548
4649// 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));
50pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001));
51pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000));
52pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
53pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000));
5154pub const f128_toint = 1.0 / f128_epsilon;
5255
5356// float.h details
......@@ -69,28 +72,28 @@ pub const f16_max = 65504;
6972pub const f16_epsilon = 0.0009765625; // 2**-10
7073pub const f16_toint = 1.0 / f16_epsilon;
7174
72pub const nan_u16 = u16(0x7C01);
75pub const nan_u16 = @as(u16, 0x7C01);
7376pub const nan_f16 = @bitCast(f16, nan_u16);
7477
75pub const inf_u16 = u16(0x7C00);
78pub const inf_u16 = @as(u16, 0x7C00);
7679pub const inf_f16 = @bitCast(f16, inf_u16);
7780
78pub const nan_u32 = u32(0x7F800001);
81pub const nan_u32 = @as(u32, 0x7F800001);
7982pub const nan_f32 = @bitCast(f32, nan_u32);
8083
81pub const inf_u32 = u32(0x7F800000);
84pub const inf_u32 = @as(u32, 0x7F800000);
8285pub const inf_f32 = @bitCast(f32, inf_u32);
8386
84pub const nan_u64 = u64(0x7FF << 52) | 1;
87pub const nan_u64 = @as(u64, 0x7FF << 52) | 1;
8588pub const nan_f64 = @bitCast(f64, nan_u64);
8689
87pub const inf_u64 = u64(0x7FF << 52);
90pub const inf_u64 = @as(u64, 0x7FF << 52);
8891pub const inf_f64 = @bitCast(f64, inf_u64);
8992
90pub const nan_u128 = u128(0x7fff0000000000000000000000000001);
93pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001);
9194pub const nan_f128 = @bitCast(f128, nan_u128);
9295
93pub const inf_u128 = u128(0x7fff0000000000000000000000000000);
96pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000);
9497pub const inf_f128 = @bitCast(f128, inf_u128);
9598
9699pub const nan = @import("math/nan.zig").nan;
......@@ -248,7 +251,7 @@ pub fn Min(comptime A: type, comptime B: type) type {
248251 },
249252 else => {},
250253 }
251 return @typeOf(A(0) + B(0));
254 return @typeOf(@as(A, 0) + @as(B, 0));
252255}
253256
254257/// Returns the smaller number. When one of the parameter's type's full range fits in the other,
......@@ -273,7 +276,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) {
273276}
274277
275278test "math.min" {
276 testing.expect(min(i32(-1), i32(2)) == -1);
279 testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
277280 {
278281 var a: u16 = 999;
279282 var b: u32 = 10;
......@@ -309,7 +312,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
309312}
310313
311314test "math.max" {
312 testing.expect(max(i32(-1), i32(2)) == 2);
315 testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
313316}
314317
315318pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
......@@ -352,10 +355,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {
352355}
353356
354357test "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);
358 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
359 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
360 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
361 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
359362 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
360363 testing.expect(shl(u8, 0b11111111, 8) == 0);
361364 testing.expect(shl(u8, 0b11111111, 9) == 0);
......@@ -380,10 +383,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
380383}
381384
382385test "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);
386 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
387 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
388 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
389 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
387390 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
388391 testing.expect(shr(u8, 0b11111111, 8) == 0);
389392 testing.expect(shr(u8, 0b11111111, 9) == 0);
......@@ -402,11 +405,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
402405}
403406
404407test "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);
408 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
409 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
410 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
411 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
412 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
410413}
411414
412415/// Rotates left. Only unsigned values can be rotated.
......@@ -421,11 +424,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
421424}
422425
423426test "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);
427 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
428 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
429 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
430 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
431 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
429432}
430433
431434pub fn Log2Int(comptime T: type) type {
......@@ -532,8 +535,8 @@ test "math.absInt" {
532535 comptime testAbsInt();
533536}
534537fn testAbsInt() void {
535 testing.expect((absInt(i32(-10)) catch unreachable) == 10);
536 testing.expect((absInt(i32(10)) catch unreachable) == 10);
538 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
539 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
537540}
538541
539542pub const absFloat = fabs;
......@@ -543,8 +546,8 @@ test "math.absFloat" {
543546 comptime testAbsFloat();
544547}
545548fn testAbsFloat() void {
546 testing.expect(absFloat(f32(-10.05)) == 10.05);
547 testing.expect(absFloat(f32(10.05)) == 10.05);
549 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
550 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
548551}
549552
550553pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
......@@ -679,14 +682,14 @@ pub fn absCast(x: var) t: {
679682}
680683
681684test "math.absCast" {
682 testing.expect(absCast(i32(-999)) == 999);
683 testing.expect(@typeOf(absCast(i32(-999))) == u32);
685 testing.expect(absCast(@as(i32, -999)) == 999);
686 testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);
684687
685 testing.expect(absCast(i32(999)) == 999);
686 testing.expect(@typeOf(absCast(i32(999))) == u32);
688 testing.expect(absCast(@as(i32, 999)) == 999);
689 testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);
687690
688 testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));
689 testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);
691 testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
692 testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);
690693
691694 testing.expect(absCast(-999) == 999);
692695}
......@@ -705,13 +708,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
705708}
706709
707710test "math.negateCast" {
708 testing.expect((negateCast(u32(999)) catch unreachable) == -999);
709 testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
711 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
712 testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
710713
711 testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
712 testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
714 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
715 testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
713716
714 testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10)));
717 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
715718}
716719
717720/// Cast an integer to a different integer type. If the value doesn't fit,
......@@ -729,13 +732,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
729732}
730733
731734test "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)));
735 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
736 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
737 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
738 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
736739
737 testing.expect((try cast(u8, u32(255))) == u8(255));
738 testing.expect(@typeOf(try cast(u8, u32(255))) == u8);
740 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
741 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
739742}
740743
741744pub const AlignCastError = error{UnalignedMemory};
......@@ -786,9 +789,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
786789 comptime assert(@typeId(T) == builtin.TypeId.Int);
787790 comptime assert(!T.is_signed);
788791 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));
792 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
793 comptime const shiftType = std.math.Log2Int(PromotedType);
794 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
792795}
793796
794797/// Returns the next power of two (if the value is not already a power of two).
......@@ -797,8 +800,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
797800pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
798801 comptime assert(@typeId(T) == builtin.TypeId.Int);
799802 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;
803 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
804 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
802805 var x = ceilPowerOfTwoPromote(T, value);
803806 if (overflowBit & x != 0) {
804807 return error.Overflow;
......@@ -812,15 +815,15 @@ test "math.ceilPowerOfTwoPromote" {
812815}
813816
814817fn 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));
818 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
819 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
820 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
821 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
822 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
823 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
824 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
825 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
826 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
824827}
825828
826829test "math.ceilPowerOfTwo" {
......@@ -829,14 +832,14 @@ test "math.ceilPowerOfTwo" {
829832}
830833
831834fn 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));
835 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
836 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
837 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
838 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
839 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
840 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
841 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
842 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
840843 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
841844}
842845
......@@ -848,7 +851,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
848851pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
849852 assert(x != 0);
850853 const log2_val = log2_int(T, x);
851 if (T(1) << log2_val == x)
854 if (@as(T, 1) << log2_val == x)
852855 return log2_val;
853856 return log2_val + 1;
854857}
......@@ -870,8 +873,8 @@ pub fn lossyCast(comptime T: type, value: var) T {
870873 switch (@typeInfo(@typeOf(value))) {
871874 builtin.TypeId.Int => return @intToFloat(T, value),
872875 builtin.TypeId.Float => return @floatCast(T, value),
873 builtin.TypeId.ComptimeInt => return T(value),
874 builtin.TypeId.ComptimeFloat => return T(value),
876 builtin.TypeId.ComptimeInt => return @as(T, value),
877 builtin.TypeId.ComptimeFloat => return @as(T, value),
875878 else => @compileError("bad type"),
876879 }
877880}
......@@ -944,7 +947,7 @@ test "max value type" {
944947
945948pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
946949 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
947 return ResultInt(a) * ResultInt(b);
950 return @as(ResultInt, a) * @as(ResultInt, b);
948951}
949952
950953test "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+13-13
......@@ -118,11 +118,11 @@ 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;
125 const byte_slice = try self.reallocFn(self, ([*]u8)(undefined)[0..0], undefined, byte_count, a);
125 const byte_slice = try self.reallocFn(self, &[0]u8{}, undefined, byte_count, a);
126126 assert(byte_slice.len == byte_count);
127127 @memset(byte_slice.ptr, undefined, byte_slice.len);
128128 if (alignment == null) {
......@@ -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 }
......@@ -976,7 +976,7 @@ pub const SplitIterator = struct {
976976/// Naively combines a series of slices with a separator.
977977/// Allocates memory for the result, which must be freed by the caller.
978978pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []const u8) ![]u8 {
979 if (slices.len == 0) return (([*]u8)(undefined))[0..0];
979 if (slices.len == 0) return &[0]u8{};
980980
981981 const total_len = blk: {
982982 var sum: usize = separator.len * (slices.len - 1);
......@@ -1011,7 +1011,7 @@ test "mem.join" {
10111011
10121012/// Copies each T from slices into a new slice that exactly holds all the elements.
10131013pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T) ![]T {
1014 if (slices.len == 0) return (([*]T)(undefined))[0..0];
1014 if (slices.len == 0) return &[0]T{};
10151015
10161016 const total_len = blk: {
10171017 var sum: usize = 0;
......@@ -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/mutex.zig+64-69
......@@ -1,19 +1,13 @@
11const std = @import("std.zig");
22const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;
4const AtomicRmwOp = builtin.AtomicRmwOp;
53const testing = std.testing;
64const SpinLock = std.SpinLock;
7const linux = std.os.linux;
8const windows = std.os.windows;
5const ThreadParker = std.ThreadParker;
96
107/// Lock may be held only once. If the same thread
118/// tries to acquire the same mutex twice, it deadlocks.
12/// This type must be initialized at runtime, and then deinitialized when no
13/// longer needed, to free resources.
14/// If you need static initialization, use std.StaticallyInitializedMutex.
15/// The Linux implementation is based on mutex3 from
16/// https://www.akkadia.org/drepper/futex.pdf
9/// This type supports static initialization and is based off of Golang 1.13 runtime.lock_futex:
10/// https://github.com/golang/go/blob/master/src/runtime/lock_futex.go
1711/// When an application is built in single threaded release mode, all the functions are
1812/// no-ops. In single threaded debug mode, there is deadlock detection.
1913pub const Mutex = if (builtin.single_threaded)
......@@ -43,84 +37,85 @@ pub const Mutex = if (builtin.single_threaded)
4337 return Held{ .mutex = self };
4438 }
4539 }
46else switch (builtin.os) {
47 builtin.Os.linux => struct {
48 /// 0: unlocked
49 /// 1: locked, no waiters
50 /// 2: locked, one or more waiters
51 lock: i32,
52
53 pub const Held = struct {
54 mutex: *Mutex,
40else
41 struct {
42 state: State, // TODO: make this an enum
43 parker: ThreadParker,
5544
56 pub fn release(self: Held) void {
57 const c = @atomicRmw(i32, &self.mutex.lock, AtomicRmwOp.Sub, 1, AtomicOrder.Release);
58 if (c != 1) {
59 _ = @atomicRmw(i32, &self.mutex.lock, AtomicRmwOp.Xchg, 0, AtomicOrder.Release);
60 const rc = linux.futex_wake(&self.mutex.lock, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, 1);
61 switch (linux.getErrno(rc)) {
62 0 => {},
63 linux.EINVAL => unreachable,
64 else => unreachable,
65 }
66 }
67 }
45 const State = enum(u32) {
46 Unlocked,
47 Sleeping,
48 Locked,
6849 };
6950
51 /// number of iterations to spin yielding the cpu
52 const SPIN_CPU = 4;
53
54 /// number of iterations to perform in the cpu yield loop
55 const SPIN_CPU_COUNT = 30;
56
57 /// number of iterations to spin yielding the thread
58 const SPIN_THREAD = 1;
59
7060 pub fn init() Mutex {
71 return Mutex{ .lock = 0 };
61 return Mutex{
62 .state = .Unlocked,
63 .parker = ThreadParker.init(),
64 };
7265 }
7366
74 pub fn deinit(self: *Mutex) void {}
75
76 pub fn acquire(self: *Mutex) Held {
77 var c = @cmpxchgWeak(i32, &self.lock, 0, 1, AtomicOrder.Acquire, AtomicOrder.Monotonic) orelse
78 return Held{ .mutex = self };
79 if (c != 2)
80 c = @atomicRmw(i32, &self.lock, AtomicRmwOp.Xchg, 2, AtomicOrder.Acquire);
81 while (c != 0) {
82 const rc = linux.futex_wait(&self.lock, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, 2, null);
83 switch (linux.getErrno(rc)) {
84 0, linux.EINTR, linux.EAGAIN => {},
85 linux.EINVAL => unreachable,
86 else => unreachable,
87 }
88 c = @atomicRmw(i32, &self.lock, AtomicRmwOp.Xchg, 2, AtomicOrder.Acquire);
89 }
90 return Held{ .mutex = self };
67 pub fn deinit(self: *Mutex) void {
68 self.parker.deinit();
9169 }
92 },
93 // TODO once https://github.com/ziglang/zig/issues/287 (copy elision) is solved, we can make a
94 // better implementation of this. The problem is we need the init() function to have access to
95 // the address of the CRITICAL_SECTION, and then have it not move.
96 builtin.Os.windows => std.StaticallyInitializedMutex,
97 else => struct {
98 /// TODO better implementation than spin lock.
99 /// When changing this, one must also change the corresponding
100 /// std.StaticallyInitializedMutex code, since it aliases this type,
101 /// under the assumption that it works both statically and at runtime.
102 lock: SpinLock,
10370
10471 pub const Held = struct {
10572 mutex: *Mutex,
10673
10774 pub fn release(self: Held) void {
108 SpinLock.Held.release(SpinLock.Held{ .spinlock = &self.mutex.lock });
75 switch (@atomicRmw(State, &self.mutex.state, .Xchg, .Unlocked, .Release)) {
76 .Locked => {},
77 .Sleeping => self.mutex.parker.unpark(@ptrCast(*const u32, &self.mutex.state)),
78 .Unlocked => unreachable, // unlocking an unlocked mutex
79 else => unreachable, // should never be anything else
80 }
10981 }
11082 };
11183
112 pub fn init() Mutex {
113 return Mutex{ .lock = SpinLock.init() };
114 }
84 pub fn acquire(self: *Mutex) Held {
85 // Try and speculatively grab the lock.
86 // If it fails, the state is either Locked or Sleeping
87 // depending on if theres a thread stuck sleeping below.
88 var state = @atomicRmw(State, &self.state, .Xchg, .Locked, .Acquire);
89 if (state == .Unlocked)
90 return Held{ .mutex = self };
11591
116 pub fn deinit(self: *Mutex) void {}
92 while (true) {
93 // try and acquire the lock using cpu spinning on failure
94 var spin: usize = 0;
95 while (spin < SPIN_CPU) : (spin += 1) {
96 var value = @atomicLoad(State, &self.state, .Monotonic);
97 while (value == .Unlocked)
98 value = @cmpxchgWeak(State, &self.state, .Unlocked, state, .Acquire, .Monotonic) orelse return Held{ .mutex = self };
99 SpinLock.yield(SPIN_CPU_COUNT);
100 }
117101
118 pub fn acquire(self: *Mutex) Held {
119 _ = self.lock.acquire();
120 return Held{ .mutex = self };
102 // try and acquire the lock using thread rescheduling on failure
103 spin = 0;
104 while (spin < SPIN_THREAD) : (spin += 1) {
105 var value = @atomicLoad(State, &self.state, .Monotonic);
106 while (value == .Unlocked)
107 value = @cmpxchgWeak(State, &self.state, .Unlocked, state, .Acquire, .Monotonic) orelse return Held{ .mutex = self };
108 std.os.sched_yield() catch std.time.sleep(1);
109 }
110
111 // failed to acquire the lock, go to sleep until woken up by `Held.release()`
112 if (@atomicRmw(State, &self.state, .Xchg, .Sleeping, .Acquire) == .Unlocked)
113 return Held{ .mutex = self };
114 state = .Sleeping;
115 self.parker.park(@ptrCast(*const u32, &self.state), @enumToInt(State.Sleeping));
116 }
121117 }
122 },
123};
118 };
124119
125120const TestContext = struct {
126121 mutex: *Mutex,
lib/std/net.zig+114-72
......@@ -10,15 +10,18 @@ test "" {
1010 _ = @import("net/test.zig");
1111}
1212
13pub const IpAddress = extern union {
13const has_unix_sockets = @hasDecl(os, "sockaddr_un");
14
15pub const Address = extern union {
1416 any: os.sockaddr,
1517 in: os.sockaddr_in,
1618 in6: os.sockaddr_in6,
19 un: if (has_unix_sockets) os.sockaddr_un else void,
1720
1821 // TODO this crashed the compiler
1922 //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0);
2023
21 pub fn parse(name: []const u8, port: u16) !IpAddress {
24 pub fn parseIp(name: []const u8, port: u16) !Address {
2225 if (parseIp4(name, port)) |ip4| return ip4 else |err| switch (err) {
2326 error.Overflow,
2427 error.InvalidEnd,
......@@ -39,17 +42,17 @@ pub const IpAddress = extern union {
3942 return error.InvalidIPAddressFormat;
4043 }
4144
42 pub fn parseExpectingFamily(name: []const u8, family: os.sa_family_t, port: u16) !IpAddress {
45 pub fn parseExpectingFamily(name: []const u8, family: os.sa_family_t, port: u16) !Address {
4346 switch (family) {
4447 os.AF_INET => return parseIp4(name, port),
4548 os.AF_INET6 => return parseIp6(name, port),
46 os.AF_UNSPEC => return parse(name, port),
49 os.AF_UNSPEC => return parseIp(name, port),
4750 else => unreachable,
4851 }
4952 }
5053
51 pub fn parseIp6(buf: []const u8, port: u16) !IpAddress {
52 var result = IpAddress{
54 pub fn parseIp6(buf: []const u8, port: u16) !Address {
55 var result = Address{
5356 .in6 = os.sockaddr_in6{
5457 .scope_id = 0,
5558 .port = mem.nativeToBig(u16, port),
......@@ -117,7 +120,7 @@ pub const IpAddress = extern union {
117120 ip_slice[10] = 0xff;
118121 ip_slice[11] = 0xff;
119122
120 const ptr = @sliceToBytes((*const [1]u32)(&addr)[0..]);
123 const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]);
121124
122125 ip_slice[12] = ptr[0];
123126 ip_slice[13] = ptr[1];
......@@ -154,14 +157,14 @@ pub const IpAddress = extern union {
154157 }
155158 }
156159
157 pub fn parseIp4(buf: []const u8, port: u16) !IpAddress {
158 var result = IpAddress{
160 pub fn parseIp4(buf: []const u8, port: u16) !Address {
161 var result = Address{
159162 .in = os.sockaddr_in{
160163 .port = mem.nativeToBig(u16, port),
161164 .addr = undefined,
162165 },
163166 };
164 const out_ptr = @sliceToBytes((*[1]u32)(&result.in.addr)[0..]);
167 const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]);
165168
166169 var x: u8 = 0;
167170 var index: u8 = 0;
......@@ -194,8 +197,8 @@ pub const IpAddress = extern union {
194197 return error.Incomplete;
195198 }
196199
197 pub fn initIp4(addr: [4]u8, port: u16) IpAddress {
198 return IpAddress{
200 pub fn initIp4(addr: [4]u8, port: u16) Address {
201 return Address{
199202 .in = os.sockaddr_in{
200203 .port = mem.nativeToBig(u16, port),
201204 .addr = @ptrCast(*align(1) const u32, &addr).*,
......@@ -203,8 +206,8 @@ pub const IpAddress = extern union {
203206 };
204207 }
205208
206 pub fn initIp6(addr: [16]u8, port: u16, flowinfo: u32, scope_id: u32) IpAddress {
207 return IpAddress{
209 pub fn initIp6(addr: [16]u8, port: u16, flowinfo: u32, scope_id: u32) Address {
210 return Address{
208211 .in6 = os.sockaddr_in6{
209212 .addr = addr,
210213 .port = mem.nativeToBig(u16, port),
......@@ -214,8 +217,24 @@ pub const IpAddress = extern union {
214217 };
215218 }
216219
220 pub fn initUnix(path: []const u8) !Address {
221 var sock_addr = os.sockaddr_un{
222 .family = os.AF_UNIX,
223 .path = undefined,
224 };
225
226 // this enables us to have the proper length of the socket in getOsSockLen
227 mem.set(u8, &sock_addr.path, 0);
228
229 if (path.len > sock_addr.path.len) return error.NameTooLong;
230 mem.copy(u8, &sock_addr.path, path);
231
232 return Address{ .un = sock_addr };
233 }
234
217235 /// Returns the port in native endian.
218 pub fn getPort(self: IpAddress) u16 {
236 /// Asserts that the address is ip4 or ip6.
237 pub fn getPort(self: Address) u16 {
219238 const big_endian_port = switch (self.any.family) {
220239 os.AF_INET => self.in.port,
221240 os.AF_INET6 => self.in6.port,
......@@ -225,7 +244,8 @@ pub const IpAddress = extern union {
225244 }
226245
227246 /// `port` is native-endian.
228 pub fn setPort(self: *IpAddress, port: u16) void {
247 /// Asserts that the address is ip4 or ip6.
248 pub fn setPort(self: *Address, port: u16) void {
229249 const ptr = switch (self.any.family) {
230250 os.AF_INET => &self.in.port,
231251 os.AF_INET6 => &self.in6.port,
......@@ -237,16 +257,16 @@ pub const IpAddress = extern union {
237257 /// Asserts that `addr` is an IP address.
238258 /// This function will read past the end of the pointer, with a size depending
239259 /// on the address family.
240 pub fn initPosix(addr: *align(4) const os.sockaddr) IpAddress {
260 pub fn initPosix(addr: *align(4) const os.sockaddr) Address {
241261 switch (addr.family) {
242 os.AF_INET => return IpAddress{ .in = @ptrCast(*const os.sockaddr_in, addr).* },
243 os.AF_INET6 => return IpAddress{ .in6 = @ptrCast(*const os.sockaddr_in6, addr).* },
262 os.AF_INET => return Address{ .in = @ptrCast(*const os.sockaddr_in, addr).* },
263 os.AF_INET6 => return Address{ .in6 = @ptrCast(*const os.sockaddr_in6, addr).* },
244264 else => unreachable,
245265 }
246266 }
247267
248268 pub fn format(
249 self: IpAddress,
269 self: Address,
250270 comptime fmt: []const u8,
251271 options: std.fmt.FormatOptions,
252272 context: var,
......@@ -271,7 +291,7 @@ pub const IpAddress = extern union {
271291 },
272292 os.AF_INET6 => {
273293 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})) {
294 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
275295 try std.fmt.format(
276296 context,
277297 Errors,
......@@ -314,20 +334,35 @@ pub const IpAddress = extern union {
314334 }
315335 try std.fmt.format(context, Errors, output, "]:{}", port);
316336 },
337 os.AF_UNIX => {
338 if (!has_unix_sockets) {
339 unreachable;
340 }
341
342 try std.fmt.format(context, Errors, output, "{}", self.un.path);
343 },
317344 else => unreachable,
318345 }
319346 }
320347
321 pub fn eql(a: IpAddress, b: IpAddress) bool {
348 pub fn eql(a: Address, b: Address) bool {
322349 const a_bytes = @ptrCast([*]const u8, &a.any)[0..a.getOsSockLen()];
323350 const b_bytes = @ptrCast([*]const u8, &b.any)[0..b.getOsSockLen()];
324351 return mem.eql(u8, a_bytes, b_bytes);
325352 }
326353
327 fn getOsSockLen(self: IpAddress) os.socklen_t {
354 fn getOsSockLen(self: Address) os.socklen_t {
328355 switch (self.any.family) {
329356 os.AF_INET => return @sizeOf(os.sockaddr_in),
330357 os.AF_INET6 => return @sizeOf(os.sockaddr_in6),
358 os.AF_UNIX => {
359 if (!has_unix_sockets) {
360 unreachable;
361 }
362
363 const path_len = std.mem.len(u8, &self.un.path);
364 return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
365 },
331366 else => unreachable,
332367 }
333368 }
......@@ -342,23 +377,20 @@ pub fn connectUnixSocket(path: []const u8) !fs.File {
342377 );
343378 errdefer os.close(sockfd);
344379
345 var sock_addr = os.sockaddr_un{
346 .family = os.AF_UNIX,
347 .path = undefined,
348 };
349
350 if (path.len > sock_addr.path.len) return error.NameTooLong;
351 mem.copy(u8, &sock_addr.path, path);
380 var addr = try std.net.Address.initUnix(path);
352381
353 const size = @intCast(u32, @sizeOf(os.sockaddr_un) - sock_addr.path.len + path.len);
354 try os.connect(sockfd, &sock_addr, size);
382 try os.connect(
383 sockfd,
384 &addr.any,
385 addr.getOsSockLen(),
386 );
355387
356388 return fs.File.openHandle(sockfd);
357389}
358390
359391pub const AddressList = struct {
360392 arena: std.heap.ArenaAllocator,
361 addrs: []IpAddress,
393 addrs: []Address,
362394 canon_name: ?[]u8,
363395
364396 fn deinit(self: *AddressList) void {
......@@ -381,7 +413,7 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)
381413 return tcpConnectToAddress(addrs[0], port);
382414}
383415
384pub fn tcpConnectToAddress(address: IpAddress) !fs.File {
416pub fn tcpConnectToAddress(address: Address) !fs.File {
385417 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
386418 const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;
387419 const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
......@@ -456,13 +488,13 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
456488 }
457489 break :blk count;
458490 };
459 result.addrs = try arena.alloc(IpAddress, addr_count);
491 result.addrs = try arena.alloc(Address, addr_count);
460492
461493 var it: ?*os.addrinfo = res;
462494 var i: usize = 0;
463495 while (it) |info| : (it = info.next) {
464496 const addr = info.addr orelse continue;
465 result.addrs[i] = IpAddress.initPosix(@alignCast(4, addr));
497 result.addrs[i] = Address.initPosix(@alignCast(4, addr));
466498
467499 if (info.canonname) |n| {
468500 if (result.canon_name == null) {
......@@ -485,7 +517,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
485517
486518 try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
487519
488 result.addrs = try arena.alloc(IpAddress, lookup_addrs.len);
520 result.addrs = try arena.alloc(Address, lookup_addrs.len);
489521 if (!canon.isNull()) {
490522 result.canon_name = canon.toOwnedSlice();
491523 }
......@@ -501,7 +533,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
501533}
502534
503535const LookupAddr = struct {
504 addr: IpAddress,
536 addr: Address,
505537 sortkey: i32 = 0,
506538};
507539
......@@ -524,7 +556,7 @@ fn linuxLookupName(
524556 if (opt_name) |name| {
525557 // reject empty name and check len so it fits into temp bufs
526558 try canon.replaceContents(name);
527 if (IpAddress.parseExpectingFamily(name, family, port)) |addr| {
559 if (Address.parseExpectingFamily(name, family, port)) |addr| {
528560 try addrs.append(LookupAddr{ .addr = addr });
529561 } else |name_err| if ((flags & std.c.AI_NUMERICHOST) != 0) {
530562 return name_err;
......@@ -611,7 +643,7 @@ fn linuxLookupName(
611643 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
612644 mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
613645 }
614 if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
646 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
615647 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
616648 prefixlen = prefixMatch(sa6.addr, da6.addr);
617649 } else |_| {}
......@@ -710,7 +742,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 {
710742 // address. However the definition of the source prefix length is
711743 // not clear and thus this limiting is not yet implemented.
712744 var i: u8 = 0;
713 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
745 while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {}
714746 return i;
715747}
716748
......@@ -751,23 +783,23 @@ fn linuxLookupNameFromNull(
751783 if ((flags & std.c.AI_PASSIVE) != 0) {
752784 if (family != os.AF_INET6) {
753785 (try addrs.addOne()).* = LookupAddr{
754 .addr = IpAddress.initIp4([1]u8{0} ** 4, port),
786 .addr = Address.initIp4([1]u8{0} ** 4, port),
755787 };
756788 }
757789 if (family != os.AF_INET) {
758790 (try addrs.addOne()).* = LookupAddr{
759 .addr = IpAddress.initIp6([1]u8{0} ** 16, port, 0, 0),
791 .addr = Address.initIp6([1]u8{0} ** 16, port, 0, 0),
760792 };
761793 }
762794 } else {
763795 if (family != os.AF_INET6) {
764796 (try addrs.addOne()).* = LookupAddr{
765 .addr = IpAddress.initIp4([4]u8{ 127, 0, 0, 1 }, port),
797 .addr = Address.initIp4([4]u8{ 127, 0, 0, 1 }, port),
766798 };
767799 }
768800 if (family != os.AF_INET) {
769801 (try addrs.addOne()).* = LookupAddr{
770 .addr = IpAddress.initIp6(([1]u8{0} ** 15) ++ [1]u8{1}, port, 0, 0),
802 .addr = Address.initIp6(([1]u8{0} ** 15) ++ [1]u8{1}, port, 0, 0),
771803 };
772804 }
773805 }
......@@ -812,7 +844,7 @@ fn linuxLookupNameFromHosts(
812844 }
813845 } else continue;
814846
815 const addr = IpAddress.parseExpectingFamily(ip_text, family, port) catch |err| switch (err) {
847 const addr = Address.parseExpectingFamily(ip_text, family, port) catch |err| switch (err) {
816848 error.Overflow,
817849 error.InvalidEnd,
818850 error.InvalidCharacter,
......@@ -1033,7 +1065,7 @@ fn linuxLookupNameFromNumericUnspec(
10331065 name: []const u8,
10341066 port: u16,
10351067) !void {
1036 const addr = try IpAddress.parse(name, port);
1068 const addr = try Address.parseIp(name, port);
10371069 (try addrs.addOne()).* = LookupAddr{ .addr = addr };
10381070}
10391071
......@@ -1049,7 +1081,7 @@ fn resMSendRc(
10491081 var sl: os.socklen_t = @sizeOf(os.sockaddr_in);
10501082 var family: os.sa_family_t = os.AF_INET;
10511083
1052 var ns_list = std.ArrayList(IpAddress).init(rc.ns.allocator);
1084 var ns_list = std.ArrayList(Address).init(rc.ns.allocator);
10531085 defer ns_list.deinit();
10541086
10551087 try ns_list.resize(rc.ns.len);
......@@ -1065,8 +1097,8 @@ fn resMSendRc(
10651097 }
10661098
10671099 // Get local address and open/bind a socket
1068 var sa: IpAddress = undefined;
1069 @memset(@ptrCast([*]u8, &sa), 0, @sizeOf(IpAddress));
1100 var sa: Address = undefined;
1101 @memset(@ptrCast([*]u8, &sa), 0, @sizeOf(Address));
10701102 sa.any.family = family;
10711103 const flags = os.SOCK_DGRAM | os.SOCK_CLOEXEC | os.SOCK_NONBLOCK;
10721104 const fd = os.socket(family, flags, 0) catch |err| switch (err) {
......@@ -1133,7 +1165,7 @@ fn resMSendRc(
11331165 }
11341166
11351167 // 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);
1168 const clamped_timeout = std.math.min(@as(u31, std.math.maxInt(u31)), t1 + retry_interval - t2);
11371169 const nevents = os.poll(&pfd, clamped_timeout) catch 0;
11381170 if (nevents == 0) continue;
11391171
......@@ -1194,23 +1226,23 @@ fn dnsParse(
11941226 if (r.len < 12) return error.InvalidDnsPacket;
11951227 if ((r[3] & 15) != 0) return;
11961228 var p = r.ptr + 12;
1197 var qdcount = r[4] * usize(256) + r[5];
1198 var ancount = r[6] * usize(256) + r[7];
1229 var qdcount = r[4] * @as(usize, 256) + r[5];
1230 var ancount = r[6] * @as(usize, 256) + r[7];
11991231 if (qdcount + ancount > 64) return error.InvalidDnsPacket;
12001232 while (qdcount != 0) {
12011233 qdcount -= 1;
12021234 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
12031235 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
12041236 return error.InvalidDnsPacket;
1205 p += usize(5) + @boolToInt(p[0] != 0);
1237 p += @as(usize, 5) + @boolToInt(p[0] != 0);
12061238 }
12071239 while (ancount != 0) {
12081240 ancount -= 1;
12091241 while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1;
12101242 if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6)
12111243 return error.InvalidDnsPacket;
1212 p += usize(1) + @boolToInt(p[0] != 0);
1213 const len = p[8] * usize(256) + p[9];
1244 p += @as(usize, 1) + @boolToInt(p[0] != 0);
1245 const len = p[8] * @as(usize, 256) + p[9];
12141246 if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket;
12151247 try callback(ctx, p[1], p[10 .. 10 + len], r);
12161248 p += 10 + len;
......@@ -1224,7 +1256,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
12241256 const new_addr = try ctx.addrs.addOne();
12251257 new_addr.* = LookupAddr{
12261258 // TODO slice [0..4] to make this *[4]u8 without @ptrCast
1227 .addr = IpAddress.initIp4(@ptrCast(*const [4]u8, data.ptr).*, ctx.port),
1259 .addr = Address.initIp4(@ptrCast(*const [4]u8, data.ptr).*, ctx.port),
12281260 };
12291261 },
12301262 os.RR_AAAA => {
......@@ -1232,7 +1264,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
12321264 const new_addr = try ctx.addrs.addOne();
12331265 new_addr.* = LookupAddr{
12341266 // TODO slice [0..16] to make this *[16]u8 without @ptrCast
1235 .addr = IpAddress.initIp6(@ptrCast(*const [16]u8, data.ptr).*, ctx.port, 0, 0),
1267 .addr = Address.initIp6(@ptrCast(*const [16]u8, data.ptr).*, ctx.port, 0, 0),
12361268 };
12371269 },
12381270 os.RR_CNAME => {
......@@ -1248,12 +1280,12 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
12481280 }
12491281}
12501282
1251pub const TcpServer = struct {
1283pub const StreamServer = struct {
12521284 /// Copied from `Options` on `init`.
12531285 kernel_backlog: u32,
12541286
12551287 /// `undefined` until `listen` returns successfully.
1256 listen_address: IpAddress,
1288 listen_address: Address,
12571289
12581290 sockfd: ?os.fd_t,
12591291
......@@ -1266,24 +1298,26 @@ pub const TcpServer = struct {
12661298
12671299 /// After this call succeeds, resources have been acquired and must
12681300 /// be released with `deinit`.
1269 pub fn init(options: Options) TcpServer {
1270 return TcpServer{
1301 pub fn init(options: Options) StreamServer {
1302 return StreamServer{
12711303 .sockfd = null,
12721304 .kernel_backlog = options.kernel_backlog,
12731305 .listen_address = undefined,
12741306 };
12751307 }
12761308
1277 /// Release all resources. The `TcpServer` memory becomes `undefined`.
1278 pub fn deinit(self: *TcpServer) void {
1309 /// Release all resources. The `StreamServer` memory becomes `undefined`.
1310 pub fn deinit(self: *StreamServer) void {
12791311 self.close();
12801312 self.* = undefined;
12811313 }
12821314
1283 pub fn listen(self: *TcpServer, address: IpAddress) !void {
1315 pub fn listen(self: *StreamServer, address: Address) !void {
12841316 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
12851317 const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;
1286 const sockfd = try os.socket(os.AF_INET, sock_flags, os.IPPROTO_TCP);
1318 const proto = if (address.any.family == os.AF_UNIX) @as(u32, 0) else os.IPPROTO_TCP;
1319
1320 const sockfd = try os.socket(address.any.family, sock_flags, proto);
12871321 self.sockfd = sockfd;
12881322 errdefer {
12891323 os.close(sockfd);
......@@ -1299,7 +1333,7 @@ pub const TcpServer = struct {
12991333 /// Stop listening. It is still necessary to call `deinit` after stopping listening.
13001334 /// Calling `deinit` will automatically call `close`. It is safe to call `close` when
13011335 /// not listening.
1302 pub fn close(self: *TcpServer) void {
1336 pub fn close(self: *StreamServer) void {
13031337 if (self.sockfd) |fd| {
13041338 os.close(fd);
13051339 self.sockfd = null;
......@@ -1326,14 +1360,22 @@ pub const TcpServer = struct {
13261360 BlockedByFirewall,
13271361 } || os.UnexpectedError;
13281362
1329 /// If this function succeeds, the returned `fs.File` is a caller-managed resource.
1330 pub fn accept(self: *TcpServer) AcceptError!fs.File {
1363 pub const Connection = struct {
1364 file: fs.File,
1365 address: Address
1366 };
1367
1368 /// If this function succeeds, the returned `Connection` is a caller-managed resource.
1369 pub fn accept(self: *StreamServer) AcceptError!Connection {
13311370 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
13321371 const accept_flags = nonblock | os.SOCK_CLOEXEC;
1333 var accepted_addr: IpAddress = undefined;
1334 var adr_len: os.socklen_t = @sizeOf(IpAddress);
1372 var accepted_addr: Address = undefined;
1373 var adr_len: os.socklen_t = @sizeOf(Address);
13351374 if (os.accept4(self.sockfd.?, &accepted_addr.any, &adr_len, accept_flags)) |fd| {
1336 return fs.File.openHandle(fd);
1375 return Connection{
1376 .file = fs.File.openHandle(fd),
1377 .address = accepted_addr,
1378 };
13371379 } else |err| switch (err) {
13381380 // We only give SOCK_NONBLOCK when I/O mode is async, in which case this error
13391381 // is handled by os.accept4.
lib/std/net/test.zig+19-19
......@@ -28,17 +28,17 @@ test "parse and render IPv6 addresses" {
2828 "::ffff:123.5.123.5",
2929 };
3030 for (ips) |ip, i| {
31 var addr = net.IpAddress.parseIp6(ip, 0) catch unreachable;
31 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
3232 var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
3333 std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
3434 }
3535
36 testing.expectError(error.InvalidCharacter, net.IpAddress.parseIp6(":::", 0));
37 testing.expectError(error.Overflow, net.IpAddress.parseIp6("FF001::FB", 0));
38 testing.expectError(error.InvalidCharacter, net.IpAddress.parseIp6("FF01::Fb:zig", 0));
39 testing.expectError(error.InvalidEnd, net.IpAddress.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
40 testing.expectError(error.Incomplete, net.IpAddress.parseIp6("FF01:", 0));
41 testing.expectError(error.InvalidIpv4Mapping, net.IpAddress.parseIp6("::123.123.123.123", 0));
36 testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
37 testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
38 testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
39 testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
40 testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
41 testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
4242}
4343
4444test "parse and render IPv4 addresses" {
......@@ -50,16 +50,16 @@ test "parse and render IPv4 addresses" {
5050 "123.255.0.91",
5151 "127.0.0.1",
5252 }) |ip| {
53 var addr = net.IpAddress.parseIp4(ip, 0) catch unreachable;
53 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
5454 var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
5555 std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
5656 }
5757
58 testing.expectError(error.Overflow, net.IpAddress.parseIp4("256.0.0.1", 0));
59 testing.expectError(error.InvalidCharacter, net.IpAddress.parseIp4("x.0.0.1", 0));
60 testing.expectError(error.InvalidEnd, net.IpAddress.parseIp4("127.0.0.1.1", 0));
61 testing.expectError(error.Incomplete, net.IpAddress.parseIp4("127.0.0.", 0));
62 testing.expectError(error.InvalidCharacter, net.IpAddress.parseIp4("100..0.1", 0));
58 testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
59 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
60 testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
61 testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
62 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
6363}
6464
6565test "resolve DNS" {
......@@ -91,9 +91,9 @@ test "listen on a port, send bytes, receive bytes" {
9191 }
9292
9393 // TODO doing this at comptime crashed the compiler
94 const localhost = net.IpAddress.parse("127.0.0.1", 0);
94 const localhost = net.Address.parseIp("127.0.0.1", 0);
9595
96 var server = net.TcpServer.init(net.TcpServer.Options{});
96 var server = net.StreamServer.init(net.StreamServer.Options{});
9797 defer server.deinit();
9898 try server.listen(localhost);
9999
......@@ -104,7 +104,7 @@ test "listen on a port, send bytes, receive bytes" {
104104 try await client_frame;
105105}
106106
107fn testClient(addr: net.IpAddress) anyerror!void {
107fn testClient(addr: net.Address) anyerror!void {
108108 const socket_file = try net.tcpConnectToAddress(addr);
109109 defer socket_file.close();
110110
......@@ -114,9 +114,9 @@ fn testClient(addr: net.IpAddress) anyerror!void {
114114 testing.expect(mem.eql(u8, msg, "hello from server\n"));
115115}
116116
117fn testServer(server: *net.TcpServer) anyerror!void {
118 var client_file = try server.accept();
117fn testServer(server: *net.StreamServer) anyerror!void {
118 var client = try server.accept();
119119
120 const stream = &client_file.outStream().stream;
120 const stream = &client.file.outStream().stream;
121121 try stream.print("hello from server\n");
122122}
lib/std/os.zig+26-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;
......@@ -3171,3 +3171,22 @@ pub fn dn_expand(
31713171 }
31723172 return error.InvalidDnsPacket;
31733173}
3174
3175pub const SchedYieldError = error{
3176 /// The system is not configured to allow yielding
3177 SystemCannotYield,
3178};
3179
3180pub fn sched_yield() SchedYieldError!void {
3181 if (builtin.os == .windows) {
3182 // The return value has to do with how many other threads there are; it is not
3183 // an error condition on Windows.
3184 _ = windows.kernel32.SwitchToThread();
3185 return;
3186 }
3187 switch (errno(system.sched_yield())) {
3188 0 => return,
3189 ENOSYS => return error.SystemCannotYield,
3190 else => return error.SystemCannotYield,
3191 }
3192}
lib/std/os/bits.zig-3
......@@ -14,9 +14,6 @@ pub usingnamespace switch (builtin.os) {
1414 else => struct {},
1515};
1616
17pub const pthread_t = *@OpaqueType();
18pub const FILE = @OpaqueType();
19
2017pub const iovec = extern struct {
2118 iov_base: [*]u8,
2219 iov_len: usize,
lib/std/os/bits/darwin.zig-6
......@@ -133,11 +133,6 @@ pub const dirent = extern struct {
133133 }
134134};
135135
136pub const pthread_attr_t = extern struct {
137 __sig: c_long,
138 __opaque: [56]u8,
139};
140
141136/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
142137pub const Kevent = extern struct {
143138 ident: usize,
......@@ -272,7 +267,6 @@ pub const SA_USERTRAMP = 0x0100;
272267/// signal handler with SA_SIGINFO args with 64bit regs information
273268pub const SA_64REGSET = 0x0200;
274269
275pub const O_LARGEFILE = 0x0000;
276270pub const O_PATH = 0x0000;
277271
278272pub const F_OK = 0;
lib/std/os/bits/dragonfly.zig+4-10
......@@ -241,7 +241,6 @@ pub const KERN_MAXID = 37;
241241
242242pub const HOST_NAME_MAX = 255;
243243
244pub const O_LARGEFILE = 0; // faked support
245244pub const O_RDONLY = 0;
246245pub const O_NDELAY = O_NONBLOCK;
247246pub const O_WRONLY = 1;
......@@ -315,7 +314,7 @@ pub const dirent = extern struct {
315314 d_name: [256]u8,
316315
317316 pub fn reclen(self: dirent) u16 {
318 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7);
317 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
319318 }
320319};
321320
......@@ -360,11 +359,6 @@ pub const Kevent = extern struct {
360359 udata: usize,
361360};
362361
363pub const pthread_attr_t = extern struct { // copied from freebsd
364 __size: [56]u8,
365 __align: c_long,
366};
367
368362pub const EVFILT_FS = -10;
369363pub const EVFILT_USER = -9;
370364pub const EVFILT_EXCEPT = -8;
......@@ -515,13 +509,13 @@ pub const sigset_t = extern struct {
515509pub const sig_atomic_t = c_int;
516510pub const Sigaction = extern struct {
517511 __sigaction_u: extern union {
518 __sa_handler: ?extern fn(c_int) void,
519 __sa_sigaction: ?extern fn(c_int, [*c]siginfo_t, ?*c_void) void,
512 __sa_handler: ?extern fn (c_int) void,
513 __sa_sigaction: ?extern fn (c_int, [*c]siginfo_t, ?*c_void) void,
520514 },
521515 sa_flags: c_int,
522516 sa_mask: sigset_t,
523517};
524pub const sig_t = [*c]extern fn(c_int) void;
518pub const sig_t = [*c]extern fn (c_int) void;
525519
526520pub const sigvec = extern struct {
527521 sv_handler: [*c]__sighandler_t,
lib/std/os/bits/freebsd.zig-6
......@@ -15,11 +15,6 @@ pub const Kevent = extern struct {
1515 // TODO ext
1616};
1717
18pub const pthread_attr_t = extern struct {
19 __size: [56]u8,
20 __align: c_long,
21};
22
2318pub const dl_phdr_info = extern struct {
2419 dlpi_addr: usize,
2520 dlpi_name: ?[*]const u8,
......@@ -305,7 +300,6 @@ pub const O_CLOEXEC = 0x00100000;
305300
306301pub const O_ASYNC = 0x0040;
307302pub const O_DIRECT = 0x00010000;
308pub const O_LARGEFILE = 0;
309303pub const O_NOATIME = 0o1000000;
310304pub const O_PATH = 0o10000000;
311305pub const O_TMPFILE = 0o20200000;
lib/std/os/bits/linux.zig+5-10
......@@ -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 {
......@@ -1000,11 +1000,6 @@ pub const dl_phdr_info = extern struct {
10001000 dlpi_phnum: u16,
10011001};
10021002
1003pub const pthread_attr_t = extern struct {
1004 __size: [56]u8,
1005 __align: c_long,
1006};
1007
10081003pub const CPU_SETSIZE = 128;
10091004pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
10101005pub const cpu_count_t = @IntType(false, std.math.log2(CPU_SETSIZE * 8));
lib/std/os/bits/netbsd.zig-7
......@@ -14,12 +14,6 @@ pub const Kevent = extern struct {
1414 udata: usize,
1515};
1616
17pub const pthread_attr_t = extern struct {
18 pta_magic: u32,
19 pta_flags: c_int,
20 pta_private: *c_void,
21};
22
2317pub const dl_phdr_info = extern struct {
2418 dlpi_addr: usize,
2519 dlpi_name: ?[*]const u8,
......@@ -298,7 +292,6 @@ pub const O_CLOEXEC = 0x00400000;
298292
299293pub const O_ASYNC = 0x0040;
300294pub const O_DIRECT = 0x00080000;
301pub const O_LARGEFILE = 0;
302295pub const O_NOATIME = 0;
303296pub const O_PATH = 0;
304297pub const O_TMPFILE = 0;
lib/std/os/bits/windows.zig+19
......@@ -186,6 +186,11 @@ pub const sockaddr_in6 = extern struct {
186186pub const in6_addr = [16]u8;
187187pub const in_addr = u32;
188188
189pub const sockaddr_un = extern struct {
190 family: sa_family_t = AF_UNIX,
191 path: [108]u8,
192};
193
189194pub const AF_UNSPEC = 0;
190195pub const AF_UNIX = 1;
191196pub const AF_INET = 2;
......@@ -221,3 +226,17 @@ pub const AF_TCNMESSAGE = 30;
221226pub const AF_ICLFXBM = 31;
222227pub const AF_BTH = 32;
223228pub const AF_MAX = 33;
229
230pub const SOCK_STREAM = 1;
231pub const SOCK_DGRAM = 2;
232pub const SOCK_RAW = 3;
233pub const SOCK_RDM = 4;
234pub const SOCK_SEQPACKET = 5;
235
236pub const IPPROTO_ICMP = 1;
237pub const IPPROTO_IGMP = 2;
238pub const BTHPROTO_RFCOMM = 3;
239pub const IPPROTO_TCP = 6;
240pub const IPPROTO_UDP = 17;
241pub const IPPROTO_ICMPV6 = 58;
242pub const IPPROTO_RM = 113;
lib/std/os/linux.zig+99-95
......@@ -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,33 +519,33 @@ 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 {
531531 const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM));
532532 // Note that we may not have a VDSO at all, update the stub address anyway
533533 // so that clock_gettime will fall back on the good old (and slow) syscall
534 _ = @cmpxchgStrong(?*const c_void, &vdso_clock_gettime, &init_vdso_clock_gettime, ptr, .Monotonic, .Monotonic);
534 @atomicStore(?*const c_void, &vdso_clock_gettime, ptr, .Monotonic);
535535 // Call into the VDSO if available
536536 if (ptr) |fn_ptr| {
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
......@@ -954,8 +954,12 @@ pub fn fremovexattr(fd: usize, name: [*]const u8) usize {
954954 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));
955955}
956956
957pub fn sched_yield() usize {
958 return syscall0(SYS_sched_yield);
959}
960
957961pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize {
958 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));
959963 if (@bitCast(isize, rc) < 0) return rc;
960964 if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
961965 return 0;
......@@ -970,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize {
970974}
971975
972976pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
973 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));
974978}
975979
976980pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
......@@ -980,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout
980984pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {
981985 return syscall6(
982986 SYS_epoll_pwait,
983 @bitCast(usize, isize(epoll_fd)),
987 @bitCast(usize, @as(isize, epoll_fd)),
984988 @ptrToInt(events),
985989 @intCast(usize, maxevents),
986 @bitCast(usize, isize(timeout)),
990 @bitCast(usize, @as(isize, timeout)),
987991 @ptrToInt(sigmask),
988992 @sizeOf(sigset_t),
989993 );
......@@ -994,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize {
994998}
995999
9961000pub fn timerfd_create(clockid: i32, flags: u32) usize {
997 return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags);
1001 return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
9981002}
9991003
10001004pub const itimerspec = extern struct {
......@@ -1003,11 +1007,11 @@ pub const itimerspec = extern struct {
10031007};
10041008
10051009pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1006 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));
10071011}
10081012
10091013pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1010 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));
10111015}
10121016
10131017pub fn unshare(flags: usize) usize {
......@@ -1092,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
10921096}
10931097
10941098pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
1095 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);
10961100}
10971101
10981102pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {
1099 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);
11001104}
11011105
11021106test "" {
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/uefi/protocols.zig+44
......@@ -1,3 +1,7 @@
1pub const LoadedImageProtocol = @import("protocols/loaded_image_protocol.zig").LoadedImageProtocol;
2
3pub const DevicePathProtocol = @import("protocols/device_path_protocol.zig").DevicePathProtocol;
4
15pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey;
26pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData;
37pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState;
......@@ -29,6 +33,46 @@ pub const EdidActiveProtocol = @import("protocols/edid_active_protocol.zig").Edi
2933pub const EdidOverrideProtocol = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocol;
3034pub const EdidOverrideProtocolAttributes = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocolAttributes;
3135
36pub const SimpleNetworkProtocol = @import("protocols/simple_network_protocol.zig").SimpleNetworkProtocol;
37pub const MacAddress = @import("protocols/simple_network_protocol.zig").MacAddress;
38pub const SimpleNetworkMode = @import("protocols/simple_network_protocol.zig").SimpleNetworkMode;
39pub const SimpleNetworkReceiveFilter = @import("protocols/simple_network_protocol.zig").SimpleNetworkReceiveFilter;
40pub const SimpleNetworkState = @import("protocols/simple_network_protocol.zig").SimpleNetworkState;
41pub const NetworkStatistics = @import("protocols/simple_network_protocol.zig").NetworkStatistics;
42pub const SimpleNetworkInterruptStatus = @import("protocols/simple_network_protocol.zig").SimpleNetworkInterruptStatus;
43
44pub const ManagedNetworkServiceBindingProtocol = @import("protocols/managed_network_service_binding_protocol.zig").ManagedNetworkServiceBindingProtocol;
45pub const ManagedNetworkProtocol = @import("protocols/managed_network_protocol.zig").ManagedNetworkProtocol;
46pub const ManagedNetworkConfigData = @import("protocols/managed_network_protocol.zig").ManagedNetworkConfigData;
47pub const ManagedNetworkCompletionToken = @import("protocols/managed_network_protocol.zig").ManagedNetworkCompletionToken;
48pub const ManagedNetworkReceiveData = @import("protocols/managed_network_protocol.zig").ManagedNetworkReceiveData;
49pub const ManagedNetworkTransmitData = @import("protocols/managed_network_protocol.zig").ManagedNetworkTransmitData;
50pub const ManagedNetworkFragmentData = @import("protocols/managed_network_protocol.zig").ManagedNetworkFragmentData;
51
52pub const Ip6ServiceBindingProtocol = @import("protocols/ip6_service_binding_protocol.zig").Ip6ServiceBindingProtocol;
53pub const Ip6Protocol = @import("protocols/ip6_protocol.zig").Ip6Protocol;
54pub const Ip6ModeData = @import("protocols/ip6_protocol.zig").Ip6ModeData;
55pub const Ip6ConfigData = @import("protocols/ip6_protocol.zig").Ip6ConfigData;
56pub const Ip6Address = @import("protocols/ip6_protocol.zig").Ip6Address;
57pub const Ip6AddressInfo = @import("protocols/ip6_protocol.zig").Ip6AddressInfo;
58pub const Ip6RouteTable = @import("protocols/ip6_protocol.zig").Ip6RouteTable;
59pub const Ip6NeighborState = @import("protocols/ip6_protocol.zig").Ip6NeighborState;
60pub const Ip6NeighborCache = @import("protocols/ip6_protocol.zig").Ip6NeighborCache;
61pub const Ip6IcmpType = @import("protocols/ip6_protocol.zig").Ip6IcmpType;
62pub const Ip6CompletionToken = @import("protocols/ip6_protocol.zig").Ip6CompletionToken;
63
64pub const Ip6ConfigProtocol = @import("protocols/ip6_config_protocol.zig").Ip6ConfigProtocol;
65pub const Ip6ConfigDataType = @import("protocols/ip6_config_protocol.zig").Ip6ConfigDataType;
66
67pub const Udp6ServiceBindingProtocol = @import("protocols/udp6_service_binding_protocol.zig").Udp6ServiceBindingProtocol;
68pub const Udp6Protocol = @import("protocols/udp6_protocol.zig").Udp6Protocol;
69pub const Udp6ConfigData = @import("protocols/udp6_protocol.zig").Udp6ConfigData;
70pub const Udp6CompletionToken = @import("protocols/udp6_protocol.zig").Udp6CompletionToken;
71pub const Udp6ReceiveData = @import("protocols/udp6_protocol.zig").Udp6ReceiveData;
72pub const Udp6TransmitData = @import("protocols/udp6_protocol.zig").Udp6TransmitData;
73pub const Udp6SessionData = @import("protocols/udp6_protocol.zig").Udp6SessionData;
74pub const Udp6FragmentData = @import("protocols/udp6_protocol.zig").Udp6FragmentData;
75
3276pub const hii = @import("protocols/hii.zig");
3377pub const HIIDatabaseProtocol = @import("protocols/hii_database_protocol.zig").HIIDatabaseProtocol;
3478pub const HIIPopupProtocol = @import("protocols/hii_popup_protocol.zig").HIIPopupProtocol;
lib/std/os/uefi/protocols/device_path_protocol.zig created+17
......@@ -0,0 +1,17 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3
4pub const DevicePathProtocol = extern struct {
5 type: u8,
6 subtype: u8,
7 length: u16,
8
9 pub const guid align(8) = Guid{
10 .time_low = 0x09576e91,
11 .time_mid = 0x6d3f,
12 .time_high_and_version = 0x11d2,
13 .clock_seq_high_and_reserved = 0x8e,
14 .clock_seq_low = 0x39,
15 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
16 };
17};
lib/std/os/uefi/protocols/ip6_config_protocol.zig created+45
......@@ -0,0 +1,45 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Event = uefi.Event;
4
5pub const Ip6ConfigProtocol = extern struct {
6 _set_data: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, usize, *const c_void) usize,
7 _get_data: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, *usize, ?*const c_void) usize,
8 _register_data_notify: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) usize,
9 _unregister_data_notify: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) usize,
10
11 pub fn setData(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, data_size: usize, data: *const c_void) usize {
12 return self._set_data(self, data_type, data_size, data);
13 }
14
15 pub fn getData(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, data_size: *usize, data: ?*const c_void) usize {
16 return self._get_data(self, data_type, data_size, data);
17 }
18
19 pub fn registerDataNotify(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, event: Event) usize {
20 return self._register_data_notify(self, data_type, event);
21 }
22
23 pub fn unregisterDataNotify(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, event: Event) usize {
24 return self._unregister_data_notify(self, data_type, event);
25 }
26
27 pub const guid align(8) = Guid{
28 .time_low = 0x937fe521,
29 .time_mid = 0x95ae,
30 .time_high_and_version = 0x4d1a,
31 .clock_seq_high_and_reserved = 0x89,
32 .clock_seq_low = 0x29,
33 .node = [_]u8{ 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a },
34 };
35};
36
37pub const Ip6ConfigDataType = extern enum(u32) {
38 InterfaceInfo,
39 AltInterfaceId,
40 Policy,
41 DupAddrDetectTransmits,
42 ManualAddress,
43 Gateway,
44 DnsServer,
45};
lib/std/os/uefi/protocols/ip6_protocol.zig created+143
......@@ -0,0 +1,143 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Event = uefi.Event;
4const MacAddress = uefi.protocols.MacAddress;
5const ManagedNetworkConfigData = uefi.protocols.ManagedNetworkConfigData;
6const SimpleNetworkMode = uefi.protocols.SimpleNetworkMode;
7
8pub const Ip6Protocol = extern struct {
9 _get_mode_data: extern fn (*const Ip6Protocol, ?*Ip6ModeData, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) usize,
10 _configure: extern fn (*const Ip6Protocol, ?*const Ip6ConfigData) usize,
11 _groups: extern fn (*const Ip6Protocol, bool, ?*const Ip6Address) usize,
12 _routes: extern fn (*const Ip6Protocol, bool, ?*const Ip6Address, u8, ?*const Ip6Address) usize,
13 _neighbors: extern fn (*const Ip6Protocol, bool, *const Ip6Address, ?*const MacAddress, u32, bool) usize,
14 _transmit: extern fn (*const Ip6Protocol, *Ip6CompletionToken) usize,
15 _receive: extern fn (*const Ip6Protocol, *Ip6CompletionToken) usize,
16 _cancel: extern fn (*const Ip6Protocol, ?*Ip6CompletionToken) usize,
17 _poll: extern fn (*const Ip6Protocol) usize,
18
19 /// Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
20 pub fn getModeData(self: *const Ip6Protocol, ip6_mode_data: ?*Ip6ModeData, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetworkMode) usize {
21 return self._get_mode_data(self, ip6_mode_data, mnp_config_data, snp_mode_data);
22 }
23
24 /// Assign IPv6 address and other configuration parameter to this EFI IPv6 Protocol driver instance.
25 pub fn configure(self: *const Ip6Protocol, ip6_config_data: ?*const Ip6ConfigData) usize {
26 return self._configure(self, ip6_config_data);
27 }
28
29 /// Joins and leaves multicast groups.
30 pub fn groups(self: *const Ip6Protocol, join_flag: bool, group_address: ?*const Ip6Address) usize {
31 return self._groups(self, join_flag, group_address);
32 }
33
34 /// Adds and deletes routing table entries.
35 pub fn routes(self: *const Ip6Protocol, delete_route: bool, destination: ?*const Ip6Address, prefix_length: u8, gateway_address: ?*const Ip6Address) usize {
36 return self._routes(self, delete_route, destination, prefix_length, gateway_address);
37 }
38
39 /// Add or delete Neighbor cache entries.
40 pub fn neighbors(self: *const Ip6Protocol, delete_flag: bool, target_ip6_address: *const Ip6Address, target_link_address: ?*const MacAddress, timeout: u32, override: bool) usize {
41 return self._neighbors(self, delete_flag, target_ip6_address, target_link_address, timeout, override);
42 }
43
44 /// Places outgoing data packets into the transmit queue.
45 pub fn transmit(self: *const Ip6Protocol, token: *Ip6CompletionToken) usize {
46 return self._transmit(self, token);
47 }
48
49 /// Places a receiving request into the receiving queue.
50 pub fn receive(self: *const Ip6Protocol, token: *Ip6CompletionToken) usize {
51 return self._receive(self, token);
52 }
53
54 /// Abort an asynchronous transmits or receive request.
55 pub fn cancel(self: *const Ip6Protocol, token: ?*Ip6CompletionToken) usize {
56 return self._cancel(self, token);
57 }
58
59 /// Polls for incoming data packets and processes outgoing data packets.
60 pub fn poll(self: *const Ip6Protocol) usize {
61 return self._poll(self);
62 }
63
64 pub const guid align(8) = Guid{
65 .time_low = 0x2c8759d5,
66 .time_mid = 0x5c2d,
67 .time_high_and_version = 0x66ef,
68 .clock_seq_high_and_reserved = 0x92,
69 .clock_seq_low = 0x5f,
70 .node = [_]u8{ 0xb6, 0x6c, 0x10, 0x19, 0x57, 0xe2 },
71 };
72};
73
74pub const Ip6ModeData = extern struct {
75 is_started: bool,
76 max_packet_size: u32,
77 config_data: Ip6ConfigData,
78 is_configured: bool,
79 address_count: u32,
80 address_list: [*]Ip6AddressInfo,
81 group_count: u32,
82 group_table: [*]Ip6Address,
83 route_count: u32,
84 route_table: [*]Ip6RouteTable,
85 neighbor_count: u32,
86 neighbor_cache: [*]Ip6NeighborCache,
87 prefix_count: u32,
88 prefix_table: [*]Ip6AddressInfo,
89 icmp_type_count: u32,
90 icmp_type_list: [*]Ip6IcmpType,
91};
92
93pub const Ip6ConfigData = extern struct {
94 default_protocol: u8,
95 accept_any_protocol: bool,
96 accept_icmp_errors: bool,
97 accept_promiscuous: bool,
98 destination_address: Ip6Address,
99 station_address: Ip6Address,
100 traffic_class: u8,
101 hop_limit: u8,
102 flow_label: u32,
103 receive_timeout: u32,
104 transmit_timeout: u32,
105};
106
107pub const Ip6Address = [16]u8;
108
109pub const Ip6AddressInfo = extern struct {
110 address: Ip6Address,
111 prefix_length: u8,
112};
113
114pub const Ip6RouteTable = extern struct {
115 gateway: Ip6Address,
116 destination: Ip6Address,
117 prefix_length: u8,
118};
119
120pub const Ip6NeighborState = extern enum(u32) {
121 Incomplete,
122 Reachable,
123 Stale,
124 Delay,
125 Probe,
126};
127
128pub const Ip6NeighborCache = extern struct {
129 neighbor: Ip6Address,
130 link_address: MacAddress,
131 state: Ip6NeighborState,
132};
133
134pub const Ip6IcmpType = extern struct {
135 type: u8,
136 code: u8,
137};
138
139pub const Ip6CompletionToken = extern struct {
140 event: Event,
141 status: usize,
142 packet: *c_void, // union TODO
143};
lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig created+25
......@@ -0,0 +1,25 @@
1const uefi = @import("std").os.uefi;
2const Handle = uefi.Handle;
3const Guid = uefi.Guid;
4
5pub const Ip6ServiceBindingProtocol = extern struct {
6 _create_child: extern fn (*const Ip6ServiceBindingProtocol, *?Handle) usize,
7 _destroy_child: extern fn (*const Ip6ServiceBindingProtocol, Handle) usize,
8
9 pub fn createChild(self: *const Ip6ServiceBindingProtocol, handle: *?Handle) usize {
10 return self._create_child(self, handle);
11 }
12
13 pub fn destroyChild(self: *const Ip6ServiceBindingProtocol, handle: Handle) usize {
14 return self._destroy_child(self, handle);
15 }
16
17 pub const guid align(8) = Guid{
18 .time_low = 0xec835dd3,
19 .time_mid = 0xfe0f,
20 .time_high_and_version = 0x617b,
21 .clock_seq_high_and_reserved = 0xa6,
22 .clock_seq_low = 0x21,
23 .node = [_]u8{ 0xb3, 0x50, 0xc3, 0xe1, 0x33, 0x88 },
24 };
25};
lib/std/os/uefi/protocols/loaded_image_protocol.zig created+36
......@@ -0,0 +1,36 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Handle = uefi.Handle;
4const SystemTable = uefi.tables.SystemTable;
5const MemoryType = uefi.tables.MemoryType;
6const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
7
8pub const LoadedImageProtocol = extern struct {
9 revision: u32,
10 parent_handle: Handle,
11 system_table: *SystemTable,
12 device_handle: ?Handle,
13 file_path: *DevicePathProtocol,
14 reserved: *c_void,
15 load_options_size: u32,
16 load_options: *c_void,
17 image_base: [*]u8,
18 image_size: u64,
19 image_code_type: MemoryType,
20 image_data_type: MemoryType,
21 _unload: extern fn (*const LoadedImageProtocol, Handle) usize,
22
23 /// Unloads an image from memory.
24 pub fn unload(self: *const LoadedImageProtocol, handle: Handle) usize {
25 return self._unload(self, handle);
26 }
27
28 pub const guid align(8) = Guid{
29 .time_low = 0x5b1b31a1,
30 .time_mid = 0x9562,
31 .time_high_and_version = 0x11d2,
32 .clock_seq_high_and_reserved = 0x8e,
33 .clock_seq_low = 0x3f,
34 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
35 };
36};
lib/std/os/uefi/protocols/managed_network_protocol.zig created+126
......@@ -0,0 +1,126 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Event = uefi.Event;
4const Time = uefi.Time;
5const SimpleNetworkMode = uefi.protocols.SimpleNetworkMode;
6const MacAddress = uefi.protocols.MacAddress;
7
8pub const ManagedNetworkProtocol = extern struct {
9 _get_mode_data: extern fn (*const ManagedNetworkProtocol, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) usize,
10 _configure: extern fn (*const ManagedNetworkProtocol, ?*const ManagedNetworkConfigData) usize,
11 _mcast_ip_to_mac: extern fn (*const ManagedNetworkProtocol, bool, *const c_void, *MacAddress) usize,
12 _groups: extern fn (*const ManagedNetworkProtocol, bool, ?*const MacAddress) usize,
13 _transmit: extern fn (*const ManagedNetworkProtocol, *const ManagedNetworkCompletionToken) usize,
14 _receive: extern fn (*const ManagedNetworkProtocol, *const ManagedNetworkCompletionToken) usize,
15 _cancel: extern fn (*const ManagedNetworkProtocol, ?*const ManagedNetworkCompletionToken) usize,
16 _poll: extern fn (*const ManagedNetworkProtocol) usize,
17
18 /// Returns the operational parameters for the current MNP child driver.
19 /// May also support returning the underlying SNP driver mode data.
20 pub fn getModeData(self: *const ManagedNetworkProtocol, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetworkMode) usize {
21 return self._get_mode_data(self, mnp_config_data, snp_mode_data);
22 }
23
24 /// Sets or clears the operational parameters for the MNP child driver.
25 pub fn configure(self: *const ManagedNetworkProtocol, mnp_config_data: ?*const ManagedNetworkConfigData) usize {
26 return self._configure(self, mnp_config_data);
27 }
28
29 /// Translates an IP multicast address to a hardware (MAC) multicast address.
30 /// This function may be unsupported in some MNP implementations.
31 pub fn mcastIpToMac(self: *const ManagedNetworkProtocol, ipv6flag: bool, ipaddress: *const c_void, mac_address: *MacAddress) usize {
32 return self._mcast_ip_to_mac(self, ipv6flag, ipaddress);
33 }
34
35 /// Enables and disables receive filters for multicast address.
36 /// This function may be unsupported in some MNP implementations.
37 pub fn groups(self: *const ManagedNetworkProtocol, join_flag: bool, mac_address: ?*const MacAddress) usiz {
38 return self._groups(self, join_flag, mac_address);
39 }
40
41 /// Places asynchronous outgoing data packets into the transmit queue.
42 pub fn transmit(self: *const ManagedNetworkProtocol, token: *const ManagedNetworkCompletionToken) usize {
43 return self._transmit(self, token);
44 }
45
46 /// Places an asynchronous receiving request into the receiving queue.
47 pub fn receive(self: *const ManagedNetworkProtocol, token: *const ManagedNetworkCompletionToken) usize {
48 return self._receive(self, token);
49 }
50
51 /// Aborts an asynchronous transmit or receive request.
52 pub fn cancel(self: *const ManagedNetworkProtocol, token: ?*const ManagedNetworkCompletionToken) usize {
53 return self._cancel(self, token);
54 }
55
56 /// Polls for incoming data packets and processes outgoing data packets.
57 pub fn poll(self: *const ManagedNetworkProtocol) usize {
58 return self._poll(self);
59 }
60
61 pub const guid align(8) = Guid{
62 .time_low = 0x7ab33a91,
63 .time_mid = 0xace5,
64 .time_high_and_version = 0x4326,
65 .clock_seq_high_and_reserved = 0xb5,
66 .clock_seq_low = 0x72,
67 .node = [_]u8{ 0xe7, 0xee, 0x33, 0xd3, 0x9f, 0x16 },
68 };
69};
70
71pub const ManagedNetworkConfigData = extern struct {
72 received_queue_timeout_value: u32,
73 transmit_queue_timeout_value: u32,
74 protocol_type_filter: u16,
75 enable_unicast_receive: bool,
76 enable_multicast_receive: bool,
77 enable_broadcast_receive: bool,
78 enable_promiscuous_receive: bool,
79 flush_queues_on_reset: bool,
80 enable_receive_timestamps: bool,
81 disable_background_polling: bool,
82};
83
84pub const ManagedNetworkCompletionToken = extern struct {
85 event: Event,
86 status: usize,
87 packet: extern union {
88 RxData: *ManagedNetworkReceiveData,
89 TxData: *ManagedNetworkTransmitData,
90 },
91};
92
93pub const ManagedNetworkReceiveData = extern struct {
94 timestamp: Time,
95 recycle_event: Event,
96 packet_length: u32,
97 header_length: u32,
98 address_length: u32,
99 data_length: u32,
100 broadcast_flag: bool,
101 multicast_flag: bool,
102 promiscuous_flag: bool,
103 protocol_type: u16,
104 destination_address: [*]u8,
105 source_address: [*]u8,
106 media_header: [*]u8,
107 packet_data: [*]u8,
108};
109
110pub const ManagedNetworkTransmitData = extern struct {
111 destination_address: ?*MacAddress,
112 source_address: ?*MacAddress,
113 protocol_type: u16,
114 data_length: u32,
115 header_length: u16,
116 fragment_count: u16,
117
118 pub fn getFragments(self: *ManagedNetworkTransmitData) []ManagedNetworkFragmentData {
119 return @ptrCast([*]ManagedNetworkFragmentData, @ptrCast([*]u8, self) + @sizeOf(ManagedNetworkTransmitData))[0..self.fragment_count];
120 }
121};
122
123pub const ManagedNetworkFragmentData = extern struct {
124 fragment_length: u32,
125 fragment_buffer: [*]u8,
126};
lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig created+25
......@@ -0,0 +1,25 @@
1const uefi = @import("std").os.uefi;
2const Handle = uefi.Handle;
3const Guid = uefi.Guid;
4
5pub const ManagedNetworkServiceBindingProtocol = extern struct {
6 _create_child: extern fn (*const ManagedNetworkServiceBindingProtocol, *?Handle) usize,
7 _destroy_child: extern fn (*const ManagedNetworkServiceBindingProtocol, Handle) usize,
8
9 pub fn createChild(self: *const ManagedNetworkServiceBindingProtocol, handle: *?Handle) usize {
10 return self._create_child(self, handle);
11 }
12
13 pub fn destroyChild(self: *const ManagedNetworkServiceBindingProtocol, handle: Handle) usize {
14 return self._destroy_child(self, handle);
15 }
16
17 pub const guid align(8) = Guid{
18 .time_low = 0xf36ff770,
19 .time_mid = 0xa7e1,
20 .time_high_and_version = 0x42cf,
21 .clock_seq_high_and_reserved = 0x9e,
22 .clock_seq_low = 0xd2,
23 .node = [_]u8{ 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c },
24 };
25};
lib/std/os/uefi/protocols/simple_network_protocol.zig created+172
......@@ -0,0 +1,172 @@
1const uefi = @import("std").os.uefi;
2const Event = uefi.Event;
3const Guid = uefi.Guid;
4
5pub const SimpleNetworkProtocol = extern struct {
6 revision: u64,
7 _start: extern fn (*const SimpleNetworkProtocol) usize,
8 _stop: extern fn (*const SimpleNetworkProtocol) usize,
9 _initialize: extern fn (*const SimpleNetworkProtocol, usize, usize) usize,
10 _reset: extern fn (*const SimpleNetworkProtocol, bool) usize,
11 _shutdown: extern fn (*const SimpleNetworkProtocol) usize,
12 _receive_filters: extern fn (*const SimpleNetworkProtocol, SimpleNetworkReceiveFilter, SimpleNetworkReceiveFilter, bool, usize, ?[*]const MacAddress) usize,
13 _station_address: extern fn (*const SimpleNetworkProtocol, bool, ?*const MacAddress) usize,
14 _statistics: extern fn (*const SimpleNetworkProtocol, bool, ?*usize, ?*NetworkStatistics) usize,
15 _mcast_ip_to_mac: extern fn (*const SimpleNetworkProtocol, bool, *const c_void, *MacAddress) usize,
16 _nvdata: extern fn (*const SimpleNetworkProtocol, bool, usize, usize, [*]u8) usize,
17 _get_status: extern fn (*const SimpleNetworkProtocol, *SimpleNetworkInterruptStatus, ?*?[*]u8) usize,
18 _transmit: extern fn (*const SimpleNetworkProtocol, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) usize,
19 _receive: extern fn (*const SimpleNetworkProtocol, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) usize,
20 wait_for_packet: Event,
21 mode: *SimpleNetworkMode,
22
23 /// Changes the state of a network interface from "stopped" to "started".
24 pub fn start(self: *const SimpleNetworkProtocol) usize {
25 return self._start(self);
26 }
27
28 /// Changes the state of a network interface from "started" to "stopped".
29 pub fn stop(self: *const SimpleNetworkProtocol) usize {
30 return self._stop(self);
31 }
32
33 /// Resets a network adapter and allocates the transmit and receive buffers required by the network interface.
34 pub fn initialize(self: *const SimpleNetworkProtocol, extra_rx_buffer_size: usize, extra_tx_buffer_size: usize) usize {
35 return self._initialize(self, extra_rx_buffer_size, extra_tx_buffer_size);
36 }
37
38 /// Resets a network adapter and reinitializes it with the parameters that were provided in the previous call to initialize().
39 pub fn reset(self: *const SimpleNetworkProtocol, extended_verification: bool) usize {
40 return self._reset(self, extended_verification);
41 }
42
43 /// Resets a network adapter and leaves it in a state that is safe for another driver to initialize.
44 pub fn shutdown(self: *const SimpleNetworkProtocol) usize {
45 return self._shutdown(self);
46 }
47
48 /// Manages the multicast receive filters of a network interface.
49 pub fn receiveFilters(self: *const SimpleNetworkProtocol, enable: SimpleNetworkReceiveFilter, disable: SimpleNetworkReceiveFilter, reset_mcast_filter: bool, mcast_filter_cnt: usize, mcast_filter: ?[*]const MacAddress) usize {
50 return self._receive_filters(self, enable, disable, reset_mcast_filter, mcast_filter_cnt, mcast_filter);
51 }
52
53 /// Modifies or resets the current station address, if supported.
54 pub fn stationAddress(self: *const SimpleNetworkProtocol, reset: bool, new: ?*const MacAddress) usize {
55 return self._station_address(self, reset, new);
56 }
57
58 /// Resets or collects the statistics on a network interface.
59 pub fn statistics(self: *const SimpleNetworkProtocol, reset_: bool, statistics_size: ?*usize, statistics_table: ?*NetworkStatistics) usize {
60 return self._statistics(self, reset_, statistics_size, statistics_table);
61 }
62
63 /// Converts a multicast IP address to a multicast HW MAC address.
64 pub fn mcastIpToMac(self: *const SimpleNetworkProtocol, ipv6: bool, ip: *const c_void, mac: *MacAddress) usize {
65 return self._mcast_ip_to_mac(self, ipv6, ip, mac);
66 }
67
68 /// Performs read and write operations on the NVRAM device attached to a network interface.
69 pub fn nvdata(self: *const SimpleNetworkProtocol, read_write: bool, offset: usize, buffer_size: usize, buffer: [*]u8) usize {
70 return self._nvdata(self, read_write, offset, buffer_size, buffer);
71 }
72
73 /// Reads the current interrupt status and recycled transmit buffer status from a network interface.
74 pub fn getStatus(self: *const SimpleNetworkProtocol, interrupt_status: *SimpleNetworkInterruptStatus, tx_buf: ?*?[*]u8) usize {
75 return self._get_status(self, interrupt_status, tx_buf);
76 }
77
78 /// Places a packet in the transmit queue of a network interface.
79 pub fn transmit(self: *const SimpleNetworkProtocol, header_size: usize, buffer_size: usize, buffer: [*]const u8, src_addr: ?*const MacAddress, dest_addr: ?*const MacAddress, protocol: ?*const u16) usize {
80 return self._transmit(self, header_size, buffer_size, buffer, src_addr, dest_addr, protocol);
81 }
82
83 /// Receives a packet from a network interface.
84 pub fn receive(self: *const SimpleNetworkProtocol, header_size: ?*usize, buffer_size: *usize, buffer: [*]u8, src_addr: ?*MacAddress, dest_addr: ?*MacAddress, protocol: ?*u16) usize {
85 return self._receive(self, header_size, buffer_size, buffer, src_addr, dest_addr, protocol);
86 }
87
88 pub const guid align(8) = Guid{
89 .time_low = 0xa19832b9,
90 .time_mid = 0xac25,
91 .time_high_and_version = 0x11d3,
92 .clock_seq_high_and_reserved = 0x9a,
93 .clock_seq_low = 0x2d,
94 .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d },
95 };
96};
97
98pub const MacAddress = [32]u8;
99
100pub const SimpleNetworkMode = extern struct {
101 state: SimpleNetworkState,
102 hw_address_size: u32,
103 media_header_size: u32,
104 max_packet_size: u32,
105 nvram_size: u32,
106 nvram_access_size: u32,
107 receive_filter_mask: SimpleNetworkReceiveFilter,
108 receive_filter_setting: SimpleNetworkReceiveFilter,
109 max_mcast_filter_count: u32,
110 mcast_filter_count: u32,
111 mcast_filter: [16]MacAddress,
112 current_address: MacAddress,
113 broadcast_address: MacAddress,
114 permanent_address: MacAddress,
115 if_type: u8,
116 mac_address_changeable: bool,
117 multiple_tx_supported: bool,
118 media_present_supported: bool,
119 media_present: bool,
120};
121
122pub const SimpleNetworkReceiveFilter = packed struct {
123 receive_unicast: bool,
124 receive_multicast: bool,
125 receive_broadcast: bool,
126 receive_promiscuous: bool,
127 receive_promiscuous_multicast: bool,
128 _pad: u27 = undefined,
129};
130
131pub const SimpleNetworkState = extern enum(u32) {
132 Stopped,
133 Started,
134 Initialized,
135};
136
137pub const NetworkStatistics = extern struct {
138 rx_total_frames: u64,
139 rx_good_frames: u64,
140 rx_undersize_frames: u64,
141 rx_oversize_frames: u64,
142 rx_dropped_frames: u64,
143 rx_unicast_frames: u64,
144 rx_broadcast_frames: u64,
145 rx_multicast_frames: u64,
146 rx_crc_error_frames: u64,
147 rx_total_bytes: u64,
148 tx_total_frames: u64,
149 tx_good_frames: u64,
150 tx_undersize_frames: u64,
151 tx_oversize_frames: u64,
152 tx_dropped_frames: u64,
153 tx_unicast_frames: u64,
154 tx_broadcast_frames: u64,
155 tx_multicast_frames: u64,
156 tx_crc_error_frames: u64,
157 tx_total_bytes: u64,
158 collisions: u64,
159 unsupported_protocol: u64,
160 rx_duplicated_frames: u64,
161 rx_decryptError_frames: u64,
162 tx_error_frames: u64,
163 tx_retry_frames: u64,
164};
165
166pub const SimpleNetworkInterruptStatus = packed struct {
167 receive_interrupt: bool,
168 transmit_interrupt: bool,
169 command_interrupt: bool,
170 software_interrupt: bool,
171 _pad: u28,
172};
lib/std/os/uefi/protocols/udp6_protocol.zig created+112
......@@ -0,0 +1,112 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Event = uefi.Event;
4const Time = uefi.Time;
5const Ip6ModeData = uefi.protocols.Ip6ModeData;
6const Ip6Address = uefi.protocols.Ip6Address;
7const ManagedNetworkConfigData = uefi.protocols.ManagedNetworkConfigData;
8const SimpleNetworkMode = uefi.protocols.SimpleNetworkMode;
9
10pub const Udp6Protocol = extern struct {
11 _get_mode_data: extern fn (*const Udp6Protocol, ?*Udp6ConfigData, ?*Ip6ModeData, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) usize,
12 _configure: extern fn (*const Udp6Protocol, ?*const Udp6ConfigData) usize,
13 _groups: extern fn (*const Udp6Protocol, bool, ?*const Ip6Address) usize,
14 _transmit: extern fn (*const Udp6Protocol, *Udp6CompletionToken) usize,
15 _receive: extern fn (*const Udp6Protocol, *Udp6CompletionToken) usize,
16 _cancel: extern fn (*const Udp6Protocol, ?*Udp6CompletionToken) usize,
17 _poll: extern fn (*const Udp6Protocol) usize,
18
19 pub fn getModeData(self: *const Udp6Protocol, udp6_config_data: ?*Udp6ConfigData, ip6_mode_data: ?*Ip6ModeData, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetworkMode) usize {
20 return self._get_mode_data(self, udp6_config_data, ip6_mode_data, mnp_config_data, snp_mode_data);
21 }
22
23 pub fn configure(self: *const Udp6Protocol, udp6_config_data: ?*const Udp6ConfigData) usize {
24 return self._configure(self, udp6_config_data);
25 }
26
27 pub fn groups(self: *const Udp6Protocol, join_flag: bool, multicast_address: ?*const Ip6Address) usize {
28 return self._groups(self, join_flag, multicast_address);
29 }
30
31 pub fn transmit(self: *const Udp6Protocol, token: *Udp6CompletionToken) usize {
32 return self._transmit(self, token);
33 }
34
35 pub fn receive(self: *const Udp6Protocol, token: *Udp6CompletionToken) usize {
36 return self._receive(self, token);
37 }
38
39 pub fn cancel(self: *const Udp6Protocol, token: ?*Udp6CompletionToken) usize {
40 return self._cancel(self, token);
41 }
42
43 pub fn poll(self: *const Udp6Protocol) usize {
44 return self._poll(self);
45 }
46
47 pub const guid align(8) = uefi.Guid{
48 .time_low = 0x4f948815,
49 .time_mid = 0xb4b9,
50 .time_high_and_version = 0x43cb,
51 .clock_seq_high_and_reserved = 0x8a,
52 .clock_seq_low = 0x33,
53 .node = [_]u8{ 0x90, 0xe0, 0x60, 0xb3, 0x49, 0x55 },
54 };
55};
56
57pub const Udp6ConfigData = extern struct {
58 accept_promiscuous: bool,
59 accept_any_port: bool,
60 allow_duplicate_port: bool,
61 traffic_class: u8,
62 hop_limit: u8,
63 receive_timeout: u32,
64 transmit_timeout: u32,
65 station_address: Ip6Address,
66 station_port: u16,
67 remote_address: Ip6Address,
68 remote_port: u16,
69};
70
71pub const Udp6CompletionToken = extern struct {
72 event: Event,
73 status: usize,
74 packet: extern union {
75 RxData: *Udp6ReceiveData,
76 TxData: *Udp6TransmitData,
77 },
78};
79
80pub const Udp6ReceiveData = extern struct {
81 timestamp: Time,
82 recycle_signal: Event,
83 udp6_session: Udp6SessionData,
84 data_length: u32,
85 fragment_count: u32,
86
87 pub fn getFragments(self: *Udp6ReceiveData) []Udp6FragmentData {
88 return @ptrCast([*]Udp6FragmentData, @ptrCast([*]u8, self) + @sizeOf(Udp6ReceiveData))[0..self.fragment_count];
89 }
90};
91
92pub const Udp6TransmitData = extern struct {
93 udp6_session_data: ?*Udp6SessionData,
94 data_length: u32,
95 fragment_count: u32,
96
97 pub fn getFragments(self: *Udp6TransmitData) []Udp6FragmentData {
98 return @ptrCast([*]Udp6FragmentData, @ptrCast([*]u8, self) + @sizeOf(Udp6TransmitData))[0..self.fragment_count];
99 }
100};
101
102pub const Udp6SessionData = extern struct {
103 source_address: Ip6Address,
104 source_port: u16,
105 destination_address: Ip6Address,
106 destination_port: u16,
107};
108
109pub const Udp6FragmentData = extern struct {
110 fragment_length: u32,
111 fragment_buffer: [*]u8,
112};
lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig created+25
......@@ -0,0 +1,25 @@
1const uefi = @import("std").os.uefi;
2const Handle = uefi.Handle;
3const Guid = uefi.Guid;
4
5pub const Udp6ServiceBindingProtocol = extern struct {
6 _create_child: extern fn (*const Udp6ServiceBindingProtocol, *?Handle) usize,
7 _destroy_child: extern fn (*const Udp6ServiceBindingProtocol, Handle) usize,
8
9 pub fn createChild(self: *const Udp6ServiceBindingProtocol, handle: *?Handle) usize {
10 return self._create_child(self, handle);
11 }
12
13 pub fn destroyChild(self: *const Udp6ServiceBindingProtocol, handle: Handle) usize {
14 return self._destroy_child(self, handle);
15 }
16
17 pub const guid align(8) = Guid{
18 .time_low = 0x66ed4721,
19 .time_mid = 0x3c98,
20 .time_high_and_version = 0x4d3e,
21 .clock_seq_high_and_reserved = 0x81,
22 .clock_seq_low = 0xe3,
23 .node = [_]u8{ 0xd0, 0x3d, 0xd3, 0x9a, 0x72, 0x54 },
24 };
25};
lib/std/os/uefi/tables.zig+3
......@@ -1,8 +1,11 @@
11pub const BootServices = @import("tables/boot_services.zig").BootServices;
22pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable;
33pub const global_variable align(8) = @import("tables/runtime_services.zig").global_variable;
4pub const LocateSearchType = @import("tables/boot_services.zig").LocateSearchType;
45pub const MemoryDescriptor = @import("tables/boot_services.zig").MemoryDescriptor;
56pub const MemoryType = @import("tables/boot_services.zig").MemoryType;
7pub const OpenProtocolAttributes = @import("tables/boot_services.zig").OpenProtocolAttributes;
8pub const ProtocolInformationEntry = @import("tables/boot_services.zig").ProtocolInformationEntry;
69pub const ResetType = @import("tables/runtime_services.zig").ResetType;
710pub const RuntimeServices = @import("tables/runtime_services.zig").RuntimeServices;
811pub const SystemTable = @import("tables/system_table.zig").SystemTable;
lib/std/os/uefi/tables/boot_services.zig+75-11
......@@ -3,6 +3,7 @@ const Event = uefi.Event;
33const Guid = uefi.Guid;
44const Handle = uefi.Handle;
55const TableHeader = uefi.tables.TableHeader;
6const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
67
78/// Boot services are services provided by the system's firmware until the operating system takes
89/// over control over the hardware by calling exitBootServices.
......@@ -17,56 +18,96 @@ const TableHeader = uefi.tables.TableHeader;
1718/// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size.
1819pub const BootServices = extern struct {
1920 hdr: TableHeader,
21
2022 raiseTpl: usize, // TODO
2123 restoreTpl: usize, // TODO
2224 allocatePages: usize, // TODO
2325 freePages: usize, // TODO
26
2427 /// Returns the current memory map.
2528 getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize,
29
2630 /// Allocates pool memory.
2731 allocatePool: extern fn (MemoryType, usize, *align(8) [*]u8) usize,
28 freePool: usize, // TODO
32
33 /// Returns pool memory to the system.
34 freePool: extern fn ([*]align(8) u8) usize,
35
2936 /// Creates an event.
30 createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize,
37 createEvent: extern fn (u32, usize, ?extern fn (Event, ?*c_void) void, ?*const c_void, *Event) usize,
38
3139 /// Sets the type of timer and the trigger time for a timer event.
3240 setTimer: extern fn (Event, TimerDelay, u64) usize,
41
3342 /// Stops execution until an event is signaled.
3443 waitForEvent: extern fn (usize, [*]const Event, *usize) usize,
44
3545 /// Signals an event.
3646 signalEvent: extern fn (Event) usize,
47
3748 /// Closes an event.
3849 closeEvent: extern fn (Event) usize,
39 checkEvent: usize, // TODO
50
51 /// Checks whether an event is in the signaled state.
52 checkEvent: extern fn (Event) usize,
53
4054 installProtocolInterface: usize, // TODO
4155 reinstallProtocolInterface: usize, // TODO
4256 uninstallProtocolInterface: usize, // TODO
43 handleProtocol: usize, // TODO
57
58 /// Queries a handle to determine if it supports a specified protocol.
59 handleProtocol: extern fn (Handle, *align(8) const Guid, *?*c_void) usize,
60
4461 reserved: *c_void,
62
4563 registerProtocolNotify: usize, // TODO
4664 locateHandle: usize, // TODO
4765 locateDevicePath: usize, // TODO
4866 installConfigurationTable: usize, // TODO
49 imageLoad: usize, // TODO
50 imageStart: usize, // TODO
67
68 /// Loads an EFI image into memory.
69 loadImage: extern fn (bool, Handle, ?*const DevicePathProtocol, ?[*]const u8, usize, *?Handle) usize,
70
71 /// Transfers control to a loaded image's entry point.
72 startImage: extern fn (Handle, ?*usize, ?*[*]u16) usize,
73
5174 /// Terminates a loaded EFI image and returns control to boot services.
5275 exit: extern fn (Handle, usize, usize, ?*const c_void) usize,
53 imageUnload: usize, // TODO
76
77 /// Unloads an image.
78 unloadImage: extern fn (Handle) usize,
79
5480 /// Terminates all boot services.
5581 exitBootServices: extern fn (Handle, usize) usize,
82
5683 getNextMonotonicCount: usize, // TODO
84
5785 /// Induces a fine-grained stall.
5886 stall: extern fn (usize) usize,
87
5988 /// Sets the system's watchdog timer.
6089 setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize,
90
6191 connectController: usize, // TODO
6292 disconnectController: usize, // TODO
63 openProtocol: usize, // TODO
64 closeProtocol: usize, // TODO
65 openProtocolInformation: usize, // TODO
93
94 /// Queries a handle to determine if it supports a specified protocol.
95 openProtocol: extern fn (Handle, *align(8) const Guid, *?*c_void, ?Handle, ?Handle, OpenProtocolAttributes) usize,
96
97 /// Closes a protocol on a handle that was opened using openProtocol().
98 closeProtocol: extern fn (Handle, *align(8) const Guid, Handle, ?Handle) usize,
99
100 /// Retrieves the list of agents that currently have a protocol interface opened.
101 openProtocolInformation: extern fn (Handle, *align(8) const Guid, *[*]ProtocolInformationEntry, *usize) usize,
102
66103 protocolsPerHandle: usize, // TODO
67 locateHandleBuffer: usize, // TODO
104
105 /// Returns an array of handles that support the requested protocol in a buffer allocated from pool.
106 locateHandleBuffer: extern fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, *[*]Handle) usize,
107
68108 /// Returns the first protocol instance that matches the given protocol.
69109 locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize,
110
70111 installMultipleProtocolInterfaces: usize, // TODO
71112 uninstallMultipleProtocolInterfaces: usize, // TODO
72113 calculateCrc32: usize, // TODO
......@@ -138,3 +179,26 @@ pub const MemoryDescriptor = extern struct {
138179 memory_runtime: bool,
139180 },
140181};
182
183pub const LocateSearchType = extern enum(u32) {
184 AllHandles,
185 ByRegisterNotify,
186 ByProtocol,
187};
188
189pub const OpenProtocolAttributes = packed struct {
190 by_handle_protocol: bool,
191 get_protocol: bool,
192 test_protocol: bool,
193 by_child_controller: bool,
194 by_driver: bool,
195 exclusive: bool,
196 _pad: u26,
197};
198
199pub const ProtocolInformationEntry = extern struct {
200 agent_handle: ?Handle,
201 controller_handle: ?Handle,
202 attributes: OpenProtocolAttributes,
203 open_count: u32,
204};
lib/std/os/uefi/tables/runtime_services.zig+8
......@@ -14,22 +14,30 @@ const TimeCapabilities = uefi.TimeCapabilities;
1414/// Some functions may not be called while other functions are running.
1515pub const RuntimeServices = extern struct {
1616 hdr: TableHeader,
17
1718 /// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.
1819 getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize,
20
1921 setTime: usize, // TODO
2022 getWakeupTime: usize, // TODO
2123 setWakeupTime: usize, // TODO
2224 setVirtualAddressMap: usize, // TODO
2325 convertPointer: usize, // TODO
26
2427 /// Returns the value of a variable.
2528 getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
29
2630 /// Enumerates the current variable names.
2731 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
32
2833 /// Sets the value of a variable.
2934 setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
35
3036 getNextHighMonotonicCount: usize, // TODO
37
3138 /// Resets the entire platform.
3239 resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn,
40
3341 updateCapsule: usize, // TODO
3442 queryCapsuleCapabilities: usize, // TODO
3543 queryVariableInfo: usize, // TODO
lib/std/os/uefi/tables/system_table.zig+1
......@@ -17,6 +17,7 @@ const TableHeader = uefi.tables.TableHeader;
1717/// hdr.crc32 must be recomputed.
1818pub const SystemTable = extern struct {
1919 hdr: TableHeader,
20
2021 /// A null-terminated string that identifies the vendor that produces the system firmware of the platform.
2122 firmware_vendor: [*]u16,
2223 firmware_revision: u32,
lib/std/os/windows.zig+129-3
......@@ -16,6 +16,7 @@ pub const kernel32 = @import("windows/kernel32.zig");
1616pub const ntdll = @import("windows/ntdll.zig");
1717pub const ole32 = @import("windows/ole32.zig");
1818pub const shell32 = @import("windows/shell32.zig");
19pub const ws2_32 = @import("windows/ws2_32.zig");
1920
2021pub usingnamespace @import("windows/bits.zig");
2122
......@@ -96,6 +97,42 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C
9697 }
9798}
9899
100pub fn DeviceIoControl(
101 h: HANDLE,
102 ioControlCode: DWORD,
103 in: ?[]const u8,
104 out: ?[]u8,
105 overlapped: ?*OVERLAPPED,
106) !DWORD {
107 var bytes: DWORD = undefined;
108 if (kernel32.DeviceIoControl(
109 h,
110 ioControlCode,
111 if (in) |i| i.ptr else null,
112 if (in) |i| @intCast(u32, i.len) else 0,
113 if (out) |o| o.ptr else null,
114 if (out) |o| @intCast(u32, o.len) else 0,
115 &bytes,
116 overlapped,
117 ) == 0) {
118 switch (kernel32.GetLastError()) {
119 else => |err| return unexpectedError(err),
120 }
121 }
122 return bytes;
123}
124
125pub fn GetOverlappedResult(h: HANDLE, overlapped: *OVERLAPPED, wait: bool) !DWORD {
126 var bytes: DWORD = undefined;
127 if (kernel32.GetOverlappedResult(h, overlapped, &bytes, wait) == 0) {
128 switch (kernel32.GetLastError()) {
129 ERROR_IO_INCOMPLETE => if (!wait) return error.WouldBlock else unreachable,
130 else => |err| return unexpectedError(err),
131 }
132 }
133 return bytes;
134}
135
99136pub const SetHandleInformationError = error{Unexpected};
100137
101138pub fn SetHandleInformation(h: HANDLE, mask: DWORD, flags: DWORD) SetHandleInformationError!void {
......@@ -262,7 +299,7 @@ pub const ReadFileError = error{Unexpected};
262299pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {
263300 var index: usize = 0;
264301 while (index < buffer.len) {
265 const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));
302 const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len - index));
266303 var amt_read: DWORD = undefined;
267304 if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
268305 switch (kernel32.GetLastError()) {
......@@ -571,6 +608,74 @@ pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD
571608 return rc;
572609}
573610
611pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA {
612 var wsadata: ws2_32.WSADATA = undefined;
613 return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) {
614 0 => wsadata,
615 else => |err| unexpectedWSAError(err),
616 };
617}
618
619pub fn WSACleanup() !void {
620 return switch (ws2_32.WSACleanup()) {
621 0 => {},
622 ws2_32.SOCKET_ERROR => switch (ws2_32.WSAGetLastError()) {
623 else => |err| return unexpectedWSAError(err),
624 },
625 else => unreachable,
626 };
627}
628
629pub fn WSASocketW(
630 af: i32,
631 socket_type: i32,
632 protocol: i32,
633 protocolInfo: ?*ws2_32.WSAPROTOCOL_INFOW,
634 g: ws2_32.GROUP,
635 dwFlags: DWORD,
636) !ws2_32.SOCKET {
637 const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags);
638 if (rc == ws2_32.INVALID_SOCKET) {
639 switch (ws2_32.WSAGetLastError()) {
640 ws2_32.WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
641 ws2_32.WSAEMFILE => return error.ProcessFdQuotaExceeded,
642 ws2_32.WSAENOBUFS => return error.SystemResources,
643 ws2_32.WSAEPROTONOSUPPORT => return error.ProtocolNotSupported,
644 else => |err| return unexpectedWSAError(err),
645 }
646 }
647 return rc;
648}
649
650pub fn WSAIoctl(
651 s: ws2_32.SOCKET,
652 dwIoControlCode: DWORD,
653 inBuffer: ?[]const u8,
654 outBuffer: []u8,
655 overlapped: ?*ws2_32.WSAOVERLAPPED,
656 completionRoutine: ?*ws2_32.WSAOVERLAPPED_COMPLETION_ROUTINE,
657) !DWORD {
658 var bytes: DWORD = undefined;
659 switch (ws2_32.WSAIoctl(
660 s,
661 dwIoControlCode,
662 if (inBuffer) |i| i.ptr else null,
663 if (inBuffer) |i| @intCast(DWORD, i.len) else 0,
664 outBuffer.ptr,
665 @intCast(DWORD, outBuffer.len),
666 &bytes,
667 overlapped,
668 completionRoutine,
669 )) {
670 0 => {},
671 ws2_32.SOCKET_ERROR => switch (ws2_32.WSAGetLastError()) {
672 else => |err| return unexpectedWSAError(err),
673 },
674 else => unreachable,
675 }
676 return bytes;
677}
678
574679const GetModuleFileNameError = error{Unexpected};
575680
576681pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 {
......@@ -801,7 +906,7 @@ pub fn toSysTime(ns: i64) i64 {
801906}
802907
803908pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 {
804 const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime);
909 const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime);
805910 return fromSysTime(hns);
806911}
807912
......@@ -822,6 +927,24 @@ pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE + 1]u16 {
822927 return sliceToPrefixedSuffixedFileW(s, [_]u16{0});
823928}
824929
930/// Assumes an absolute path.
931pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE + 1]u16 {
932 // TODO https://github.com/ziglang/zig/issues/2765
933 var result: [PATH_MAX_WIDE + 1]u16 = undefined;
934
935 const start_index = if (mem.startsWith(u16, s, [_]u16{'\\', '?'})) 0 else blk: {
936 const prefix = [_]u16{ '\\', '?', '?', '\\' };
937 mem.copy(u16, result[0..], prefix);
938 break :blk prefix.len;
939 };
940 const end_index = start_index + s.len;
941 if (end_index + 1 > result.len) return error.NameTooLong;
942 mem.copy(u16, result[start_index..], s);
943 result[end_index] = 0;
944 return result;
945
946}
947
825948pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len]u16 {
826949 // TODO https://github.com/ziglang/zig/issues/2765
827950 var result: [PATH_MAX_WIDE + suffix.len]u16 = undefined;
......@@ -843,7 +966,6 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
843966 break :blk prefix.len;
844967 };
845968 const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s);
846 assert(end_index <= result.len);
847969 if (end_index + suffix.len > result.len) return error.NameTooLong;
848970 mem.copy(u16, result[end_index..], suffix);
849971 return result;
......@@ -868,6 +990,10 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
868990 return error.Unexpected;
869991}
870992
993pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {
994 return unexpectedError(@intCast(DWORD, err));
995}
996
871997/// Call this when you made a windows NtDll call
872998/// and you get an unexpected status.
873999pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
lib/std/os/windows/bits.zig+119-12
......@@ -67,9 +67,116 @@ pub const va_list = *@OpaqueType();
6767pub const TRUE = 1;
6868pub const FALSE = 0;
6969
70pub const DEVICE_TYPE = ULONG;
71pub const FILE_DEVICE_BEEP: DEVICE_TYPE = 0x0001;
72pub const FILE_DEVICE_CD_ROM: DEVICE_TYPE = 0x0002;
73pub const FILE_DEVICE_CD_ROM_FILE_SYSTEM: DEVICE_TYPE = 0x0003;
74pub const FILE_DEVICE_CONTROLLER: DEVICE_TYPE = 0x0004;
75pub const FILE_DEVICE_DATALINK: DEVICE_TYPE = 0x0005;
76pub const FILE_DEVICE_DFS: DEVICE_TYPE = 0x0006;
77pub const FILE_DEVICE_DISK: DEVICE_TYPE = 0x0007;
78pub const FILE_DEVICE_DISK_FILE_SYSTEM: DEVICE_TYPE = 0x0008;
79pub const FILE_DEVICE_FILE_SYSTEM: DEVICE_TYPE = 0x0009;
80pub const FILE_DEVICE_INPORT_PORT: DEVICE_TYPE = 0x000a;
81pub const FILE_DEVICE_KEYBOARD: DEVICE_TYPE = 0x000b;
82pub const FILE_DEVICE_MAILSLOT: DEVICE_TYPE = 0x000c;
83pub const FILE_DEVICE_MIDI_IN: DEVICE_TYPE = 0x000d;
84pub const FILE_DEVICE_MIDI_OUT: DEVICE_TYPE = 0x000e;
85pub const FILE_DEVICE_MOUSE: DEVICE_TYPE = 0x000f;
86pub const FILE_DEVICE_MULTI_UNC_PROVIDER: DEVICE_TYPE = 0x0010;
87pub const FILE_DEVICE_NAMED_PIPE: DEVICE_TYPE = 0x0011;
88pub const FILE_DEVICE_NETWORK: DEVICE_TYPE = 0x0012;
89pub const FILE_DEVICE_NETWORK_BROWSER: DEVICE_TYPE = 0x0013;
90pub const FILE_DEVICE_NETWORK_FILE_SYSTEM: DEVICE_TYPE = 0x0014;
91pub const FILE_DEVICE_NULL: DEVICE_TYPE = 0x0015;
92pub const FILE_DEVICE_PARALLEL_PORT: DEVICE_TYPE = 0x0016;
93pub const FILE_DEVICE_PHYSICAL_NETCARD: DEVICE_TYPE = 0x0017;
94pub const FILE_DEVICE_PRINTER: DEVICE_TYPE = 0x0018;
95pub const FILE_DEVICE_SCANNER: DEVICE_TYPE = 0x0019;
96pub const FILE_DEVICE_SERIAL_MOUSE_PORT: DEVICE_TYPE = 0x001a;
97pub const FILE_DEVICE_SERIAL_PORT: DEVICE_TYPE = 0x001b;
98pub const FILE_DEVICE_SCREEN: DEVICE_TYPE = 0x001c;
99pub const FILE_DEVICE_SOUND: DEVICE_TYPE = 0x001d;
100pub const FILE_DEVICE_STREAMS: DEVICE_TYPE = 0x001e;
101pub const FILE_DEVICE_TAPE: DEVICE_TYPE = 0x001f;
102pub const FILE_DEVICE_TAPE_FILE_SYSTEM: DEVICE_TYPE = 0x0020;
103pub const FILE_DEVICE_TRANSPORT: DEVICE_TYPE = 0x0021;
104pub const FILE_DEVICE_UNKNOWN: DEVICE_TYPE = 0x0022;
105pub const FILE_DEVICE_VIDEO: DEVICE_TYPE = 0x0023;
106pub const FILE_DEVICE_VIRTUAL_DISK: DEVICE_TYPE = 0x0024;
107pub const FILE_DEVICE_WAVE_IN: DEVICE_TYPE = 0x0025;
108pub const FILE_DEVICE_WAVE_OUT: DEVICE_TYPE = 0x0026;
109pub const FILE_DEVICE_8042_PORT: DEVICE_TYPE = 0x0027;
110pub const FILE_DEVICE_NETWORK_REDIRECTOR: DEVICE_TYPE = 0x0028;
111pub const FILE_DEVICE_BATTERY: DEVICE_TYPE = 0x0029;
112pub const FILE_DEVICE_BUS_EXTENDER: DEVICE_TYPE = 0x002a;
113pub const FILE_DEVICE_MODEM: DEVICE_TYPE = 0x002b;
114pub const FILE_DEVICE_VDM: DEVICE_TYPE = 0x002c;
115pub const FILE_DEVICE_MASS_STORAGE: DEVICE_TYPE = 0x002d;
116pub const FILE_DEVICE_SMB: DEVICE_TYPE = 0x002e;
117pub const FILE_DEVICE_KS: DEVICE_TYPE = 0x002f;
118pub const FILE_DEVICE_CHANGER: DEVICE_TYPE = 0x0030;
119pub const FILE_DEVICE_SMARTCARD: DEVICE_TYPE = 0x0031;
120pub const FILE_DEVICE_ACPI: DEVICE_TYPE = 0x0032;
121pub const FILE_DEVICE_DVD: DEVICE_TYPE = 0x0033;
122pub const FILE_DEVICE_FULLSCREEN_VIDEO: DEVICE_TYPE = 0x0034;
123pub const FILE_DEVICE_DFS_FILE_SYSTEM: DEVICE_TYPE = 0x0035;
124pub const FILE_DEVICE_DFS_VOLUME: DEVICE_TYPE = 0x0036;
125pub const FILE_DEVICE_SERENUM: DEVICE_TYPE = 0x0037;
126pub const FILE_DEVICE_TERMSRV: DEVICE_TYPE = 0x0038;
127pub const FILE_DEVICE_KSEC: DEVICE_TYPE = 0x0039;
128pub const FILE_DEVICE_FIPS: DEVICE_TYPE = 0x003a;
129pub const FILE_DEVICE_INFINIBAND: DEVICE_TYPE = 0x003b;
130// TODO: missing values?
131pub const FILE_DEVICE_VMBUS: DEVICE_TYPE = 0x003e;
132pub const FILE_DEVICE_CRYPT_PROVIDER: DEVICE_TYPE = 0x003f;
133pub const FILE_DEVICE_WPD: DEVICE_TYPE = 0x0040;
134pub const FILE_DEVICE_BLUETOOTH: DEVICE_TYPE = 0x0041;
135pub const FILE_DEVICE_MT_COMPOSITE: DEVICE_TYPE = 0x0042;
136pub const FILE_DEVICE_MT_TRANSPORT: DEVICE_TYPE = 0x0043;
137pub const FILE_DEVICE_BIOMETRIC: DEVICE_TYPE = 0x0044;
138pub const FILE_DEVICE_PMI: DEVICE_TYPE = 0x0045;
139pub const FILE_DEVICE_EHSTOR: DEVICE_TYPE = 0x0046;
140pub const FILE_DEVICE_DEVAPI: DEVICE_TYPE = 0x0047;
141pub const FILE_DEVICE_GPIO: DEVICE_TYPE = 0x0048;
142pub const FILE_DEVICE_USBEX: DEVICE_TYPE = 0x0049;
143pub const FILE_DEVICE_CONSOLE: DEVICE_TYPE = 0x0050;
144pub const FILE_DEVICE_NFP: DEVICE_TYPE = 0x0051;
145pub const FILE_DEVICE_SYSENV: DEVICE_TYPE = 0x0052;
146pub const FILE_DEVICE_VIRTUAL_BLOCK: DEVICE_TYPE = 0x0053;
147pub const FILE_DEVICE_POINT_OF_SERVICE: DEVICE_TYPE = 0x0054;
148pub const FILE_DEVICE_STORAGE_REPLICATION: DEVICE_TYPE = 0x0055;
149pub const FILE_DEVICE_TRUST_ENV: DEVICE_TYPE = 0x0056;
150pub const FILE_DEVICE_UCM: DEVICE_TYPE = 0x0057;
151pub const FILE_DEVICE_UCMTCPCI: DEVICE_TYPE = 0x0058;
152pub const FILE_DEVICE_PERSISTENT_MEMORY: DEVICE_TYPE = 0x0059;
153pub const FILE_DEVICE_NVDIMM: DEVICE_TYPE = 0x005a;
154pub const FILE_DEVICE_HOLOGRAPHIC: DEVICE_TYPE = 0x005b;
155pub const FILE_DEVICE_SDFXHCI: DEVICE_TYPE = 0x005c;
156
157/// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/buffer-descriptions-for-i-o-control-codes
158pub const TransferType = enum(u2) {
159 METHOD_BUFFERED = 0,
160 METHOD_IN_DIRECT = 1,
161 METHOD_OUT_DIRECT = 2,
162 METHOD_NEITHER = 3,
163};
164
165pub const FILE_ANY_ACCESS = 0;
166pub const FILE_READ_ACCESS = 1;
167pub const FILE_WRITE_ACCESS = 2;
168
169/// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/defining-i-o-control-codes
170pub fn CTL_CODE(deviceType: u16, function: u12, method: TransferType, access: u2) DWORD {
171 return (@as(DWORD, deviceType) << 16) |
172 (@as(DWORD, access) << 14) |
173 (@as(DWORD, function) << 2) |
174 @enumToInt(method);
175}
176
70177pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
71178
72pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
179pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
73180
74181pub const FILE_ALL_INFORMATION = extern struct {
75182 BasicInformation: FILE_BASIC_INFORMATION,
......@@ -571,16 +678,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;
571678pub const KF_FLAG_ALIAS_ONLY = -2147483648;
572679
573680pub 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));
681pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001));
682pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002));
683pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003));
684pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004));
685pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005));
686pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF));
687pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005));
688pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006));
689pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E));
690pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057));
584691
585692pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
586693pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
......@@ -873,4 +980,4 @@ pub const CURDIR = extern struct {
873980 Handle: HANDLE,
874981};
875982
876pub const DUPLICATE_SAME_ACCESS = 2;
\ No newline at end of file
983pub const DUPLICATE_SAME_ACCESS = 2;
lib/std/os/windows/kernel32.zig+13
......@@ -45,6 +45,17 @@ pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, Ex
4545
4646pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE;
4747
48pub extern "kernel32" stdcallcc fn DeviceIoControl(
49 h: HANDLE,
50 dwIoControlCode: DWORD,
51 lpInBuffer: ?*const c_void,
52 nInBufferSize: DWORD,
53 lpOutBuffer: ?LPVOID,
54 nOutBufferSize: DWORD,
55 lpBytesReturned: LPDWORD,
56 lpOverlapped: ?*OVERLAPPED,
57) BOOL;
58
4859pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL;
4960
5061pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL;
......@@ -184,6 +195,8 @@ pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask:
184195
185196pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD) void;
186197
198pub extern "kernel32" stdcallcc fn SwitchToThread() BOOL;
199
187200pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) BOOL;
188201
189202pub extern "kernel32" stdcallcc fn TlsAlloc() DWORD;
lib/std/os/windows/ntdll.zig+30
......@@ -21,6 +21,18 @@ pub extern "NtDll" stdcallcc fn NtCreateFile(
2121 EaBuffer: ?*c_void,
2222 EaLength: ULONG,
2323) NTSTATUS;
24pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(
25 FileHandle: HANDLE,
26 Event: ?HANDLE,
27 ApcRoutine: ?*IO_APC_ROUTINE,
28 ApcContext: usize,
29 IoStatusBlock: *IO_STATUS_BLOCK,
30 IoControlCode: ULONG,
31 InputBuffer: ?*const c_void,
32 InputBufferLength: ULONG,
33 OutputBuffer: ?PVOID,
34 OutputBufferLength: ULONG,
35) NTSTATUS;
2436pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS;
2537pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U(
2638 DosPathName: [*]const u16,
......@@ -43,3 +55,21 @@ pub extern "NtDll" stdcallcc fn NtQueryDirectoryFile(
4355 FileName: ?*UNICODE_STRING,
4456 RestartScan: BOOLEAN,
4557) NTSTATUS;
58pub extern "NtDll" stdcallcc fn NtCreateKeyedEvent(
59 KeyedEventHandle: *HANDLE,
60 DesiredAccess: ACCESS_MASK,
61 ObjectAttributes: ?PVOID,
62 Flags: ULONG,
63) NTSTATUS;
64pub extern "NtDll" stdcallcc fn NtReleaseKeyedEvent(
65 EventHandle: HANDLE,
66 Key: *const c_void,
67 Alertable: BOOLEAN,
68 Timeout: ?*LARGE_INTEGER,
69) NTSTATUS;
70pub extern "NtDll" stdcallcc fn NtWaitForKeyedEvent(
71 EventHandle: HANDLE,
72 Key: *const c_void,
73 Alertable: BOOLEAN,
74 Timeout: ?*LARGE_INTEGER,
75) NTSTATUS;
lib/std/os/windows/status.zig+1652-2
......@@ -1,13 +1,1663 @@
11/// The operation completed successfully.
22pub const SUCCESS = 0x00000000;
33
4/// The data was too large to fit into the specified buffer.
4pub const WAIT_0 = 0x00000000;
5pub const WAIT_1 = 0x00000001;
6pub const WAIT_2 = 0x00000002;
7pub const WAIT_3 = 0x00000003;
8pub const WAIT_63 = 0x0000003F;
9pub const ABANDONED = 0x00000080;
10pub const ABANDONED_WAIT_0 = 0x00000080;
11pub const ABANDONED_WAIT_63 = 0x000000BF;
12pub const USER_APC = 0x000000C0;
13pub const ALERTED = 0x00000101;
14pub const TIMEOUT = 0x00000102;
15pub const PENDING = 0x00000103;
16pub const REPARSE = 0x00000104;
17pub const MORE_ENTRIES = 0x00000105;
18pub const NOT_ALL_ASSIGNED = 0x00000106;
19pub const SOME_NOT_MAPPED = 0x00000107;
20pub const OPLOCK_BREAK_IN_PROGRESS = 0x00000108;
21pub const VOLUME_MOUNTED = 0x00000109;
22pub const RXACT_COMMITTED = 0x0000010A;
23pub const NOTIFY_CLEANUP = 0x0000010B;
24pub const NOTIFY_ENUM_DIR = 0x0000010C;
25pub const NO_QUOTAS_FOR_ACCOUNT = 0x0000010D;
26pub const PRIMARY_TRANSPORT_CONNECT_FAILED = 0x0000010E;
27pub const PAGE_FAULT_TRANSITION = 0x00000110;
28pub const PAGE_FAULT_DEMAND_ZERO = 0x00000111;
29pub const PAGE_FAULT_COPY_ON_WRITE = 0x00000112;
30pub const PAGE_FAULT_GUARD_PAGE = 0x00000113;
31pub const PAGE_FAULT_PAGING_FILE = 0x00000114;
32pub const CACHE_PAGE_LOCKED = 0x00000115;
33pub const CRASH_DUMP = 0x00000116;
34pub const BUFFER_ALL_ZEROS = 0x00000117;
35pub const REPARSE_OBJECT = 0x00000118;
36pub const RESOURCE_REQUIREMENTS_CHANGED = 0x00000119;
37pub const TRANSLATION_COMPLETE = 0x00000120;
38pub const DS_MEMBERSHIP_EVALUATED_LOCALLY = 0x00000121;
39pub const NOTHING_TO_TERMINATE = 0x00000122;
40pub const PROCESS_NOT_IN_JOB = 0x00000123;
41pub const PROCESS_IN_JOB = 0x00000124;
42pub const VOLSNAP_HIBERNATE_READY = 0x00000125;
43pub const FSFILTER_OP_COMPLETED_SUCCESSFULLY = 0x00000126;
44pub const INTERRUPT_VECTOR_ALREADY_CONNECTED = 0x00000127;
45pub const INTERRUPT_STILL_CONNECTED = 0x00000128;
46pub const PROCESS_CLONED = 0x00000129;
47pub const FILE_LOCKED_WITH_ONLY_READERS = 0x0000012A;
48pub const FILE_LOCKED_WITH_WRITERS = 0x0000012B;
49pub const RESOURCEMANAGER_READ_ONLY = 0x00000202;
50pub const WAIT_FOR_OPLOCK = 0x00000367;
51pub const FLT_IO_COMPLETE = 0x001C0001;
52pub const FILE_NOT_AVAILABLE = 0xC0000467;
53pub const OBJECT_NAME_EXISTS = 0x40000000;
54pub const THREAD_WAS_SUSPENDED = 0x40000001;
55pub const WORKING_SET_LIMIT_RANGE = 0x40000002;
56pub const IMAGE_NOT_AT_BASE = 0x40000003;
57pub const RXACT_STATE_CREATED = 0x40000004;
58pub const SEGMENT_NOTIFICATION = 0x40000005;
59pub const LOCAL_USER_SESSION_KEY = 0x40000006;
60pub const BAD_CURRENT_DIRECTORY = 0x40000007;
61pub const SERIAL_MORE_WRITES = 0x40000008;
62pub const REGISTRY_RECOVERED = 0x40000009;
63pub const FT_READ_RECOVERY_FROM_BACKUP = 0x4000000A;
64pub const FT_WRITE_RECOVERY = 0x4000000B;
65pub const SERIAL_COUNTER_TIMEOUT = 0x4000000C;
66pub const NULL_LM_PASSWORD = 0x4000000D;
67pub const IMAGE_MACHINE_TYPE_MISMATCH = 0x4000000E;
68pub const RECEIVE_PARTIAL = 0x4000000F;
69pub const RECEIVE_EXPEDITED = 0x40000010;
70pub const RECEIVE_PARTIAL_EXPEDITED = 0x40000011;
71pub const EVENT_DONE = 0x40000012;
72pub const EVENT_PENDING = 0x40000013;
73pub const CHECKING_FILE_SYSTEM = 0x40000014;
74pub const FATAL_APP_EXIT = 0x40000015;
75pub const PREDEFINED_HANDLE = 0x40000016;
76pub const WAS_UNLOCKED = 0x40000017;
77pub const SERVICE_NOTIFICATION = 0x40000018;
78pub const WAS_LOCKED = 0x40000019;
79pub const LOG_HARD_ERROR = 0x4000001A;
80pub const ALREADY_WIN32 = 0x4000001B;
81pub const WX86_UNSIMULATE = 0x4000001C;
82pub const WX86_CONTINUE = 0x4000001D;
83pub const WX86_SINGLE_STEP = 0x4000001E;
84pub const WX86_BREAKPOINT = 0x4000001F;
85pub const WX86_EXCEPTION_CONTINUE = 0x40000020;
86pub const WX86_EXCEPTION_LASTCHANCE = 0x40000021;
87pub const WX86_EXCEPTION_CHAIN = 0x40000022;
88pub const IMAGE_MACHINE_TYPE_MISMATCH_EXE = 0x40000023;
89pub const NO_YIELD_PERFORMED = 0x40000024;
90pub const TIMER_RESUME_IGNORED = 0x40000025;
91pub const ARBITRATION_UNHANDLED = 0x40000026;
92pub const CARDBUS_NOT_SUPPORTED = 0x40000027;
93pub const WX86_CREATEWX86TIB = 0x40000028;
94pub const MP_PROCESSOR_MISMATCH = 0x40000029;
95pub const HIBERNATED = 0x4000002A;
96pub const RESUME_HIBERNATION = 0x4000002B;
97pub const FIRMWARE_UPDATED = 0x4000002C;
98pub const DRIVERS_LEAKING_LOCKED_PAGES = 0x4000002D;
99pub const MESSAGE_RETRIEVED = 0x4000002E;
100pub const SYSTEM_POWERSTATE_TRANSITION = 0x4000002F;
101pub const ALPC_CHECK_COMPLETION_LIST = 0x40000030;
102pub const SYSTEM_POWERSTATE_COMPLEX_TRANSITION = 0x40000031;
103pub const ACCESS_AUDIT_BY_POLICY = 0x40000032;
104pub const ABANDON_HIBERFILE = 0x40000033;
105pub const BIZRULES_NOT_ENABLED = 0x40000034;
106pub const WAKE_SYSTEM = 0x40000294;
107pub const DS_SHUTTING_DOWN = 0x40000370;
108pub const CTX_CDM_CONNECT = 0x400A0004;
109pub const CTX_CDM_DISCONNECT = 0x400A0005;
110pub const SXS_RELEASE_ACTIVATION_CONTEXT = 0x4015000D;
111pub const RECOVERY_NOT_NEEDED = 0x40190034;
112pub const RM_ALREADY_STARTED = 0x40190035;
113pub const LOG_NO_RESTART = 0x401A000C;
114pub const VIDEO_DRIVER_DEBUG_REPORT_REQUEST = 0x401B00EC;
115pub const GRAPHICS_PARTIAL_DATA_POPULATED = 0x401E000A;
116pub const GRAPHICS_DRIVER_MISMATCH = 0x401E0117;
117pub const GRAPHICS_MODE_NOT_PINNED = 0x401E0307;
118pub const GRAPHICS_NO_PREFERRED_MODE = 0x401E031E;
119pub const GRAPHICS_DATASET_IS_EMPTY = 0x401E034B;
120pub const GRAPHICS_NO_MORE_ELEMENTS_IN_DATASET = 0x401E034C;
121pub const GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_PINNED = 0x401E0351;
122pub const GRAPHICS_UNKNOWN_CHILD_STATUS = 0x401E042F;
123pub const GRAPHICS_LEADLINK_START_DEFERRED = 0x401E0437;
124pub const GRAPHICS_POLLING_TOO_FREQUENTLY = 0x401E0439;
125pub const GRAPHICS_START_DEFERRED = 0x401E043A;
126pub const NDIS_INDICATION_REQUIRED = 0x40230001;
127pub const GUARD_PAGE_VIOLATION = 0x80000001;
128pub const DATATYPE_MISALIGNMENT = 0x80000002;
129pub const BREAKPOINT = 0x80000003;
130pub const SINGLE_STEP = 0x80000004;
5131pub const BUFFER_OVERFLOW = 0x80000005;
6
132pub const NO_MORE_FILES = 0x80000006;
133pub const WAKE_SYSTEM_DEBUGGER = 0x80000007;
134pub const HANDLES_CLOSED = 0x8000000A;
135pub const NO_INHERITANCE = 0x8000000B;
136pub const GUID_SUBSTITUTION_MADE = 0x8000000C;
137pub const PARTIAL_COPY = 0x8000000D;
138pub const DEVICE_PAPER_EMPTY = 0x8000000E;
139pub const DEVICE_POWERED_OFF = 0x8000000F;
140pub const DEVICE_OFF_LINE = 0x80000010;
141pub const DEVICE_BUSY = 0x80000011;
142pub const NO_MORE_EAS = 0x80000012;
143pub const INVALID_EA_NAME = 0x80000013;
144pub const EA_LIST_INCONSISTENT = 0x80000014;
145pub const INVALID_EA_FLAG = 0x80000015;
146pub const VERIFY_REQUIRED = 0x80000016;
147pub const EXTRANEOUS_INFORMATION = 0x80000017;
148pub const RXACT_COMMIT_NECESSARY = 0x80000018;
149pub const NO_MORE_ENTRIES = 0x8000001A;
150pub const FILEMARK_DETECTED = 0x8000001B;
151pub const MEDIA_CHANGED = 0x8000001C;
152pub const BUS_RESET = 0x8000001D;
153pub const END_OF_MEDIA = 0x8000001E;
154pub const BEGINNING_OF_MEDIA = 0x8000001F;
155pub const MEDIA_CHECK = 0x80000020;
156pub const SETMARK_DETECTED = 0x80000021;
157pub const NO_DATA_DETECTED = 0x80000022;
158pub const REDIRECTOR_HAS_OPEN_HANDLES = 0x80000023;
159pub const SERVER_HAS_OPEN_HANDLES = 0x80000024;
160pub const ALREADY_DISCONNECTED = 0x80000025;
161pub const LONGJUMP = 0x80000026;
162pub const CLEANER_CARTRIDGE_INSTALLED = 0x80000027;
163pub const PLUGPLAY_QUERY_VETOED = 0x80000028;
164pub const UNWIND_CONSOLIDATE = 0x80000029;
165pub const REGISTRY_HIVE_RECOVERED = 0x8000002A;
166pub const DLL_MIGHT_BE_INSECURE = 0x8000002B;
167pub const DLL_MIGHT_BE_INCOMPATIBLE = 0x8000002C;
168pub const STOPPED_ON_SYMLINK = 0x8000002D;
169pub const DEVICE_REQUIRES_CLEANING = 0x80000288;
170pub const DEVICE_DOOR_OPEN = 0x80000289;
171pub const DATA_LOST_REPAIR = 0x80000803;
172pub const CLUSTER_NODE_ALREADY_UP = 0x80130001;
173pub const CLUSTER_NODE_ALREADY_DOWN = 0x80130002;
174pub const CLUSTER_NETWORK_ALREADY_ONLINE = 0x80130003;
175pub const CLUSTER_NETWORK_ALREADY_OFFLINE = 0x80130004;
176pub const CLUSTER_NODE_ALREADY_MEMBER = 0x80130005;
177pub const COULD_NOT_RESIZE_LOG = 0x80190009;
178pub const NO_TXF_METADATA = 0x80190029;
179pub const CANT_RECOVER_WITH_HANDLE_OPEN = 0x80190031;
180pub const TXF_METADATA_ALREADY_PRESENT = 0x80190041;
181pub const TRANSACTION_SCOPE_CALLBACKS_NOT_SET = 0x80190042;
182pub const VIDEO_HUNG_DISPLAY_DRIVER_THREAD_RECOVERED = 0x801B00EB;
183pub const FLT_BUFFER_TOO_SMALL = 0x801C0001;
184pub const FVE_PARTIAL_METADATA = 0x80210001;
185pub const FVE_TRANSIENT_STATE = 0x80210002;
186pub const UNSUCCESSFUL = 0xC0000001;
187pub const NOT_IMPLEMENTED = 0xC0000002;
188pub const INVALID_INFO_CLASS = 0xC0000003;
189pub const INFO_LENGTH_MISMATCH = 0xC0000004;
190pub const ACCESS_VIOLATION = 0xC0000005;
191pub const IN_PAGE_ERROR = 0xC0000006;
192pub const PAGEFILE_QUOTA = 0xC0000007;
193pub const INVALID_HANDLE = 0xC0000008;
194pub const BAD_INITIAL_STACK = 0xC0000009;
195pub const BAD_INITIAL_PC = 0xC000000A;
196pub const INVALID_CID = 0xC000000B;
197pub const TIMER_NOT_CANCELED = 0xC000000C;
7198pub const INVALID_PARAMETER = 0xC000000D;
199pub const NO_SUCH_DEVICE = 0xC000000E;
200pub const NO_SUCH_FILE = 0xC000000F;
201pub const INVALID_DEVICE_REQUEST = 0xC0000010;
202pub const END_OF_FILE = 0xC0000011;
203pub const WRONG_VOLUME = 0xC0000012;
204pub const NO_MEDIA_IN_DEVICE = 0xC0000013;
205pub const UNRECOGNIZED_MEDIA = 0xC0000014;
206pub const NONEXISTENT_SECTOR = 0xC0000015;
207pub const MORE_PROCESSING_REQUIRED = 0xC0000016;
208pub const NO_MEMORY = 0xC0000017;
209pub const CONFLICTING_ADDRESSES = 0xC0000018;
210pub const NOT_MAPPED_VIEW = 0xC0000019;
211pub const UNABLE_TO_FREE_VM = 0xC000001A;
212pub const UNABLE_TO_DELETE_SECTION = 0xC000001B;
213pub const INVALID_SYSTEM_SERVICE = 0xC000001C;
214pub const ILLEGAL_INSTRUCTION = 0xC000001D;
215pub const INVALID_LOCK_SEQUENCE = 0xC000001E;
216pub const INVALID_VIEW_SIZE = 0xC000001F;
217pub const INVALID_FILE_FOR_SECTION = 0xC0000020;
218pub const ALREADY_COMMITTED = 0xC0000021;
8219pub const ACCESS_DENIED = 0xC0000022;
220pub const BUFFER_TOO_SMALL = 0xC0000023;
221pub const OBJECT_TYPE_MISMATCH = 0xC0000024;
222pub const NONCONTINUABLE_EXCEPTION = 0xC0000025;
223pub const INVALID_DISPOSITION = 0xC0000026;
224pub const UNWIND = 0xC0000027;
225pub const BAD_STACK = 0xC0000028;
226pub const INVALID_UNWIND_TARGET = 0xC0000029;
227pub const NOT_LOCKED = 0xC000002A;
228pub const PARITY_ERROR = 0xC000002B;
229pub const UNABLE_TO_DECOMMIT_VM = 0xC000002C;
230pub const NOT_COMMITTED = 0xC000002D;
231pub const INVALID_PORT_ATTRIBUTES = 0xC000002E;
232pub const PORT_MESSAGE_TOO_LONG = 0xC000002F;
233pub const INVALID_PARAMETER_MIX = 0xC0000030;
234pub const INVALID_QUOTA_LOWER = 0xC0000031;
235pub const DISK_CORRUPT_ERROR = 0xC0000032;
9236pub const OBJECT_NAME_INVALID = 0xC0000033;
10237pub const OBJECT_NAME_NOT_FOUND = 0xC0000034;
238pub const OBJECT_NAME_COLLISION = 0xC0000035;
239pub const PORT_DISCONNECTED = 0xC0000037;
240pub const DEVICE_ALREADY_ATTACHED = 0xC0000038;
241pub const OBJECT_PATH_INVALID = 0xC0000039;
11242pub const OBJECT_PATH_NOT_FOUND = 0xC000003A;
12243pub const OBJECT_PATH_SYNTAX_BAD = 0xC000003B;
244pub const DATA_OVERRUN = 0xC000003C;
245pub const DATA_LATE_ERROR = 0xC000003D;
246pub const DATA_ERROR = 0xC000003E;
247pub const CRC_ERROR = 0xC000003F;
248pub const SECTION_TOO_BIG = 0xC0000040;
249pub const PORT_CONNECTION_REFUSED = 0xC0000041;
250pub const INVALID_PORT_HANDLE = 0xC0000042;
251pub const SHARING_VIOLATION = 0xC0000043;
252pub const QUOTA_EXCEEDED = 0xC0000044;
253pub const INVALID_PAGE_PROTECTION = 0xC0000045;
254pub const MUTANT_NOT_OWNED = 0xC0000046;
255pub const SEMAPHORE_LIMIT_EXCEEDED = 0xC0000047;
256pub const PORT_ALREADY_SET = 0xC0000048;
257pub const SECTION_NOT_IMAGE = 0xC0000049;
258pub const SUSPEND_COUNT_EXCEEDED = 0xC000004A;
259pub const THREAD_IS_TERMINATING = 0xC000004B;
260pub const BAD_WORKING_SET_LIMIT = 0xC000004C;
261pub const INCOMPATIBLE_FILE_MAP = 0xC000004D;
262pub const SECTION_PROTECTION = 0xC000004E;
263pub const EAS_NOT_SUPPORTED = 0xC000004F;
264pub const EA_TOO_LARGE = 0xC0000050;
265pub const NONEXISTENT_EA_ENTRY = 0xC0000051;
266pub const NO_EAS_ON_FILE = 0xC0000052;
267pub const EA_CORRUPT_ERROR = 0xC0000053;
268pub const FILE_LOCK_CONFLICT = 0xC0000054;
269pub const LOCK_NOT_GRANTED = 0xC0000055;
270pub const DELETE_PENDING = 0xC0000056;
271pub const CTL_FILE_NOT_SUPPORTED = 0xC0000057;
272pub const UNKNOWN_REVISION = 0xC0000058;
273pub const REVISION_MISMATCH = 0xC0000059;
274pub const INVALID_OWNER = 0xC000005A;
275pub const INVALID_PRIMARY_GROUP = 0xC000005B;
276pub const NO_IMPERSONATION_TOKEN = 0xC000005C;
277pub const CANT_DISABLE_MANDATORY = 0xC000005D;
278pub const NO_LOGON_SERVERS = 0xC000005E;
279pub const NO_SUCH_LOGON_SESSION = 0xC000005F;
280pub const NO_SUCH_PRIVILEGE = 0xC0000060;
281pub const PRIVILEGE_NOT_HELD = 0xC0000061;
282pub const INVALID_ACCOUNT_NAME = 0xC0000062;
283pub const USER_EXISTS = 0xC0000063;
284pub const NO_SUCH_USER = 0xC0000064;
285pub const GROUP_EXISTS = 0xC0000065;
286pub const NO_SUCH_GROUP = 0xC0000066;
287pub const MEMBER_IN_GROUP = 0xC0000067;
288pub const MEMBER_NOT_IN_GROUP = 0xC0000068;
289pub const LAST_ADMIN = 0xC0000069;
290pub const WRONG_PASSWORD = 0xC000006A;
291pub const ILL_FORMED_PASSWORD = 0xC000006B;
292pub const PASSWORD_RESTRICTION = 0xC000006C;
293pub const LOGON_FAILURE = 0xC000006D;
294pub const ACCOUNT_RESTRICTION = 0xC000006E;
295pub const INVALID_LOGON_HOURS = 0xC000006F;
296pub const INVALID_WORKSTATION = 0xC0000070;
297pub const PASSWORD_EXPIRED = 0xC0000071;
298pub const ACCOUNT_DISABLED = 0xC0000072;
299pub const NONE_MAPPED = 0xC0000073;
300pub const TOO_MANY_LUIDS_REQUESTED = 0xC0000074;
301pub const LUIDS_EXHAUSTED = 0xC0000075;
302pub const INVALID_SUB_AUTHORITY = 0xC0000076;
303pub const INVALID_ACL = 0xC0000077;
304pub const INVALID_SID = 0xC0000078;
305pub const INVALID_SECURITY_DESCR = 0xC0000079;
306pub const PROCEDURE_NOT_FOUND = 0xC000007A;
307pub const INVALID_IMAGE_FORMAT = 0xC000007B;
308pub const NO_TOKEN = 0xC000007C;
309pub const BAD_INHERITANCE_ACL = 0xC000007D;
310pub const RANGE_NOT_LOCKED = 0xC000007E;
311pub const DISK_FULL = 0xC000007F;
312pub const SERVER_DISABLED = 0xC0000080;
313pub const SERVER_NOT_DISABLED = 0xC0000081;
314pub const TOO_MANY_GUIDS_REQUESTED = 0xC0000082;
315pub const GUIDS_EXHAUSTED = 0xC0000083;
316pub const INVALID_ID_AUTHORITY = 0xC0000084;
317pub const AGENTS_EXHAUSTED = 0xC0000085;
318pub const INVALID_VOLUME_LABEL = 0xC0000086;
319pub const SECTION_NOT_EXTENDED = 0xC0000087;
320pub const NOT_MAPPED_DATA = 0xC0000088;
321pub const RESOURCE_DATA_NOT_FOUND = 0xC0000089;
322pub const RESOURCE_TYPE_NOT_FOUND = 0xC000008A;
323pub const RESOURCE_NAME_NOT_FOUND = 0xC000008B;
324pub const ARRAY_BOUNDS_EXCEEDED = 0xC000008C;
325pub const FLOAT_DENORMAL_OPERAND = 0xC000008D;
326pub const FLOAT_DIVIDE_BY_ZERO = 0xC000008E;
327pub const FLOAT_INEXACT_RESULT = 0xC000008F;
328pub const FLOAT_INVALID_OPERATION = 0xC0000090;
329pub const FLOAT_OVERFLOW = 0xC0000091;
330pub const FLOAT_STACK_CHECK = 0xC0000092;
331pub const FLOAT_UNDERFLOW = 0xC0000093;
332pub const INTEGER_DIVIDE_BY_ZERO = 0xC0000094;
333pub const INTEGER_OVERFLOW = 0xC0000095;
334pub const PRIVILEGED_INSTRUCTION = 0xC0000096;
335pub const TOO_MANY_PAGING_FILES = 0xC0000097;
336pub const FILE_INVALID = 0xC0000098;
337pub const ALLOTTED_SPACE_EXCEEDED = 0xC0000099;
338pub const INSUFFICIENT_RESOURCES = 0xC000009A;
339pub const DFS_EXIT_PATH_FOUND = 0xC000009B;
340pub const DEVICE_DATA_ERROR = 0xC000009C;
341pub const DEVICE_NOT_CONNECTED = 0xC000009D;
342pub const FREE_VM_NOT_AT_BASE = 0xC000009F;
343pub const MEMORY_NOT_ALLOCATED = 0xC00000A0;
344pub const WORKING_SET_QUOTA = 0xC00000A1;
345pub const MEDIA_WRITE_PROTECTED = 0xC00000A2;
346pub const DEVICE_NOT_READY = 0xC00000A3;
347pub const INVALID_GROUP_ATTRIBUTES = 0xC00000A4;
348pub const BAD_IMPERSONATION_LEVEL = 0xC00000A5;
349pub const CANT_OPEN_ANONYMOUS = 0xC00000A6;
350pub const BAD_VALIDATION_CLASS = 0xC00000A7;
351pub const BAD_TOKEN_TYPE = 0xC00000A8;
352pub const BAD_MASTER_BOOT_RECORD = 0xC00000A9;
353pub const INSTRUCTION_MISALIGNMENT = 0xC00000AA;
354pub const INSTANCE_NOT_AVAILABLE = 0xC00000AB;
355pub const PIPE_NOT_AVAILABLE = 0xC00000AC;
356pub const INVALID_PIPE_STATE = 0xC00000AD;
357pub const PIPE_BUSY = 0xC00000AE;
358pub const ILLEGAL_FUNCTION = 0xC00000AF;
359pub const PIPE_DISCONNECTED = 0xC00000B0;
360pub const PIPE_CLOSING = 0xC00000B1;
361pub const PIPE_CONNECTED = 0xC00000B2;
362pub const PIPE_LISTENING = 0xC00000B3;
363pub const INVALID_READ_MODE = 0xC00000B4;
364pub const IO_TIMEOUT = 0xC00000B5;
365pub const FILE_FORCED_CLOSED = 0xC00000B6;
366pub const PROFILING_NOT_STARTED = 0xC00000B7;
367pub const PROFILING_NOT_STOPPED = 0xC00000B8;
368pub const COULD_NOT_INTERPRET = 0xC00000B9;
13369pub const FILE_IS_A_DIRECTORY = 0xC00000BA;
370pub const NOT_SUPPORTED = 0xC00000BB;
371pub const REMOTE_NOT_LISTENING = 0xC00000BC;
372pub const DUPLICATE_NAME = 0xC00000BD;
373pub const BAD_NETWORK_PATH = 0xC00000BE;
374pub const NETWORK_BUSY = 0xC00000BF;
375pub const DEVICE_DOES_NOT_EXIST = 0xC00000C0;
376pub const TOO_MANY_COMMANDS = 0xC00000C1;
377pub const ADAPTER_HARDWARE_ERROR = 0xC00000C2;
378pub const INVALID_NETWORK_RESPONSE = 0xC00000C3;
379pub const UNEXPECTED_NETWORK_ERROR = 0xC00000C4;
380pub const BAD_REMOTE_ADAPTER = 0xC00000C5;
381pub const PRINT_QUEUE_FULL = 0xC00000C6;
382pub const NO_SPOOL_SPACE = 0xC00000C7;
383pub const PRINT_CANCELLED = 0xC00000C8;
384pub const NETWORK_NAME_DELETED = 0xC00000C9;
385pub const NETWORK_ACCESS_DENIED = 0xC00000CA;
386pub const BAD_DEVICE_TYPE = 0xC00000CB;
387pub const BAD_NETWORK_NAME = 0xC00000CC;
388pub const TOO_MANY_NAMES = 0xC00000CD;
389pub const TOO_MANY_SESSIONS = 0xC00000CE;
390pub const SHARING_PAUSED = 0xC00000CF;
391pub const REQUEST_NOT_ACCEPTED = 0xC00000D0;
392pub const REDIRECTOR_PAUSED = 0xC00000D1;
393pub const NET_WRITE_FAULT = 0xC00000D2;
394pub const PROFILING_AT_LIMIT = 0xC00000D3;
395pub const NOT_SAME_DEVICE = 0xC00000D4;
396pub const FILE_RENAMED = 0xC00000D5;
397pub const VIRTUAL_CIRCUIT_CLOSED = 0xC00000D6;
398pub const NO_SECURITY_ON_OBJECT = 0xC00000D7;
399pub const CANT_WAIT = 0xC00000D8;
400pub const PIPE_EMPTY = 0xC00000D9;
401pub const CANT_ACCESS_DOMAIN_INFO = 0xC00000DA;
402pub const CANT_TERMINATE_SELF = 0xC00000DB;
403pub const INVALID_SERVER_STATE = 0xC00000DC;
404pub const INVALID_DOMAIN_STATE = 0xC00000DD;
405pub const INVALID_DOMAIN_ROLE = 0xC00000DE;
406pub const NO_SUCH_DOMAIN = 0xC00000DF;
407pub const DOMAIN_EXISTS = 0xC00000E0;
408pub const DOMAIN_LIMIT_EXCEEDED = 0xC00000E1;
409pub const OPLOCK_NOT_GRANTED = 0xC00000E2;
410pub const INVALID_OPLOCK_PROTOCOL = 0xC00000E3;
411pub const INTERNAL_DB_CORRUPTION = 0xC00000E4;
412pub const INTERNAL_ERROR = 0xC00000E5;
413pub const GENERIC_NOT_MAPPED = 0xC00000E6;
414pub const BAD_DESCRIPTOR_FORMAT = 0xC00000E7;
415pub const INVALID_USER_BUFFER = 0xC00000E8;
416pub const UNEXPECTED_IO_ERROR = 0xC00000E9;
417pub const UNEXPECTED_MM_CREATE_ERR = 0xC00000EA;
418pub const UNEXPECTED_MM_MAP_ERROR = 0xC00000EB;
419pub const UNEXPECTED_MM_EXTEND_ERR = 0xC00000EC;
420pub const NOT_LOGON_PROCESS = 0xC00000ED;
421pub const LOGON_SESSION_EXISTS = 0xC00000EE;
422pub const INVALID_PARAMETER_1 = 0xC00000EF;
423pub const INVALID_PARAMETER_2 = 0xC00000F0;
424pub const INVALID_PARAMETER_3 = 0xC00000F1;
425pub const INVALID_PARAMETER_4 = 0xC00000F2;
426pub const INVALID_PARAMETER_5 = 0xC00000F3;
427pub const INVALID_PARAMETER_6 = 0xC00000F4;
428pub const INVALID_PARAMETER_7 = 0xC00000F5;
429pub const INVALID_PARAMETER_8 = 0xC00000F6;
430pub const INVALID_PARAMETER_9 = 0xC00000F7;
431pub const INVALID_PARAMETER_10 = 0xC00000F8;
432pub const INVALID_PARAMETER_11 = 0xC00000F9;
433pub const INVALID_PARAMETER_12 = 0xC00000FA;
434pub const REDIRECTOR_NOT_STARTED = 0xC00000FB;
435pub const REDIRECTOR_STARTED = 0xC00000FC;
436pub const STACK_OVERFLOW = 0xC00000FD;
437pub const NO_SUCH_PACKAGE = 0xC00000FE;
438pub const BAD_FUNCTION_TABLE = 0xC00000FF;
439pub const VARIABLE_NOT_FOUND = 0xC0000100;
440pub const DIRECTORY_NOT_EMPTY = 0xC0000101;
441pub const FILE_CORRUPT_ERROR = 0xC0000102;
442pub const NOT_A_DIRECTORY = 0xC0000103;
443pub const BAD_LOGON_SESSION_STATE = 0xC0000104;
444pub const LOGON_SESSION_COLLISION = 0xC0000105;
445pub const NAME_TOO_LONG = 0xC0000106;
446pub const FILES_OPEN = 0xC0000107;
447pub const CONNECTION_IN_USE = 0xC0000108;
448pub const MESSAGE_NOT_FOUND = 0xC0000109;
449pub const PROCESS_IS_TERMINATING = 0xC000010A;
450pub const INVALID_LOGON_TYPE = 0xC000010B;
451pub const NO_GUID_TRANSLATION = 0xC000010C;
452pub const CANNOT_IMPERSONATE = 0xC000010D;
453pub const IMAGE_ALREADY_LOADED = 0xC000010E;
454pub const NO_LDT = 0xC0000117;
455pub const INVALID_LDT_SIZE = 0xC0000118;
456pub const INVALID_LDT_OFFSET = 0xC0000119;
457pub const INVALID_LDT_DESCRIPTOR = 0xC000011A;
458pub const INVALID_IMAGE_NE_FORMAT = 0xC000011B;
459pub const RXACT_INVALID_STATE = 0xC000011C;
460pub const RXACT_COMMIT_FAILURE = 0xC000011D;
461pub const MAPPED_FILE_SIZE_ZERO = 0xC000011E;
462pub const TOO_MANY_OPENED_FILES = 0xC000011F;
463pub const CANCELLED = 0xC0000120;
464pub const CANNOT_DELETE = 0xC0000121;
465pub const INVALID_COMPUTER_NAME = 0xC0000122;
466pub const FILE_DELETED = 0xC0000123;
467pub const SPECIAL_ACCOUNT = 0xC0000124;
468pub const SPECIAL_GROUP = 0xC0000125;
469pub const SPECIAL_USER = 0xC0000126;
470pub const MEMBERS_PRIMARY_GROUP = 0xC0000127;
471pub const FILE_CLOSED = 0xC0000128;
472pub const TOO_MANY_THREADS = 0xC0000129;
473pub const THREAD_NOT_IN_PROCESS = 0xC000012A;
474pub const TOKEN_ALREADY_IN_USE = 0xC000012B;
475pub const PAGEFILE_QUOTA_EXCEEDED = 0xC000012C;
476pub const COMMITMENT_LIMIT = 0xC000012D;
477pub const INVALID_IMAGE_LE_FORMAT = 0xC000012E;
478pub const INVALID_IMAGE_NOT_MZ = 0xC000012F;
479pub const INVALID_IMAGE_PROTECT = 0xC0000130;
480pub const INVALID_IMAGE_WIN_16 = 0xC0000131;
481pub const LOGON_SERVER_CONFLICT = 0xC0000132;
482pub const TIME_DIFFERENCE_AT_DC = 0xC0000133;
483pub const SYNCHRONIZATION_REQUIRED = 0xC0000134;
484pub const DLL_NOT_FOUND = 0xC0000135;
485pub const OPEN_FAILED = 0xC0000136;
486pub const IO_PRIVILEGE_FAILED = 0xC0000137;
487pub const ORDINAL_NOT_FOUND = 0xC0000138;
488pub const ENTRYPOINT_NOT_FOUND = 0xC0000139;
489pub const CONTROL_C_EXIT = 0xC000013A;
490pub const LOCAL_DISCONNECT = 0xC000013B;
491pub const REMOTE_DISCONNECT = 0xC000013C;
492pub const REMOTE_RESOURCES = 0xC000013D;
493pub const LINK_FAILED = 0xC000013E;
494pub const LINK_TIMEOUT = 0xC000013F;
495pub const INVALID_CONNECTION = 0xC0000140;
496pub const INVALID_ADDRESS = 0xC0000141;
497pub const DLL_INIT_FAILED = 0xC0000142;
498pub const MISSING_SYSTEMFILE = 0xC0000143;
499pub const UNHANDLED_EXCEPTION = 0xC0000144;
500pub const APP_INIT_FAILURE = 0xC0000145;
501pub const PAGEFILE_CREATE_FAILED = 0xC0000146;
502pub const NO_PAGEFILE = 0xC0000147;
503pub const INVALID_LEVEL = 0xC0000148;
504pub const WRONG_PASSWORD_CORE = 0xC0000149;
505pub const ILLEGAL_FLOAT_CONTEXT = 0xC000014A;
506pub const PIPE_BROKEN = 0xC000014B;
507pub const REGISTRY_CORRUPT = 0xC000014C;
508pub const REGISTRY_IO_FAILED = 0xC000014D;
509pub const NO_EVENT_PAIR = 0xC000014E;
510pub const UNRECOGNIZED_VOLUME = 0xC000014F;
511pub const SERIAL_NO_DEVICE_INITED = 0xC0000150;
512pub const NO_SUCH_ALIAS = 0xC0000151;
513pub const MEMBER_NOT_IN_ALIAS = 0xC0000152;
514pub const MEMBER_IN_ALIAS = 0xC0000153;
515pub const ALIAS_EXISTS = 0xC0000154;
516pub const LOGON_NOT_GRANTED = 0xC0000155;
517pub const TOO_MANY_SECRETS = 0xC0000156;
518pub const SECRET_TOO_LONG = 0xC0000157;
519pub const INTERNAL_DB_ERROR = 0xC0000158;
520pub const FULLSCREEN_MODE = 0xC0000159;
521pub const TOO_MANY_CONTEXT_IDS = 0xC000015A;
522pub const LOGON_TYPE_NOT_GRANTED = 0xC000015B;
523pub const NOT_REGISTRY_FILE = 0xC000015C;
524pub const NT_CROSS_ENCRYPTION_REQUIRED = 0xC000015D;
525pub const DOMAIN_CTRLR_CONFIG_ERROR = 0xC000015E;
526pub const FT_MISSING_MEMBER = 0xC000015F;
527pub const ILL_FORMED_SERVICE_ENTRY = 0xC0000160;
528pub const ILLEGAL_CHARACTER = 0xC0000161;
529pub const UNMAPPABLE_CHARACTER = 0xC0000162;
530pub const UNDEFINED_CHARACTER = 0xC0000163;
531pub const FLOPPY_VOLUME = 0xC0000164;
532pub const FLOPPY_ID_MARK_NOT_FOUND = 0xC0000165;
533pub const FLOPPY_WRONG_CYLINDER = 0xC0000166;
534pub const FLOPPY_UNKNOWN_ERROR = 0xC0000167;
535pub const FLOPPY_BAD_REGISTERS = 0xC0000168;
536pub const DISK_RECALIBRATE_FAILED = 0xC0000169;
537pub const DISK_OPERATION_FAILED = 0xC000016A;
538pub const DISK_RESET_FAILED = 0xC000016B;
539pub const SHARED_IRQ_BUSY = 0xC000016C;
540pub const FT_ORPHANING = 0xC000016D;
541pub const BIOS_FAILED_TO_CONNECT_INTERRUPT = 0xC000016E;
542pub const PARTITION_FAILURE = 0xC0000172;
543pub const INVALID_BLOCK_LENGTH = 0xC0000173;
544pub const DEVICE_NOT_PARTITIONED = 0xC0000174;
545pub const UNABLE_TO_LOCK_MEDIA = 0xC0000175;
546pub const UNABLE_TO_UNLOAD_MEDIA = 0xC0000176;
547pub const EOM_OVERFLOW = 0xC0000177;
548pub const NO_MEDIA = 0xC0000178;
549pub const NO_SUCH_MEMBER = 0xC000017A;
550pub const INVALID_MEMBER = 0xC000017B;
551pub const KEY_DELETED = 0xC000017C;
552pub const NO_LOG_SPACE = 0xC000017D;
553pub const TOO_MANY_SIDS = 0xC000017E;
554pub const LM_CROSS_ENCRYPTION_REQUIRED = 0xC000017F;
555pub const KEY_HAS_CHILDREN = 0xC0000180;
556pub const CHILD_MUST_BE_VOLATILE = 0xC0000181;
557pub const DEVICE_CONFIGURATION_ERROR = 0xC0000182;
558pub const DRIVER_INTERNAL_ERROR = 0xC0000183;
559pub const INVALID_DEVICE_STATE = 0xC0000184;
560pub const IO_DEVICE_ERROR = 0xC0000185;
561pub const DEVICE_PROTOCOL_ERROR = 0xC0000186;
562pub const BACKUP_CONTROLLER = 0xC0000187;
563pub const LOG_FILE_FULL = 0xC0000188;
564pub const TOO_LATE = 0xC0000189;
565pub const NO_TRUST_LSA_SECRET = 0xC000018A;
566pub const NO_TRUST_SAM_ACCOUNT = 0xC000018B;
567pub const TRUSTED_DOMAIN_FAILURE = 0xC000018C;
568pub const TRUSTED_RELATIONSHIP_FAILURE = 0xC000018D;
569pub const EVENTLOG_FILE_CORRUPT = 0xC000018E;
570pub const EVENTLOG_CANT_START = 0xC000018F;
571pub const TRUST_FAILURE = 0xC0000190;
572pub const MUTANT_LIMIT_EXCEEDED = 0xC0000191;
573pub const NETLOGON_NOT_STARTED = 0xC0000192;
574pub const ACCOUNT_EXPIRED = 0xC0000193;
575pub const POSSIBLE_DEADLOCK = 0xC0000194;
576pub const NETWORK_CREDENTIAL_CONFLICT = 0xC0000195;
577pub const REMOTE_SESSION_LIMIT = 0xC0000196;
578pub const EVENTLOG_FILE_CHANGED = 0xC0000197;
579pub const NOLOGON_INTERDOMAIN_TRUST_ACCOUNT = 0xC0000198;
580pub const NOLOGON_WORKSTATION_TRUST_ACCOUNT = 0xC0000199;
581pub const NOLOGON_SERVER_TRUST_ACCOUNT = 0xC000019A;
582pub const DOMAIN_TRUST_INCONSISTENT = 0xC000019B;
583pub const FS_DRIVER_REQUIRED = 0xC000019C;
584pub const IMAGE_ALREADY_LOADED_AS_DLL = 0xC000019D;
585pub const INCOMPATIBLE_WITH_GLOBAL_SHORT_NAME_REGISTRY_SETTING = 0xC000019E;
586pub const SHORT_NAMES_NOT_ENABLED_ON_VOLUME = 0xC000019F;
587pub const SECURITY_STREAM_IS_INCONSISTENT = 0xC00001A0;
588pub const INVALID_LOCK_RANGE = 0xC00001A1;
589pub const INVALID_ACE_CONDITION = 0xC00001A2;
590pub const IMAGE_SUBSYSTEM_NOT_PRESENT = 0xC00001A3;
591pub const NOTIFICATION_GUID_ALREADY_DEFINED = 0xC00001A4;
592pub const NETWORK_OPEN_RESTRICTION = 0xC0000201;
593pub const NO_USER_SESSION_KEY = 0xC0000202;
594pub const USER_SESSION_DELETED = 0xC0000203;
595pub const RESOURCE_LANG_NOT_FOUND = 0xC0000204;
596pub const INSUFF_SERVER_RESOURCES = 0xC0000205;
597pub const INVALID_BUFFER_SIZE = 0xC0000206;
598pub const INVALID_ADDRESS_COMPONENT = 0xC0000207;
599pub const INVALID_ADDRESS_WILDCARD = 0xC0000208;
600pub const TOO_MANY_ADDRESSES = 0xC0000209;
601pub const ADDRESS_ALREADY_EXISTS = 0xC000020A;
602pub const ADDRESS_CLOSED = 0xC000020B;
603pub const CONNECTION_DISCONNECTED = 0xC000020C;
604pub const CONNECTION_RESET = 0xC000020D;
605pub const TOO_MANY_NODES = 0xC000020E;
606pub const TRANSACTION_ABORTED = 0xC000020F;
607pub const TRANSACTION_TIMED_OUT = 0xC0000210;
608pub const TRANSACTION_NO_RELEASE = 0xC0000211;
609pub const TRANSACTION_NO_MATCH = 0xC0000212;
610pub const TRANSACTION_RESPONDED = 0xC0000213;
611pub const TRANSACTION_INVALID_ID = 0xC0000214;
612pub const TRANSACTION_INVALID_TYPE = 0xC0000215;
613pub const NOT_SERVER_SESSION = 0xC0000216;
614pub const NOT_CLIENT_SESSION = 0xC0000217;
615pub const CANNOT_LOAD_REGISTRY_FILE = 0xC0000218;
616pub const DEBUG_ATTACH_FAILED = 0xC0000219;
617pub const SYSTEM_PROCESS_TERMINATED = 0xC000021A;
618pub const DATA_NOT_ACCEPTED = 0xC000021B;
619pub const NO_BROWSER_SERVERS_FOUND = 0xC000021C;
620pub const VDM_HARD_ERROR = 0xC000021D;
621pub const DRIVER_CANCEL_TIMEOUT = 0xC000021E;
622pub const REPLY_MESSAGE_MISMATCH = 0xC000021F;
623pub const MAPPED_ALIGNMENT = 0xC0000220;
624pub const IMAGE_CHECKSUM_MISMATCH = 0xC0000221;
625pub const LOST_WRITEBEHIND_DATA = 0xC0000222;
626pub const CLIENT_SERVER_PARAMETERS_INVALID = 0xC0000223;
627pub const PASSWORD_MUST_CHANGE = 0xC0000224;
628pub const NOT_FOUND = 0xC0000225;
629pub const NOT_TINY_STREAM = 0xC0000226;
630pub const RECOVERY_FAILURE = 0xC0000227;
631pub const STACK_OVERFLOW_READ = 0xC0000228;
632pub const FAIL_CHECK = 0xC0000229;
633pub const DUPLICATE_OBJECTID = 0xC000022A;
634pub const OBJECTID_EXISTS = 0xC000022B;
635pub const CONVERT_TO_LARGE = 0xC000022C;
636pub const RETRY = 0xC000022D;
637pub const FOUND_OUT_OF_SCOPE = 0xC000022E;
638pub const ALLOCATE_BUCKET = 0xC000022F;
639pub const PROPSET_NOT_FOUND = 0xC0000230;
640pub const MARSHALL_OVERFLOW = 0xC0000231;
641pub const INVALID_VARIANT = 0xC0000232;
642pub const DOMAIN_CONTROLLER_NOT_FOUND = 0xC0000233;
643pub const ACCOUNT_LOCKED_OUT = 0xC0000234;
644pub const HANDLE_NOT_CLOSABLE = 0xC0000235;
645pub const CONNECTION_REFUSED = 0xC0000236;
646pub const GRACEFUL_DISCONNECT = 0xC0000237;
647pub const ADDRESS_ALREADY_ASSOCIATED = 0xC0000238;
648pub const ADDRESS_NOT_ASSOCIATED = 0xC0000239;
649pub const CONNECTION_INVALID = 0xC000023A;
650pub const CONNECTION_ACTIVE = 0xC000023B;
651pub const NETWORK_UNREACHABLE = 0xC000023C;
652pub const HOST_UNREACHABLE = 0xC000023D;
653pub const PROTOCOL_UNREACHABLE = 0xC000023E;
654pub const PORT_UNREACHABLE = 0xC000023F;
655pub const REQUEST_ABORTED = 0xC0000240;
656pub const CONNECTION_ABORTED = 0xC0000241;
657pub const BAD_COMPRESSION_BUFFER = 0xC0000242;
658pub const USER_MAPPED_FILE = 0xC0000243;
659pub const AUDIT_FAILED = 0xC0000244;
660pub const TIMER_RESOLUTION_NOT_SET = 0xC0000245;
661pub const CONNECTION_COUNT_LIMIT = 0xC0000246;
662pub const LOGIN_TIME_RESTRICTION = 0xC0000247;
663pub const LOGIN_WKSTA_RESTRICTION = 0xC0000248;
664pub const IMAGE_MP_UP_MISMATCH = 0xC0000249;
665pub const INSUFFICIENT_LOGON_INFO = 0xC0000250;
666pub const BAD_DLL_ENTRYPOINT = 0xC0000251;
667pub const BAD_SERVICE_ENTRYPOINT = 0xC0000252;
668pub const LPC_REPLY_LOST = 0xC0000253;
669pub const IP_ADDRESS_CONFLICT1 = 0xC0000254;
670pub const IP_ADDRESS_CONFLICT2 = 0xC0000255;
671pub const REGISTRY_QUOTA_LIMIT = 0xC0000256;
672pub const PATH_NOT_COVERED = 0xC0000257;
673pub const NO_CALLBACK_ACTIVE = 0xC0000258;
674pub const LICENSE_QUOTA_EXCEEDED = 0xC0000259;
675pub const PWD_TOO_SHORT = 0xC000025A;
676pub const PWD_TOO_RECENT = 0xC000025B;
677pub const PWD_HISTORY_CONFLICT = 0xC000025C;
678pub const PLUGPLAY_NO_DEVICE = 0xC000025E;
679pub const UNSUPPORTED_COMPRESSION = 0xC000025F;
680pub const INVALID_HW_PROFILE = 0xC0000260;
681pub const INVALID_PLUGPLAY_DEVICE_PATH = 0xC0000261;
682pub const DRIVER_ORDINAL_NOT_FOUND = 0xC0000262;
683pub const DRIVER_ENTRYPOINT_NOT_FOUND = 0xC0000263;
684pub const RESOURCE_NOT_OWNED = 0xC0000264;
685pub const TOO_MANY_LINKS = 0xC0000265;
686pub const QUOTA_LIST_INCONSISTENT = 0xC0000266;
687pub const FILE_IS_OFFLINE = 0xC0000267;
688pub const EVALUATION_EXPIRATION = 0xC0000268;
689pub const ILLEGAL_DLL_RELOCATION = 0xC0000269;
690pub const LICENSE_VIOLATION = 0xC000026A;
691pub const DLL_INIT_FAILED_LOGOFF = 0xC000026B;
692pub const DRIVER_UNABLE_TO_LOAD = 0xC000026C;
693pub const DFS_UNAVAILABLE = 0xC000026D;
694pub const VOLUME_DISMOUNTED = 0xC000026E;
695pub const WX86_INTERNAL_ERROR = 0xC000026F;
696pub const WX86_FLOAT_STACK_CHECK = 0xC0000270;
697pub const VALIDATE_CONTINUE = 0xC0000271;
698pub const NO_MATCH = 0xC0000272;
699pub const NO_MORE_MATCHES = 0xC0000273;
700pub const NOT_A_REPARSE_POINT = 0xC0000275;
701pub const IO_REPARSE_TAG_INVALID = 0xC0000276;
702pub const IO_REPARSE_TAG_MISMATCH = 0xC0000277;
703pub const IO_REPARSE_DATA_INVALID = 0xC0000278;
704pub const IO_REPARSE_TAG_NOT_HANDLED = 0xC0000279;
705pub const REPARSE_POINT_NOT_RESOLVED = 0xC0000280;
706pub const DIRECTORY_IS_A_REPARSE_POINT = 0xC0000281;
707pub const RANGE_LIST_CONFLICT = 0xC0000282;
708pub const SOURCE_ELEMENT_EMPTY = 0xC0000283;
709pub const DESTINATION_ELEMENT_FULL = 0xC0000284;
710pub const ILLEGAL_ELEMENT_ADDRESS = 0xC0000285;
711pub const MAGAZINE_NOT_PRESENT = 0xC0000286;
712pub const REINITIALIZATION_NEEDED = 0xC0000287;
713pub const ENCRYPTION_FAILED = 0xC000028A;
714pub const DECRYPTION_FAILED = 0xC000028B;
715pub const RANGE_NOT_FOUND = 0xC000028C;
716pub const NO_RECOVERY_POLICY = 0xC000028D;
717pub const NO_EFS = 0xC000028E;
718pub const WRONG_EFS = 0xC000028F;
719pub const NO_USER_KEYS = 0xC0000290;
720pub const FILE_NOT_ENCRYPTED = 0xC0000291;
721pub const NOT_EXPORT_FORMAT = 0xC0000292;
722pub const FILE_ENCRYPTED = 0xC0000293;
723pub const WMI_GUID_NOT_FOUND = 0xC0000295;
724pub const WMI_INSTANCE_NOT_FOUND = 0xC0000296;
725pub const WMI_ITEMID_NOT_FOUND = 0xC0000297;
726pub const WMI_TRY_AGAIN = 0xC0000298;
727pub const SHARED_POLICY = 0xC0000299;
728pub const POLICY_OBJECT_NOT_FOUND = 0xC000029A;
729pub const POLICY_ONLY_IN_DS = 0xC000029B;
730pub const VOLUME_NOT_UPGRADED = 0xC000029C;
731pub const REMOTE_STORAGE_NOT_ACTIVE = 0xC000029D;
732pub const REMOTE_STORAGE_MEDIA_ERROR = 0xC000029E;
733pub const NO_TRACKING_SERVICE = 0xC000029F;
734pub const SERVER_SID_MISMATCH = 0xC00002A0;
735pub const DS_NO_ATTRIBUTE_OR_VALUE = 0xC00002A1;
736pub const DS_INVALID_ATTRIBUTE_SYNTAX = 0xC00002A2;
737pub const DS_ATTRIBUTE_TYPE_UNDEFINED = 0xC00002A3;
738pub const DS_ATTRIBUTE_OR_VALUE_EXISTS = 0xC00002A4;
739pub const DS_BUSY = 0xC00002A5;
740pub const DS_UNAVAILABLE = 0xC00002A6;
741pub const DS_NO_RIDS_ALLOCATED = 0xC00002A7;
742pub const DS_NO_MORE_RIDS = 0xC00002A8;
743pub const DS_INCORRECT_ROLE_OWNER = 0xC00002A9;
744pub const DS_RIDMGR_INIT_ERROR = 0xC00002AA;
745pub const DS_OBJ_CLASS_VIOLATION = 0xC00002AB;
746pub const DS_CANT_ON_NON_LEAF = 0xC00002AC;
747pub const DS_CANT_ON_RDN = 0xC00002AD;
748pub const DS_CANT_MOD_OBJ_CLASS = 0xC00002AE;
749pub const DS_CROSS_DOM_MOVE_FAILED = 0xC00002AF;
750pub const DS_GC_NOT_AVAILABLE = 0xC00002B0;
751pub const DIRECTORY_SERVICE_REQUIRED = 0xC00002B1;
752pub const REPARSE_ATTRIBUTE_CONFLICT = 0xC00002B2;
753pub const CANT_ENABLE_DENY_ONLY = 0xC00002B3;
754pub const FLOAT_MULTIPLE_FAULTS = 0xC00002B4;
755pub const FLOAT_MULTIPLE_TRAPS = 0xC00002B5;
756pub const DEVICE_REMOVED = 0xC00002B6;
757pub const JOURNAL_DELETE_IN_PROGRESS = 0xC00002B7;
758pub const JOURNAL_NOT_ACTIVE = 0xC00002B8;
759pub const NOINTERFACE = 0xC00002B9;
760pub const DS_ADMIN_LIMIT_EXCEEDED = 0xC00002C1;
761pub const DRIVER_FAILED_SLEEP = 0xC00002C2;
762pub const MUTUAL_AUTHENTICATION_FAILED = 0xC00002C3;
763pub const CORRUPT_SYSTEM_FILE = 0xC00002C4;
764pub const DATATYPE_MISALIGNMENT_ERROR = 0xC00002C5;
765pub const WMI_READ_ONLY = 0xC00002C6;
766pub const WMI_SET_FAILURE = 0xC00002C7;
767pub const COMMITMENT_MINIMUM = 0xC00002C8;
768pub const REG_NAT_CONSUMPTION = 0xC00002C9;
769pub const TRANSPORT_FULL = 0xC00002CA;
770pub const DS_SAM_INIT_FAILURE = 0xC00002CB;
771pub const ONLY_IF_CONNECTED = 0xC00002CC;
772pub const DS_SENSITIVE_GROUP_VIOLATION = 0xC00002CD;
773pub const PNP_RESTART_ENUMERATION = 0xC00002CE;
774pub const JOURNAL_ENTRY_DELETED = 0xC00002CF;
775pub const DS_CANT_MOD_PRIMARYGROUPID = 0xC00002D0;
776pub const SYSTEM_IMAGE_BAD_SIGNATURE = 0xC00002D1;
777pub const PNP_REBOOT_REQUIRED = 0xC00002D2;
778pub const POWER_STATE_INVALID = 0xC00002D3;
779pub const DS_INVALID_GROUP_TYPE = 0xC00002D4;
780pub const DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN = 0xC00002D5;
781pub const DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN = 0xC00002D6;
782pub const DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER = 0xC00002D7;
783pub const DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER = 0xC00002D8;
784pub const DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER = 0xC00002D9;
785pub const DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER = 0xC00002DA;
786pub const DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER = 0xC00002DB;
787pub const DS_HAVE_PRIMARY_MEMBERS = 0xC00002DC;
788pub const WMI_NOT_SUPPORTED = 0xC00002DD;
789pub const INSUFFICIENT_POWER = 0xC00002DE;
790pub const SAM_NEED_BOOTKEY_PASSWORD = 0xC00002DF;
791pub const SAM_NEED_BOOTKEY_FLOPPY = 0xC00002E0;
792pub const DS_CANT_START = 0xC00002E1;
793pub const DS_INIT_FAILURE = 0xC00002E2;
794pub const SAM_INIT_FAILURE = 0xC00002E3;
795pub const DS_GC_REQUIRED = 0xC00002E4;
796pub const DS_LOCAL_MEMBER_OF_LOCAL_ONLY = 0xC00002E5;
797pub const DS_NO_FPO_IN_UNIVERSAL_GROUPS = 0xC00002E6;
798pub const DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED = 0xC00002E7;
799pub const CURRENT_DOMAIN_NOT_ALLOWED = 0xC00002E9;
800pub const CANNOT_MAKE = 0xC00002EA;
801pub const SYSTEM_SHUTDOWN = 0xC00002EB;
802pub const DS_INIT_FAILURE_CONSOLE = 0xC00002EC;
803pub const DS_SAM_INIT_FAILURE_CONSOLE = 0xC00002ED;
804pub const UNFINISHED_CONTEXT_DELETED = 0xC00002EE;
805pub const NO_TGT_REPLY = 0xC00002EF;
806pub const OBJECTID_NOT_FOUND = 0xC00002F0;
807pub const NO_IP_ADDRESSES = 0xC00002F1;
808pub const WRONG_CREDENTIAL_HANDLE = 0xC00002F2;
809pub const CRYPTO_SYSTEM_INVALID = 0xC00002F3;
810pub const MAX_REFERRALS_EXCEEDED = 0xC00002F4;
811pub const MUST_BE_KDC = 0xC00002F5;
812pub const STRONG_CRYPTO_NOT_SUPPORTED = 0xC00002F6;
813pub const TOO_MANY_PRINCIPALS = 0xC00002F7;
814pub const NO_PA_DATA = 0xC00002F8;
815pub const PKINIT_NAME_MISMATCH = 0xC00002F9;
816pub const SMARTCARD_LOGON_REQUIRED = 0xC00002FA;
817pub const KDC_INVALID_REQUEST = 0xC00002FB;
818pub const KDC_UNABLE_TO_REFER = 0xC00002FC;
819pub const KDC_UNKNOWN_ETYPE = 0xC00002FD;
820pub const SHUTDOWN_IN_PROGRESS = 0xC00002FE;
821pub const SERVER_SHUTDOWN_IN_PROGRESS = 0xC00002FF;
822pub const NOT_SUPPORTED_ON_SBS = 0xC0000300;
823pub const WMI_GUID_DISCONNECTED = 0xC0000301;
824pub const WMI_ALREADY_DISABLED = 0xC0000302;
825pub const WMI_ALREADY_ENABLED = 0xC0000303;
826pub const MFT_TOO_FRAGMENTED = 0xC0000304;
827pub const COPY_PROTECTION_FAILURE = 0xC0000305;
828pub const CSS_AUTHENTICATION_FAILURE = 0xC0000306;
829pub const CSS_KEY_NOT_PRESENT = 0xC0000307;
830pub const CSS_KEY_NOT_ESTABLISHED = 0xC0000308;
831pub const CSS_SCRAMBLED_SECTOR = 0xC0000309;
832pub const CSS_REGION_MISMATCH = 0xC000030A;
833pub const CSS_RESETS_EXHAUSTED = 0xC000030B;
834pub const PKINIT_FAILURE = 0xC0000320;
835pub const SMARTCARD_SUBSYSTEM_FAILURE = 0xC0000321;
836pub const NO_KERB_KEY = 0xC0000322;
837pub const HOST_DOWN = 0xC0000350;
838pub const UNSUPPORTED_PREAUTH = 0xC0000351;
839pub const EFS_ALG_BLOB_TOO_BIG = 0xC0000352;
840pub const PORT_NOT_SET = 0xC0000353;
841pub const DEBUGGER_INACTIVE = 0xC0000354;
842pub const DS_VERSION_CHECK_FAILURE = 0xC0000355;
843pub const AUDITING_DISABLED = 0xC0000356;
844pub const PRENT4_MACHINE_ACCOUNT = 0xC0000357;
845pub const DS_AG_CANT_HAVE_UNIVERSAL_MEMBER = 0xC0000358;
846pub const INVALID_IMAGE_WIN_32 = 0xC0000359;
847pub const INVALID_IMAGE_WIN_64 = 0xC000035A;
848pub const BAD_BINDINGS = 0xC000035B;
849pub const NETWORK_SESSION_EXPIRED = 0xC000035C;
850pub const APPHELP_BLOCK = 0xC000035D;
851pub const ALL_SIDS_FILTERED = 0xC000035E;
852pub const NOT_SAFE_MODE_DRIVER = 0xC000035F;
853pub const ACCESS_DISABLED_BY_POLICY_DEFAULT = 0xC0000361;
854pub const ACCESS_DISABLED_BY_POLICY_PATH = 0xC0000362;
855pub const ACCESS_DISABLED_BY_POLICY_PUBLISHER = 0xC0000363;
856pub const ACCESS_DISABLED_BY_POLICY_OTHER = 0xC0000364;
857pub const FAILED_DRIVER_ENTRY = 0xC0000365;
858pub const DEVICE_ENUMERATION_ERROR = 0xC0000366;
859pub const MOUNT_POINT_NOT_RESOLVED = 0xC0000368;
860pub const INVALID_DEVICE_OBJECT_PARAMETER = 0xC0000369;
861pub const MCA_OCCURED = 0xC000036A;
862pub const DRIVER_BLOCKED_CRITICAL = 0xC000036B;
863pub const DRIVER_BLOCKED = 0xC000036C;
864pub const DRIVER_DATABASE_ERROR = 0xC000036D;
865pub const SYSTEM_HIVE_TOO_LARGE = 0xC000036E;
866pub const INVALID_IMPORT_OF_NON_DLL = 0xC000036F;
867pub const NO_SECRETS = 0xC0000371;
868pub const ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY = 0xC0000372;
869pub const FAILED_STACK_SWITCH = 0xC0000373;
870pub const HEAP_CORRUPTION = 0xC0000374;
871pub const SMARTCARD_WRONG_PIN = 0xC0000380;
872pub const SMARTCARD_CARD_BLOCKED = 0xC0000381;
873pub const SMARTCARD_CARD_NOT_AUTHENTICATED = 0xC0000382;
874pub const SMARTCARD_NO_CARD = 0xC0000383;
875pub const SMARTCARD_NO_KEY_CONTAINER = 0xC0000384;
876pub const SMARTCARD_NO_CERTIFICATE = 0xC0000385;
877pub const SMARTCARD_NO_KEYSET = 0xC0000386;
878pub const SMARTCARD_IO_ERROR = 0xC0000387;
879pub const DOWNGRADE_DETECTED = 0xC0000388;
880pub const SMARTCARD_CERT_REVOKED = 0xC0000389;
881pub const ISSUING_CA_UNTRUSTED = 0xC000038A;
882pub const REVOCATION_OFFLINE_C = 0xC000038B;
883pub const PKINIT_CLIENT_FAILURE = 0xC000038C;
884pub const SMARTCARD_CERT_EXPIRED = 0xC000038D;
885pub const DRIVER_FAILED_PRIOR_UNLOAD = 0xC000038E;
886pub const SMARTCARD_SILENT_CONTEXT = 0xC000038F;
887pub const PER_USER_TRUST_QUOTA_EXCEEDED = 0xC0000401;
888pub const ALL_USER_TRUST_QUOTA_EXCEEDED = 0xC0000402;
889pub const USER_DELETE_TRUST_QUOTA_EXCEEDED = 0xC0000403;
890pub const DS_NAME_NOT_UNIQUE = 0xC0000404;
891pub const DS_DUPLICATE_ID_FOUND = 0xC0000405;
892pub const DS_GROUP_CONVERSION_ERROR = 0xC0000406;
893pub const VOLSNAP_PREPARE_HIBERNATE = 0xC0000407;
894pub const USER2USER_REQUIRED = 0xC0000408;
895pub const STACK_BUFFER_OVERRUN = 0xC0000409;
896pub const NO_S4U_PROT_SUPPORT = 0xC000040A;
897pub const CROSSREALM_DELEGATION_FAILURE = 0xC000040B;
898pub const REVOCATION_OFFLINE_KDC = 0xC000040C;
899pub const ISSUING_CA_UNTRUSTED_KDC = 0xC000040D;
900pub const KDC_CERT_EXPIRED = 0xC000040E;
901pub const KDC_CERT_REVOKED = 0xC000040F;
902pub const PARAMETER_QUOTA_EXCEEDED = 0xC0000410;
903pub const HIBERNATION_FAILURE = 0xC0000411;
904pub const DELAY_LOAD_FAILED = 0xC0000412;
905pub const AUTHENTICATION_FIREWALL_FAILED = 0xC0000413;
906pub const VDM_DISALLOWED = 0xC0000414;
907pub const HUNG_DISPLAY_DRIVER_THREAD = 0xC0000415;
908pub const INSUFFICIENT_RESOURCE_FOR_SPECIFIED_SHARED_SECTION_SIZE = 0xC0000416;
909pub const INVALID_CRUNTIME_PARAMETER = 0xC0000417;
910pub const NTLM_BLOCKED = 0xC0000418;
911pub const DS_SRC_SID_EXISTS_IN_FOREST = 0xC0000419;
912pub const DS_DOMAIN_NAME_EXISTS_IN_FOREST = 0xC000041A;
913pub const DS_FLAT_NAME_EXISTS_IN_FOREST = 0xC000041B;
914pub const INVALID_USER_PRINCIPAL_NAME = 0xC000041C;
915pub const ASSERTION_FAILURE = 0xC0000420;
916pub const VERIFIER_STOP = 0xC0000421;
917pub const CALLBACK_POP_STACK = 0xC0000423;
918pub const INCOMPATIBLE_DRIVER_BLOCKED = 0xC0000424;
919pub const HIVE_UNLOADED = 0xC0000425;
920pub const COMPRESSION_DISABLED = 0xC0000426;
921pub const FILE_SYSTEM_LIMITATION = 0xC0000427;
922pub const INVALID_IMAGE_HASH = 0xC0000428;
923pub const NOT_CAPABLE = 0xC0000429;
924pub const REQUEST_OUT_OF_SEQUENCE = 0xC000042A;
925pub const IMPLEMENTATION_LIMIT = 0xC000042B;
926pub const ELEVATION_REQUIRED = 0xC000042C;
927pub const NO_SECURITY_CONTEXT = 0xC000042D;
928pub const PKU2U_CERT_FAILURE = 0xC000042E;
929pub const BEYOND_VDL = 0xC0000432;
930pub const ENCOUNTERED_WRITE_IN_PROGRESS = 0xC0000433;
931pub const PTE_CHANGED = 0xC0000434;
932pub const PURGE_FAILED = 0xC0000435;
933pub const CRED_REQUIRES_CONFIRMATION = 0xC0000440;
934pub const CS_ENCRYPTION_INVALID_SERVER_RESPONSE = 0xC0000441;
935pub const CS_ENCRYPTION_UNSUPPORTED_SERVER = 0xC0000442;
936pub const CS_ENCRYPTION_EXISTING_ENCRYPTED_FILE = 0xC0000443;
937pub const CS_ENCRYPTION_NEW_ENCRYPTED_FILE = 0xC0000444;
938pub const CS_ENCRYPTION_FILE_NOT_CSE = 0xC0000445;
939pub const INVALID_LABEL = 0xC0000446;
940pub const DRIVER_PROCESS_TERMINATED = 0xC0000450;
941pub const AMBIGUOUS_SYSTEM_DEVICE = 0xC0000451;
942pub const SYSTEM_DEVICE_NOT_FOUND = 0xC0000452;
943pub const RESTART_BOOT_APPLICATION = 0xC0000453;
944pub const INSUFFICIENT_NVRAM_RESOURCES = 0xC0000454;
945pub const INVALID_TASK_NAME = 0xC0000500;
946pub const INVALID_TASK_INDEX = 0xC0000501;
947pub const THREAD_ALREADY_IN_TASK = 0xC0000502;
948pub const CALLBACK_BYPASS = 0xC0000503;
949pub const FAIL_FAST_EXCEPTION = 0xC0000602;
950pub const IMAGE_CERT_REVOKED = 0xC0000603;
951pub const PORT_CLOSED = 0xC0000700;
952pub const MESSAGE_LOST = 0xC0000701;
953pub const INVALID_MESSAGE = 0xC0000702;
954pub const REQUEST_CANCELED = 0xC0000703;
955pub const RECURSIVE_DISPATCH = 0xC0000704;
956pub const LPC_RECEIVE_BUFFER_EXPECTED = 0xC0000705;
957pub const LPC_INVALID_CONNECTION_USAGE = 0xC0000706;
958pub const LPC_REQUESTS_NOT_ALLOWED = 0xC0000707;
959pub const RESOURCE_IN_USE = 0xC0000708;
960pub const HARDWARE_MEMORY_ERROR = 0xC0000709;
961pub const THREADPOOL_HANDLE_EXCEPTION = 0xC000070A;
962pub const THREADPOOL_SET_EVENT_ON_COMPLETION_FAILED = 0xC000070B;
963pub const THREADPOOL_RELEASE_SEMAPHORE_ON_COMPLETION_FAILED = 0xC000070C;
964pub const THREADPOOL_RELEASE_MUTEX_ON_COMPLETION_FAILED = 0xC000070D;
965pub const THREADPOOL_FREE_LIBRARY_ON_COMPLETION_FAILED = 0xC000070E;
966pub const THREADPOOL_RELEASED_DURING_OPERATION = 0xC000070F;
967pub const CALLBACK_RETURNED_WHILE_IMPERSONATING = 0xC0000710;
968pub const APC_RETURNED_WHILE_IMPERSONATING = 0xC0000711;
969pub const PROCESS_IS_PROTECTED = 0xC0000712;
970pub const MCA_EXCEPTION = 0xC0000713;
971pub const CERTIFICATE_MAPPING_NOT_UNIQUE = 0xC0000714;
972pub const SYMLINK_CLASS_DISABLED = 0xC0000715;
973pub const INVALID_IDN_NORMALIZATION = 0xC0000716;
974pub const NO_UNICODE_TRANSLATION = 0xC0000717;
975pub const ALREADY_REGISTERED = 0xC0000718;
976pub const CONTEXT_MISMATCH = 0xC0000719;
977pub const PORT_ALREADY_HAS_COMPLETION_LIST = 0xC000071A;
978pub const CALLBACK_RETURNED_THREAD_PRIORITY = 0xC000071B;
979pub const INVALID_THREAD = 0xC000071C;
980pub const CALLBACK_RETURNED_TRANSACTION = 0xC000071D;
981pub const CALLBACK_RETURNED_LDR_LOCK = 0xC000071E;
982pub const CALLBACK_RETURNED_LANG = 0xC000071F;
983pub const CALLBACK_RETURNED_PRI_BACK = 0xC0000720;
984pub const DISK_REPAIR_DISABLED = 0xC0000800;
985pub const DS_DOMAIN_RENAME_IN_PROGRESS = 0xC0000801;
986pub const DISK_QUOTA_EXCEEDED = 0xC0000802;
987pub const CONTENT_BLOCKED = 0xC0000804;
988pub const BAD_CLUSTERS = 0xC0000805;
989pub const VOLUME_DIRTY = 0xC0000806;
990pub const FILE_CHECKED_OUT = 0xC0000901;
991pub const CHECKOUT_REQUIRED = 0xC0000902;
992pub const BAD_FILE_TYPE = 0xC0000903;
993pub const FILE_TOO_LARGE = 0xC0000904;
994pub const FORMS_AUTH_REQUIRED = 0xC0000905;
995pub const VIRUS_INFECTED = 0xC0000906;
996pub const VIRUS_DELETED = 0xC0000907;
997pub const BAD_MCFG_TABLE = 0xC0000908;
998pub const CANNOT_BREAK_OPLOCK = 0xC0000909;
999pub const WOW_ASSERTION = 0xC0009898;
1000pub const INVALID_SIGNATURE = 0xC000A000;
1001pub const HMAC_NOT_SUPPORTED = 0xC000A001;
1002pub const IPSEC_QUEUE_OVERFLOW = 0xC000A010;
1003pub const ND_QUEUE_OVERFLOW = 0xC000A011;
1004pub const HOPLIMIT_EXCEEDED = 0xC000A012;
1005pub const PROTOCOL_NOT_SUPPORTED = 0xC000A013;
1006pub const LOST_WRITEBEHIND_DATA_NETWORK_DISCONNECTED = 0xC000A080;
1007pub const LOST_WRITEBEHIND_DATA_NETWORK_SERVER_ERROR = 0xC000A081;
1008pub const LOST_WRITEBEHIND_DATA_LOCAL_DISK_ERROR = 0xC000A082;
1009pub const XML_PARSE_ERROR = 0xC000A083;
1010pub const XMLDSIG_ERROR = 0xC000A084;
1011pub const WRONG_COMPARTMENT = 0xC000A085;
1012pub const AUTHIP_FAILURE = 0xC000A086;
1013pub const DS_OID_MAPPED_GROUP_CANT_HAVE_MEMBERS = 0xC000A087;
1014pub const DS_OID_NOT_FOUND = 0xC000A088;
1015pub const HASH_NOT_SUPPORTED = 0xC000A100;
1016pub const HASH_NOT_PRESENT = 0xC000A101;
1017pub const PNP_BAD_MPS_TABLE = 0xC0040035;
1018pub const PNP_TRANSLATION_FAILED = 0xC0040036;
1019pub const PNP_IRQ_TRANSLATION_FAILED = 0xC0040037;
1020pub const PNP_INVALID_ID = 0xC0040038;
1021pub const IO_REISSUE_AS_CACHED = 0xC0040039;
1022pub const CTX_WINSTATION_NAME_INVALID = 0xC00A0001;
1023pub const CTX_INVALID_PD = 0xC00A0002;
1024pub const CTX_PD_NOT_FOUND = 0xC00A0003;
1025pub const CTX_CLOSE_PENDING = 0xC00A0006;
1026pub const CTX_NO_OUTBUF = 0xC00A0007;
1027pub const CTX_MODEM_INF_NOT_FOUND = 0xC00A0008;
1028pub const CTX_INVALID_MODEMNAME = 0xC00A0009;
1029pub const CTX_RESPONSE_ERROR = 0xC00A000A;
1030pub const CTX_MODEM_RESPONSE_TIMEOUT = 0xC00A000B;
1031pub const CTX_MODEM_RESPONSE_NO_CARRIER = 0xC00A000C;
1032pub const CTX_MODEM_RESPONSE_NO_DIALTONE = 0xC00A000D;
1033pub const CTX_MODEM_RESPONSE_BUSY = 0xC00A000E;
1034pub const CTX_MODEM_RESPONSE_VOICE = 0xC00A000F;
1035pub const CTX_TD_ERROR = 0xC00A0010;
1036pub const CTX_LICENSE_CLIENT_INVALID = 0xC00A0012;
1037pub const CTX_LICENSE_NOT_AVAILABLE = 0xC00A0013;
1038pub const CTX_LICENSE_EXPIRED = 0xC00A0014;
1039pub const CTX_WINSTATION_NOT_FOUND = 0xC00A0015;
1040pub const CTX_WINSTATION_NAME_COLLISION = 0xC00A0016;
1041pub const CTX_WINSTATION_BUSY = 0xC00A0017;
1042pub const CTX_BAD_VIDEO_MODE = 0xC00A0018;
1043pub const CTX_GRAPHICS_INVALID = 0xC00A0022;
1044pub const CTX_NOT_CONSOLE = 0xC00A0024;
1045pub const CTX_CLIENT_QUERY_TIMEOUT = 0xC00A0026;
1046pub const CTX_CONSOLE_DISCONNECT = 0xC00A0027;
1047pub const CTX_CONSOLE_CONNECT = 0xC00A0028;
1048pub const CTX_SHADOW_DENIED = 0xC00A002A;
1049pub const CTX_WINSTATION_ACCESS_DENIED = 0xC00A002B;
1050pub const CTX_INVALID_WD = 0xC00A002E;
1051pub const CTX_WD_NOT_FOUND = 0xC00A002F;
1052pub const CTX_SHADOW_INVALID = 0xC00A0030;
1053pub const CTX_SHADOW_DISABLED = 0xC00A0031;
1054pub const RDP_PROTOCOL_ERROR = 0xC00A0032;
1055pub const CTX_CLIENT_LICENSE_NOT_SET = 0xC00A0033;
1056pub const CTX_CLIENT_LICENSE_IN_USE = 0xC00A0034;
1057pub const CTX_SHADOW_ENDED_BY_MODE_CHANGE = 0xC00A0035;
1058pub const CTX_SHADOW_NOT_RUNNING = 0xC00A0036;
1059pub const CTX_LOGON_DISABLED = 0xC00A0037;
1060pub const CTX_SECURITY_LAYER_ERROR = 0xC00A0038;
1061pub const TS_INCOMPATIBLE_SESSIONS = 0xC00A0039;
1062pub const MUI_FILE_NOT_FOUND = 0xC00B0001;
1063pub const MUI_INVALID_FILE = 0xC00B0002;
1064pub const MUI_INVALID_RC_CONFIG = 0xC00B0003;
1065pub const MUI_INVALID_LOCALE_NAME = 0xC00B0004;
1066pub const MUI_INVALID_ULTIMATEFALLBACK_NAME = 0xC00B0005;
1067pub const MUI_FILE_NOT_LOADED = 0xC00B0006;
1068pub const RESOURCE_ENUM_USER_STOP = 0xC00B0007;
1069pub const CLUSTER_INVALID_NODE = 0xC0130001;
1070pub const CLUSTER_NODE_EXISTS = 0xC0130002;
1071pub const CLUSTER_JOIN_IN_PROGRESS = 0xC0130003;
1072pub const CLUSTER_NODE_NOT_FOUND = 0xC0130004;
1073pub const CLUSTER_LOCAL_NODE_NOT_FOUND = 0xC0130005;
1074pub const CLUSTER_NETWORK_EXISTS = 0xC0130006;
1075pub const CLUSTER_NETWORK_NOT_FOUND = 0xC0130007;
1076pub const CLUSTER_NETINTERFACE_EXISTS = 0xC0130008;
1077pub const CLUSTER_NETINTERFACE_NOT_FOUND = 0xC0130009;
1078pub const CLUSTER_INVALID_REQUEST = 0xC013000A;
1079pub const CLUSTER_INVALID_NETWORK_PROVIDER = 0xC013000B;
1080pub const CLUSTER_NODE_DOWN = 0xC013000C;
1081pub const CLUSTER_NODE_UNREACHABLE = 0xC013000D;
1082pub const CLUSTER_NODE_NOT_MEMBER = 0xC013000E;
1083pub const CLUSTER_JOIN_NOT_IN_PROGRESS = 0xC013000F;
1084pub const CLUSTER_INVALID_NETWORK = 0xC0130010;
1085pub const CLUSTER_NO_NET_ADAPTERS = 0xC0130011;
1086pub const CLUSTER_NODE_UP = 0xC0130012;
1087pub const CLUSTER_NODE_PAUSED = 0xC0130013;
1088pub const CLUSTER_NODE_NOT_PAUSED = 0xC0130014;
1089pub const CLUSTER_NO_SECURITY_CONTEXT = 0xC0130015;
1090pub const CLUSTER_NETWORK_NOT_INTERNAL = 0xC0130016;
1091pub const CLUSTER_POISONED = 0xC0130017;
1092pub const ACPI_INVALID_OPCODE = 0xC0140001;
1093pub const ACPI_STACK_OVERFLOW = 0xC0140002;
1094pub const ACPI_ASSERT_FAILED = 0xC0140003;
1095pub const ACPI_INVALID_INDEX = 0xC0140004;
1096pub const ACPI_INVALID_ARGUMENT = 0xC0140005;
1097pub const ACPI_FATAL = 0xC0140006;
1098pub const ACPI_INVALID_SUPERNAME = 0xC0140007;
1099pub const ACPI_INVALID_ARGTYPE = 0xC0140008;
1100pub const ACPI_INVALID_OBJTYPE = 0xC0140009;
1101pub const ACPI_INVALID_TARGETTYPE = 0xC014000A;
1102pub const ACPI_INCORRECT_ARGUMENT_COUNT = 0xC014000B;
1103pub const ACPI_ADDRESS_NOT_MAPPED = 0xC014000C;
1104pub const ACPI_INVALID_EVENTTYPE = 0xC014000D;
1105pub const ACPI_HANDLER_COLLISION = 0xC014000E;
1106pub const ACPI_INVALID_DATA = 0xC014000F;
1107pub const ACPI_INVALID_REGION = 0xC0140010;
1108pub const ACPI_INVALID_ACCESS_SIZE = 0xC0140011;
1109pub const ACPI_ACQUIRE_GLOBAL_LOCK = 0xC0140012;
1110pub const ACPI_ALREADY_INITIALIZED = 0xC0140013;
1111pub const ACPI_NOT_INITIALIZED = 0xC0140014;
1112pub const ACPI_INVALID_MUTEX_LEVEL = 0xC0140015;
1113pub const ACPI_MUTEX_NOT_OWNED = 0xC0140016;
1114pub const ACPI_MUTEX_NOT_OWNER = 0xC0140017;
1115pub const ACPI_RS_ACCESS = 0xC0140018;
1116pub const ACPI_INVALID_TABLE = 0xC0140019;
1117pub const ACPI_REG_HANDLER_FAILED = 0xC0140020;
1118pub const ACPI_POWER_REQUEST_FAILED = 0xC0140021;
1119pub const SXS_SECTION_NOT_FOUND = 0xC0150001;
1120pub const SXS_CANT_GEN_ACTCTX = 0xC0150002;
1121pub const SXS_INVALID_ACTCTXDATA_FORMAT = 0xC0150003;
1122pub const SXS_ASSEMBLY_NOT_FOUND = 0xC0150004;
1123pub const SXS_MANIFEST_FORMAT_ERROR = 0xC0150005;
1124pub const SXS_MANIFEST_PARSE_ERROR = 0xC0150006;
1125pub const SXS_ACTIVATION_CONTEXT_DISABLED = 0xC0150007;
1126pub const SXS_KEY_NOT_FOUND = 0xC0150008;
1127pub const SXS_VERSION_CONFLICT = 0xC0150009;
1128pub const SXS_WRONG_SECTION_TYPE = 0xC015000A;
1129pub const SXS_THREAD_QUERIES_DISABLED = 0xC015000B;
1130pub const SXS_ASSEMBLY_MISSING = 0xC015000C;
1131pub const SXS_PROCESS_DEFAULT_ALREADY_SET = 0xC015000E;
1132pub const SXS_EARLY_DEACTIVATION = 0xC015000F;
1133pub const SXS_INVALID_DEACTIVATION = 0xC0150010;
1134pub const SXS_MULTIPLE_DEACTIVATION = 0xC0150011;
1135pub const SXS_SYSTEM_DEFAULT_ACTIVATION_CONTEXT_EMPTY = 0xC0150012;
1136pub const SXS_PROCESS_TERMINATION_REQUESTED = 0xC0150013;
1137pub const SXS_CORRUPT_ACTIVATION_STACK = 0xC0150014;
1138pub const SXS_CORRUPTION = 0xC0150015;
1139pub const SXS_INVALID_IDENTITY_ATTRIBUTE_VALUE = 0xC0150016;
1140pub const SXS_INVALID_IDENTITY_ATTRIBUTE_NAME = 0xC0150017;
1141pub const SXS_IDENTITY_DUPLICATE_ATTRIBUTE = 0xC0150018;
1142pub const SXS_IDENTITY_PARSE_ERROR = 0xC0150019;
1143pub const SXS_COMPONENT_STORE_CORRUPT = 0xC015001A;
1144pub const SXS_FILE_HASH_MISMATCH = 0xC015001B;
1145pub const SXS_MANIFEST_IDENTITY_SAME_BUT_CONTENTS_DIFFERENT = 0xC015001C;
1146pub const SXS_IDENTITIES_DIFFERENT = 0xC015001D;
1147pub const SXS_ASSEMBLY_IS_NOT_A_DEPLOYMENT = 0xC015001E;
1148pub const SXS_FILE_NOT_PART_OF_ASSEMBLY = 0xC015001F;
1149pub const ADVANCED_INSTALLER_FAILED = 0xC0150020;
1150pub const XML_ENCODING_MISMATCH = 0xC0150021;
1151pub const SXS_MANIFEST_TOO_BIG = 0xC0150022;
1152pub const SXS_SETTING_NOT_REGISTERED = 0xC0150023;
1153pub const SXS_TRANSACTION_CLOSURE_INCOMPLETE = 0xC0150024;
1154pub const SMI_PRIMITIVE_INSTALLER_FAILED = 0xC0150025;
1155pub const GENERIC_COMMAND_FAILED = 0xC0150026;
1156pub const SXS_FILE_HASH_MISSING = 0xC0150027;
1157pub const TRANSACTIONAL_CONFLICT = 0xC0190001;
1158pub const INVALID_TRANSACTION = 0xC0190002;
1159pub const TRANSACTION_NOT_ACTIVE = 0xC0190003;
1160pub const TM_INITIALIZATION_FAILED = 0xC0190004;
1161pub const RM_NOT_ACTIVE = 0xC0190005;
1162pub const RM_METADATA_CORRUPT = 0xC0190006;
1163pub const TRANSACTION_NOT_JOINED = 0xC0190007;
1164pub const DIRECTORY_NOT_RM = 0xC0190008;
1165pub const TRANSACTIONS_UNSUPPORTED_REMOTE = 0xC019000A;
1166pub const LOG_RESIZE_INVALID_SIZE = 0xC019000B;
1167pub const REMOTE_FILE_VERSION_MISMATCH = 0xC019000C;
1168pub const CRM_PROTOCOL_ALREADY_EXISTS = 0xC019000F;
1169pub const TRANSACTION_PROPAGATION_FAILED = 0xC0190010;
1170pub const CRM_PROTOCOL_NOT_FOUND = 0xC0190011;
1171pub const TRANSACTION_SUPERIOR_EXISTS = 0xC0190012;
1172pub const TRANSACTION_REQUEST_NOT_VALID = 0xC0190013;
1173pub const TRANSACTION_NOT_REQUESTED = 0xC0190014;
1174pub const TRANSACTION_ALREADY_ABORTED = 0xC0190015;
1175pub const TRANSACTION_ALREADY_COMMITTED = 0xC0190016;
1176pub const TRANSACTION_INVALID_MARSHALL_BUFFER = 0xC0190017;
1177pub const CURRENT_TRANSACTION_NOT_VALID = 0xC0190018;
1178pub const LOG_GROWTH_FAILED = 0xC0190019;
1179pub const OBJECT_NO_LONGER_EXISTS = 0xC0190021;
1180pub const STREAM_MINIVERSION_NOT_FOUND = 0xC0190022;
1181pub const STREAM_MINIVERSION_NOT_VALID = 0xC0190023;
1182pub const MINIVERSION_INACCESSIBLE_FROM_SPECIFIED_TRANSACTION = 0xC0190024;
1183pub const CANT_OPEN_MINIVERSION_WITH_MODIFY_INTENT = 0xC0190025;
1184pub const CANT_CREATE_MORE_STREAM_MINIVERSIONS = 0xC0190026;
1185pub const HANDLE_NO_LONGER_VALID = 0xC0190028;
1186pub const LOG_CORRUPTION_DETECTED = 0xC0190030;
1187pub const RM_DISCONNECTED = 0xC0190032;
1188pub const ENLISTMENT_NOT_SUPERIOR = 0xC0190033;
1189pub const FILE_IDENTITY_NOT_PERSISTENT = 0xC0190036;
1190pub const CANT_BREAK_TRANSACTIONAL_DEPENDENCY = 0xC0190037;
1191pub const CANT_CROSS_RM_BOUNDARY = 0xC0190038;
1192pub const TXF_DIR_NOT_EMPTY = 0xC0190039;
1193pub const INDOUBT_TRANSACTIONS_EXIST = 0xC019003A;
1194pub const TM_VOLATILE = 0xC019003B;
1195pub const ROLLBACK_TIMER_EXPIRED = 0xC019003C;
1196pub const TXF_ATTRIBUTE_CORRUPT = 0xC019003D;
1197pub const EFS_NOT_ALLOWED_IN_TRANSACTION = 0xC019003E;
1198pub const TRANSACTIONAL_OPEN_NOT_ALLOWED = 0xC019003F;
1199pub const TRANSACTED_MAPPING_UNSUPPORTED_REMOTE = 0xC0190040;
1200pub const TRANSACTION_REQUIRED_PROMOTION = 0xC0190043;
1201pub const CANNOT_EXECUTE_FILE_IN_TRANSACTION = 0xC0190044;
1202pub const TRANSACTIONS_NOT_FROZEN = 0xC0190045;
1203pub const TRANSACTION_FREEZE_IN_PROGRESS = 0xC0190046;
1204pub const NOT_SNAPSHOT_VOLUME = 0xC0190047;
1205pub const NO_SAVEPOINT_WITH_OPEN_FILES = 0xC0190048;
1206pub const SPARSE_NOT_ALLOWED_IN_TRANSACTION = 0xC0190049;
1207pub const TM_IDENTITY_MISMATCH = 0xC019004A;
1208pub const FLOATED_SECTION = 0xC019004B;
1209pub const CANNOT_ACCEPT_TRANSACTED_WORK = 0xC019004C;
1210pub const CANNOT_ABORT_TRANSACTIONS = 0xC019004D;
1211pub const TRANSACTION_NOT_FOUND = 0xC019004E;
1212pub const RESOURCEMANAGER_NOT_FOUND = 0xC019004F;
1213pub const ENLISTMENT_NOT_FOUND = 0xC0190050;
1214pub const TRANSACTIONMANAGER_NOT_FOUND = 0xC0190051;
1215pub const TRANSACTIONMANAGER_NOT_ONLINE = 0xC0190052;
1216pub const TRANSACTIONMANAGER_RECOVERY_NAME_COLLISION = 0xC0190053;
1217pub const TRANSACTION_NOT_ROOT = 0xC0190054;
1218pub const TRANSACTION_OBJECT_EXPIRED = 0xC0190055;
1219pub const COMPRESSION_NOT_ALLOWED_IN_TRANSACTION = 0xC0190056;
1220pub const TRANSACTION_RESPONSE_NOT_ENLISTED = 0xC0190057;
1221pub const TRANSACTION_RECORD_TOO_LONG = 0xC0190058;
1222pub const NO_LINK_TRACKING_IN_TRANSACTION = 0xC0190059;
1223pub const OPERATION_NOT_SUPPORTED_IN_TRANSACTION = 0xC019005A;
1224pub const TRANSACTION_INTEGRITY_VIOLATED = 0xC019005B;
1225pub const EXPIRED_HANDLE = 0xC0190060;
1226pub const TRANSACTION_NOT_ENLISTED = 0xC0190061;
1227pub const LOG_SECTOR_INVALID = 0xC01A0001;
1228pub const LOG_SECTOR_PARITY_INVALID = 0xC01A0002;
1229pub const LOG_SECTOR_REMAPPED = 0xC01A0003;
1230pub const LOG_BLOCK_INCOMPLETE = 0xC01A0004;
1231pub const LOG_INVALID_RANGE = 0xC01A0005;
1232pub const LOG_BLOCKS_EXHAUSTED = 0xC01A0006;
1233pub const LOG_READ_CONTEXT_INVALID = 0xC01A0007;
1234pub const LOG_RESTART_INVALID = 0xC01A0008;
1235pub const LOG_BLOCK_VERSION = 0xC01A0009;
1236pub const LOG_BLOCK_INVALID = 0xC01A000A;
1237pub const LOG_READ_MODE_INVALID = 0xC01A000B;
1238pub const LOG_METADATA_CORRUPT = 0xC01A000D;
1239pub const LOG_METADATA_INVALID = 0xC01A000E;
1240pub const LOG_METADATA_INCONSISTENT = 0xC01A000F;
1241pub const LOG_RESERVATION_INVALID = 0xC01A0010;
1242pub const LOG_CANT_DELETE = 0xC01A0011;
1243pub const LOG_CONTAINER_LIMIT_EXCEEDED = 0xC01A0012;
1244pub const LOG_START_OF_LOG = 0xC01A0013;
1245pub const LOG_POLICY_ALREADY_INSTALLED = 0xC01A0014;
1246pub const LOG_POLICY_NOT_INSTALLED = 0xC01A0015;
1247pub const LOG_POLICY_INVALID = 0xC01A0016;
1248pub const LOG_POLICY_CONFLICT = 0xC01A0017;
1249pub const LOG_PINNED_ARCHIVE_TAIL = 0xC01A0018;
1250pub const LOG_RECORD_NONEXISTENT = 0xC01A0019;
1251pub const LOG_RECORDS_RESERVED_INVALID = 0xC01A001A;
1252pub const LOG_SPACE_RESERVED_INVALID = 0xC01A001B;
1253pub const LOG_TAIL_INVALID = 0xC01A001C;
1254pub const LOG_FULL = 0xC01A001D;
1255pub const LOG_MULTIPLEXED = 0xC01A001E;
1256pub const LOG_DEDICATED = 0xC01A001F;
1257pub const LOG_ARCHIVE_NOT_IN_PROGRESS = 0xC01A0020;
1258pub const LOG_ARCHIVE_IN_PROGRESS = 0xC01A0021;
1259pub const LOG_EPHEMERAL = 0xC01A0022;
1260pub const LOG_NOT_ENOUGH_CONTAINERS = 0xC01A0023;
1261pub const LOG_CLIENT_ALREADY_REGISTERED = 0xC01A0024;
1262pub const LOG_CLIENT_NOT_REGISTERED = 0xC01A0025;
1263pub const LOG_FULL_HANDLER_IN_PROGRESS = 0xC01A0026;
1264pub const LOG_CONTAINER_READ_FAILED = 0xC01A0027;
1265pub const LOG_CONTAINER_WRITE_FAILED = 0xC01A0028;
1266pub const LOG_CONTAINER_OPEN_FAILED = 0xC01A0029;
1267pub const LOG_CONTAINER_STATE_INVALID = 0xC01A002A;
1268pub const LOG_STATE_INVALID = 0xC01A002B;
1269pub const LOG_PINNED = 0xC01A002C;
1270pub const LOG_METADATA_FLUSH_FAILED = 0xC01A002D;
1271pub const LOG_INCONSISTENT_SECURITY = 0xC01A002E;
1272pub const LOG_APPENDED_FLUSH_FAILED = 0xC01A002F;
1273pub const LOG_PINNED_RESERVATION = 0xC01A0030;
1274pub const VIDEO_HUNG_DISPLAY_DRIVER_THREAD = 0xC01B00EA;
1275pub const FLT_NO_HANDLER_DEFINED = 0xC01C0001;
1276pub const FLT_CONTEXT_ALREADY_DEFINED = 0xC01C0002;
1277pub const FLT_INVALID_ASYNCHRONOUS_REQUEST = 0xC01C0003;
1278pub const FLT_DISALLOW_FAST_IO = 0xC01C0004;
1279pub const FLT_INVALID_NAME_REQUEST = 0xC01C0005;
1280pub const FLT_NOT_SAFE_TO_POST_OPERATION = 0xC01C0006;
1281pub const FLT_NOT_INITIALIZED = 0xC01C0007;
1282pub const FLT_FILTER_NOT_READY = 0xC01C0008;
1283pub const FLT_POST_OPERATION_CLEANUP = 0xC01C0009;
1284pub const FLT_INTERNAL_ERROR = 0xC01C000A;
1285pub const FLT_DELETING_OBJECT = 0xC01C000B;
1286pub const FLT_MUST_BE_NONPAGED_POOL = 0xC01C000C;
1287pub const FLT_DUPLICATE_ENTRY = 0xC01C000D;
1288pub const FLT_CBDQ_DISABLED = 0xC01C000E;
1289pub const FLT_DO_NOT_ATTACH = 0xC01C000F;
1290pub const FLT_DO_NOT_DETACH = 0xC01C0010;
1291pub const FLT_INSTANCE_ALTITUDE_COLLISION = 0xC01C0011;
1292pub const FLT_INSTANCE_NAME_COLLISION = 0xC01C0012;
1293pub const FLT_FILTER_NOT_FOUND = 0xC01C0013;
1294pub const FLT_VOLUME_NOT_FOUND = 0xC01C0014;
1295pub const FLT_INSTANCE_NOT_FOUND = 0xC01C0015;
1296pub const FLT_CONTEXT_ALLOCATION_NOT_FOUND = 0xC01C0016;
1297pub const FLT_INVALID_CONTEXT_REGISTRATION = 0xC01C0017;
1298pub const FLT_NAME_CACHE_MISS = 0xC01C0018;
1299pub const FLT_NO_DEVICE_OBJECT = 0xC01C0019;
1300pub const FLT_VOLUME_ALREADY_MOUNTED = 0xC01C001A;
1301pub const FLT_ALREADY_ENLISTED = 0xC01C001B;
1302pub const FLT_CONTEXT_ALREADY_LINKED = 0xC01C001C;
1303pub const FLT_NO_WAITER_FOR_REPLY = 0xC01C0020;
1304pub const MONITOR_NO_DESCRIPTOR = 0xC01D0001;
1305pub const MONITOR_UNKNOWN_DESCRIPTOR_FORMAT = 0xC01D0002;
1306pub const MONITOR_INVALID_DESCRIPTOR_CHECKSUM = 0xC01D0003;
1307pub const MONITOR_INVALID_STANDARD_TIMING_BLOCK = 0xC01D0004;
1308pub const MONITOR_WMI_DATABLOCK_REGISTRATION_FAILED = 0xC01D0005;
1309pub const MONITOR_INVALID_SERIAL_NUMBER_MONDSC_BLOCK = 0xC01D0006;
1310pub const MONITOR_INVALID_USER_FRIENDLY_MONDSC_BLOCK = 0xC01D0007;
1311pub const MONITOR_NO_MORE_DESCRIPTOR_DATA = 0xC01D0008;
1312pub const MONITOR_INVALID_DETAILED_TIMING_BLOCK = 0xC01D0009;
1313pub const MONITOR_INVALID_MANUFACTURE_DATE = 0xC01D000A;
1314pub const GRAPHICS_NOT_EXCLUSIVE_MODE_OWNER = 0xC01E0000;
1315pub const GRAPHICS_INSUFFICIENT_DMA_BUFFER = 0xC01E0001;
1316pub const GRAPHICS_INVALID_DISPLAY_ADAPTER = 0xC01E0002;
1317pub const GRAPHICS_ADAPTER_WAS_RESET = 0xC01E0003;
1318pub const GRAPHICS_INVALID_DRIVER_MODEL = 0xC01E0004;
1319pub const GRAPHICS_PRESENT_MODE_CHANGED = 0xC01E0005;
1320pub const GRAPHICS_PRESENT_OCCLUDED = 0xC01E0006;
1321pub const GRAPHICS_PRESENT_DENIED = 0xC01E0007;
1322pub const GRAPHICS_CANNOTCOLORCONVERT = 0xC01E0008;
1323pub const GRAPHICS_PRESENT_REDIRECTION_DISABLED = 0xC01E000B;
1324pub const GRAPHICS_PRESENT_UNOCCLUDED = 0xC01E000C;
1325pub const GRAPHICS_NO_VIDEO_MEMORY = 0xC01E0100;
1326pub const GRAPHICS_CANT_LOCK_MEMORY = 0xC01E0101;
1327pub const GRAPHICS_ALLOCATION_BUSY = 0xC01E0102;
1328pub const GRAPHICS_TOO_MANY_REFERENCES = 0xC01E0103;
1329pub const GRAPHICS_TRY_AGAIN_LATER = 0xC01E0104;
1330pub const GRAPHICS_TRY_AGAIN_NOW = 0xC01E0105;
1331pub const GRAPHICS_ALLOCATION_INVALID = 0xC01E0106;
1332pub const GRAPHICS_UNSWIZZLING_APERTURE_UNAVAILABLE = 0xC01E0107;
1333pub const GRAPHICS_UNSWIZZLING_APERTURE_UNSUPPORTED = 0xC01E0108;
1334pub const GRAPHICS_CANT_EVICT_PINNED_ALLOCATION = 0xC01E0109;
1335pub const GRAPHICS_INVALID_ALLOCATION_USAGE = 0xC01E0110;
1336pub const GRAPHICS_CANT_RENDER_LOCKED_ALLOCATION = 0xC01E0111;
1337pub const GRAPHICS_ALLOCATION_CLOSED = 0xC01E0112;
1338pub const GRAPHICS_INVALID_ALLOCATION_INSTANCE = 0xC01E0113;
1339pub const GRAPHICS_INVALID_ALLOCATION_HANDLE = 0xC01E0114;
1340pub const GRAPHICS_WRONG_ALLOCATION_DEVICE = 0xC01E0115;
1341pub const GRAPHICS_ALLOCATION_CONTENT_LOST = 0xC01E0116;
1342pub const GRAPHICS_GPU_EXCEPTION_ON_DEVICE = 0xC01E0200;
1343pub const GRAPHICS_INVALID_VIDPN_TOPOLOGY = 0xC01E0300;
1344pub const GRAPHICS_VIDPN_TOPOLOGY_NOT_SUPPORTED = 0xC01E0301;
1345pub const GRAPHICS_VIDPN_TOPOLOGY_CURRENTLY_NOT_SUPPORTED = 0xC01E0302;
1346pub const GRAPHICS_INVALID_VIDPN = 0xC01E0303;
1347pub const GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE = 0xC01E0304;
1348pub const GRAPHICS_INVALID_VIDEO_PRESENT_TARGET = 0xC01E0305;
1349pub const GRAPHICS_VIDPN_MODALITY_NOT_SUPPORTED = 0xC01E0306;
1350pub const GRAPHICS_INVALID_VIDPN_SOURCEMODESET = 0xC01E0308;
1351pub const GRAPHICS_INVALID_VIDPN_TARGETMODESET = 0xC01E0309;
1352pub const GRAPHICS_INVALID_FREQUENCY = 0xC01E030A;
1353pub const GRAPHICS_INVALID_ACTIVE_REGION = 0xC01E030B;
1354pub const GRAPHICS_INVALID_TOTAL_REGION = 0xC01E030C;
1355pub const GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE_MODE = 0xC01E0310;
1356pub const GRAPHICS_INVALID_VIDEO_PRESENT_TARGET_MODE = 0xC01E0311;
1357pub const GRAPHICS_PINNED_MODE_MUST_REMAIN_IN_SET = 0xC01E0312;
1358pub const GRAPHICS_PATH_ALREADY_IN_TOPOLOGY = 0xC01E0313;
1359pub const GRAPHICS_MODE_ALREADY_IN_MODESET = 0xC01E0314;
1360pub const GRAPHICS_INVALID_VIDEOPRESENTSOURCESET = 0xC01E0315;
1361pub const GRAPHICS_INVALID_VIDEOPRESENTTARGETSET = 0xC01E0316;
1362pub const GRAPHICS_SOURCE_ALREADY_IN_SET = 0xC01E0317;
1363pub const GRAPHICS_TARGET_ALREADY_IN_SET = 0xC01E0318;
1364pub const GRAPHICS_INVALID_VIDPN_PRESENT_PATH = 0xC01E0319;
1365pub const GRAPHICS_NO_RECOMMENDED_VIDPN_TOPOLOGY = 0xC01E031A;
1366pub const GRAPHICS_INVALID_MONITOR_FREQUENCYRANGESET = 0xC01E031B;
1367pub const GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE = 0xC01E031C;
1368pub const GRAPHICS_FREQUENCYRANGE_NOT_IN_SET = 0xC01E031D;
1369pub const GRAPHICS_FREQUENCYRANGE_ALREADY_IN_SET = 0xC01E031F;
1370pub const GRAPHICS_STALE_MODESET = 0xC01E0320;
1371pub const GRAPHICS_INVALID_MONITOR_SOURCEMODESET = 0xC01E0321;
1372pub const GRAPHICS_INVALID_MONITOR_SOURCE_MODE = 0xC01E0322;
1373pub const GRAPHICS_NO_RECOMMENDED_FUNCTIONAL_VIDPN = 0xC01E0323;
1374pub const GRAPHICS_MODE_ID_MUST_BE_UNIQUE = 0xC01E0324;
1375pub const GRAPHICS_EMPTY_ADAPTER_MONITOR_MODE_SUPPORT_INTERSECTION = 0xC01E0325;
1376pub const GRAPHICS_VIDEO_PRESENT_TARGETS_LESS_THAN_SOURCES = 0xC01E0326;
1377pub const GRAPHICS_PATH_NOT_IN_TOPOLOGY = 0xC01E0327;
1378pub const GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_SOURCE = 0xC01E0328;
1379pub const GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_TARGET = 0xC01E0329;
1380pub const GRAPHICS_INVALID_MONITORDESCRIPTORSET = 0xC01E032A;
1381pub const GRAPHICS_INVALID_MONITORDESCRIPTOR = 0xC01E032B;
1382pub const GRAPHICS_MONITORDESCRIPTOR_NOT_IN_SET = 0xC01E032C;
1383pub const GRAPHICS_MONITORDESCRIPTOR_ALREADY_IN_SET = 0xC01E032D;
1384pub const GRAPHICS_MONITORDESCRIPTOR_ID_MUST_BE_UNIQUE = 0xC01E032E;
1385pub const GRAPHICS_INVALID_VIDPN_TARGET_SUBSET_TYPE = 0xC01E032F;
1386pub const GRAPHICS_RESOURCES_NOT_RELATED = 0xC01E0330;
1387pub const GRAPHICS_SOURCE_ID_MUST_BE_UNIQUE = 0xC01E0331;
1388pub const GRAPHICS_TARGET_ID_MUST_BE_UNIQUE = 0xC01E0332;
1389pub const GRAPHICS_NO_AVAILABLE_VIDPN_TARGET = 0xC01E0333;
1390pub const GRAPHICS_MONITOR_COULD_NOT_BE_ASSOCIATED_WITH_ADAPTER = 0xC01E0334;
1391pub const GRAPHICS_NO_VIDPNMGR = 0xC01E0335;
1392pub const GRAPHICS_NO_ACTIVE_VIDPN = 0xC01E0336;
1393pub const GRAPHICS_STALE_VIDPN_TOPOLOGY = 0xC01E0337;
1394pub const GRAPHICS_MONITOR_NOT_CONNECTED = 0xC01E0338;
1395pub const GRAPHICS_SOURCE_NOT_IN_TOPOLOGY = 0xC01E0339;
1396pub const GRAPHICS_INVALID_PRIMARYSURFACE_SIZE = 0xC01E033A;
1397pub const GRAPHICS_INVALID_VISIBLEREGION_SIZE = 0xC01E033B;
1398pub const GRAPHICS_INVALID_STRIDE = 0xC01E033C;
1399pub const GRAPHICS_INVALID_PIXELFORMAT = 0xC01E033D;
1400pub const GRAPHICS_INVALID_COLORBASIS = 0xC01E033E;
1401pub const GRAPHICS_INVALID_PIXELVALUEACCESSMODE = 0xC01E033F;
1402pub const GRAPHICS_TARGET_NOT_IN_TOPOLOGY = 0xC01E0340;
1403pub const GRAPHICS_NO_DISPLAY_MODE_MANAGEMENT_SUPPORT = 0xC01E0341;
1404pub const GRAPHICS_VIDPN_SOURCE_IN_USE = 0xC01E0342;
1405pub const GRAPHICS_CANT_ACCESS_ACTIVE_VIDPN = 0xC01E0343;
1406pub const GRAPHICS_INVALID_PATH_IMPORTANCE_ORDINAL = 0xC01E0344;
1407pub const GRAPHICS_INVALID_PATH_CONTENT_GEOMETRY_TRANSFORMATION = 0xC01E0345;
1408pub const GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_SUPPORTED = 0xC01E0346;
1409pub const GRAPHICS_INVALID_GAMMA_RAMP = 0xC01E0347;
1410pub const GRAPHICS_GAMMA_RAMP_NOT_SUPPORTED = 0xC01E0348;
1411pub const GRAPHICS_MULTISAMPLING_NOT_SUPPORTED = 0xC01E0349;
1412pub const GRAPHICS_MODE_NOT_IN_MODESET = 0xC01E034A;
1413pub const GRAPHICS_INVALID_VIDPN_TOPOLOGY_RECOMMENDATION_REASON = 0xC01E034D;
1414pub const GRAPHICS_INVALID_PATH_CONTENT_TYPE = 0xC01E034E;
1415pub const GRAPHICS_INVALID_COPYPROTECTION_TYPE = 0xC01E034F;
1416pub const GRAPHICS_UNASSIGNED_MODESET_ALREADY_EXISTS = 0xC01E0350;
1417pub const GRAPHICS_INVALID_SCANLINE_ORDERING = 0xC01E0352;
1418pub const GRAPHICS_TOPOLOGY_CHANGES_NOT_ALLOWED = 0xC01E0353;
1419pub const GRAPHICS_NO_AVAILABLE_IMPORTANCE_ORDINALS = 0xC01E0354;
1420pub const GRAPHICS_INCOMPATIBLE_PRIVATE_FORMAT = 0xC01E0355;
1421pub const GRAPHICS_INVALID_MODE_PRUNING_ALGORITHM = 0xC01E0356;
1422pub const GRAPHICS_INVALID_MONITOR_CAPABILITY_ORIGIN = 0xC01E0357;
1423pub const GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE_CONSTRAINT = 0xC01E0358;
1424pub const GRAPHICS_MAX_NUM_PATHS_REACHED = 0xC01E0359;
1425pub const GRAPHICS_CANCEL_VIDPN_TOPOLOGY_AUGMENTATION = 0xC01E035A;
1426pub const GRAPHICS_INVALID_CLIENT_TYPE = 0xC01E035B;
1427pub const GRAPHICS_CLIENTVIDPN_NOT_SET = 0xC01E035C;
1428pub const GRAPHICS_SPECIFIED_CHILD_ALREADY_CONNECTED = 0xC01E0400;
1429pub const GRAPHICS_CHILD_DESCRIPTOR_NOT_SUPPORTED = 0xC01E0401;
1430pub const GRAPHICS_NOT_A_LINKED_ADAPTER = 0xC01E0430;
1431pub const GRAPHICS_LEADLINK_NOT_ENUMERATED = 0xC01E0431;
1432pub const GRAPHICS_CHAINLINKS_NOT_ENUMERATED = 0xC01E0432;
1433pub const GRAPHICS_ADAPTER_CHAIN_NOT_READY = 0xC01E0433;
1434pub const GRAPHICS_CHAINLINKS_NOT_STARTED = 0xC01E0434;
1435pub const GRAPHICS_CHAINLINKS_NOT_POWERED_ON = 0xC01E0435;
1436pub const GRAPHICS_INCONSISTENT_DEVICE_LINK_STATE = 0xC01E0436;
1437pub const GRAPHICS_NOT_POST_DEVICE_DRIVER = 0xC01E0438;
1438pub const GRAPHICS_ADAPTER_ACCESS_NOT_EXCLUDED = 0xC01E043B;
1439pub const GRAPHICS_OPM_NOT_SUPPORTED = 0xC01E0500;
1440pub const GRAPHICS_COPP_NOT_SUPPORTED = 0xC01E0501;
1441pub const GRAPHICS_UAB_NOT_SUPPORTED = 0xC01E0502;
1442pub const GRAPHICS_OPM_INVALID_ENCRYPTED_PARAMETERS = 0xC01E0503;
1443pub const GRAPHICS_OPM_PARAMETER_ARRAY_TOO_SMALL = 0xC01E0504;
1444pub const GRAPHICS_OPM_NO_PROTECTED_OUTPUTS_EXIST = 0xC01E0505;
1445pub const GRAPHICS_PVP_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME = 0xC01E0506;
1446pub const GRAPHICS_PVP_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP = 0xC01E0507;
1447pub const GRAPHICS_PVP_MIRRORING_DEVICES_NOT_SUPPORTED = 0xC01E0508;
1448pub const GRAPHICS_OPM_INVALID_POINTER = 0xC01E050A;
1449pub const GRAPHICS_OPM_INTERNAL_ERROR = 0xC01E050B;
1450pub const GRAPHICS_OPM_INVALID_HANDLE = 0xC01E050C;
1451pub const GRAPHICS_PVP_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE = 0xC01E050D;
1452pub const GRAPHICS_PVP_INVALID_CERTIFICATE_LENGTH = 0xC01E050E;
1453pub const GRAPHICS_OPM_SPANNING_MODE_ENABLED = 0xC01E050F;
1454pub const GRAPHICS_OPM_THEATER_MODE_ENABLED = 0xC01E0510;
1455pub const GRAPHICS_PVP_HFS_FAILED = 0xC01E0511;
1456pub const GRAPHICS_OPM_INVALID_SRM = 0xC01E0512;
1457pub const GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_HDCP = 0xC01E0513;
1458pub const GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_ACP = 0xC01E0514;
1459pub const GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_CGMSA = 0xC01E0515;
1460pub const GRAPHICS_OPM_HDCP_SRM_NEVER_SET = 0xC01E0516;
1461pub const GRAPHICS_OPM_RESOLUTION_TOO_HIGH = 0xC01E0517;
1462pub const GRAPHICS_OPM_ALL_HDCP_HARDWARE_ALREADY_IN_USE = 0xC01E0518;
1463pub const GRAPHICS_OPM_PROTECTED_OUTPUT_NO_LONGER_EXISTS = 0xC01E051A;
1464pub const GRAPHICS_OPM_SESSION_TYPE_CHANGE_IN_PROGRESS = 0xC01E051B;
1465pub const GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_COPP_SEMANTICS = 0xC01E051C;
1466pub const GRAPHICS_OPM_INVALID_INFORMATION_REQUEST = 0xC01E051D;
1467pub const GRAPHICS_OPM_DRIVER_INTERNAL_ERROR = 0xC01E051E;
1468pub const GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_OPM_SEMANTICS = 0xC01E051F;
1469pub const GRAPHICS_OPM_SIGNALING_NOT_SUPPORTED = 0xC01E0520;
1470pub const GRAPHICS_OPM_INVALID_CONFIGURATION_REQUEST = 0xC01E0521;
1471pub const GRAPHICS_I2C_NOT_SUPPORTED = 0xC01E0580;
1472pub const GRAPHICS_I2C_DEVICE_DOES_NOT_EXIST = 0xC01E0581;
1473pub const GRAPHICS_I2C_ERROR_TRANSMITTING_DATA = 0xC01E0582;
1474pub const GRAPHICS_I2C_ERROR_RECEIVING_DATA = 0xC01E0583;
1475pub const GRAPHICS_DDCCI_VCP_NOT_SUPPORTED = 0xC01E0584;
1476pub const GRAPHICS_DDCCI_INVALID_DATA = 0xC01E0585;
1477pub const GRAPHICS_DDCCI_MONITOR_RETURNED_INVALID_TIMING_STATUS_BYTE = 0xC01E0586;
1478pub const GRAPHICS_DDCCI_INVALID_CAPABILITIES_STRING = 0xC01E0587;
1479pub const GRAPHICS_MCA_INTERNAL_ERROR = 0xC01E0588;
1480pub const GRAPHICS_DDCCI_INVALID_MESSAGE_COMMAND = 0xC01E0589;
1481pub const GRAPHICS_DDCCI_INVALID_MESSAGE_LENGTH = 0xC01E058A;
1482pub const GRAPHICS_DDCCI_INVALID_MESSAGE_CHECKSUM = 0xC01E058B;
1483pub const GRAPHICS_INVALID_PHYSICAL_MONITOR_HANDLE = 0xC01E058C;
1484pub const GRAPHICS_MONITOR_NO_LONGER_EXISTS = 0xC01E058D;
1485pub const GRAPHICS_ONLY_CONSOLE_SESSION_SUPPORTED = 0xC01E05E0;
1486pub const GRAPHICS_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME = 0xC01E05E1;
1487pub const GRAPHICS_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP = 0xC01E05E2;
1488pub const GRAPHICS_MIRRORING_DEVICES_NOT_SUPPORTED = 0xC01E05E3;
1489pub const GRAPHICS_INVALID_POINTER = 0xC01E05E4;
1490pub const GRAPHICS_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE = 0xC01E05E5;
1491pub const GRAPHICS_PARAMETER_ARRAY_TOO_SMALL = 0xC01E05E6;
1492pub const GRAPHICS_INTERNAL_ERROR = 0xC01E05E7;
1493pub const GRAPHICS_SESSION_TYPE_CHANGE_IN_PROGRESS = 0xC01E05E8;
1494pub const FVE_LOCKED_VOLUME = 0xC0210000;
1495pub const FVE_NOT_ENCRYPTED = 0xC0210001;
1496pub const FVE_BAD_INFORMATION = 0xC0210002;
1497pub const FVE_TOO_SMALL = 0xC0210003;
1498pub const FVE_FAILED_WRONG_FS = 0xC0210004;
1499pub const FVE_FAILED_BAD_FS = 0xC0210005;
1500pub const FVE_FS_NOT_EXTENDED = 0xC0210006;
1501pub const FVE_FS_MOUNTED = 0xC0210007;
1502pub const FVE_NO_LICENSE = 0xC0210008;
1503pub const FVE_ACTION_NOT_ALLOWED = 0xC0210009;
1504pub const FVE_BAD_DATA = 0xC021000A;
1505pub const FVE_VOLUME_NOT_BOUND = 0xC021000B;
1506pub const FVE_NOT_DATA_VOLUME = 0xC021000C;
1507pub const FVE_CONV_READ_ERROR = 0xC021000D;
1508pub const FVE_CONV_WRITE_ERROR = 0xC021000E;
1509pub const FVE_OVERLAPPED_UPDATE = 0xC021000F;
1510pub const FVE_FAILED_SECTOR_SIZE = 0xC0210010;
1511pub const FVE_FAILED_AUTHENTICATION = 0xC0210011;
1512pub const FVE_NOT_OS_VOLUME = 0xC0210012;
1513pub const FVE_KEYFILE_NOT_FOUND = 0xC0210013;
1514pub const FVE_KEYFILE_INVALID = 0xC0210014;
1515pub const FVE_KEYFILE_NO_VMK = 0xC0210015;
1516pub const FVE_TPM_DISABLED = 0xC0210016;
1517pub const FVE_TPM_SRK_AUTH_NOT_ZERO = 0xC0210017;
1518pub const FVE_TPM_INVALID_PCR = 0xC0210018;
1519pub const FVE_TPM_NO_VMK = 0xC0210019;
1520pub const FVE_PIN_INVALID = 0xC021001A;
1521pub const FVE_AUTH_INVALID_APPLICATION = 0xC021001B;
1522pub const FVE_AUTH_INVALID_CONFIG = 0xC021001C;
1523pub const FVE_DEBUGGER_ENABLED = 0xC021001D;
1524pub const FVE_DRY_RUN_FAILED = 0xC021001E;
1525pub const FVE_BAD_METADATA_POINTER = 0xC021001F;
1526pub const FVE_OLD_METADATA_COPY = 0xC0210020;
1527pub const FVE_REBOOT_REQUIRED = 0xC0210021;
1528pub const FVE_RAW_ACCESS = 0xC0210022;
1529pub const FVE_RAW_BLOCKED = 0xC0210023;
1530pub const FVE_NO_FEATURE_LICENSE = 0xC0210026;
1531pub const FVE_POLICY_USER_DISABLE_RDV_NOT_ALLOWED = 0xC0210027;
1532pub const FVE_CONV_RECOVERY_FAILED = 0xC0210028;
1533pub const FVE_VIRTUALIZED_SPACE_TOO_BIG = 0xC0210029;
1534pub const FVE_VOLUME_TOO_SMALL = 0xC0210030;
1535pub const FWP_CALLOUT_NOT_FOUND = 0xC0220001;
1536pub const FWP_CONDITION_NOT_FOUND = 0xC0220002;
1537pub const FWP_FILTER_NOT_FOUND = 0xC0220003;
1538pub const FWP_LAYER_NOT_FOUND = 0xC0220004;
1539pub const FWP_PROVIDER_NOT_FOUND = 0xC0220005;
1540pub const FWP_PROVIDER_CONTEXT_NOT_FOUND = 0xC0220006;
1541pub const FWP_SUBLAYER_NOT_FOUND = 0xC0220007;
1542pub const FWP_NOT_FOUND = 0xC0220008;
1543pub const FWP_ALREADY_EXISTS = 0xC0220009;
1544pub const FWP_IN_USE = 0xC022000A;
1545pub const FWP_DYNAMIC_SESSION_IN_PROGRESS = 0xC022000B;
1546pub const FWP_WRONG_SESSION = 0xC022000C;
1547pub const FWP_NO_TXN_IN_PROGRESS = 0xC022000D;
1548pub const FWP_TXN_IN_PROGRESS = 0xC022000E;
1549pub const FWP_TXN_ABORTED = 0xC022000F;
1550pub const FWP_SESSION_ABORTED = 0xC0220010;
1551pub const FWP_INCOMPATIBLE_TXN = 0xC0220011;
1552pub const FWP_TIMEOUT = 0xC0220012;
1553pub const FWP_NET_EVENTS_DISABLED = 0xC0220013;
1554pub const FWP_INCOMPATIBLE_LAYER = 0xC0220014;
1555pub const FWP_KM_CLIENTS_ONLY = 0xC0220015;
1556pub const FWP_LIFETIME_MISMATCH = 0xC0220016;
1557pub const FWP_BUILTIN_OBJECT = 0xC0220017;
1558pub const FWP_TOO_MANY_BOOTTIME_FILTERS = 0xC0220018;
1559pub const FWP_TOO_MANY_CALLOUTS = 0xC0220018;
1560pub const FWP_NOTIFICATION_DROPPED = 0xC0220019;
1561pub const FWP_TRAFFIC_MISMATCH = 0xC022001A;
1562pub const FWP_INCOMPATIBLE_SA_STATE = 0xC022001B;
1563pub const FWP_NULL_POINTER = 0xC022001C;
1564pub const FWP_INVALID_ENUMERATOR = 0xC022001D;
1565pub const FWP_INVALID_FLAGS = 0xC022001E;
1566pub const FWP_INVALID_NET_MASK = 0xC022001F;
1567pub const FWP_INVALID_RANGE = 0xC0220020;
1568pub const FWP_INVALID_INTERVAL = 0xC0220021;
1569pub const FWP_ZERO_LENGTH_ARRAY = 0xC0220022;
1570pub const FWP_NULL_DISPLAY_NAME = 0xC0220023;
1571pub const FWP_INVALID_ACTION_TYPE = 0xC0220024;
1572pub const FWP_INVALID_WEIGHT = 0xC0220025;
1573pub const FWP_MATCH_TYPE_MISMATCH = 0xC0220026;
1574pub const FWP_TYPE_MISMATCH = 0xC0220027;
1575pub const FWP_OUT_OF_BOUNDS = 0xC0220028;
1576pub const FWP_RESERVED = 0xC0220029;
1577pub const FWP_DUPLICATE_CONDITION = 0xC022002A;
1578pub const FWP_DUPLICATE_KEYMOD = 0xC022002B;
1579pub const FWP_ACTION_INCOMPATIBLE_WITH_LAYER = 0xC022002C;
1580pub const FWP_ACTION_INCOMPATIBLE_WITH_SUBLAYER = 0xC022002D;
1581pub const FWP_CONTEXT_INCOMPATIBLE_WITH_LAYER = 0xC022002E;
1582pub const FWP_CONTEXT_INCOMPATIBLE_WITH_CALLOUT = 0xC022002F;
1583pub const FWP_INCOMPATIBLE_AUTH_METHOD = 0xC0220030;
1584pub const FWP_INCOMPATIBLE_DH_GROUP = 0xC0220031;
1585pub const FWP_EM_NOT_SUPPORTED = 0xC0220032;
1586pub const FWP_NEVER_MATCH = 0xC0220033;
1587pub const FWP_PROVIDER_CONTEXT_MISMATCH = 0xC0220034;
1588pub const FWP_INVALID_PARAMETER = 0xC0220035;
1589pub const FWP_TOO_MANY_SUBLAYERS = 0xC0220036;
1590pub const FWP_CALLOUT_NOTIFICATION_FAILED = 0xC0220037;
1591pub const FWP_INCOMPATIBLE_AUTH_CONFIG = 0xC0220038;
1592pub const FWP_INCOMPATIBLE_CIPHER_CONFIG = 0xC0220039;
1593pub const FWP_DUPLICATE_AUTH_METHOD = 0xC022003C;
1594pub const FWP_TCPIP_NOT_READY = 0xC0220100;
1595pub const FWP_INJECT_HANDLE_CLOSING = 0xC0220101;
1596pub const FWP_INJECT_HANDLE_STALE = 0xC0220102;
1597pub const FWP_CANNOT_PEND = 0xC0220103;
1598pub const NDIS_CLOSING = 0xC0230002;
1599pub const NDIS_BAD_VERSION = 0xC0230004;
1600pub const NDIS_BAD_CHARACTERISTICS = 0xC0230005;
1601pub const NDIS_ADAPTER_NOT_FOUND = 0xC0230006;
1602pub const NDIS_OPEN_FAILED = 0xC0230007;
1603pub const NDIS_DEVICE_FAILED = 0xC0230008;
1604pub const NDIS_MULTICAST_FULL = 0xC0230009;
1605pub const NDIS_MULTICAST_EXISTS = 0xC023000A;
1606pub const NDIS_MULTICAST_NOT_FOUND = 0xC023000B;
1607pub const NDIS_REQUEST_ABORTED = 0xC023000C;
1608pub const NDIS_RESET_IN_PROGRESS = 0xC023000D;
1609pub const NDIS_INVALID_PACKET = 0xC023000F;
1610pub const NDIS_INVALID_DEVICE_REQUEST = 0xC0230010;
1611pub const NDIS_ADAPTER_NOT_READY = 0xC0230011;
1612pub const NDIS_INVALID_LENGTH = 0xC0230014;
1613pub const NDIS_INVALID_DATA = 0xC0230015;
1614pub const NDIS_BUFFER_TOO_SHORT = 0xC0230016;
1615pub const NDIS_INVALID_OID = 0xC0230017;
1616pub const NDIS_ADAPTER_REMOVED = 0xC0230018;
1617pub const NDIS_UNSUPPORTED_MEDIA = 0xC0230019;
1618pub const NDIS_GROUP_ADDRESS_IN_USE = 0xC023001A;
1619pub const NDIS_FILE_NOT_FOUND = 0xC023001B;
1620pub const NDIS_ERROR_READING_FILE = 0xC023001C;
1621pub const NDIS_ALREADY_MAPPED = 0xC023001D;
1622pub const NDIS_RESOURCE_CONFLICT = 0xC023001E;
1623pub const NDIS_MEDIA_DISCONNECTED = 0xC023001F;
1624pub const NDIS_INVALID_ADDRESS = 0xC0230022;
1625pub const NDIS_PAUSED = 0xC023002A;
1626pub const NDIS_INTERFACE_NOT_FOUND = 0xC023002B;
1627pub const NDIS_UNSUPPORTED_REVISION = 0xC023002C;
1628pub const NDIS_INVALID_PORT = 0xC023002D;
1629pub const NDIS_INVALID_PORT_STATE = 0xC023002E;
1630pub const NDIS_LOW_POWER_STATE = 0xC023002F;
1631pub const NDIS_NOT_SUPPORTED = 0xC02300BB;
1632pub const NDIS_OFFLOAD_POLICY = 0xC023100F;
1633pub const NDIS_OFFLOAD_CONNECTION_REJECTED = 0xC0231012;
1634pub const NDIS_OFFLOAD_PATH_REJECTED = 0xC0231013;
1635pub const NDIS_DOT11_AUTO_CONFIG_ENABLED = 0xC0232000;
1636pub const NDIS_DOT11_MEDIA_IN_USE = 0xC0232001;
1637pub const NDIS_DOT11_POWER_STATE_INVALID = 0xC0232002;
1638pub const NDIS_PM_WOL_PATTERN_LIST_FULL = 0xC0232003;
1639pub const NDIS_PM_PROTOCOL_OFFLOAD_LIST_FULL = 0xC0232004;
1640pub const IPSEC_BAD_SPI = 0xC0360001;
1641pub const IPSEC_SA_LIFETIME_EXPIRED = 0xC0360002;
1642pub const IPSEC_WRONG_SA = 0xC0360003;
1643pub const IPSEC_REPLAY_CHECK_FAILED = 0xC0360004;
1644pub const IPSEC_INVALID_PACKET = 0xC0360005;
1645pub const IPSEC_INTEGRITY_CHECK_FAILED = 0xC0360006;
1646pub const IPSEC_CLEAR_TEXT_DROP = 0xC0360007;
1647pub const IPSEC_AUTH_FIREWALL_DROP = 0xC0360008;
1648pub const IPSEC_THROTTLE_DROP = 0xC0360009;
1649pub const IPSEC_DOSP_BLOCK = 0xC0368000;
1650pub const IPSEC_DOSP_RECEIVED_MULTICAST = 0xC0368001;
1651pub const IPSEC_DOSP_INVALID_PACKET = 0xC0368002;
1652pub const IPSEC_DOSP_STATE_LOOKUP_FAILED = 0xC0368003;
1653pub const IPSEC_DOSP_MAX_ENTRIES = 0xC0368004;
1654pub const IPSEC_DOSP_KEYMOD_NOT_ALLOWED = 0xC0368005;
1655pub const IPSEC_DOSP_MAX_PER_IP_RATELIMIT_QUEUES = 0xC0368006;
1656pub const VOLMGR_MIRROR_NOT_SUPPORTED = 0xC038005B;
1657pub const VOLMGR_RAID5_NOT_SUPPORTED = 0xC038005C;
1658pub const VIRTDISK_PROVIDER_NOT_FOUND = 0xC03A0014;
1659pub const VIRTDISK_NOT_VIRTUAL_DISK = 0xC03A0015;
1660pub const VHD_PARENT_VHD_ACCESS_DENIED = 0xC03A0016;
1661pub const VHD_CHILD_PARENT_SIZE_MISMATCH = 0xC03A0017;
1662pub const VHD_DIFFERENCING_CHAIN_CYCLE_DETECTED = 0xC03A0018;
1663pub const VHD_DIFFERENCING_CHAIN_ERROR_IN_PARENT = 0xC03A0019;
lib/std/os/windows/ws2_32.zig created+257
......@@ -0,0 +1,257 @@
1usingnamespace @import("bits.zig");
2
3pub const SOCKET = *@OpaqueType();
4pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));
5pub const SOCKET_ERROR = -1;
6
7pub const WSADESCRIPTION_LEN = 256;
8pub const WSASYS_STATUS_LEN = 128;
9
10pub const WSADATA = if (usize.bit_count == u64.bit_count)
11 extern struct {
12 wVersion: WORD,
13 wHighVersion: WORD,
14 iMaxSockets: u16,
15 iMaxUdpDg: u16,
16 lpVendorInfo: *u8,
17 szDescription: [WSADESCRIPTION_LEN + 1]u8,
18 szSystemStatus: [WSASYS_STATUS_LEN + 1]u8,
19 }
20else
21 extern struct {
22 wVersion: WORD,
23 wHighVersion: WORD,
24 szDescription: [WSADESCRIPTION_LEN + 1]u8,
25 szSystemStatus: [WSASYS_STATUS_LEN + 1]u8,
26 iMaxSockets: u16,
27 iMaxUdpDg: u16,
28 lpVendorInfo: *u8,
29 };
30
31pub const MAX_PROTOCOL_CHAIN = 7;
32
33pub const WSAPROTOCOLCHAIN = extern struct {
34 ChainLen: c_int,
35 ChainEntries: [MAX_PROTOCOL_CHAIN]DWORD,
36};
37
38pub const WSAPROTOCOL_LEN = 255;
39
40pub const WSAPROTOCOL_INFOA = extern struct {
41 dwServiceFlags1: DWORD,
42 dwServiceFlags2: DWORD,
43 dwServiceFlags3: DWORD,
44 dwServiceFlags4: DWORD,
45 dwProviderFlags: DWORD,
46 ProviderId: GUID,
47 dwCatalogEntryId: DWORD,
48 ProtocolChain: WSAPROTOCOLCHAIN,
49 iVersion: c_int,
50 iAddressFamily: c_int,
51 iMaxSockAddr: c_int,
52 iMinSockAddr: c_int,
53 iSocketType: c_int,
54 iProtocol: c_int,
55 iProtocolMaxOffset: c_int,
56 iNetworkByteOrder: c_int,
57 iSecurityScheme: c_int,
58 dwMessageSize: DWORD,
59 dwProviderReserved: DWORD,
60 szProtocol: [WSAPROTOCOL_LEN + 1]CHAR,
61};
62
63pub const WSAPROTOCOL_INFOW = extern struct {
64 dwServiceFlags1: DWORD,
65 dwServiceFlags2: DWORD,
66 dwServiceFlags3: DWORD,
67 dwServiceFlags4: DWORD,
68 dwProviderFlags: DWORD,
69 ProviderId: GUID,
70 dwCatalogEntryId: DWORD,
71 ProtocolChain: WSAPROTOCOLCHAIN,
72 iVersion: c_int,
73 iAddressFamily: c_int,
74 iMaxSockAddr: c_int,
75 iMinSockAddr: c_int,
76 iSocketType: c_int,
77 iProtocol: c_int,
78 iProtocolMaxOffset: c_int,
79 iNetworkByteOrder: c_int,
80 iSecurityScheme: c_int,
81 dwMessageSize: DWORD,
82 dwProviderReserved: DWORD,
83 szProtocol: [WSAPROTOCOL_LEN + 1]WCHAR,
84};
85
86pub const GROUP = u32;
87
88pub const SG_UNCONSTRAINED_GROUP = 0x1;
89pub const SG_CONSTRAINED_GROUP = 0x2;
90
91pub const WSA_FLAG_OVERLAPPED = 0x01;
92pub const WSA_FLAG_MULTIPOINT_C_ROOT = 0x02;
93pub const WSA_FLAG_MULTIPOINT_C_LEAF = 0x04;
94pub const WSA_FLAG_MULTIPOINT_D_ROOT = 0x08;
95pub const WSA_FLAG_MULTIPOINT_D_LEAF = 0x10;
96pub const WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40;
97pub const WSA_FLAG_NO_HANDLE_INHERIT = 0x80;
98
99pub const WSAEVENT = HANDLE;
100
101pub const WSAOVERLAPPED = extern struct {
102 Internal: DWORD,
103 InternalHigh: DWORD,
104 Offset: DWORD,
105 OffsetHigh: DWORD,
106 hEvent: ?WSAEVENT,
107};
108
109pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn (
110 dwError: DWORD,
111 cbTransferred: DWORD,
112 lpOverlapped: *WSAOVERLAPPED,
113 dwFlags: DWORD
114) void;
115
116pub const WSA_INVALID_HANDLE = 6;
117pub const WSA_NOT_ENOUGH_MEMORY = 8;
118pub const WSA_INVALID_PARAMETER = 87;
119pub const WSA_OPERATION_ABORTED = 995;
120pub const WSA_IO_INCOMPLETE = 996;
121pub const WSA_IO_PENDING = 997;
122pub const WSAEINTR = 10004;
123pub const WSAEBADF = 10009;
124pub const WSAEACCES = 10013;
125pub const WSAEFAULT = 10014;
126pub const WSAEINVAL = 10022;
127pub const WSAEMFILE = 10024;
128pub const WSAEWOULDBLOCK = 10035;
129pub const WSAEINPROGRESS = 10036;
130pub const WSAEALREADY = 10037;
131pub const WSAENOTSOCK = 10038;
132pub const WSAEDESTADDRREQ = 10039;
133pub const WSAEMSGSIZE = 10040;
134pub const WSAEPROTOTYPE = 10041;
135pub const WSAENOPROTOOPT = 10042;
136pub const WSAEPROTONOSUPPORT = 10043;
137pub const WSAESOCKTNOSUPPORT = 10044;
138pub const WSAEOPNOTSUPP = 10045;
139pub const WSAEPFNOSUPPORT = 10046;
140pub const WSAEAFNOSUPPORT = 10047;
141pub const WSAEADDRINUSE = 10048;
142pub const WSAEADDRNOTAVAIL = 10049;
143pub const WSAENETDOWN = 10050;
144pub const WSAENETUNREACH = 10051;
145pub const WSAENETRESET = 10052;
146pub const WSAECONNABORTED = 10053;
147pub const WSAECONNRESET = 10054;
148pub const WSAENOBUFS = 10055;
149pub const WSAEISCONN = 10056;
150pub const WSAENOTCONN = 10057;
151pub const WSAESHUTDOWN = 10058;
152pub const WSAETOOMANYREFS = 10059;
153pub const WSAETIMEDOUT = 10060;
154pub const WSAECONNREFUSED = 10061;
155pub const WSAELOOP = 10062;
156pub const WSAENAMETOOLONG = 10063;
157pub const WSAEHOSTDOWN = 10064;
158pub const WSAEHOSTUNREACH = 10065;
159pub const WSAENOTEMPTY = 10066;
160pub const WSAEPROCLIM = 10067;
161pub const WSAEUSERS = 10068;
162pub const WSAEDQUOT = 10069;
163pub const WSAESTALE = 10070;
164pub const WSAEREMOTE = 10071;
165pub const WSASYSNOTREADY = 10091;
166pub const WSAVERNOTSUPPORTED = 10092;
167pub const WSANOTINITIALISED = 10093;
168pub const WSAEDISCON = 10101;
169pub const WSAENOMORE = 10102;
170pub const WSAECANCELLED = 10103;
171pub const WSAEINVALIDPROCTABLE = 10104;
172pub const WSAEINVALIDPROVIDER = 10105;
173pub const WSAEPROVIDERFAILEDINIT = 10106;
174pub const WSASYSCALLFAILURE = 10107;
175pub const WSASERVICE_NOT_FOUND = 10108;
176pub const WSATYPE_NOT_FOUND = 10109;
177pub const WSA_E_NO_MORE = 10110;
178pub const WSA_E_CANCELLED = 10111;
179pub const WSAEREFUSED = 10112;
180pub const WSAHOST_NOT_FOUND = 11001;
181pub const WSATRY_AGAIN = 11002;
182pub const WSANO_RECOVERY = 11003;
183pub const WSANO_DATA = 11004;
184pub const WSA_QOS_RECEIVERS = 11005;
185pub const WSA_QOS_SENDERS = 11006;
186pub const WSA_QOS_NO_SENDERS = 11007;
187pub const WSA_QOS_NO_RECEIVERS = 11008;
188pub const WSA_QOS_REQUEST_CONFIRMED = 11009;
189pub const WSA_QOS_ADMISSION_FAILURE = 11010;
190pub const WSA_QOS_POLICY_FAILURE = 11011;
191pub const WSA_QOS_BAD_STYLE = 11012;
192pub const WSA_QOS_BAD_OBJECT = 11013;
193pub const WSA_QOS_TRAFFIC_CTRL_ERROR = 11014;
194pub const WSA_QOS_GENERIC_ERROR = 11015;
195pub const WSA_QOS_ESERVICETYPE = 11016;
196pub const WSA_QOS_EFLOWSPEC = 11017;
197pub const WSA_QOS_EPROVSPECBUF = 11018;
198pub const WSA_QOS_EFILTERSTYLE = 11019;
199pub const WSA_QOS_EFILTERTYPE = 11020;
200pub const WSA_QOS_EFILTERCOUNT = 11021;
201pub const WSA_QOS_EOBJLENGTH = 11022;
202pub const WSA_QOS_EFLOWCOUNT = 11023;
203pub const WSA_QOS_EUNKOWNPSOBJ = 11024;
204pub const WSA_QOS_EPOLICYOBJ = 11025;
205pub const WSA_QOS_EFLOWDESC = 11026;
206pub const WSA_QOS_EPSFLOWSPEC = 11027;
207pub const WSA_QOS_EPSFILTERSPEC = 11028;
208pub const WSA_QOS_ESDMODEOBJ = 11029;
209pub const WSA_QOS_ESHAPERATEOBJ = 11030;
210pub const WSA_QOS_RESERVED_PETYPE = 11031;
211
212
213/// no parameters
214const IOC_VOID = 0x80000000;
215/// copy out parameters
216const IOC_OUT = 0x40000000;
217/// copy in parameters
218const IOC_IN = 0x80000000;
219
220/// The IOCTL is a generic Windows Sockets 2 IOCTL code. New IOCTL codes defined for Windows Sockets 2 will have T == 1.
221const IOC_WS2 = 0x08000000;
222
223pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34;
224
225pub extern "ws2_32" stdcallcc fn WSAStartup(
226 wVersionRequired: WORD,
227 lpWSAData: *WSADATA,
228) c_int;
229pub extern "ws2_32" stdcallcc fn WSACleanup() c_int;
230pub extern "ws2_32" stdcallcc fn WSAGetLastError() c_int;
231pub extern "ws2_32" stdcallcc fn WSASocketA(
232 af: c_int,
233 type: c_int,
234 protocol: c_int,
235 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,
236 g: GROUP,
237 dwFlags: DWORD,
238) SOCKET;
239pub extern "ws2_32" stdcallcc fn WSASocketW(
240 af: c_int,
241 type: c_int,
242 protocol: c_int,
243 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,
244 g: GROUP,
245 dwFlags: DWORD,
246) SOCKET;
247pub extern "ws2_32" stdcallcc fn WSAIoctl(
248 s: SOCKET,
249 dwIoControlCode: DWORD,
250 lpvInBuffer: ?*const c_void,
251 cbInBuffer: DWORD,
252 lpvOutBuffer: ?LPVOID,
253 cbOutBuffer: DWORD,
254 lpcbBytesReturned: LPDWORD,
255 lpOverlapped: ?*WSAOVERLAPPED,
256 lpCompletionRoutine: ?*WSAOVERLAPPED_COMPLETION_ROUTINE,
257) c_int;
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/parker.zig created+180
......@@ -0,0 +1,180 @@
1const std = @import("std.zig");
2const builtin = @import("builtin");
3const time = std.time;
4const testing = std.testing;
5const assert = std.debug.assert;
6const SpinLock = std.SpinLock;
7const linux = std.os.linux;
8const windows = std.os.windows;
9
10pub const ThreadParker = switch (builtin.os) {
11 .linux => if (builtin.link_libc) PosixParker else LinuxParker,
12 .windows => WindowsParker,
13 else => if (builtin.link_libc) PosixParker else SpinParker,
14};
15
16const SpinParker = struct {
17 pub fn init() SpinParker {
18 return SpinParker{};
19 }
20 pub fn deinit(self: *SpinParker) void {}
21
22 pub fn unpark(self: *SpinParker, ptr: *const u32) void {}
23
24 pub fn park(self: *SpinParker, ptr: *const u32, expected: u32) void {
25 var backoff = SpinLock.Backoff.init();
26 while (@atomicLoad(u32, ptr, .Acquire) == expected)
27 backoff.yield();
28 }
29};
30
31const LinuxParker = struct {
32 pub fn init() LinuxParker {
33 return LinuxParker{};
34 }
35 pub fn deinit(self: *LinuxParker) void {}
36
37 pub fn unpark(self: *LinuxParker, ptr: *const u32) void {
38 const rc = linux.futex_wake(@ptrCast(*const i32, ptr), linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, 1);
39 assert(linux.getErrno(rc) == 0);
40 }
41
42 pub fn park(self: *LinuxParker, ptr: *const u32, expected: u32) void {
43 const value = @intCast(i32, expected);
44 while (@atomicLoad(u32, ptr, .Acquire) == expected) {
45 const rc = linux.futex_wait(@ptrCast(*const i32, ptr), linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, value, null);
46 switch (linux.getErrno(rc)) {
47 0, linux.EAGAIN => return,
48 linux.EINTR => continue,
49 linux.EINVAL => unreachable,
50 else => continue,
51 }
52 }
53 }
54};
55
56const WindowsParker = struct {
57 waiters: u32,
58
59 pub fn init() WindowsParker {
60 return WindowsParker{ .waiters = 0 };
61 }
62 pub fn deinit(self: *WindowsParker) void {}
63
64 pub fn unpark(self: *WindowsParker, ptr: *const u32) void {
65 const key = @ptrCast(*const c_void, ptr);
66 const handle = getEventHandle() orelse return;
67
68 var waiting = @atomicLoad(u32, &self.waiters, .Monotonic);
69 while (waiting != 0) {
70 waiting = @cmpxchgWeak(u32, &self.waiters, waiting, waiting - 1, .Acquire, .Monotonic) orelse {
71 const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);
72 assert(rc == 0);
73 return;
74 };
75 }
76 }
77
78 pub fn park(self: *WindowsParker, ptr: *const u32, expected: u32) void {
79 var spin = SpinLock.Backoff.init();
80 const ev_handle = getEventHandle();
81 const key = @ptrCast(*const c_void, ptr);
82
83 while (@atomicLoad(u32, ptr, .Monotonic) == expected) {
84 if (ev_handle) |handle| {
85 _ = @atomicRmw(u32, &self.waiters, .Add, 1, .Release);
86 const rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, null);
87 assert(rc == 0);
88 } else {
89 spin.yield();
90 }
91 }
92 }
93
94 var event_handle = std.lazyInit(windows.HANDLE);
95
96 fn getEventHandle() ?windows.HANDLE {
97 if (event_handle.get()) |handle_ptr|
98 return handle_ptr.*;
99 defer event_handle.resolve();
100
101 const access_mask = windows.GENERIC_READ | windows.GENERIC_WRITE;
102 if (windows.ntdll.NtCreateKeyedEvent(&event_handle.data, access_mask, null, 0) != 0)
103 return null;
104 return event_handle.data;
105 }
106};
107
108const PosixParker = struct {
109 cond: c.pthread_cond_t,
110 mutex: c.pthread_mutex_t,
111
112 const c = std.c;
113
114 pub fn init() PosixParker {
115 return PosixParker{
116 .cond = c.PTHREAD_COND_INITIALIZER,
117 .mutex = c.PTHREAD_MUTEX_INITIALIZER,
118 };
119 }
120
121 pub fn deinit(self: *PosixParker) void {
122 // On dragonfly, the destroy functions return EINVAL if they were initialized statically.
123 const retm = c.pthread_mutex_destroy(&self.mutex);
124 assert(retm == 0 or retm == (if (builtin.os == .dragonfly) os.EINVAL else 0));
125 const retc = c.pthread_cond_destroy(&self.cond);
126 assert(retc == 0 or retc == (if (builtin.os == .dragonfly) os.EINVAL else 0));
127 }
128
129 pub fn unpark(self: *PosixParker, ptr: *const u32) void {
130 assert(c.pthread_mutex_lock(&self.mutex) == 0);
131 defer assert(c.pthread_mutex_unlock(&self.mutex) == 0);
132 assert(c.pthread_cond_signal(&self.cond) == 0);
133 }
134
135 pub fn park(self: *PosixParker, ptr: *const u32, expected: u32) void {
136 assert(c.pthread_mutex_lock(&self.mutex) == 0);
137 defer assert(c.pthread_mutex_unlock(&self.mutex) == 0);
138 while (@atomicLoad(u32, ptr, .Acquire) == expected)
139 assert(c.pthread_cond_wait(&self.cond, &self.mutex) == 0);
140 }
141};
142
143test "std.ThreadParker" {
144 if (builtin.single_threaded)
145 return error.SkipZigTest;
146
147 const Context = struct {
148 parker: ThreadParker,
149 data: u32,
150
151 fn receiver(self: *@This()) void {
152 self.parker.park(&self.data, 0); // receives 1
153 assert(@atomicRmw(u32, &self.data, .Xchg, 2, .SeqCst) == 1); // sends 2
154 self.parker.unpark(&self.data); // wakes up waiters on 2
155 self.parker.park(&self.data, 2); // receives 3
156 assert(@atomicRmw(u32, &self.data, .Xchg, 4, .SeqCst) == 3); // sends 4
157 self.parker.unpark(&self.data); // wakes up waiters on 4
158 }
159
160 fn sender(self: *@This()) void {
161 assert(@atomicRmw(u32, &self.data, .Xchg, 1, .SeqCst) == 0); // sends 1
162 self.parker.unpark(&self.data); // wakes up waiters on 1
163 self.parker.park(&self.data, 1); // receives 2
164 assert(@atomicRmw(u32, &self.data, .Xchg, 3, .SeqCst) == 2); // sends 3
165 self.parker.unpark(&self.data); // wakes up waiters on 3
166 self.parker.park(&self.data, 3); // receives 4
167 }
168 };
169
170 var context = Context{
171 .parker = ThreadParker.init(),
172 .data = 0,
173 };
174 defer context.parker.deinit();
175
176 var receiver = try std.Thread.spawn(&context, Context.receiver);
177 defer receiver.wait();
178
179 context.sender();
180}
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/progress.zig+2-5
......@@ -98,11 +98,8 @@ pub const Progress = struct {
9898 /// TODO solve https://github.com/ziglang/zig/issues/2765 and then change this
9999 /// API to return Progress rather than accept it as a parameter.
100100 pub fn start(self: *Progress, name: []const u8, estimated_total_items: ?usize) !*Node {
101 if (std.io.getStdErr()) |stderr| {
102 self.terminal = if (stderr.supportsAnsiEscapeCodes()) stderr else null;
103 } else |_| {
104 self.terminal = null;
105 }
101 const stderr = std.io.getStdErr();
102 self.terminal = if (stderr.supportsAnsiEscapeCodes()) stderr else null;
106103 self.root = Node{
107104 .context = self,
108105 .parent = null,
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/build_runner.zig+12-23
......@@ -43,19 +43,8 @@ pub fn main() !void {
4343
4444 var targets = ArrayList([]const u8).init(allocator);
4545
46 var stderr_file = io.getStdErr();
47 var stderr_file_stream: File.OutStream = undefined;
48 var stderr_stream = if (stderr_file) |f| x: {
49 stderr_file_stream = f.outStream();
50 break :x &stderr_file_stream.stream;
51 } else |err| err;
52
53 var stdout_file = io.getStdOut();
54 var stdout_file_stream: File.OutStream = undefined;
55 var stdout_stream = if (stdout_file) |f| x: {
56 stdout_file_stream = f.outStream();
57 break :x &stdout_file_stream.stream;
58 } else |err| err;
46 const stderr_stream = &io.getStdErr().outStream().stream;
47 const stdout_stream = &io.getStdOut().outStream().stream;
5948
6049 while (arg_it.next(allocator)) |err_or_arg| {
6150 const arg = try unwrapArg(err_or_arg);
......@@ -63,37 +52,37 @@ pub fn main() !void {
6352 const option_contents = arg[2..];
6453 if (option_contents.len == 0) {
6554 warn("Expected option name after '-D'\n\n");
66 return usageAndErr(builder, false, try stderr_stream);
55 return usageAndErr(builder, false, stderr_stream);
6756 }
6857 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
6958 const option_name = option_contents[0..name_end];
7059 const option_value = option_contents[name_end + 1 ..];
7160 if (try builder.addUserInputOption(option_name, option_value))
72 return usageAndErr(builder, false, try stderr_stream);
61 return usageAndErr(builder, false, stderr_stream);
7362 } else {
7463 if (try builder.addUserInputFlag(option_contents))
75 return usageAndErr(builder, false, try stderr_stream);
64 return usageAndErr(builder, false, stderr_stream);
7665 }
7766 } else if (mem.startsWith(u8, arg, "-")) {
7867 if (mem.eql(u8, arg, "--verbose")) {
7968 builder.verbose = true;
8069 } else if (mem.eql(u8, arg, "--help")) {
81 return usage(builder, false, try stdout_stream);
70 return usage(builder, false, stdout_stream);
8271 } else if (mem.eql(u8, arg, "--prefix")) {
8372 builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse {
8473 warn("Expected argument after --prefix\n\n");
85 return usageAndErr(builder, false, try stderr_stream);
74 return usageAndErr(builder, false, stderr_stream);
8675 });
8776 } else if (mem.eql(u8, arg, "--search-prefix")) {
8877 const search_prefix = try unwrapArg(arg_it.next(allocator) orelse {
8978 warn("Expected argument after --search-prefix\n\n");
90 return usageAndErr(builder, false, try stderr_stream);
79 return usageAndErr(builder, false, stderr_stream);
9180 });
9281 builder.addSearchPrefix(search_prefix);
9382 } else if (mem.eql(u8, arg, "--override-lib-dir")) {
9483 builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse {
9584 warn("Expected argument after --override-lib-dir\n\n");
96 return usageAndErr(builder, false, try stderr_stream);
85 return usageAndErr(builder, false, stderr_stream);
9786 });
9887 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
9988 builder.verbose_tokenize = true;
......@@ -111,7 +100,7 @@ pub fn main() !void {
111100 builder.verbose_cc = true;
112101 } else {
113102 warn("Unrecognized argument: {}\n\n", arg);
114 return usageAndErr(builder, false, try stderr_stream);
103 return usageAndErr(builder, false, stderr_stream);
115104 }
116105 } else {
117106 try targets.append(arg);
......@@ -122,12 +111,12 @@ pub fn main() !void {
122111 try runBuild(builder);
123112
124113 if (builder.validateUserInputDidItFail())
125 return usageAndErr(builder, true, try stderr_stream);
114 return usageAndErr(builder, true, stderr_stream);
126115
127116 builder.make(targets.toSliceConst()) catch |err| {
128117 switch (err) {
129118 error.InvalidStepName => {
130 return usageAndErr(builder, true, try stderr_stream);
119 return usageAndErr(builder, true, stderr_stream);
131120 },
132121 error.UncleanExit => process.exit(1),
133122 else => return err,
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/special/docs/index.html+1-1
......@@ -484,7 +484,7 @@
484484 doc comments.
485485 </p>
486486 </div>
487 <div id="fnDocs" class="hidden"></div>
487 <div id="tldDocs" class="hidden"></div>
488488 <div id="sectFnErrors" class="hidden">
489489 <h2>Errors</h2>
490490 <div id="fnErrorsAnyError">
lib/std/special/docs/main.js+19-12
......@@ -20,7 +20,7 @@
2020 var domListValues = document.getElementById("listValues");
2121 var domFnProto = document.getElementById("fnProto");
2222 var domFnProtoCode = document.getElementById("fnProtoCode");
23 var domFnDocs = document.getElementById("fnDocs");
23 var domTldDocs = document.getElementById("tldDocs");
2424 var domSectFnErrors = document.getElementById("sectFnErrors");
2525 var domListFnErrors = document.getElementById("listFnErrors");
2626 var domTableFnErrors = document.getElementById("tableFnErrors");
......@@ -34,7 +34,6 @@
3434 var domListSearchResults = document.getElementById("listSearchResults");
3535 var domSectSearchNoResults = document.getElementById("sectSearchNoResults");
3636 var domSectInfo = document.getElementById("sectInfo");
37 var domListInfo = document.getElementById("listInfo");
3837 var domTdTarget = document.getElementById("tdTarget");
3938 var domTdZigVer = document.getElementById("tdZigVer");
4039 var domHdrName = document.getElementById("hdrName");
......@@ -102,7 +101,7 @@
102101 function render() {
103102 domStatus.classList.add("hidden");
104103 domFnProto.classList.add("hidden");
105 domFnDocs.classList.add("hidden");
104 domTldDocs.classList.add("hidden");
106105 domSectPkgs.classList.add("hidden");
107106 domSectTypes.classList.add("hidden");
108107 domSectNamespaces.classList.add("hidden");
......@@ -190,11 +189,11 @@
190189
191190 var docs = zigAnalysis.astNodes[decl.src].docs;
192191 if (docs != null) {
193 domFnDocs.innerHTML = markdown(docs);
192 domTldDocs.innerHTML = markdown(docs);
194193 } else {
195 domFnDocs.innerHTML = '<p>There are no doc comments for this declaration.</p>';
194 domTldDocs.innerHTML = '<p>There are no doc comments for this declaration.</p>';
196195 }
197 domFnDocs.classList.remove("hidden");
196 domTldDocs.classList.remove("hidden");
198197 }
199198
200199 function typeIsErrSet(typeIndex) {
......@@ -274,8 +273,8 @@
274273 docsSource = protoSrcNode.docs;
275274 }
276275 if (docsSource != null) {
277 domFnDocs.innerHTML = markdown(docsSource);
278 domFnDocs.classList.remove("hidden");
276 domTldDocs.innerHTML = markdown(docsSource);
277 domTldDocs.classList.remove("hidden");
279278 }
280279 domFnProto.classList.remove("hidden");
281280 }
......@@ -893,8 +892,8 @@
893892
894893 var docs = zigAnalysis.astNodes[decl.src].docs;
895894 if (docs != null) {
896 domFnDocs.innerHTML = markdown(docs);
897 domFnDocs.classList.remove("hidden");
895 domTldDocs.innerHTML = markdown(docs);
896 domTldDocs.classList.remove("hidden");
898897 }
899898
900899 domFnProto.classList.remove("hidden");
......@@ -906,8 +905,8 @@
906905
907906 var docs = zigAnalysis.astNodes[decl.src].docs;
908907 if (docs != null) {
909 domFnDocs.innerHTML = markdown(docs);
910 domFnDocs.classList.remove("hidden");
908 domTldDocs.innerHTML = markdown(docs);
909 domTldDocs.classList.remove("hidden");
911910 }
912911
913912 domFnProto.classList.remove("hidden");
......@@ -957,6 +956,14 @@
957956 varsList.sort(byNameProperty);
958957 valsList.sort(byNameProperty);
959958
959 if (container.src != null) {
960 var docs = zigAnalysis.astNodes[container.src].docs;
961 if (docs != null) {
962 domTldDocs.innerHTML = markdown(docs);
963 domTldDocs.classList.remove("hidden");
964 }
965 }
966
960967 if (typesList.length !== 0) {
961968 resizeDomList(domListTypes, typesList.length, '<li><a href="#"></a></li>');
962969 for (var i = 0; i < typesList.length; i += 1) {
lib/std/special/start.zig+1-1
......@@ -214,7 +214,7 @@ inline fn initEventLoopAndCallMain() u8 {
214214 return @inlineCall(callMain);
215215}
216216
217fn callMainAsync(loop: *std.event.Loop) u8 {
217async fn callMainAsync(loop: *std.event.Loop) u8 {
218218 // This prevents the event loop from terminating at least until main() has returned.
219219 loop.beginOneEvent();
220220 defer loop.finishOneEvent();
lib/std/spinlock.zig+41-4
......@@ -1,8 +1,8 @@
11const std = @import("std.zig");
22const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;
4const AtomicRmwOp = builtin.AtomicRmwOp;
53const assert = std.debug.assert;
4const time = std.time;
5const os = std.os;
66
77pub const SpinLock = struct {
88 lock: u8, // TODO use a bool or enum
......@@ -11,7 +11,7 @@ pub const SpinLock = struct {
1111 spinlock: *SpinLock,
1212
1313 pub fn release(self: Held) void {
14 assert(@atomicRmw(u8, &self.spinlock.lock, builtin.AtomicRmwOp.Xchg, 0, AtomicOrder.SeqCst) == 1);
14 @atomicStore(u8, &self.spinlock.lock, 0, .Release);
1515 }
1616 };
1717
......@@ -20,9 +20,46 @@ pub const SpinLock = struct {
2020 }
2121
2222 pub fn acquire(self: *SpinLock) Held {
23 while (@atomicRmw(u8, &self.lock, builtin.AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst) != 0) {}
23 var backoff = Backoff.init();
24 while (@atomicRmw(u8, &self.lock, .Xchg, 1, .Acquire) != 0)
25 backoff.yield();
2426 return Held{ .spinlock = self };
2527 }
28
29 pub fn yield(iterations: usize) void {
30 var i = iterations;
31 while (i != 0) : (i -= 1) {
32 switch (builtin.arch) {
33 .i386, .x86_64 => asm volatile ("pause"),
34 .arm, .aarch64 => asm volatile ("yield"),
35 else => time.sleep(0),
36 }
37 }
38 }
39
40 /// Provides a method to incrementally yield longer each time its called.
41 pub const Backoff = struct {
42 iteration: usize,
43
44 pub fn init() @This() {
45 return @This(){ .iteration = 0 };
46 }
47
48 /// Modified hybrid yielding from
49 /// http://www.1024cores.net/home/lock-free-algorithms/tricks/spinning
50 pub fn yield(self: *@This()) void {
51 defer self.iteration +%= 1;
52 if (self.iteration < 20) {
53 SpinLock.yield(self.iteration);
54 } else if (self.iteration < 24) {
55 os.sched_yield() catch time.sleep(1);
56 } else if (self.iteration < 26) {
57 time.sleep(1 * time.millisecond);
58 } else {
59 time.sleep(10 * time.millisecond);
60 }
61 }
62 };
2663};
2764
2865test "spinlock" {
lib/std/statically_initialized_mutex.zig deleted-105
......@@ -1,105 +0,0 @@
1const std = @import("std.zig");
2const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;
4const AtomicRmwOp = builtin.AtomicRmwOp;
5const assert = std.debug.assert;
6const expect = std.testing.expect;
7const windows = std.os.windows;
8
9/// Lock may be held only once. If the same thread
10/// tries to acquire the same mutex twice, it deadlocks.
11/// This type is intended to be initialized statically. If you don't
12/// require static initialization, use std.Mutex.
13/// On Windows, this mutex allocates resources when it is
14/// first used, and the resources cannot be freed.
15/// On Linux, this is an alias of std.Mutex.
16pub const StaticallyInitializedMutex = switch (builtin.os) {
17 builtin.Os.linux => std.Mutex,
18 builtin.Os.windows => struct {
19 lock: windows.CRITICAL_SECTION,
20 init_once: windows.RTL_RUN_ONCE,
21
22 pub const Held = struct {
23 mutex: *StaticallyInitializedMutex,
24
25 pub fn release(self: Held) void {
26 windows.kernel32.LeaveCriticalSection(&self.mutex.lock);
27 }
28 };
29
30 pub fn init() StaticallyInitializedMutex {
31 return StaticallyInitializedMutex{
32 .lock = undefined,
33 .init_once = windows.INIT_ONCE_STATIC_INIT,
34 };
35 }
36
37 extern fn initCriticalSection(
38 InitOnce: *windows.RTL_RUN_ONCE,
39 Parameter: ?*c_void,
40 Context: ?*c_void,
41 ) windows.BOOL {
42 const lock = @ptrCast(*windows.CRITICAL_SECTION, @alignCast(@alignOf(windows.CRITICAL_SECTION), Parameter));
43 windows.kernel32.InitializeCriticalSection(lock);
44 return windows.TRUE;
45 }
46
47 /// TODO: once https://github.com/ziglang/zig/issues/287 is solved and std.Mutex has a better
48 /// implementation of a runtime initialized mutex, remove this function.
49 pub fn deinit(self: *StaticallyInitializedMutex) void {
50 windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null);
51 windows.kernel32.DeleteCriticalSection(&self.lock);
52 }
53
54 pub fn acquire(self: *StaticallyInitializedMutex) Held {
55 windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null);
56 windows.kernel32.EnterCriticalSection(&self.lock);
57 return Held{ .mutex = self };
58 }
59 },
60 else => std.Mutex,
61};
62
63test "std.StaticallyInitializedMutex" {
64 const TestContext = struct {
65 data: i128,
66
67 const TestContext = @This();
68 const incr_count = 10000;
69
70 var mutex = StaticallyInitializedMutex.init();
71
72 fn worker(ctx: *TestContext) void {
73 var i: usize = 0;
74 while (i != TestContext.incr_count) : (i += 1) {
75 const held = mutex.acquire();
76 defer held.release();
77
78 ctx.data += 1;
79 }
80 }
81 };
82
83 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);
84 defer std.heap.direct_allocator.free(plenty_of_memory);
85
86 var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory);
87 var a = &fixed_buffer_allocator.allocator;
88
89 var context = TestContext{ .data = 0 };
90
91 if (builtin.single_threaded) {
92 TestContext.worker(&context);
93 expect(context.data == TestContext.incr_count);
94 } else {
95 const thread_count = 10;
96 var threads: [thread_count]*std.Thread = undefined;
97 for (threads) |*t| {
98 t.* = try std.Thread.spawn(&context, TestContext.worker);
99 }
100 for (threads) |t|
101 t.wait();
102
103 expect(context.data == thread_count * TestContext.incr_count);
104 }
105}
lib/std/std.zig+1-1
......@@ -19,11 +19,11 @@ pub const Progress = @import("progress.zig").Progress;
1919pub const SegmentedList = @import("segmented_list.zig").SegmentedList;
2020pub const SinglyLinkedList = @import("linked_list.zig").SinglyLinkedList;
2121pub const SpinLock = @import("spinlock.zig").SpinLock;
22pub const StaticallyInitializedMutex = @import("statically_initialized_mutex.zig").StaticallyInitializedMutex;
2322pub const StringHashMap = @import("hash_map.zig").StringHashMap;
2423pub const TailQueue = @import("linked_list.zig").TailQueue;
2524pub const Target = @import("target.zig").Target;
2625pub const Thread = @import("thread.zig").Thread;
26pub const ThreadParker = @import("parker.zig").ThreadParker;
2727
2828pub const atomic = @import("atomic.zig");
2929pub const base64 = @import("base64.zig");
lib/std/target.zig+36-2
......@@ -218,6 +218,40 @@ pub const Target = union(enum) {
218218 );
219219 }
220220
221 /// Returned slice must be freed by the caller.
222 pub fn vcpkgTriplet(allocator: *mem.Allocator, target: Target, linkage: std.build.VcpkgLinkage) ![]const u8 {
223 const arch = switch (target.getArch()) {
224 .i386 => "x86",
225 .x86_64 => "x64",
226
227 .arm,
228 .armeb,
229 .thumb,
230 .thumbeb,
231 .aarch64_32,
232 => "arm",
233
234 .aarch64,
235 .aarch64_be,
236 => "arm64",
237
238 else => return error.VcpkgNoSuchArchitecture,
239 };
240
241 const os = switch (target.getOs()) {
242 .windows => "windows",
243 .linux => "linux",
244 .macosx => "macos",
245 else => return error.VcpkgNoSuchOs,
246 };
247
248 if (linkage == .Static) {
249 return try mem.join(allocator, "-", [_][]const u8{ arch, os, "static" });
250 } else {
251 return try mem.join(allocator, "-", [_][]const u8{ arch, os });
252 }
253 }
254
221255 pub fn allocDescription(self: Target, allocator: *mem.Allocator) ![]u8 {
222256 // TODO is there anything else worthy of the description that is not
223257 // already captured in the triple?
......@@ -319,7 +353,7 @@ pub const Target = union(enum) {
319353 inline for (info.Union.fields) |field| {
320354 if (mem.eql(u8, text, field.name)) {
321355 if (field.field_type == void) {
322 return (Arch)(@field(Arch, field.name));
356 return @as(Arch, @field(Arch, field.name));
323357 } else {
324358 const sub_info = @typeInfo(field.field_type);
325359 inline for (sub_info.Enum.fields) |sub_field| {
......@@ -581,7 +615,7 @@ pub const Target = union(enum) {
581615 };
582616
583617 pub fn getExternalExecutor(self: Target) Executor {
584 if (@TagType(Target)(self) == .Native) return .native;
618 if (@as(@TagType(Target), self) == .Native) return .native;
585619
586620 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
587621 if (self.getOs() == builtin.os) {
lib/std/testing.zig+1-1
......@@ -62,7 +62,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
6262 builtin.TypeInfo.Pointer.Size.C,
6363 => {
6464 if (actual != expected) {
65 std.debug.panic("expected {}, found {}", expected, actual);
65 std.debug.panic("expected {*}, found {*}", expected, actual);
6666 }
6767 },
6868
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/unicode/throughput_test.zig+1-3
......@@ -2,9 +2,7 @@ const builtin = @import("builtin");
22const std = @import("std");
33
44pub fn main() !void {
5 var stdout_file = try std.io.getStdOut();
6 var stdout_out_stream = stdout_file.outStream();
7 const stdout = &stdout_out_stream.stream;
5 const stdout = &std.io.getStdOut().outStream().stream;
86
97 const args = try std.process.argsAlloc(std.heap.direct_allocator);
108
lib/std/valgrind.zig+45-35
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
2const math = @import("index.zig").math;
2const std = @import("std.zig");
3const math = std.math;
34
45pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
56 if (!builtin.valgrind_support) {
......@@ -13,7 +14,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
1314 \\ roll $29, %%edi ; roll $19, %%edi
1415 \\ xchgl %%ebx,%%ebx
1516 : [_] "={edx}" (-> usize)
16 : [_] "{eax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),
17 : [_] "{eax}" (&[_]usize{ request, a1, a2, a3, a4, a5 }),
1718 [_] "0" (default)
1819 : "cc", "memory"
1920 );
......@@ -24,7 +25,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
2425 \\ rolq $61, %%rdi ; rolq $51, %%rdi
2526 \\ xchgq %%rbx,%%rbx
2627 : [_] "={rdx}" (-> usize)
27 : [_] "{rax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),
28 : [_] "{rax}" (&[_]usize{ request, a1, a2, a3, a4, a5 }),
2829 [_] "0" (default)
2930 : "cc", "memory"
3031 );
......@@ -76,7 +77,7 @@ pub const ClientRequest = extern enum {
7677 InnerThreads = 6402,
7778};
7879pub fn ToolBase(base: [2]u8) u32 {
79 return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16);
80 return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16);
8081}
8182pub fn IsTool(base: [2]u8, code: usize) bool {
8283 return ToolBase(base) == (code & 0xffff0000);
......@@ -95,48 +96,52 @@ fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize,
9596/// running under Valgrind which is running under another Valgrind,
9697/// etc.
9798pub fn runningOnValgrind() usize {
98 return doClientRequestExpr(0, ClientRequest.RunningOnValgrind, 0, 0, 0, 0, 0);
99 return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0);
100}
101
102test "works whether running on valgrind or not" {
103 _ = runningOnValgrind();
99104}
100105
101106/// Discard translation of code in the slice qzz. Useful if you are debugging
102107/// a JITter or some such, since it provides a way to make sure valgrind will
103108/// retranslate the invalidated area. Returns no value.
104109pub fn discardTranslations(qzz: []const u8) void {
105 doClientRequestStmt(ClientRequest.DiscardTranslations, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
110 doClientRequestStmt(.DiscardTranslations, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
106111}
107112
108113pub fn innerThreads(qzz: [*]u8) void {
109 doClientRequestStmt(ClientRequest.InnerThreads, qzz, 0, 0, 0, 0);
114 doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0);
110115}
111116
112117//pub fn printf(format: [*]const u8, args: ...) usize {
113118// return doClientRequestExpr(0,
114// ClientRequest.PrintfValistByRef,
119// .PrintfValistByRef,
115120// @ptrToInt(format), @ptrToInt(args),
116121// 0, 0, 0);
117122//}
118123
119124//pub fn printfBacktrace(format: [*]const u8, args: ...) usize {
120125// return doClientRequestExpr(0,
121// ClientRequest.PrintfBacktraceValistByRef,
126// .PrintfBacktraceValistByRef,
122127// @ptrToInt(format), @ptrToInt(args),
123128// 0, 0, 0);
124129//}
125130
126131pub fn nonSIMDCall0(func: fn (usize) usize) usize {
127 return doClientRequestExpr(0, ClientRequest.ClientCall0, @ptrToInt(func), 0, 0, 0, 0);
132 return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0);
128133}
129134
130135pub fn nonSIMDCall1(func: fn (usize, usize) usize, a1: usize) usize {
131 return doClientRequestExpr(0, ClientRequest.ClientCall1, @ptrToInt(func), a1, 0, 0, 0);
136 return doClientRequestExpr(0, .ClientCall1, @ptrToInt(func), a1, 0, 0, 0);
132137}
133138
134139pub fn nonSIMDCall2(func: fn (usize, usize, usize) usize, a1: usize, a2: usize) usize {
135 return doClientRequestExpr(0, ClientRequest.ClientCall2, @ptrToInt(func), a1, a2, 0, 0);
140 return doClientRequestExpr(0, .ClientCall2, @ptrToInt(func), a1, a2, 0, 0);
136141}
137142
138143pub fn nonSIMDCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: usize, a3: usize) usize {
139 return doClientRequestExpr(0, ClientRequest.ClientCall3, @ptrToInt(func), a1, a2, a3, 0);
144 return doClientRequestExpr(0, .ClientCall3, @ptrToInt(func), a1, a2, a3, 0);
140145}
141146
142147/// Counts the number of errors that have been recorded by a tool. Nb:
......@@ -144,19 +149,19 @@ pub fn nonSIMDCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2:
144149/// VG_(unique_error)() for them to be counted.
145150pub fn countErrors() usize {
146151 return doClientRequestExpr(0, // default return
147 ClientRequest.CountErrors, 0, 0, 0, 0, 0);
152 .CountErrors, 0, 0, 0, 0, 0);
148153}
149154
150155pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void {
151 doClientRequestStmt(ClientRequest.MalloclikeBlock, @ptrToInt(mem.ptr), mem.len, rzB, @boolToInt(is_zeroed), 0);
156 doClientRequestStmt(.MalloclikeBlock, @ptrToInt(mem.ptr), mem.len, rzB, @boolToInt(is_zeroed), 0);
152157}
153158
154159pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void {
155 doClientRequestStmt(ClientRequest.ResizeinplaceBlock, @ptrToInt(oldmem.ptr), oldmem.len, newsize, rzB, 0);
160 doClientRequestStmt(.ResizeinplaceBlock, @ptrToInt(oldmem.ptr), oldmem.len, newsize, rzB, 0);
156161}
157162
158163pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void {
159 doClientRequestStmt(ClientRequest.FreelikeBlock, @ptrToInt(addr), rzB, 0, 0, 0);
164 doClientRequestStmt(.FreelikeBlock, @ptrToInt(addr), rzB, 0, 0, 0);
160165}
161166
162167/// Create a memory pool.
......@@ -165,66 +170,66 @@ pub const MempoolFlags = extern enum {
165170 MetaPool = 2,
166171};
167172pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void {
168 doClientRequestStmt(ClientRequest.CreateMempool, @ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags, 0);
173 doClientRequestStmt(.CreateMempool, @ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags, 0);
169174}
170175
171176/// Destroy a memory pool.
172177pub fn destroyMempool(pool: [*]u8) void {
173 doClientRequestStmt(ClientRequest.DestroyMempool, pool, 0, 0, 0, 0);
178 doClientRequestStmt(.DestroyMempool, pool, 0, 0, 0, 0);
174179}
175180
176181/// Associate a piece of memory with a memory pool.
177182pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void {
178 doClientRequestStmt(ClientRequest.MempoolAlloc, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0);
183 doClientRequestStmt(.MempoolAlloc, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0);
179184}
180185
181186/// Disassociate a piece of memory from a memory pool.
182187pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void {
183 doClientRequestStmt(ClientRequest.MempoolFree, @ptrToInt(pool), @ptrToInt(addr), 0, 0, 0);
188 doClientRequestStmt(.MempoolFree, @ptrToInt(pool), @ptrToInt(addr), 0, 0, 0);
184189}
185190
186191/// Disassociate any pieces outside a particular range.
187192pub fn mempoolTrim(pool: [*]u8, mem: []u8) void {
188 doClientRequestStmt(ClientRequest.MempoolTrim, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0);
193 doClientRequestStmt(.MempoolTrim, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0);
189194}
190195
191196/// Resize and/or move a piece associated with a memory pool.
192197pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void {
193 doClientRequestStmt(ClientRequest.MoveMempool, @ptrToInt(poolA), @ptrToInt(poolB), 0, 0, 0);
198 doClientRequestStmt(.MoveMempool, @ptrToInt(poolA), @ptrToInt(poolB), 0, 0, 0);
194199}
195200
196201/// Resize and/or move a piece associated with a memory pool.
197202pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void {
198 doClientRequestStmt(ClientRequest.MempoolChange, @ptrToInt(pool), @ptrToInt(addrA), @ptrToInt(mem.ptr), mem.len, 0);
203 doClientRequestStmt(.MempoolChange, @ptrToInt(pool), @ptrToInt(addrA), @ptrToInt(mem.ptr), mem.len, 0);
199204}
200205
201206/// Return if a mempool exists.
202207pub fn mempoolExists(pool: [*]u8) bool {
203 return doClientRequestExpr(0, ClientRequest.MempoolExists, @ptrToInt(pool), 0, 0, 0, 0) != 0;
208 return doClientRequestExpr(0, .MempoolExists, @ptrToInt(pool), 0, 0, 0, 0) != 0;
204209}
205210
206211/// Mark a piece of memory as being a stack. Returns a stack id.
207212/// start is the lowest addressable stack byte, end is the highest
208213/// addressable stack byte.
209214pub fn stackRegister(stack: []u8) usize {
210 return doClientRequestExpr(0, ClientRequest.StackRegister, @ptrToInt(stack.ptr), @ptrToInt(stack.ptr) + stack.len, 0, 0, 0);
215 return doClientRequestExpr(0, .StackRegister, @ptrToInt(stack.ptr), @ptrToInt(stack.ptr) + stack.len, 0, 0, 0);
211216}
212217
213218/// Unmark the piece of memory associated with a stack id as being a stack.
214219pub fn stackDeregister(id: usize) void {
215 doClientRequestStmt(ClientRequest.StackDeregister, id, 0, 0, 0, 0);
220 doClientRequestStmt(.StackDeregister, id, 0, 0, 0, 0);
216221}
217222
218223/// Change the start and end address of the stack id.
219224/// start is the new lowest addressable stack byte, end is the new highest
220225/// addressable stack byte.
221226pub fn stackChange(id: usize, newstack: []u8) void {
222 doClientRequestStmt(ClientRequest.StackChange, id, @ptrToInt(newstack.ptr), @ptrToInt(newstack.ptr) + newstack.len, 0, 0);
227 doClientRequestStmt(.StackChange, id, @ptrToInt(newstack.ptr), @ptrToInt(newstack.ptr) + newstack.len, 0, 0);
223228}
224229
225230// Load PDB debug info for Wine PE image_map.
226231// pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void {
227// doClientRequestStmt(ClientRequest.LoadPdbDebuginfo,
232// doClientRequestStmt(.LoadPdbDebuginfo,
228233// fd, ptr, total_size, delta,
229234// 0);
230235// }
......@@ -234,7 +239,7 @@ pub fn stackChange(id: usize, newstack: []u8) void {
234239/// result will be dumped in there and is guaranteed to be zero
235240/// terminated. If no info is found, the first byte is set to zero.
236241pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize {
237 return doClientRequestExpr(0, ClientRequest.MapIpToSrcloc, @ptrToInt(addr), @ptrToInt(&buf64[0]), 0, 0, 0);
242 return doClientRequestExpr(0, .MapIpToSrcloc, @ptrToInt(addr), @ptrToInt(&buf64[0]), 0, 0, 0);
238243}
239244
240245/// Disable error reporting for this thread. Behaves in a stack like
......@@ -246,12 +251,12 @@ pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize {
246251/// reporting. Child threads do not inherit this setting from their
247252/// parents -- they are always created with reporting enabled.
248253pub fn disableErrorReporting() void {
249 doClientRequestStmt(ClientRequest.ChangeErrDisablement, 1, 0, 0, 0, 0);
254 doClientRequestStmt(.ChangeErrDisablement, 1, 0, 0, 0, 0);
250255}
251256
252257/// Re-enable error reporting, (see disableErrorReporting())
253258pub fn enableErrorReporting() void {
254 doClientRequestStmt(ClientRequest.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0);
259 doClientRequestStmt(.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0);
255260}
256261
257262/// Execute a monitor command from the client program.
......@@ -260,8 +265,13 @@ pub fn enableErrorReporting() void {
260265/// If no connection is opened, output will go to the log output.
261266/// Returns 1 if command not recognised, 0 otherwise.
262267pub fn monitorCommand(command: [*]u8) bool {
263 return doClientRequestExpr(0, ClientRequest.GdbMonitorCommand, @ptrToInt(command.ptr), 0, 0, 0, 0) != 0;
268 return doClientRequestExpr(0, .GdbMonitorCommand, @ptrToInt(command.ptr), 0, 0, 0, 0) != 0;
264269}
265270
266pub const memcheck = @import("memcheck.zig");
267pub const callgrind = @import("callgrind.zig");
271pub const memcheck = @import("valgrind/memcheck.zig");
272pub const callgrind = @import("valgrind/callgrind.zig");
273
274test "" {
275 _ = @import("valgrind/memcheck.zig");
276 _ = @import("valgrind/callgrind.zig");
277}
lib/std/valgrind/callgrind.zig+7-7
......@@ -1,4 +1,4 @@
1const std = @import("../index.zig");
1const std = @import("../std.zig");
22const valgrind = std.valgrind;
33
44pub const CallgrindClientRequest = extern enum {
......@@ -20,7 +20,7 @@ fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, a1: usize, a2:
2020
2121/// Dump current state of cost centers, and zero them afterwards
2222pub fn dumpStats() void {
23 doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStats, 0, 0, 0, 0, 0);
23 doCallgrindClientRequestStmt(.DumpStats, 0, 0, 0, 0, 0);
2424}
2525
2626/// Dump current state of cost centers, and zero them afterwards.
......@@ -28,12 +28,12 @@ pub fn dumpStats() void {
2828/// the dump. This string is written as a description field into the
2929/// profile data dump.
3030pub fn dumpStatsAt(pos_str: [*]u8) void {
31 doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStatsAt, @ptrToInt(pos_str), 0, 0, 0, 0);
31 doCallgrindClientRequestStmt(.DumpStatsAt, @ptrToInt(pos_str), 0, 0, 0, 0);
3232}
3333
3434/// Zero cost centers
3535pub fn zeroStats() void {
36 doCallgrindClientRequestStmt(CallgrindClientRequest.ZeroStats, 0, 0, 0, 0, 0);
36 doCallgrindClientRequestStmt(.ZeroStats, 0, 0, 0, 0, 0);
3737}
3838
3939/// Toggles collection state.
......@@ -41,7 +41,7 @@ pub fn zeroStats() void {
4141/// should be noted or if they are to be ignored. Events are noted
4242/// by increment of counters in a cost center
4343pub fn toggleCollect() void {
44 doCallgrindClientRequestStmt(CallgrindClientRequest.ToggleCollect, 0, 0, 0, 0, 0);
44 doCallgrindClientRequestStmt(.ToggleCollect, 0, 0, 0, 0, 0);
4545}
4646
4747/// Start full callgrind instrumentation if not already switched on.
......@@ -49,7 +49,7 @@ pub fn toggleCollect() void {
4949/// this will lead to an artificial cache warmup phase afterwards with
5050/// cache misses which would not have happened in reality.
5151pub fn startInstrumentation() void {
52 doCallgrindClientRequestStmt(CallgrindClientRequest.StartInstrumentation, 0, 0, 0, 0, 0);
52 doCallgrindClientRequestStmt(.StartInstrumentation, 0, 0, 0, 0, 0);
5353}
5454
5555/// Stop full callgrind instrumentation if not already switched off.
......@@ -60,5 +60,5 @@ pub fn startInstrumentation() void {
6060/// To start Callgrind in this mode to ignore the setup phase, use
6161/// the option "--instr-atstart=no".
6262pub fn stopInstrumentation() void {
63 doCallgrindClientRequestStmt(CallgrindClientRequest.StopInstrumentation, 0, 0, 0, 0, 0);
63 doCallgrindClientRequestStmt(.StopInstrumentation, 0, 0, 0, 0, 0);
6464}
lib/std/valgrind/memcheck.zig+60-21
......@@ -1,4 +1,5 @@
1const std = @import("../index.zig");
1const std = @import("../std.zig");
2const testing = std.testing;
23const valgrind = std.valgrind;
34
45pub const MemCheckClientRequest = extern enum {
......@@ -31,7 +32,7 @@ fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: us
3132/// This returns -1 when run on Valgrind and 0 otherwise.
3233pub fn makeMemNoAccess(qzz: []u8) i1 {
3334 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
34 MemCheckClientRequest.MakeMemNoAccess, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
35 .MakeMemNoAccess, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
3536}
3637
3738/// Similarly, mark memory at qzz.ptr as addressable but undefined
......@@ -39,7 +40,7 @@ pub fn makeMemNoAccess(qzz: []u8) i1 {
3940/// This returns -1 when run on Valgrind and 0 otherwise.
4041pub fn makeMemUndefined(qzz: []u8) i1 {
4142 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
42 MemCheckClientRequest.MakeMemUndefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
43 .MakeMemUndefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
4344}
4445
4546/// Similarly, mark memory at qzz.ptr as addressable and defined
......@@ -47,7 +48,7 @@ pub fn makeMemUndefined(qzz: []u8) i1 {
4748pub fn makeMemDefined(qzz: []u8) i1 {
4849 // This returns -1 when run on Valgrind and 0 otherwise.
4950 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
50 MemCheckClientRequest.MakeMemDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
51 .MakeMemDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
5152}
5253
5354/// Similar to makeMemDefined except that addressability is
......@@ -56,7 +57,7 @@ pub fn makeMemDefined(qzz: []u8) i1 {
5657/// This returns -1 when run on Valgrind and 0 otherwise.
5758pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 {
5859 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
59 MemCheckClientRequest.MakeMemDefinedIfAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
60 .MakeMemDefinedIfAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
6061}
6162
6263/// Create a block-description handle. The description is an ascii
......@@ -65,14 +66,14 @@ pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 {
6566/// properties of the memory range.
6667pub fn createBlock(qzz: []u8, desc: [*]u8) usize {
6768 return doMemCheckClientRequestExpr(0, // default return
68 MemCheckClientRequest.CreateBlock, @ptrToInt(qzz.ptr), qzz.len, @ptrToInt(desc), 0, 0);
69 .CreateBlock, @ptrToInt(qzz.ptr), qzz.len, @ptrToInt(desc), 0, 0);
6970}
7071
7172/// Discard a block-description-handle. Returns 1 for an
7273/// invalid handle, 0 for a valid handle.
7374pub fn discard(blkindex) bool {
7475 return doMemCheckClientRequestExpr(0, // default return
75 MemCheckClientRequest.Discard, 0, blkindex, 0, 0, 0) != 0;
76 .Discard, 0, blkindex, 0, 0, 0) != 0;
7677}
7778
7879/// Check that memory at qzz.ptr is addressable for qzz.len bytes.
......@@ -80,7 +81,7 @@ pub fn discard(blkindex) bool {
8081/// error message and returns the address of the first offending byte.
8182/// Otherwise it returns zero.
8283pub fn checkMemIsAddressable(qzz: []u8) usize {
83 return doMemCheckClientRequestExpr(0, MemCheckClientRequest.CheckMemIsAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
84 return doMemCheckClientRequestExpr(0, .CheckMemIsAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
8485}
8586
8687/// Check that memory at qzz.ptr is addressable and defined for
......@@ -88,31 +89,31 @@ pub fn checkMemIsAddressable(qzz: []u8) usize {
8889/// established, Valgrind prints an error message and returns the
8990/// address of the first offending byte. Otherwise it returns zero.
9091pub fn checkMemIsDefined(qzz: []u8) usize {
91 return doMemCheckClientRequestExpr(0, MemCheckClientRequest.CheckMemIsDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
92 return doMemCheckClientRequestExpr(0, .CheckMemIsDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
9293}
9394
9495/// Do a full memory leak check (like --leak-check=full) mid-execution.
9596pub fn doLeakCheck() void {
96 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 0, 0, 0, 0);
97 doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 0, 0, 0, 0, 0);
9798}
9899
99100/// Same as doLeakCheck() but only showing the entries for
100101/// which there was an increase in leaked bytes or leaked nr of blocks
101102/// since the previous leak search.
102103pub fn doAddedLeakCheck() void {
103 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 1, 0, 0, 0);
104 doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 0, 1, 0, 0, 0);
104105}
105106
106107/// Same as doAddedLeakCheck() but showing entries with
107108/// increased or decreased leaked bytes/blocks since previous leak
108109/// search.
109110pub fn doChangedLeakCheck() void {
110 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 2, 0, 0, 0);
111 doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 0, 2, 0, 0, 0);
111112}
112113
113114/// Do a summary memory leak check (like --leak-check=summary) mid-execution.
114115pub fn doQuickLeakCheck() void {
115 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 1, 0, 0, 0, 0);
116 doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 1, 0, 0, 0, 0);
116117}
117118
118119/// Return number of leaked, dubious, reachable and suppressed bytes found by
......@@ -125,27 +126,65 @@ const CountResult = struct {
125126};
126127
127128pub fn countLeaks() CountResult {
128 var res = CountResult{
129 var res: CountResult = .{
129130 .leaked = 0,
130131 .dubious = 0,
131132 .reachable = 0,
132133 .suppressed = 0,
133134 };
134 doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeaks, &res.leaked, &res.dubious, &res.reachable, &res.suppressed, 0);
135 doMemCheckClientRequestStmt(
136 .CountLeaks,
137 @ptrToInt(&res.leaked),
138 @ptrToInt(&res.dubious),
139 @ptrToInt(&res.reachable),
140 @ptrToInt(&res.suppressed),
141 0,
142 );
135143 return res;
136144}
137145
146test "countLeaks" {
147 testing.expectEqual(
148 @as(CountResult, .{
149 .leaked = 0,
150 .dubious = 0,
151 .reachable = 0,
152 .suppressed = 0,
153 }),
154 countLeaks(),
155 );
156}
157
138158pub fn countLeakBlocks() CountResult {
139 var res = CountResult{
159 var res: CountResult = .{
140160 .leaked = 0,
141161 .dubious = 0,
142162 .reachable = 0,
143163 .suppressed = 0,
144164 };
145 doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeakBlocks, &res.leaked, &res.dubious, &res.reachable, &res.suppressed, 0);
165 doMemCheckClientRequestStmt(
166 .CountLeakBlocks,
167 @ptrToInt(&res.leaked),
168 @ptrToInt(&res.dubious),
169 @ptrToInt(&res.reachable),
170 @ptrToInt(&res.suppressed),
171 0,
172 );
146173 return res;
147174}
148175
176test "countLeakBlocks" {
177 testing.expectEqual(
178 @as(CountResult, .{
179 .leaked = 0,
180 .dubious = 0,
181 .reachable = 0,
182 .suppressed = 0,
183 }),
184 countLeakBlocks(),
185 );
186}
187
149188/// Get the validity data for addresses zza and copy it
150189/// into the provided zzvbits array. Return values:
151190/// 0 if not running on valgrind
......@@ -156,7 +195,7 @@ pub fn countLeakBlocks() CountResult {
156195/// impossible to segfault your system by using this call.
157196pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
158197 std.debug.assert(zzvbits.len >= zza.len / 8);
159 return @intCast(u2, doMemCheckClientRequestExpr(0, MemCheckClientRequest.GetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0));
198 return @intCast(u2, doMemCheckClientRequestExpr(0, .GetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0));
160199}
161200
162201/// Set the validity data for addresses zza, copying it
......@@ -169,17 +208,17 @@ pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
169208/// impossible to segfault your system by using this call.
170209pub fn setVbits(zzvbits: []u8, zza: []u8) u2 {
171210 std.debug.assert(zzvbits.len >= zza.len / 8);
172 return @intCast(u2, doMemCheckClientRequestExpr(0, MemCheckClientRequest.SetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0));
211 return @intCast(u2, doMemCheckClientRequestExpr(0, .SetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0));
173212}
174213
175214/// Disable and re-enable reporting of addressing errors in the
176215/// specified address range.
177216pub fn disableAddrErrorReportingInRange(qzz: []u8) usize {
178217 return doMemCheckClientRequestExpr(0, // default return
179 MemCheckClientRequest.DisableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
218 .DisableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
180219}
181220
182221pub fn enableAddrErrorReportingInRange(qzz: []u8) usize {
183222 return doMemCheckClientRequestExpr(0, // default return
184 MemCheckClientRequest.EnableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
223 .EnableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
185224}
lib/std/zig/ast.zig+17-6
......@@ -576,7 +576,6 @@ pub const Node = struct {
576576
577577 pub const Root = struct {
578578 base: Node,
579 doc_comments: ?*DocComment,
580579 decls: DeclList,
581580 eof_token: TokenIndex,
582581
......@@ -1648,10 +1647,15 @@ pub const Node = struct {
16481647
16491648 pub const SuffixOp = struct {
16501649 base: Node,
1651 lhs: *Node,
1650 lhs: Lhs,
16521651 op: Op,
16531652 rtoken: TokenIndex,
16541653
1654 pub const Lhs = union(enum) {
1655 node: *Node,
1656 dot: TokenIndex,
1657 };
1658
16551659 pub const Op = union(enum) {
16561660 Call: Call,
16571661 ArrayAccess: *Node,
......@@ -1679,8 +1683,13 @@ pub const Node = struct {
16791683 pub fn iterate(self: *SuffixOp, index: usize) ?*Node {
16801684 var i = index;
16811685
1682 if (i < 1) return self.lhs;
1683 i -= 1;
1686 switch (self.lhs) {
1687 .node => |node| {
1688 if (i == 0) return node;
1689 i -= 1;
1690 },
1691 .dot => {},
1692 }
16841693
16851694 switch (self.op) {
16861695 .Call => |*call_info| {
......@@ -1721,7 +1730,10 @@ pub const Node = struct {
17211730 .Call => |*call_info| if (call_info.async_token) |async_token| return async_token,
17221731 else => {},
17231732 }
1724 return self.lhs.firstToken();
1733 switch (self.lhs) {
1734 .node => |node| return node.firstToken(),
1735 .dot => |dot| return dot,
1736 }
17251737 }
17261738
17271739 pub fn lastToken(self: *const SuffixOp) TokenIndex {
......@@ -2241,7 +2253,6 @@ pub const Node = struct {
22412253test "iterate" {
22422254 var root = Node.Root{
22432255 .base = Node{ .id = Node.Id.Root },
2244 .doc_comments = null,
22452256 .decls = Node.Root.DeclList.init(std.debug.global_allocator),
22462257 .eof_token = 0,
22472258 };
lib/std/zig/parse.zig+65-28
......@@ -58,13 +58,6 @@ fn parseRoot(arena: *Allocator, it: *TokenIterator, tree: *Tree) Allocator.Error
5858 node.* = Node.Root{
5959 .base = Node{ .id = .Root },
6060 .decls = undefined,
61 // TODO: Because zig fmt collapses consecutive comments separated by blank lines into
62 // a single multi-line comment, it is currently impossible to have a container-level
63 // doc comment and NO doc comment on the first decl. For now, simply
64 // ignore the problem and assume that there will be no container-level
65 // doc comments.
66 // See: https://github.com/ziglang/zig/issues/2288
67 .doc_comments = null,
6861 .eof_token = undefined,
6962 };
7063 node.decls = parseContainerMembers(arena, it, tree) catch |err| {
......@@ -94,6 +87,11 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
9487 var list = Node.Root.DeclList.init(arena);
9588
9689 while (true) {
90 if (try parseContainerDocComments(arena, it, tree)) |node| {
91 try list.push(node);
92 continue;
93 }
94
9795 const doc_comments = try parseDocComment(arena, it, tree);
9896
9997 if (try parseTestDecl(arena, it, tree)) |node| {
......@@ -155,12 +153,35 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
155153 continue;
156154 }
157155
156 // Dangling doc comment
157 if (doc_comments != null) {
158 try tree.errors.push(AstError{
159 .UnattachedDocComment = AstError.UnattachedDocComment{ .token = doc_comments.?.firstToken() },
160 });
161 }
158162 break;
159163 }
160164
161165 return list;
162166}
163167
168/// Eat a multiline container doc comment
169fn parseContainerDocComments(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
170 var lines = Node.DocComment.LineList.init(arena);
171 while (eatToken(it, .ContainerDocComment)) |line| {
172 try lines.push(line);
173 }
174
175 if (lines.len == 0) return null;
176
177 const node = try arena.create(Node.DocComment);
178 node.* = Node.DocComment{
179 .base = Node{ .id = .DocComment },
180 .lines = lines,
181 };
182 return &node.base;
183}
184
164185/// TestDecl <- KEYWORD_test STRINGLITERAL Block
165186fn parseTestDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
166187 const test_token = eatToken(it, .Keyword_test) orelse return null;
......@@ -1026,16 +1047,16 @@ fn parseWhileExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
10261047/// CurlySuffixExpr <- TypeExpr InitList?
10271048fn parseCurlySuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
10281049 const type_expr = (try parseTypeExpr(arena, it, tree)) orelse return null;
1029 const init_list = (try parseInitList(arena, it, tree)) orelse return type_expr;
1030 init_list.cast(Node.SuffixOp).?.lhs = type_expr;
1031 return init_list;
1050 const suffix_op = (try parseInitList(arena, it, tree)) orelse return type_expr;
1051 suffix_op.lhs.node = type_expr;
1052 return &suffix_op.base;
10321053}
10331054
10341055/// InitList
10351056/// <- LBRACE FieldInit (COMMA FieldInit)* COMMA? RBRACE
10361057/// / LBRACE Expr (COMMA Expr)* COMMA? RBRACE
10371058/// / LBRACE RBRACE
1038fn parseInitList(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
1059fn parseInitList(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node.SuffixOp {
10391060 const lbrace = eatToken(it, .LBrace) orelse return null;
10401061 var init_list = Node.SuffixOp.Op.InitList.init(arena);
10411062
......@@ -1064,11 +1085,11 @@ fn parseInitList(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
10641085 const node = try arena.create(Node.SuffixOp);
10651086 node.* = Node.SuffixOp{
10661087 .base = Node{ .id = .SuffixOp },
1067 .lhs = undefined, // set by caller
1088 .lhs = .{.node = undefined}, // set by caller
10681089 .op = op,
10691090 .rtoken = try expectToken(it, tree, .RBrace),
10701091 };
1071 return &node.base;
1092 return node;
10721093}
10731094
10741095/// TypeExpr <- PrefixTypeOp* ErrorUnionExpr
......@@ -1117,7 +1138,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
11171138
11181139 while (try parseSuffixOp(arena, it, tree)) |node| {
11191140 switch (node.id) {
1120 .SuffixOp => node.cast(Node.SuffixOp).?.lhs = res,
1141 .SuffixOp => node.cast(Node.SuffixOp).?.lhs = .{.node = res},
11211142 .InfixOp => node.cast(Node.InfixOp).?.lhs = res,
11221143 else => unreachable,
11231144 }
......@@ -1133,7 +1154,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
11331154 const node = try arena.create(Node.SuffixOp);
11341155 node.* = Node.SuffixOp{
11351156 .base = Node{ .id = .SuffixOp },
1136 .lhs = res,
1157 .lhs = .{.node = res},
11371158 .op = Node.SuffixOp.Op{
11381159 .Call = Node.SuffixOp.Op.Call{
11391160 .params = params.list,
......@@ -1150,7 +1171,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
11501171 while (true) {
11511172 if (try parseSuffixOp(arena, it, tree)) |node| {
11521173 switch (node.id) {
1153 .SuffixOp => node.cast(Node.SuffixOp).?.lhs = res,
1174 .SuffixOp => node.cast(Node.SuffixOp).?.lhs = .{.node = res},
11541175 .InfixOp => node.cast(Node.InfixOp).?.lhs = res,
11551176 else => unreachable,
11561177 }
......@@ -1161,7 +1182,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
11611182 const call = try arena.create(Node.SuffixOp);
11621183 call.* = Node.SuffixOp{
11631184 .base = Node{ .id = .SuffixOp },
1164 .lhs = res,
1185 .lhs = .{.node = res},
11651186 .op = Node.SuffixOp.Op{
11661187 .Call = Node.SuffixOp.Op.Call{
11671188 .params = params.list,
......@@ -1215,7 +1236,7 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N
12151236 return &node.base;
12161237 }
12171238 if (try parseContainerDecl(arena, it, tree)) |node| return node;
1218 if (try parseEnumLiteral(arena, it, tree)) |node| return node;
1239 if (try parseAnonLiteral(arena, it, tree)) |node| return node;
12191240 if (try parseErrorSetDecl(arena, it, tree)) |node| return node;
12201241 if (try parseFloatLiteral(arena, it, tree)) |node| return node;
12211242 if (try parseFnProto(arena, it, tree)) |node| return node;
......@@ -1494,16 +1515,28 @@ fn parseAsmExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
14941515}
14951516
14961517/// DOT IDENTIFIER
1497fn parseEnumLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
1518fn parseAnonLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
14981519 const dot = eatToken(it, .Period) orelse return null;
1499 const name = try expectToken(it, tree, .Identifier);
1500 const node = try arena.create(Node.EnumLiteral);
1501 node.* = Node.EnumLiteral{
1502 .base = Node{ .id = .EnumLiteral },
1503 .dot = dot,
1504 .name = name,
1505 };
1506 return &node.base;
1520
1521 // anon enum literal
1522 if (eatToken(it, .Identifier)) |name| {
1523 const node = try arena.create(Node.EnumLiteral);
1524 node.* = Node.EnumLiteral{
1525 .base = Node{ .id = .EnumLiteral },
1526 .dot = dot,
1527 .name = name,
1528 };
1529 return &node.base;
1530 }
1531
1532 // anon container literal
1533 if (try parseInitList(arena, it, tree)) |node| {
1534 node.lhs = .{.dot = dot};
1535 return &node.base;
1536 }
1537
1538 putBackToken(it, dot);
1539 return null;
15071540}
15081541
15091542/// AsmOutput <- COLON AsmOutputList AsmInput?
......@@ -1618,7 +1651,11 @@ fn parseBlockLabel(arena: *Allocator, it: *TokenIterator, tree: *Tree) ?TokenInd
16181651/// FieldInit <- DOT IDENTIFIER EQUAL Expr
16191652fn parseFieldInit(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
16201653 const period_token = eatToken(it, .Period) orelse return null;
1621 const name_token = try expectToken(it, tree, .Identifier);
1654 const name_token = eatToken(it, .Identifier) orelse {
1655 // Because of anon literals `.{` is also valid.
1656 putBackToken(it, period_token);
1657 return null;
1658 };
16221659 const eq_token = eatToken(it, .Equal) orelse {
16231660 // `.Name` may also be an enum literal, which is a later rule.
16241661 putBackToken(it, name_token);
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+85-13
......@@ -1,9 +1,26 @@
1// TODO remove `use` keyword eventually: https://github.com/ziglang/zig/issues/2591
2test "zig fmt: change use to usingnamespace" {
3 try testTransform(
4 \\use @import("std");
5 ,
6 \\usingnamespace @import("std");
1test "zig fmt: anon literal in array" {
2 try testCanonical(
3 \\var arr: [2]Foo = .{
4 \\ .{ .a = 2 },
5 \\ .{ .b = 3 },
6 \\};
7 \\
8 );
9}
10
11test "zig fmt: anon struct literal syntax" {
12 try testCanonical(
13 \\const x = .{
14 \\ .a = b,
15 \\ .c = d,
16 \\};
17 \\
18 );
19}
20
21test "zig fmt: anon list literal syntax" {
22 try testCanonical(
23 \\const x = .{ a, b, c };
724 \\
825 );
926}
......@@ -37,7 +54,7 @@ test "zig fmt: while else err prong with no block" {
3754 \\test "" {
3855 \\ const result = while (returnError()) |value| {
3956 \\ break value;
40 \\ } else |err| i32(2);
57 \\ } else |err| @as(i32, 2);
4158 \\ expect(result == 2);
4259 \\}
4360 \\
......@@ -1444,11 +1461,11 @@ test "zig fmt: preserve spacing" {
14441461 \\const std = @import("std");
14451462 \\
14461463 \\pub fn main() !void {
1447 \\ var stdout_file = try std.io.getStdOut;
1448 \\ var stdout_file = try std.io.getStdOut;
1464 \\ var stdout_file = std.io.getStdOut;
1465 \\ var stdout_file = std.io.getStdOut;
14491466 \\
1450 \\ var stdout_file = try std.io.getStdOut;
1451 \\ var stdout_file = try std.io.getStdOut;
1467 \\ var stdout_file = std.io.getStdOut;
1468 \\ var stdout_file = std.io.getStdOut;
14521469 \\}
14531470 \\
14541471 );
......@@ -2549,6 +2566,62 @@ test "zig fmt: comments at several places in struct init" {
25492566 );
25502567}
25512568
2569test "zig fmt: top level doc comments" {
2570 try testCanonical(
2571 \\//! tld 1
2572 \\//! tld 2
2573 \\//! tld 3
2574 \\
2575 \\// comment
2576 \\
2577 \\/// A doc
2578 \\const A = struct {
2579 \\ //! A tld 1
2580 \\ //! A tld 2
2581 \\ //! A tld 3
2582 \\};
2583 \\
2584 \\/// B doc
2585 \\const B = struct {
2586 \\ //! B tld 1
2587 \\ //! B tld 2
2588 \\ //! B tld 3
2589 \\
2590 \\ /// b doc
2591 \\ b: u32,
2592 \\};
2593 \\
2594 \\/// C doc
2595 \\const C = struct {
2596 \\ //! C tld 1
2597 \\ //! C tld 2
2598 \\ //! C tld 3
2599 \\
2600 \\ /// c1 doc
2601 \\ c1: u32,
2602 \\
2603 \\ //! C tld 4
2604 \\ //! C tld 5
2605 \\ //! C tld 6
2606 \\
2607 \\ /// c2 doc
2608 \\ c2: u32,
2609 \\};
2610 \\
2611 );
2612 try testCanonical(
2613 \\//! Top-level documentation.
2614 \\
2615 \\/// This is A
2616 \\pub const A = usize;
2617 \\
2618 );
2619 try testCanonical(
2620 \\//! Nothing here
2621 \\
2622 );
2623}
2624
25522625const std = @import("std");
25532626const mem = std.mem;
25542627const warn = std.debug.warn;
......@@ -2558,8 +2631,7 @@ const maxInt = std.math.maxInt;
25582631var fixed_buffer_mem: [100 * 1024]u8 = undefined;
25592632
25602633fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 {
2561 var stderr_file = try io.getStdErr();
2562 var stderr = &stderr_file.outStream().stream;
2634 const stderr = &io.getStdErr().outStream().stream;
25632635
25642636 const tree = try std.zig.parse(allocator, source);
25652637 defer tree.deinit();
lib/std/zig/render.zig+57-21
......@@ -226,9 +226,7 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
226226 if (use_decl.visib_token) |visib_token| {
227227 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
228228 }
229 // TODO after depracating use, go back to this:
230 //try renderToken(tree, stream, use_decl.use_token, indent, start_col, Space.Space); // usingnamespace
231 try stream.write("usingnamespace ");
229 try renderToken(tree, stream, use_decl.use_token, indent, start_col, Space.Space); // usingnamespace
232230 try renderExpression(allocator, stream, tree, indent, start_col, use_decl.expr, Space.None);
233231 try renderToken(tree, stream, use_decl.semicolon_token, indent, start_col, Space.Newline); // ;
234232 },
......@@ -301,6 +299,17 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
301299 assert(!decl.requireSemiColon());
302300 try renderExpression(allocator, stream, tree, indent, start_col, decl, Space.Newline);
303301 },
302
303 ast.Node.Id.DocComment => {
304 const comment = @fieldParentPtr(ast.Node.DocComment, "base", decl);
305 var it = comment.lines.iterator(0);
306 while (it.next()) |line_token_index| {
307 try renderToken(tree, stream, line_token_index.*, indent, start_col, Space.Newline);
308 if (it.peek()) |_| {
309 try stream.writeByteNTimes(' ', indent);
310 }
311 }
312 },
304313 else => unreachable,
305314 }
306315}
......@@ -410,8 +419,8 @@ fn renderExpression(
410419 switch (prefix_op_node.op) {
411420 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
412421 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {
413 Token.Id.AsteriskAsterisk => usize(1),
414 else => usize(0),
422 Token.Id.AsteriskAsterisk => @as(usize, 1),
423 else => @as(usize, 0),
415424 };
416425 try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // *
417426 if (ptr_info.allowzero_token) |allowzero_token| {
......@@ -540,9 +549,9 @@ fn renderExpression(
540549 try renderToken(tree, stream, async_token, indent, start_col, Space.Space);
541550 }
542551
543 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
552 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs.node, Space.None);
544553
545 const lparen = tree.nextToken(suffix_op.lhs.lastToken());
554 const lparen = tree.nextToken(suffix_op.lhs.node.lastToken());
546555
547556 if (call_info.params.len == 0) {
548557 try renderToken(tree, stream, lparen, indent, start_col, Space.None);
......@@ -600,7 +609,7 @@ fn renderExpression(
600609 const lbracket = tree.prevToken(index_expr.firstToken());
601610 const rbracket = tree.nextToken(index_expr.lastToken());
602611
603 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
612 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs.node, Space.None);
604613 try renderToken(tree, stream, lbracket, indent, start_col, Space.None); // [
605614
606615 const starts_with_comment = tree.tokens.at(lbracket + 1).id == .LineComment;
......@@ -618,18 +627,18 @@ fn renderExpression(
618627 },
619628
620629 ast.Node.SuffixOp.Op.Deref => {
621 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
630 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs.node, Space.None);
622631 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space); // .*
623632 },
624633
625634 ast.Node.SuffixOp.Op.UnwrapOptional => {
626 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
635 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs.node, Space.None);
627636 try renderToken(tree, stream, tree.prevToken(suffix_op.rtoken), indent, start_col, Space.None); // .
628637 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space); // ?
629638 },
630639
631640 @TagType(ast.Node.SuffixOp.Op).Slice => |range| {
632 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
641 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs.node, Space.None);
633642
634643 const lbracket = tree.prevToken(range.start.firstToken());
635644 const dotdot = tree.nextToken(range.start.lastToken());
......@@ -649,10 +658,16 @@ fn renderExpression(
649658 },
650659
651660 ast.Node.SuffixOp.Op.StructInitializer => |*field_inits| {
652 const lbrace = tree.nextToken(suffix_op.lhs.lastToken());
661 const lbrace = switch (suffix_op.lhs) {
662 .dot => |dot| tree.nextToken(dot),
663 .node => |node| tree.nextToken(node.lastToken()),
664 };
653665
654666 if (field_inits.len == 0) {
655 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
667 switch (suffix_op.lhs) {
668 .dot => |dot| try renderToken(tree, stream, dot, indent, start_col, Space.None),
669 .node => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, Space.None),
670 }
656671 try renderToken(tree, stream, lbrace, indent + indent_delta, start_col, Space.None);
657672 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
658673 }
......@@ -693,7 +708,10 @@ fn renderExpression(
693708 break :blk;
694709 }
695710
696 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
711 switch (suffix_op.lhs) {
712 .dot => |dot| try renderToken(tree, stream, dot, indent, start_col, Space.None),
713 .node => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, Space.None),
714 }
697715 try renderToken(tree, stream, lbrace, indent, start_col, Space.Space);
698716 try renderExpression(allocator, stream, tree, indent, start_col, &field_init.base, Space.Space);
699717 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
......@@ -701,7 +719,10 @@ fn renderExpression(
701719
702720 if (!src_has_trailing_comma and src_same_line and expr_outputs_one_line) {
703721 // render all on one line, no trailing comma
704 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
722 switch (suffix_op.lhs) {
723 .dot => |dot| try renderToken(tree, stream, dot, indent, start_col, Space.None),
724 .node => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, Space.None),
725 }
705726 try renderToken(tree, stream, lbrace, indent, start_col, Space.Space);
706727
707728 var it = field_inits.iterator(0);
......@@ -721,7 +742,10 @@ fn renderExpression(
721742
722743 const new_indent = indent + indent_delta;
723744
724 try renderExpression(allocator, stream, tree, new_indent, start_col, suffix_op.lhs, Space.None);
745 switch (suffix_op.lhs) {
746 .dot => |dot| try renderToken(tree, stream, dot, new_indent, start_col, Space.None),
747 .node => |node| try renderExpression(allocator, stream, tree, new_indent, start_col, node, Space.None),
748 }
725749 try renderToken(tree, stream, lbrace, new_indent, start_col, Space.Newline);
726750
727751 var it = field_inits.iterator(0);
......@@ -745,23 +769,35 @@ fn renderExpression(
745769 },
746770
747771 ast.Node.SuffixOp.Op.ArrayInitializer => |*exprs| {
748 const lbrace = tree.nextToken(suffix_op.lhs.lastToken());
772 const lbrace = switch (suffix_op.lhs) {
773 .dot => |dot| tree.nextToken(dot),
774 .node => |node| tree.nextToken(node.lastToken()),
775 };
749776
750777 if (exprs.len == 0) {
751 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
778 switch (suffix_op.lhs) {
779 .dot => |dot| try renderToken(tree, stream, dot, indent, start_col, Space.None),
780 .node => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, Space.None),
781 }
752782 try renderToken(tree, stream, lbrace, indent, start_col, Space.None);
753783 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
754784 }
755785 if (exprs.len == 1 and tree.tokens.at(exprs.at(0).*.lastToken() + 1).id == .RBrace) {
756786 const expr = exprs.at(0).*;
757787
758 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
788 switch (suffix_op.lhs) {
789 .dot => |dot| try renderToken(tree, stream, dot, indent, start_col, Space.None),
790 .node => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, Space.None),
791 }
759792 try renderToken(tree, stream, lbrace, indent, start_col, Space.None);
760793 try renderExpression(allocator, stream, tree, indent, start_col, expr, Space.None);
761794 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
762795 }
763796
764 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
797 switch (suffix_op.lhs) {
798 .dot => |dot| try renderToken(tree, stream, dot, indent, start_col, Space.None),
799 .node => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, Space.None),
800 }
765801
766802 // scan to find row size
767803 const maybe_row_size: ?usize = blk: {
......@@ -2097,7 +2133,7 @@ fn renderTokenOffset(
20972133
20982134 while (true) {
20992135 assert(loc.line != 0);
2100 const newline_count = if (loc.line == 1) u8(1) else u8(2);
2136 const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2);
21012137 try stream.writeByteNTimes('\n', newline_count);
21022138 try stream.writeByteNTimes(' ', indent);
21032139 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
lib/std/zig/tokenizer.zig+32-24
......@@ -59,7 +59,6 @@ pub const Token = struct {
5959 Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined },
6060 Keyword{ .bytes = "union", .id = Id.Keyword_union },
6161 Keyword{ .bytes = "unreachable", .id = Id.Keyword_unreachable },
62 Keyword{ .bytes = "use", .id = Id.Keyword_usingnamespace },
6362 Keyword{ .bytes = "usingnamespace", .id = Id.Keyword_usingnamespace },
6463 Keyword{ .bytes = "var", .id = Id.Keyword_var },
6564 Keyword{ .bytes = "volatile", .id = Id.Keyword_volatile },
......@@ -143,6 +142,7 @@ pub const Token = struct {
143142 FloatLiteral,
144143 LineComment,
145144 DocComment,
145 ContainerDocComment,
146146 BracketStarBracket,
147147 BracketStarCBracket,
148148 ShebangLine,
......@@ -212,6 +212,7 @@ pub const Token = struct {
212212 .FloatLiteral => "FloatLiteral",
213213 .LineComment => "LineComment",
214214 .DocComment => "DocComment",
215 .ContainerDocComment => "ContainerDocComment",
215216 .ShebangLine => "ShebangLine",
216217
217218 .Bang => "!",
......@@ -337,26 +338,13 @@ pub const Tokenizer = struct {
337338 }
338339
339340 pub fn init(buffer: []const u8) Tokenizer {
340 if (mem.startsWith(u8, buffer, "#!")) {
341 const src_start = if (mem.indexOfScalar(u8, buffer, '\n')) |i| i + 1 else buffer.len;
342 return Tokenizer{
343 .buffer = buffer,
344 .index = src_start,
345 .pending_invalid_token = Token{
346 .id = Token.Id.ShebangLine,
347 .start = 0,
348 .end = src_start,
349 },
350 };
351 } else {
352 // Skip the UTF-8 BOM if present
353 const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0);
354 return Tokenizer{
355 .buffer = buffer,
356 .index = src_start,
357 .pending_invalid_token = null,
358 };
359 }
341 // Skip the UTF-8 BOM if present
342 const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else @as(usize, 0);
343 return Tokenizer{
344 .buffer = buffer,
345 .index = src_start,
346 .pending_invalid_token = null,
347 };
360348 }
361349
362350 const State = enum {
......@@ -388,6 +376,7 @@ pub const Tokenizer = struct {
388376 LineComment,
389377 DocCommentStart,
390378 DocComment,
379 ContainerDocComment,
391380 Zero,
392381 IntegerLiteral,
393382 IntegerLiteralWithRadix,
......@@ -763,12 +752,12 @@ pub const Tokenizer = struct {
763752 self.index += 1;
764753 break;
765754 },
766 '\n' => break, // Look for this error later.
755 '\n', '\r' => break, // Look for this error later.
767756 else => self.checkLiteralCharacter(),
768757 },
769758
770759 State.StringLiteralBackslash => switch (c) {
771 '\n' => break, // Look for this error later.
760 '\n', '\r' => break, // Look for this error later.
772761 else => {
773762 state = State.StringLiteral;
774763 },
......@@ -1077,6 +1066,10 @@ pub const Tokenizer = struct {
10771066 '/' => {
10781067 state = State.DocCommentStart;
10791068 },
1069 '!' => {
1070 result.id = Token.Id.ContainerDocComment;
1071 state = State.ContainerDocComment;
1072 },
10801073 '\n' => break,
10811074 else => {
10821075 state = State.LineComment;
......@@ -1097,7 +1090,7 @@ pub const Tokenizer = struct {
10971090 self.checkLiteralCharacter();
10981091 },
10991092 },
1100 State.LineComment, State.DocComment => switch (c) {
1093 State.LineComment, State.DocComment, State.ContainerDocComment => switch (c) {
11011094 '\n' => break,
11021095 else => self.checkLiteralCharacter(),
11031096 },
......@@ -1235,6 +1228,9 @@ pub const Tokenizer = struct {
12351228 State.DocComment, State.DocCommentStart => {
12361229 result.id = Token.Id.DocComment;
12371230 },
1231 State.ContainerDocComment => {
1232 result.id = Token.Id.ContainerDocComment;
1233 },
12381234
12391235 State.NumberDot,
12401236 State.NumberDotHex,
......@@ -1602,6 +1598,8 @@ test "tokenizer - line comment and doc comment" {
16021598 testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});
16031599 testTokenize("///", [_]Token.Id{Token.Id.DocComment});
16041600 testTokenize("////", [_]Token.Id{Token.Id.LineComment});
1601 testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment});
1602 testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment});
16051603}
16061604
16071605test "tokenizer - line comment followed by identifier" {
......@@ -1625,6 +1623,16 @@ test "tokenizer - UTF-8 BOM is recognized and skipped" {
16251623 });
16261624}
16271625
1626test "correctly parse pointer assignment" {
1627 testTokenize("b.*=3;\n", [_]Token.Id{
1628 Token.Id.Identifier,
1629 Token.Id.PeriodAsterisk,
1630 Token.Id.Equal,
1631 Token.Id.IntegerLiteral,
1632 Token.Id.Semicolon,
1633 });
1634}
1635
16281636fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
16291637 var tokenizer = Tokenizer.init(source);
16301638 for (expected_tokens) |expected_token_id| {
src-self-hosted/clang.zig+4
......@@ -42,6 +42,7 @@ pub const struct_ZigClangImplicitCastExpr = @OpaqueType();
4242pub const struct_ZigClangIncompleteArrayType = @OpaqueType();
4343pub const struct_ZigClangIntegerLiteral = @OpaqueType();
4444pub const struct_ZigClangMacroDefinitionRecord = @OpaqueType();
45pub const struct_ZigClangMacroQualifiedType = @OpaqueType();
4546pub const struct_ZigClangMemberExpr = @OpaqueType();
4647pub const struct_ZigClangNamedDecl = @OpaqueType();
4748pub const struct_ZigClangNone = @OpaqueType();
......@@ -831,6 +832,7 @@ pub const ZigClangImplicitCastExpr = struct_ZigClangImplicitCastExpr;
831832pub const ZigClangIncompleteArrayType = struct_ZigClangIncompleteArrayType;
832833pub const ZigClangIntegerLiteral = struct_ZigClangIntegerLiteral;
833834pub const ZigClangMacroDefinitionRecord = struct_ZigClangMacroDefinitionRecord;
835pub const ZigClangMacroQualifiedType = struct_ZigClangMacroQualifiedType;
834836pub const ZigClangMemberExpr = struct_ZigClangMemberExpr;
835837pub const ZigClangNamedDecl = struct_ZigClangNamedDecl;
836838pub const ZigClangNone = struct_ZigClangNone;
......@@ -937,6 +939,8 @@ pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType)
937939
938940pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType;
939941
942pub extern fn ZigClangMacroQualifiedType_getModifiedType(*const ZigClangMacroQualifiedType) ZigClangQualType;
943
940944pub extern fn ZigClangCStyleCastExpr_getBeginLoc(*const ZigClangCStyleCastExpr) ZigClangSourceLocation;
941945pub extern fn ZigClangCStyleCastExpr_getSubExpr(*const ZigClangCStyleCastExpr) *const ZigClangExpr;
942946pub extern fn ZigClangCStyleCastExpr_getType(*const ZigClangCStyleCastExpr) ZigClangQualType;
src-self-hosted/main.zig+4-7
......@@ -58,13 +58,10 @@ pub fn main() !void {
5858 // libc allocator is guaranteed to have this property.
5959 const allocator = std.heap.c_allocator;
6060
61 var stdout_file = try std.io.getStdOut();
62 var stdout_out_stream = stdout_file.outStream();
63 stdout = &stdout_out_stream.stream;
61 stdout = &std.io.getStdOut().outStream().stream;
6462
65 stderr_file = try std.io.getStdErr();
66 var stderr_out_stream = stderr_file.outStream();
67 stderr = &stderr_out_stream.stream;
63 stderr_file = std.io.getStdErr();
64 stderr = &stderr_file.outStream().stream;
6865
6966 const args = try process.argsAlloc(allocator);
7067 // TODO I'm getting unreachable code here, which shouldn't happen
......@@ -610,7 +607,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
610607 process.exit(1);
611608 }
612609
613 var stdin_file = try io.getStdIn();
610 var stdin_file = io.getStdIn();
614611 var stdin = stdin_file.inStream();
615612
616613 const source_code = try stdin.stream.readAllAlloc(allocator, max_src_size);
src-self-hosted/stage1.zig+5-9
......@@ -165,13 +165,9 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
165165 try args_list.append(std.mem.toSliceConst(u8, argv[arg_i]));
166166 }
167167
168 var stdout_file = try std.io.getStdOut();
169 var stdout_out_stream = stdout_file.outStream();
170 stdout = &stdout_out_stream.stream;
171
172 stderr_file = try std.io.getStdErr();
173 var stderr_out_stream = stderr_file.outStream();
174 stderr = &stderr_out_stream.stream;
168 stdout = &std.io.getStdOut().outStream().stream;
169 stderr_file = std.io.getStdErr();
170 stderr = &stderr_file.outStream().stream;
175171
176172 const args = args_list.toSliceConst();
177173 var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]);
......@@ -202,7 +198,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
202198 process.exit(1);
203199 }
204200
205 var stdin_file = try io.getStdIn();
201 const stdin_file = io.getStdIn();
206202 var stdin = stdin_file.inStream();
207203
208204 const source_code = try stdin.stream.readAllAlloc(allocator, self_hosted_main.max_src_size);
......@@ -223,7 +219,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
223219 }
224220 if (flags.present("check")) {
225221 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
226 const code = if (anything_changed) u8(1) else u8(0);
222 const code = if (anything_changed) @as(u8, 1) else @as(u8, 0);
227223 process.exit(code);
228224 }
229225
src-self-hosted/test.zig+3-3
......@@ -171,8 +171,8 @@ pub const TestContext = struct {
171171 return error.OutputMismatch;
172172 }
173173 },
174 .Error => |err| return err,
175 .Fail => |msgs| {
174 Compilation.Event.Error => |err| return err,
175 Compilation.Event.Fail => |msgs| {
176176 var stderr = try std.io.getStdErr();
177177 try stderr.write("build incorrectly failed:\n");
178178 for (msgs) |msg| {
......@@ -223,7 +223,7 @@ pub const TestContext = struct {
223223 text,
224224 );
225225 std.debug.warn("\n====found:========\n");
226 var stderr = try std.io.getStdErr();
226 const stderr = std.io.getStdErr();
227227 for (msgs) |msg| {
228228 defer msg.destroy();
229229 try msg.printToFile(stderr, errmsg.Color.Auto);
src-self-hosted/translate_c.zig+11-8
......@@ -122,7 +122,7 @@ const Context = struct {
122122 fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 {
123123 const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc);
124124 const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc);
125 const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)");
125 const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)");
126126
127127 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
128128 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
......@@ -173,7 +173,6 @@ pub fn translate(
173173 tree.root_node.* = ast.Node.Root{
174174 .base = ast.Node{ .id = ast.Node.Id.Root },
175175 .decls = ast.Node.Root.DeclList.init(arena),
176 .doc_comments = null,
177176 // initialized with the eof token at the end
178177 .eof_token = undefined,
179178 };
......@@ -773,12 +772,14 @@ fn transCCast(
773772 if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))
774773 return transCPtrCast(rp, loc, dst_type, src_type, expr);
775774 if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) {
776 const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
775 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
776 try cast_node.params.push(try transQualType(rp, dst_type, loc));
777 _ = try appendToken(rp.c, .Comma, ",");
777778 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");
778779 try builtin_node.params.push(expr);
779780 builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")");
780 try cast_node.op.Call.params.push(&builtin_node.base);
781 cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
781 try cast_node.params.push(&builtin_node.base);
782 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
782783 return &cast_node.base;
783784 }
784785 if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) {
......@@ -792,9 +793,11 @@ fn transCCast(
792793 // TODO: maybe widen to increase size
793794 // TODO: maybe bitcast to change sign
794795 // TODO: maybe truncate to reduce size
795 const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
796 try cast_node.op.Call.params.push(expr);
797 cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
796 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
797 try cast_node.params.push(try transQualType(rp, dst_type, loc));
798 _ = try appendToken(rp.c, .Comma, ",");
799 try cast_node.params.push(expr);
800 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
798801 return &cast_node.base;
799802}
800803
src/all_types.hpp+50-13
......@@ -48,6 +48,7 @@ struct ResultLoc;
4848struct ResultLocPeer;
4949struct ResultLocPeerParent;
5050struct ResultLocBitCast;
51struct ResultLocCast;
5152struct ResultLocReturn;
5253
5354enum PtrLen {
......@@ -151,7 +152,7 @@ struct ConstParent {
151152};
152153
153154struct ConstStructValue {
154 ConstExprValue *fields;
155 ConstExprValue **fields;
155156};
156157
157158struct ConstUnionValue {
......@@ -967,6 +968,7 @@ struct AstNodeContainerDecl {
967968 AstNode *init_arg_expr; // enum(T), struct(endianness), or union(T), or union(enum(T))
968969 ZigList<AstNode *> fields;
969970 ZigList<AstNode *> decls;
971 Buf doc_comments;
970972
971973 ContainerKind kind;
972974 ContainerLayout layout;
......@@ -1186,10 +1188,22 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b);
11861188static const uint32_t VECTOR_INDEX_NONE = UINT32_MAX;
11871189static const uint32_t VECTOR_INDEX_RUNTIME = UINT32_MAX - 1;
11881190
1191struct InferredStructField {
1192 ZigType *inferred_struct_type;
1193 Buf *field_name;
1194};
1195
11891196struct ZigTypePointer {
11901197 ZigType *child_type;
11911198 ZigType *slice_parent;
11921199
1200 // Anonymous struct literal syntax uses this when the result location has
1201 // no type in it. This field is null if this pointer does not refer to
1202 // a field of a currently-being-inferred struct type.
1203 // When this is non-null, the pointer is pointing to the base of the inferred
1204 // struct.
1205 InferredStructField *inferred_struct_field;
1206
11931207 PtrLen ptr_len;
11941208 uint32_t explicit_alignment; // 0 means use ABI alignment
11951209
......@@ -1236,6 +1250,7 @@ struct TypeStructField {
12361250enum ResolveStatus {
12371251 ResolveStatusUnstarted,
12381252 ResolveStatusInvalid,
1253 ResolveStatusBeingInferred,
12391254 ResolveStatusZeroBitsKnown,
12401255 ResolveStatusAlignmentKnown,
12411256 ResolveStatusSizeKnown,
......@@ -1265,7 +1280,7 @@ struct RootStruct {
12651280
12661281struct ZigTypeStruct {
12671282 AstNode *decl_node;
1268 TypeStructField *fields;
1283 TypeStructField **fields;
12691284 ScopeDecls *decls_scope;
12701285 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
12711286 RootStruct *root_struct;
......@@ -1284,6 +1299,7 @@ struct ZigTypeStruct {
12841299 bool requires_comptime;
12851300 bool resolve_loop_flag_zero_bits;
12861301 bool resolve_loop_flag_other;
1302 bool is_inferred;
12871303};
12881304
12891305struct ZigTypeOptional {
......@@ -1685,12 +1701,14 @@ enum BuiltinFnId {
16851701 BuiltinFnIdErrorReturnTrace,
16861702 BuiltinFnIdAtomicRmw,
16871703 BuiltinFnIdAtomicLoad,
1704 BuiltinFnIdAtomicStore,
16881705 BuiltinFnIdHasDecl,
16891706 BuiltinFnIdUnionInit,
16901707 BuiltinFnIdFrameAddress,
16911708 BuiltinFnIdFrameType,
16921709 BuiltinFnIdFrameHandle,
16931710 BuiltinFnIdFrameSize,
1711 BuiltinFnIdAs,
16941712};
16951713
16961714struct BuiltinFnEntry {
......@@ -1739,6 +1757,7 @@ struct TypeId {
17391757 union {
17401758 struct {
17411759 ZigType *child_type;
1760 InferredStructField *inferred_struct_field;
17421761 PtrLen ptr_len;
17431762 uint32_t alignment;
17441763
......@@ -2552,6 +2571,7 @@ enum IrInstructionId {
25522571 IrInstructionIdErrorUnion,
25532572 IrInstructionIdAtomicRmw,
25542573 IrInstructionIdAtomicLoad,
2574 IrInstructionIdAtomicStore,
25552575 IrInstructionIdSaveErrRetAddr,
25562576 IrInstructionIdAddImplicitReturnType,
25572577 IrInstructionIdErrSetCast,
......@@ -2810,7 +2830,7 @@ struct IrInstructionElemPtr {
28102830
28112831 IrInstruction *array_ptr;
28122832 IrInstruction *elem_index;
2813 IrInstruction *init_array_type;
2833 AstNode *init_array_type_source_node;
28142834 PtrLen ptr_len;
28152835 bool safety_check_on;
28162836};
......@@ -2907,11 +2927,11 @@ struct IrInstructionResizeSlice {
29072927struct IrInstructionContainerInitList {
29082928 IrInstruction base;
29092929
2910 IrInstruction *container_type;
29112930 IrInstruction *elem_type;
29122931 size_t item_count;
29132932 IrInstruction **elem_result_loc_list;
29142933 IrInstruction *result_loc;
2934 AstNode *init_array_type_source_node;
29152935};
29162936
29172937struct IrInstructionContainerInitFieldsField {
......@@ -2924,7 +2944,6 @@ struct IrInstructionContainerInitFieldsField {
29242944struct IrInstructionContainerInitFields {
29252945 IrInstruction base;
29262946
2927 IrInstruction *container_type;
29282947 size_t field_count;
29292948 IrInstructionContainerInitFieldsField *fields;
29302949 IrInstruction *result_loc;
......@@ -3458,6 +3477,13 @@ struct IrInstructionPtrCastGen {
34583477 bool safety_check_on;
34593478};
34603479
3480struct IrInstructionImplicitCast {
3481 IrInstruction base;
3482
3483 IrInstruction *operand;
3484 ResultLocCast *result_loc_cast;
3485};
3486
34613487struct IrInstructionBitCastSrc {
34623488 IrInstruction base;
34633489
......@@ -3642,6 +3668,7 @@ struct IrInstructionArgType {
36423668
36433669 IrInstruction *fn_type;
36443670 IrInstruction *arg_index;
3671 bool allow_var;
36453672};
36463673
36473674struct IrInstructionExport {
......@@ -3690,6 +3717,16 @@ struct IrInstructionAtomicLoad {
36903717 AtomicOrder resolved_ordering;
36913718};
36923719
3720struct IrInstructionAtomicStore {
3721 IrInstruction base;
3722
3723 IrInstruction *operand_type;
3724 IrInstruction *ptr;
3725 IrInstruction *value;
3726 IrInstruction *ordering;
3727 AtomicOrder resolved_ordering;
3728};
3729
36933730struct IrInstructionSaveErrRetAddr {
36943731 IrInstruction base;
36953732};
......@@ -3823,14 +3860,6 @@ struct IrInstructionEndExpr {
38233860 ResultLoc *result_loc;
38243861};
38253862
3826struct IrInstructionImplicitCast {
3827 IrInstruction base;
3828
3829 IrInstruction *dest_type;
3830 IrInstruction *target;
3831 ResultLoc *result_loc;
3832};
3833
38343863// This one is for writing through the result pointer.
38353864struct IrInstructionResolveResult {
38363865 IrInstruction base;
......@@ -3928,6 +3957,7 @@ enum ResultLocId {
39283957 ResultLocIdPeerParent,
39293958 ResultLocIdInstruction,
39303959 ResultLocIdBitCast,
3960 ResultLocIdCast,
39313961};
39323962
39333963// Additions to this struct may need to be handled in
......@@ -3995,6 +4025,13 @@ struct ResultLocBitCast {
39954025 ResultLoc *parent;
39964026};
39974027
4028// The source_instruction is the destination type
4029struct ResultLocCast {
4030 ResultLoc base;
4031
4032 ResultLoc *parent;
4033};
4034
39984035static const size_t slice_ptr_index = 0;
39994036static const size_t slice_len_index = 1;
40004037
src/analyze.cpp+196-92
......@@ -140,7 +140,6 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope
140140static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type,
141141 ZigType *import, Buf *bare_name)
142142{
143 assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);
144143 ScopeDecls *scope = allocate<ScopeDecls>(1);
145144 init_scope(g, &scope->base, ScopeIdDecls, node, parent);
146145 scope->decl_table.init(4);
......@@ -346,6 +345,8 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
346345 switch (status) {
347346 case ResolveStatusInvalid:
348347 zig_unreachable();
348 case ResolveStatusBeingInferred:
349 zig_unreachable();
349350 case ResolveStatusUnstarted:
350351 case ResolveStatusZeroBitsKnown:
351352 return true;
......@@ -362,6 +363,8 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
362363 switch (status) {
363364 case ResolveStatusInvalid:
364365 zig_unreachable();
366 case ResolveStatusBeingInferred:
367 zig_unreachable();
365368 case ResolveStatusUnstarted:
366369 return true;
367370 case ResolveStatusZeroBitsKnown:
......@@ -483,7 +486,7 @@ ZigType *get_fn_frame_type(CodeGen *g, ZigFn *fn) {
483486ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_const,
484487 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment,
485488 uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero,
486 uint32_t vector_index)
489 uint32_t vector_index, InferredStructField *inferred_struct_field)
487490{
488491 assert(ptr_len != PtrLenC || allow_zero);
489492 assert(!type_is_invalid(child_type));
......@@ -506,7 +509,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
506509 TypeId type_id = {};
507510 ZigType **parent_pointer = nullptr;
508511 if (host_int_bytes != 0 || is_volatile || byte_alignment != 0 || ptr_len != PtrLenSingle ||
509 allow_zero || vector_index != VECTOR_INDEX_NONE)
512 allow_zero || vector_index != VECTOR_INDEX_NONE || inferred_struct_field != nullptr)
510513 {
511514 type_id.id = ZigTypeIdPointer;
512515 type_id.data.pointer.child_type = child_type;
......@@ -518,6 +521,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
518521 type_id.data.pointer.ptr_len = ptr_len;
519522 type_id.data.pointer.allow_zero = allow_zero;
520523 type_id.data.pointer.vector_index = vector_index;
524 type_id.data.pointer.inferred_struct_field = inferred_struct_field;
521525
522526 auto existing_entry = g->type_table.maybe_get(type_id);
523527 if (existing_entry)
......@@ -545,8 +549,15 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
545549 }
546550 buf_resize(&entry->name, 0);
547551 if (host_int_bytes == 0 && byte_alignment == 0 && vector_index == VECTOR_INDEX_NONE) {
548 buf_appendf(&entry->name, "%s%s%s%s%s",
549 star_str, const_str, volatile_str, allow_zero_str, buf_ptr(&child_type->name));
552 if (inferred_struct_field == nullptr) {
553 buf_appendf(&entry->name, "%s%s%s%s%s",
554 star_str, const_str, volatile_str, allow_zero_str, buf_ptr(&child_type->name));
555 } else {
556 buf_appendf(&entry->name, "(%s%s%s%s field '%s' of %s)",
557 star_str, const_str, volatile_str, allow_zero_str,
558 buf_ptr(inferred_struct_field->field_name),
559 buf_ptr(&inferred_struct_field->inferred_struct_type->name));
560 }
550561 } else if (host_int_bytes == 0 && vector_index == VECTOR_INDEX_NONE) {
551562 buf_appendf(&entry->name, "%salign(%" PRIu32 ") %s%s%s%s", star_str, byte_alignment,
552563 const_str, volatile_str, allow_zero_str, buf_ptr(&child_type->name));
......@@ -603,6 +614,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
603614 entry->data.pointer.host_int_bytes = host_int_bytes;
604615 entry->data.pointer.allow_zero = allow_zero;
605616 entry->data.pointer.vector_index = vector_index;
617 entry->data.pointer.inferred_struct_field = inferred_struct_field;
606618
607619 if (parent_pointer) {
608620 *parent_pointer = entry;
......@@ -617,12 +629,12 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
617629 uint32_t bit_offset_in_host, uint32_t host_int_bytes, bool allow_zero)
618630{
619631 return get_pointer_to_type_extra2(g, child_type, is_const, is_volatile, ptr_len,
620 byte_alignment, bit_offset_in_host, host_int_bytes, allow_zero, VECTOR_INDEX_NONE);
632 byte_alignment, bit_offset_in_host, host_int_bytes, allow_zero, VECTOR_INDEX_NONE, nullptr);
621633}
622634
623635ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) {
624636 return get_pointer_to_type_extra2(g, child_type, is_const, false, PtrLenSingle, 0, 0, 0, false,
625 VECTOR_INDEX_NONE);
637 VECTOR_INDEX_NONE, nullptr);
626638}
627639
628640ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
......@@ -791,19 +803,19 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
791803 entry->data.structure.is_slice = true;
792804 entry->data.structure.src_field_count = element_count;
793805 entry->data.structure.gen_field_count = element_count;
794 entry->data.structure.fields = allocate<TypeStructField>(element_count);
806 entry->data.structure.fields = alloc_type_struct_fields(element_count);
795807 entry->data.structure.fields_by_name.init(element_count);
796 entry->data.structure.fields[slice_ptr_index].name = ptr_field_name;
797 entry->data.structure.fields[slice_ptr_index].type_entry = ptr_type;
798 entry->data.structure.fields[slice_ptr_index].src_index = slice_ptr_index;
799 entry->data.structure.fields[slice_ptr_index].gen_index = 0;
800 entry->data.structure.fields[slice_len_index].name = len_field_name;
801 entry->data.structure.fields[slice_len_index].type_entry = g->builtin_types.entry_usize;
802 entry->data.structure.fields[slice_len_index].src_index = slice_len_index;
803 entry->data.structure.fields[slice_len_index].gen_index = 1;
804
805 entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]);
806 entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]);
808 entry->data.structure.fields[slice_ptr_index]->name = ptr_field_name;
809 entry->data.structure.fields[slice_ptr_index]->type_entry = ptr_type;
810 entry->data.structure.fields[slice_ptr_index]->src_index = slice_ptr_index;
811 entry->data.structure.fields[slice_ptr_index]->gen_index = 0;
812 entry->data.structure.fields[slice_len_index]->name = len_field_name;
813 entry->data.structure.fields[slice_len_index]->type_entry = g->builtin_types.entry_usize;
814 entry->data.structure.fields[slice_len_index]->src_index = slice_len_index;
815 entry->data.structure.fields[slice_len_index]->gen_index = 1;
816
817 entry->data.structure.fields_by_name.put(ptr_field_name, entry->data.structure.fields[slice_ptr_index]);
818 entry->data.structure.fields_by_name.put(len_field_name, entry->data.structure.fields[slice_len_index]);
807819
808820 switch (type_requires_comptime(g, ptr_type)) {
809821 case ReqCompTimeInvalid:
......@@ -816,8 +828,8 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
816828
817829 if (!type_has_bits(ptr_type)) {
818830 entry->data.structure.gen_field_count = 1;
819 entry->data.structure.fields[slice_ptr_index].gen_index = SIZE_MAX;
820 entry->data.structure.fields[slice_len_index].gen_index = 0;
831 entry->data.structure.fields[slice_ptr_index]->gen_index = SIZE_MAX;
832 entry->data.structure.fields[slice_len_index]->gen_index = 0;
821833 }
822834
823835 ZigType *child_type = ptr_type->data.pointer.child_type;
......@@ -1449,8 +1461,8 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
14491461 if (type_is_invalid(result_val->type))
14501462 return false;
14511463
1452 ConstExprValue *ptr_field = &result_val->data.x_struct.fields[slice_ptr_index];
1453 ConstExprValue *len_field = &result_val->data.x_struct.fields[slice_len_index];
1464 ConstExprValue *ptr_field = result_val->data.x_struct.fields[slice_ptr_index];
1465 ConstExprValue *len_field = result_val->data.x_struct.fields[slice_len_index];
14541466
14551467 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
14561468 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
......@@ -1972,12 +1984,12 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
19721984 struct_type->data.structure.src_field_count = field_count;
19731985 struct_type->data.structure.gen_field_count = 0;
19741986 struct_type->data.structure.resolve_status = ResolveStatusSizeKnown;
1975 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
1987 struct_type->data.structure.fields = alloc_type_struct_fields(field_count);
19761988 struct_type->data.structure.fields_by_name.init(field_count);
19771989
19781990 size_t abi_align = min_abi_align;
19791991 for (size_t i = 0; i < field_count; i += 1) {
1980 TypeStructField *field = &struct_type->data.structure.fields[i];
1992 TypeStructField *field = struct_type->data.structure.fields[i];
19811993 field->name = buf_create_from_str(fields[i].name);
19821994 field->type_entry = fields[i].ty;
19831995 field->src_index = i;
......@@ -1997,7 +2009,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
19972009
19982010 size_t next_offset = 0;
19992011 for (size_t i = 0; i < field_count; i += 1) {
2000 TypeStructField *field = &struct_type->data.structure.fields[i];
2012 TypeStructField *field = struct_type->data.structure.fields[i];
20012013 if (!type_has_bits(field->type_entry))
20022014 continue;
20032015
......@@ -2006,7 +2018,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
20062018 // find the next non-zero-byte field for offset calculations
20072019 size_t next_src_field_index = i + 1;
20082020 for (; next_src_field_index < field_count; next_src_field_index += 1) {
2009 if (type_has_bits(struct_type->data.structure.fields[next_src_field_index].type_entry))
2021 if (type_has_bits(struct_type->data.structure.fields[next_src_field_index]->type_entry))
20102022 break;
20112023 }
20122024 size_t next_abi_align;
......@@ -2014,7 +2026,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
20142026 next_abi_align = abi_align;
20152027 } else {
20162028 next_abi_align = max(fields[next_src_field_index].align,
2017 struct_type->data.structure.fields[next_src_field_index].type_entry->abi_align);
2029 struct_type->data.structure.fields[next_src_field_index]->type_entry->abi_align);
20182030 }
20192031 next_offset = next_field_offset(next_offset, abi_align, field->type_entry->abi_size, next_abi_align);
20202032 }
......@@ -2079,7 +2091,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
20792091 }
20802092
20812093 assert(struct_type->data.structure.fields || struct_type->data.structure.src_field_count == 0);
2082 assert(decl_node->type == NodeTypeContainerDecl);
2094 assert(decl_node->type == NodeTypeContainerDecl || decl_node->type == NodeTypeContainerInitExpr);
20832095
20842096 size_t field_count = struct_type->data.structure.src_field_count;
20852097
......@@ -2097,7 +2109,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
20972109
20982110 // Calculate offsets
20992111 for (size_t i = 0; i < field_count; i += 1) {
2100 TypeStructField *field = &struct_type->data.structure.fields[i];
2112 TypeStructField *field = struct_type->data.structure.fields[i];
21012113 if (field->gen_index == SIZE_MAX)
21022114 continue;
21032115
......@@ -2166,12 +2178,12 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
21662178 gen_field_index += 1;
21672179 size_t next_src_field_index = i + 1;
21682180 for (; next_src_field_index < field_count; next_src_field_index += 1) {
2169 if (struct_type->data.structure.fields[next_src_field_index].gen_index != SIZE_MAX) {
2181 if (struct_type->data.structure.fields[next_src_field_index]->gen_index != SIZE_MAX) {
21702182 break;
21712183 }
21722184 }
21732185 size_t next_align = (next_src_field_index == field_count) ?
2174 abi_align : struct_type->data.structure.fields[next_src_field_index].align;
2186 abi_align : struct_type->data.structure.fields[next_src_field_index]->align;
21752187 next_offset = next_field_offset(next_offset, abi_align, field_abi_size, next_align);
21762188 size_in_bits = next_offset * 8;
21772189 }
......@@ -2194,7 +2206,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
21942206
21952207 // Resolve types for fields
21962208 for (size_t i = 0; i < field_count; i += 1) {
2197 TypeStructField *field = &struct_type->data.structure.fields[i];
2209 TypeStructField *field = struct_type->data.structure.fields[i];
21982210 ZigType *field_type = resolve_struct_field_type(g, field);
21992211 if (field_type == nullptr) {
22002212 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
......@@ -2667,7 +2679,6 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
26672679 return ErrorNone;
26682680
26692681 AstNode *decl_node = struct_type->data.structure.decl_node;
2670 assert(decl_node->type == NodeTypeContainerDecl);
26712682
26722683 if (struct_type->data.structure.resolve_loop_flag_zero_bits) {
26732684 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
......@@ -2678,29 +2689,46 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
26782689 }
26792690 return ErrorSemanticAnalyzeFail;
26802691 }
2681
26822692 struct_type->data.structure.resolve_loop_flag_zero_bits = true;
26832693
2684 assert(!struct_type->data.structure.fields);
2685 size_t field_count = decl_node->data.container_decl.fields.length;
2686 struct_type->data.structure.src_field_count = (uint32_t)field_count;
2687 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
2694 size_t field_count;
2695 if (decl_node->type == NodeTypeContainerDecl) {
2696 field_count = decl_node->data.container_decl.fields.length;
2697 struct_type->data.structure.src_field_count = (uint32_t)field_count;
2698
2699 src_assert(struct_type->data.structure.fields == nullptr, decl_node);
2700 struct_type->data.structure.fields = alloc_type_struct_fields(field_count);
2701 } else if (decl_node->type == NodeTypeContainerInitExpr) {
2702 src_assert(struct_type->data.structure.is_inferred, decl_node);
2703 src_assert(struct_type->data.structure.fields != nullptr, decl_node);
2704
2705 field_count = struct_type->data.structure.src_field_count;
2706 } else zig_unreachable();
2707
26882708 struct_type->data.structure.fields_by_name.init(field_count);
26892709
26902710 Scope *scope = &struct_type->data.structure.decls_scope->base;
26912711
26922712 size_t gen_field_index = 0;
26932713 for (size_t i = 0; i < field_count; i += 1) {
2694 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
2695 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
2696 type_struct_field->name = field_node->data.struct_field.name;
2697 type_struct_field->decl_node = field_node;
2714 TypeStructField *type_struct_field = struct_type->data.structure.fields[i];
26982715
2699 if (field_node->data.struct_field.type == nullptr) {
2700 add_node_error(g, field_node, buf_sprintf("struct field missing type"));
2701 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2702 return ErrorSemanticAnalyzeFail;
2703 }
2716 AstNode *field_node;
2717 if (decl_node->type == NodeTypeContainerDecl) {
2718 field_node = decl_node->data.container_decl.fields.at(i);
2719 type_struct_field->name = field_node->data.struct_field.name;
2720 type_struct_field->decl_node = field_node;
2721
2722 if (field_node->data.struct_field.type == nullptr) {
2723 add_node_error(g, field_node, buf_sprintf("struct field missing type"));
2724 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2725 return ErrorSemanticAnalyzeFail;
2726 }
2727 } else if (decl_node->type == NodeTypeContainerInitExpr) {
2728 field_node = type_struct_field->decl_node;
2729
2730 src_assert(type_struct_field->type_entry != nullptr, field_node);
2731 } else zig_unreachable();
27042732
27052733 auto field_entry = struct_type->data.structure.fields_by_name.put_unique(type_struct_field->name, type_struct_field);
27062734 if (field_entry != nullptr) {
......@@ -2711,16 +2739,21 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
27112739 return ErrorSemanticAnalyzeFail;
27122740 }
27132741
2714 ConstExprValue *field_type_val = analyze_const_value(g, scope,
2715 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
2716 if (type_is_invalid(field_type_val->type)) {
2717 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2718 return ErrorSemanticAnalyzeFail;
2719 }
2720 assert(field_type_val->special != ConstValSpecialRuntime);
2721 type_struct_field->type_val = field_type_val;
2722 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid)
2723 return ErrorSemanticAnalyzeFail;
2742 ConstExprValue *field_type_val;
2743 if (decl_node->type == NodeTypeContainerDecl) {
2744 field_type_val = analyze_const_value(g, scope,
2745 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
2746 if (type_is_invalid(field_type_val->type)) {
2747 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2748 return ErrorSemanticAnalyzeFail;
2749 }
2750 assert(field_type_val->special != ConstValSpecialRuntime);
2751 type_struct_field->type_val = field_type_val;
2752 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid)
2753 return ErrorSemanticAnalyzeFail;
2754 } else if (decl_node->type == NodeTypeContainerInitExpr) {
2755 field_type_val = type_struct_field->type_val;
2756 } else zig_unreachable();
27242757
27252758 bool field_is_opaque_type;
27262759 if ((err = type_val_resolve_is_opaque_type(g, field_type_val, &field_is_opaque_type))) {
......@@ -2804,17 +2837,18 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
28042837 }
28052838
28062839 struct_type->data.structure.resolve_loop_flag_other = true;
2807 assert(decl_node->type == NodeTypeContainerDecl);
2840 assert(decl_node->type == NodeTypeContainerDecl || decl_node->type == NodeTypeContainerInitExpr);
28082841
28092842 size_t field_count = struct_type->data.structure.src_field_count;
28102843 bool packed = struct_type->data.structure.layout == ContainerLayoutPacked;
28112844
28122845 for (size_t i = 0; i < field_count; i += 1) {
2813 TypeStructField *field = &struct_type->data.structure.fields[i];
2846 TypeStructField *field = struct_type->data.structure.fields[i];
28142847 if (field->gen_index == SIZE_MAX)
28152848 continue;
28162849
2817 AstNode *align_expr = field->decl_node->data.struct_field.align_expr;
2850 AstNode *align_expr = (field->decl_node->type == NodeTypeStructField) ?
2851 field->decl_node->data.struct_field.align_expr : nullptr;
28182852 if (align_expr != nullptr) {
28192853 if (!analyze_const_align(g, &struct_type->data.structure.decls_scope->base, align_expr,
28202854 &field->align))
......@@ -5249,7 +5283,7 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
52495283 zig_unreachable();
52505284 case ZigTypeIdStruct:
52515285 for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
5252 if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))
5286 if (can_mutate_comptime_var_state(value->data.x_struct.fields[i]))
52535287 return true;
52545288 }
52555289 return false;
......@@ -5398,7 +5432,7 @@ bool fn_eval_eql(Scope *a, Scope *b) {
53985432 return false;
53995433}
54005434
5401// Whether the type has bits at runtime.
5435// Deprecated. Use type_has_bits2.
54025436bool type_has_bits(ZigType *type_entry) {
54035437 assert(type_entry != nullptr);
54045438 assert(!type_is_invalid(type_entry));
......@@ -5406,6 +5440,27 @@ bool type_has_bits(ZigType *type_entry) {
54065440 return type_entry->abi_size != 0;
54075441}
54085442
5443// Whether the type has bits at runtime.
5444Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result) {
5445 Error err;
5446
5447 if (type_is_invalid(type_entry))
5448 return ErrorSemanticAnalyzeFail;
5449
5450 if (type_entry->id == ZigTypeIdStruct &&
5451 type_entry->data.structure.resolve_status == ResolveStatusBeingInferred)
5452 {
5453 *result = true;
5454 return ErrorNone;
5455 }
5456
5457 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
5458 return err;
5459
5460 *result = type_entry->abi_size != 0;
5461 return ErrorNone;
5462}
5463
54095464// Whether you can infer the value based solely on the type.
54105465OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
54115466 assert(type_entry != nullptr);
......@@ -5413,6 +5468,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
54135468 if (type_entry->one_possible_value != OnePossibleValueInvalid)
54145469 return type_entry->one_possible_value;
54155470
5471 if (type_entry->id == ZigTypeIdStruct &&
5472 type_entry->data.structure.resolve_status == ResolveStatusBeingInferred)
5473 {
5474 return OnePossibleValueNo;
5475 }
5476
54165477 Error err;
54175478 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
54185479 return OnePossibleValueInvalid;
......@@ -5445,7 +5506,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
54455506 return type_has_one_possible_value(g, type_entry->data.array.child_type);
54465507 case ZigTypeIdStruct:
54475508 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
5448 TypeStructField *field = &type_entry->data.structure.fields[i];
5509 TypeStructField *field = type_entry->data.structure.fields[i];
54495510 OnePossibleValue opv = (field->type_entry != nullptr) ?
54505511 type_has_one_possible_value(g, field->type_entry) :
54515512 type_val_resolve_has_one_possible_value(g, field->type_val);
......@@ -5737,11 +5798,11 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
57375798
57385799 const_val->special = ConstValSpecialStatic;
57395800 const_val->type = get_slice_type(g, ptr_type);
5740 const_val->data.x_struct.fields = create_const_vals(2);
5801 const_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
57415802
5742 init_const_ptr_array(g, &const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,
5803 init_const_ptr_array(g, const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,
57435804 PtrLenUnknown);
5744 init_const_usize(g, &const_val->data.x_struct.fields[slice_len_index], len);
5805 init_const_usize(g, const_val->data.x_struct.fields[slice_len_index], len);
57455806}
57465807
57475808ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const) {
......@@ -5825,6 +5886,38 @@ ConstExprValue *create_const_vals(size_t count) {
58255886 return vals;
58265887}
58275888
5889ConstExprValue **alloc_const_vals_ptrs(size_t count) {
5890 return realloc_const_vals_ptrs(nullptr, 0, count);
5891}
5892
5893ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count) {
5894 assert(new_count >= old_count);
5895
5896 size_t new_item_count = new_count - old_count;
5897 ConstExprValue **result = reallocate(ptr, old_count, new_count, "ConstExprValue*");
5898 ConstExprValue *vals = create_const_vals(new_item_count);
5899 for (size_t i = old_count; i < new_count; i += 1) {
5900 result[i] = &vals[i - old_count];
5901 }
5902 return result;
5903}
5904
5905TypeStructField **alloc_type_struct_fields(size_t count) {
5906 return realloc_type_struct_fields(nullptr, 0, count);
5907}
5908
5909TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count) {
5910 assert(new_count >= old_count);
5911
5912 size_t new_item_count = new_count - old_count;
5913 TypeStructField **result = reallocate(ptr, old_count, new_count, "TypeStructField*");
5914 TypeStructField *vals = allocate<TypeStructField>(new_item_count, "TypeStructField");
5915 for (size_t i = old_count; i < new_count; i += 1) {
5916 result[i] = &vals[i - old_count];
5917 }
5918 return result;
5919}
5920
58285921static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
58295922 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)
58305923 return orig_fn_type;
......@@ -6132,6 +6225,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
61326225 continue;
61336226 if (instruction->ref_count == 0)
61346227 continue;
6228 if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown)))
6229 return ErrorSemanticAnalyzeFail;
61356230 if (!type_has_bits(instruction->value.type))
61366231 continue;
61376232 if (scope_needs_spill(instruction->scope)) {
......@@ -6271,6 +6366,8 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) {
62716366 switch (status) {
62726367 case ResolveStatusUnstarted:
62736368 return ErrorNone;
6369 case ResolveStatusBeingInferred:
6370 zig_unreachable();
62746371 case ResolveStatusInvalid:
62756372 zig_unreachable();
62766373 case ResolveStatusZeroBitsKnown:
......@@ -6502,8 +6599,8 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
65026599 }
65036600 case ZigTypeIdStruct:
65046601 for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
6505 ConstExprValue *field_a = &a->data.x_struct.fields[i];
6506 ConstExprValue *field_b = &b->data.x_struct.fields[i];
6602 ConstExprValue *field_a = a->data.x_struct.fields[i];
6603 ConstExprValue *field_b = b->data.x_struct.fields[i];
65076604 if (!const_values_equal(g, field_a, field_b))
65086605 return false;
65096606 }
......@@ -6811,10 +6908,10 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
68116908 case ZigTypeIdStruct:
68126909 {
68136910 if (is_slice(type_entry)) {
6814 ConstExprValue *len_val = &const_val->data.x_struct.fields[slice_len_index];
6911 ConstExprValue *len_val = const_val->data.x_struct.fields[slice_len_index];
68156912 size_t len = bigint_as_usize(&len_val->data.x_bigint);
68166913
6817 ConstExprValue *ptr_val = &const_val->data.x_struct.fields[slice_ptr_index];
6914 ConstExprValue *ptr_val = const_val->data.x_struct.fields[slice_ptr_index];
68186915 if (ptr_val->special == ConstValSpecialUndef) {
68196916 assert(len == 0);
68206917 buf_appendf(buf, "((%s)(undefined))[0..0]", buf_ptr(&type_entry->name));
......@@ -6995,7 +7092,16 @@ bool type_id_eql(TypeId a, TypeId b) {
69957092 a.data.pointer.alignment == b.data.pointer.alignment &&
69967093 a.data.pointer.bit_offset_in_host == b.data.pointer.bit_offset_in_host &&
69977094 a.data.pointer.vector_index == b.data.pointer.vector_index &&
6998 a.data.pointer.host_int_bytes == b.data.pointer.host_int_bytes;
7095 a.data.pointer.host_int_bytes == b.data.pointer.host_int_bytes &&
7096 (
7097 a.data.pointer.inferred_struct_field == b.data.pointer.inferred_struct_field ||
7098 (a.data.pointer.inferred_struct_field != nullptr &&
7099 b.data.pointer.inferred_struct_field != nullptr &&
7100 a.data.pointer.inferred_struct_field->inferred_struct_type ==
7101 b.data.pointer.inferred_struct_field->inferred_struct_type &&
7102 buf_eql_buf(a.data.pointer.inferred_struct_field->field_name,
7103 b.data.pointer.inferred_struct_field->field_name))
7104 );
69997105 case ZigTypeIdArray:
70007106 return a.data.array.child_type == b.data.array.child_type &&
70017107 a.data.array.size == b.data.array.size;
......@@ -7082,10 +7188,10 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
70827188
70837189 const_val->special = ConstValSpecialStatic;
70847190 size_t field_count = wanted_type->data.structure.src_field_count;
7085 const_val->data.x_struct.fields = create_const_vals(field_count);
7191 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
70867192 for (size_t i = 0; i < field_count; i += 1) {
7087 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];
7088 field_val->type = wanted_type->data.structure.fields[i].type_entry;
7193 ConstExprValue *field_val = const_val->data.x_struct.fields[i];
7194 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);
70897195 assert(field_val->type);
70907196 init_const_undefined(g, field_val);
70917197 field_val->parent.id = ConstParentIdStruct;
......@@ -7517,7 +7623,7 @@ static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size
75177623 }
75187624 X64CABIClass working_class = X64CABIClass_Unknown;
75197625 for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
7520 X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry);
7626 X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields[0]->type_entry);
75217627 if (field_class == X64CABIClass_Unknown)
75227628 return X64CABIClass_Unknown;
75237629 if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) {
......@@ -7649,7 +7755,7 @@ Buf *type_h_name(ZigType *t) {
76497755static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wanted_resolve_status) {
76507756 if (type->data.structure.resolve_status >= wanted_resolve_status) return;
76517757
7652 ZigType *ptr_type = type->data.structure.fields[slice_ptr_index].type_entry;
7758 ZigType *ptr_type = type->data.structure.fields[slice_ptr_index]->type_entry;
76537759 ZigType *child_type = ptr_type->data.pointer.child_type;
76547760 ZigType *usize_type = g->builtin_types.entry_usize;
76557761
......@@ -7671,7 +7777,7 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
76717777 // If the child type is []const T then we need to make sure the type ref
76727778 // and debug info is the same as if the child type were []T.
76737779 if (is_slice(child_type)) {
7674 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
7780 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index]->type_entry;
76757781 assert(child_ptr_type->id == ZigTypeIdPointer);
76767782 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
76777783 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero)
......@@ -7808,7 +7914,6 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
78087914 ZigLLVMDIScope *di_scope;
78097915 unsigned line;
78107916 if (decl_node != nullptr) {
7811 assert(decl_node->type == NodeTypeContainerDecl);
78127917 Scope *scope = &struct_type->data.structure.decls_scope->base;
78137918 ZigType *import = get_scope_import(scope);
78147919 di_file = import->data.structure.root_struct->di_file;
......@@ -7849,7 +7954,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
78497954
78507955 // trigger all the recursive get_llvm_type calls
78517956 for (size_t i = 0; i < field_count; i += 1) {
7852 TypeStructField *field = &struct_type->data.structure.fields[i];
7957 TypeStructField *field = struct_type->data.structure.fields[i];
78537958 ZigType *field_type = field->type_entry;
78547959 if (!type_has_bits(field_type))
78557960 continue;
......@@ -7863,7 +7968,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
78637968 // inserting padding bytes where LLVM would do it automatically.
78647969 size_t llvm_struct_abi_align = 0;
78657970 for (size_t i = 0; i < field_count; i += 1) {
7866 ZigType *field_type = struct_type->data.structure.fields[i].type_entry;
7971 ZigType *field_type = struct_type->data.structure.fields[i]->type_entry;
78677972 if (!type_has_bits(field_type))
78687973 continue;
78697974 LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type);
......@@ -7872,7 +7977,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
78727977 }
78737978
78747979 for (size_t i = 0; i < field_count; i += 1) {
7875 TypeStructField *field = &struct_type->data.structure.fields[i];
7980 TypeStructField *field = struct_type->data.structure.fields[i];
78767981 ZigType *field_type = field->type_entry;
78777982
78787983 if (!type_has_bits(field_type)) {
......@@ -7922,23 +8027,23 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
79228027 // find the next non-zero-byte field for offset calculations
79238028 size_t next_src_field_index = i + 1;
79248029 for (; next_src_field_index < field_count; next_src_field_index += 1) {
7925 if (type_has_bits(struct_type->data.structure.fields[next_src_field_index].type_entry))
8030 if (type_has_bits(struct_type->data.structure.fields[next_src_field_index]->type_entry))
79268031 break;
79278032 }
79288033 size_t next_abi_align;
79298034 if (next_src_field_index == field_count) {
79308035 next_abi_align = struct_type->abi_align;
79318036 } else {
7932 if (struct_type->data.structure.fields[next_src_field_index].align == 0) {
7933 next_abi_align = struct_type->data.structure.fields[next_src_field_index].type_entry->abi_align;
8037 if (struct_type->data.structure.fields[next_src_field_index]->align == 0) {
8038 next_abi_align = struct_type->data.structure.fields[next_src_field_index]->type_entry->abi_align;
79348039 } else {
7935 next_abi_align = struct_type->data.structure.fields[next_src_field_index].align;
8040 next_abi_align = struct_type->data.structure.fields[next_src_field_index]->align;
79368041 }
79378042 }
79388043 size_t llvm_next_abi_align = (next_src_field_index == field_count) ?
79398044 llvm_struct_abi_align :
79408045 LLVMABIAlignmentOfType(g->target_data_ref,
7941 get_llvm_type(g, struct_type->data.structure.fields[next_src_field_index].type_entry));
8046 get_llvm_type(g, struct_type->data.structure.fields[next_src_field_index]->type_entry));
79428047
79438048 size_t next_offset = next_field_offset(field->offset, struct_type->abi_align,
79448049 field_type->abi_size, next_abi_align);
......@@ -7977,7 +8082,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
79778082 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
79788083 size_t debug_field_index = 0;
79798084 for (size_t i = 0; i < field_count; i += 1) {
7980 TypeStructField *field = &struct_type->data.structure.fields[i];
8085 TypeStructField *field = struct_type->data.structure.fields[i];
79818086 size_t gen_field_index = field->gen_index;
79828087 if (gen_field_index == SIZE_MAX) {
79838088 continue;
......@@ -8011,7 +8116,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
80118116 }
80128117 unsigned line;
80138118 if (decl_node != nullptr) {
8014 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
8119 AstNode *field_node = field->decl_node;
80158120 line = field_node->line + 1;
80168121 } else {
80178122 line = 0;
......@@ -8307,12 +8412,12 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus
83078412 if (type->data.pointer.vector_index == VECTOR_INDEX_NONE) {
83088413 peer_type = get_pointer_to_type_extra2(g, elem_type, false, false,
83098414 PtrLenSingle, 0, 0, type->data.pointer.host_int_bytes, false,
8310 VECTOR_INDEX_NONE);
8415 VECTOR_INDEX_NONE, nullptr);
83118416 } else {
83128417 uint32_t host_vec_len = type->data.pointer.host_int_bytes;
83138418 ZigType *host_vec_type = get_vector_type(g, host_vec_len, elem_type);
83148419 peer_type = get_pointer_to_type_extra2(g, host_vec_type, false, false,
8315 PtrLenSingle, 0, 0, 0, false, VECTOR_INDEX_NONE);
8420 PtrLenSingle, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr);
83168421 }
83178422 type->llvm_type = get_llvm_type(g, peer_type);
83188423 type->llvm_di_type = get_llvm_di_type(g, peer_type);
......@@ -9038,4 +9143,3 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
90389143 *out_import = add_source_file(g, target_package, resolved_path, import_code, source_kind);
90399144 return ErrorNone;
90409145}
9041
src/analyze.hpp+8-1
......@@ -24,7 +24,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type,
2424ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type,
2525 bool is_const, bool is_volatile, PtrLen ptr_len,
2626 uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count,
27 bool allow_zero, uint32_t vector_index);
27 bool allow_zero, uint32_t vector_index, InferredStructField *inferred_struct_field);
2828uint64_t type_size(CodeGen *g, ZigType *type_entry);
2929uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
3030ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
......@@ -46,6 +46,8 @@ ZigType *get_any_frame_type(CodeGen *g, ZigType *result_type);
4646bool handle_is_ptr(ZigType *type_entry);
4747
4848bool type_has_bits(ZigType *type_entry);
49Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result);
50
4951Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result);
5052bool ptr_allows_addr_zero(ZigType *ptr_type);
5153bool type_is_nonnull_ptr(ZigType *type);
......@@ -175,6 +177,11 @@ void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_inde
175177ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
176178
177179ConstExprValue *create_const_vals(size_t count);
180ConstExprValue **alloc_const_vals_ptrs(size_t count);
181ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);
182
183TypeStructField **alloc_type_struct_fields(size_t count);
184TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);
178185
179186ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
180187void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
src/ast_render.cpp+17-5
......@@ -821,7 +821,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
821821 break;
822822 }
823823 case NodeTypeContainerInitExpr:
824 render_node_ungrouped(ar, node->data.container_init_expr.type);
824 if (node->data.container_init_expr.type != nullptr) {
825 render_node_ungrouped(ar, node->data.container_init_expr.type);
826 }
825827 if (node->data.container_init_expr.kind == ContainerInitKindStruct) {
826828 fprintf(ar->f, "{\n");
827829 ar->indent += ar->indent_size;
......@@ -1137,10 +1139,20 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
11371139
11381140 for (size_t i = 0; i < node->data.err_set_decl.decls.length; i += 1) {
11391141 AstNode *field_node = node->data.err_set_decl.decls.at(i);
1140 assert(field_node->type == NodeTypeSymbol);
1141 print_indent(ar);
1142 print_symbol(ar, field_node->data.symbol_expr.symbol);
1143 fprintf(ar->f, ",\n");
1142 switch (field_node->type) {
1143 case NodeTypeSymbol:
1144 print_indent(ar);
1145 print_symbol(ar, field_node->data.symbol_expr.symbol);
1146 fprintf(ar->f, ",\n");
1147 break;
1148 case NodeTypeErrorSetField:
1149 print_indent(ar);
1150 print_symbol(ar, field_node->data.err_set_field.field_name->data.symbol_expr.symbol);
1151 fprintf(ar->f, ",\n");
1152 break;
1153 default:
1154 zig_unreachable();
1155 }
11441156 }
11451157
11461158 ar->indent -= ar->indent_size;
src/codegen.cpp+112-72
......@@ -1108,15 +1108,15 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
11081108 LLVMValueRef err_ret_trace_ptr = LLVMGetParam(fn_val, 0);
11091109 LLVMValueRef address_value = LLVMGetParam(fn_val, 1);
11101110
1111 size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
1111 size_t index_field_index = g->stack_trace_type->data.structure.fields[0]->gen_index;
11121112 LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)index_field_index, "");
1113 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
1113 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1]->gen_index;
11141114 LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, "");
11151115
1116 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
1117 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
1116 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1]->type_entry;
1117 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;
11181118 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
1119 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
1119 size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
11201120 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, "");
11211121
11221122 LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, "");
......@@ -1699,6 +1699,10 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
16991699}
17001700
17011701static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1702 Error err;
1703 if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown))) {
1704 codegen_report_errors_and_exit(g);
1705 }
17021706 if (!type_has_bits(instruction->value.type))
17031707 return nullptr;
17041708 if (!instruction->llvm_value) {
......@@ -2172,16 +2176,16 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
21722176 LLVMBuildCondBr(g->builder, null_bit, return_block, non_null_block);
21732177
21742178 LLVMPositionBuilderAtEnd(g->builder, non_null_block);
2175 size_t src_index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
2176 size_t src_addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
2179 size_t src_index_field_index = g->stack_trace_type->data.structure.fields[0]->gen_index;
2180 size_t src_addresses_field_index = g->stack_trace_type->data.structure.fields[1]->gen_index;
21772181 LLVMValueRef src_index_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
21782182 (unsigned)src_index_field_index, "");
21792183 LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
21802184 (unsigned)src_addresses_field_index, "");
2181 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
2182 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
2185 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1]->type_entry;
2186 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;
21832187 LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, "");
2184 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
2188 size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
21852189 LLVMValueRef src_len_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)len_field_index, "");
21862190 LLVMValueRef src_index_val = LLVMBuildLoad(g->builder, src_index_field_ptr, "");
21872191 LLVMValueRef src_ptr_val = LLVMBuildLoad(g->builder, src_ptr_field_ptr, "");
......@@ -3006,21 +3010,21 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
30063010 assert(actual_type->id == ZigTypeIdStruct);
30073011 assert(actual_type->data.structure.is_slice);
30083012
3009 ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
3013 ZigType *actual_pointer_type = actual_type->data.structure.fields[0]->type_entry;
30103014 ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type;
3011 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
3015 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0]->type_entry;
30123016 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
30133017
30143018
3015 size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index;
3016 size_t actual_len_index = actual_type->data.structure.fields[slice_len_index].gen_index;
3017 size_t wanted_ptr_index = wanted_type->data.structure.fields[slice_ptr_index].gen_index;
3018 size_t wanted_len_index = wanted_type->data.structure.fields[slice_len_index].gen_index;
3019 size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index]->gen_index;
3020 size_t actual_len_index = actual_type->data.structure.fields[slice_len_index]->gen_index;
3021 size_t wanted_ptr_index = wanted_type->data.structure.fields[slice_ptr_index]->gen_index;
3022 size_t wanted_len_index = wanted_type->data.structure.fields[slice_len_index]->gen_index;
30193023
30203024 LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_ptr_index, "");
30213025 LLVMValueRef src_ptr = gen_load_untyped(g, src_ptr_ptr, 0, false, "");
30223026 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr,
3023 get_llvm_type(g, wanted_type->data.structure.fields[0].type_entry), "");
3027 get_llvm_type(g, wanted_type->data.structure.fields[0]->type_entry), "");
30243028 LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, result_loc,
30253029 (unsigned)wanted_ptr_index, "");
30263030 gen_store_untyped(g, src_ptr_casted, dest_ptr_ptr, 0, false);
......@@ -3136,9 +3140,9 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex
31363140{
31373141 ZigType *actual_type = instruction->operand->value.type;
31383142 ZigType *slice_type = instruction->base.value.type;
3139 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry;
3140 size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
3141 size_t len_index = slice_type->data.structure.fields[slice_len_index].gen_index;
3143 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
3144 size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;
3145 size_t len_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
31423146
31433147 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
31443148
......@@ -3504,7 +3508,7 @@ static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {
35043508 case ConstValSpecialStatic:
35053509 if (const_val->type->id == ZigTypeIdStruct) {
35063510 for (size_t i = 0; i < const_val->type->data.structure.src_field_count; i += 1) {
3507 if (!value_is_all_undef(g, &const_val->data.x_struct.fields[i]))
3511 if (!value_is_all_undef(g, const_val->data.x_struct.fields[i]))
35083512 return false;
35093513 }
35103514 return true;
......@@ -3618,9 +3622,14 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
36183622}
36193623
36203624static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
3625 Error err;
3626
36213627 ZigType *ptr_type = instruction->ptr->value.type;
36223628 assert(ptr_type->id == ZigTypeIdPointer);
3623 if (!type_has_bits(ptr_type))
3629 bool ptr_type_has_bits;
3630 if ((err = type_has_bits2(g, ptr_type, &ptr_type_has_bits)))
3631 codegen_report_errors_and_exit(g);
3632 if (!ptr_type_has_bits)
36243633 return nullptr;
36253634 if (instruction->ptr->ref_count == 0) {
36263635 // In this case, this StorePtr instruction should be elided. Something happened like this:
......@@ -3757,14 +3766,14 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
37573766 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
37583767
37593768 if (safety_check_on) {
3760 size_t len_index = array_type->data.structure.fields[slice_len_index].gen_index;
3769 size_t len_index = array_type->data.structure.fields[slice_len_index]->gen_index;
37613770 assert(len_index != SIZE_MAX);
37623771 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, "");
37633772 LLVMValueRef len = gen_load_untyped(g, len_ptr, 0, false, "");
37643773 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len);
37653774 }
37663775
3767 size_t ptr_index = array_type->data.structure.fields[slice_ptr_index].gen_index;
3776 size_t ptr_index = array_type->data.structure.fields[slice_ptr_index]->gen_index;
37683777 assert(ptr_index != SIZE_MAX);
37693778 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, "");
37703779 LLVMValueRef ptr = gen_load_untyped(g, ptr_ptr, 0, false, "");
......@@ -3856,7 +3865,7 @@ static void render_async_spills(CodeGen *g) {
38563865 if (instruction->field_index == SIZE_MAX)
38573866 continue;
38583867
3859 size_t gen_index = frame_type->data.structure.fields[instruction->field_index].gen_index;
3868 size_t gen_index = frame_type->data.structure.fields[instruction->field_index]->gen_index;
38603869 instruction->base.llvm_value = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, gen_index,
38613870 instruction->name_hint);
38623871 }
......@@ -4342,17 +4351,32 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
43424351 TypeUnionField *field = instruction->field;
43434352
43444353 if (!type_has_bits(field->type_entry)) {
4345 if (union_type->data.unionation.gen_tag_index == SIZE_MAX) {
4354 ZigType *tag_type = union_type->data.unionation.tag_type;
4355 if (!instruction->initializing || !type_has_bits(tag_type))
43464356 return nullptr;
4357
4358 // The field has no bits but we still have to change the discriminant
4359 // value here
4360 LLVMValueRef union_ptr = ir_llvm_value(g, instruction->union_ptr);
4361
4362 LLVMTypeRef tag_type_ref = get_llvm_type(g, tag_type);
4363 LLVMValueRef tag_field_ptr = nullptr;
4364 if (union_type->data.unionation.gen_field_count == 0) {
4365 assert(union_type->data.unionation.gen_tag_index == SIZE_MAX);
4366 // The whole union is collapsed into the discriminant
4367 tag_field_ptr = LLVMBuildBitCast(g->builder, union_ptr,
4368 LLVMPointerType(tag_type_ref, 0), "");
4369 } else {
4370 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
4371 tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr,
4372 union_type->data.unionation.gen_tag_index, "");
43474373 }
4348 if (instruction->initializing) {
4349 LLVMValueRef union_ptr = ir_llvm_value(g, instruction->union_ptr);
4350 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr,
4351 union_type->data.unionation.gen_tag_index, "");
4352 LLVMValueRef tag_value = bigint_to_llvm_const(get_llvm_type(g, union_type->data.unionation.tag_type),
4353 &field->enum_field->value);
4354 gen_store_untyped(g, tag_value, tag_field_ptr, 0, false);
4355 }
4374
4375 LLVMValueRef tag_value = bigint_to_llvm_const(tag_type_ref,
4376 &field->enum_field->value);
4377 assert(tag_field_ptr != nullptr);
4378 gen_store_untyped(g, tag_value, tag_field_ptr, 0, false);
4379
43564380 return nullptr;
43574381 }
43584382
......@@ -4983,10 +5007,10 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
49835007 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
49845008 ptr_val = target_val;
49855009 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
4986 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
5010 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;
49875011 align_bytes = get_ptr_align(g, slice_ptr_type);
49885012
4989 size_t ptr_index = target_type->data.structure.fields[slice_ptr_index].gen_index;
5013 size_t ptr_index = target_type->data.structure.fields[slice_ptr_index]->gen_index;
49905014 LLVMValueRef ptr_val_ptr = LLVMBuildStructGEP(g->builder, target_val, (unsigned)ptr_index, "");
49915015 ptr_val = gen_load_untyped(g, ptr_val_ptr, 0, false, "");
49925016 } else {
......@@ -5128,7 +5152,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
51285152
51295153 bool val_is_undef = value_is_all_undef(g, &instruction->byte->value);
51305154 LLVMValueRef fill_char;
5131 if (val_is_undef) {
5155 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {
51325156 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
51335157 } else {
51345158 fill_char = ir_llvm_value(g, instruction->byte);
......@@ -5231,13 +5255,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
52315255 }
52325256
52335257 if (type_has_bits(array_type)) {
5234 size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index].gen_index;
5258 size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index]->gen_index;
52355259 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
52365260 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");
52375261 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
52385262 }
52395263
5240 size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index].gen_index;
5264 size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index]->gen_index;
52415265 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");
52425266 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
52435267 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
......@@ -5249,9 +5273,9 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
52495273 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
52505274 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(tmp_struct_ptr))) == LLVMStructTypeKind);
52515275
5252 size_t ptr_index = array_type->data.structure.fields[slice_ptr_index].gen_index;
5276 size_t ptr_index = array_type->data.structure.fields[slice_ptr_index]->gen_index;
52535277 assert(ptr_index != SIZE_MAX);
5254 size_t len_index = array_type->data.structure.fields[slice_len_index].gen_index;
5278 size_t len_index = array_type->data.structure.fields[slice_len_index]->gen_index;
52555279 assert(len_index != SIZE_MAX);
52565280
52575281 LLVMValueRef prev_end = nullptr;
......@@ -5646,6 +5670,17 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
56465670 return load_inst;
56475671}
56485672
5673static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
5674 IrInstructionAtomicStore *instruction)
5675{
5676 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5677 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5678 LLVMValueRef value = ir_llvm_value(g, instruction->value);
5679 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value.type);
5680 LLVMSetOrdering(store_inst, ordering);
5681 return nullptr;
5682}
5683
56495684static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {
56505685 LLVMValueRef op = ir_llvm_value(g, instruction->op1);
56515686 assert(instruction->base.value.type->id == ZigTypeIdFloat);
......@@ -6249,6 +6284,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
62496284 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);
62506285 case IrInstructionIdAtomicLoad:
62516286 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);
6287 case IrInstructionIdAtomicStore:
6288 return ir_render_atomic_store(g, executable, (IrInstructionAtomicStore *)instruction);
62526289 case IrInstructionIdSaveErrRetAddr:
62536290 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);
62546291 case IrInstructionIdFloatOp:
......@@ -6546,11 +6583,11 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
65466583 LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false);
65476584 size_t used_bits = 0;
65486585 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
6549 TypeStructField *field = &type_entry->data.structure.fields[i];
6586 TypeStructField *field = type_entry->data.structure.fields[i];
65506587 if (field->gen_index == SIZE_MAX) {
65516588 continue;
65526589 }
6553 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, &const_val->data.x_struct.fields[i]);
6590 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref, const_val->data.x_struct.fields[i]);
65546591 uint32_t packed_bits_size = type_size_bits(g, field->type_entry);
65556592 if (is_big_endian) {
65566593 LLVMValueRef shift_amt = LLVMConstInt(big_int_type_ref, packed_bits_size, false);
......@@ -6625,7 +6662,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
66256662 return const_val->global_refs->llvm_value;
66266663 }
66276664 size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index;
6628 size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index].gen_index;
6665 size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index]->gen_index;
66296666 LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val,
66306667 gen_field_index);
66316668 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
......@@ -6804,7 +6841,7 @@ check: switch (const_val->special) {
68046841 if (type_entry->data.structure.layout == ContainerLayoutPacked) {
68056842 size_t src_field_index = 0;
68066843 while (src_field_index < src_field_count) {
6807 TypeStructField *type_struct_field = &type_entry->data.structure.fields[src_field_index];
6844 TypeStructField *type_struct_field = type_entry->data.structure.fields[src_field_index];
68086845 if (type_struct_field->gen_index == SIZE_MAX) {
68096846 src_field_index += 1;
68106847 continue;
......@@ -6812,13 +6849,13 @@ check: switch (const_val->special) {
68126849
68136850 size_t src_field_index_end = src_field_index + 1;
68146851 for (; src_field_index_end < src_field_count; src_field_index_end += 1) {
6815 TypeStructField *it_field = &type_entry->data.structure.fields[src_field_index_end];
6852 TypeStructField *it_field = type_entry->data.structure.fields[src_field_index_end];
68166853 if (it_field->gen_index != type_struct_field->gen_index)
68176854 break;
68186855 }
68196856
68206857 if (src_field_index + 1 == src_field_index_end) {
6821 ConstExprValue *field_val = &const_val->data.x_struct.fields[src_field_index];
6858 ConstExprValue *field_val = const_val->data.x_struct.fields[src_field_index];
68226859 LLVMValueRef val = gen_const_val(g, field_val, "");
68236860 fields[type_struct_field->gen_index] = val;
68246861 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);
......@@ -6831,12 +6868,12 @@ check: switch (const_val->special) {
68316868 LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false);
68326869 size_t used_bits = 0;
68336870 for (size_t i = src_field_index; i < src_field_index_end; i += 1) {
6834 TypeStructField *it_field = &type_entry->data.structure.fields[i];
6871 TypeStructField *it_field = type_entry->data.structure.fields[i];
68356872 if (it_field->gen_index == SIZE_MAX) {
68366873 continue;
68376874 }
68386875 LLVMValueRef child_val = pack_const_int(g, big_int_type_ref,
6839 &const_val->data.x_struct.fields[i]);
6876 const_val->data.x_struct.fields[i]);
68406877 uint32_t packed_bits_size = type_size_bits(g, it_field->type_entry);
68416878 if (is_big_endian) {
68426879 LLVMValueRef shift_amt = LLVMConstInt(big_int_type_ref,
......@@ -6871,11 +6908,11 @@ check: switch (const_val->special) {
68716908 }
68726909 } else {
68736910 for (uint32_t i = 0; i < src_field_count; i += 1) {
6874 TypeStructField *type_struct_field = &type_entry->data.structure.fields[i];
6911 TypeStructField *type_struct_field = type_entry->data.structure.fields[i];
68756912 if (type_struct_field->gen_index == SIZE_MAX) {
68766913 continue;
68776914 }
6878 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];
6915 ConstExprValue *field_val = const_val->data.x_struct.fields[i];
68796916 assert(field_val->type != nullptr);
68806917 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,
68816918 type_struct_field->type_entry)))
......@@ -6888,10 +6925,10 @@ check: switch (const_val->special) {
68886925 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val);
68896926
68906927 size_t end_pad_gen_index = (i + 1 < src_field_count) ?
6891 type_entry->data.structure.fields[i + 1].gen_index :
6928 type_entry->data.structure.fields[i + 1]->gen_index :
68926929 type_entry->data.structure.gen_field_count;
68936930 size_t next_offset = (i + 1 < src_field_count) ?
6894 type_entry->data.structure.fields[i + 1].offset : type_entry->abi_size;
6931 type_entry->data.structure.fields[i + 1]->offset : type_entry->abi_size;
68956932 if (end_pad_gen_index != SIZE_MAX) {
68966933 for (size_t gen_i = type_struct_field->gen_index + 1; gen_i < end_pad_gen_index;
68976934 gen_i += 1)
......@@ -7050,16 +7087,12 @@ check: switch (const_val->special) {
70507087 case ZigTypeIdEnum:
70517088 return bigint_to_llvm_const(get_llvm_type(g, type_entry), &const_val->data.x_enum_tag);
70527089 case ZigTypeIdFn:
7053 if (const_val->data.x_ptr.special == ConstPtrSpecialFunction) {
7054 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
7055 return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
7056 } else if (const_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
7057 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
7058 uint64_t addr = const_val->data.x_ptr.data.hard_coded_addr.addr;
7059 return LLVMConstIntToPtr(LLVMConstInt(usize_type_ref, addr, false), get_llvm_type(g, type_entry));
7060 } else {
7090 if (const_val->data.x_ptr.special == ConstPtrSpecialFunction &&
7091 const_val->data.x_ptr.mut != ConstPtrMutComptimeConst) {
70617092 zig_unreachable();
70627093 }
7094 // Treat it the same as we do for pointers
7095 return gen_const_val_ptr(g, const_val, name);
70637096 case ZigTypeIdPointer:
70647097 return gen_const_val_ptr(g, const_val, name);
70657098 case ZigTypeIdErrorUnion:
......@@ -7558,15 +7591,15 @@ static void do_code_gen(CodeGen *g) {
75587591 // finishing error return trace setup. we have to do this after all the allocas.
75597592 if (have_err_ret_trace_stack) {
75607593 ZigType *usize = g->builtin_types.entry_usize;
7561 size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
7594 size_t index_field_index = g->stack_trace_type->data.structure.fields[0]->gen_index;
75627595 LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, "");
75637596 gen_store_untyped(g, LLVMConstNull(usize->llvm_type), index_field_ptr, 0, false);
75647597
7565 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
7598 size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1]->gen_index;
75667599 LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, "");
75677600
7568 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
7569 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
7601 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1]->type_entry;
7602 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index;
75707603 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
75717604 LLVMValueRef zero = LLVMConstNull(usize->llvm_type);
75727605 LLVMValueRef indices[] = {zero, zero};
......@@ -7575,7 +7608,7 @@ static void do_code_gen(CodeGen *g) {
75757608 ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false);
75767609 gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type);
75777610
7578 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
7611 size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
75797612 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, "");
75807613 gen_store(g, LLVMConstInt(usize->llvm_type, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false));
75817614 }
......@@ -7692,7 +7725,7 @@ static void do_code_gen(CodeGen *g) {
76927725
76937726 char *error = nullptr;
76947727 if (LLVMVerifyModule(g->module, LLVMReturnStatusAction, &error)) {
7695 zig_panic("broken LLVM module found: %s", error);
7728 zig_panic("broken LLVM module found: %s\nThis is a bug in the Zig compiler.", error);
76967729 }
76977730}
76987731
......@@ -7820,6 +7853,11 @@ static void define_builtin_types(CodeGen *g) {
78207853 buf_init_from_str(&entry->name, "(null)");
78217854 g->builtin_types.entry_null = entry;
78227855 }
7856 {
7857 ZigType *entry = new_type_table_entry(ZigTypeIdOpaque);
7858 buf_init_from_str(&entry->name, "(var)");
7859 g->builtin_types.entry_var = entry;
7860 }
78237861 {
78247862 ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple);
78257863 buf_init_from_str(&entry->name, "(args)");
......@@ -8064,6 +8102,7 @@ static void define_builtin_fns(CodeGen *g) {
80648102 create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);
80658103 create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);
80668104 create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3);
8105 create_builtin_fn(g, BuiltinFnIdAtomicStore, "atomicStore", 4);
80678106 create_builtin_fn(g, BuiltinFnIdErrSetCast, "errSetCast", 2);
80688107 create_builtin_fn(g, BuiltinFnIdToBytes, "sliceToBytes", 1);
80698108 create_builtin_fn(g, BuiltinFnIdFromBytes, "bytesToSlice", 2);
......@@ -8074,6 +8113,7 @@ static void define_builtin_fns(CodeGen *g) {
80748113 create_builtin_fn(g, BuiltinFnIdFrameType, "Frame", 1);
80758114 create_builtin_fn(g, BuiltinFnIdFrameAddress, "frameAddress", 0);
80768115 create_builtin_fn(g, BuiltinFnIdFrameSize, "frameSize", 1);
8116 create_builtin_fn(g, BuiltinFnIdAs, "as", 2);
80778117}
80788118
80798119static const char *bool_to_str(bool b) {
......@@ -9049,13 +9089,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
90499089 this_val->parent.id = ConstParentIdArray;
90509090 this_val->parent.data.p_array.array_val = test_fn_array;
90519091 this_val->parent.data.p_array.elem_index = i;
9052 this_val->data.x_struct.fields = create_const_vals(2);
9092 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
90539093
9054 ConstExprValue *name_field = &this_val->data.x_struct.fields[0];
9094 ConstExprValue *name_field = this_val->data.x_struct.fields[0];
90559095 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name);
90569096 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
90579097
9058 ConstExprValue *fn_field = &this_val->data.x_struct.fields[1];
9098 ConstExprValue *fn_field = this_val->data.x_struct.fields[1];
90599099 fn_field->type = fn_type;
90609100 fn_field->special = ConstValSpecialStatic;
90619101 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
......@@ -9483,7 +9523,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
94839523 return;
94849524 case ZigTypeIdStruct:
94859525 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
9486 TypeStructField *field = &type_entry->data.structure.fields[i];
9526 TypeStructField *field = type_entry->data.structure.fields[i];
94879527 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
94889528 }
94899529 gen_h->types_to_declare.append(type_entry);
......@@ -9849,7 +9889,7 @@ static void gen_h_file(CodeGen *g) {
98499889 if (type_entry->data.structure.layout == ContainerLayoutExtern) {
98509890 fprintf(out_h, "struct %s {\n", buf_ptr(type_h_name(type_entry)));
98519891 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
9852 TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];
9892 TypeStructField *struct_field = type_entry->data.structure.fields[field_i];
98539893
98549894 Buf *type_name_buf = buf_alloc();
98559895 get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
src/dump_analysis.cpp+4-3
......@@ -268,7 +268,7 @@ static void tree_print_struct(FILE *f, ZigType *struct_type, size_t indent) {
268268 ZigList<ZigType *> children = {};
269269 uint64_t sum_from_fields = 0;
270270 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
271 TypeStructField *field = &struct_type->data.structure.fields[i];
271 TypeStructField *field = struct_type->data.structure.fields[i];
272272 children.append(field->type_entry);
273273 sum_from_fields += field->type_entry->abi_size;
274274 }
......@@ -747,7 +747,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
747747 if (ty->data.structure.is_slice) {
748748 jw_object_field(jw, "len");
749749 jw_int(jw, 2);
750 anal_dump_pointer_attrs(ctx, ty->data.structure.fields[slice_ptr_index].type_entry);
750 anal_dump_pointer_attrs(ctx, ty->data.structure.fields[slice_ptr_index]->type_entry);
751751 break;
752752 }
753753
......@@ -803,7 +803,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
803803
804804 for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
805805 jw_array_elem(jw);
806 anal_dump_type_ref(ctx, ty->data.structure.fields[i].type_entry);
806 anal_dump_type_ref(ctx, ty->data.structure.fields[i]->type_entry);
807807 }
808808 jw_end_array(jw);
809809 }
......@@ -1088,6 +1088,7 @@ static void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {
10881088 break;
10891089 case NodeTypeContainerDecl:
10901090 field_nodes = &node->data.container_decl.fields;
1091 doc_comments_buf = &node->data.container_decl.doc_comments;
10911092 break;
10921093 default:
10931094 break;
src/ir.cpp+1121-482
......@@ -200,6 +200,13 @@ 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);
205static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,
206 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing);
207static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
208 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
209static ResultLoc *no_result_loc(void);
203210
204211static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
205212 assert(get_src_ptr_type(const_val->type) != nullptr);
......@@ -233,7 +240,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
233240 case ConstPtrSpecialBaseStruct: {
234241 ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val;
235242 expand_undef_struct(g, struct_val);
236 result = &struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];
243 result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index];
237244 break;
238245 }
239246 case ConstPtrSpecialBaseErrorUnionCode:
......@@ -270,7 +277,7 @@ static bool is_slice(ZigType *type) {
270277
271278static bool slice_is_const(ZigType *type) {
272279 assert(is_slice(type));
273 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
280 return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
274281}
275282
276283// This function returns true when you can change the type of a ConstExprValue and the
......@@ -1003,6 +1010,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {
10031010 return IrInstructionIdAtomicLoad;
10041011}
10051012
1013static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) {
1014 return IrInstructionIdAtomicStore;
1015}
1016
10061017static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {
10071018 return IrInstructionIdSaveErrRetAddr;
10081019}
......@@ -1348,18 +1359,17 @@ static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_
13481359
13491360static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
13501361 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,
1351 IrInstruction *init_array_type)
1362 AstNode *init_array_type_source_node)
13521363{
13531364 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
13541365 instruction->array_ptr = array_ptr;
13551366 instruction->elem_index = elem_index;
13561367 instruction->safety_check_on = safety_check_on;
13571368 instruction->ptr_len = ptr_len;
1358 instruction->init_array_type = init_array_type;
1369 instruction->init_array_type_source_node = init_array_type_source_node;
13591370
13601371 ir_ref_instruction(array_ptr, irb->current_basic_block);
13611372 ir_ref_instruction(elem_index, irb->current_basic_block);
1362 if (init_array_type != nullptr) ir_ref_instruction(init_array_type, irb->current_basic_block);
13631373
13641374 return &instruction->base;
13651375}
......@@ -1573,17 +1583,16 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour
15731583}
15741584
15751585static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,
1576 IrInstruction *container_type, size_t item_count, IrInstruction **elem_result_loc_list,
1577 IrInstruction *result_loc)
1586 size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc,
1587 AstNode *init_array_type_source_node)
15781588{
15791589 IrInstructionContainerInitList *container_init_list_instruction =
15801590 ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);
1581 container_init_list_instruction->container_type = container_type;
15821591 container_init_list_instruction->item_count = item_count;
15831592 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
15841593 container_init_list_instruction->result_loc = result_loc;
1594 container_init_list_instruction->init_array_type_source_node = init_array_type_source_node;
15851595
1586 ir_ref_instruction(container_type, irb->current_basic_block);
15871596 for (size_t i = 0; i < item_count; i += 1) {
15881597 ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block);
15891598 }
......@@ -1593,17 +1602,14 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope,
15931602}
15941603
15951604static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,
1596 IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields,
1597 IrInstruction *result_loc)
1605 size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc)
15981606{
15991607 IrInstructionContainerInitFields *container_init_fields_instruction =
16001608 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);
1601 container_init_fields_instruction->container_type = container_type;
16021609 container_init_fields_instruction->field_count = field_count;
16031610 container_init_fields_instruction->fields = fields;
16041611 container_init_fields_instruction->result_loc = result_loc;
16051612
1606 ir_ref_instruction(container_type, irb->current_basic_block);
16071613 for (size_t i = 0; i < field_count; i += 1) {
16081614 ir_ref_instruction(fields[i].result_loc, irb->current_basic_block);
16091615 }
......@@ -2766,6 +2772,18 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc
27662772 return &instruction->base;
27672773}
27682774
2775static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
2776 IrInstruction *operand, ResultLocCast *result_loc_cast)
2777{
2778 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);
2779 instruction->operand = operand;
2780 instruction->result_loc_cast = result_loc_cast;
2781
2782 ir_ref_instruction(operand, irb->current_basic_block);
2783
2784 return &instruction->base;
2785}
2786
27692787static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
27702788 IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)
27712789{
......@@ -3063,20 +3081,6 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode
30633081 return &instruction->base;
30643082}
30653083
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
30803084static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
30813085 ResultLoc *result_loc, IrInstruction *ty)
30823086{
......@@ -3084,7 +3088,7 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN
30843088 instruction->result_loc = result_loc;
30853089 instruction->ty = ty;
30863090
3087 ir_ref_instruction(ty, irb->current_basic_block);
3091 if (ty != nullptr) ir_ref_instruction(ty, irb->current_basic_block);
30883092
30893093 return &instruction->base;
30903094}
......@@ -3116,11 +3120,12 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast
31163120}
31173121
31183122static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3119 IrInstruction *fn_type, IrInstruction *arg_index)
3123 IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var)
31203124{
31213125 IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node);
31223126 instruction->fn_type = fn_type;
31233127 instruction->arg_index = arg_index;
3128 instruction->allow_var = allow_var;
31243129
31253130 ir_ref_instruction(fn_type, irb->current_basic_block);
31263131 ir_ref_instruction(arg_index, irb->current_basic_block);
......@@ -3187,6 +3192,25 @@ static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode
31873192 return &instruction->base;
31883193}
31893194
3195static IrInstruction *ir_build_atomic_store(IrBuilder *irb, Scope *scope, AstNode *source_node,
3196 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *value,
3197 IrInstruction *ordering, AtomicOrder resolved_ordering)
3198{
3199 IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node);
3200 instruction->operand_type = operand_type;
3201 instruction->ptr = ptr;
3202 instruction->value = value;
3203 instruction->ordering = ordering;
3204 instruction->resolved_ordering = resolved_ordering;
3205
3206 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
3207 ir_ref_instruction(ptr, irb->current_basic_block);
3208 ir_ref_instruction(value, irb->current_basic_block);
3209 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
3210
3211 return &instruction->base;
3212}
3213
31903214static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {
31913215 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);
31923216 return &instruction->base;
......@@ -5374,6 +5398,24 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
53745398 IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
53755399 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
53765400 }
5401 case BuiltinFnIdAs:
5402 {
5403 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5404 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
5405 if (dest_type == irb->codegen->invalid_instruction)
5406 return dest_type;
5407
5408 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
5409
5410 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5411 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
5412 &result_loc_cast->base);
5413 if (arg1_value == irb->codegen->invalid_instruction)
5414 return arg1_value;
5415
5416 IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
5417 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5418 }
53775419 case BuiltinFnIdIntToPtr:
53785420 {
53795421 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
......@@ -5630,7 +5672,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
56305672 if (arg1_value == irb->codegen->invalid_instruction)
56315673 return arg1_value;
56325674
5633 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value);
5675 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
56345676 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
56355677 }
56365678 case BuiltinFnIdExport:
......@@ -5713,6 +5755,33 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
57135755 AtomicOrderMonotonic);
57145756 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
57155757 }
5758 case BuiltinFnIdAtomicStore:
5759 {
5760 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5761 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5762 if (arg0_value == irb->codegen->invalid_instruction)
5763 return arg0_value;
5764
5765 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5766 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5767 if (arg1_value == irb->codegen->invalid_instruction)
5768 return arg1_value;
5769
5770 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5771 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5772 if (arg2_value == irb->codegen->invalid_instruction)
5773 return arg2_value;
5774
5775 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5776 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
5777 if (arg3_value == irb->codegen->invalid_instruction)
5778 return arg3_value;
5779
5780 IrInstruction *inst = ir_build_atomic_store(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,
5781 // this value does not mean anything since we passed non-null values for other arg
5782 AtomicOrderMonotonic);
5783 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
5784 }
57165785 case BuiltinFnIdIntToEnum:
57175786 {
57185787 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
......@@ -5825,13 +5894,22 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
58255894 if (fn_ref == irb->codegen->invalid_instruction)
58265895 return fn_ref;
58275896
5897 IrInstruction *fn_type = ir_build_typeof(irb, scope, node, fn_ref);
5898
58285899 size_t arg_count = node->data.fn_call_expr.params.length;
58295900 IrInstruction **args = allocate<IrInstruction*>(arg_count);
58305901 for (size_t i = 0; i < arg_count; i += 1) {
58315902 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
5832 args[i] = ir_gen_node(irb, arg_node, scope);
5833 if (args[i] == irb->codegen->invalid_instruction)
5834 return args[i];
5903
5904 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
5905 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, fn_type, arg_index, true);
5906 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result_loc());
5907
5908 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
5909 if (arg == irb->codegen->invalid_instruction)
5910 return arg;
5911
5912 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);
58355913 }
58365914
58375915 IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
......@@ -6109,28 +6187,46 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
61096187 AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;
61106188 ContainerInitKind kind = container_init_expr->kind;
61116189
6112 IrInstruction *container_type = nullptr;
6113 IrInstruction *elem_type = nullptr;
6114 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
6115 elem_type = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.child_type, scope);
6116 if (elem_type == irb->codegen->invalid_instruction)
6117 return elem_type;
6118 } else {
6119 container_type = ir_gen_node(irb, container_init_expr->type, scope);
6120 if (container_type == irb->codegen->invalid_instruction)
6121 return container_type;
6122 }
6123
6124 switch (kind) {
6125 case ContainerInitKindStruct: {
6126 if (elem_type != nullptr) {
6190 ResultLocCast *result_loc_cast = nullptr;
6191 ResultLoc *child_result_loc;
6192 AstNode *init_array_type_source_node;
6193 if (container_init_expr->type != nullptr) {
6194 IrInstruction *container_type;
6195 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
6196 if (kind == ContainerInitKindStruct) {
61276197 add_node_error(irb->codegen, container_init_expr->type,
61286198 buf_sprintf("initializing array with struct syntax"));
61296199 return irb->codegen->invalid_instruction;
61306200 }
6201 IrInstruction *elem_type = ir_gen_node(irb,
6202 container_init_expr->type->data.inferred_array_type.child_type, scope);
6203 if (elem_type == irb->codegen->invalid_instruction)
6204 return elem_type;
6205 size_t item_count = container_init_expr->entries.length;
6206 IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
6207 container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type);
6208 } else {
6209 container_type = ir_gen_node(irb, container_init_expr->type, scope);
6210 if (container_type == irb->codegen->invalid_instruction)
6211 return container_type;
6212 }
61316213
6132 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, parent_result_loc,
6133 container_type);
6214 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);
6215 child_result_loc = &result_loc_cast->base;
6216 init_array_type_source_node = container_type->source_node;
6217 } else {
6218 child_result_loc = parent_result_loc;
6219 if (parent_result_loc->source_instruction != nullptr) {
6220 init_array_type_source_node = parent_result_loc->source_instruction->source_node;
6221 } else {
6222 init_array_type_source_node = node;
6223 }
6224 }
6225
6226 switch (kind) {
6227 case ContainerInitKindStruct: {
6228 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
6229 nullptr);
61346230
61356231 size_t field_count = container_init_expr->entries.length;
61366232 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);
......@@ -6158,29 +6254,27 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
61586254 fields[i].source_node = entry_node;
61596255 fields[i].result_loc = field_ptr;
61606256 }
6161 IrInstruction *init_fields = ir_build_container_init_fields(irb, scope, node, container_type,
6162 field_count, fields, container_ptr);
6257 IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count,
6258 fields, container_ptr);
61636259
6164 return ir_lval_wrap(irb, scope, init_fields, lval, parent_result_loc);
6260 if (result_loc_cast != nullptr) {
6261 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);
6262 }
6263 return ir_lval_wrap(irb, scope, result, lval, parent_result_loc);
61656264 }
61666265 case ContainerInitKindArray: {
61676266 size_t item_count = container_init_expr->entries.length;
61686267
6169 if (container_type == nullptr) {
6170 IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
6171 container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type);
6172 }
6173
6174 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, parent_result_loc,
6175 container_type);
6268 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
6269 nullptr);
61766270
61776271 IrInstruction **result_locs = allocate<IrInstruction *>(item_count);
61786272 for (size_t i = 0; i < item_count; i += 1) {
61796273 AstNode *expr_node = container_init_expr->entries.at(i);
61806274
61816275 IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
6182 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, elem_index,
6183 false, PtrLenSingle, container_type);
6276 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
6277 elem_index, false, PtrLenSingle, init_array_type_source_node);
61846278 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
61856279 result_loc_inst->base.id = ResultLocIdInstruction;
61866280 result_loc_inst->base.source_instruction = elem_ptr;
......@@ -6195,9 +6289,12 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
61956289
61966290 result_locs[i] = elem_ptr;
61976291 }
6198 IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type,
6199 item_count, result_locs, container_ptr);
6200 return ir_lval_wrap(irb, scope, init_list, lval, parent_result_loc);
6292 IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count,
6293 result_locs, container_ptr, init_array_type_source_node);
6294 if (result_loc_cast != nullptr) {
6295 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);
6296 }
6297 return ir_lval_wrap(irb, scope, result, lval, parent_result_loc);
62016298 }
62026299 }
62036300 zig_unreachable();
......@@ -6214,6 +6311,20 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo
62146311 return result_loc_var;
62156312}
62166313
6314static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
6315 ResultLoc *parent_result_loc)
6316{
6317 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
6318 result_loc_cast->base.id = ResultLocIdCast;
6319 result_loc_cast->base.source_instruction = dest_type;
6320 ir_ref_instruction(dest_type, irb->current_basic_block);
6321 result_loc_cast->parent = parent_result_loc;
6322
6323 ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
6324
6325 return result_loc_cast;
6326}
6327
62176328static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
62186329 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)
62196330{
......@@ -6282,7 +6393,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
62826393
62836394 // Create a result location for the initialization expression.
62846395 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;
6396 ResultLoc *init_result_loc;
6397 ResultLocCast *result_loc_cast;
6398 if (type_instruction != nullptr) {
6399 result_loc_cast = ir_build_cast_result_loc(irb, type_instruction, &result_loc_var->base);
6400 init_result_loc = &result_loc_cast->base;
6401 } else {
6402 result_loc_cast = nullptr;
6403 init_result_loc = &result_loc_var->base;
6404 }
62866405
62876406 Scope *init_scope = is_comptime_scalar ?
62886407 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
......@@ -6298,9 +6417,9 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
62986417 if (init_value == irb->codegen->invalid_instruction)
62996418 return irb->codegen->invalid_instruction;
63006419
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);
6420 if (result_loc_cast != nullptr) {
6421 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,
6422 init_value, result_loc_cast);
63046423 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
63056424 }
63066425
......@@ -7895,14 +8014,14 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o
78958014static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
78968015 Scope *scope, AstNode *source_node, Buf *out_bare_name)
78978016{
7898 if (exec->name) {
8017 if (exec != nullptr && exec->name) {
78998018 ZigType *import = get_scope_import(scope);
79008019 Buf *namespace_name = buf_alloc();
79018020 append_namespace_qualification(codegen, namespace_name, import);
79028021 buf_append_buf(namespace_name, exec->name);
79038022 buf_init_from_buf(out_bare_name, exec->name);
79048023 return namespace_name;
7905 } else if (exec->name_fn != nullptr) {
8024 } else if (exec != nullptr && exec->name_fn != nullptr) {
79068025 Buf *name = buf_alloc();
79078026 buf_append_buf(name, &exec->name_fn->symbol_name);
79088027 buf_appendf(name, "(");
......@@ -8009,7 +8128,6 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
80098128 }
80108129 }
80118130 assert(index == count);
8012 assert(count != 0);
80138131
80148132 if (type_name == nullptr) {
80158133 buf_appendf(&err_set_type->name, "}");
......@@ -9571,7 +9689,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
95719689 }
95729690
95739691 ir_add_error(ira, instruction,
9574 buf_sprintf("%s value %s cannot be implicitly casted to type '%s'",
9692 buf_sprintf("%s value %s cannot be coerced to type '%s'",
95759693 num_lit_str,
95769694 buf_ptr(val_buf),
95779695 buf_ptr(&other_type->name)));
......@@ -9739,8 +9857,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
97399857
97409858 // slice const
97419859 if (is_slice(wanted_type) && is_slice(actual_type)) {
9742 ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
9743 ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
9860 ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index]->type_entry;
9861 ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
97449862 if ((err = type_resolve(g, actual_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) {
97459863 result.id = ConstCastResultIdInvalid;
97469864 return result;
......@@ -10494,22 +10612,67 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1049410612 continue;
1049510613 }
1049610614
10615 // *[N]T to []T
10616 // *[N]T to E![]T
10617 if (cur_type->id == ZigTypeIdPointer &&
10618 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
10619 ((prev_type->id == ZigTypeIdErrorUnion && is_slice(prev_type->data.error_union.payload_type)) ||
10620 is_slice(prev_type)))
10621 {
10622 ZigType *array_type = cur_type->data.pointer.child_type;
10623 ZigType *slice_type = (prev_type->id == ZigTypeIdErrorUnion) ?
10624 prev_type->data.error_union.payload_type : prev_type;
10625 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
10626 if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
10627 types_match_const_cast_only(ira,
10628 slice_ptr_type->data.pointer.child_type,
10629 array_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
10630 {
10631 convert_to_const_slice = false;
10632 continue;
10633 }
10634 }
10635
10636 // *[N]T to []T
10637 // *[N]T to E![]T
10638 if (prev_type->id == ZigTypeIdPointer &&
10639 prev_type->data.pointer.child_type->id == ZigTypeIdArray &&
10640 ((cur_type->id == ZigTypeIdErrorUnion && is_slice(cur_type->data.error_union.payload_type)) ||
10641 is_slice(cur_type)))
10642 {
10643 ZigType *array_type = prev_type->data.pointer.child_type;
10644 ZigType *slice_type = (cur_type->id == ZigTypeIdErrorUnion) ?
10645 cur_type->data.error_union.payload_type : cur_type;
10646 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
10647 if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
10648 types_match_const_cast_only(ira,
10649 slice_ptr_type->data.pointer.child_type,
10650 array_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
10651 {
10652 prev_inst = cur_inst;
10653 convert_to_const_slice = false;
10654 continue;
10655 }
10656 }
10657
10658 // [N]T to []T
1049710659 if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
10498 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
10660 (prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
1049910661 cur_type->data.array.len == 0) &&
1050010662 types_match_const_cast_only(ira,
10501 prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
10663 prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
1050210664 cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
1050310665 {
1050410666 convert_to_const_slice = false;
1050510667 continue;
1050610668 }
1050710669
10670 // [N]T to []T
1050810671 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
10509 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
10672 (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
1051010673 prev_type->data.array.len == 0) &&
1051110674 types_match_const_cast_only(ira,
10512 cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
10675 cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
1051310676 prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
1051410677 {
1051510678 prev_inst = cur_inst;
......@@ -10620,9 +10783,9 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
1062010783 if (src->special != ConstValSpecialStatic)
1062110784 return;
1062210785 if (dest->type->id == ZigTypeIdStruct) {
10623 dest->data.x_struct.fields = create_const_vals(dest->type->data.structure.src_field_count);
10786 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
1062410787 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
10625 copy_const_val(&dest->data.x_struct.fields[i], &src->data.x_struct.fields[i], false);
10788 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i], false);
1062610789 }
1062710790 }
1062810791 }
......@@ -10814,12 +10977,11 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1081410977 assert(value->value.type->id == ZigTypeIdPointer);
1081510978 ZigType *array_type = value->value.type->data.pointer.child_type;
1081610979 assert(is_slice(wanted_type));
10817 bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
10980 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1081810981
1081910982 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1082010983 init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const);
10821 result->value.data.x_struct.fields[slice_ptr_index].data.x_ptr.mut =
10822 value->value.data.x_ptr.mut;
10984 result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = value->value.data.x_ptr.mut;
1082310985 result->value.type = wanted_type;
1082410986 return result;
1082510987 }
......@@ -12401,6 +12563,27 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
1240112563 return result;
1240212564}
1240312565
12566static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr,
12567 IrInstruction *value, ZigType *wanted_type)
12568{
12569 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array"));
12570 return ira->codegen->invalid_instruction;
12571}
12572
12573static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr,
12574 IrInstruction *value, ZigType *wanted_type)
12575{
12576 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct"));
12577 return ira->codegen->invalid_instruction;
12578}
12579
12580static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr,
12581 IrInstruction *value, ZigType *wanted_type)
12582{
12583 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union"));
12584 return ira->codegen->invalid_instruction;
12585}
12586
1240412587static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
1240512588 ZigType *wanted_type, IrInstruction *value, ResultLoc *result_loc)
1240612589{
......@@ -12412,6 +12595,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1241212595 return ira->codegen->invalid_instruction;
1241312596 }
1241412597
12598 // This means the wanted type is anything.
12599 if (wanted_type == ira->codegen->builtin_types.entry_var) {
12600 return value;
12601 }
12602
1241512603 // perfect match or non-const to const
1241612604 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,
1241712605 source_node, false);
......@@ -12586,7 +12774,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1258612774 // cast from [N]T to []const T
1258712775 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
1258812776 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
12589 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
12777 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
1259012778 assert(ptr_type->id == ZigTypeIdPointer);
1259112779 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1259212780 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
......@@ -12603,7 +12791,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1260312791 actual_type->id == ZigTypeIdArray)
1260412792 {
1260512793 ZigType *ptr_type =
12606 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
12794 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index]->type_entry;
1260712795 assert(ptr_type->id == ZigTypeIdPointer);
1260812796 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1260912797 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
......@@ -12642,12 +12830,71 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1264212830 }
1264312831
1264412832 // *[N]T to []T
12645 if (is_slice(wanted_type) &&
12833 // *[N]T to E![]T
12834 if ((is_slice(wanted_type) ||
12835 (wanted_type->id == ZigTypeIdErrorUnion &&
12836 is_slice(wanted_type->data.error_union.payload_type))) &&
1264612837 actual_type->id == ZigTypeIdPointer &&
1264712838 actual_type->data.pointer.ptr_len == PtrLenSingle &&
1264812839 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1264912840 {
12650 ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
12841 ZigType *slice_type = (wanted_type->id == ZigTypeIdErrorUnion) ?
12842 wanted_type->data.error_union.payload_type : wanted_type;
12843 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
12844 assert(slice_ptr_type->id == ZigTypeIdPointer);
12845 ZigType *array_type = actual_type->data.pointer.child_type;
12846 bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0
12847 || !actual_type->data.pointer.is_const);
12848 if (const_ok && types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
12849 array_type->data.array.child_type, source_node,
12850 !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)
12851 {
12852 // If the pointers both have ABI align, it works.
12853 // Or if the array length is 0, alignment doesn't matter.
12854 bool ok_align = array_type->data.array.len == 0 ||
12855 (slice_ptr_type->data.pointer.explicit_alignment == 0 &&
12856 actual_type->data.pointer.explicit_alignment == 0);
12857 if (!ok_align) {
12858 // If either one has non ABI align, we have to resolve them both
12859 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
12860 ResolveStatusAlignmentKnown)))
12861 {
12862 return ira->codegen->invalid_instruction;
12863 }
12864 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
12865 ResolveStatusAlignmentKnown)))
12866 {
12867 return ira->codegen->invalid_instruction;
12868 }
12869 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
12870 }
12871 if (ok_align) {
12872 if (wanted_type->id == ZigTypeIdErrorUnion) {
12873 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value, nullptr);
12874 if (type_is_invalid(cast1->value.type))
12875 return ira->codegen->invalid_instruction;
12876
12877 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);
12878 if (type_is_invalid(cast2->value.type))
12879 return ira->codegen->invalid_instruction;
12880
12881 return cast2;
12882 } else {
12883 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, result_loc);
12884 }
12885 }
12886 }
12887 }
12888
12889 // *[N]T to E![]T
12890 if (wanted_type->id == ZigTypeIdErrorUnion &&
12891 is_slice(wanted_type->data.error_union.payload_type) &&
12892 actual_type->id == ZigTypeIdPointer &&
12893 actual_type->data.pointer.ptr_len == PtrLenSingle &&
12894 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
12895 {
12896 ZigType *slice_type = wanted_type->data.error_union.payload_type;
12897 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
1265112898 assert(slice_ptr_type->id == ZigTypeIdPointer);
1265212899 ZigType *array_type = actual_type->data.pointer.child_type;
1265312900 bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0
......@@ -12674,7 +12921,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1267412921 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
1267512922 }
1267612923 if (ok_align) {
12677 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, wanted_type, result_loc);
12924 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, result_loc);
1267812925 }
1267912926 }
1268012927 }
......@@ -12724,7 +12971,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1272412971 actual_type->id == ZigTypeIdArray)
1272512972 {
1272612973 ZigType *ptr_type =
12727 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
12974 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index]->type_entry;
1272812975 assert(ptr_type->id == ZigTypeIdPointer);
1272912976 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
1273012977 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
......@@ -12909,6 +13156,25 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1290913156 return ir_analyze_int_to_c_ptr(ira, source_instr, value, wanted_type);
1291013157 }
1291113158
13159 // cast from inferred struct type to array, union, or struct
13160 if (actual_type->id == ZigTypeIdStruct && actual_type->data.structure.is_inferred) {
13161 AstNode *decl_node = actual_type->data.structure.decl_node;
13162 ir_assert(decl_node->type == NodeTypeContainerInitExpr, source_instr);
13163 ContainerInitKind init_kind = decl_node->data.container_init_expr.kind;
13164 uint32_t field_count = actual_type->data.structure.src_field_count;
13165 if (wanted_type->id == ZigTypeIdArray && (init_kind == ContainerInitKindArray || field_count == 0) &&
13166 wanted_type->data.array.len == field_count)
13167 {
13168 return ir_analyze_struct_literal_to_array(ira, source_instr, value, wanted_type);
13169 } else if (wanted_type->id == ZigTypeIdStruct &&
13170 (init_kind == ContainerInitKindStruct || field_count == 0))
13171 {
13172 return ir_analyze_struct_literal_to_struct(ira, source_instr, value, wanted_type);
13173 } else if (wanted_type->id == ZigTypeIdUnion && init_kind == ContainerInitKindStruct && field_count == 1) {
13174 return ir_analyze_struct_literal_to_union(ira, source_instr, value, wanted_type);
13175 }
13176 }
13177
1291213178 // cast from undefined to anything
1291313179 if (actual_type->id == ZigTypeIdUndefined) {
1291413180 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
......@@ -12922,8 +13188,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1292213188 return ira->codegen->invalid_instruction;
1292313189}
1292413190
12925static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type,
12926 ResultLoc *result_loc)
13191static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *source_instr,
13192 IrInstruction *value, ZigType *expected_type, ResultLoc *result_loc)
1292713193{
1292813194 assert(value);
1292913195 assert(value != ira->codegen->invalid_instruction);
......@@ -12937,11 +13203,11 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction
1293713203 if (value->value.type->id == ZigTypeIdUnreachable)
1293813204 return value;
1293913205
12940 return ir_analyze_cast(ira, value, expected_type, value, result_loc);
13206 return ir_analyze_cast(ira, source_instr, expected_type, value, result_loc);
1294113207}
1294213208
1294313209static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
12944 return ir_implicit_cast_with_result(ira, value, expected_type, nullptr);
13210 return ir_implicit_cast_with_result(ira, value, value, expected_type, nullptr);
1294513211}
1294613212
1294713213static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
......@@ -13223,8 +13489,8 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1322313489 if (!const_val)
1322413490 return nullptr;
1322513491
13226 ConstExprValue *ptr_field = &const_val->data.x_struct.fields[slice_ptr_index];
13227 ConstExprValue *len_field = &const_val->data.x_struct.fields[slice_len_index];
13492 ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index];
13493 ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index];
1322813494
1322913495 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
1323013496 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
......@@ -13269,16 +13535,6 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1326913535 if (type_is_invalid(operand->value.type))
1327013536 return ir_unreach_error(ira);
1327113537
13272 if (!instr_is_comptime(operand) && ira->explicit_return_type != nullptr &&
13273 handle_is_ptr(ira->explicit_return_type))
13274 {
13275 // result location mechanism took care of it.
13276 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
13277 instruction->base.source_node, nullptr);
13278 result->value.type = ira->codegen->builtin_types.entry_unreachable;
13279 return ir_finish_anal(ira, result);
13280 }
13281
1328213538 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
1328313539 if (type_is_invalid(casted_operand->value.type)) {
1328413540 AstNode *source_node = ira->explicit_return_type_source_node;
......@@ -13290,6 +13546,16 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1329013546 return ir_unreach_error(ira);
1329113547 }
1329213548
13549 if (!instr_is_comptime(operand) && ira->explicit_return_type != nullptr &&
13550 handle_is_ptr(ira->explicit_return_type))
13551 {
13552 // result location mechanism took care of it.
13553 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
13554 instruction->base.source_node, nullptr);
13555 result->value.type = ira->codegen->builtin_types.entry_unreachable;
13556 return ir_finish_anal(ira, result);
13557 }
13558
1329313559 if (casted_operand->value.special == ConstValSpecialRuntime &&
1329413560 casted_operand->value.type->id == ZigTypeIdPointer &&
1329513561 casted_operand->value.data.rh_ptr == RuntimeHintPtrStack)
......@@ -14550,13 +14816,13 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1455014816 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;
1455114817 op1_array_end = op1_array_val->type->data.array.len - 1;
1455214818 } else if (is_slice(op1_type)) {
14553 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
14819 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;
1455414820 child_type = ptr_type->data.pointer.child_type;
14555 ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];
14821 ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index];
1455614822 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
1455714823 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
1455814824 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
14559 ConstExprValue *len_val = &op1_val->data.x_struct.fields[slice_len_index];
14825 ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index];
1456014826 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
1456114827 } else {
1456214828 ir_add_error(ira, op1,
......@@ -14583,13 +14849,13 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1458314849 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;
1458414850 op2_array_end = op2_array_val->type->data.array.len - 1;
1458514851 } else if (is_slice(op2_type)) {
14586 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
14852 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;
1458714853 op2_type_valid = ptr_type->data.pointer.child_type == child_type;
14588 ConstExprValue *ptr_val = &op2_val->data.x_struct.fields[slice_ptr_index];
14854 ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index];
1458914855 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
1459014856 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
1459114857 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
14592 ConstExprValue *len_val = &op2_val->data.x_struct.fields[slice_len_index];
14858 ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index];
1459314859 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
1459414860 } else {
1459514861 ir_add_error(ira, op2,
......@@ -14621,17 +14887,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1462114887 out_array_val->special = ConstValSpecialStatic;
1462214888 out_array_val->type = get_array_type(ira->codegen, child_type, new_len);
1462314889
14624 out_val->data.x_struct.fields = create_const_vals(2);
14890 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
1462514891
14626 out_val->data.x_struct.fields[slice_ptr_index].type = ptr_type;
14627 out_val->data.x_struct.fields[slice_ptr_index].special = ConstValSpecialStatic;
14628 out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.special = ConstPtrSpecialBaseArray;
14629 out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.data.base_array.array_val = out_array_val;
14630 out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.data.base_array.elem_index = 0;
14892 out_val->data.x_struct.fields[slice_ptr_index]->type = ptr_type;
14893 out_val->data.x_struct.fields[slice_ptr_index]->special = ConstValSpecialStatic;
14894 out_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.special = ConstPtrSpecialBaseArray;
14895 out_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.data.base_array.array_val = out_array_val;
14896 out_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.data.base_array.elem_index = 0;
1463114897
14632 out_val->data.x_struct.fields[slice_len_index].type = ira->codegen->builtin_types.entry_usize;
14633 out_val->data.x_struct.fields[slice_len_index].special = ConstValSpecialStatic;
14634 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index].data.x_bigint, new_len);
14898 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
14899 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
14900 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
1463514901 } else {
1463614902 new_len += 1; // null byte
1463714903
......@@ -15295,15 +15561,16 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1529515561 result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
1529615562 result->base.value.data.x_ptr.data.ref.pointee = pointee;
1529715563
15298 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusZeroBitsKnown)))
15564 bool var_type_has_bits;
15565 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))
1529915566 return ira->codegen->invalid_instruction;
1530015567 if (align != 0) {
1530115568 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
1530215569 return ira->codegen->invalid_instruction;
15303 if (!type_has_bits(var_type)) {
15304 ir_add_error(ira, source_inst,
15305 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
15306 name_hint, buf_ptr(&var_type->name)));
15570 if (!var_type_has_bits) {
15571 ir_add_error(ira, source_inst,
15572 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
15573 name_hint, buf_ptr(&var_type->name)));
1530715574 return ira->codegen->invalid_instruction;
1530815575 }
1530915576 }
......@@ -15331,6 +15598,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe
1533115598 case ResultLocIdNone:
1533215599 case ResultLocIdVar:
1533315600 case ResultLocIdBitCast:
15601 case ResultLocIdCast:
1533415602 return nullptr;
1533515603 case ResultLocIdInstruction:
1533615604 return result_loc->source_instruction->child->value.type;
......@@ -15374,24 +15642,51 @@ static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
1537415642 ptr->value.data.x_ptr.data.ref.pointee = undef_child;
1537515643}
1537615644
15377static bool ir_result_has_type(ResultLoc *result_loc) {
15645static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out) {
1537815646 switch (result_loc->id) {
1537915647 case ResultLocIdInvalid:
1538015648 case ResultLocIdPeerParent:
1538115649 zig_unreachable();
1538215650 case ResultLocIdNone:
1538315651 case ResultLocIdPeer:
15384 return false;
15652 *out = false;
15653 return ErrorNone;
1538515654 case ResultLocIdReturn:
1538615655 case ResultLocIdInstruction:
1538715656 case ResultLocIdBitCast:
15388 return true;
15657 *out = true;
15658 return ErrorNone;
15659 case ResultLocIdCast: {
15660 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
15661 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
15662 if (type_is_invalid(dest_type))
15663 return ErrorSemanticAnalyzeFail;
15664 *out = (dest_type != ira->codegen->builtin_types.entry_var);
15665 return ErrorNone;
15666 }
1538915667 case ResultLocIdVar:
15390 return reinterpret_cast<ResultLocVar *>(result_loc)->var->decl_node->data.variable_declaration.type != nullptr;
15668 *out = reinterpret_cast<ResultLocVar *>(result_loc)->var->decl_node->data.variable_declaration.type != nullptr;
15669 return ErrorNone;
1539115670 }
1539215671 zig_unreachable();
1539315672}
1539415673
15674static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,
15675 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
15676{
15677 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
15678 alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
15679 PtrLenSingle, 0, 0, 0, false);
15680 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
15681 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
15682 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
15683 fn_entry->alloca_gen_list.append(alloca_gen);
15684 }
15685 result_loc->written = true;
15686 result_loc->resolved_loc = &alloca_gen->base;
15687 return result_loc->resolved_loc;
15688}
15689
1539515690// when calling this function, at the callsite must check for result type noreturn and propagate it up
1539615691static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
1539715692 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
......@@ -15414,19 +15709,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1541415709 return nullptr;
1541515710 }
1541615711 // need to return a result location and don't have one. use a stack allocation
15417 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
15418 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
15419 return ira->codegen->invalid_instruction;
15420 alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
15421 PtrLenSingle, 0, 0, 0, false);
15422 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
15423 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
15424 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
15425 fn_entry->alloca_gen_list.append(alloca_gen);
15426 }
15427 result_loc->written = true;
15428 result_loc->resolved_loc = &alloca_gen->base;
15429 return result_loc->resolved_loc;
15712 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
15713 force_runtime, non_null_comptime);
1543015714 }
1543115715 case ResultLocIdVar: {
1543215716 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
......@@ -15529,7 +15813,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1552915813 }
1553015814 return nullptr;
1553115815 }
15532 if (ir_result_has_type(peer_parent->parent)) {
15816 bool peer_parent_has_type;
15817 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
15818 return ira->codegen->invalid_instruction;
15819 if (peer_parent_has_type) {
1553315820 if (peer_parent->parent->id == ResultLocIdReturn && value != nullptr) {
1553415821 reinterpret_cast<ResultLocReturn *>(peer_parent->parent)->implicit_return_type_done = true;
1553515822 ira->src_implicit_return_type_list.append(value);
......@@ -15564,6 +15851,89 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1556415851 result_loc->resolved_loc = parent_result_loc;
1556515852 return result_loc->resolved_loc;
1556615853 }
15854 case ResultLocIdCast: {
15855 if (value != nullptr && value->value.special != ConstValSpecialRuntime)
15856 return nullptr;
15857 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
15858 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
15859 if (type_is_invalid(dest_type))
15860 return ira->codegen->invalid_instruction;
15861
15862 if (dest_type == ira->codegen->builtin_types.entry_var) {
15863 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
15864 force_runtime, non_null_comptime);
15865 }
15866
15867 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type,
15868 result_cast->base.source_instruction->source_node, false);
15869 if (const_cast_result.id == ConstCastResultIdInvalid)
15870 return ira->codegen->invalid_instruction;
15871 if (const_cast_result.id != ConstCastResultIdOk) {
15872 // We will not be able to provide a result location for this value. Create
15873 // a new result location.
15874 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
15875 force_runtime, non_null_comptime);
15876 }
15877
15878 // In this case we can pointer cast the result location.
15879 IrInstruction *casted_value;
15880 if (value != nullptr) {
15881 casted_value = ir_implicit_cast(ira, value, dest_type);
15882 } else {
15883 casted_value = nullptr;
15884 }
15885
15886 if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) {
15887 return casted_value;
15888 }
15889
15890 bool old_parent_result_loc_written = result_cast->parent->written;
15891 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
15892 dest_type, casted_value, force_runtime, non_null_comptime, true);
15893 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
15894 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
15895 {
15896 return parent_result_loc;
15897 }
15898 ZigType *parent_ptr_type = parent_result_loc->value.type;
15899 assert(parent_ptr_type->id == ZigTypeIdPointer);
15900 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
15901 ResolveStatusAlignmentKnown)))
15902 {
15903 return ira->codegen->invalid_instruction;
15904 }
15905 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
15906 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
15907 return ira->codegen->invalid_instruction;
15908 }
15909 if (!type_has_bits(value_type)) {
15910 parent_ptr_align = 0;
15911 }
15912 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
15913 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
15914 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
15915
15916 {
15917 // we also need to check that this cast is OK.
15918 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
15919 parent_result_loc->value.type, ptr_type,
15920 result_cast->base.source_instruction->source_node, false);
15921 if (const_cast_result.id == ConstCastResultIdInvalid)
15922 return ira->codegen->invalid_instruction;
15923 if (const_cast_result.id != ConstCastResultIdOk) {
15924 // We will not be able to provide a result location for this value. Create
15925 // a new result location.
15926 result_cast->parent->written = old_parent_result_loc_written;
15927 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
15928 force_runtime, non_null_comptime);
15929 }
15930 }
15931
15932 result_loc->written = true;
15933 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
15934 ptr_type, result_cast->base.source_instruction, false);
15935 return result_loc->resolved_loc;
15936 }
1556715937 case ResultLocIdBitCast: {
1556815938 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
1556915939 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
......@@ -15686,22 +16056,40 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1568616056 return result_loc;
1568716057}
1568816058
15689static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
15690 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
15691 if (type_is_invalid(dest_type))
15692 return ira->codegen->invalid_instruction;
15693
15694 IrInstruction *target = instruction->target->child;
15695 if (type_is_invalid(target->value.type))
15696 return ira->codegen->invalid_instruction;
15697
15698 return ir_implicit_cast_with_result(ira, target, dest_type, instruction->result_loc);
15699}
16059static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
16060 IrInstructionResolveResult *instruction)
16061{
16062 ZigType *implicit_elem_type;
16063 if (instruction->ty == nullptr) {
16064 if (instruction->result_loc->id == ResultLocIdCast) {
16065 implicit_elem_type = ir_resolve_type(ira,
16066 instruction->result_loc->source_instruction->child);
16067 if (type_is_invalid(implicit_elem_type))
16068 return ira->codegen->invalid_instruction;
16069 } else if (instruction->result_loc->id == ResultLocIdReturn) {
16070 implicit_elem_type = ira->explicit_return_type;
16071 if (type_is_invalid(implicit_elem_type))
16072 return ira->codegen->invalid_instruction;
16073 } else {
16074 implicit_elem_type = ira->codegen->builtin_types.entry_var;
16075 }
16076 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {
16077 Buf *bare_name = buf_alloc();
16078 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
16079 instruction->base.scope, instruction->base.source_node, bare_name);
1570016080
15701static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) {
15702 ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
15703 if (type_is_invalid(implicit_elem_type))
15704 return ira->codegen->invalid_instruction;
16081 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
16082 instruction->base.scope, ContainerKindStruct, instruction->base.source_node,
16083 buf_ptr(name), bare_name, ContainerLayoutAuto);
16084 inferred_struct_type->data.structure.is_inferred = true;
16085 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
16086 implicit_elem_type = inferred_struct_type;
16087 }
16088 } else {
16089 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
16090 if (type_is_invalid(implicit_elem_type))
16091 return ira->codegen->invalid_instruction;
16092 }
1570516093 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
1570616094 implicit_elem_type, nullptr, false, true, true);
1570716095 if (result_loc != nullptr)
......@@ -15760,6 +16148,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
1576016148 case ResultLocIdNone:
1576116149 case ResultLocIdInstruction:
1576216150 case ResultLocIdBitCast:
16151 case ResultLocIdCast:
1576316152 break;
1576416153 }
1576516154}
......@@ -16062,13 +16451,63 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1606216451 return ir_const_void(ira, source_instr);
1606316452 }
1606416453
16065 ZigType *child_type = ptr->value.type->data.pointer.child_type;
16454 InferredStructField *isf = ptr->value.type->data.pointer.inferred_struct_field;
16455 if (allow_write_through_const && isf != nullptr) {
16456 // Now it's time to add the field to the struct type.
16457 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;
16458 uint32_t new_field_count = old_field_count + 1;
16459 isf->inferred_struct_type->data.structure.src_field_count = new_field_count;
16460 isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields(
16461 isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count);
16462
16463 TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count];
16464 field->name = isf->field_name;
16465 field->type_entry = uncasted_value->value.type;
16466 field->type_val = create_const_type(ira->codegen, field->type_entry);
16467 field->src_index = old_field_count;
16468 field->decl_node = uncasted_value->source_node;
16469
16470 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
16471 IrInstruction *casted_ptr;
16472 if (instr_is_comptime(ptr)) {
16473 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);
16474 copy_const_val(&casted_ptr->value, &ptr->value, false);
16475 casted_ptr->value.type = struct_ptr_type;
16476 } else {
16477 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,
16478 source_instr->source_node, struct_ptr_type, ptr, CastOpNoop);
16479 casted_ptr->value.type = struct_ptr_type;
16480 }
16481 if (instr_is_comptime(casted_ptr)) {
16482 ConstExprValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
16483 if (!ptr_val)
16484 return ira->codegen->invalid_instruction;
16485 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
16486 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
16487 source_instr->source_node);
16488 struct_val->special = ConstValSpecialStatic;
16489 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
16490 old_field_count, new_field_count);
16491
16492 ConstExprValue *field_val = struct_val->data.x_struct.fields[old_field_count];
16493 field_val->special = ConstValSpecialUndef;
16494 field_val->type = field->type_entry;
16495 field_val->parent.id = ConstParentIdStruct;
16496 field_val->parent.data.p_struct.struct_val = struct_val;
16497 field_val->parent.data.p_struct.field_index = old_field_count;
16498 }
16499 }
16500
16501 ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, casted_ptr,
16502 isf->inferred_struct_type, true);
16503 }
1606616504
1606716505 if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) {
1606816506 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
1606916507 return ira->codegen->invalid_instruction;
1607016508 }
1607116509
16510 ZigType *child_type = ptr->value.type->data.pointer.child_type;
1607216511 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);
1607316512 if (value == ira->codegen->invalid_instruction)
1607416513 return ira->codegen->invalid_instruction;
......@@ -16799,25 +17238,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1679917238
1680017239 if (is_comptime || instr_is_comptime(fn_ref)) {
1680117240 if (fn_ref->value.type->id == ZigTypeIdMetaType) {
16802 ZigType *dest_type = ir_resolve_type(ira, fn_ref);
16803 if (type_is_invalid(dest_type))
16804 return ira->codegen->invalid_instruction;
16805
16806 size_t actual_param_count = call_instruction->arg_count;
16807
16808 if (actual_param_count != 1) {
16809 ir_add_error_node(ira, call_instruction->base.source_node,
16810 buf_sprintf("cast expression expects exactly one parameter"));
17241 ZigType *ty = ir_resolve_type(ira, fn_ref);
17242 if (ty == nullptr)
1681117243 return ira->codegen->invalid_instruction;
16812 }
16813
16814 IrInstruction *arg = call_instruction->args[0]->child;
16815
16816 IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg,
16817 call_instruction->result_loc);
16818 if (type_is_invalid(cast_instruction->value.type))
16819 return ira->codegen->invalid_instruction;
16820 return ir_finish_anal(ira, cast_instruction);
17244 ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,
17245 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
17246 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
17247 buf_sprintf("use @as builtin for type coercion"));
17248 return ira->codegen->invalid_instruction;
1682117249 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
1682217250 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
1682317251 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type;
......@@ -17215,6 +17643,8 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,
1721517643}
1721617644
1721717645static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
17646 Error err;
17647
1721817648 if (ira->const_predecessor_bb) {
1721917649 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
1722017650 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
......@@ -17264,6 +17694,8 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1726417694 peer_parent->resolved_type = ir_resolve_peer_types(ira,
1726517695 peer_parent->base.source_instruction->source_node, expected_type, instructions,
1726617696 peer_parent->peers.length);
17697 if (type_is_invalid(peer_parent->resolved_type))
17698 return ira->codegen->invalid_instruction;
1726717699
1726817700 // the logic below assumes there are no instructions in the new current basic block yet
1726917701 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base);
......@@ -17346,20 +17778,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1734617778 }
1734717779
1734817780 ZigType *resolved_type;
17349 if (peer_parent != nullptr && ir_result_has_type(peer_parent->parent)) {
17350 if (peer_parent->parent->id == ResultLocIdReturn) {
17351 resolved_type = ira->explicit_return_type;
17352 } else {
17353 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type;
17354 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
17355 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
17781 if (peer_parent != nullptr) {
17782 bool peer_parent_has_type;
17783 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
17784 return ira->codegen->invalid_instruction;
17785 if (peer_parent_has_type) {
17786 if (peer_parent->parent->id == ResultLocIdReturn) {
17787 resolved_type = ira->explicit_return_type;
17788 } else if (peer_parent->parent->id == ResultLocIdCast) {
17789 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
17790 if (type_is_invalid(resolved_type))
17791 return ira->codegen->invalid_instruction;
17792 } else {
17793 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type;
17794 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
17795 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
17796 }
17797 goto skip_resolve_peer_types;
1735617798 }
17357 } else {
17799 }
17800 {
1735817801 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
1735917802 new_incoming_values.items, new_incoming_values.length);
1736017803 if (type_is_invalid(resolved_type))
1736117804 return ira->codegen->invalid_instruction;
1736217805 }
17806skip_resolve_peer_types:
1736317807
1736417808 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1736517809 case OnePossibleValueInvalid:
......@@ -17449,7 +17893,7 @@ static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_ali
1744917893
1745017894static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) {
1745117895 assert(is_slice(slice_type));
17452 ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry,
17896 ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index]->type_entry,
1745317897 new_align);
1745417898 return get_slice_type(g, ptr_type);
1745517899}
......@@ -17535,7 +17979,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1753517979 }
1753617980 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
1753717981 } else if (is_slice(array_type)) {
17538 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
17982 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,
1753917983 elem_ptr_instruction->ptr_len);
1754017984 } else if (array_type->id == ZigTypeIdArgTuple) {
1754117985 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
......@@ -17571,6 +18015,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1757118015 } else if (array_type->id == ZigTypeIdVector) {
1757218016 // This depends on whether the element index is comptime, so it is computed later.
1757318017 return_type = nullptr;
18018 } else if (elem_ptr_instruction->init_array_type_source_node != nullptr &&
18019 array_type->id == ZigTypeIdStruct &&
18020 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)
18021 {
18022 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18023 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
18024 if (casted_elem_index == ira->codegen->invalid_instruction)
18025 return ira->codegen->invalid_instruction;
18026 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);
18027 Buf *field_name = buf_alloc();
18028 bigint_append_buf(field_name, &casted_elem_index->value.data.x_bigint, 10);
18029 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,
18030 array_ptr, array_type);
1757418031 } else {
1757518032 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1757618033 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
......@@ -17601,7 +18058,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1760118058 return_type = get_pointer_to_type_extra2(ira->codegen, elem_type,
1760218059 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
1760318060 elem_ptr_instruction->ptr_len,
17604 get_ptr_align(ira->codegen, ptr_type), 0, host_vec_len, false, (uint32_t)index);
18061 get_ptr_align(ira->codegen, ptr_type), 0, host_vec_len, false, (uint32_t)index,
18062 nullptr);
1760518063 } else if (return_type->data.pointer.explicit_alignment != 0) {
1760618064 // figure out the largest alignment possible
1760718065
......@@ -17639,7 +18097,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1763918097 if (array_ptr_val == nullptr)
1764018098 return ira->codegen->invalid_instruction;
1764118099
17642 if (array_ptr_val->special == ConstValSpecialUndef && elem_ptr_instruction->init_array_type != nullptr) {
18100 if (array_ptr_val->special == ConstValSpecialUndef &&
18101 elem_ptr_instruction->init_array_type_source_node != nullptr)
18102 {
1764318103 if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
1764418104 array_ptr_val->data.x_array.special = ConstArraySpecialNone;
1764518105 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
......@@ -17653,11 +18113,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1765318113 elem_val->parent.data.p_array.elem_index = i;
1765418114 }
1765518115 } else if (is_slice(array_type)) {
17656 ZigType *actual_array_type = ir_resolve_type(ira, elem_ptr_instruction->init_array_type->child);
18116 ir_assert(array_ptr->value.type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);
18117 ZigType *actual_array_type = array_ptr->value.type->data.pointer.child_type;
18118
1765718119 if (type_is_invalid(actual_array_type))
1765818120 return ira->codegen->invalid_instruction;
1765918121 if (actual_array_type->id != ZigTypeIdArray) {
17660 ir_add_error(ira, elem_ptr_instruction->init_array_type,
18122 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
1766118123 buf_sprintf("expected array type or [_], found slice"));
1766218124 return ira->codegen->invalid_instruction;
1766318125 }
......@@ -17679,9 +18141,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1767918141
1768018142 init_const_slice(ira->codegen, array_ptr_val, array_init_val, 0, actual_array_type->data.array.len,
1768118143 false);
17682 array_ptr_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.mut = ConstPtrMutInfer;
18144 array_ptr_val->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutInfer;
1768318145 } else {
17684 ir_add_error(ira, elem_ptr_instruction->init_array_type,
18146 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
1768518147 buf_sprintf("expected array type or [_], found '%s'",
1768618148 buf_ptr(&array_type->name)));
1768718149 return ira->codegen->invalid_instruction;
......@@ -17751,7 +18213,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1775118213 }
1775218214 return result;
1775318215 } else if (is_slice(array_type)) {
17754 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
18216 ConstExprValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
1775518217 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
1775618218 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
1775718219 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
......@@ -17760,7 +18222,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1776018222 result->value.type = return_type;
1776118223 return result;
1776218224 }
17763 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
18225 ConstExprValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
1776418226 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
1776518227 ConstExprValue *out_val = &result->value;
1776618228 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
......@@ -17814,7 +18276,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1781418276 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
1781518277 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1781618278 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
17817 false, elem_ptr_instruction->ptr_len, elem_ptr_instruction->init_array_type);
18279 false, elem_ptr_instruction->ptr_len, nullptr);
1781818280 result->value.type = return_type;
1781918281 result->value.special = ConstValSpecialStatic;
1782018282 } else {
......@@ -17838,7 +18300,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1783818300 return_type = get_pointer_to_type_extra2(ira->codegen, elem_type,
1783918301 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
1784018302 elem_ptr_instruction->ptr_len,
17841 get_ptr_align(ira->codegen, ptr_type), 0, host_vec_len, false, VECTOR_INDEX_RUNTIME);
18303 get_ptr_align(ira->codegen, ptr_type), 0, host_vec_len, false, VECTOR_INDEX_RUNTIME,
18304 nullptr);
1784218305 } else {
1784318306 // runtime known element index
1784418307 switch (type_requires_comptime(ira->codegen, return_type)) {
......@@ -17875,7 +18338,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1787518338
1787618339 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1787718340 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
17878 elem_ptr_instruction->ptr_len, elem_ptr_instruction->init_array_type);
18341 elem_ptr_instruction->ptr_len, nullptr);
1787918342 result->value.type = return_type;
1788018343 return result;
1788118344}
......@@ -17954,43 +18417,47 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1795418417 case OnePossibleValueNo:
1795518418 break;
1795618419 }
17957 ResolveStatus needed_resolve_status =
17958 (struct_type->data.structure.layout == ContainerLayoutAuto) ?
17959 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
17960 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
17961 return ira->codegen->invalid_instruction;
17962 assert(struct_ptr->value.type->id == ZigTypeIdPointer);
17963 uint32_t ptr_bit_offset = struct_ptr->value.type->data.pointer.bit_offset_in_host;
17964 uint32_t ptr_host_int_bytes = struct_ptr->value.type->data.pointer.host_int_bytes;
17965 uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ?
17966 get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes;
1796718420 bool is_const = struct_ptr->value.type->data.pointer.is_const;
1796818421 bool is_volatile = struct_ptr->value.type->data.pointer.is_volatile;
17969 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
17970 is_const, is_volatile, PtrLenSingle, field->align,
17971 (uint32_t)(ptr_bit_offset + field->bit_offset_in_host),
17972 (uint32_t)host_int_bytes_for_result_type, false);
18422 ZigType *ptr_type;
18423 if (struct_type->data.structure.is_inferred) {
18424 ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
18425 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
18426 } else {
18427 ResolveStatus needed_resolve_status =
18428 (struct_type->data.structure.layout == ContainerLayoutAuto) ?
18429 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
18430 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
18431 return ira->codegen->invalid_instruction;
18432 assert(struct_ptr->value.type->id == ZigTypeIdPointer);
18433 uint32_t ptr_bit_offset = struct_ptr->value.type->data.pointer.bit_offset_in_host;
18434 uint32_t ptr_host_int_bytes = struct_ptr->value.type->data.pointer.host_int_bytes;
18435 uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ?
18436 get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes;
18437 ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
18438 is_const, is_volatile, PtrLenSingle, field->align,
18439 (uint32_t)(ptr_bit_offset + field->bit_offset_in_host),
18440 (uint32_t)host_int_bytes_for_result_type, false);
18441 }
1797318442 if (instr_is_comptime(struct_ptr)) {
1797418443 ConstExprValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
1797518444 if (!ptr_val)
1797618445 return ira->codegen->invalid_instruction;
1797718446
1797818447 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
17979 if ((err = type_resolve(ira->codegen, struct_type, ResolveStatusSizeKnown)))
17980 return ira->codegen->invalid_instruction;
17981
1798218448 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
1798318449 if (struct_val == nullptr)
1798418450 return ira->codegen->invalid_instruction;
1798518451 if (type_is_invalid(struct_val->type))
1798618452 return ira->codegen->invalid_instruction;
1798718453 if (initializing && struct_val->special == ConstValSpecialUndef) {
17988 struct_val->data.x_struct.fields = create_const_vals(struct_type->data.structure.src_field_count);
18454 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
1798918455 struct_val->special = ConstValSpecialStatic;
1799018456 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
17991 ConstExprValue *field_val = &struct_val->data.x_struct.fields[i];
18457 ConstExprValue *field_val = struct_val->data.x_struct.fields[i];
1799218458 field_val->special = ConstValSpecialUndef;
17993 field_val->type = struct_type->data.structure.fields[i].type_entry;
18459 field_val->type = resolve_struct_field_type(ira->codegen,
18460 struct_type->data.structure.fields[i]);
1799418461 field_val->parent.id = ConstParentIdStruct;
1799518462 field_val->parent.data.p_struct.struct_val = struct_val;
1799618463 field_val->parent.data.p_struct.field_index = i;
......@@ -18019,12 +18486,53 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1801918486 return result;
1802018487}
1802118488
18489static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
18490 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)
18491{
18492 // The type of the field is not available until a store using this pointer happens.
18493 // So, here we create a special pointer type which has the inferred struct type and
18494 // field name encoded in the type. Later, when there is a store via this pointer,
18495 // the field type will then be available, and the field will be added to the inferred
18496 // struct.
18497
18498 ZigType *container_ptr_type = container_ptr->value.type;
18499 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);
18500
18501 InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField");
18502 inferred_struct_field->inferred_struct_type = container_type;
18503 inferred_struct_field->field_name = field_name;
18504
18505 ZigType *elem_type = ira->codegen->builtin_types.entry_var;
18506 ZigType *field_ptr_type = get_pointer_to_type_extra2(ira->codegen, elem_type,
18507 container_ptr_type->data.pointer.is_const, container_ptr_type->data.pointer.is_volatile,
18508 PtrLenSingle, 0, 0, 0, false, VECTOR_INDEX_NONE, inferred_struct_field);
18509
18510 if (instr_is_comptime(container_ptr)) {
18511 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);
18512 copy_const_val(&result->value, &container_ptr->value, false);
18513 result->value.type = field_ptr_type;
18514 return result;
18515 }
18516
18517 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,
18518 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
18519 result->value.type = field_ptr_type;
18520 return result;
18521}
18522
1802218523static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
1802318524 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing)
1802418525{
1802518526 Error err;
1802618527
1802718528 ZigType *bare_type = container_ref_type(container_type);
18529
18530 if (initializing && bare_type->id == ZigTypeIdStruct &&
18531 bare_type->data.structure.resolve_status == ResolveStatusBeingInferred)
18532 {
18533 return ir_analyze_inferred_field_ptr(ira, field_name, source_instr, container_ptr, bare_type);
18534 }
18535
1802818536 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
1802918537 return ira->codegen->invalid_instruction;
1803018538
......@@ -18065,7 +18573,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1806518573 if (!ptr_val)
1806618574 return ira->codegen->invalid_instruction;
1806718575
18068 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
18576 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
18577 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1806918578 ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
1807018579 if (union_val == nullptr)
1807118580 return ira->codegen->invalid_instruction;
......@@ -18097,7 +18606,6 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1809718606
1809818607 ConstExprValue *payload_val = union_val->data.x_union.payload;
1809918608
18100
1810118609 IrInstruction *result;
1810218610 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
1810318611 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
......@@ -19799,6 +20307,11 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
1979920307 return ira->codegen->invalid_instruction;
1980020308 }
1980120309
20310 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
20311 // We're now done inferring the type.
20312 container_type->data.structure.resolve_status = ResolveStatusUnstarted;
20313 }
20314
1980220315 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
1980320316 return ira->codegen->invalid_instruction;
1980420317
......@@ -19865,14 +20378,18 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
1986520378 if (field_assign_nodes[i] != nullptr) continue;
1986620379
1986720380 // look for a default field value
19868 TypeStructField *field = &container_type->data.structure.fields[i];
20381 TypeStructField *field = container_type->data.structure.fields[i];
1986920382 if (field->init_val == nullptr) {
1987020383 // it's not memoized. time to go analyze it
19871 assert(field->decl_node->type == NodeTypeStructField);
19872 AstNode *init_node = field->decl_node->data.struct_field.value;
20384 AstNode *init_node;
20385 if (field->decl_node->type == NodeTypeStructField) {
20386 init_node = field->decl_node->data.struct_field.value;
20387 } else {
20388 init_node = nullptr;
20389 }
1987320390 if (init_node == nullptr) {
1987420391 ir_add_error_node(ira, instruction->source_node,
19875 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));
20392 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));
1987620393 any_missing = true;
1987720394 continue;
1987820395 }
......@@ -19926,14 +20443,18 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
1992620443static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1992720444 IrInstructionContainerInitList *instruction)
1992820445{
19929 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
19930 if (type_is_invalid(container_type))
19931 return ira->codegen->invalid_instruction;
20446 ir_assert(instruction->result_loc != nullptr, &instruction->base);
20447 IrInstruction *result_loc = instruction->result_loc->child;
20448 if (type_is_invalid(result_loc->value.type))
20449 return result_loc;
20450 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base);
20451
20452 ZigType *container_type = result_loc->value.type->data.pointer.child_type;
1993220453
1993320454 size_t elem_count = instruction->item_count;
1993420455
1993520456 if (is_slice(container_type)) {
19936 ir_add_error(ira, instruction->container_type,
20457 ir_add_error_node(ira, instruction->init_array_type_source_node,
1993720458 buf_sprintf("expected array type or [_], found slice"));
1993820459 return ira->codegen->invalid_instruction;
1993920460 }
......@@ -19955,29 +20476,28 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1995520476 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);
1995620477 }
1995720478
19958 if (container_type->id != ZigTypeIdArray) {
20479 if (container_type->id == ZigTypeIdArray) {
20480 ZigType *child_type = container_type->data.array.child_type;
20481 if (container_type->data.array.len != elem_count) {
20482 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count);
20483
20484 ir_add_error(ira, &instruction->base,
20485 buf_sprintf("expected %s literal, found %s literal",
20486 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
20487 return ira->codegen->invalid_instruction;
20488 }
20489 } else if (container_type->id == ZigTypeIdStruct &&
20490 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)
20491 {
20492 // We're now done inferring the type.
20493 container_type->data.structure.resolve_status = ResolveStatusUnstarted;
20494 } else {
1995920495 ir_add_error_node(ira, instruction->base.source_node,
1996020496 buf_sprintf("type '%s' does not support array initialization",
1996120497 buf_ptr(&container_type->name)));
1996220498 return ira->codegen->invalid_instruction;
1996320499 }
1996420500
19965 ir_assert(instruction->result_loc != nullptr, &instruction->base);
19966 IrInstruction *result_loc = instruction->result_loc->child;
19967 if (type_is_invalid(result_loc->value.type))
19968 return result_loc;
19969 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base);
19970
19971 ZigType *child_type = container_type->data.array.child_type;
19972 if (container_type->data.array.len != elem_count) {
19973 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count);
19974
19975 ir_add_error(ira, &instruction->base,
19976 buf_sprintf("expected %s literal, found %s literal",
19977 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
19978 return ira->codegen->invalid_instruction;
19979 }
19980
1998120501 switch (type_has_one_possible_value(ira->codegen, container_type)) {
1998220502 case OnePossibleValueInvalid:
1998320503 return ira->codegen->invalid_instruction;
......@@ -20064,16 +20584,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2006420584static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
2006520585 IrInstructionContainerInitFields *instruction)
2006620586{
20067 IrInstruction *container_type_value = instruction->container_type->child;
20068 ZigType *container_type = ir_resolve_type(ira, container_type_value);
20069 if (type_is_invalid(container_type))
20070 return ira->codegen->invalid_instruction;
20071
2007220587 ir_assert(instruction->result_loc != nullptr, &instruction->base);
2007320588 IrInstruction *result_loc = instruction->result_loc->child;
2007420589 if (type_is_invalid(result_loc->value.type))
2007520590 return result_loc;
2007620591
20592 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base);
20593 ZigType *container_type = result_loc->value.type->data.pointer.child_type;
20594
2007720595 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
2007820596 instruction->field_count, instruction->fields, result_loc);
2007920597}
......@@ -20472,17 +20990,17 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2047220990 declaration_val->special = ConstValSpecialStatic;
2047320991 declaration_val->type = type_info_declaration_type;
2047420992
20475 ConstExprValue *inner_fields = create_const_vals(3);
20993 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
2047620994 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key);
20477 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(curr_entry->key), true);
20478 inner_fields[1].special = ConstValSpecialStatic;
20479 inner_fields[1].type = ira->codegen->builtin_types.entry_bool;
20480 inner_fields[1].data.x_bool = curr_entry->value->visib_mod == VisibModPub;
20481 inner_fields[2].special = ConstValSpecialStatic;
20482 inner_fields[2].type = type_info_declaration_data_type;
20483 inner_fields[2].parent.id = ConstParentIdStruct;
20484 inner_fields[2].parent.data.p_struct.struct_val = declaration_val;
20485 inner_fields[2].parent.data.p_struct.field_index = 1;
20995 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
20996 inner_fields[1]->special = ConstValSpecialStatic;
20997 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
20998 inner_fields[1]->data.x_bool = curr_entry->value->visib_mod == VisibModPub;
20999 inner_fields[2]->special = ConstValSpecialStatic;
21000 inner_fields[2]->type = type_info_declaration_data_type;
21001 inner_fields[2]->parent.id = ConstParentIdStruct;
21002 inner_fields[2]->parent.data.p_struct.struct_val = declaration_val;
21003 inner_fields[2]->parent.data.p_struct.field_index = 1;
2048621004
2048721005 switch (curr_entry->value->id) {
2048821006 case TldIdVar:
......@@ -20494,19 +21012,19 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2049421012 if (var->const_value->type->id == ZigTypeIdMetaType) {
2049521013 // We have a variable of type 'type', so it's actually a type declaration.
2049621014 // 0: Data.Type: type
20497 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);
20498 inner_fields[2].data.x_union.payload = var->const_value;
21015 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
21016 inner_fields[2]->data.x_union.payload = var->const_value;
2049921017 } else {
2050021018 // We have a variable of another type, so we store the type of the variable.
2050121019 // 1: Data.Var: type
20502 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 1);
21020 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
2050321021
2050421022 ConstExprValue *payload = create_const_vals(1);
2050521023 payload->special = ConstValSpecialStatic;
2050621024 payload->type = ira->codegen->builtin_types.entry_type;
2050721025 payload->data.x_type = var->const_value->type;
2050821026
20509 inner_fields[2].data.x_union.payload = payload;
21027 inner_fields[2]->data.x_union.payload = payload;
2051021028 }
2051121029
2051221030 break;
......@@ -20514,7 +21032,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2051421032 case TldIdFn:
2051521033 {
2051621034 // 2: Data.Fn: Data.FnDecl
20517 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2);
21035 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 2);
2051821036
2051921037 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
2052021038 assert(!fn_entry->is_test);
......@@ -20530,63 +21048,63 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2053021048 fn_decl_val->special = ConstValSpecialStatic;
2053121049 fn_decl_val->type = type_info_fn_decl_type;
2053221050 fn_decl_val->parent.id = ConstParentIdUnion;
20533 fn_decl_val->parent.data.p_union.union_val = &inner_fields[2];
21051 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
2053421052
20535 ConstExprValue *fn_decl_fields = create_const_vals(9);
21053 ConstExprValue **fn_decl_fields = alloc_const_vals_ptrs(9);
2053621054 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2053721055
2053821056 // fn_type: type
2053921057 ensure_field_index(fn_decl_val->type, "fn_type", 0);
20540 fn_decl_fields[0].special = ConstValSpecialStatic;
20541 fn_decl_fields[0].type = ira->codegen->builtin_types.entry_type;
20542 fn_decl_fields[0].data.x_type = fn_entry->type_entry;
21058 fn_decl_fields[0]->special = ConstValSpecialStatic;
21059 fn_decl_fields[0]->type = ira->codegen->builtin_types.entry_type;
21060 fn_decl_fields[0]->data.x_type = fn_entry->type_entry;
2054321061 // inline_type: Data.FnDecl.Inline
2054421062 ensure_field_index(fn_decl_val->type, "inline_type", 1);
20545 fn_decl_fields[1].special = ConstValSpecialStatic;
20546 fn_decl_fields[1].type = type_info_fn_decl_inline_type;
20547 bigint_init_unsigned(&fn_decl_fields[1].data.x_enum_tag, fn_entry->fn_inline);
21063 fn_decl_fields[1]->special = ConstValSpecialStatic;
21064 fn_decl_fields[1]->type = type_info_fn_decl_inline_type;
21065 bigint_init_unsigned(&fn_decl_fields[1]->data.x_enum_tag, fn_entry->fn_inline);
2054821066 // calling_convention: TypeInfo.CallingConvention
2054921067 ensure_field_index(fn_decl_val->type, "calling_convention", 2);
20550 fn_decl_fields[2].special = ConstValSpecialStatic;
20551 fn_decl_fields[2].type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
20552 bigint_init_unsigned(&fn_decl_fields[2].data.x_enum_tag, fn_node->cc);
21068 fn_decl_fields[2]->special = ConstValSpecialStatic;
21069 fn_decl_fields[2]->type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
21070 bigint_init_unsigned(&fn_decl_fields[2]->data.x_enum_tag, fn_node->cc);
2055321071 // is_var_args: bool
2055421072 ensure_field_index(fn_decl_val->type, "is_var_args", 3);
2055521073 bool is_varargs = fn_node->is_var_args;
20556 fn_decl_fields[3].special = ConstValSpecialStatic;
20557 fn_decl_fields[3].type = ira->codegen->builtin_types.entry_bool;
20558 fn_decl_fields[3].data.x_bool = is_varargs;
21074 fn_decl_fields[3]->special = ConstValSpecialStatic;
21075 fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool;
21076 fn_decl_fields[3]->data.x_bool = is_varargs;
2055921077 // is_extern: bool
2056021078 ensure_field_index(fn_decl_val->type, "is_extern", 4);
20561 fn_decl_fields[4].special = ConstValSpecialStatic;
20562 fn_decl_fields[4].type = ira->codegen->builtin_types.entry_bool;
20563 fn_decl_fields[4].data.x_bool = fn_node->is_extern;
21079 fn_decl_fields[4]->special = ConstValSpecialStatic;
21080 fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool;
21081 fn_decl_fields[4]->data.x_bool = fn_node->is_extern;
2056421082 // is_export: bool
2056521083 ensure_field_index(fn_decl_val->type, "is_export", 5);
20566 fn_decl_fields[5].special = ConstValSpecialStatic;
20567 fn_decl_fields[5].type = ira->codegen->builtin_types.entry_bool;
20568 fn_decl_fields[5].data.x_bool = fn_node->is_export;
21084 fn_decl_fields[5]->special = ConstValSpecialStatic;
21085 fn_decl_fields[5]->type = ira->codegen->builtin_types.entry_bool;
21086 fn_decl_fields[5]->data.x_bool = fn_node->is_export;
2056921087 // lib_name: ?[]const u8
2057021088 ensure_field_index(fn_decl_val->type, "lib_name", 6);
20571 fn_decl_fields[6].special = ConstValSpecialStatic;
21089 fn_decl_fields[6]->special = ConstValSpecialStatic;
2057221090 ZigType *u8_ptr = get_pointer_to_type_extra(
2057321091 ira->codegen, ira->codegen->builtin_types.entry_u8,
2057421092 true, false, PtrLenUnknown,
2057521093 0, 0, 0, false);
20576 fn_decl_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
21094 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
2057721095 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
20578 fn_decl_fields[6].data.x_optional = create_const_vals(1);
21096 fn_decl_fields[6]->data.x_optional = create_const_vals(1);
2057921097 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
20580 init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0,
21098 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
2058121099 buf_len(fn_node->lib_name), true);
2058221100 } else {
20583 fn_decl_fields[6].data.x_optional = nullptr;
21101 fn_decl_fields[6]->data.x_optional = nullptr;
2058421102 }
2058521103 // return_type: type
2058621104 ensure_field_index(fn_decl_val->type, "return_type", 7);
20587 fn_decl_fields[7].special = ConstValSpecialStatic;
20588 fn_decl_fields[7].type = ira->codegen->builtin_types.entry_type;
20589 fn_decl_fields[7].data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
21105 fn_decl_fields[7]->special = ConstValSpecialStatic;
21106 fn_decl_fields[7]->type = ira->codegen->builtin_types.entry_type;
21107 fn_decl_fields[7]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
2059021108 // arg_names: [][] const u8
2059121109 ensure_field_index(fn_decl_val->type, "arg_names", 8);
2059221110 size_t fn_arg_count = fn_entry->variable_list.length;
......@@ -20597,7 +21115,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2059721115 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
2059821116 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
2059921117
20600 init_const_slice(ira->codegen, &fn_decl_fields[8], fn_arg_name_array, 0, fn_arg_count, false);
21118 init_const_slice(ira->codegen, fn_decl_fields[8], fn_arg_name_array, 0, fn_arg_count, false);
2060121119
2060221120 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2060321121 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
......@@ -20610,7 +21128,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2061021128 fn_arg_name_val->parent.data.p_array.elem_index = fn_arg_index;
2061121129 }
2061221130
20613 inner_fields[2].data.x_union.payload = fn_decl_val;
21131 inner_fields[2]->data.x_union.payload = fn_decl_val;
2061421132 break;
2061521133 }
2061621134 case TldIdContainer:
......@@ -20620,14 +21138,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2062021138 return ErrorSemanticAnalyzeFail;
2062121139
2062221140 // This is a type.
20623 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);
21141 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
2062421142
2062521143 ConstExprValue *payload = create_const_vals(1);
2062621144 payload->special = ConstValSpecialStatic;
2062721145 payload->type = ira->codegen->builtin_types.entry_type;
2062821146 payload->data.x_type = type_entry;
2062921147
20630 inner_fields[2].data.x_union.payload = payload;
21148 inner_fields[2]->data.x_union.payload = payload;
2063121149
2063221150 break;
2063321151 }
......@@ -20636,7 +21154,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2063621154 }
2063721155
2063821156 declaration_val->data.x_struct.fields = inner_fields;
20639 declaration_index++;
21157 declaration_index += 1;
2064021158 }
2064121159
2064221160 assert(declaration_index == declaration_count);
......@@ -20673,7 +21191,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
2067321191 ZigType *attrs_type;
2067421192 BuiltinPtrSize size_enum_index;
2067521193 if (is_slice(ptr_type_entry)) {
20676 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
21194 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index]->type_entry;
2067721195 size_enum_index = BuiltinPtrSizeSlice;
2067821196 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
2067921197 attrs_type = ptr_type_entry;
......@@ -20692,42 +21210,42 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
2069221210 result->special = ConstValSpecialStatic;
2069321211 result->type = type_info_pointer_type;
2069421212
20695 ConstExprValue *fields = create_const_vals(6);
21213 ConstExprValue **fields = alloc_const_vals_ptrs(6);
2069621214 result->data.x_struct.fields = fields;
2069721215
2069821216 // size: Size
2069921217 ensure_field_index(result->type, "size", 0);
2070021218 ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
2070121219 assertNoError(type_resolve(ira->codegen, type_info_pointer_size_type, ResolveStatusSizeKnown));
20702 fields[0].special = ConstValSpecialStatic;
20703 fields[0].type = type_info_pointer_size_type;
20704 bigint_init_unsigned(&fields[0].data.x_enum_tag, size_enum_index);
21220 fields[0]->special = ConstValSpecialStatic;
21221 fields[0]->type = type_info_pointer_size_type;
21222 bigint_init_unsigned(&fields[0]->data.x_enum_tag, size_enum_index);
2070521223
2070621224 // is_const: bool
2070721225 ensure_field_index(result->type, "is_const", 1);
20708 fields[1].special = ConstValSpecialStatic;
20709 fields[1].type = ira->codegen->builtin_types.entry_bool;
20710 fields[1].data.x_bool = attrs_type->data.pointer.is_const;
21226 fields[1]->special = ConstValSpecialStatic;
21227 fields[1]->type = ira->codegen->builtin_types.entry_bool;
21228 fields[1]->data.x_bool = attrs_type->data.pointer.is_const;
2071121229 // is_volatile: bool
2071221230 ensure_field_index(result->type, "is_volatile", 2);
20713 fields[2].special = ConstValSpecialStatic;
20714 fields[2].type = ira->codegen->builtin_types.entry_bool;
20715 fields[2].data.x_bool = attrs_type->data.pointer.is_volatile;
21231 fields[2]->special = ConstValSpecialStatic;
21232 fields[2]->type = ira->codegen->builtin_types.entry_bool;
21233 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;
2071621234 // alignment: u32
2071721235 ensure_field_index(result->type, "alignment", 3);
20718 fields[3].special = ConstValSpecialStatic;
20719 fields[3].type = ira->codegen->builtin_types.entry_num_lit_int;
20720 bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type));
21236 fields[3]->special = ConstValSpecialStatic;
21237 fields[3]->type = ira->codegen->builtin_types.entry_num_lit_int;
21238 bigint_init_unsigned(&fields[3]->data.x_bigint, get_ptr_align(ira->codegen, attrs_type));
2072121239 // child: type
2072221240 ensure_field_index(result->type, "child", 4);
20723 fields[4].special = ConstValSpecialStatic;
20724 fields[4].type = ira->codegen->builtin_types.entry_type;
20725 fields[4].data.x_type = attrs_type->data.pointer.child_type;
21241 fields[4]->special = ConstValSpecialStatic;
21242 fields[4]->type = ira->codegen->builtin_types.entry_type;
21243 fields[4]->data.x_type = attrs_type->data.pointer.child_type;
2072621244 // is_allowzero: bool
2072721245 ensure_field_index(result->type, "is_allowzero", 5);
20728 fields[5].special = ConstValSpecialStatic;
20729 fields[5].type = ira->codegen->builtin_types.entry_bool;
20730 fields[5].data.x_bool = attrs_type->data.pointer.allow_zero;
21246 fields[5]->special = ConstValSpecialStatic;
21247 fields[5]->type = ira->codegen->builtin_types.entry_bool;
21248 fields[5]->data.x_bool = attrs_type->data.pointer.allow_zero;
2073121249
2073221250 return result;
2073321251};
......@@ -20738,14 +21256,14 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
2073821256 enum_field_val->special = ConstValSpecialStatic;
2073921257 enum_field_val->type = type_info_enum_field_type;
2074021258
20741 ConstExprValue *inner_fields = create_const_vals(2);
20742 inner_fields[1].special = ConstValSpecialStatic;
20743 inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
21259 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);
21260 inner_fields[1]->special = ConstValSpecialStatic;
21261 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2074421262
2074521263 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);
20746 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true);
21264 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2074721265
20748 bigint_init_bigint(&inner_fields[1].data.x_bigint, &enum_field->value);
21266 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);
2074921267
2075021268 enum_field_val->data.x_struct.fields = inner_fields;
2075121269}
......@@ -20789,19 +21307,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2078921307 result->special = ConstValSpecialStatic;
2079021308 result->type = ir_type_info_get_type(ira, "Int", nullptr);
2079121309
20792 ConstExprValue *fields = create_const_vals(2);
21310 ConstExprValue **fields = alloc_const_vals_ptrs(2);
2079321311 result->data.x_struct.fields = fields;
2079421312
2079521313 // is_signed: bool
2079621314 ensure_field_index(result->type, "is_signed", 0);
20797 fields[0].special = ConstValSpecialStatic;
20798 fields[0].type = ira->codegen->builtin_types.entry_bool;
20799 fields[0].data.x_bool = type_entry->data.integral.is_signed;
21315 fields[0]->special = ConstValSpecialStatic;
21316 fields[0]->type = ira->codegen->builtin_types.entry_bool;
21317 fields[0]->data.x_bool = type_entry->data.integral.is_signed;
2080021318 // bits: u8
2080121319 ensure_field_index(result->type, "bits", 1);
20802 fields[1].special = ConstValSpecialStatic;
20803 fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
20804 bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count);
21320 fields[1]->special = ConstValSpecialStatic;
21321 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
21322 bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count);
2080521323
2080621324 break;
2080721325 }
......@@ -20811,14 +21329,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2081121329 result->special = ConstValSpecialStatic;
2081221330 result->type = ir_type_info_get_type(ira, "Float", nullptr);
2081321331
20814 ConstExprValue *fields = create_const_vals(1);
21332 ConstExprValue **fields = alloc_const_vals_ptrs(1);
2081521333 result->data.x_struct.fields = fields;
2081621334
2081721335 // bits: u8
2081821336 ensure_field_index(result->type, "bits", 0);
20819 fields[0].special = ConstValSpecialStatic;
20820 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
20821 bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count);
21337 fields[0]->special = ConstValSpecialStatic;
21338 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;
21339 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count);
2082221340
2082321341 break;
2082421342 }
......@@ -20835,19 +21353,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2083521353 result->special = ConstValSpecialStatic;
2083621354 result->type = ir_type_info_get_type(ira, "Array", nullptr);
2083721355
20838 ConstExprValue *fields = create_const_vals(2);
21356 ConstExprValue **fields = alloc_const_vals_ptrs(2);
2083921357 result->data.x_struct.fields = fields;
2084021358
2084121359 // len: usize
2084221360 ensure_field_index(result->type, "len", 0);
20843 fields[0].special = ConstValSpecialStatic;
20844 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
20845 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len);
21361 fields[0]->special = ConstValSpecialStatic;
21362 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;
21363 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len);
2084621364 // child: type
2084721365 ensure_field_index(result->type, "child", 1);
20848 fields[1].special = ConstValSpecialStatic;
20849 fields[1].type = ira->codegen->builtin_types.entry_type;
20850 fields[1].data.x_type = type_entry->data.array.child_type;
21366 fields[1]->special = ConstValSpecialStatic;
21367 fields[1]->type = ira->codegen->builtin_types.entry_type;
21368 fields[1]->data.x_type = type_entry->data.array.child_type;
2085121369
2085221370 break;
2085321371 }
......@@ -20856,19 +21374,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2085621374 result->special = ConstValSpecialStatic;
2085721375 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
2085821376
20859 ConstExprValue *fields = create_const_vals(2);
21377 ConstExprValue **fields = alloc_const_vals_ptrs(2);
2086021378 result->data.x_struct.fields = fields;
2086121379
2086221380 // len: usize
2086321381 ensure_field_index(result->type, "len", 0);
20864 fields[0].special = ConstValSpecialStatic;
20865 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
20866 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.vector.len);
21382 fields[0]->special = ConstValSpecialStatic;
21383 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;
21384 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len);
2086721385 // child: type
2086821386 ensure_field_index(result->type, "child", 1);
20869 fields[1].special = ConstValSpecialStatic;
20870 fields[1].type = ira->codegen->builtin_types.entry_type;
20871 fields[1].data.x_type = type_entry->data.vector.elem_type;
21387 fields[1]->special = ConstValSpecialStatic;
21388 fields[1]->type = ira->codegen->builtin_types.entry_type;
21389 fields[1]->data.x_type = type_entry->data.vector.elem_type;
2087221390
2087321391 break;
2087421392 }
......@@ -20878,14 +21396,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2087821396 result->special = ConstValSpecialStatic;
2087921397 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
2088021398
20881 ConstExprValue *fields = create_const_vals(1);
21399 ConstExprValue **fields = alloc_const_vals_ptrs(1);
2088221400 result->data.x_struct.fields = fields;
2088321401
2088421402 // child: type
2088521403 ensure_field_index(result->type, "child", 0);
20886 fields[0].special = ConstValSpecialStatic;
20887 fields[0].type = ira->codegen->builtin_types.entry_type;
20888 fields[0].data.x_type = type_entry->data.maybe.child_type;
21404 fields[0]->special = ConstValSpecialStatic;
21405 fields[0]->type = ira->codegen->builtin_types.entry_type;
21406 fields[0]->data.x_type = type_entry->data.maybe.child_type;
2088921407
2089021408 break;
2089121409 }
......@@ -20894,14 +21412,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2089421412 result->special = ConstValSpecialStatic;
2089521413 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
2089621414
20897 ConstExprValue *fields = create_const_vals(1);
21415 ConstExprValue **fields = alloc_const_vals_ptrs(1);
2089821416 result->data.x_struct.fields = fields;
2089921417
2090021418 // child: ?type
2090121419 ensure_field_index(result->type, "child", 0);
20902 fields[0].special = ConstValSpecialStatic;
20903 fields[0].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
20904 fields[0].data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr :
21420 fields[0]->special = ConstValSpecialStatic;
21421 fields[0]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21422 fields[0]->data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr :
2090521423 create_const_type(ira->codegen, type_entry->data.any_frame.result_type);
2090621424 break;
2090721425 }
......@@ -20911,19 +21429,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2091121429 result->special = ConstValSpecialStatic;
2091221430 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2091321431
20914 ConstExprValue *fields = create_const_vals(4);
21432 ConstExprValue **fields = alloc_const_vals_ptrs(4);
2091521433 result->data.x_struct.fields = fields;
2091621434
2091721435 // layout: ContainerLayout
2091821436 ensure_field_index(result->type, "layout", 0);
20919 fields[0].special = ConstValSpecialStatic;
20920 fields[0].type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
20921 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.enumeration.layout);
21437 fields[0]->special = ConstValSpecialStatic;
21438 fields[0]->type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21439 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.enumeration.layout);
2092221440 // tag_type: type
2092321441 ensure_field_index(result->type, "tag_type", 1);
20924 fields[1].special = ConstValSpecialStatic;
20925 fields[1].type = ira->codegen->builtin_types.entry_type;
20926 fields[1].data.x_type = type_entry->data.enumeration.tag_int_type;
21442 fields[1]->special = ConstValSpecialStatic;
21443 fields[1]->type = ira->codegen->builtin_types.entry_type;
21444 fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type;
2092721445 // fields: []TypeInfo.EnumField
2092821446 ensure_field_index(result->type, "fields", 2);
2092921447
......@@ -20939,7 +21457,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2093921457 enum_field_array->data.x_array.special = ConstArraySpecialNone;
2094021458 enum_field_array->data.x_array.data.s_none.elements = create_const_vals(enum_field_count);
2094121459
20942 init_const_slice(ira->codegen, &fields[2], enum_field_array, 0, enum_field_count, false);
21460 init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false);
2094321461
2094421462 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
2094521463 {
......@@ -20952,7 +21470,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2095221470 }
2095321471 // decls: []TypeInfo.Declaration
2095421472 ensure_field_index(result->type, "decls", 3);
20955 if ((err = ir_make_type_info_decls(ira, source_instr, &fields[3],
21473 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
2095621474 type_entry->data.enumeration.decls_scope)))
2095721475 {
2095821476 return err;
......@@ -20995,17 +21513,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2099521513 error_val->special = ConstValSpecialStatic;
2099621514 error_val->type = type_info_error_type;
2099721515
20998 ConstExprValue *inner_fields = create_const_vals(2);
20999 inner_fields[1].special = ConstValSpecialStatic;
21000 inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
21516 ConstExprValue **inner_fields = alloc_const_vals_ptrs(2);
21517 inner_fields[1]->special = ConstValSpecialStatic;
21518 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2100121519
2100221520 ConstExprValue *name = nullptr;
2100321521 if (error->cached_error_name_val != nullptr)
2100421522 name = error->cached_error_name_val;
2100521523 if (name == nullptr)
2100621524 name = create_const_str_lit(ira->codegen, &error->name);
21007 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(&error->name), true);
21008 bigint_init_unsigned(&inner_fields[1].data.x_bigint, error->value);
21525 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true);
21526 bigint_init_unsigned(&inner_fields[1]->data.x_bigint, error->value);
2100921527
2101021528 error_val->data.x_struct.fields = inner_fields;
2101121529 error_val->parent.id = ConstParentIdArray;
......@@ -21021,20 +21539,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2102121539 result->special = ConstValSpecialStatic;
2102221540 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
2102321541
21024 ConstExprValue *fields = create_const_vals(2);
21542 ConstExprValue **fields = alloc_const_vals_ptrs(2);
2102521543 result->data.x_struct.fields = fields;
2102621544
2102721545 // error_set: type
2102821546 ensure_field_index(result->type, "error_set", 0);
21029 fields[0].special = ConstValSpecialStatic;
21030 fields[0].type = ira->codegen->builtin_types.entry_type;
21031 fields[0].data.x_type = type_entry->data.error_union.err_set_type;
21547 fields[0]->special = ConstValSpecialStatic;
21548 fields[0]->type = ira->codegen->builtin_types.entry_type;
21549 fields[0]->data.x_type = type_entry->data.error_union.err_set_type;
2103221550
2103321551 // payload: type
2103421552 ensure_field_index(result->type, "payload", 1);
21035 fields[1].special = ConstValSpecialStatic;
21036 fields[1].type = ira->codegen->builtin_types.entry_type;
21037 fields[1].data.x_type = type_entry->data.error_union.payload_type;
21553 fields[1]->special = ConstValSpecialStatic;
21554 fields[1]->type = ira->codegen->builtin_types.entry_type;
21555 fields[1]->data.x_type = type_entry->data.error_union.payload_type;
2103821556
2103921557 break;
2104021558 }
......@@ -21044,18 +21562,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2104421562 result->special = ConstValSpecialStatic;
2104521563 result->type = ir_type_info_get_type(ira, "Union", nullptr);
2104621564
21047 ConstExprValue *fields = create_const_vals(4);
21565 ConstExprValue **fields = alloc_const_vals_ptrs(4);
2104821566 result->data.x_struct.fields = fields;
2104921567
2105021568 // layout: ContainerLayout
2105121569 ensure_field_index(result->type, "layout", 0);
21052 fields[0].special = ConstValSpecialStatic;
21053 fields[0].type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21054 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.unionation.layout);
21570 fields[0]->special = ConstValSpecialStatic;
21571 fields[0]->type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21572 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.unionation.layout);
2105521573 // tag_type: ?type
2105621574 ensure_field_index(result->type, "tag_type", 1);
21057 fields[1].special = ConstValSpecialStatic;
21058 fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21575 fields[1]->special = ConstValSpecialStatic;
21576 fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
2105921577
2106021578 AstNode *union_decl_node = type_entry->data.unionation.decl_node;
2106121579 if (union_decl_node->data.container_decl.auto_enum ||
......@@ -21065,9 +21583,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2106521583 tag_type->special = ConstValSpecialStatic;
2106621584 tag_type->type = ira->codegen->builtin_types.entry_type;
2106721585 tag_type->data.x_type = type_entry->data.unionation.tag_type;
21068 fields[1].data.x_optional = tag_type;
21586 fields[1]->data.x_optional = tag_type;
2106921587 } else {
21070 fields[1].data.x_optional = nullptr;
21588 fields[1]->data.x_optional = nullptr;
2107121589 }
2107221590 // fields: []TypeInfo.UnionField
2107321591 ensure_field_index(result->type, "fields", 2);
......@@ -21083,7 +21601,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2108321601 union_field_array->data.x_array.special = ConstArraySpecialNone;
2108421602 union_field_array->data.x_array.data.s_none.elements = create_const_vals(union_field_count);
2108521603
21086 init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false);
21604 init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false);
2108721605
2108821606 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
2108921607
......@@ -21094,23 +21612,23 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2109421612 union_field_val->special = ConstValSpecialStatic;
2109521613 union_field_val->type = type_info_union_field_type;
2109621614
21097 ConstExprValue *inner_fields = create_const_vals(3);
21098 inner_fields[1].special = ConstValSpecialStatic;
21099 inner_fields[1].type = get_optional_type(ira->codegen, type_info_enum_field_type);
21615 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21616 inner_fields[1]->special = ConstValSpecialStatic;
21617 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2110021618
21101 if (fields[1].data.x_optional == nullptr) {
21102 inner_fields[1].data.x_optional = nullptr;
21619 if (fields[1]->data.x_optional == nullptr) {
21620 inner_fields[1]->data.x_optional = nullptr;
2110321621 } else {
21104 inner_fields[1].data.x_optional = create_const_vals(1);
21105 make_enum_field_val(ira, inner_fields[1].data.x_optional, union_field->enum_field, type_info_enum_field_type);
21622 inner_fields[1]->data.x_optional = create_const_vals(1);
21623 make_enum_field_val(ira, inner_fields[1]->data.x_optional, union_field->enum_field, type_info_enum_field_type);
2110621624 }
2110721625
21108 inner_fields[2].special = ConstValSpecialStatic;
21109 inner_fields[2].type = ira->codegen->builtin_types.entry_type;
21110 inner_fields[2].data.x_type = union_field->type_entry;
21626 inner_fields[2]->special = ConstValSpecialStatic;
21627 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
21628 inner_fields[2]->data.x_type = union_field->type_entry;
2111121629
2111221630 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name);
21113 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(union_field->name), true);
21631 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2111421632
2111521633 union_field_val->data.x_struct.fields = inner_fields;
2111621634 union_field_val->parent.id = ConstParentIdArray;
......@@ -21119,7 +21637,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2111921637 }
2112021638 // decls: []TypeInfo.Declaration
2112121639 ensure_field_index(result->type, "decls", 3);
21122 if ((err = ir_make_type_info_decls(ira, source_instr, &fields[3],
21640 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
2112321641 type_entry->data.unionation.decls_scope)))
2112421642 {
2112521643 return err;
......@@ -21140,14 +21658,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2114021658 result->special = ConstValSpecialStatic;
2114121659 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
2114221660
21143 ConstExprValue *fields = create_const_vals(3);
21661 ConstExprValue **fields = alloc_const_vals_ptrs(3);
2114421662 result->data.x_struct.fields = fields;
2114521663
2114621664 // layout: ContainerLayout
2114721665 ensure_field_index(result->type, "layout", 0);
21148 fields[0].special = ConstValSpecialStatic;
21149 fields[0].type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21150 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.structure.layout);
21666 fields[0]->special = ConstValSpecialStatic;
21667 fields[0]->type = ir_type_info_get_type(ira, "ContainerLayout", nullptr);
21668 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.structure.layout);
2115121669 // fields: []TypeInfo.StructField
2115221670 ensure_field_index(result->type, "fields", 1);
2115321671
......@@ -21163,18 +21681,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2116321681 struct_field_array->data.x_array.special = ConstArraySpecialNone;
2116421682 struct_field_array->data.x_array.data.s_none.elements = create_const_vals(struct_field_count);
2116521683
21166 init_const_slice(ira->codegen, &fields[1], struct_field_array, 0, struct_field_count, false);
21684 init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false);
2116721685
2116821686 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
21169 TypeStructField *struct_field = &type_entry->data.structure.fields[struct_field_index];
21687 TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index];
2117021688 ConstExprValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index];
2117121689
2117221690 struct_field_val->special = ConstValSpecialStatic;
2117321691 struct_field_val->type = type_info_struct_field_type;
2117421692
21175 ConstExprValue *inner_fields = create_const_vals(3);
21176 inner_fields[1].special = ConstValSpecialStatic;
21177 inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
21693 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21694 inner_fields[1]->special = ConstValSpecialStatic;
21695 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
2117821696
2117921697 ZigType *field_type = resolve_struct_field_type(ira->codegen, struct_field);
2118021698 if (field_type == nullptr)
......@@ -21182,21 +21700,21 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2118221700 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
2118321701 return err;
2118421702 if (!type_has_bits(struct_field->type_entry)) {
21185 inner_fields[1].data.x_optional = nullptr;
21703 inner_fields[1]->data.x_optional = nullptr;
2118621704 } else {
2118721705 size_t byte_offset = struct_field->offset;
21188 inner_fields[1].data.x_optional = create_const_vals(1);
21189 inner_fields[1].data.x_optional->special = ConstValSpecialStatic;
21190 inner_fields[1].data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
21191 bigint_init_unsigned(&inner_fields[1].data.x_optional->data.x_bigint, byte_offset);
21706 inner_fields[1]->data.x_optional = create_const_vals(1);
21707 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;
21708 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
21709 bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset);
2119221710 }
2119321711
21194 inner_fields[2].special = ConstValSpecialStatic;
21195 inner_fields[2].type = ira->codegen->builtin_types.entry_type;
21196 inner_fields[2].data.x_type = struct_field->type_entry;
21712 inner_fields[2]->special = ConstValSpecialStatic;
21713 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
21714 inner_fields[2]->data.x_type = struct_field->type_entry;
2119721715
2119821716 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name);
21199 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(struct_field->name), true);
21717 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2120021718
2120121719 struct_field_val->data.x_struct.fields = inner_fields;
2120221720 struct_field_val->parent.id = ConstParentIdArray;
......@@ -21205,7 +21723,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2120521723 }
2120621724 // decls: []TypeInfo.Declaration
2120721725 ensure_field_index(result->type, "decls", 2);
21208 if ((err = ir_make_type_info_decls(ira, source_instr, &fields[2],
21726 if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],
2120921727 type_entry->data.structure.decls_scope)))
2121021728 {
2121121729 return err;
......@@ -21219,38 +21737,38 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2121921737 result->special = ConstValSpecialStatic;
2122021738 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2122121739
21222 ConstExprValue *fields = create_const_vals(5);
21740 ConstExprValue **fields = alloc_const_vals_ptrs(5);
2122321741 result->data.x_struct.fields = fields;
2122421742
2122521743 // calling_convention: TypeInfo.CallingConvention
2122621744 ensure_field_index(result->type, "calling_convention", 0);
21227 fields[0].special = ConstValSpecialStatic;
21228 fields[0].type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
21229 bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
21745 fields[0]->special = ConstValSpecialStatic;
21746 fields[0]->type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
21747 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
2123021748 // is_generic: bool
2123121749 ensure_field_index(result->type, "is_generic", 1);
2123221750 bool is_generic = type_entry->data.fn.is_generic;
21233 fields[1].special = ConstValSpecialStatic;
21234 fields[1].type = ira->codegen->builtin_types.entry_bool;
21235 fields[1].data.x_bool = is_generic;
21751 fields[1]->special = ConstValSpecialStatic;
21752 fields[1]->type = ira->codegen->builtin_types.entry_bool;
21753 fields[1]->data.x_bool = is_generic;
2123621754 // is_varargs: bool
2123721755 ensure_field_index(result->type, "is_var_args", 2);
2123821756 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
21239 fields[2].special = ConstValSpecialStatic;
21240 fields[2].type = ira->codegen->builtin_types.entry_bool;
21241 fields[2].data.x_bool = type_entry->data.fn.fn_type_id.is_var_args;
21757 fields[2]->special = ConstValSpecialStatic;
21758 fields[2]->type = ira->codegen->builtin_types.entry_bool;
21759 fields[2]->data.x_bool = type_entry->data.fn.fn_type_id.is_var_args;
2124221760 // return_type: ?type
2124321761 ensure_field_index(result->type, "return_type", 3);
21244 fields[3].special = ConstValSpecialStatic;
21245 fields[3].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21762 fields[3]->special = ConstValSpecialStatic;
21763 fields[3]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
2124621764 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
21247 fields[3].data.x_optional = nullptr;
21765 fields[3]->data.x_optional = nullptr;
2124821766 else {
2124921767 ConstExprValue *return_type = create_const_vals(1);
2125021768 return_type->special = ConstValSpecialStatic;
2125121769 return_type->type = ira->codegen->builtin_types.entry_type;
2125221770 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
21253 fields[3].data.x_optional = return_type;
21771 fields[3]->data.x_optional = return_type;
2125421772 }
2125521773 // args: []TypeInfo.FnArg
2125621774 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
......@@ -21266,7 +21784,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2126621784 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
2126721785 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
2126821786
21269 init_const_slice(ira->codegen, &fields[4], fn_arg_array, 0, fn_arg_count, false);
21787 init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false);
2127021788
2127121789 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2127221790 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
......@@ -21278,24 +21796,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2127821796 bool arg_is_generic = fn_param_info->type == nullptr;
2127921797 if (arg_is_generic) assert(is_generic);
2128021798
21281 ConstExprValue *inner_fields = create_const_vals(3);
21282 inner_fields[0].special = ConstValSpecialStatic;
21283 inner_fields[0].type = ira->codegen->builtin_types.entry_bool;
21284 inner_fields[0].data.x_bool = arg_is_generic;
21285 inner_fields[1].special = ConstValSpecialStatic;
21286 inner_fields[1].type = ira->codegen->builtin_types.entry_bool;
21287 inner_fields[1].data.x_bool = fn_param_info->is_noalias;
21288 inner_fields[2].special = ConstValSpecialStatic;
21289 inner_fields[2].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21799 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21800 inner_fields[0]->special = ConstValSpecialStatic;
21801 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
21802 inner_fields[0]->data.x_bool = arg_is_generic;
21803 inner_fields[1]->special = ConstValSpecialStatic;
21804 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
21805 inner_fields[1]->data.x_bool = fn_param_info->is_noalias;
21806 inner_fields[2]->special = ConstValSpecialStatic;
21807 inner_fields[2]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
2129021808
2129121809 if (arg_is_generic)
21292 inner_fields[2].data.x_optional = nullptr;
21810 inner_fields[2]->data.x_optional = nullptr;
2129321811 else {
2129421812 ConstExprValue *arg_type = create_const_vals(1);
2129521813 arg_type->special = ConstValSpecialStatic;
2129621814 arg_type->type = ira->codegen->builtin_types.entry_type;
2129721815 arg_type->data.x_type = fn_param_info->type;
21298 inner_fields[2].data.x_optional = arg_type;
21816 inner_fields[2]->data.x_optional = arg_type;
2129921817 }
2130021818
2130121819 fn_arg_val->data.x_struct.fields = inner_fields;
......@@ -21356,8 +21874,8 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2135621874static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
2135721875{
2135821876 ensure_field_index(struct_value->type, name, field_index);
21359 assert(struct_value->data.x_struct.fields[field_index].special == ConstValSpecialStatic);
21360 return &struct_value->data.x_struct.fields[field_index];
21877 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
21878 return struct_value->data.x_struct.fields[field_index];
2136121879}
2136221880
2136321881static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
......@@ -21656,15 +22174,15 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2165622174 }
2165722175 for (size_t i = 0; i < errors_len; i += 1) {
2165822176 Stage2ErrorMsg *clang_err = &errors_ptr[i];
21659 // Clang can emit "too many errors, stopping now", in which case `source` and `filename_ptr` are null
21660 if (clang_err->source && clang_err->filename_ptr) {
22177 // Clang can emit "too many errors, stopping now", in which case `source` and `filename_ptr` are null
22178 if (clang_err->source && clang_err->filename_ptr) {
2166122179 ErrorMsg *err_msg = err_msg_create_with_offset(
2166222180 clang_err->filename_ptr ?
2166322181 buf_create_from_mem(clang_err->filename_ptr, clang_err->filename_len) : buf_alloc(),
2166422182 clang_err->line, clang_err->column, clang_err->offset, clang_err->source,
2166522183 buf_create_from_mem(clang_err->msg_ptr, clang_err->msg_len));
2166622184 err_msg_add_note(parent_err_msg, err_msg);
21667 }
22185 }
2166822186 }
2166922187
2167022188 return ira->codegen->invalid_instruction;
......@@ -22122,7 +22640,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2212222640 if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align)))
2212322641 return ira->codegen->invalid_instruction;
2212422642 } else if (is_slice(target->value.type)) {
22125 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
22643 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;
2212622644 src_ptr_const = src_ptr_type->data.pointer.is_const;
2212722645 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
2212822646
......@@ -22165,7 +22683,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2216522683 if (!val)
2216622684 return ira->codegen->invalid_instruction;
2216722685
22168 ConstExprValue *len_val = &val->data.x_struct.fields[slice_len_index];
22686 ConstExprValue *len_val = val->data.x_struct.fields[slice_len_index];
2216922687 if (value_is_comptime(len_val)) {
2217022688 known_len = bigint_as_u64(&len_val->data.x_bigint);
2217122689 have_known_len = true;
......@@ -22215,7 +22733,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2221522733 return ira->codegen->invalid_instruction;
2221622734 }
2221722735
22218 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
22736 ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;
2221922737
2222022738 uint32_t alignment;
2222122739 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
......@@ -22232,17 +22750,17 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2223222750 return ira->codegen->invalid_instruction;
2223322751
2223422752 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);
22235 result->value.data.x_struct.fields = create_const_vals(2);
22753 result->value.data.x_struct.fields = alloc_const_vals_ptrs(2);
2223622754
22237 ConstExprValue *ptr_val = &result->value.data.x_struct.fields[slice_ptr_index];
22238 ConstExprValue *target_ptr_val = &target_val->data.x_struct.fields[slice_ptr_index];
22755 ConstExprValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index];
22756 ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
2223922757 copy_const_val(ptr_val, target_ptr_val, false);
2224022758 ptr_val->type = dest_ptr_type;
2224122759
22242 ConstExprValue *len_val = &result->value.data.x_struct.fields[slice_len_index];
22760 ConstExprValue *len_val = result->value.data.x_struct.fields[slice_len_index];
2224322761 len_val->special = ConstValSpecialStatic;
2224422762 len_val->type = ira->codegen->builtin_types.entry_usize;
22245 ConstExprValue *target_len_val = &target_val->data.x_struct.fields[slice_len_index];
22763 ConstExprValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];
2224622764 ZigType *elem_type = src_ptr_type->data.pointer.child_type;
2224722765 BigInt elem_size_bigint;
2224822766 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));
......@@ -23023,7 +23541,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2302323541 }
2302423542 }
2302523543 } else if (is_slice(array_type)) {
23026 ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
23544 ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
2302723545 return_type = get_slice_type(ira->codegen, ptr_type);
2302823546 } else {
2302923547 ir_add_error(ira, &instruction->base,
......@@ -23131,13 +23649,13 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2313123649 return ira->codegen->invalid_instruction;
2313223650 }
2313323651
23134 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
23652 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
2313523653 if (parent_ptr->special == ConstValSpecialUndef) {
2313623654 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
2313723655 return ira->codegen->invalid_instruction;
2313823656 }
2313923657
23140 ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];
23658 ConstExprValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
2314123659
2314223660 switch (parent_ptr->data.x_ptr.special) {
2314323661 case ConstPtrSpecialInvalid:
......@@ -23209,9 +23727,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2320923727
2321023728 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
2321123729 ConstExprValue *out_val = &result->value;
23212 out_val->data.x_struct.fields = create_const_vals(2);
23730 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2321323731
23214 ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index];
23732 ConstExprValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];
2321523733
2321623734 if (array_val) {
2321723735 size_t index = abs_offset + start_scalar;
......@@ -23258,7 +23776,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2325823776 zig_panic("TODO");
2325923777 }
2326023778
23261 ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index];
23779 ConstExprValue *len_val = out_val->data.x_struct.fields[slice_len_index];
2326223780 init_const_usize(ira->codegen, len_val, end_scalar - start_scalar);
2326323781
2326423782 return result;
......@@ -23332,7 +23850,7 @@ static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstr
2333223850 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
2333323851 return ira->codegen->invalid_instruction;
2333423852 }
23335 TypeStructField *field = &container_type->data.structure.fields[member_index];
23853 TypeStructField *field = container_type->data.structure.fields[member_index];
2333623854
2333723855 return ir_const_type(ira, &instruction->base, field->type_entry);
2333823856 } else if (container_type->id == ZigTypeIdUnion) {
......@@ -23374,7 +23892,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr
2337423892 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
2337523893 return ira->codegen->invalid_instruction;
2337623894 }
23377 TypeStructField *field = &container_type->data.structure.fields[member_index];
23895 TypeStructField *field = container_type->data.structure.fields[member_index];
2337823896
2337923897 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
2338023898 init_const_str_lit(ira->codegen, &result->value, field->name);
......@@ -24360,7 +24878,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2436024878 ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id);
2436124879 result_type = get_optional_type(ira->codegen, fn_type);
2436224880 } else if (is_slice(target_type)) {
24363 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
24881 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;
2436424882 if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes)))
2436524883 return ira->codegen->invalid_instruction;
2436624884 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
......@@ -24409,6 +24927,10 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2440924927 ZigType *src_type = ptr->value.type;
2441024928 assert(!type_is_invalid(src_type));
2441124929
24930 if (src_type == dest_type) {
24931 return ptr;
24932 }
24933
2441224934 // We have a check for zero bits later so we use get_src_ptr_type to
2441324935 // validate src_type and dest_type.
2441424936
......@@ -24458,6 +24980,9 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2445824980 IrInstruction *result;
2445924981 if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) {
2446024982 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
24983
24984 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
24985 return ira->codegen->invalid_instruction;
2446124986 } else {
2446224987 result = ir_const(ira, source_instr, dest_type);
2446324988 }
......@@ -24598,10 +25123,10 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2459825123 case ContainerLayoutExtern: {
2459925124 size_t src_field_count = val->type->data.structure.src_field_count;
2460025125 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
24601 TypeStructField *struct_field = &val->type->data.structure.fields[field_i];
25126 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
2460225127 if (struct_field->gen_index == SIZE_MAX)
2460325128 continue;
24604 ConstExprValue *field_val = &val->data.x_struct.fields[field_i];
25129 ConstExprValue *field_val = val->data.x_struct.fields[field_i];
2460525130 size_t offset = struct_field->offset;
2460625131 buf_write_value_bytes(codegen, buf + offset, field_val);
2460725132 }
......@@ -24627,12 +25152,12 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2462725152 bigint_init_unsigned(&big_int, 0);
2462825153 size_t used_bits = 0;
2462925154 while (src_i < src_field_count) {
24630 TypeStructField *field = &val->type->data.structure.fields[src_i];
25155 TypeStructField *field = val->type->data.structure.fields[src_i];
2463125156 assert(field->gen_index != SIZE_MAX);
2463225157 if (field->gen_index != gen_i)
2463325158 break;
2463425159 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);
24635 buf_write_value_bytes(codegen, child_buf, &val->data.x_struct.fields[src_i]);
25160 buf_write_value_bytes(codegen, child_buf, val->data.x_struct.fields[src_i]);
2463625161 BigInt child_val;
2463725162 bigint_read_twos_complement(&child_val, child_buf, packed_bits_size, is_big_endian,
2463825163 false);
......@@ -24770,11 +25295,11 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2477025295 }
2477125296 case ContainerLayoutExtern: {
2477225297 size_t src_field_count = val->type->data.structure.src_field_count;
24773 val->data.x_struct.fields = create_const_vals(src_field_count);
25298 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
2477425299 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
24775 ConstExprValue *field_val = &val->data.x_struct.fields[field_i];
25300 ConstExprValue *field_val = val->data.x_struct.fields[field_i];
2477625301 field_val->special = ConstValSpecialStatic;
24777 TypeStructField *struct_field = &val->type->data.structure.fields[field_i];
25302 TypeStructField *struct_field = val->type->data.structure.fields[field_i];
2477825303 field_val->type = struct_field->type_entry;
2477925304 if (struct_field->gen_index == SIZE_MAX)
2478025305 continue;
......@@ -24787,7 +25312,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2478725312 }
2478825313 case ContainerLayoutPacked: {
2478925314 size_t src_field_count = val->type->data.structure.src_field_count;
24790 val->data.x_struct.fields = create_const_vals(src_field_count);
25315 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
2479125316 size_t gen_field_count = val->type->data.structure.gen_field_count;
2479225317 size_t gen_i = 0;
2479325318 size_t src_i = 0;
......@@ -24805,11 +25330,11 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2480525330 BigInt big_int;
2480625331 bigint_read_twos_complement(&big_int, buf + offset, big_int_byte_count * 8, is_big_endian, false);
2480725332 while (src_i < src_field_count) {
24808 TypeStructField *field = &val->type->data.structure.fields[src_i];
25333 TypeStructField *field = val->type->data.structure.fields[src_i];
2480925334 src_assert(field->gen_index != SIZE_MAX, source_node);
2481025335 if (field->gen_index != gen_i)
2481125336 break;
24812 ConstExprValue *field_val = &val->data.x_struct.fields[src_i];
25337 ConstExprValue *field_val = val->data.x_struct.fields[src_i];
2481325338 field_val->special = ConstValSpecialStatic;
2481425339 field_val->type = field->type_entry;
2481525340 uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry);
......@@ -24992,6 +25517,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2499225517}
2499325518
2499425519static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
25520 Error err;
2499525521 IrInstruction *target = instruction->target->child;
2499625522 if (type_is_invalid(target->value.type))
2499725523 return ira->codegen->invalid_instruction;
......@@ -25005,6 +25531,8 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru
2500525531 return ira->codegen->invalid_instruction;
2500625532 }
2500725533
25534 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))
25535 return ira->codegen->invalid_instruction;
2500825536 if (!type_has_bits(target->value.type)) {
2500925537 ir_add_error(ira, target,
2501025538 buf_sprintf("pointer to size 0 type has no address"));
......@@ -25065,7 +25593,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
2506525593
2506625594 ZigType *elem_type = nullptr;
2506725595 if (is_slice(target->value.type)) {
25068 ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
25596 ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry;
2506925597 elem_type = slice_ptr_type->data.pointer.child_type;
2507025598 } else if (target->value.type->id == ZigTypeIdPointer) {
2507125599 elem_type = target->value.type->data.pointer.child_type;
......@@ -25142,6 +25670,10 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
2514225670 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
2514325671 return ira->codegen->invalid_instruction;
2514425672
25673 if (fn_type->id == ZigTypeIdBoundFn) {
25674 fn_type = fn_type->data.bound_fn.fn_type;
25675 arg_index += 1;
25676 }
2514525677 if (fn_type->id != ZigTypeIdFn) {
2514625678 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
2514725679 return ira->codegen->invalid_instruction;
......@@ -25149,6 +25681,10 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
2514925681
2515025682 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
2515125683 if (arg_index >= fn_type_id->param_count) {
25684 if (instruction->allow_var) {
25685 // TODO remove this with var args
25686 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);
25687 }
2515225688 ir_add_error(ira, arg_index_inst,
2515325689 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
2515425690 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
......@@ -25160,10 +25696,14 @@ static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruct
2516025696 // Args are only unresolved if our function is generic.
2516125697 ir_assert(fn_type->data.fn.is_generic, &instruction->base);
2516225698
25163 ir_add_error(ira, arg_index_inst,
25164 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
25165 arg_index, buf_ptr(&fn_type->name)));
25166 return ira->codegen->invalid_instruction;
25699 if (instruction->allow_var) {
25700 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);
25701 } else {
25702 ir_add_error(ira, arg_index_inst,
25703 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
25704 arg_index, buf_ptr(&fn_type->name)));
25705 return ira->codegen->invalid_instruction;
25706 }
2516725707 }
2516825708 return ir_const_type(ira, &instruction->base, result_type);
2516925709}
......@@ -25216,9 +25756,29 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
2521625756 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));
2521725757 return ira->codegen->builtin_types.entry_invalid;
2521825758 }
25759 } else if (operand_type->id == ZigTypeIdEnum) {
25760 ZigType *int_type = operand_type->data.enumeration.tag_int_type;
25761 if (int_type->data.integral.bit_count < 8) {
25762 ir_add_error(ira, op,
25763 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",
25764 int_type->data.integral.bit_count));
25765 return ira->codegen->builtin_types.entry_invalid;
25766 }
25767 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
25768 if (int_type->data.integral.bit_count > max_atomic_bits) {
25769 ir_add_error(ira, op,
25770 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",
25771 max_atomic_bits, int_type->data.integral.bit_count));
25772 return ira->codegen->builtin_types.entry_invalid;
25773 }
25774 if (!is_power_of_2(int_type->data.integral.bit_count)) {
25775 ir_add_error(ira, op,
25776 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));
25777 return ira->codegen->builtin_types.entry_invalid;
25778 }
2521925779 } else if (get_codegen_ptr_type(operand_type) == nullptr) {
2522025780 ir_add_error(ira, op,
25221 buf_sprintf("expected integer or pointer type, found '%s'", buf_ptr(&operand_type->name)));
25781 buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
2522225782 return ira->codegen->builtin_types.entry_invalid;
2522325783 }
2522425784
......@@ -25249,6 +25809,12 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
2524925809 }
2525025810 }
2525125811
25812 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
25813 ir_add_error(ira, instruction->op,
25814 buf_sprintf("@atomicRmw on enum only works with .Xchg"));
25815 return ira->codegen->invalid_instruction;
25816 }
25817
2525225818 IrInstruction *operand = instruction->operand->child;
2525325819 if (type_is_invalid(operand->value.type))
2525425820 return ira->codegen->invalid_instruction;
......@@ -25323,6 +25889,56 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2532325889 return result;
2532425890}
2532525891
25892static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) {
25893 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
25894 if (type_is_invalid(operand_type))
25895 return ira->codegen->invalid_instruction;
25896
25897 IrInstruction *ptr_inst = instruction->ptr->child;
25898 if (type_is_invalid(ptr_inst->value.type))
25899 return ira->codegen->invalid_instruction;
25900
25901 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
25902 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
25903 if (type_is_invalid(casted_ptr->value.type))
25904 return ira->codegen->invalid_instruction;
25905
25906 IrInstruction *value = instruction->value->child;
25907 if (type_is_invalid(value->value.type))
25908 return ira->codegen->invalid_instruction;
25909
25910 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);
25911 if (type_is_invalid(casted_value->value.type))
25912 return ira->codegen->invalid_instruction;
25913
25914
25915 AtomicOrder ordering;
25916 if (instruction->ordering == nullptr) {
25917 ordering = instruction->resolved_ordering;
25918 } else {
25919 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
25920 return ira->codegen->invalid_instruction;
25921 }
25922
25923 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
25924 ir_assert(instruction->ordering != nullptr, &instruction->base);
25925 ir_add_error(ira, instruction->ordering,
25926 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
25927 return ira->codegen->invalid_instruction;
25928 }
25929
25930 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
25931 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
25932 result->value.type = ira->codegen->builtin_types.entry_void;
25933 return result;
25934 }
25935
25936 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,
25937 instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering);
25938 result->value.type = ira->codegen->builtin_types.entry_void;
25939 return result;
25940}
25941
2532625942static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
2532725943 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
2532825944 instruction->base.source_node);
......@@ -25854,6 +26470,26 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2585426470 return ir_const_void(ira, &instruction->base);
2585526471}
2585626472
26473static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
26474 IrInstruction *operand = instruction->operand->child;
26475 if (type_is_invalid(operand->value.type))
26476 return operand;
26477
26478 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
26479 &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true);
26480 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))
26481 return result_loc;
26482
26483 if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {
26484 return instruction->result_loc_cast->parent->gen_instruction;
26485 }
26486
26487 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
26488 if (type_is_invalid(dest_type))
26489 return ira->codegen->invalid_instruction;
26490 return ir_implicit_cast_with_result(ira, &instruction->base, operand, dest_type, nullptr);
26491}
26492
2585726493static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
2585826494 IrInstruction *operand = instruction->operand->child;
2585926495 if (type_is_invalid(operand->value.type))
......@@ -26337,6 +26973,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2633726973 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);
2633826974 case IrInstructionIdAtomicLoad:
2633926975 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);
26976 case IrInstructionIdAtomicStore:
26977 return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction);
2634026978 case IrInstructionIdSaveErrRetAddr:
2634126979 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);
2634226980 case IrInstructionIdAddImplicitReturnType:
......@@ -26517,6 +27155,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2651727155 case IrInstructionIdSaveErrRetAddr:
2651827156 case IrInstructionIdAddImplicitReturnType:
2651927157 case IrInstructionIdAtomicRmw:
27158 case IrInstructionIdAtomicStore:
2652027159 case IrInstructionIdCmpxchgGen:
2652127160 case IrInstructionIdCmpxchgSrc:
2652227161 case IrInstructionIdAssertZero:
src/ir_print.cpp+60-12
......@@ -324,6 +324,8 @@ const char* ir_instruction_type_str(IrInstructionId id) {
324324 return "AtomicRmw";
325325 case IrInstructionIdAtomicLoad:
326326 return "AtomicLoad";
327 case IrInstructionIdAtomicStore:
328 return "AtomicStore";
327329 case IrInstructionIdSaveErrRetAddr:
328330 return "SaveErrRetAddr";
329331 case IrInstructionIdAddImplicitReturnType:
......@@ -601,6 +603,12 @@ static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_
601603 fprintf(irp->f, ")");
602604}
603605
606static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) {
607 fprintf(irp->f, "cast(ty=");
608 ir_print_other_instruction(irp, result_loc_cast->base.source_instruction);
609 fprintf(irp->f, ")");
610}
611
604612static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
605613 switch (result_loc->id) {
606614 case ResultLocIdInvalid:
......@@ -619,6 +627,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
619627 return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc);
620628 case ResultLocIdBitCast:
621629 return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc);
630 case ResultLocIdCast:
631 return ir_print_result_loc_cast(irp, (ResultLocCast *)result_loc);
622632 case ResultLocIdPeerParent:
623633 fprintf(irp->f, "peer_parent");
624634 return;
......@@ -723,7 +733,6 @@ static void ir_print_phi(IrPrint *irp, IrInstructionPhi *phi_instruction) {
723733}
724734
725735static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerInitList *instruction) {
726 ir_print_other_instruction(irp, instruction->container_type);
727736 fprintf(irp->f, "{");
728737 if (instruction->item_count > 50) {
729738 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
......@@ -735,11 +744,11 @@ static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerIni
735744 ir_print_other_instruction(irp, result_loc);
736745 }
737746 }
738 fprintf(irp->f, "}");
747 fprintf(irp->f, "}result=");
748 ir_print_other_instruction(irp, instruction->result_loc);
739749}
740750
741751static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {
742 ir_print_other_instruction(irp, instruction->container_type);
743752 fprintf(irp->f, "{");
744753 for (size_t i = 0; i < instruction->field_count; i += 1) {
745754 IrInstructionContainerInitFieldsField *field = &instruction->fields[i];
......@@ -747,7 +756,8 @@ static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerI
747756 fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));
748757 ir_print_other_instruction(irp, field->result_loc);
749758 }
750 fprintf(irp->f, "} // container init");
759 fprintf(irp->f, "}result=");
760 ir_print_other_instruction(irp, instruction->result_loc);
751761}
752762
753763static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {
......@@ -1484,6 +1494,13 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc
14841494 fprintf(irp->f, ")");
14851495}
14861496
1497static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
1498 fprintf(irp->f, "@implicitCast(");
1499 ir_print_other_instruction(irp, instruction->operand);
1500 fprintf(irp->f, ")result=");
1501 ir_print_result_loc(irp, &instruction->result_loc_cast->base);
1502}
1503
14871504static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {
14881505 fprintf(irp->f, "@bitCast(");
14891506 ir_print_other_instruction(irp, instruction->operand);
......@@ -1739,14 +1756,6 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio
17391756 fprintf(irp->f, ")");
17401757}
17411758
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
17501759static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {
17511760 fprintf(irp->f, "ResolveResult(");
17521761 ir_print_result_loc(irp, instruction->result_loc);
......@@ -1864,6 +1873,27 @@ static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruct
18641873 fprintf(irp->f, ")");
18651874}
18661875
1876static void ir_print_atomic_store(IrPrint *irp, IrInstructionAtomicStore *instruction) {
1877 fprintf(irp->f, "@atomicStore(");
1878 if (instruction->operand_type != nullptr) {
1879 ir_print_other_instruction(irp, instruction->operand_type);
1880 } else {
1881 fprintf(irp->f, "[TODO print]");
1882 }
1883 fprintf(irp->f, ",");
1884 ir_print_other_instruction(irp, instruction->ptr);
1885 fprintf(irp->f, ",");
1886 ir_print_other_instruction(irp, instruction->value);
1887 fprintf(irp->f, ",");
1888 if (instruction->ordering != nullptr) {
1889 ir_print_other_instruction(irp, instruction->ordering);
1890 } else {
1891 fprintf(irp->f, "[TODO print]");
1892 }
1893 fprintf(irp->f, ")");
1894}
1895
1896
18671897static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {
18681898 fprintf(irp->f, "@saveErrRetAddr()");
18691899}
......@@ -2424,6 +2454,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
24242454 case IrInstructionIdAtomicLoad:
24252455 ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);
24262456 break;
2457 case IrInstructionIdAtomicStore:
2458 ir_print_atomic_store(irp, (IrInstructionAtomicStore *)instruction);
2459 break;
24272460 case IrInstructionIdEnumToInt:
24282461 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
24292462 break;
......@@ -2542,3 +2575,18 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction,
25422575
25432576 ir_print_instruction(irp, instruction, false);
25442577}
2578
2579void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass) {
2580 IrPrint ir_print = {};
2581 IrPrint *irp = &ir_print;
2582 irp->pass = pass;
2583 irp->codegen = codegen;
2584 irp->f = f;
2585 irp->indent = indent_size;
2586 irp->indent_size = indent_size;
2587 irp->printed = {};
2588 irp->printed.init(4);
2589 irp->pending = {};
2590
2591 ir_print_const_value(irp, value);
2592}
src/ir_print.hpp+1
......@@ -14,6 +14,7 @@
1414
1515void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
1616void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass);
1718
1819const char* ir_instruction_type_str(IrInstructionId id);
1920
src/parser.cpp+48-12
......@@ -81,7 +81,7 @@ static AstNode *ast_parse_for_type_expr(ParseContext *pc);
8181static AstNode *ast_parse_while_type_expr(ParseContext *pc);
8282static AstNode *ast_parse_switch_expr(ParseContext *pc);
8383static AstNode *ast_parse_asm_expr(ParseContext *pc);
84static AstNode *ast_parse_enum_lit(ParseContext *pc);
84static AstNode *ast_parse_anon_lit(ParseContext *pc);
8585static AstNode *ast_parse_asm_output(ParseContext *pc);
8686static AsmOutput *ast_parse_asm_output_item(ParseContext *pc);
8787static AstNode *ast_parse_asm_input(ParseContext *pc);
......@@ -493,6 +493,9 @@ static AstNode *ast_parse_root(ParseContext *pc) {
493493 node->data.container_decl.layout = ContainerLayoutAuto;
494494 node->data.container_decl.kind = ContainerKindStruct;
495495 node->data.container_decl.is_root = true;
496 if (buf_len(&members.doc_comments) != 0) {
497 node->data.container_decl.doc_comments = members.doc_comments;
498 }
496499
497500 return node;
498501}
......@@ -514,6 +517,21 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
514517 return first_doc_token;
515518}
516519
520static void ast_parse_container_doc_comments(ParseContext *pc, Buf *buf) {
521 if (buf_len(buf) != 0 && peek_token(pc)->id == TokenIdContainerDocComment) {
522 buf_append_char(buf, '\n');
523 }
524 Token *doc_token = nullptr;
525 while ((doc_token = eat_token_if(pc, TokenIdContainerDocComment))) {
526 if (buf->list.length == 0) {
527 buf_resize(buf, 0);
528 }
529 // chops off '//!' but leaves '\n'
530 buf_append_mem(buf, buf_ptr(pc->buf) + doc_token->start_pos + 3,
531 doc_token->end_pos - doc_token->start_pos - 3);
532 }
533}
534
517535// ContainerMembers
518536// <- TestDecl ContainerMembers
519537// / TopLevelComptime ContainerMembers
......@@ -523,7 +541,11 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
523541// /
524542static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
525543 AstNodeContainerDecl res = {};
544 Buf tld_doc_comment_buf = BUF_INIT;
545 buf_resize(&tld_doc_comment_buf, 0);
526546 for (;;) {
547 ast_parse_container_doc_comments(pc, &tld_doc_comment_buf);
548
527549 AstNode *test_decl = ast_parse_test_decl(pc);
528550 if (test_decl != nullptr) {
529551 res.decls.append(test_decl);
......@@ -566,7 +588,7 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
566588
567589 break;
568590 }
569
591 res.doc_comments = tld_doc_comment_buf;
570592 return res;
571593}
572594
......@@ -1600,9 +1622,9 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
16001622 if (container_decl != nullptr)
16011623 return container_decl;
16021624
1603 AstNode *enum_lit = ast_parse_enum_lit(pc);
1604 if (enum_lit != nullptr)
1605 return enum_lit;
1625 AstNode *anon_lit = ast_parse_anon_lit(pc);
1626 if (anon_lit != nullptr)
1627 return anon_lit;
16061628
16071629 AstNode *error_set_decl = ast_parse_error_set_decl(pc);
16081630 if (error_set_decl != nullptr)
......@@ -1876,16 +1898,22 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc) {
18761898 return res;
18771899}
18781900
1879static AstNode *ast_parse_enum_lit(ParseContext *pc) {
1901static AstNode *ast_parse_anon_lit(ParseContext *pc) {
18801902 Token *period = eat_token_if(pc, TokenIdDot);
18811903 if (period == nullptr)
18821904 return nullptr;
18831905
1884 Token *identifier = expect_token(pc, TokenIdSymbol);
1885 AstNode *res = ast_create_node(pc, NodeTypeEnumLiteral, period);
1886 res->data.enum_literal.period = period;
1887 res->data.enum_literal.identifier = identifier;
1888 return res;
1906 // anon enum literal
1907 Token *identifier = eat_token_if(pc, TokenIdSymbol);
1908 if (identifier != nullptr) {
1909 AstNode *res = ast_create_node(pc, NodeTypeEnumLiteral, period);
1910 res->data.enum_literal.period = period;
1911 res->data.enum_literal.identifier = identifier;
1912 return res;
1913 }
1914
1915 // anon container literal
1916 return ast_parse_init_list(pc);
18891917}
18901918
18911919// AsmOutput <- COLON AsmOutputList AsmInput?
......@@ -2019,7 +2047,12 @@ static AstNode *ast_parse_field_init(ParseContext *pc) {
20192047 if (first == nullptr)
20202048 return nullptr;
20212049
2022 Token *name = expect_token(pc, TokenIdSymbol);
2050 Token *name = eat_token_if(pc, TokenIdSymbol);
2051 if (name == nullptr) {
2052 // Because of anon literals ".{" is also valid.
2053 put_back_token(pc);
2054 return nullptr;
2055 }
20232056 if (eat_token_if(pc, TokenIdEq) == nullptr) {
20242057 // Because ".Name" can also be intepreted as an enum literal, we should put back
20252058 // those two tokens again so that the parser can try to parse them as the enum
......@@ -2791,6 +2824,9 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc) {
27912824
27922825 res->data.container_decl.fields = members.fields;
27932826 res->data.container_decl.decls = members.decls;
2827 if (buf_len(&members.doc_comments) != 0) {
2828 res->data.container_decl.doc_comments = members.doc_comments;
2829 }
27942830 return res;
27952831}
27962832
src/range_set.cpp+3
......@@ -40,6 +40,9 @@ void rangeset_sort(RangeSet *rs) {
4040}
4141
4242bool rangeset_spans(RangeSet *rs, BigInt *first, BigInt *last) {
43 if (rs->src_range_list.length == 0)
44 return false;
45
4346 rangeset_sort(rs);
4447
4548 const Range *first_range = &rs->src_range_list.at(0).range;
src/tokenizer.cpp+32-1
......@@ -153,7 +153,6 @@ static const struct ZigKeyword zig_keywords[] = {
153153 {"undefined", TokenIdKeywordUndefined},
154154 {"union", TokenIdKeywordUnion},
155155 {"unreachable", TokenIdKeywordUnreachable},
156 {"use", TokenIdKeywordUsingNamespace},
157156 {"usingnamespace", TokenIdKeywordUsingNamespace},
158157 {"var", TokenIdKeywordVar},
159158 {"volatile", TokenIdKeywordVolatile},
......@@ -199,6 +198,7 @@ enum TokenizeState {
199198 TokenizeStateSawSlash,
200199 TokenizeStateSawSlash2,
201200 TokenizeStateSawSlash3,
201 TokenizeStateSawSlashBang,
202202 TokenizeStateSawBackslash,
203203 TokenizeStateSawPercent,
204204 TokenizeStateSawPlus,
......@@ -210,6 +210,7 @@ enum TokenizeState {
210210 TokenizeStateSawBar,
211211 TokenizeStateSawBarBar,
212212 TokenizeStateDocComment,
213 TokenizeStateContainerDocComment,
213214 TokenizeStateLineComment,
214215 TokenizeStateLineString,
215216 TokenizeStateLineStringEnd,
......@@ -939,6 +940,9 @@ void tokenize(Buf *buf, Tokenization *out) {
939940 case '/':
940941 t.state = TokenizeStateSawSlash3;
941942 break;
943 case '!':
944 t.state = TokenizeStateSawSlashBang;
945 break;
942946 case '\n':
943947 cancel_token(&t);
944948 t.state = TokenizeStateStart;
......@@ -966,6 +970,19 @@ void tokenize(Buf *buf, Tokenization *out) {
966970 break;
967971 }
968972 break;
973 case TokenizeStateSawSlashBang:
974 switch (c) {
975 case '\n':
976 set_token_id(&t, t.cur_tok, TokenIdContainerDocComment);
977 end_token(&t);
978 t.state = TokenizeStateStart;
979 break;
980 default:
981 set_token_id(&t, t.cur_tok, TokenIdContainerDocComment);
982 t.state = TokenizeStateContainerDocComment;
983 break;
984 }
985 break;
969986 case TokenizeStateSawBackslash:
970987 switch (c) {
971988 case '\\':
......@@ -1056,6 +1073,17 @@ void tokenize(Buf *buf, Tokenization *out) {
10561073 break;
10571074 }
10581075 break;
1076 case TokenizeStateContainerDocComment:
1077 switch (c) {
1078 case '\n':
1079 end_token(&t);
1080 t.state = TokenizeStateStart;
1081 break;
1082 default:
1083 // do nothing
1084 break;
1085 }
1086 break;
10591087 case TokenizeStateSymbolFirstC:
10601088 switch (c) {
10611089 case '"':
......@@ -1546,6 +1574,7 @@ void tokenize(Buf *buf, Tokenization *out) {
15461574 case TokenizeStateSawBarBar:
15471575 case TokenizeStateLBracket:
15481576 case TokenizeStateDocComment:
1577 case TokenizeStateContainerDocComment:
15491578 end_token(&t);
15501579 break;
15511580 case TokenizeStateSawDotDot:
......@@ -1560,6 +1589,7 @@ void tokenize(Buf *buf, Tokenization *out) {
15601589 case TokenizeStateLineComment:
15611590 case TokenizeStateSawSlash2:
15621591 case TokenizeStateSawSlash3:
1592 case TokenizeStateSawSlashBang:
15631593 break;
15641594 }
15651595 if (t.state != TokenizeStateError) {
......@@ -1607,6 +1637,7 @@ const char * token_name(TokenId id) {
16071637 case TokenIdDash: return "-";
16081638 case TokenIdDivEq: return "/=";
16091639 case TokenIdDocComment: return "DocComment";
1640 case TokenIdContainerDocComment: return "ContainerDocComment";
16101641 case TokenIdDot: return ".";
16111642 case TokenIdDotStar: return ".*";
16121643 case TokenIdEllipsis2: return "..";
src/tokenizer.hpp+1
......@@ -43,6 +43,7 @@ enum TokenId {
4343 TokenIdDash,
4444 TokenIdDivEq,
4545 TokenIdDocComment,
46 TokenIdContainerDocComment,
4647 TokenIdDot,
4748 TokenIdDotStar,
4849 TokenIdEllipsis2,
src/translate_c.cpp+20-15
......@@ -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) {
......@@ -1212,6 +1213,11 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc
12121213 const ZigClangAttributedType *attributed_ty = reinterpret_cast<const ZigClangAttributedType *>(ty);
12131214 return trans_qual_type(c, ZigClangAttributedType_getEquivalentType(attributed_ty), source_loc);
12141215 }
1216 case ZigClangType_MacroQualified:
1217 {
1218 const ZigClangMacroQualifiedType *macroqualified_ty = reinterpret_cast<const ZigClangMacroQualifiedType *>(ty);
1219 return trans_qual_type(c, ZigClangMacroQualifiedType_getModifiedType(macroqualified_ty), source_loc);
1220 }
12151221 case ZigClangType_IncompleteArray:
12161222 {
12171223 const ZigClangIncompleteArrayType *incomplete_array_ty = reinterpret_cast<const ZigClangIncompleteArrayType *>(ty);
......@@ -1261,7 +1267,6 @@ static AstNode *trans_type(Context *c, const ZigClangType *ty, ZigClangSourceLoc
12611267 case ZigClangType_DeducedTemplateSpecialization:
12621268 case ZigClangType_DependentAddressSpace:
12631269 case ZigClangType_DependentVector:
1264 case ZigClangType_MacroQualified:
12651270 emit_warning(c, source_loc, "unsupported type: '%s'", ZigClangType_getTypeClassName(ty));
12661271 return nullptr;
12671272 }
......@@ -1527,7 +1532,7 @@ static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQua
15271532
15281533 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, rhs_expr, TransRValue);
15291534 if (rhs == nullptr) return nullptr;
1530 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1535 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
15311536
15321537 return trans_create_node_bin_op(c, lhs, bin_op, coerced_rhs);
15331538}
......@@ -1702,7 +1707,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
17021707
17031708 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
17041709 if (rhs == nullptr) return nullptr;
1705 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1710 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
17061711
17071712 return trans_create_node_bin_op(c, lhs, assign_op, coerced_rhs);
17081713 } else {
......@@ -1733,7 +1738,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
17331738
17341739 AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
17351740 if (rhs == nullptr) return nullptr;
1736 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1741 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
17371742
17381743 // operation_type(*_ref)
17391744 AstNode *operation_type_cast = trans_c_cast(c, rhs_location,
......@@ -2684,7 +2689,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type)
26842689
26852690 // @TagType(Enum)(0)
26862691 AstNode *zero = trans_create_node_unsigned_negative(c, 0, false);
2687 AstNode *casted_zero = trans_create_node_fn_call_1(c, tag_type, zero);
2692 AstNode *casted_zero = trans_create_node_cast(c, tag_type, zero);
26882693
26892694 // @bitCast(Enum, @TagType(Enum)(0))
26902695 AstNode *bitcast = trans_create_node_builtin_fn_call_str(c, "bitCast");
src/zig_clang.cpp+5
......@@ -2214,6 +2214,11 @@ struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct Zi
22142214 return bitcast(casted->getEquivalentType());
22152215}
22162216
2217struct ZigClangQualType ZigClangMacroQualifiedType_getModifiedType(const struct ZigClangMacroQualifiedType *self) {
2218 auto casted = reinterpret_cast<const clang::MacroQualifiedType *>(self);
2219 return bitcast(casted->getModifiedType());
2220}
2221
22172222struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *self) {
22182223 auto casted = reinterpret_cast<const clang::ElaboratedType *>(self);
22192224 return bitcast(casted->getNamedType());
src/zig_clang.h+3
......@@ -112,6 +112,7 @@ struct ZigClangImplicitCastExpr;
112112struct ZigClangIncompleteArrayType;
113113struct ZigClangIntegerLiteral;
114114struct ZigClangMacroDefinitionRecord;
115struct ZigClangMacroQualifiedType;
115116struct ZigClangMemberExpr;
116117struct ZigClangNamedDecl;
117118struct ZigClangNone;
......@@ -1004,6 +1005,8 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangParenType_getInnerType(const struct
10041005
10051006ZIG_EXTERN_C struct ZigClangQualType ZigClangAttributedType_getEquivalentType(const struct ZigClangAttributedType *);
10061007
1008ZIG_EXTERN_C struct ZigClangQualType ZigClangMacroQualifiedType_getModifiedType(const struct ZigClangMacroQualifiedType *);
1009
10071010ZIG_EXTERN_C struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *);
10081011ZIG_EXTERN_C enum ZigClangElaboratedTypeKeyword ZigClangElaboratedType_getKeyword(const struct ZigClangElaboratedType *);
10091012
test/compare_output.zig+61-61
......@@ -14,12 +14,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
1414
1515 cases.addCase(x: {
1616 var tc = cases.create("multiple files with private function",
17 \\use @import("std").io;
18 \\use @import("foo.zig");
17 \\usingnamespace @import("std").io;
18 \\usingnamespace @import("foo.zig");
1919 \\
2020 \\pub fn main() void {
2121 \\ privateFunction();
22 \\ const stdout = &(getStdOut() catch unreachable).outStream().stream;
22 \\ const stdout = &getStdOut().outStream().stream;
2323 \\ stdout.print("OK 2\n") catch unreachable;
2424 \\}
2525 \\
......@@ -29,12 +29,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
2929 , "OK 1\nOK 2\n");
3030
3131 tc.addSourceFile("foo.zig",
32 \\use @import("std").io;
32 \\usingnamespace @import("std").io;
3333 \\
3434 \\// purposefully conflicting function with main.zig
3535 \\// but it's private so it should be OK
3636 \\fn privateFunction() void {
37 \\ const stdout = &(getStdOut() catch unreachable).outStream().stream;
37 \\ const stdout = &getStdOut().outStream().stream;
3838 \\ stdout.print("OK 1\n") catch unreachable;
3939 \\}
4040 \\
......@@ -48,8 +48,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
4848
4949 cases.addCase(x: {
5050 var tc = cases.create("import segregation",
51 \\use @import("foo.zig");
52 \\use @import("bar.zig");
51 \\usingnamespace @import("foo.zig");
52 \\usingnamespace @import("bar.zig");
5353 \\
5454 \\pub fn main() void {
5555 \\ foo_function();
......@@ -58,20 +58,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
5858 , "OK\nOK\n");
5959
6060 tc.addSourceFile("foo.zig",
61 \\use @import("std").io;
61 \\usingnamespace @import("std").io;
6262 \\pub fn foo_function() void {
63 \\ const stdout = &(getStdOut() catch unreachable).outStream().stream;
63 \\ const stdout = &getStdOut().outStream().stream;
6464 \\ stdout.print("OK\n") catch unreachable;
6565 \\}
6666 );
6767
6868 tc.addSourceFile("bar.zig",
69 \\use @import("other.zig");
70 \\use @import("std").io;
69 \\usingnamespace @import("other.zig");
70 \\usingnamespace @import("std").io;
7171 \\
7272 \\pub fn bar_function() void {
7373 \\ if (foo_function()) {
74 \\ const stdout = &(getStdOut() catch unreachable).outStream().stream;
74 \\ const stdout = &getStdOut().outStream().stream;
7575 \\ stdout.print("OK\n") catch unreachable;
7676 \\ }
7777 \\}
......@@ -88,8 +88,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
8888 });
8989
9090 cases.addCase(x: {
91 var tc = cases.create("two files use import each other",
92 \\use @import("a.zig");
91 var tc = cases.create("two files usingnamespace import each other",
92 \\usingnamespace @import("a.zig");
9393 \\
9494 \\pub fn main() void {
9595 \\ ok();
......@@ -97,19 +97,19 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
9797 , "OK\n");
9898
9999 tc.addSourceFile("a.zig",
100 \\use @import("b.zig");
100 \\usingnamespace @import("b.zig");
101101 \\const io = @import("std").io;
102102 \\
103103 \\pub const a_text = "OK\n";
104104 \\
105105 \\pub fn ok() void {
106 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
106 \\ const stdout = &io.getStdOut().outStream().stream;
107107 \\ stdout.print(b_text) catch unreachable;
108108 \\}
109109 );
110110
111111 tc.addSourceFile("b.zig",
112 \\use @import("a.zig");
112 \\usingnamespace @import("a.zig");
113113 \\
114114 \\pub const b_text = a_text;
115115 );
......@@ -121,8 +121,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
121121 \\const io = @import("std").io;
122122 \\
123123 \\pub fn main() void {
124 \\ 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;
124 \\ const stdout = &io.getStdOut().outStream().stream;
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 \\}
......@@ -264,7 +264,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
264264 \\ var x_local : i32 = print_ok(x);
265265 \\}
266266 \\fn print_ok(val: @typeOf(x)) @typeOf(foo) {
267 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
267 \\ const stdout = &io.getStdOut().outStream().stream;
268268 \\ stdout.print("OK\n") catch unreachable;
269269 \\ return 0;
270270 \\}
......@@ -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");
......@@ -346,7 +346,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
346346 \\pub fn main() void {
347347 \\ const bar = Bar {.field2 = 13,};
348348 \\ const foo = Foo {.field1 = bar,};
349 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
349 \\ const stdout = &io.getStdOut().outStream().stream;
350350 \\ if (!foo.method()) {
351351 \\ stdout.print("BAD\n") catch unreachable;
352352 \\ }
......@@ -360,7 +360,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
360360 cases.add("defer with only fallthrough",
361361 \\const io = @import("std").io;
362362 \\pub fn main() void {
363 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
363 \\ const stdout = &io.getStdOut().outStream().stream;
364364 \\ stdout.print("before\n") catch unreachable;
365365 \\ defer stdout.print("defer1\n") catch unreachable;
366366 \\ defer stdout.print("defer2\n") catch unreachable;
......@@ -373,7 +373,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
373373 \\const io = @import("std").io;
374374 \\const os = @import("std").os;
375375 \\pub fn main() void {
376 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
376 \\ const stdout = &io.getStdOut().outStream().stream;
377377 \\ stdout.print("before\n") catch unreachable;
378378 \\ defer stdout.print("defer1\n") catch unreachable;
379379 \\ defer stdout.print("defer2\n") catch unreachable;
......@@ -390,7 +390,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
390390 \\ do_test() catch return;
391391 \\}
392392 \\fn do_test() !void {
393 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
393 \\ const stdout = &io.getStdOut().outStream().stream;
394394 \\ stdout.print("before\n") catch unreachable;
395395 \\ defer stdout.print("defer1\n") catch unreachable;
396396 \\ errdefer stdout.print("deferErr\n") catch unreachable;
......@@ -409,7 +409,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
409409 \\ do_test() catch return;
410410 \\}
411411 \\fn do_test() !void {
412 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
412 \\ const stdout = &io.getStdOut().outStream().stream;
413413 \\ stdout.print("before\n") catch unreachable;
414414 \\ defer stdout.print("defer1\n") catch unreachable;
415415 \\ errdefer stdout.print("deferErr\n") catch unreachable;
......@@ -426,7 +426,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
426426 \\const io = @import("std").io;
427427 \\
428428 \\pub fn main() void {
429 \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
429 \\ const stdout = &io.getStdOut().outStream().stream;
430430 \\ stdout.print(foo_txt) catch unreachable;
431431 \\}
432432 , "1234\nabcd\n");
......@@ -445,7 +445,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
445445 \\
446446 \\pub fn main() !void {
447447 \\ var args_it = std.process.args();
448 \\ var stdout_file = try io.getStdOut();
448 \\ var stdout_file = io.getStdOut();
449449 \\ var stdout_adapter = stdout_file.outStream();
450450 \\ const stdout = &stdout_adapter.stream;
451451 \\ var index: usize = 0;
......@@ -486,7 +486,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
486486 \\
487487 \\pub fn main() !void {
488488 \\ var args_it = std.process.args();
489 \\ var stdout_file = try io.getStdOut();
489 \\ var stdout_file = io.getStdOut();
490490 \\ var stdout_adapter = stdout_file.outStream();
491491 \\ const stdout = &stdout_adapter.stream;
492492 \\ var index: usize = 0;
test/compile_errors.zig+196-74
......@@ -2,6 +2,130 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "empty switch on an integer",
7 \\export fn entry() void {
8 \\ var x: u32 = 0;
9 \\ switch(x) {}
10 \\}
11 ,
12 "tmp.zig:3:5: error: switch must handle all possibilities",
13 );
14
15 cases.add(
16 "incorrect return type",
17 \\ pub export fn entry() void{
18 \\ _ = foo();
19 \\ }
20 \\ const A = struct {
21 \\ a: u32,
22 \\ };
23 \\ fn foo() A {
24 \\ return bar();
25 \\ }
26 \\ const B = struct {
27 \\ a: u32,
28 \\ };
29 \\ fn bar() B {
30 \\ unreachable;
31 \\ }
32 ,
33 "tmp.zig:8:16: error: expected type 'A', found 'B'",
34 );
35
36 cases.add(
37 "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
38 \\const Foo = struct {
39 \\ ptr: ?*usize,
40 \\ uval: u32,
41 \\};
42 \\fn get_uval(x: u32) !u32 {
43 \\ return error.NotFound;
44 \\}
45 \\export fn entry() void {
46 \\ const afoo = Foo{
47 \\ .ptr = null,
48 \\ .uval = get_uval(42),
49 \\ };
50 \\}
51 ,
52 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",
53 );
54
55 cases.add(
56 "asigning to struct or union fields that are not optionals with a function that returns an optional",
57 \\fn maybe(is: bool) ?u8 {
58 \\ if (is) return @as(u8, 10) else return null;
59 \\}
60 \\const U = union {
61 \\ Ye: u8,
62 \\};
63 \\const S = struct {
64 \\ num: u8,
65 \\};
66 \\export fn entry() void {
67 \\ var u = U{ .Ye = maybe(false) };
68 \\ var s = S{ .num = maybe(false) };
69 \\}
70 ,
71 "tmp.zig:11:27: error: expected type 'u8', found '?u8'",
72 );
73
74 cases.add(
75 "missing result type for phi node",
76 \\fn foo() !void {
77 \\ return anyerror.Foo;
78 \\}
79 \\export fn entry() void {
80 \\ foo() catch 0;
81 \\}
82 ,
83 "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'",
84 );
85
86 cases.add(
87 "atomicrmw with enum op not .Xchg",
88 \\export fn entry() void {
89 \\ const E = enum(u8) {
90 \\ a,
91 \\ b,
92 \\ c,
93 \\ d,
94 \\ };
95 \\ var x: E = .a;
96 \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
97 \\}
98 ,
99 "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
100 );
101
102 cases.add(
103 "atomic orderings of atomicStore Acquire or AcqRel",
104 \\export fn entry() void {
105 \\ var x: u32 = 0;
106 \\ @atomicStore(u32, &x, 1, .Acquire);
107 \\}
108 ,
109 "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
110 );
111
112 cases.add(
113 "missing const in slice with nested array type",
114 \\const Geo3DTex2D = struct { vertices: [][2]f32 };
115 \\pub fn getGeo3DTex2D() Geo3DTex2D {
116 \\ return Geo3DTex2D{
117 \\ .vertices = [_][2]f32{
118 \\ [_]f32{ -0.5, -0.5},
119 \\ },
120 \\ };
121 \\}
122 \\export fn entry() void {
123 \\ var geo_data = getGeo3DTex2D();
124 \\}
125 ,
126 "tmp.zig:4:30: error: expected type '[][2]f32', found '[1][2]f32'",
127 );
128
5129 cases.add(
6130 "slicing of global undefined pointer",
7131 \\var buf: *[1]u8 = undefined;
......@@ -186,21 +310,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
186310 cases.add(
187311 "shift amount has to be an integer type",
188312 \\export fn entry() void {
189 \\ const x = 1 << &u8(10);
313 \\ const x = 1 << &@as(u8, 10);
190314 \\}
191315 ,
192 "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'",
316 "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'",
193317 "tmp.zig:2:17: note: referenced here",
194318 );
195319
196320 cases.add(
197321 "bit shifting only works on integer types",
198322 \\export fn entry() void {
199 \\ const x = &u8(1) << 10;
323 \\ const x = &@as(u8, 1) << 10;
200324 \\}
201325 ,
202 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",
203 "tmp.zig:2:22: note: referenced here",
326 "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'",
327 "tmp.zig:2:27: note: referenced here",
204328 );
205329
206330 cases.add(
......@@ -216,9 +340,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
216340 \\ const obj = AstObject{ .lhsExpr = lhsExpr };
217341 \\}
218342 ,
219 "tmp.zig:4:19: error: union 'AstObject' depends on itself",
220 "tmp.zig:2:5: note: while checking this field",
343 "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself",
221344 "tmp.zig:5:5: note: while checking this field",
345 "tmp.zig:2:5: note: while checking this field",
222346 );
223347
224348 cases.add(
......@@ -241,11 +365,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
241365 \\ var x: []align(true) i32 = undefined;
242366 \\}
243367 \\export fn entry2() void {
244 \\ var x: *align(f64(12.34)) i32 = undefined;
368 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
245369 \\}
246370 ,
247371 "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'",
372 "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
249373 );
250374
251375 cases.addCase(x: {
......@@ -1243,7 +1367,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12431367 \\ var ptr: [*c]u8 = x;
12441368 \\}
12451369 ,
1246 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be implicitly casted to type 'usize'",
1370 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
12471371 "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
12481372 );
12491373
......@@ -1297,17 +1421,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12971421 cases.add(
12981422 "@truncate undefined value",
12991423 \\export fn entry() void {
1300 \\ var z = @truncate(u8, u16(undefined));
1424 \\ var z = @truncate(u8, @as(u16, undefined));
13011425 \\}
13021426 ,
1303 "tmp.zig:2:30: error: use of undefined value here causes undefined behavior",
1427 "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
13041428 );
13051429
13061430 cases.addTest(
13071431 "return invalid type from test",
13081432 \\test "example" { return 1; }
13091433 ,
1310 "tmp.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'",
1434 "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",
13111435 );
13121436
13131437 cases.add(
......@@ -1332,7 +1456,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13321456 cases.add(
13331457 "@bitCast with different sizes inside an expression",
13341458 \\export fn entry() void {
1335 \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf);
1459 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
13361460 \\}
13371461 ,
13381462 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
......@@ -1464,8 +1588,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14641588 \\ var byte: u8 = spartan_count;
14651589 \\}
14661590 ,
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'",
1591 "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'",
1592 "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'",
14691593 "tmp.zig:11:20: error: expected type 'u8', found 'u16'",
14701594 );
14711595
......@@ -1498,7 +1622,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14981622 \\ var x: i65536 = 1;
14991623 \\}
15001624 ,
1501 "tmp.zig:2:31: error: integer value 65536 cannot be implicitly casted to type 'u16'",
1625 "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
15021626 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
15031627 );
15041628
......@@ -1686,10 +1810,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16861810 cases.add(
16871811 "non float passed to @floatToInt",
16881812 \\export fn entry() void {
1689 \\ const x = @floatToInt(i32, i32(54));
1813 \\ const x = @floatToInt(i32, @as(i32, 54));
16901814 \\}
16911815 ,
1692 "tmp.zig:2:35: error: expected float type, found 'i32'",
1816 "tmp.zig:2:32: error: expected float type, found 'i32'",
16931817 );
16941818
16951819 cases.add(
......@@ -1698,7 +1822,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16981822 \\ const x = @floatToInt(i8, 200);
16991823 \\}
17001824 ,
1701 "tmp.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'",
1825 "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
17021826 );
17031827
17041828 cases.add(
......@@ -2096,8 +2220,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20962220 \\
20972221 \\fn bar(x: *b.Foo) void {}
20982222 ,
2099 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
2100 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
2223 "tmp.zig:6:9: error: expected type '*b.Foo', found '*a.Foo'",
2224 "tmp.zig:6:9: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
21012225 "a.zig:1:17: note: a.Foo declared here",
21022226 "b.zig:1:17: note: b.Foo declared here",
21032227 );
......@@ -2120,13 +2244,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21202244 cases.add(
21212245 "@floatToInt comptime safety",
21222246 \\comptime {
2123 \\ _ = @floatToInt(i8, f32(-129.1));
2247 \\ _ = @floatToInt(i8, @as(f32, -129.1));
21242248 \\}
21252249 \\comptime {
2126 \\ _ = @floatToInt(u8, f32(-1.1));
2250 \\ _ = @floatToInt(u8, @as(f32, -1.1));
21272251 \\}
21282252 \\comptime {
2129 \\ _ = @floatToInt(u8, f32(256.1));
2253 \\ _ = @floatToInt(u8, @as(f32, 256.1));
21302254 \\}
21312255 ,
21322256 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
......@@ -2197,7 +2321,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21972321 cases.add(
21982322 "error when evaluating return type",
21992323 \\const Foo = struct {
2200 \\ map: i32(i32),
2324 \\ map: @as(i32, i32),
22012325 \\
22022326 \\ fn init() Foo {
22032327 \\ return undefined;
......@@ -2207,7 +2331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22072331 \\ var rule_set = try Foo.init();
22082332 \\}
22092333 ,
2210 "tmp.zig:2:13: error: expected type 'i32', found 'type'",
2334 "tmp.zig:2:10: error: expected type 'i32', found 'type'",
22112335 );
22122336
22132337 cases.add(
......@@ -2338,7 +2462,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23382462 cases.add(
23392463 "var not allowed in structs",
23402464 \\export fn entry() void {
2341 \\ var s = (struct{v: var}){.v=i32(10)};
2465 \\ var s = (struct{v: var}){.v=@as(i32, 10)};
23422466 \\}
23432467 ,
23442468 "tmp.zig:2:23: error: invalid token: 'var'",
......@@ -2357,10 +2481,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23572481 cases.add(
23582482 "comptime slice of undefined pointer non-zero len",
23592483 \\export fn entry() void {
2360 \\ const slice = ([*]i32)(undefined)[0..1];
2484 \\ const slice = @as([*]i32, undefined)[0..1];
23612485 \\}
23622486 ,
2363 "tmp.zig:2:38: error: non-zero length slice of undefined pointer",
2487 "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
23642488 );
23652489
23662490 cases.add(
......@@ -2657,10 +2781,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26572781 cases.add(
26582782 "cast negative integer literal to usize",
26592783 \\export fn entry() void {
2660 \\ const x = usize(-10);
2784 \\ const x = @as(usize, -10);
26612785 \\}
26622786 ,
2663 "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'",
2787 "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
26642788 );
26652789
26662790 cases.add(
......@@ -3384,11 +3508,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
33843508 \\ const x : i32 = if (b) h: { break :h 1; };
33853509 \\}
33863510 \\fn g(b: bool) void {
3387 \\ const y = if (b) h: { break :h i32(1); };
3511 \\ const y = if (b) h: { break :h @as(i32, 1); };
33883512 \\}
33893513 \\export fn entry() void { f(true); g(true); }
33903514 ,
3391 "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
3515 "tmp.zig:2:21: error: expected type 'i32', found 'void'",
33923516 "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
33933517 );
33943518
......@@ -3520,11 +3644,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35203644 cases.add(
35213645 "cast unreachable",
35223646 \\fn f() i32 {
3523 \\ return i32(return 1);
3647 \\ return @as(i32, return 1);
35243648 \\}
35253649 \\export fn entry() void { _ = f(); }
35263650 ,
3527 "tmp.zig:2:15: error: unreachable code",
3651 "tmp.zig:2:12: error: unreachable code",
35283652 );
35293653
35303654 cases.add(
......@@ -3595,7 +3719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35953719 \\ switch (n) {
35963720 \\ Number.One => 1,
35973721 \\ Number.Two => 2,
3598 \\ Number.Three => i32(3),
3722 \\ Number.Three => @as(i32, 3),
35993723 \\ }
36003724 \\}
36013725 \\
......@@ -3616,7 +3740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36163740 \\ switch (n) {
36173741 \\ Number.One => 1,
36183742 \\ Number.Two => 2,
3619 \\ Number.Three => i32(3),
3743 \\ Number.Three => @as(i32, 3),
36203744 \\ Number.Four => 4,
36213745 \\ Number.Two => 2,
36223746 \\ }
......@@ -3640,7 +3764,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36403764 \\ switch (n) {
36413765 \\ Number.One => 1,
36423766 \\ Number.Two => 2,
3643 \\ Number.Three => i32(3),
3767 \\ Number.Three => @as(i32, 3),
36443768 \\ Number.Four => 4,
36453769 \\ Number.Two => 2,
36463770 \\ else => 10,
......@@ -3685,7 +3809,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36853809 "switch expression - duplicate or overlapping integer value",
36863810 \\fn foo(x: u8) u8 {
36873811 \\ return switch (x) {
3688 \\ 0 ... 100 => u8(0),
3812 \\ 0 ... 100 => @as(u8, 0),
36893813 \\ 101 ... 200 => 1,
36903814 \\ 201, 203 ... 207 => 2,
36913815 \\ 206 ... 255 => 3,
......@@ -3722,7 +3846,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37223846 cases.add(
37233847 "array concatenation with wrong type",
37243848 \\const src = "aoeu";
3725 \\const derp = usize(1234);
3849 \\const derp = @as(usize, 1234);
37263850 \\const a = derp ++ "foo";
37273851 \\
37283852 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
......@@ -3765,7 +3889,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37653889 \\const x : u8 = 300;
37663890 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
37673891 ,
3768 "tmp.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'",
3892 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
37693893 );
37703894
37713895 cases.add(
......@@ -3887,8 +4011,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38874011 "division by zero",
38884012 \\const lit_int_x = 1 / 0;
38894013 \\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);
4014 \\const int_x = @as(u32, 1) / @as(u32, 0);
4015 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
38924016 \\
38934017 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
38944018 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }
......@@ -3897,8 +4021,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38974021 ,
38984022 "tmp.zig:1:21: error: division by zero",
38994023 "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",
4024 "tmp.zig:3:27: error: division by zero",
4025 "tmp.zig:4:31: error: division by zero",
39024026 );
39034027
39044028 cases.add(
......@@ -4590,7 +4714,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
45904714 \\var bytes: [ext()]u8 = undefined;
45914715 \\export fn f() void {
45924716 \\ for (bytes) |*b, i| {
4593 \\ b.* = u8(i);
4717 \\ b.* = @as(u8, i);
45944718 \\ }
45954719 \\}
45964720 ,
......@@ -4874,7 +4998,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48744998 \\}
48754999 \\
48765000 \\fn foo() i32 {
4877 \\ return add(i32(1234));
5001 \\ return add(@as(i32, 1234));
48785002 \\}
48795003 \\
48805004 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
......@@ -4886,7 +5010,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48865010 cases.add(
48875011 "pass integer literal to var args",
48885012 \\fn add(args: ...) i32 {
4889 \\ var sum = i32(0);
5013 \\ var sum = @as(i32, 0);
48905014 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
48915015 \\ sum += args[i];
48925016 \\ }}
......@@ -4908,7 +5032,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49085032 \\ var vga_mem: u16 = 0xB8000;
49095033 \\}
49105034 ,
4911 "tmp.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'",
5035 "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
49125036 );
49135037
49145038 cases.add(
......@@ -4961,7 +5085,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49615085 \\
49625086 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
49635087 ,
4964 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
5088 "tmp.zig:8:16: error: expected type '*const u3', found '*align(:3:1) const u3'",
49655089 );
49665090
49675091 cases.add(
......@@ -5080,7 +5204,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50805204 cases.add(
50815205 "pass const ptr to mutable ptr fn",
50825206 \\fn foo() bool {
5083 \\ const a = ([]const u8)("a",);
5207 \\ const a = @as([]const u8, "a",);
50845208 \\ const b = &a;
50855209 \\ return ptrEql(b, b);
50865210 \\}
......@@ -5581,10 +5705,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55815705 cases.add(
55825706 "explicit cast float literal to integer when there is a fraction component",
55835707 \\export fn entry() i32 {
5584 \\ return i32(12.34);
5708 \\ return @as(i32, 12.34);
55855709 \\}
55865710 ,
5587 "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
5711 "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
55885712 );
55895713
55905714 cases.add(
......@@ -5599,7 +5723,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55995723 cases.add(
56005724 "@shlExact shifts out 1 bits",
56015725 \\comptime {
5602 \\ const x = @shlExact(u8(0b01010101), 2);
5726 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
56035727 \\}
56045728 ,
56055729 "tmp.zig:2:15: error: operation caused overflow",
......@@ -5608,7 +5732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56085732 cases.add(
56095733 "@shrExact shifts out 1 bits",
56105734 \\comptime {
5611 \\ const x = @shrExact(u8(0b10101010), 2);
5735 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
56125736 \\}
56135737 ,
56145738 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
......@@ -5658,7 +5782,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56585782 \\ x.* += 1;
56595783 \\}
56605784 ,
5661 "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
5785 "tmp.zig:8:9: error: expected type '*u32', found '*align(1) u32'",
56625786 );
56635787
56645788 cases.add(
......@@ -5671,16 +5795,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56715795 \\export fn entry() void {
56725796 \\ var foo = Foo { .a = 1, .b = 10 };
56735797 \\ foo.b += 1;
5674 \\ bar((*[1]u32)(&foo.b)[0..]);
5798 \\ bar(@as(*[1]u32, &foo.b)[0..]);
56755799 \\}
56765800 \\
56775801 \\fn bar(x: []u32) void {
56785802 \\ x[0] += 1;
56795803 \\}
56805804 ,
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",
5805 "tmp.zig:9:9: error: cast increases pointer alignment",
5806 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
5807 "tmp.zig:9:9: note: '*[1]u32' has alignment 4",
56845808 );
56855809
56865810 cases.add(
......@@ -5699,10 +5823,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56995823 cases.add(
57005824 "@alignCast expects pointer or slice",
57015825 \\export fn entry() void {
5702 \\ @alignCast(4, u32(3));
5826 \\ @alignCast(4, @as(u32, 3));
57035827 \\}
57045828 ,
5705 "tmp.zig:2:22: error: expected pointer or slice, found 'u32'",
5829 "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
57065830 );
57075831
57085832 cases.add(
......@@ -5740,11 +5864,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57405864 );
57415865
57425866 cases.add(
5743 "wrong pointer implicitly casted to pointer to @OpaqueType()",
5867 "wrong pointer coerced to pointer to @OpaqueType()",
57445868 \\const Derp = @OpaqueType();
57455869 \\extern fn bar(d: *Derp) void;
57465870 \\export fn foo() void {
5747 \\ var x = u8(1);
5871 \\ var x = @as(u8, 1);
57485872 \\ bar(@ptrCast(*c_void, &x));
57495873 \\}
57505874 ,
......@@ -5793,27 +5917,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57935917 "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
57945918 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",
57955919 "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",
5920 "tmp.zig:26:22: error: unreachable code",
57975921 );
57985922
57995923 cases.add(
58005924 "wrong types given to atomic order args in cmpxchg",
58015925 \\export fn entry() void {
58025926 \\ var x: i32 = 1234;
5803 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {}
5927 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
58045928 \\}
58055929 ,
5806 "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
5930 "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
58075931 );
58085932
58095933 cases.add(
58105934 "wrong types given to @export",
58115935 \\extern fn entry() void { }
58125936 \\comptime {
5813 \\ @export("entry", entry, u32(1234));
5937 \\ @export("entry", entry, @as(u32, 1234));
58145938 \\}
58155939 ,
5816 "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
5940 "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
58175941 );
58185942
58195943 cases.add(
......@@ -6185,7 +6309,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
61856309 \\};
61866310 \\
61876311 \\export fn entry() void {
6188 \\ var y = u3(3);
6312 \\ var y = @as(u3, 3);
61896313 \\ var x = @intToEnum(Small, y);
61906314 \\}
61916315 ,
......@@ -6722,8 +6846,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67226846 "tmp.zig:1:1: note: declared here",
67236847 );
67246848
6725 // fixed bug #2032
6726 cases.add(
6849 cases.add( // fixed bug #2032
67276850 "compile diagnostic string for top level decl type",
67286851 \\export fn entry() void {
67296852 \\ var foo: u32 = @This(){};
......@@ -6731,6 +6854,5 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67316854 ,
67326855 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",
67336856 "tmp.zig:1:1: note: (root) declared here",
6734 "tmp.zig:2:5: note: referenced here",
67356857 );
67366858}
test/stage1/behavior.zig+2
......@@ -32,6 +32,8 @@ comptime {
3232 _ = @import("behavior/bugs/2346.zig");
3333 _ = @import("behavior/bugs/2578.zig");
3434 _ = @import("behavior/bugs/2692.zig");
35 _ = @import("behavior/bugs/2889.zig");
36 _ = @import("behavior/bugs/3007.zig");
3537 _ = @import("behavior/bugs/3046.zig");
3638 _ = @import("behavior/bugs/3112.zig");
3739 _ = @import("behavior/bugs/3367.zig");
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+37-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}
......@@ -298,3 +298,38 @@ test "implicit cast zero sized array ptr to slice" {
298298 const c: []const u8 = &b;
299299 expect(c.len == 0);
300300}
301
302test "anonymous list literal syntax" {
303 const S = struct {
304 fn doTheTest() void {
305 var array: [4]u8 = .{1, 2, 3, 4};
306 expect(array[0] == 1);
307 expect(array[1] == 2);
308 expect(array[2] == 3);
309 expect(array[3] == 4);
310 }
311 };
312 S.doTheTest();
313 comptime S.doTheTest();
314}
315
316test "anonymous literal in array" {
317 const S = struct {
318 const Foo = struct {
319 a: usize = 2,
320 b: usize = 4,
321 };
322 fn doTheTest() void {
323 var array: [2]Foo = .{
324 .{.a = 3},
325 .{.b = 3},
326 };
327 expect(array[0].a == 3);
328 expect(array[0].b == 4);
329 expect(array[1].a == 2);
330 expect(array[1].b == 3);
331 }
332 };
333 S.doTheTest();
334 comptime S.doTheTest();
335}
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+7-7
......@@ -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);
......@@ -1214,7 +1214,7 @@ test "spill target expr in a for loop" {
12141214 }
12151215
12161216 const Foo = struct {
1217 slice: []i32,
1217 slice: []const i32,
12181218 };
12191219
12201220 fn atest(foo: *Foo) i32 {
......@@ -1245,7 +1245,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
12451245 }
12461246
12471247 const Foo = struct {
1248 slice: []i32,
1248 slice: []const i32,
12491249 };
12501250
12511251 fn atest(foo: *Foo) i32 {
test/stage1/behavior/atomics.zig+40-3
......@@ -98,12 +98,49 @@ 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}
110
111test "atomic load and rmw with enum" {
112 const Value = enum(u8) {
113 a,
114 b,
115 c,
116 };
117 var x = Value.a;
118
119 expect(@atomicLoad(Value, &x, .SeqCst) != .b);
120
121 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);
122 expect(@atomicLoad(Value, &x, .SeqCst) == .c);
123 expect(@atomicLoad(Value, &x, .SeqCst) != .a);
124 expect(@atomicLoad(Value, &x, .SeqCst) != .b);
125}
126
127test "atomic store" {
128 var x: u32 = 0;
129 @atomicStore(u32, &x, 1, .SeqCst);
130 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
131 @atomicStore(u32, &x, 12345678, .SeqCst);
132 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
133}
134
135test "atomic store comptime" {
136 comptime testAtomicStore();
137 testAtomicStore();
138}
139
140fn testAtomicStore() void {
141 var x: u32 = 0;
142 @atomicStore(u32, &x, 1, .SeqCst);
143 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
144 @atomicStore(u32, &x, 12345678, .SeqCst);
145 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
146}
\ No newline at end of file
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/2889.zig created+31
......@@ -0,0 +1,31 @@
1const std = @import("std");
2
3const source = "A-";
4
5fn parseNote() ?i32 {
6 const letter = source[0];
7 const modifier = source[1];
8
9 const semitone = blk: {
10 if (letter == 'C' and modifier == '-') break :blk @as(i32, 0);
11 if (letter == 'C' and modifier == '#') break :blk @as(i32, 1);
12 if (letter == 'D' and modifier == '-') break :blk @as(i32, 2);
13 if (letter == 'D' and modifier == '#') break :blk @as(i32, 3);
14 if (letter == 'E' and modifier == '-') break :blk @as(i32, 4);
15 if (letter == 'F' and modifier == '-') break :blk @as(i32, 5);
16 if (letter == 'F' and modifier == '#') break :blk @as(i32, 6);
17 if (letter == 'G' and modifier == '-') break :blk @as(i32, 7);
18 if (letter == 'G' and modifier == '#') break :blk @as(i32, 8);
19 if (letter == 'A' and modifier == '-') break :blk @as(i32, 9);
20 if (letter == 'A' and modifier == '#') break :blk @as(i32, 10);
21 if (letter == 'B' and modifier == '-') break :blk @as(i32, 11);
22 return null;
23 };
24
25 return semitone;
26}
27
28test "fixed" {
29 const result = parseNote();
30 std.testing.expect(result.? == 9);
31}
test/stage1/behavior/bugs/3007.zig created+23
......@@ -0,0 +1,23 @@
1const std = @import("std");
2
3const Foo = struct {
4 free: bool,
5
6 pub const FooError = error{NotFree};
7};
8
9var foo = Foo{ .free = true };
10var default_foo: ?*Foo = null;
11
12fn get_foo() Foo.FooError!*Foo {
13 if (foo.free) {
14 foo.free = false;
15 return &foo;
16 }
17 return error.NotFree;
18}
19
20test "fixed" {
21 default_foo = get_foo() catch null; // This Line
22 std.testing.expect(!default_foo.?.free);
23}
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+38-11
......@@ -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,6 +535,33 @@ 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}
541
542test "implicit cast *[0]T to E![]const u8" {
543 var x = @as(anyerror![]const u8, &[0]u8{});
544 expect((x catch unreachable).len == 0);
545}
546
547test "peer cast *[0]T to E![]const T" {
548 var buffer: [5]u8 = "abcde";
549 var buf: anyerror![]const u8 = buffer[0..];
550 var b = false;
551 var y = if (b) &[0]u8{} else buf;
552 expect(mem.eql(u8, "abcde", y catch unreachable));
553}
554
555test "peer cast *[0]T to []const T" {
556 var buffer: [5]u8 = "abcde";
557 var buf: []const u8 = buffer[0..];
558 var b = false;
559 var y = if (b) &[0]u8{} else buf;
560 expect(mem.eql(u8, "abcde", y));
561}
562
563var global_array: [4]u8 = undefined;
564test "cast from array reference to fn" {
565 const f = @ptrCast(extern fn () void, &global_array);
566 expect(@ptrToInt(f) == @ptrToInt(&global_array));
567}
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+6-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" {
......@@ -160,6 +160,10 @@ fn testErrToIntWithOnePossibleValue(
160160 }
161161}
162162
163test "empty error union" {
164 const x = error{} || error{};
165}
166
163167test "error union peer type resolution" {
164168 testErrorUnionPeerTypeResolution(1);
165169}
......@@ -295,7 +299,7 @@ test "nested error union function call in optional unwrap" {
295299test "widen cast integer payload of error union function call" {
296300 const S = struct {
297301 fn errorable() !u64 {
298 var x = u64(try number());
302 var x = @as(u64, try number());
299303 return x;
300304 }
301305
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+18-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);
......@@ -247,3 +247,19 @@ test "discard the result of a function that returns a struct" {
247247 S.entry();
248248 comptime S.entry();
249249}
250
251test "function call with anon list literal" {
252 const S = struct {
253 fn doTheTest() void {
254 consumeVec(.{9, 8, 7});
255 }
256
257 fn consumeVec(vec: [3]f32) void {
258 expect(vec[0] == 9);
259 expect(vec[1] == 8);
260 expect(vec[2] == 7);
261 }
262 };
263 S.doTheTest();
264 comptime S.doTheTest();
265}
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+76-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
......@@ -709,3 +709,71 @@ test "packed struct field passed to generic function" {
709709 var loaded = S.genericReadPackedField(&p.b);
710710 expect(loaded == 29);
711711}
712
713test "anonymous struct literal syntax" {
714 const S = struct {
715 const Point = struct {
716 x: i32,
717 y: i32,
718 };
719
720 fn doTheTest() void {
721 var p: Point = .{
722 .x = 1,
723 .y = 2,
724 };
725 expect(p.x == 1);
726 expect(p.y == 2);
727 }
728 };
729 S.doTheTest();
730 comptime S.doTheTest();
731}
732
733test "fully anonymous struct" {
734 const S = struct {
735 fn doTheTest() void {
736 dump(.{
737 .int = @as(u32, 1234),
738 .float = @as(f64, 12.34),
739 .b = true,
740 .s = "hi",
741 });
742 }
743 fn dump(args: var) void {
744 expect(args.int == 1234);
745 expect(args.float == 12.34);
746 expect(args.b);
747 expect(args.s[0] == 'h');
748 expect(args.s[1] == 'i');
749 }
750 };
751 S.doTheTest();
752 comptime S.doTheTest();
753}
754
755test "fully anonymous list literal" {
756 const S = struct {
757 fn doTheTest() void {
758 dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
759 }
760 fn dump(args: var) void {
761 expect(args.@"0" == 1234);
762 expect(args.@"1" == 12.34);
763 expect(args.@"2");
764 expect(args.@"3"[0] == 'h');
765 expect(args.@"3"[1] == 'i');
766 }
767 };
768 S.doTheTest();
769 comptime S.doTheTest();
770}
771
772test "anonymous struct literal assigned to variable" {
773 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };
774 expect(vec.@"0" == 22);
775 expect(vec.@"1" == 55);
776 expect(vec.@"2" == 99);
777 vec.@"1" += 1;
778 expect(vec.@"1" == 56);
779}
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+59-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);
......@@ -535,3 +535,50 @@ test "global union with single field is correctly initialized" {
535535 };
536536 expect(glbl.f.x == 123);
537537}
538
539pub const FooUnion = union(enum) {
540 U0: usize,
541 U1: u8,
542};
543
544var glbl_array: [2]FooUnion = undefined;
545
546test "initialize global array of union" {
547 glbl_array[1] = FooUnion{ .U1 = 2 };
548 glbl_array[0] = FooUnion{ .U0 = 1 };
549 expect(glbl_array[0].U0 == 1);
550 expect(glbl_array[1].U1 == 2);
551}
552
553test "anonymous union literal syntax" {
554 const S = struct {
555 const Number = union {
556 int: i32,
557 float: f64,
558 };
559
560 fn doTheTest() void {
561 var i: Number = .{ .int = 42 };
562 var f = makeNumber();
563 expect(i.int == 42);
564 expect(f.float == 12.34);
565 }
566
567 fn makeNumber() Number {
568 return .{ .float = 12.34 };
569 }
570 };
571 S.doTheTest();
572 comptime S.doTheTest();
573}
574
575test "update the tag value for zero-sized unions" {
576 const S = union(enum) {
577 U0: void,
578 U1: void,
579 };
580 var x = S{ .U0 = {} };
581 expect(x == .U0);
582 x = S{ .U1 = {} };
583 expect(x == .U1);
584}
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/standalone/brace_expansion/main.zig+2-2
......@@ -179,8 +179,8 @@ fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
179179}
180180
181181pub fn main() !void {
182 var stdin_file = try io.getStdIn();
183 var stdout_file = try io.getStdOut();
182 const stdin_file = io.getStdIn();
183 const stdout_file = io.getStdOut();
184184
185185 var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator);
186186 defer arena.deinit();
test/standalone/cat/main.zig+6-8
......@@ -10,30 +10,28 @@ pub fn main() !void {
1010 var args_it = process.args();
1111 const exe = try unwrapArg(args_it.next(allocator).?);
1212 var catted_anything = false;
13 var stdout_file = try io.getStdOut();
13 const stdout_file = io.getStdOut();
1414
1515 while (args_it.next(allocator)) |arg_or_err| {
1616 const arg = try unwrapArg(arg_or_err);
1717 if (mem.eql(u8, arg, "-")) {
1818 catted_anything = true;
19 var stdin_file = try io.getStdIn();
20 try cat_file(&stdout_file, &stdin_file);
19 try cat_file(stdout_file, io.getStdIn());
2120 } else if (arg[0] == '-') {
2221 return usage(exe);
2322 } else {
24 var file = File.openRead(arg) catch |err| {
23 const file = File.openRead(arg) catch |err| {
2524 warn("Unable to open file: {}\n", @errorName(err));
2625 return err;
2726 };
2827 defer file.close();
2928
3029 catted_anything = true;
31 try cat_file(&stdout_file, &file);
30 try cat_file(stdout_file, file);
3231 }
3332 }
3433 if (!catted_anything) {
35 var stdin_file = try io.getStdIn();
36 try cat_file(&stdout_file, &stdin_file);
34 try cat_file(stdout_file, io.getStdIn());
3735 }
3836}
3937
......@@ -42,7 +40,7 @@ fn usage(exe: []const u8) !void {
4240 return error.Invalid;
4341}
4442
45fn cat_file(stdout: *File, file: *File) !void {
43fn cat_file(stdout: File, file: File) !void {
4644 var buf: [1024 * 4]u8 = undefined;
4745
4846 while (true) {
test/standalone/guess_number/main.zig+1-2
......@@ -4,8 +4,7 @@ const io = std.io;
44const fmt = std.fmt;
55
66pub fn main() !void {
7 var stdout_file = try io.getStdOut();
8 const stdout = &stdout_file.outStream().stream;
7 const stdout = &io.getStdOut().outStream().stream;
98
109 try stdout.print("Welcome to the Guess Number Game in Zig.\n");
1110
test/standalone/hello_world/hello.zig+1-2
......@@ -1,8 +1,7 @@
11const std = @import("std");
22
33pub fn main() !void {
4 // If this program is run without stdout attached, exit with an error.
5 const stdout_file = try std.io.getStdOut();
4 const stdout_file = std.io.getStdOut();
65 // If this program encounters pipe failure when printing to stdout, exit
76 // with an error.
87 try stdout_file.write("Hello, world!\n");
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+66-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,22 +1798,31 @@ 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 \\
18151815 );
18161816
1817 if (builtin.os != builtin.Os.windows) {
1818 // sysv_abi not currently supported on windows
1819 cases.add("Macro qualified functions",
1820 \\void __attribute__((sysv_abi)) foo(void);
1821 ,
1822 \\pub extern fn foo() void;
1823 );
1824 }
1825
18171826 /////////////// Cases for only stage1 because stage2 behavior is better ////////////////
18181827 cases.addC("Parameterless function prototypes",
18191828 \\void foo() {}